VR-Forces 5.0.3 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 
271  virtual bool loadNavData(const DtString& path, const DtVariableBindingsList& variableBindings =
272  DtReaderWriter::nullVariableReference(), bool objectNavData = false) = 0;
273 
275  virtual bool inNavArea(const DtVector& localPos) const = 0;
276 
282  virtual bool validPosition(const DtString& profile, const DtVector& localPos,
283  DtNavTag* navTag = 0, DtVector* outPos = 0) = 0;
284 
288  virtual bool navTopoPosition(const DtVector& localPosition,
289  DtVector& navPosition) const = 0;
290 
293  virtual bool localPosition(const DtVector& navPosition,
294  DtVector& localPosition) const = 0;
295 
298  virtual bool navTopoVector(const DtVector& localVector,
299  DtVector& navVector) const = 0;
300 
303  virtual bool localVector(const DtVector& navPosition,
304  DtVector& localVector) const = 0;
305 
307  virtual bool validForProfile(const DtString& profile) const = 0;
308 
309  virtual DtNavDataDebugInfo* debugInfo() = 0;
310 
311  virtual void setExtent(DtExtent* e) = 0;
312  virtual DtExtent localExtent() = 0;
313 
315 
316  virtual double areaWidth() const = 0;
317  virtual double areaLength() const = 0;
319 
321  virtual void cancelQuery(DtNavAreaQuery::Ptr) = 0;
322 
326  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterest(const DtString& profile,
327  const DtVector& startLocalPos, int tag = DtNavDataTagAny, double propagationRadius = 200.,
328  DtPointOfInterestEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0,
329  void* evalFcnUserData = 0) = 0;
330 
335  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterestUsingNavTag(const DtString& profile,
336  const DtVector& startLocalPos, bool useHighPriorityQueue, int tag = DtNavDataTagAny,
337  double propagationRadius = 200., DtPointOfInterestNavTagEvaluatorFcn evalFcn = 0,
338  DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
339 
343  virtual void findNearbyNavEdgesUsingNavTags(const DtString& profile, double searchRadius,
344  const DtVector& fromFromHere, const std::vector<DtInputNavTag>& navTagVals,
345  std::list<const DtNavEdge*>& result) const = 0;
346 
349  virtual void findVerticesUsingNavTags(const DtString& profile, double searchRadius,
350  const DtVector& fromFromHere, const std::vector<DtInputNavTag>& navTagVals,
351  std::list<DtVector>& result) const = 0;
352 
356  virtual DtNavAreaQuery::Ptr findBestExitPoint(const DtString& profile, DtNavBot* searcher,
357  const DtVector& startLocalPos, const DtVector& destination, int tag = DtNavDataTagAny,
358  double propagationRadius = 200., DtPointOfInterestEvaluatorFcn evalFcn = 0,
359  DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
360 
363  virtual bool findInsidePositionFromOutsidePosition(const DtString& profile,
364  double searchRadius, double searchHeight, const DtVector& fromFromHere,
365  DtVector& result, int& halfEdgeType) const = 0;
366 
368  virtual DtNavAreaQuery::Ptr findBestPathTo(const DtString& profile, const DtVector& start,
369  const std::vector<DtVector>& localDestinationPositions, DtNavBot* searcher, int tag = -1,
370  DtSearchAreaPointCostModifierEvaluatorFcn = 0, DtPointOfInterestEvaluatorFcn = 0,
371  DtPathCalculatedEvaluatorFcn = 0, void* usrData = 0, bool startMovingWhenFound = false) = 0;
372 
374  virtual DtNavAreaQuery::Ptr findPathToLocation(const DtString& profile, const DtVector& start,
375  const DtVector& destination, bool useAbstractGraphs = true,
376  const DtVector& locationToAvoid = DtVector(), double avoidanceRadius = 0,
377  DtNavBot::DtNavBotPathLocationEvalFcn costEvalFcn = 0, void* costEvalFcnUsrData = 0) = 0;
378 
381  virtual bool findFarthestPositionAlongHeading(const DtString& profile, const DtVector& start,
382  double heading, double maxDistance, DtVector& result, bool& reachedMaxDist) const = 0;
383 
386  virtual bool doesNavIntersectBetweenTwoPoints(const DtString& profile, const DtVector& start,
387  const DtVector& end) const = 0;
388 
389  virtual DtPersistentPointAlongHeadingQuery* createPeristentPointAlongHeadingQuery(const DtString& profile) const = 0;
390  virtual DtObjectsCollectorInExtentQuery* createObjectsCollectorInExtentQuery(const DtString& profile) const = 0;
391 
392  //User callback to check randomly generated points. The callback function
393  //should return true if the point is acceptable.
394  typedef bool (*DtLocalPointUserEvalCallback)(const DtVector& localVector, DtNavAreaQuery* query, void* userData);
395  static bool emptyCallback(const DtVector&, DtNavAreaQuery*, void*);
396 
419  virtual DtNavAreaQuery::Ptr generateRandomPoints(const DtString& profile,
420  const DtVector& localAccessibilityPoint = DtVector::zero(),
421  double minRadius = -1,
422  double maxRadius = -1,
423  const DtLocalVertexList& boundingArea = DtLocalVertexList(),
424  unsigned numberOfPoints = 1,
425  double minDistanceBetweenPoints = 0.0,
426  const DtString& placementRestriction = DtString::nullString(),
427  bool isStrict = true,
428  bool tightlyPack = false,
429  bool needLos = false,
430  bool groundClamp = false,
431  const DtLocalVertexList& leftOfLine = DtLocalVertexList(),
432  DtLocalPointUserEvalCallback callbackFcn = emptyCallback,
433  void* userData = 0) = 0;
434 
436  virtual bool tagVolumesToBeIntegrated() const = 0;
437 
439  const DtSimObject* attachedObject() { return myAttachedObject; }
440 
442  void setAttachedObject(const DtSimObject* object) { myAttachedObject = object; }
443 
452  virtual std::vector<DtVector> searchInArea(const DtString& profile,
453  const DtVector& startLocalPos, double radius, double postSpacing, DtNavBot* searcher,
454  DtPointOfInterestEvaluatorFcn evalFcn = 0, void* evalFcnUserData = 0, int tag = -1) const = 0;
455 
457  virtual bool navTrianglesInArea(const DtString& profile, const DtVector& location, double radius,
458  std::list<DtNavTriangleInfo>& triangles) = 0;
459 
461  virtual unsigned newNavTagId() = 0;
462 
464  virtual void associateNavTagIdWithObject(unsigned tagVolumeId, const DtUUID& objectUUID) = 0;
465 
467  virtual void disassociateNavTagId(unsigned navTagId) = 0;
468 
471  virtual DtUUID uuidFromNavTagId(unsigned navTagId) const = 0;
472 
475  virtual unsigned navTagVolumeIdFromUuid(const DtUUID& objectUUID) = 0;
476 
478  virtual const DtNavSectorNames& sectorsQueuedForRegeneration() const = 0;
479 
481  virtual const DtNavSectorNames& sectorsBeingRegenerated() const = 0;
482 
485  virtual void addSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
486  virtual void removeSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
487 
491  virtual DtNavRegenRequestId requestNavDataGeneration(const DtVector& location, double radius,
492  const std::set<DtString>& profiles = std::set<DtString>()) = 0;
493 
495  virtual void requestNavDataReversion(DtNavRegenRequestId id) = 0;
496 
498  virtual void pauseNavDataRegeneration() = 0;
499 
501  virtual void resumeNavDataRegeneration() = 0;
502 
504  virtual bool revertNavData() = 0;
505 
509  virtual unsigned addNavEdge(const DtString& profile, std::vector<DtVector>& LocalPoints,
510  const DtInputNavTag& navTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
511 
515  virtual unsigned addNavIEdge(const DtString& profile, std::vector<DtVector>& LocalPoints, std::vector< std::vector<DtVector> >& localIPoints,
516  const DtInputNavTag& navTag, const DtInputNavTag& entryExitNavTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
517 
519  virtual void removeNavEdge(unsigned edgeId) = 0;
520 
524  virtual unsigned addCoverPoint(const DtString& profile, const DtVector& localPoint,
525  bool& creationComplete) = 0;
526 
528  virtual bool isCoverPointCreated(unsigned coverPointId) = 0;
529 
531  virtual void removeCoverPoint(unsigned coverPointId) = 0;
532 
534  virtual unsigned numberOfPendingQueries() const = 0;
535 
536 public:
537 
539  virtual void printNavDataInfoForLocation(const DtVector& location, std::ostream& strm) const = 0;
540 
541 protected:
542  static DtNavAreaCreatorFcn theNavAreaCreatorFcn;
543 
545 
549 };
UUID is a unique ID wrapper class.
Definition: rwUUID.h:229
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:439
static bool theNavAreaDebuggingEnabled
Definition: navArea.h:544
static DtNavAreaCreatorFcn theNavAreaCreatorFcn
Definition: navArea.h:542
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:442
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:99
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:548
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:79
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 Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)