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 <readerWriter/rwString.h>
20 #include "vrfutil/rwUUID.h"
21 #include <tbb/spin_mutex.h>
22 
23 class Coordinate_System;
24 class DtExtent;
25 class DtSimObject;
26 class DtTerrainInterface;
27 struct DtInputNavTag;
28 class DtNavEdge;
32 
34 {
40 };
41 
43 {
48 };
49 
50 typedef std::set<DtNavSectorName> DtNavSectorNames;
51 
57 {
58 public:
59  typedef std::shared_ptr<DtNavAreaQuery> Ptr;
60  typedef std::weak_ptr<DtNavAreaQuery> WeakPtr;
61 
63  virtual ~DtNavAreaQuery() { };
64 
66  virtual bool complete() = 0;
67 
69  virtual bool tick() = 0;
70 
72  virtual bool success() = 0;
73 
75  virtual bool navDataChanged() = 0;
76 
78  virtual bool outOfWorkingMemory() = 0;
79 
81  virtual bool hadComputationError() = 0;
82 
84  virtual std::vector<DtVector> results() = 0;
85 
87  virtual double outputValue() { return 0.0; };
88 
90  virtual std::vector<DtVector> debugPoints() { return std::vector<DtVector>(); };
91 
93  virtual void* internalQuery() = 0;
94 };
95 
98 {
99 public:
101  virtual ~DtNavAreaNullQuery() override { };
102 
103  virtual bool complete() override { return true; };
104  virtual bool tick() override { return true; };
105  virtual bool success() override { return true; };
106  virtual void cancel() {};
107  virtual bool navDataChanged() override { return false; };
108  virtual bool outOfWorkingMemory() override { return false; };
109  virtual bool hadComputationError() override { return false; };
110  virtual std::vector<DtVector> results() override { return std::vector<DtVector>(); };
111  virtual void * internalQuery(void) override { return 0; };
112 };
113 
116 {
117  DtNavAreaConfig() : workingMemorySize(16), regenerateAtRuntime(true),
118  maxRegenerationThreads(2), regenerationDelay(2.5), queryTimeBudget(1),
119  regenerationFileDirectory() {};
120 
123  int workingMemorySize;
124 
127 
130 
133 
137 
140 };
141 
145 {
146 public:
148 
149 protected:
152 };
153 
154 
156 typedef std::weak_ptr<DtNavRegenRequestIdData> DtNavRegenRequestId;
157 
161 {
162 public:
164 
165  void setMaxThreads(unsigned maxThreads)
166  {
168  }
169 
170  unsigned maxThreads() const { return myMaxThreads; }
171 
172  bool claimThread()
173  {
175  {
176  ++myUsedThreads;
177  return true;
178  }
179  return false;
180  }
181 
183  {
184  if (myUsedThreads > 0)
185  {
186  --myUsedThreads;
187  }
188  }
189 
191  {
192  myUsedThreads = 0;
193  }
194 
195 private:
196 
197  unsigned myMaxThreads;
198  unsigned myUsedThreads;
199 };
200 
206 {
207 public:
209  {
211  int port;
212  std::vector<DtRwString> profiles;
214  };
215 
216  typedef unsigned NavAreaId;
218  {
219  DtNavTriangleInfo() : navTag(0, 0) {};
220  DtVector points[3];
222  };
223 
225  {
226  DtNavTriangleInfoExt() : navTagExt(0, 0) {};
227  DtVector points[3];
229  };
230 
231  typedef DtNavArea* (*DtNavAreaCreatorFcn)();
232  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestEvaluatorFcn)(const DtVector& localPoint, void* userData);
233  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestNavTagEvaluatorFcn)(const DtVector& localPoint, const DtNavTag& tag, void* userData);
234  typedef void (*DtSearchAreaPointCostModifierEvaluatorFcn)(const DtVector& localPoint, float* currentCost, void* userData);
235  typedef DtOnPathToGraphVertexComputedResult(*DtPathCalculatedEvaluatorFcn)(const DtVector& localPoint, double pathCost, void* userData);
236  typedef void(*DtSectorRegenerationCb)(void* userData);
237 
239  static DtNavArea* create();
240 
242  static void setNavAreaCreatorFcn(DtNavAreaCreatorFcn fcn);
243 
246 
247  static bool navAreaDebuggingEnabled();
248  static void setNavAreaDebuggingEnabled(bool enable);
250 
251  virtual ~DtNavArea() {};
252  virtual bool initialize(NavAreaId navAreaId, Coordinate_System* coordSys,
253  DtTerrainInterface* terrainIf, DtNavAreaConfig config,
254  DtNavGenerationThreadCounter* threadCounter,
255  bool parallelQueryQueueProcessing = false,
256  std::vector<DtString> profiles = std::vector<DtString>()) = 0;
257 
259  virtual NavAreaId navAreaId() const = 0;
260 
262  virtual void update(float deltaTimeInSeconds) = 0;
263 
266  virtual void processQueues() = 0;
267 
269  virtual bool hasPendingQueries() const = 0;
270 
274  virtual void processTerrainChangeNotification(const DtTerrainChangeNotificationInfo& terrainChangeInfo) = 0;
275 
278  virtual bool loadNavData(const DtString& path, const DtVariableBindingsList& variableBindings =
280 
282  virtual bool inNavArea(const DtVector& localPos) const = 0;
283 
289  virtual bool validPosition(const DtString& profile, const DtVector& localPos,
290  DtNavTag* navTag = 0, DtVector* outPos = 0) = 0;
291 
295  virtual bool navTopoPosition(const DtVector& localPosition,
296  DtVector& navPosition) const = 0;
297 
300  virtual bool localPosition(const DtVector& navPosition,
301  DtVector& localPosition) const = 0;
302 
305  virtual bool navTopoVector(const DtVector& localVector,
306  DtVector& navVector) const = 0;
307 
310  virtual bool localVector(const DtVector& navPosition,
311  DtVector& localVector) const = 0;
312 
314  virtual bool validForProfile(const DtString& profile) const = 0;
315 
318  virtual bool profileEntitySize(const DtString& profile, double& radius, double& height) const = 0;
319 
320  virtual DtNavDataDebugInfo* debugInfo() = 0;
321 
322  virtual void setExtent(DtExtent* e) = 0;
323  virtual DtExtent localExtent() = 0;
324 
326 
327  virtual double areaWidth() const = 0;
328  virtual double areaLength() const = 0;
330 
332  virtual void cancelQuery(DtNavAreaQuery::Ptr) = 0;
333 
337  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterest(const DtString& profile,
338  const DtVector& startLocalPos, int tag = DtNavDataTagAny, double propagationRadius = 200.,
339  DtPointOfInterestEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0,
340  void* evalFcnUserData = 0) = 0;
341 
346  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterestUsingNavTag(const DtString& profile,
347  const DtVector& startLocalPos, bool useHighPriorityQueue, int tag = DtNavDataTagAny,
348  double propagationRadius = 200., DtPointOfInterestNavTagEvaluatorFcn evalFcn = 0,
349  DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
350 
354  virtual void findNearbyNavEdgesUsingNavTags(const DtString& profile, double searchRadius,
355  const DtVector& fromFromHere, const std::vector<DtInputNavTag>& navTagVals,
356  std::list<const DtNavEdge*>& result) const = 0;
357 
360  virtual void findVerticesUsingNavTags(const DtString& profile, double searchRadius,
361  const DtVector& fromFromHere, const std::vector<DtInputNavTag>& navTagVals,
362  std::list<DtVector>& result) const = 0;
363 
367  virtual DtNavAreaQuery::Ptr findBestExitPoint(const DtString& profile, DtNavBot* searcher,
368  const DtVector& startLocalPos, const DtVector& destination, int tag = DtNavDataTagAny,
369  double propagationRadius = 200.) = 0;
370 
376  virtual bool isPositionInside(const DtString& profile, const DtVector& testPosition,
377  double searchHeight = 1000., DtVector* heightAdjustedLocation = nullptr) const = 0;
378 
381  virtual bool movePositionInsideIfOutside(const DtString& profile,
382  double searchRadius, double searchHeight,
383  const DtVector& fromFromHere, DtVector& result, int& halfEdgeType) const = 0;
384 
387  virtual bool findInsidePositionFromOutsidePosition(const DtString& profile,
388  double searchRadius, double searchHeight, const DtVector& fromFromHere,
389  DtVector& result, int& halfEdgeType) const = 0;
390 
392  virtual DtNavAreaQuery::Ptr findBestPathTo(const DtString& profile, const DtVector& start,
393  const std::vector<DtVector>& localDestinationPositions, DtNavBot* searcher, int tag = -1,
394  DtSearchAreaPointCostModifierEvaluatorFcn = 0, DtPointOfInterestEvaluatorFcn = 0,
395  DtPathCalculatedEvaluatorFcn = 0, void* usrData = 0, bool startMovingWhenFound = false) = 0;
396 
398  virtual DtNavAreaQuery::Ptr findPathToLocation(const DtString& profile, const DtVector& start,
399  const DtVector& destination, bool useAbstractGraphs = true,
400  bool useChannels = false, double channelRadius = 4.0,
401  const DtVector& locationToAvoid = DtVector(), double avoidanceRadius = 0,
402  DtNavBot::NavBotPathLocationEvalFcn costEvalFcn = 0, void* costEvalFcnUsrData = 0) = 0;
403 
406  virtual bool findFarthestPositionAlongHeading(const DtString& profile, const DtVector& start,
407  double heading, double maxDistance, DtVector& result, bool& reachedMaxDist) const = 0;
408 
411  virtual bool doesNavIntersectBetweenTwoPoints(const DtString& profile, const DtVector& start,
412  const DtVector& end) const = 0;
413 
414  virtual DtPersistentPointAlongHeadingQuery* createPeristentPointAlongHeadingQuery(const DtString& profile) const = 0;
415  virtual DtObjectsCollectorInExtentQuery* createObjectsCollectorInExtentQuery(const DtString& profile) const = 0;
416 
417  //User callback to check randomly generated points. The callback function
418  //should return true if the point is acceptable.
419  typedef bool (*DtLocalPointUserEvalCallback)(const DtVector& localVector, DtNavAreaQuery* query, void* userData);
420  static bool emptyCallback(const DtVector&, DtNavAreaQuery*, void*);
421 
444  virtual DtNavAreaQuery::Ptr generateRandomPoints(const DtString& profile,
445  const DtVector& localAccessibilityPoint = DtVector::zero(),
446  double minRadius = -1,
447  double maxRadius = -1,
448  const DtLocalVertexList& boundingArea = DtLocalVertexList(),
449  unsigned numberOfPoints = 1,
450  double minDistanceBetweenPoints = 0.0,
451  const DtString& placementRestriction = DtString::nullString(),
452  bool isStrict = true,
453  bool tightlyPack = false,
454  bool needLos = false,
455  bool groundClamp = false,
456  const DtLocalVertexList& leftOfLine = DtLocalVertexList(),
457  DtLocalPointUserEvalCallback callbackFcn = emptyCallback,
458  void* userData = 0) = 0;
459 
461  virtual DtNavAreaQuery::Ptr placeFormation(const DtString& profile,
462  std::vector<DtVector>& localPositions, double entityWidth) = 0;
463 
465  virtual bool tagVolumesToBeIntegrated() const = 0;
466 
468  const DtSimObject* attachedObject() { return myAttachedObject; }
469 
471  void setAttachedObject(const DtSimObject* object) { myAttachedObject = object; }
472 
481  virtual std::vector<DtVector> searchInArea(const DtString& profile,
482  const DtVector& startLocalPos, double radius, double postSpacing, DtNavBot* searcher,
483  DtPointOfInterestEvaluatorFcn evalFcn = 0, void* evalFcnUserData = 0, int tag = -1) const = 0;
484 
486  virtual bool navTrianglesInArea(const DtString& profile, const DtVector& location, double radius,
487  std::list<DtNavTriangleInfo>& triangles) = 0;
488 
490  virtual unsigned newNavTagId() = 0;
491 
493  virtual void associateNavTagIdWithObject(unsigned tagVolumeId, const DtUUID& objectUUID) = 0;
494 
496  virtual void disassociateNavTagId(unsigned navTagId) = 0;
497 
500  virtual DtUUID uuidFromNavTagId(unsigned navTagId) const = 0;
501 
504  virtual unsigned navTagVolumeIdFromUuid(const DtUUID& objectUUID) = 0;
505 
507  virtual const DtNavSectorNames& sectorsQueuedForRegeneration() const = 0;
508 
510  virtual const DtNavSectorNames& sectorsBeingRegenerated() const = 0;
511 
513  virtual DtNavSectorName sectorAtLocation(const DtString& profile, const DtVector& localPos) const = 0;
514 
517  virtual void addSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
518  virtual void removeSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
519 
523  virtual DtNavRegenRequestId requestNavDataGeneration(const DtVector& location, double radius,
524  const std::set<DtString>& profiles = std::set<DtString>()) = 0;
525 
527  virtual void requestNavDataReversion(DtNavRegenRequestId id) = 0;
528 
530  virtual void pauseNavDataRegeneration() = 0;
531 
533  virtual void resumeNavDataRegeneration() = 0;
534 
536  virtual bool revertNavData() = 0;
537 
541  virtual unsigned addNavEdge(const DtString& profile, std::vector<DtVector>& LocalPoints,
542  const DtInputNavTag& navTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
543 
547  virtual unsigned addNavIEdge(const DtString& profile, std::vector<DtVector>& LocalPoints, std::vector< std::vector<DtVector> >& localIPoints,
548  const DtInputNavTag& navTag, const DtInputNavTag& entryExitNavTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
549 
551  virtual void removeNavEdge(unsigned edgeId) = 0;
552 
556  virtual unsigned addCoverPoint(const DtString& profile, const DtVector& localPoint,
557  bool& creationComplete) = 0;
558 
560  virtual bool isCoverPointCreated(unsigned coverPointId) = 0;
561 
563  virtual void removeCoverPoint(unsigned coverPointId) = 0;
564 
566  virtual unsigned numberOfPendingQueries() const = 0;
567 
569  virtual bool objectNavData() const = 0;
570 
572  virtual void setBlockOnAsynchronousOperations(bool shouldBlock) = 0;
573 
574 public:
575 
577  virtual void printNavDataInfoForLocation(const DtVector& location, std::ostream& strm) const = 0;
578 
579  virtual bool hasPendingOperations() const = 0;
580 
581 protected:
582  static DtNavAreaCreatorFcn theNavAreaCreatorFcn;
583 
585 
589 };
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:160
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
virtual bool complete() override
Returns true when the query has completed.
Definition: navArea.h:103
DtNavAreaQuery()
Definition: navArea.h:62
DtNavTagExt navTagExt
Definition: navArea.h:228
bool regenerateAtRuntime
Whether nav data should be regenerated at runtime.
Definition: navArea.h:129
DtNavGenerationThreadCounter(unsigned maxThreads)
Definition: navArea.h:163
virtual ~DtNavAreaQuery()
Definition: navArea.h:63
Definition: navArea.h:224
void releaseAllThreads()
Definition: navArea.h:190
Definition: navGeneration.h:55
Aids in creating and parsing nav sector names.
Definition: navSectorName.h:25
double queryTimeBudget
The time budget per frame for path queries in ms. Default value is 1.
Definition: navArea.h:126
DtNavAreaNullQuery()
Definition: navArea.h:100
virtual ~DtNavArea()
Definition: navArea.h:251
Query that can be used when there is no valid navData.
Definition: navArea.h:97
double regenerationDelay
Minimum delay between an event resulting in nav data regeneration and the start of the regeneration t...
Definition: navArea.h:136
virtual void * internalQuery(void) override
A pointer to the internal query. Not generally used.
Definition: navArea.h:111
Contains the DtUUID class declaration.
The DtExtent represents an axis-aligned 3d bounding box.
Definition: extent.h:43
virtual void cancel()
Definition: navArea.h:106
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:139
std::weak_ptr< DtNavAreaQuery > WeakPtr
Definition: navArea.h:60
const DtSimObject * attachedObject()
If this Nav Area is attached to a sim object, returns that object.
Definition: navArea.h:468
static bool theNavAreaDebuggingEnabled
Definition: navArea.h:584
static DtNavAreaCreatorFcn theNavAreaCreatorFcn
Definition: navArea.h:582
virtual bool hadComputationError() override
Returns true if the query failed due to a computation error.
Definition: navArea.h:109
Definition: asyncJobServer.h:37
void releaseThread()
Definition: navArea.h:182
static const DtUUID & nullUUID()
unsigned NavAreaId
Definition: navArea.h:216
void setAttachedObject(const DtSimObject *object)
Sets the sim object his Nav Ara is attached to.
Definition: navArea.h:471
virtual ~DtNavAreaNullQuery() override
Definition: navArea.h:101
Definition: coordSystem.h:54
virtual bool outOfWorkingMemory() override
Returns true if the query failed due to a lack of working memory.
Definition: navArea.h:108
virtual ~DtNavRegenRequestIdData()
Definition: navArea.h:147
This class contains all the data and logic for navigation within a specific area. Nav Data may be loa...
Definition: navArea.h:205
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 bool success() override
Returns true if the query completed successfully.
Definition: navArea.h:105
int port
Definition: navArea.h:211
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:144
virtual std::vector< DtVector > results() override
A list of locations that may be the result of this query.
Definition: navArea.h:110
std::vector< DtFilename > SearchPaths
Definition: readerWriter.h:92
DtNavRegenRequestIdData(const DtNavRegenRequestIdData &)
Definition: navArea.h:151
DtTerrainInterface allows access to common terrain calls without having to know the terrain implement...
Definition: terrainInterface.h:93
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:90
int maxRegenerationThreads
Maximum number of threads performing nav data regeneration at a time.
Definition: navArea.h:132
DtNavRegenRequestIdData()
Definition: navArea.h:150
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:588
std::shared_ptr< DtNavAreaQuery > Ptr
Definition: navArea.h:59
static const DtVariableBindingsList & nullVariableReference()
bool claimThread()
Definition: navArea.h:172
void setMaxThreads(unsigned maxThreads)
Definition: navArea.h:165
Definition: navBot.h:32
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:80
virtual bool navDataChanged() override
Returns true if the nav data has changed during this query.
Definition: navArea.h:107
unsigned myUsedThreads
Definition: navArea.h:198
Definition: navArea.h:208
DtNavAreaConfig()
Definition: navArea.h:117
#define DT_DLL_vrfNavigation
This file is used to determine how to build.
Definition: vrfNavigationDefines.h:26
Configuration options for DtNavArea.
Definition: navArea.h:115
DtString status
Definition: navArea.h:213
virtual double outputValue()
An output value that may be the result of this query. May not relevant to all queries.
Definition: navArea.h:87
DtNavTag navTag
Definition: navArea.h:221
Extended DtNavTag class that keeps a local copy of myData.
Definition: navDataTag.h:110
virtual bool tick() override
Main function for performing query processing.
Definition: navArea.h:104
bool(* NavBotPathLocationEvalFcn)(const DtNavTag &navTag, float slope, float elevationChange, float *costMultiplier, void *userData)
Definition: navBot.h:130
class DtLocalVertexList:
Definition: localVertexList.h:20
DtString navAreaName
Definition: navArea.h:210
std::vector< DtRwString > profiles
Definition: navArea.h:212
Definition: navArea.h:217
Provides information about the terrain changes: mySpatExtent defines the terrain change type - e...
Definition: terrainImplementation.h:50
Base class for all asynchronous Nav Area queries. In this context asynchronous means non-blocking...
Definition: navArea.h:56
unsigned myMaxThreads
Definition: navArea.h:197
unsigned maxThreads() const
Definition: navArea.h:170

Document ID: Generated on Thu Oct 23 22:29:17 EDT 2025 from SVN revision 280951
Copyright © 2005-2024 MAK Technologies. All Rights Reserved (www.mak.com)