VR-Forces 4.10 Class Documentation
 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 
24 class Coordinate_System;
25 class DtExtent;
26 class DtVrfObject;
27 class DtTerrainInterface;
28 struct DtInputNavTag;
29 class DtNavEdge;
30 
32 {
38 };
39 
41 {
46 };
47 
48 typedef std::set<DtNavSectorName> DtNavSectorNames;
49 
50 //Base class for asynchronous Nav Area queries.
51 //In this context asynchronous means non-blocking, but performed
52 //in a single-thread. These queries are time-sliced by
53 //gameware's infrastructure.
54 //Will be ticked by the navArea's update function.
55 
57 {
58 public:
59  typedef boost::shared_ptr<DtNavAreaQuery> Ptr;
60  typedef boost::weak_ptr<DtNavAreaQuery> WeakPtr;
61 
63  virtual ~DtNavAreaQuery() { };
64 
65  virtual bool complete() = 0;
66  virtual bool tick() = 0;
67  virtual bool success() = 0;
68 
70  virtual bool navDataChanged() = 0;
71  virtual bool outOfWorkingMemory() = 0;
72  virtual bool hadComputationError() = 0;
73 
74  virtual std::vector<DtVector> results() = 0;
75  virtual double outputValue() { return 0.0; };
76  virtual std::vector<DtVector> debugPoints() { return std::vector<DtVector>(); };
77  virtual void* internalQuery() = 0;
78 };
79 
80 //Query that can be used when there is no valid navData.
82 {
83 public:
85  virtual ~DtNavAreaNullQuery() { };
86 
87  virtual bool complete() { return true; };
88  virtual bool tick() { return true; };
89  virtual bool success() { return true; };
90  virtual void cancel() {};
91  virtual bool navDataChanged() { return false; };
92  virtual bool outOfWorkingMemory() { return false; };
93  virtual bool hadComputationError() { return false; };
94  virtual std::vector<DtVector> results() { return std::vector<DtVector>(); };
95  virtual void *internalQuery(void) { return 0; };
96 };
97 
100 {
101  DtNavAreaConfig() : workingMemorySize(16), regenerateAtRuntime(true),
102  maxRegenerationThreads(2), regenerationDelay(2.5), queryTimeBudget(1) {};
103 
106  int workingMemorySize;
107 
110 
113 
116 
120 
121 };
122 
126 {
127 public:
129 
130 protected:
133 };
134 
135 
137 typedef boost::weak_ptr<DtNavRegenRequestIdData> DtNavRegenRequestId;
138 
142 {
143 public:
145 
146  void setMaxThreads(unsigned maxThreads)
147  {
149  }
150 
151  unsigned maxThreads() const { return myMaxThreads; }
152 
153  bool claimThread()
154  {
156  {
157  ++myUsedThreads;
158  return true;
159  }
160  return false;
161  }
162 
164  {
165  if (myUsedThreads > 0)
166  {
167  --myUsedThreads;
168  }
169  }
170 
171 private:
172 
173  unsigned myMaxThreads;
174  unsigned myUsedThreads;
175 };
176 
182 {
183 public:
185  {
187  int port;
188  std::vector<DtRwString> profiles;
190  };
191 
194  {
195  DtNavTriangleInfo() : navTag(0, 0) {};
196  DtVector points[3];
198  };
199 
201  {
202  DtNavTriangleInfoExt() : navTagExt(0, 0) {};
203  DtVector points[3];
205  };
206 
207  typedef DtNavArea* (*DtNavAreaCreatorFcn)();
208  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestEvaluatorFcn)(const DtVector& localPoint, void* userData);
209  typedef DtOnGraphVertexVisitedResult (*DtPointOfInterestNavTagEvaluatorFcn)(const DtVector& localPoint, const DtNavTag& tag, void* userData);
210  typedef void (*DtSearchAreaPointCostModifierEvaluatorFcn)(const DtVector& localPoint, float* currentCost, void* userData);
211  typedef DtOnPathToGraphVertexComputedResult(*DtPathCalculatedEvaluatorFcn)(const DtVector& localPoint, double pathCost, void* userData);
212  typedef void(*DtSectorRegenerationCb)(void* userData);
213 
214  static DtNavArea* create();
215  static void setNavAreaCreatorFcn(DtNavAreaCreatorFcn fcn);
216 
217  static bool navAreaDebuggingEnabled();
218  static void setNavAreaDebuggingEnabled(bool enable);
219 
220  virtual ~DtNavArea() {};
221  virtual bool initialize(Coordinate_System* coordSys, DtTerrainInterface* terrainIf, DtNavAreaConfig config,
222  DtNavGenerationThreadCounter* threadCounter,
223  std::vector<DtString> profiles = std::vector<DtString>()) = 0;
224  virtual void update(float deltaTimeInSeconds) = 0;
226  virtual bool loadNavData(const DtString& path, const DtVariableBindingsList& variableBindings =
227  DtReaderWriter::nullVariableReference(), bool objectNavData = false) = 0;
228  virtual bool inNavArea(const DtVector& localPos) const = 0;
234  virtual bool validPosition(const DtString& profile, const DtVector& localPos,
235  DtNavTag* navTag = 0, DtVector* outPos = 0) = 0;
236 
237  //Returns true if this area is valid for the given navigation profile.
238  virtual bool validForProfile(const DtString& profile) const = 0;
239 
240  virtual DtNavDataDebugInfo* debugInfo() = 0;
241 
242  virtual void setExtent(DtExtent* e) = 0;
243  virtual DtExtent localExtent() = 0;
244 
246  virtual void cancelQuery(DtNavAreaQuery::Ptr) = 0;
247 
250  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterest(const DtString& profile, const DtVector& startLocalPos,
251  int tag = DtNavDataTagAny, double propagationRadius = 200.,
252  DtPointOfInterestEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
253 
257  virtual DtNavAreaQuery::Ptr findNearbyPointOfInterestUsingNavTag(const DtString& profile, const DtVector& startLocalPos,
258  bool useHighPriorityQueue,
259  int tag = DtNavDataTagAny, double propagationRadius = 200.,
260  DtPointOfInterestNavTagEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
261 
264  virtual void findNearbyNavEdgesUsingNavTags(const DtString& profile, double searchRadius, const DtVector& fromFromHere,
265  const std::vector<DtInputNavTag>& navTagVals, std::list<DtNavEdge*>& result) const = 0;
266 
268  virtual void findVerticesUsingNavTags(const DtString& profile, double searchRadius, const DtVector& fromFromHere,
269  const std::vector<DtInputNavTag>& navTagVals, std::list<DtVector>& result) const = 0;
270 
273  virtual DtNavAreaQuery::Ptr findBestExitPoint(const DtString& profile, DtNavBot* searcher,
274  const DtVector& startLocalPos, const DtVector& destination,
275  int tag = DtNavDataTagAny, double propagationRadius = 200.,
276  DtPointOfInterestEvaluatorFcn evalFcn = 0, DtPathCalculatedEvaluatorFcn pathFcn = 0, void* evalFcnUserData = 0) = 0;
277 
279  virtual bool findInsidePositionFromOutsidePosition(const DtString& profile,
280  double searchRadius, double searchHeight, const DtVector& fromFromHere,
281  DtVector& result, int& halfEdgeType) const = 0;
282 
284  virtual DtNavAreaQuery::Ptr findBestPathTo(const DtString& profile, const DtVector& start,
285  const std::vector<DtVector>& localDestinationPositions, DtNavBot* searcher, int tag = -1,
286  DtSearchAreaPointCostModifierEvaluatorFcn = 0, DtPointOfInterestEvaluatorFcn = 0, DtPathCalculatedEvaluatorFcn = 0,
287  void* usrData = 0, bool startMovingWhenFound = false) = 0;
288 
290  virtual DtNavAreaQuery::Ptr findPathToLocation(const DtString& profile, const DtVector& start,
291  const DtVector& destination, bool useAbstractGraphs = true,
292  const DtVector& locationToAvoid = DtVector(), double avoidanceRadius = 0,
293  DtNavBot::DtNavBotPathLocationEvalFcn costEvalFcn = 0, void* costEvalFcnUsrData = 0) = 0;
294 
297  virtual bool findFarthestPositionAlongHeading(const DtString& profile, const DtVector& start,
298  double heading, double maxDistance, DtVector& result, bool& reachedMaxDist) const = 0;
299 
301  virtual bool doesNavIntersectBetweenTwoPoints(const DtString& profile, const DtVector& start, const DtVector& end) const = 0;
302 
303  //User callback to check randomly generated points. The callback function
304  //should return true if the point is acceptable.
305  typedef bool (*DtLocalPointUserEvalCallback)(const DtVector& localVector, DtNavAreaQuery* query, void* userData);
306  static bool emptyCallback(const DtVector&, DtNavAreaQuery*, void*);
307 
308  //Generate some number of random points.
309  //If localAccessibilityPoint is set, all points must be navigable
310  //from the access point.
311  //If boundingArea is set, all points must be inside the area,
312  //ignoring elevation. Note that this will not cause points to be
313  //generated outside the navArea.
314  //If boundingArea is not set, and radius is set, points will be generated
315  //using radius as a maximum distance from accessibilityPoint.
316  //If minDistanceBetweenPoints is set, generated points will be tested
317  //against the rest of the set of random points to make sure none are within
318  //the given distance of each other.
319  //If placementRestriction is set to one of the MovementMode strings (e.g.
320  //DtMovementModePreferRoads), points will be chosen that match that criteria.
321  //If isStrict is true, only points matching the placementRestriction will be
322  //generated, even if we can't create enough to match the desired number.
323  //If tightlyPack is true, points closer to access point or bounding area center
324  //will be favored.
325  //If needLos is true, will try to choose points that should have LOS to the
326  //specified access point.
327  //If groundClamp is true, points will be ground clamped to the terrain at a point
328  //below the original point plus the height of the entity specified in nav generation.
329  //If leftOfLine, the points specified will be considered a line, and only points
330  //to the left of that line will be generated.
331  //If callbackFcn is set, this user function is called on each generated
332  //point, to test if each point is acceptable.
333  virtual DtNavAreaQuery::Ptr generateRandomPoints(const DtString& profile,
334  const DtVector& localAccessibilityPoint = DtVector::zero(),
335  double minRadius = -1,
336  double maxRadius = -1,
337  const DtLocalVertexList& boundingArea = DtLocalVertexList(),
338  unsigned numberOfPoints = 1,
339  double minDistanceBetweenPoints = 0.0,
340  const DtString& placementRestriction = DtString::nullString(),
341  bool isStrict = true,
342  bool tightlyPack = false,
343  bool needLos = false,
344  bool groundClamp = false,
345  const DtLocalVertexList& leftOfLine = DtLocalVertexList(),
346  DtLocalPointUserEvalCallback callbackFcn = emptyCallback,
347  void* userData = 0) = 0;
348 
350  virtual bool tagVolumesToBeIntegrated() const = 0;
351 
352  DtVrfObject* attachedObject() { return myAttachedObject; }
353  void setAttachedObject(DtVrfObject* object) { myAttachedObject = object; }
354 
359  virtual std::vector<DtVector> searchInArea(const DtString& profile,
360  const DtVector& startLocalPos, double radius, double postSpacing, DtNavBot* searcher,
361  DtPointOfInterestEvaluatorFcn evalFcn = 0, void* evalFcnUserData = 0, int tag = -1) const = 0;
362 
363  virtual bool navTrianglesInArea(const DtString& profile, const DtVector& location, double radius, std::list<DtNavTriangleInfo>& triangles) = 0;
364 
366  virtual unsigned newNavTagId() = 0;
367 
369  virtual void associateNavTagIdWithObject(unsigned tagVolumeId, const DtUUID& objectUUID) = 0;
370 
372  virtual void disassociateNavTagId(unsigned navTagId) = 0;
373 
376  virtual DtUUID uuidFromNavTagId(unsigned navTagId) const = 0;
377 
380  virtual unsigned navTagVolumeIdFromUuid(const DtUUID& objectUUID) = 0;
381 
383  virtual const DtNavSectorNames& sectorsQueuedForRegeneration() const = 0;
384 
386  virtual const DtNavSectorNames& sectorsBeingRegenerated() const = 0;
387 
390  virtual void addSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
391  virtual void removeSectorRegenerationCallback(DtSectorRegenerationCb cb, void* usr) = 0;
392 
396  virtual DtNavRegenRequestId requestNavDataGeneration(const DtVector& location, double radius,
397  const std::set<DtString>& profiles = std::set<DtString>()) = 0;
398 
400  virtual void requestNavDataReversion(DtNavRegenRequestId id) = 0;
401 
405  virtual unsigned addNavEdge(const DtString& profile, std::vector<DtVector>& LocalPoints,
406  const DtInputNavTag& navTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
407 
411  virtual unsigned addNavIEdge(const DtString& profile, std::vector<DtVector>& LocalPoints, std::vector< std::vector<DtVector> >& localIPoints,
412  const DtInputNavTag& navTag, const DtInputNavTag& entryExitNavTag, const DtUUID& associatedObject = DtUUID::nullUUID()) = 0;
413 
415  virtual void removeNavEdge(unsigned edgeId) = 0;
416 
420  virtual unsigned addCoverPoint(const DtString& profile, const DtVector& localPoint,
421  bool& creationComplete) = 0;
422 
424  virtual bool isCoverPointCreated(unsigned coverPointId) = 0;
425 
427  virtual void removeCoverPoint(unsigned coverPointId) = 0;
428 
430  virtual void printNavDataInfoForLocation(const DtVector& location, std::ostream& strm) const = 0;
431 
432 protected:
433  static DtNavAreaCreatorFcn theNavAreaCreatorFcn;
434 
436 
440 };
UUID is a unique ID wrapper class.
Definition: rwUUID.h:222
This class is just used to count the nav generation threads to ensure we do not start too many thread...
Definition: navArea.h:141
DtNavAreaQuery()
Definition: navArea.h:62
DtNavTagExt navTagExt
Definition: navArea.h:204
bool regenerateAtRuntime
Whether nav data should be regenerated at runtime.
Definition: navArea.h:112
DtVrfObject is used to represent any type of simulated object (entities, aggregate, control objects) in a VR-Forces application.
Definition: vrfObject.h:215
DtNavGenerationThreadCounter(unsigned maxThreads)
Definition: navArea.h:144
virtual ~DtNavAreaQuery()
Definition: navArea.h:63
Definition: navArea.h:200
virtual bool tick()
Definition: navArea.h:88
DtVrfObject * myAttachedObject
Points to the host object if this navArea is attached to an object like a cultural feature or a large...
Definition: navArea.h:439
Definition: navGeneration.h:56
virtual bool outOfWorkingMemory()
Definition: navArea.h:92
double queryTimeBudget
The time budget per frame for path queries in ms. Default value is 1.
Definition: navArea.h:109
virtual bool success()
Definition: navArea.h:89
DtNavAreaNullQuery()
Definition: navArea.h:84
virtual ~DtNavArea()
Definition: navArea.h:220
Definition: navArea.h:81
double regenerationDelay
Minimum delay between an event resulting in nav data regeneration and the start of the regeneration t...
Definition: navArea.h:119
The DtExtent represents an axis-aligned 3d bounding box.
Definition: extent.h:43
virtual void cancel()
Definition: navArea.h:90
Wrapper for GameWare NavTag.
Definition: navDataTag.h:54
static bool theNavAreaDebuggingEnabled
Definition: navArea.h:435
static DtNavAreaCreatorFcn theNavAreaCreatorFcn
Definition: navArea.h:433
Definition: asyncJobServer.h:37
void releaseThread()
Definition: navArea.h:163
static const DtUUID & nullUUID()
Definition: coordSystem.h:54
virtual void * internalQuery(void)
Definition: navArea.h:95
virtual ~DtNavRegenRequestIdData()
Definition: navArea.h:128
Contains all the data and logic for navigation within a specific area.
Definition: navArea.h:181
DtVrfObject * attachedObject()
Definition: navArea.h:352
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:85
int port
Definition: navArea.h:187
This is just an abstract base class for the data contained in a DtNavRegenRequestId.
Definition: navArea.h:125
bool(* DtNavBotPathLocationEvalFcn)(const DtNavTag &navTag, float slope, float elevationChange, float *costMultiplier, void *userData)
Definition: navBot.h:121
DtNavRegenRequestIdData(const DtNavRegenRequestIdData &)
Definition: navArea.h:132
DtTerrainInterface allows access to common terrain calls without having to know the terrain implement...
Definition: terrainInterface.h:88
boost::shared_ptr< DtNavAreaQuery > Ptr
Definition: navArea.h:59
virtual std::vector< DtVector > debugPoints()
Definition: navArea.h:76
int maxRegenerationThreads
Maximum number of threads performing nav data regeneration at a time.
Definition: navArea.h:115
DtNavRegenRequestIdData()
Definition: navArea.h:131
static const DtVariableBindingsList & nullVariableReference()
bool claimThread()
Definition: navArea.h:153
void setMaxThreads(unsigned maxThreads)
Definition: navArea.h:146
Definition: navBot.h:29
unsigned myUsedThreads
Definition: navArea.h:174
Definition: navArea.h:184
void setAttachedObject(DtVrfObject *object)
Definition: navArea.h:353
virtual bool navDataChanged()
Returns true if the nav data has changed during this query.
Definition: navArea.h:91
DtNavAreaConfig()
Definition: navArea.h:101
#define DT_DLL_vrfNavigation
This file is used to determine how to build.
Definition: vrfNavigationDefines.h:26
Configuration options for DtNavArea.
Definition: navArea.h:99
DtString status
Definition: navArea.h:189
virtual double outputValue()
Definition: navArea.h:75
DtNavTag navTag
Definition: navArea.h:197
Extended DtNavTag class that keep a local copy of myData.
Definition: navDataTag.h:77
virtual bool hadComputationError()
Definition: navArea.h:93
class DtLocalVertexList:
Definition: localVertexList.h:20
DtString navAreaName
Definition: navArea.h:186
std::vector< DtRwString > profiles
Definition: navArea.h:188
Used by the Debud Draw tool.
Definition: navArea.h:193
virtual std::vector< DtVector > results()
Definition: navArea.h:94
boost::weak_ptr< DtNavAreaQuery > WeakPtr
Definition: navArea.h:60
virtual bool complete()
Definition: navArea.h:87
Definition: navArea.h:56
unsigned myMaxThreads
Definition: navArea.h:173
unsigned maxThreads() const
Definition: navArea.h:151

Document ID: Generated on Tue Sep 21 17:42:52 EDT 2021 from SVN revision 234861
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)