VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtDynamicTerrainParser.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2025 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
17 
19 
20 #include <vlutil/vlString.h>
21 
22 #include <osg/Matrixd>
23 #include <osg/Group>
24 #include <unordered_map>
25 
26 #include <vector>
27 #include <stack>
28 #include <boost/thread/mutex.hpp>
29 
30 namespace osgSim
31 {
32  class MultiSwitch;
33 }
34 
35 namespace osg
36 {
37  class sequence;
38 }
39 
40 namespace makVrv
41 {
42  class DtDe;
43  class DtDynamicTerrainSequenceNode;
44 
66  {
67  public:
70 
73  typedef std::vector< osg::Vec3d > StateLocationList;
74 
77  typedef std::vector< DynamicTerrain::NodePathHash > StateIndexList;
78 
84  typedef std::vector<osg::ref_ptr< DtDynamicTerrainSwitchNode> > TerrainSwitchList;
86 
92  struct TupleHasher
93  {
94  std::size_t operator()( const std::tuple<unsigned int, std::string, std::string>& tuple ) const
95  {
96  std::size_t seed = 0;
97  boost::hash_combine( seed, std::get<0>( tuple ) ); // number of switch states
98  boost::hash_combine( seed, std::get<1>( tuple ) ); // optional switch comments
99  boost::hash_combine( seed, std::get<2>( tuple ) ); // dynamic terrain state ID
100  return seed;
101  }
102  };
103  using DtDamageStateMappings = std::unordered_map<std::tuple<unsigned int, std::string, std::string>, std::string, TupleHasher>;
105 
109  DtDynamicTerrainParser(DtDe& de, bool addInstances = true);
110 
116  DtDynamicTerrainParser(DtDe& de, DtDynamicTerrainWorld& world, DtModelSemanticsMapper& modelSematicsMapper, bool addInstances = true);
117 
118  private:
121 
122  public:
124  virtual ~DtDynamicTerrainParser();
125 
132  osg::Node& node,
133  const osg::Matrix& matrix = osg::Matrix::identity());
134 
138  osg::Node& node,
139  const osg::Matrix& matrix = osg::Matrix::identity());
140 
142  DtDynamicTerrainWorld::FeatureHandle featureHandle() const { return myFeatureHandles; }
143 
146  static std::string parserFormat();
147 
150  virtual void apply( osg::Group& group ) override;
151  virtual void apply( osgSim::MultiSwitch& multiswitch ) override;
152  virtual void apply( DtDynamicTerrainSwitchNode& terrainSwitch );
153  virtual void apply( osg::Sequence& sequence ) override;
154  virtual void apply( DtDynamicTerrainSequenceNode& terrainSequence );
156 
159  const StateLocationList& stateLocations() const;
160  void addStateLocation(const osg::Vec3d& vec);
161 
162  const TerrainSwitchList& terrainSwitches() const;
163  void addTerrainSwitch( DtDynamicTerrainSwitchNode* tSwitch );
164 
165  const StateIndexList& stateIndices() const;
166  void addStateIndex( DynamicTerrain::NodePathHash index );
168 
170  const DtDamageStateMappings& getDamageStateMappings() const;
171  protected:
176  virtual void runVisitor(osg::Node&, const osg::Matrix&);
177 
182  virtual bool parseSwitchNames( const std::string& desc,
183  osgSim::MultiSwitch& multiswitch, std::list<DtString>& stateNames );
184 
189  virtual bool parseSwitchPosition(const std::string& desc,
190  osgSim::MultiSwitch& multiswitch, DtString& positionStr);
191 
194  virtual void parseSwitchValues( const osg::Node& node, std::list<DtString>& valueNames );
195  virtual void addSwitchValueFromMappings( unsigned int childCount,
196  std::list<DtString>& stateNames, std::list<DtString>& valueNames );
197 
200  virtual void parseValueListString( const std::string& valueList, std::list<DtString>& valueNames );
201 
202  virtual void pushSwitch( DtDynamicTerrainSwitchNode* switchNode );
203  virtual void popSwitch();
204  virtual DtDynamicTerrainSwitchNode* findCurrentSwitch() const;
205 
206  virtual void pushSwitchIndex( DynamicTerrain::NodePathHash index );
207  virtual void popSwitchIndex();
208  virtual DynamicTerrain::NodePathHash findCurrentSwitchIndex() const;
209 
210  virtual void pushSwitchChildCount( int child );
211  virtual void popSwitchChildCount();
212  virtual int findCurrentSwitchChildCount() const;
213  virtual void incrementSwitchChildCount();
214  virtual void decrementSwitchChildCount();
215  protected:
216 
218 
222  std::stack<std::string> myStateNames;
223  std::stack<osg::ref_ptr<DtDynamicTerrainSwitchNode> > myCurrentSwitchStack;
224  std::stack<DynamicTerrain::NodePathHash> myCurrentSwitchIndexStack;
226 
227  std::string mySwitchPosTag;
228 
229  // maps node's hash to it's parents hash
230  typedef std::unordered_map<DynamicTerrain::NodePathHash, DynamicTerrain::NodePathHash> ParentHashMap;
232 
234 
235  static boost::mutex theParserMutex;
236 
238 
240  };
241 
245  {
246  public:
247 
250  static void registerCreator(DtDe& de);
251 
254 
257 
259  virtual DtModelParser* create(DtDe& de);
260  };
261 
265  {
266  public:
267  static DtDynamicTerrainParserSettings& instance( DtDe& de );
268 
270  static DtDynamicTerrainParserSettings* instance( std::string appDataPath );
271 
274 
276  const DtDynamicTerrainParser::DtDamageStateMappings& getDamageStateMappings() const;
277 
279  const unsigned int& getNumberOfVrvDamageStates();
280  protected:
282  DtDynamicTerrainParserSettings( std::string appDataPath );
283 
285  virtual bool loadDamageStateMappings();
286  protected:
287  std::string myAppDataPath;
290  };
291 }
DtDynamicTerrainWorld & myWorld
Definition: DtDynamicTerrainParser.h:217
Implementation of the model parser for Dynamic Terrain The DtDynamicTerrainParser visits all the node...
Definition: DtDynamicTerrainParser.h:65
std::stack< std::string > myStateNames
Definition: DtDynamicTerrainParser.h:222
StateIndexList myStateIndexList
Definition: DtDynamicTerrainParser.h:220
Virtual base class. Allows for RTTI and proper virtual destruction. Used by Creators, Factories, Providers, Assemblers and User Interfaces.
Definition: DtVirtualBaseClass.h:19
std::vector< osg::ref_ptr< DtDynamicTerrainSwitchNode > > TerrainSwitchList
TerrainSwitchList defines a vector of all the dynamic terrain switches discovered. Note that there are many duplicates here. The transforms, nodePath hashes and terrain switches in these lists correspond one to one. So a hundred references to the same switch would result in a hundred different transforms in the transform list; a hundred different node path hashes, one for each reference; and then a hundred osg::ref_ptrs to the same underlying switch node used to manage those one hundred references.
Definition: DtDynamicTerrainParser.h:84
DtDynamicTerrainSwitchNode replaces an osgSim::multiswitch in a terrain patch (or page) that is tagge...
Definition: DtDynamicTerrainSwitchNode.h:74
size_t NodePathHash
Typedef used to represent a hash of an OSG Node path to a referenced node.
Definition: DtMultiReferencedNodeContainer.h:26
DtDynamicTerrainWorld::FeatureHandle myFeatureHandles
Definition: DtDynamicTerrainParser.h:233
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
Abstract base class used to parse a model.
Definition: DtModelParser.h:22
std::vector< DynamicTerrain::NodePathHash > StateIndexList
StateIndexList defines a vector of a NodePathHash values associated with each switch reference discov...
Definition: DtDynamicTerrainParser.h:77
DtDamageStateMappings is loaded from appData/importConfig/damage_state_mappings.csv The Key is a tupl...
Definition: DtDynamicTerrainParser.h:92
static boost::mutex theParserMutex
Definition: DtDynamicTerrainParser.h:235
std::vector< osg::Vec3d > StateLocationList
StateLocationList defines a vector of the world locations of each dynamic terrain switch reference di...
Definition: DtDynamicTerrainParser.h:73
std::stack< osg::ref_ptr< DtDynamicTerrainSwitchNode > > myCurrentSwitchStack
Definition: DtDynamicTerrainParser.h:223
const DtDynamicTerrainParser::DtDamageStateMappings & myDamageStateMappings
Definition: DtDynamicTerrainParser.h:239
std::unordered_map< DynamicTerrain::NodePathHash, DynamicTerrain::NodePathHash > ParentHashMap
Definition: DtDynamicTerrainParser.h:230
Contains makVrv::DtDynamicTerrainStateManipulatorFactory class.
unsigned int myNumberOfVrvDamageStates
Definition: DtDynamicTerrainParser.h:289
StateLocationList myStateLocationList
Definition: DtDynamicTerrainParser.h:219
Create an articulated model parser.
Definition: DtDynamicTerrainParser.h:244
DtDynamicTerrainParser::DtDamageStateMappings myDamageStateMappings
Definition: DtDynamicTerrainParser.h:288
Factory for creating objects which implement some kind of manipulation of the state of dynamically ch...
Definition: DtDynamicTerrainStateManipulatorFactory.h:64
std::stack< int > myCurrentSwitchChildCountStack
Definition: DtDynamicTerrainParser.h:225
std::size_t operator()(const std::tuple< unsigned int, std::string, std::string > &tuple) const
Definition: DtDynamicTerrainParser.h:94
ParentHashMap myParentHashMap
Definition: DtDynamicTerrainParser.h:231
std::string myAppDataPath
Definition: DtDynamicTerrainParser.h:287
bool myAddInstances
Definition: DtDynamicTerrainParser.h:237
Settings for DtDynamicTerrainParser Singleton so that settings can be shared across multiple parser i...
Definition: DtDynamicTerrainParser.h:264
DtDynamicTerrainWorld::FeatureHandle featureHandle() const
Accessor the handle to the features which have been paged in by calls to parse.
Definition: DtDynamicTerrainParser.h:142
Contains makVrv::DtArticulatedModelParser class.
DtDynamicTerrainSequenceNode replaces an osg::Sequence in a terrain patch (or page) that is tagged wi...
Definition: DtDynamicTerrainSequenceNode.h:62
Contains makVrv::DtDynamicTerrainWorld class.
std::unordered_map< std::tuple< unsigned int, std::string, std::string >, std::string, TupleHasher > DtDamageStateMappings
Definition: DtDynamicTerrainParser.h:103
Contains DLL export macros.
Feature Insertion/Removal/Paging Features represent parts of the terrain which are individually ident...
Definition: DtDynamicTerrainWorld.h:97
Contains makVrv::DtDynamicTerrainSwitchNode class.
The DtDe is the core component of any VR-Vantage application. It owns a DtRenderer, DtDeCommunicator, as well as a DtDisplay and other things.
Definition: DtDe.h:76
TerrainSwitchList myTerrainSwitchList
Definition: DtDynamicTerrainParser.h:221
An abstract creator class for the model parser.
Definition: DtModelParser.h:35
std::string mySwitchPosTag
Definition: DtDynamicTerrainParser.h:227
Container for dynamic terrain features, change requests, and queries.
Definition: DtDynamicTerrainWorld.h:69
The DtModelSemanticsMapper object is responsible for mapping Names of model semantics declarations (f...
Definition: DtModelSemanticsMapper.h:27
std::stack< DynamicTerrain::NodePathHash > myCurrentSwitchIndexStack
Definition: DtDynamicTerrainParser.h:224
Default implementation of the model parser for Articulated models.
Definition: DtArticulatedModelParser.h:38

Document ID: Generated on Thu Oct 15 21:27:02 EDT 2026 from SVN revision 296421
Copyright © 2005-2026 MAK Technologies. All Rights Reserved (www.mak.com)