VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
terrainSourcePager.h
Go to the documentation of this file.
1 /*******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 *******************************************************************************/
5 #pragma once
6 
9 
10 #include <string>
11 
12 #include <tbb/spin_rw_mutex.h>
13 #include <tbb/concurrent_queue.h>
14 #include <atomic>
15 
16 #include <osg/Node>
17 
22 
24 
26 
27 #include <boost/unordered_map.hpp>
28 #include <boost/optional.hpp>
29 
31 #include <boost/geometry.hpp>
32 #include <boost/geometry/geometries/point.hpp>
33 #include <boost/geometry/geometries/box.hpp>
34 
35 #include <boost/geometry/index/rtree.hpp>
36 
37 #include <map>
38 
42 #define DO_NOT_USE_CUTOUT_CACHE
43 
49 
50 typedef std::multimap<int, DtTerrainPagerCommand*> DtCommandPriorityMultimap;
51 
58 {
59 public:
60 
62  DtTerrainSourcePager(DtVantageTerrainEngine* terrainEngine, osgEarth::MapNode* mapNode);
63 
65  virtual ~DtTerrainSourcePager() override;
66 
68  virtual bool init();
69 
73  virtual void tick();
74 
77  virtual void setEarthFileName(const DtFilename& file);
78 
80  virtual void setCutoutFilename(const char* OptionalSuffixe=NULL);
81 
87  virtual bool isContainedWithinCutoutCache(const osgEarth::GeoExtent & extent, const osgEarth::TileKey & key);
88 
90  virtual DtTerrainSourceTracker* createTerrainSourceTracker(DtVantageTerrainEngine*) = 0;
91 
93  virtual DtTerrainSourceTracker* terrainSourceTracker();
94 
95  virtual void updatePageTracker(DtTerrainIntersectIDType intersectId = 0) = 0;
96 
100  virtual int highestPriorityPendingWork();
101 
104  virtual void processCommandQueue();
105 
109  virtual void setCurrentTime(const double& currentTime);
110 
112  virtual unsigned long numTriangles() const;
113 
114  virtual unsigned long numPendingCommands() const;
115  virtual std::map<int, unsigned long> numPendingCommandsByPriority() const;
116 
118  virtual bool quitFlagSet() const;
119 
121  virtual void setQuit(bool);
122 
124  virtual const Coordinate_System* localCS() const;
125 
127  virtual void setLabel(const DtString&);
128  virtual DtString label() const;
129 
130  virtual DtString type() const = 0;
131 
133  virtual unsigned queuePageReloadsWithinExtent(const osgEarth::GeoExtent & extent, const DtUUID& dynamicUuid, bool isRemoval = false);
134 
136  virtual void clearCutoutCache();
137 
139  virtual void clearTerrainEngineReference();
140 
141 protected:
143  {
144  public:
145  typedef boost::unordered_map<DtNodeId, TerrainRecord> Map;
146 
148  void pageOut();
149 
150  protected:
152  };
153 
155  {
156  public:
157  DynamicTerrainNode(const DtUUID& dynamicTerrainUUID, const osgEarth::GeoExtent& extent);
158  DynamicTerrainNode(const DynamicTerrainNode & clone);
159  DynamicTerrainNode& operator=(const DynamicTerrainNode& rhs);
160 
161  void setGeoExent(const osgEarth::GeoExtent& extent);
162  const osgEarth::GeoExtent& geoExtent() const;
163 
164  void setUUID(const DtUUID& dynamicTerrainUUID);
165  const DtUUID& uuid() const;
166 
167  protected:
168  osgEarth::GeoExtent myExtent;
170 
171  };
172 
173  typedef boost::geometry::model::point<double, 2, boost::geometry::cs::geographic<boost::geometry::degree> > DtDynamicTerrainRtreeCoord;
174  typedef boost::geometry::model::box<DtDynamicTerrainRtreeCoord> DtDynamicTerrainRtreeBox;
175  typedef std::pair<DtDynamicTerrainRtreeBox, std::shared_ptr<DynamicTerrainNode> > DtDynamicTerrainRtreeValue;
176 
177  typedef boost::geometry::index::rtree<DtDynamicTerrainRtreeValue, boost::geometry::index::quadratic<16> > DtDynamicTerrainRtree;
178 
179 
181  {
182  public:
185  DtPendingTileKeyReload(const osgEarth::TileKey & key, bool isRemoval, unsigned count = 1);
186  bool operator<(const DtPendingTileKeyReload & rhs) const;
187  bool operator==(const DtPendingTileKeyReload & rhs) const;
188  bool operator!=(const DtPendingTileKeyReload & rhs) const;
189  DtPendingTileKeyReload & operator=(const DtPendingTileKeyReload & rhs);
190 
192  osgEarth::TileKey myTileKey;
193  };
194 
195  typedef std::set<DtPendingTileKeyReload> DtPendingTileKeyReloadSet;
196 
198  virtual unsigned int addTerrain(const osg::ref_ptr<osg::Node>& node, DtVrfSimTerrainProcessor&,
199  const char* debugWhoisCalling = "unknown", const char* defaulSoilType = "");
200 
202  virtual unsigned int removeTerrain(const osg::ref_ptr<osg::Node>& node, const char* debugWhoisCalling = "unknown");
203 
205  virtual void addTriangles(unsigned int, const char* debugString="unknown");
206 
208  virtual void removeTriangles(unsigned int, const char* debugString = "unknown");
209 
214  void modifyDynamicTerrainExtent(const DtPoint & swCorner, const DtPoint & neCorner, bool isRemoval, unsigned amount = 1);
215 
220  bool hasDynamicTerrainWithinExtent(const DtPoint & swCorner, const DtPoint& neCorner) const;
221 
222  bool modifyDynamicTerrain(const osgEarth::GeoExtent& dynamicTerrainExtent, const DtUUID& dynamicTerrainUUID, bool isRemoval);
223  bool hasDynamicTerrainWithinExtent(std::vector<DtDynamicTerrainRtreeValue> & values, const osgEarth::GeoExtent & extent);
224 
226  void eraseCommand(DtCommandPriorityMultimap::iterator& itr);
228  void eraseAndInsertCommand(DtCommandPriorityMultimap::iterator& itr);
230  bool getFirsCommand(DtCommandPriorityMultimap::iterator& itrToProcess);
231 
233  typedef tbb::spin_rw_mutex Mutex;
234  mutable Mutex myMutex;
235  static tbb::spin_rw_mutex myMultiMapMutex;
236 
239 
241  std::atomic<bool> myQuitFlag;
242 
246 
249 
254 
257 
261 
263  unsigned long myNumTriangles;
264 
265  tbb::spin_mutex myTerrainRecordsMutex;
267 
268  boost::optional<short int> myDefaultBulletObjectMask;
269 
271  osgEarth::MapNode* myMapNode;
272  const osgEarth::Map* myMap;
273  const osgEarth::Profile* myMapProfile;
274 
276  DtFilename myEarthFile;
277 
282  const std::unique_ptr<DtCutoutCache> myCutoutCache;
283 
285  mutable tbb::spin_rw_mutex myPagedInTilesMapMutex;
286 
289 
291  mutable tbb::spin_rw_mutex myTileKeysForReloadMutex;
294 
296  mutable tbb::spin_rw_mutex myDynamicTerrainRtreeMutex;
298 
300 
301  std::set<osgEarth::TileKey> mySetOfTileKeysToReload;
302 
304  std::string myDefaultSoilType;
305 };
UUID is a unique ID wrapper class.
Definition: uuid.h:59
boost::geometry::model::point< double, 2, boost::geometry::cs::geographic< boost::geometry::degree > > DtDynamicTerrainRtreeCoord
Definition: terrainSourcePager.h:173
Class DtTerrainInterfaceConfig is a readable-writable class holding terrain interface configuration o...
Definition: terrainInterfaceConfig.h:33
DtFilename myEarthFile
Path to earth file that was used to load this elevation source.
Definition: terrainSourcePager.h:276
osgEarth::TileKey myTileKey
Definition: terrainSourcePager.h:192
DtTerrainSourcePager is the base class for terrain pagers. There will be one terrainSourcePager per t...
Definition: terrainSourcePager.h:56
std::set< DtPendingTileKeyReload > DtPendingTileKeyReloadSet
Definition: terrainSourcePager.h:195
std::multimap< int, DtTerrainPagerCommand * > DtCommandPriorityMultimap
Definition: terrainSourcePager.h:48
This class keeps track of what parts of the terrain database are currently paged in and what ones are...
Definition: activePageTracker.h:38
boost::unordered_map< DtNodeId, TerrainRecord > Map
Definition: terrainSourcePager.h:145
std::pair< DtDynamicTerrainRtreeBox, std::shared_ptr< DynamicTerrainNode > > DtDynamicTerrainRtreeValue
Definition: terrainSourcePager.h:175
TerrainRecord::Map myTerrainRecords
Definition: terrainSourcePager.h:266
DtPendingTileKeyReloadSet myTileKeysForReload
Definition: terrainSourcePager.h:293
Mutex myMutex
Definition: terrainSourcePager.h:234
DT_DLL_terrainCS bool operator==(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
unsigned long long DtTerrainIntersectIDType
Definition: terrainInterfaceDefines.h:28
boost::geometry::index::rtree< DtDynamicTerrainRtreeValue, boost::geometry::index::quadratic< 16 > > DtDynamicTerrainRtree
Definition: terrainSourcePager.h:177
DtUUID myUuid
Definition: terrainSourcePager.h:169
tbb::spin_rw_mutex myTileKeysForReloadMutex
Definition: terrainSourcePager.h:291
makVrv::DtDynamicTerrainWorld::FeatureHandle myFeatures
Definition: terrainSourcePager.h:151
tbb::concurrent_queue< DtTerrainPagerCommand * > DtPagerCommandQueue
Definition: vantageTerrainImplementationUtil.h:42
tbb::spin_rw_mutex myDynamicTerrainRtreeMutex
Definition: terrainSourcePager.h:296
const std::unique_ptr< DtCutoutCache > myCutoutCache
Cache for storing mask cutout areas and skirt geometry. Creating the cutout masks (areas of the eleva...
Definition: terrainSourcePager.h:282
DtVantageTerrainEngine * myTerrainEngine
Pointer to the terrain implementation&#39;s terrain engine. This class does not own the terrain engine...
Definition: terrainSourcePager.h:245
DtDynamicTerrainRtree myDynamicTerrainRtree
Definition: terrainSourcePager.h:299
std::set< osgEarth::TileKey > mySetOfTileKeysToReload
Definition: terrainSourcePager.h:301
Definition: coordSystem.h:54
Definition: terrainSourcePager.h:154
double myCurrentTime
Time to compare a command&#39;s expire time to before executing the command. If the command&#39;s expire time...
Definition: terrainSourcePager.h:253
std::map< osgEarth::TileKey, std::shared_ptr< DtTileData > > DtTerrainTileMap
Definition: tileData.h:342
Definition: terrainSourcePager.h:142
tbb::spin_mutex myTerrainRecordsMutex
Definition: terrainSourcePager.h:265
Base class for Terrain Source trackers. Determines if the necessary data To perform an intersection i...
Definition: terrainSourceTracker.h:75
bool myIsRemoval
Definition: terrainSourcePager.h:191
std::atomic< bool > myQuitFlag
Set when the paging should stop.
Definition: terrainSourcePager.h:241
tbb::spin_rw_mutex myPagedInTilesMapMutex
Mutex for page in map.
Definition: terrainSourcePager.h:285
tbb::spin_rw_mutex Mutex
Definition: terrainSourcePager.h:233
DtCommandPriorityMultimap myPriorityCommandMultimap
Multimap of priorities to paging commands. Commands are taken off the queue and put here until they a...
Definition: terrainSourcePager.h:260
unsigned long myNumTriangles
Number of triangles paged in to this pager.
Definition: terrainSourcePager.h:263
const osgEarth::Profile * myMapProfile
Definition: terrainSourcePager.h:273
#define DT_DLL_vantageTerrainImplementation
This file is used to determine how to build.
Definition: vantageTerrainImplementationDefines.h:28
osgEarth::MapNode * myMapNode
Map node.
Definition: terrainSourcePager.h:271
DT_DLL_DEBUGDRAWRENDERER void init(makVrv::DtDe &de)
Work function for the plugin initialization.
Contains makVrv::DtDynamicTerrainWorld class.
Note: The implementation of this processor class can be found in osgToBullet.cxx (class called DtVrfS...
Definition: osgToBullet.h:281
Definition: terrainSourcePager.h:180
Feature Insertion/Removal/Paging Features represent parts of the terrain which are individually ident...
Definition: DtDynamicTerrainWorld.h:97
const osgEarth::Map * myMap
Definition: terrainSourcePager.h:272
DT_DLL_terrainCS bool operator!=(const DtDegMinSec &lhs, const DtDegMinSec &rhs)
boost::geometry::model::box< DtDynamicTerrainRtreeCoord > DtDynamicTerrainRtreeBox
Definition: terrainSourcePager.h:174
DtTerrainTileMap myPagedInTilesMap
Map of tileIds to terrainTiles.
Definition: terrainSourcePager.h:288
This class wraps the VR-Vantage Display Engine, and uses as a terrain loader and intersector. This is the terrain engine that powers the DtVantageTerrainImplementation. The DtVantageTerrainEngine runs the DtDe it its own thread, and processes commands thought the command queue.
Definition: vantageTerrainEngine.h:112
osgEarth::GeoExtent myExtent
Definition: terrainSourcePager.h:168
DtPagerCommandQueue myCommandQueue
Thread-safe queue to put commands on.
Definition: terrainSourcePager.h:256
DtTerrainSourceTracker * myTerrainSourceTracker
The terrain source tracker that is updated by this pager.
Definition: terrainSourcePager.h:248
static tbb::spin_rw_mutex myMultiMapMutex
Definition: terrainSourcePager.h:235
std::string myDefaultSoilType
Default soil type to use when none is found with the model/textures/texture name. ...
Definition: terrainSourcePager.h:304
Definition: point.h:34
DtString myName
Definition: terrainSourcePager.h:238
boost::optional< short int > myDefaultBulletObjectMask
Definition: terrainSourcePager.h:268

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)