VR-Forces 5.0.1 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
aStarGraph.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2012 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 
9 
10 #pragma once
11 
14 #include <features/pathFeature.h>
17 
18 #include <vrfutil/asyncJob.h>
19 #include <vrfutil/kinematicTools.h>
20 #include <vrfutil/railSegment.h>
22 
23 #include <boost/graph/adjacency_list.hpp>
24 #include <boost/graph/properties.hpp>
25 #include <boost/graph/graph_traits.hpp>
26 #include <boost/function.hpp>
27 #include <boost/unordered_set.hpp>
28 
29 #include <tbb/queuing_mutex.h>
30 #include <tbb/queuing_rw_mutex.h>
31 #include <tbb/atomic.h>
32 #include <tbb/compat/condition_variable>
33 #include <tbb/mutex.h>
34 
35 #include <list>
36 #include <map>
37 
38 namespace MAKVRinTerra
39 {
40  class DtAStarGraphDebugger;
41 
42  //Properties of each vertex
44  {
45  explicit VertexInfo();
46  explicit VertexInfo(const DtPoint& point);
47 
49 
50  //DtFeatureGeometry::Point geometry() const;
51  };
52 
53  //Properties on each edge
55  {
56  explicit EdgeInfo(const DtPathFeature& p, const DtFeatureGeometry::Path&);
57  explicit EdgeInfo(const DtPathFeature::CPtr& p, const DtFeatureGeometry::Path&);
58 
59  typedef std::vector<DtPathFeature::CPtr> FeatureVector;
60 
61  DtFeatureGeometry::Path edgeGeometry() const;
62  double distance() const;
63  double width() const;
64  bool isOneway() const;
65  bool isDeleted() const;
66  FeatureVector features() const;
67  DtPathFeature::CPtr firstValidFeature() const;
68  void addFeature(const DtPathFeature::CPtr&);
69  size_t hash() const;
70 
71  private:
72  friend class DtAStarGraph;
73  struct Data;
74 
75  boost::shared_ptr<Data> myData;
76  };
77 
78  //DtAStarGraph processes path features to make a graph for path planning.
80  {
81  class BoostGraphVisitor;
82  friend class BoostGraphVisitor;
83 
87 
88  public:
89  typedef boost::shared_ptr<DtAStarGraph> Ptr;
90 
91  Ptr shared_from_this();
92 
93  typedef boost::adjacency_list< //graph is adjacency list (vs adjacency matrix)
94  boost::setS, //per-vertex edge-list is a set
95  boost::vecS, //graph's vertex-list is a vector
96  boost::directedS, //graph is directed
97  VertexInfo, //VertexInfo struct is property on edges
98  EdgeInfo, //EdgeInfo struct is property on edges
99  boost::no_property, //no property on graph
100  boost::vecS> //graph's edge-list is a vector
102 
103  typedef boost::graph_traits<DtBoostGraph> GraphTraits;
104 
105  typedef DtBoostGraph::vertex_descriptor vertex_descriptor;
106  typedef DtBoostGraph::edge_descriptor edge_descriptor;
107 
108  typedef GraphTraits::vertex_iterator vertex_iterator;
109  typedef GraphTraits::edge_iterator edge_iterator;
110 
111  typedef std::list<vertex_descriptor> VertexList;
112 
113  //Weight is a property on edges.
114  typedef boost::property<boost::edge_weight_t, double> Weight;
115 
121  {
122  typedef std::list<PathVertex> List;
123 
124  static double Distance(const List&);
125 
126  explicit PathVertex(
127  const DtPoint& l,
128  vertex_descriptor v = GraphTraits::null_vertex(),
130 
134  };
135 
137  {
138  typedef std::list<MultiPathVertex> List;
139 
140  explicit MultiPathVertex(
141  const DtPoint& l,
142  vertex_descriptor v = GraphTraits::null_vertex(),
144 
145  explicit MultiPathVertex(const PathVertex&);
146 
147  PathVertex::List getSinglePath() const;
148  void addPath(PathVertex::List::const_iterator, PathVertex::List::const_iterator);
149  void addPathToFront(const PathVertex::List&);
150  void addPathToEnd(PathVertex::List::const_iterator, PathVertex::List::const_iterator);
151  void addPathToEnd(const MultiPathVertex&);
152 
155  };
156 
158  {
159  public:
160  typedef std::vector<Path> Sequence;
161 
162  explicit Path(const std::string& = std::string());
163 
164  PathVertex::List getSinglePath() const;
165  void addPath(const PathVertex::List&);
166  void addPath(const MultiPathVertex::List&);
167  void addPath(const Path&);
168  void addPathToFront(const PathVertex::List&);
169  void addPathToEnd(const PathVertex::List&);
170 
171  bool empty() const { return myPathVertices.empty(); }
172  size_t numPaths() const { return myPathVertices.size(); }
173 
174  std::string description() const { return myDescription; }
175 
176  const MultiPathVertex::List& pathVertices() const { return myPathVertices; }
177  MultiPathVertex::List& pathVertices() { return myPathVertices; }
178 
179  private:
181  std::string myDescription;
182  };
183 
184  template <typename T>
186 
188 
189  typedef std::pair<DtQuery, double> DtWeightFactor;
190  typedef std::list<DtWeightFactor> DtWeightFactorsList;
191 
192  typedef boost::function<double (edge_descriptor)> EdgeWeightAdjustor;
193 
194  typedef boost::function<bool ()> CancelCheck;
195 
197  static DtRailSegmentList* DtPath2RailSegmentList(const Path& path);
198 
199  static Ptr Make(
200  std::auto_ptr<DtFeatureSet> input,
201  DtProj::CPtr localProj,
202  const DtTerrainInterfaceConfig& config,
203  std::string label = std::string());
204 
205  virtual ~DtAStarGraph();
206 
207  virtual void shutdown();
208  virtual bool isShutdown() const;
209 
220  Path makePath(
221  const DtPoint& startLocation,
222  const DtPoint& endLocation,
223  double maxSearchRadius,
224  double startProximityThreshold,
225  double stopProximityThreshold,
226  const DtWeightFactorsList& weightFactors,
227  const CancelCheck& cancelCheck);
228 
229  struct Results;
230 
232  {
235  boost::optional<DtFeatureGeometry::Area> searchArea;
240 
242  const DtFeatureGeometry::Point& start,
243  const DtFeatureGeometry::Point& end);
244 
245  void setMaxSearchRadius(double radius);
246  void setSearchRadius(double maxRadius, double minRadius);
247 
248  bool cancel() const;
249  };
250 
251  Path makePath(
252  SearchParameters params,
253  Results* results = 0,
254  unsigned recursionLevel = 0);
255 
258  bool onPathFeature(const DtPoint& location, double offset = 0.5);
259 
260  std::auto_ptr<DtPathFeatureSet> paths() const;
261 
262  const DtFeatureSet& inputFeatureSet() const;
263 
264  DtProj::CPtr localProj() const;
265 
275  DtClosestPathFeatureFinder closestFeatureOnNetwork(
276  const DtPoint& startingLocation,
277  const double& searchRadius,
278  bool* dataAvailable = NULL);
279 
280  std::string label() const;
281 
282  virtual DtFeaturesDebugger::Record& addToDebugger(DtFeaturesDebugger&);
283 
285  void addFeatureToGraph(
286  const DtFeature & r,
287  bool joinToIntersectingEdges,
288  const boost::optional<DtFeatureGeometry>& searchArea = boost::none);
289 
290  void addFeatureToGraph(
291  const DtFeature&,
292  const boost::optional<DtFeatureGeometry>& searchArea = boost::none);
293 
294  void addGeometryToGraph(DtFeatureGeometry g);
295 
296  bool loadTile(const DtPoint& localLocation, double timeout = 0);
297  bool loadTile(const DtFeatureGeometry& geom, double timeout = 0);
298  bool loadTileAndBlock(
299  const DtPoint& localLocation, const CancelCheck& = CancelCheck());
300  bool loadTileAndBlock(
301  const DtFeatureGeometry& geom, const CancelCheck& = CancelCheck());
302 
303  protected:
304  DtAStarGraph(
305  std::auto_ptr<DtFeatureSet> input,
306  DtProj::CPtr localProj,
307  const DtTerrainInterfaceConfig& config,
308  std::string label);
309 
311  boost::scoped_ptr<DtFeatureSet> myInputFeatureSet;
312 
315 
316  typedef tbb::queuing_rw_mutex GraphMutex;
317 
320 
323 
324  struct GridTile : public boost::enable_shared_from_this<GridTile>
325  {
326  typedef boost::shared_ptr<GridTile> Ptr;
327  typedef std::vector<Ptr> PtrVector;
328 
329  struct EdgeRecord
330  {
331  struct Hash
332  {
333  size_t operator()(const EdgeRecord& edge) const;
334  };
335 
336  bool operator==(const EdgeRecord& other) const;
337 
340 
341  explicit EdgeRecord(edge_descriptor, const EdgeInfo&);
342  };
343 
345  typedef std::vector<EdgeRecord> EdgeSet;
346  //typedef boost::unordered_set<EdgeRecord, EdgeRecord::Hash> EdgeSet;
347 
349  const unsigned level;
350  const unsigned maxLevel;
352 
353  explicit GridTile(const GridTile& parent, unsigned x, unsigned y);
354  explicit GridTile(DtAStarGraph&, const DtProj::Bounds&, unsigned maxLevel);
355 
356  ~GridTile();
357 
358  bool load(const DtFeatureGeometry&, double timeout);
359  void find(const DtFeatureGeometry&, PtrVector&);
360  void getTiles(PtrVector&);
361 
362  void addEdge(edge_descriptor, const EdgeInfo&);
363  void getEdges(const DtFeatureGeometry&, EdgeSet&);
364  void getEdgesWithWidth(const DtFeatureGeometry&, EdgeSet&);
365 
366  private:
367  void loadAndGet();
368  bool loaded(double timeout) const;
369 
371 
372  typedef tbb::mutex LoadingMutex;
373 
375  enum State { None, Loading, Done, Error };
376  tbb::atomic<State> state;
377 
378  typedef tbb::queuing_rw_mutex Mutex;
379 
380  mutable Mutex mutex;
383  boost::shared_ptr<GridTile> subtiles[2][2];
384 
385  mutable Mutex edgesMutex;
387  };
388 
389  friend struct GridTile;
390 
393 
395 
396  tbb::atomic<bool> myShutdownFlag;
397 
398  std::string myLabel;
399  };
400 
401  template <typename T>
403  {
404  typedef std::vector<T> Sequence;
405 
406  static T CreateDefault(T def, size_t) { return def; }
407 
408  public:
409  typedef size_t key_type;
410  typedef typename Sequence::value_type value_type;
411  typedef typename Sequence::reference reference;
412  typedef boost::lvalue_property_map_tag category;
413 
414  typedef boost::function<T (size_t)> DefaultFactory;
415 
416  explicit DynamicPropertyMap(const DefaultFactory& def, size_t size = 0)
417  : myDefaultFactory(def)
418  , myValues(new Sequence(size))
419  {
420  for (size_t i=0; i != size; ++i)
421  (*myValues)[i] = myDefaultFactory(i);
422  }
423 
424  explicit DynamicPropertyMap(T def, size_t size = 0)
425  : myDefaultFactory(boost::bind(&CreateDefault, def, _1))
426  , myValues(new Sequence(size, def))
427  {
428  }
429 
430  T& operator[](size_t index)
431  {
432  while (index >= size())
433  myValues->push_back(myDefaultFactory(index));
434 
435  return (*myValues)[index];
436  }
437 
438  T& operator[](size_t index) const
439  {
440  while (index >= size())
441  myValues->push_back(myDefaultFactory(index));
442 
443  return (*myValues)[index];
444  }
445 
446  size_t size() const
447  {
448  return myValues->size();
449  }
450 
451  void clear()
452  {
453  myValues->clear();
454  }
455 
456  private:
458  boost::shared_ptr<Sequence> myValues;
459  };
460 
461  template <typename T>
462  T get(const DtAStarGraph::DynamicPropertyMap<T>& map, size_t index)
463  {
464  return map[index];
465  }
466 
472 
473  template <typename T>
474  void put(DtAStarGraph::DynamicPropertyMap<T>& map, size_t index, const T& value)
475  {
476  map[index] = value;
477  }
478 
484 
486  {
487  public:
489  };
490 
492  {
493  public:
495  const DtAStarGraph::Ptr& pathFinder,
496  const DtPoint& localStart,
497  const DtPoint& localDestination,
498  double maxSearchRadius,
499  double startProximityThreshold,
500  double stopProximityThreshold,
501  const DtAStarGraph::DtWeightFactorsList& factors);
502 
503  task* onExecute();
504  task* onException();
505 
506  public:
514  };
515 }
516 
Represents a set of DtFeature objects or others which conform to the DtFeature concept.
Definition: featureSet.h:101
Concrete job class which manages a weak pointer to it&#39;s job map entry. Using this job will require th...
Definition: asyncJob.h:92
double startProximityThreshold
Definition: aStarGraph.h:236
State
Definition: aStarGraph.h:375
GraphTraits::edge_iterator edge_iterator
Definition: aStarGraph.h:109
#define DT_DLL_features
stop complaining about multiple independent base classes for boost::noncopyable this should probably ...
Definition: featuresDefines.h:41
Mutex edgesMutex
Definition: aStarGraph.h:385
DtFeatureGeometry::Point endPoint
Definition: aStarGraph.h:234
Class DtTerrainInterfaceConfig is a readable-writable class holding terrain interface configuration o...
Definition: terrainInterfaceConfig.h:32
boost::graph_traits< DtBoostGraph > GraphTraits
Definition: aStarGraph.h:103
Definition: aStarGraph.h:491
const DtProj::Bounds bounds
Definition: aStarGraph.h:348
DtFeatureGeometry::Point startPoint
Definition: aStarGraph.h:233
boost::function< void()> DetachCallback
Callback type for disconnecting other callbacks. Functions which register callbacks return a DetachCa...
Definition: featureSet.h:125
FeaturePtr addFeatureRef(const Feature &f)
Definition: featureSetUtils.h:308
boost::shared_ptr< Sequence > myValues
Definition: aStarGraph.h:458
Definition: aStarGraph.h:54
tbb::atomic< bool > myShutdownFlag
Definition: aStarGraph.h:396
std::list< PathVertex > List
Definition: aStarGraph.h:122
std::list< DtRailSegment * > DtRailSegmentList
Definition: railSegment.h:197
DtBoostGraph myGraph
Boost graph for path planning.
Definition: aStarGraph.h:322
Mutex mutex
Definition: aStarGraph.h:380
std::vector< Path > Sequence
Definition: aStarGraph.h:160
boost::lvalue_property_map_tag category
Definition: aStarGraph.h:412
DynamicPropertyMap(T def, size_t size=0)
Definition: aStarGraph.h:424
DtAStarGraph & graph
Definition: aStarGraph.h:370
EdgeSet edges
Definition: aStarGraph.h:386
void put(DtAStarGraph::DynamicPropertyMap< T > &map, size_t index, const T &value)
template &lt;typename t&gt;=&quot;&quot;&gt; T get(const DtAStarGraph::DynamicPropertyMap&lt;T&gt;* map, size_t index) { retur...
Definition: aStarGraph.h:474
Vertex data passed back from makePath. location is the location of the current vertex in local coordi...
Definition: aStarGraph.h:120
tbb::mutex LoadingMutex
Definition: aStarGraph.h:372
voidpf void uLong size
Definition: ioapi.h:39
GraphTraits::vertex_iterator vertex_iterator
Definition: aStarGraph.h:108
FeaturePtr addFeature(Feature *f)
these functions make it easier to take the address of addFeature
Definition: featureSetUtils.h:306
edge_descriptor descriptor
Definition: aStarGraph.h:338
tbb::queuing_rw_mutex GraphMutex
Definition: aStarGraph.h:316
double stopProximityThreshold
Definition: aStarGraph.h:237
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
MultiPathVertex::List myPathVertices
Definition: aStarGraph.h:180
boost::shared_ptr< DtAStarGraph > Ptr
Definition: aStarGraph.h:89
List nextVertices
Definition: aStarGraph.h:154
Definition: featureGeometry.h:60
virtual FeaturePtr addFeaturePtr(Feature *feature)
These functions are used to add features to the feature sets. The argument is the feature being added...
Definition: proj.h:68
Definition: featureSet.h:60
DtProj::CPtr myLocalProj
For converting local coordinates passed in from the user.
Definition: aStarGraph.h:314
Definition: aStarGraph.h:79
boost::function< bool()> CancelCheck
Definition: aStarGraph.h:194
double myStartProximityThreshold
Definition: aStarGraph.h:511
std::list< DtWeightFactor > DtWeightFactorsList
Definition: aStarGraph.h:190
Entry for a feature set in the debugger.
Definition: featuresDebugger.h:55
EdgeInfo info
Definition: aStarGraph.h:339
size_t size() const
Definition: aStarGraph.h:446
std::list< vertex_descriptor > VertexList
Definition: aStarGraph.h:111
MAKVRinTerra::DtAStarGraph::Path path
Definition: aStarGraph.h:488
DtPoint localLocation
Definition: aStarGraph.h:131
std::string description() const
Definition: aStarGraph.h:174
DtWeightFactorsList weightFactors
Definition: aStarGraph.h:238
DtTerrainInterfaceConfig myTerrainInterfaceConfig
Definition: aStarGraph.h:394
std::string myLabel
Definition: aStarGraph.h:398
Handle< PointType > Point
Definition: featureGeometry.h:69
Definition: aStarGraph.h:157
DT_DLL_VRVCORE double distance(const makVrv::DtCoordinateSystem &, const DtVector &from, const DtVector &to)
Returns the distance from the two points. Coordinates are in local database coordinates The coordinat...
binderNoArgs< _Fn > bind(const _Fn &_Func, const _Ty &_Left)
Definition: DtSTLUtilities.h:76
const unsigned level
Definition: aStarGraph.h:349
Sequence::reference reference
Definition: aStarGraph.h:411
boost::shared_ptr< const DtPathFeature > CPtr
Definition: pathFeature.h:21
DtPoint myLocalStart
Definition: aStarGraph.h:508
Definition: aStarGraph.h:43
Definition: aStarGraph.h:324
boost::shared_ptr< GridTile > Ptr
Definition: aStarGraph.h:326
DefaultFactory myDefaultFactory
Definition: aStarGraph.h:457
MultiPathVertex::List & pathVertices()
Definition: aStarGraph.h:177
boost::shared_ptr< const DtProj > CPtr
Definition: proj.h:48
Handle< PathType > Path
Definition: featureGeometry.h:70
DtBoostGraph::edge_descriptor edge_descriptor
Definition: aStarGraph.h:106
size_t key_type
Definition: aStarGraph.h:409
Base class for result of job.
Definition: asyncJobServer.h:43
const unsigned maxLevel
Definition: aStarGraph.h:350
template &lt;typename t&gt;=&quot;&quot;&gt; void put(DtAStarGraph::DynamicPropertyMap&lt;T&gt;* map, size_t index...
Definition: aStarGraph.h:485
DtPathFeature::CPtr nextEdgeFeature
Definition: aStarGraph.h:133
boost::optional< DtFeatureGeometry::Area > searchArea
Definition: aStarGraph.h:235
std::vector< Ptr > PtrVector
Definition: aStarGraph.h:327
std::vector< DtPathFeature::CPtr > FeatureVector
Definition: aStarGraph.h:59
DtPoint myLocalDestination
Definition: aStarGraph.h:509
void clear()
Definition: aStarGraph.h:451
LoadingMutex loadingMutex
Definition: aStarGraph.h:374
Definition: pathFeature.h:106
double myStopProximityThreshold
Definition: aStarGraph.h:512
boost::function< T(size_t)> DefaultFactory
Definition: aStarGraph.h:414
Definition: pathFeature.h:17
const MultiPathVertex::List & pathVertices() const
Definition: aStarGraph.h:176
double myMaxSearchRadius
Definition: aStarGraph.h:510
DynamicPropertyMap(const DefaultFactory &def, size_t size=0)
Definition: aStarGraph.h:416
boost::shared_ptr< Data > myData
Definition: aStarGraph.h:73
Source feature sets are used to create your own feature sets with your own features.
Definition: featureSetUtils.h:286
std::vector< EdgeRecord > EdgeSet
fixme change to unordered set
Definition: aStarGraph.h:345
boost::function< double(edge_descriptor)> EdgeWeightAdjustor
Definition: aStarGraph.h:192
boost::scoped_ptr< DtFeatureSet > myInputFeatureSet
Feature source for this graph.
Definition: aStarGraph.h:311
DynamicPropertyMap< unsigned > VertexBoolMap
Definition: aStarGraph.h:185
const DtFeatureGeometry::Area geometry
Definition: aStarGraph.h:351
GraphMutex myGraphMutex
Synchronize access to boost graph.
Definition: aStarGraph.h:319
DtPoint location
Definition: aStarGraph.h:48
T & operator[](size_t index)
Definition: aStarGraph.h:430
Sequence::value_type value_type
Definition: aStarGraph.h:410
tbb::queuing_rw_mutex Mutex
Definition: aStarGraph.h:378
vertex_descriptor vertex
Definition: aStarGraph.h:132
PathVertex pathVertex
Definition: aStarGraph.h:153
T & operator[](size_t index) const
Definition: aStarGraph.h:438
Represents a GIS feature. Features consist of a DtFeatureGeometry (2.5D geometric vector data) and a ...
Definition: feature.h:37
bool empty() const
Definition: aStarGraph.h:171
Definition: featuresDebugger.h:33
std::list< MultiPathVertex > List
Definition: aStarGraph.h:138
voidpf uLong offset
Definition: ioapi.h:42
std::pair< DtQuery, double > DtWeightFactor
Definition: aStarGraph.h:189
DtAStarGraph::Ptr myPathFinder
Definition: aStarGraph.h:507
GridTile::Ptr myLoadedTiles
Used to track which tiles are loaded.
Definition: aStarGraph.h:392
std::string myDescription
Definition: aStarGraph.h:181
std::vector< T > Sequence
Definition: aStarGraph.h:404
static T CreateDefault(T def, size_t)
Definition: aStarGraph.h:406
Represents a feature geometry.
Definition: featureGeometry.h:39
size_t numPaths() const
Definition: aStarGraph.h:172
Definition: point.h:34
DtAStarGraph::DtWeightFactorsList myWeightFactors
Definition: aStarGraph.h:513
boost::property< boost::edge_weight_t, double > Weight
Definition: aStarGraph.h:114
DtFeatureSetWrapper< DtFeatureSet, boost::shared_ptr > featureSet
Definition: aStarGraph.h:381
DtFeatureSet::DetachCallback detacher
Definition: aStarGraph.h:382
CancelCheck cancelCheck
Definition: aStarGraph.h:239
boost::adjacency_list< boost::setS, boost::vecS, boost::directedS, VertexInfo, EdgeInfo, boost::no_property, boost::vecS > DtBoostGraph
Definition: aStarGraph.h:101
tbb::atomic< State > state
Definition: aStarGraph.h:376
DtBoostGraph::vertex_descriptor vertex_descriptor
Definition: aStarGraph.h:105

Document ID: Generated on Mon Jun 20 00:38:30 EDT 2022 from SVN revision 244029
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)