VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
navArea.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2021 MaK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
8 
9 
10 #pragma once
11 
13 #include <string>
16 #include "vrfNavigation/navBot.h"
17 #include <matrix/vlVector.h>
19 #include "boost/shared_ptr.hpp"
20 #include "boost/weak_ptr.hpp"
21 #include <readerWriter/rwString.h>
22 #include "vrfutil/rwUUID.h"
23 #include <tbb/spin_mutex.h>
24 
25 class Coordinate_System;
26 class DtExtent;
27 class DtSimObject;
28 class DtTerrainInterface;
29 struct DtInputNavTag;
30 class DtNavEdge;
33 
35 {
41 };
42 
44 {
49 };
50 
51 typedef std::set<DtNavSectorName> DtNavSectorNames;
52 
58 {
59 public:
60  typedef boost::shared_ptr<DtNavAreaQuery> Ptr;
61  typedef boost::weak_ptr<DtNavAreaQuery> WeakPtr;
62 
64  virtual ~DtNavAreaQuery() { };
65 
67  virtual bool complete() = 0;
68 
70  virtual bool tick() = 0;
71 
73  virtual bool success() = 0;
74 
76  virtual bool navDataChanged() = 0;
77 
79  virtual bool outOfWorkingMemory() = 0;
80 
82  virtual bool hadComputationError() = 0;
83 
85  virtual std::vector<DtVector> results() = 0;
86 
88  virtual double outputValue() { return 0.0; };
89 
91  virtual std::vector<DtVector> debugPoints() { return std::vector<DtVector>(); };
92 
94  virtual void* internalQuery() = 0;
95 };
96 
99 {
100 public:
102  virtual ~DtNavAreaNullQuery() { };
103 
104  virtual bool complete() { return true; };
105  virtual bool tick() { return true; };
106  virtual bool success() { return true; };
107  virtual void cancel() {};
108  virtual bool navDataChanged() { return false; };
109  virtual bool outOfWorkingMemory() { return false; };
110  virtual bool hadComputationError() { return false; };
111  virtual std::vector<DtVector> results() { return std::vector<DtVector>(); };
112  virtual void *internalQuery(void) { return 0; };
113 };
114 
117 {
118  DtNavAreaConfig() : workingMemorySize(16), regenerateAtRuntime(true),
119  maxRegenerationThreads(2), regenerationDelay(2.5), queryTimeBudget(1),
120  regenerationFileDirectory() {};
121 
124  int workingMemorySize;
125 
128 
131 
134 
138 
141 };
142 
146 {
147 public:
149 
150 protected:
153 };
154 
155 
157 typedef boost::weak_ptr<DtNavRegenRequestIdData> DtNavRegenRequestId;
158 
162 {
163 public:
165 
166  void setMaxThreads(unsigned maxThreads)
167  {
169  }
170 
171  unsigned maxThreads() const { return myMaxThreads; }
172 
173  bool claimThread()
174  {
176  {
177  ++myUsedThreads;
178  return true;
179  }
180  return false;
181  }
182 
184  {
185  if (myUsedThreads > 0)
186  {
187  --myUsedThreads;
188  }
189  }
190 
192  {
193  myUsedThreads = 0;
194  }
195 
196 private:
197 
198  unsigned myMaxThreads;
199  unsigned myUsedThreads;
200 };
201 
207 {
208 public:
210  {
212  int port;
213  std::vector<DtRwString> profiles;
215  };
216 
217  typedef unsigned NavAreaId;
219  {
220  DtNavTriangleInfo() : navTag(0, 0) {};
221  DtVector points[3];
223  };
224 
226  {
227  DtNavTriangleInfoExt() : navTagExt(0, 0) {};
228  DtVector points[3];
230  };
231 
232  typedef DtNavArea* (*DtNavAreaCreatorFcn)();
233  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestEvaluatorFcn)(const DtVector& localPoint, void* userData);
234  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestNavTagEvaluatorFcn)(const DtVector& localPoint, const DtNavTag& tag, void* userData);
235  typedef void (*DtSearchAreaPointCostModifierEvaluatorFcn)(const DtVector& localPoint, float* currentCost, void* userData);
236  typedef DtOnPathToGraphVertexComputedResult(*DtPathCalculatedEvaluatorFcn)(const DtVector& localPoint, double pathCost, void* userData);
237  typedef void(*DtSectorRegenerationCb)(void* userData);
238 
240  static DtNavArea* create();
241 
243  static void setNavAreaCreatorFcn(DtNavAreaCreatorFcn fcn);
244 
247 
248  static bool navAreaDebuggingEnabled();
249  static void setNavAreaDebuggingEnabled(bool enable);
251 
252  virtual ~DtNavArea() {};
253  virtual bool initialize(NavAreaId navAreaId, Coordinate_System* coordSys,
254  DtTerrainInterface* terrainIf, DtNavAreaConfig config,
255  DtNavGenerationThreadCounter* threadCounter,
256  bool parallelQueryQueueProcessing = false,
257  std::vector<DtString> profiles = std::vector<DtString>()) = 0;
258 
260  virtual NavAreaId navAreaId() const = 0;
261 
263  virtual void update(float deltaTimeInSeconds) = 0;
264 
267  virtual void processQueues() = 0;
268 
270  virtual bool hasPendingQueries() const = 0;
271 
274  virtual bool loadNavData(const DtString& path, const DtVariableBindingsList& variableBindings =
275  DtReaderWriter::nullVariableReference(), bool objectNavData = false) = 0;
276 
278  virtual bool inNavArea(const DtVector& localPos) const = 0;
279 
285  virtual bool validPosition(const DtString& profile, const DtVector& localPos,
286  DtNavTag* navTag = 0, DtVector* outPos = 0) = 0;
287 
291  virtual bool navTopoPosition(const DtVector& localPosition,
292  DtVector& navPosition) const = 0;
293 
296  virtual bool localPosition(const DtVector& navPosition,
297  DtVector& localPosition) const = 0;
298 
301  virtual bool navTopoVector(const DtVector& localVector,
302  DtVector& navVector) const = 0;
303 
306  virtual bool localVector(const DtVector& navPosition,
307  DtVector& localVector) const = 0;
308 
310  virtual bool validForProfile(const DtString& profile) const = 0;
311 
314  virtual bool profileEntitySize(const DtString& profile, double& radius, double& height) const = 0;
315 
316  virtual DtNavDataDebugInfo* debugInfo() = 0;
317 
318  virtual void setExtent(DtExtent* e) = 0;
319  virtual DtExtent localExtent() = 0;
320 
322 
323  virtual double areaWidth() const = 0;
324  virtual double areaLength() const = 0;
326 
328  virtual void cancelQuery(DtNavAreaQuery::Ptr) = 0;
329 
333  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterest(const DtString& profile,
334  const DtVector& startLocalPos, int tag = DtNavDataTagAny, double propagationRadius = 200.,
335  DtPointOfInterestEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0,
336  void* evalFcnUserData = 0) = 0;
337 
342  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterestUsingNavTag(const DtString& profile,
343  const DtVector& startLocalPos, bool useHighPriorityQueue, int tag = DtNavDataTagAny,
344  double propagationRadius = 200., DtPointOfInterestNavTagEvaluatorFcn evalFcn = 0,
345  DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
346 
350  virtual void findNearbyNavEdgesUsingNavTags(const DtString& profile, double searchRadius,
351  const DtVector& fromFromHere, const std::vector<DtInputNavTag>& navTagVals,
352  std::list<const DtNavEdge*>& result) const = 0;
353 
356  virtual void findVerticesUsingNavTags(const DtString& profile, double searchRadius,
357  const DtVector& fromFromHere, const std::vector<DtInputNavTag>& navTagVals,
358  std::list<DtVector>& result) const = 0;
359 
363  virtual DtNavAreaQuery::Ptr findBestExitPoint(const DtString& profile, DtNavBot* searcher,
364  const DtVector& startLocalPos, const DtVector& destination, int tag = DtNavDataTagAny,
365  double propagationRadius = 200., DtPointOfInterestEvaluatorFcn evalFcn = 0,
366  DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
367 
369  virtual bool isPositionInside(const DtString& profile, const DtVector& testPosition, double searchHeight = 1000.) const = 0;
370 
374  virtual bool movePositionInsideIfOutside(const DtString& profile,
375  double searchRadius, double searchHeight,
376  const DtVector& fromFromHere, DtVector& result, int& halfEdgeType) const = 0;
377 
380  virtual bool findInsidePositionFromOutsidePosition(const DtString& profile,
381  double searchRadius, double searchHeight, const DtVector& fromFromHere,
382  DtVector& result, int& halfEdgeType) const = 0;
383 
385  virtual DtNavAreaQuery::Ptr findBestPathTo(const DtString& profile, const DtVector& start,
386  const std::vector<DtVector>& localDestinationPositions, DtNavBot* searcher, int tag = -1,
387  DtSearchAreaPointCostModifierEvaluatorFcn = 0, DtPointOfInterestEvaluatorFcn = 0,
388  DtPathCalculatedEvaluatorFcn = 0, void* usrData = 0, bool startMovingWhenFound = false) = 0;
389 
391  virtual DtNavAreaQuery::Ptr findPathToLocation(const DtString& profile, const DtVector& start,
392  const DtVector& destination, bool useAbstractGraphs = true,
393  const DtVector& locationToAvoid = DtVector(), double avoidanceRadius = 0,
394  DtNavBot::DtNavBotPathLocationEvalFcn costEvalFcn = 0, void* costEvalFcnUsrData = 0) = 0;
395 
398  virtual bool findFarthestPositionAlongHeading(const DtString& profile, const DtVector& start,
399  double heading, double maxDistance, DtVector& result, bool& reachedMaxDist) const = 0;
400 
403  virtual bool doesNavIntersectBetweenTwoPoints(const DtString& profile, const DtVector& start,
404  const DtVector& end) const = 0;
405 
406  virtual DtPersistentPointAlongHeadingQuery* createPeristentPointAlongHeadingQuery(const DtString& profile) const = 0;
407  virtual DtObjectsCollectorInExtentQuery* createObjectsCollectorInExtentQuery(const DtString& profile) const = 0;
408 
409  //User callback to check randomly generated points. The callback function
410  //should return true if the point is acceptable.
411  typedef bool (*DtLocalPointUserEvalCallback)(const DtVector& localVector, DtNavAreaQuery* query, void* userData);
412  static bool emptyCallback(const DtVector&, DtNavAreaQuery*, void*);
413 
436  virtual DtNavAreaQuery::Ptr generateRandomPoints(const DtString& profile,
437  const DtVector& localAccessibilityPoint = DtVector::zero(),
438  double minRadius = -1,
439  double maxRadius = -1,
440  const DtLocalVertexList& boundingArea = DtLocalVertexList(),
441  unsigned numberOfPoints = 1,
442  double minDistanceBetweenPoints = 0.0,
443  const DtString& placementRestriction = DtString::nullString(),
444  bool isStrict = true,
445  bool tightlyPack = false,
446  bool needLos = false,
447  bool groundClamp = false,
448  const DtLocalVertexList& leftOfLine = DtLocalVertexList(),
449  DtLocalPointUserEvalCallback callbackFcn = emptyCallback,
450  void* userData = 0) = 0;
451 
453  virtual bool tagVolumesToBeIntegrated() const = 0;
454 
456  const DtSimObject* attachedObject() { return myAttachedObject; }
457 
459  void setAttachedObject(const DtSimObject* object) { myAttachedObject = object; }
460 
469  virtual std::vector<DtVector> searchInArea(const DtString& profile,
470  const DtVector& startLocalPos, double radius, double postSpacing, DtNavBot* searcher,
471  DtPointOfInterestEvaluatorFcn evalFcn = 0, void* evalFcnUserData = 0, int tag = -1) const = 0;
472 
474  virtual bool navTrianglesInArea(const DtString& profile, const DtVector& location, double radius,
475  std::list<DtNavTriangleInfo>& triangles) = 0;
476 
478  virtual unsigned newNavTagId() = 0;
479 
481  virtual void associateNavTagIdWithObject(unsigned tagVolumeId, const DtUUID& objectUUID) = 0;
482 
484  virtual void disassociateNavTagId(unsigned navTagId) = 0;
485 
488  virtual DtUUID uuidFromNavTagId(unsigned navTagId) const = 0;
489 
492  virtual unsigned navTagVolumeIdFromUuid(const DtUUID& objectUUID) = 0;
493 
495  virtual const DtNavSectorNames& sectorsQueuedForRegeneration() const = 0;
496 
498  virtual const DtNavSectorNames& sectorsBeingRegenerated() const = 0;
499 
502  virtual void addSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
503  virtual void removeSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
504 
508  virtual DtNavRegenRequestId requestNavDataGeneration(const DtVector& location, double radius,
509  const std::set<DtString>& profiles = std::set<DtString>()) = 0;
510 
512  virtual void requestNavDataReversion(DtNavRegenRequestId id) = 0;
513 
515  virtual void pauseNavDataRegeneration() = 0;
516 
518  virtual void resumeNavDataRegeneration() = 0;
519 
521  virtual bool revertNavData() = 0;
522 
526  virtual unsigned addNavEdge(const DtString& profile, std::vector<DtVector>& LocalPoints,
527  const DtInputNavTag& navTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
528 
532  virtual unsigned addNavIEdge(const DtString& profile, std::vector<DtVector>& LocalPoints, std::vector< std::vector<DtVector> >& localIPoints,
533  const DtInputNavTag& navTag, const DtInputNavTag& entryExitNavTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
534 
536  virtual void removeNavEdge(unsigned edgeId) = 0;
537 
541  virtual unsigned addCoverPoint(const DtString& profile, const DtVector& localPoint,
542  bool& creationComplete) = 0;
543 
545  virtual bool isCoverPointCreated(unsigned coverPointId) = 0;
546 
548  virtual void removeCoverPoint(unsigned coverPointId) = 0;
549 
551  virtual unsigned numberOfPendingQueries() const = 0;
552 
554  virtual bool objectNavData() const = 0;
555 
556 public:
557 
559  virtual void printNavDataInfoForLocation(const DtVector& location, std::ostream& strm) const = 0;
560 
561 protected:
562  static DtNavAreaCreatorFcn theNavAreaCreatorFcn;
563 
565 
569 };
UUID is a unique ID wrapper class.
Definition: uuid.h:59
This class is just used to count the nav generation threads to ensure we do not start too many thread...
Definition: navArea.h:161
Test class for providing a fast way for an entity to &quot;walk&quot; along the nav mesh. This is the abstract ...
Definition: persistentPointAlongHeadingQuery.h:11
DtNavAreaQuery()
Definition: navArea.h:63
DtNavTagExt navTagExt
Definition: navArea.h:229
bool regenerateAtRuntime
Whether nav data should be regenerated at runtime.
Definition: navArea.h:130
DtNavGenerationThreadCounter(unsigned maxThreads)
Definition: navArea.h:164
virtual ~DtNavAreaQuery()
Definition: navArea.h:64
Definition: navArea.h:225
void releaseAllThreads()
Definition: navArea.h:191
virtual bool tick()
Main function for performing query processing.
Definition: navArea.h:105
Definition: navGeneration.h:56
virtual bool outOfWorkingMemory()
Returns true if the query failed due to a lack of working memory.
Definition: navArea.h:109
double queryTimeBudget
The time budget per frame for path queries in ms. Default value is 1.
Definition: navArea.h:127
virtual bool success()
Returns true if the query completed successfully.
Definition: navArea.h:106
DtNavAreaNullQuery()
Definition: navArea.h:101
virtual ~DtNavArea()
Definition: navArea.h:252
Query that can be used when there is no valid navData.
Definition: navArea.h:98
double regenerationDelay
Minimum delay between an event resulting in nav data regeneration and the start of the regeneration t...
Definition: navArea.h:137
Contains the DtUUID class declaration.
The DtExtent represents an axis-aligned 3d bounding box.
Definition: extent.h:43
virtual void cancel()
Definition: navArea.h:107
VR-Forces wrapper for Gameware NavTag. Note: This class keeps only a pointer to the data...
Definition: navDataTag.h:87
DtFilename regenerationFileDirectory
The directory in which nav data regeneration files should be stored.
Definition: navArea.h:140
const DtSimObject * attachedObject()
If this Nav Area is attached to a sim object, returns that object.
Definition: navArea.h:456
static bool theNavAreaDebuggingEnabled
Definition: navArea.h:564
static DtNavAreaCreatorFcn theNavAreaCreatorFcn
Definition: navArea.h:562
Definition: asyncJobServer.h:37
void releaseThread()
Definition: navArea.h:183
static const DtUUID & nullUUID()
unsigned NavAreaId
Definition: navArea.h:217
void setAttachedObject(const DtSimObject *object)
Sets the sim object his Nav Ara is attached to.
Definition: navArea.h:459
Definition: coordSystem.h:54
virtual void * internalQuery(void)
A pointer to the internal query. Not generally used.
Definition: navArea.h:112
virtual ~DtNavRegenRequestIdData()
Definition: navArea.h:148
This class contains all the data and logic for navigation within a specific area. Nav Data may be loa...
Definition: navArea.h:206
std::list< const DtRwVariableBindings * > DtVariableBindingsList
Definition: readerWriterRegistry.h:29
Contains all the data and logic for navigation within a specific edge.
Definition: navEdge.h:18
virtual ~DtNavAreaNullQuery()
Definition: navArea.h:102
int port
Definition: navArea.h:212
This is just an abstract base class for the data contained in a DtNavRegenRequestId. The implementation of such an id is handled in a subclass.
Definition: navArea.h:145
bool(* DtNavBotPathLocationEvalFcn)(const DtNavTag &navTag, float slope, float elevationChange, float *costMultiplier, void *userData)
Definition: navBot.h:129
DtNavRegenRequestIdData(const DtNavRegenRequestIdData &)
Definition: navArea.h:152
DtTerrainInterface allows access to common terrain calls without having to know the terrain implement...
Definition: terrainInterface.h:100
boost::shared_ptr< DtNavAreaQuery > Ptr
Definition: navArea.h:60
virtual std::vector< DtVector > debugPoints()
A list of locations that may be generated to debug issues. May not relevant to all queries...
Definition: navArea.h:91
int maxRegenerationThreads
Maximum number of threads performing nav data regeneration at a time.
Definition: navArea.h:133
DtNavRegenRequestIdData()
Definition: navArea.h:151
const DtSimObject * myAttachedObject
Points to the host object if this navArea is attached to an object like a cultural feature or a large...
Definition: navArea.h:568
static const DtVariableBindingsList & nullVariableReference()
bool claimThread()
Definition: navArea.h:173
void setMaxThreads(unsigned maxThreads)
Definition: navArea.h:166
Definition: navBot.h:31
Class providing querying for entities in an extent within the nav mesh. This is the abstract base cla...
Definition: objectsCollectorInExtentQuery.h:11
Represents a single simulation object in the exercise. Object may be VRF simulation, or non-VRF simulated, and may be simulated by the local sim engine, or by a remote sim engine. Only public (external) state of the object is available. All data is read-only. All access to data of the object is thread safe within the simulation frame.
Definition: simObject.h:88
unsigned myUsedThreads
Definition: navArea.h:199
Definition: navArea.h:209
virtual bool navDataChanged()
Returns true if the nav data has changed during this query.
Definition: navArea.h:108
DtNavAreaConfig()
Definition: navArea.h:118
#define DT_DLL_vrfNavigation
This file is used to determine how to build.
Definition: vrfNavigationDefines.h:26
Configuration options for DtNavArea.
Definition: navArea.h:116
DtString status
Definition: navArea.h:214
virtual double outputValue()
An output value that may be the result of this query. May not relevant to all queries.
Definition: navArea.h:88
DtNavTag navTag
Definition: navArea.h:222
Extended DtNavTag class that keeps a local copy of myData.
Definition: navDataTag.h:110
virtual bool hadComputationError()
Returns true if the query failed due to a computation error.
Definition: navArea.h:110
class DtLocalVertexList:
Definition: localVertexList.h:20
DtString navAreaName
Definition: navArea.h:211
std::vector< DtRwString > profiles
Definition: navArea.h:213
Definition: navArea.h:218
virtual std::vector< DtVector > results()
A list of locations that may be the result of this query.
Definition: navArea.h:111
boost::weak_ptr< DtNavAreaQuery > WeakPtr
Definition: navArea.h:61
virtual bool complete()
Returns true when the query has completed.
Definition: navArea.h:104
Base class for all asynchronous Nav Area queries. In this context asynchronous means non-blocking...
Definition: navArea.h:57
unsigned myMaxThreads
Definition: navArea.h:198
unsigned maxThreads() const
Definition: navArea.h:171

Document ID: Generated on Wed Mar 27 22:49:11 EDT 2024 from SVN revision 264633
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)