VR-Forces Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtOsgIndirectEntityManager.h
Go to the documentation of this file.
1 /*****************************************************************************
2  * Copyright (c) 2026 MAK Technologies, Inc.
3  * All rights reserved.
4  *****************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvOsg/vrvOsg.h>
13 
20 
24 #include <vrvMath/DtVector3.h>
25 
26 #include <vrvCore/DtUniqueID.h>
28 
29 #include <matrix/vlVector.h>
30 #include <matrix/vlTaitBryan.h>
31 
32 #include <boost/thread.hpp>
33 
34 #include <unordered_map>
35 #include <tuple>
36 #include <unordered_set>
37 #include <vector>
38 
39 #include <tbb/concurrent_hash_map.h>
40 
41 namespace osg
42 {
43  class StateSet;
44 }
45 
46 namespace makVrv
47 {
48  class DtIndirectModelsContainer;
49  class DtModelDefinition;
50  class DtOsgModelInstance;
51  class DtIndirectGeometryGrid;
52 
53  class DtIndirectEntityManagerInstanceMoveInfo;
54  class DtIndirectEntityLimitTextureStrategy;
55 
56  class DtIndirectModelMasterMappings;
57 
71  {
72  public:
74  {
75  int myLightPointGroupId = 0;
76  std::string myLightPointGroupName = "";
77  };
78 
79  public:
81  virtual ~DtOsgIndirectEntityManager();
82 
84  static void registerInstance(DtDe& de);
85 
88  static DtOsgIndirectEntityManager& instance(DtDe& de);
89 
90 
91  protected:
94 
96  DtOsgIndirectEntityManager() = delete;
97 
100 
102  DtOsgIndirectEntityManager& operator=(const DtOsgIndirectEntityManager&) = delete;
103  public:
104 
108  virtual bool addInstance(DtUniqueID uniqueId, const DtModelDefinition& modelDefinition
109  , const DtOsgModelInstance& modelInstance, DtModel* model
110  , DtModelSetId modelSet, float modelScale, float modelRadius
111  , bool daylightControlled, bool mapDofsSwitchesSequences
112  , const DtLightPointGroupInfo& lightPointGroupInfo
113  , bool trackLifeTime
114  , const std::string& trackName);
115 
119  virtual bool addInstanceAsProp(DtUniqueID uniqueId, const DtModelDefinition& modelDefinition
120  , const DtOsgModelInstance& modelInstance, DtModel* model
121  , float modelScale, float modelRadius
122  , bool daylightControlled, bool mapDofsSwitchesSequences
123  , int lightPointGroupId);
124 
126  virtual bool hasInstance(DtUniqueID uniqueId) const;
127 
129  virtual void removeInstance(DtUniqueID uniqueID);
130 
132  virtual int numInstances(void) const;
133 
143  virtual void mapMultiSwitches(DtUniqueID uniqueID
145 
147  virtual void unMapMultiSwitches(DtUniqueID uniqueID);
148 
150  virtual void mapSequences(DtUniqueID uniqueID, DtArticulatedModelParser::AnimationMap& animationMap);
151 
153  virtual void unMapSequences(DtUniqueID uniqueID);
154 
156  virtual void mapDofs(DtUniqueID uniqueID, DtArticulatedModelParser::PartMap& partMap);
157 
159  virtual void unMapDofs(DtUniqueID uniqueID);
160 
162  virtual void setMultiSwitchActiveSwitchSet(DtUniqueID id, osgSim::MultiSwitch* multiSwitchOfInstance);
163 
165  virtual void setSequenceUpdate(DtUniqueID uniqueID, osg::Sequence* dof);
166 
168  virtual void setUvOffsetUpdate(DtUniqueID uniqueID, const std::string& annotation,
169  float uOffset, float vOffset);
170 
172  virtual void scrollUvTextures(DtUniqueID uniqueID, const std::tuple<float, float, float>& uvspeeds);
173 
175  virtual void setDofUpdate(DtUniqueID uniqueID, osgSim::DOFTransform* dof);
176 
178  virtual void setDofAnimationFlags(DtUniqueID uniqueID, osgSim::DOFTransform* dof, int animationFlags);
179 
181  virtual void setDofTranslation(DtUniqueID uniqueID, osgSim::DOFTransform* dof
182  , const Vector3_64& trans
183  , const Vector3_64& transVel);
184 
186  virtual void setDofOrientation(DtUniqueID uniqueID, osgSim::DOFTransform* dof
187  , const Vector3_64& hpr
188  , const Vector3_64& hprVel
189  , int animationFlags);
190 
192  virtual void setDofOrientation(DtUniqueID uniqueID, osgSim::DOFTransform* dof
193  , const Vector3_64& hprVel
194  , bool forceUpdate
195  , int animationFlags);
196 
204  virtual void setDofOrientationBatch(DtUniqueID uniqueID,
205  const std::vector<DtDofOrientationBatchEntry>& entries);
206 
209  void slot_atcGlobalModelEnableChanged();
210 
212  virtual void setPositionAndOrientation(DtUniqueID uniqueId
213  , const DtVector& position, const DtTaitBryan& orientation
214  , const DtVector& positionOffset, const DtTaitBryan& orientationOffset);
215 
217  virtual void setColor(DtUniqueID uniqueId, const Vector4_32& color);
218 
220  virtual void setOtherData0(DtUniqueID uniqueId, const Vector4_32& data);
221 
223  virtual void setVisible(DtUniqueID uniqueId, bool visible);
224 
226  virtual void setLightPointGroupId(DtUniqueID uniqueId, int groupId);
227 
229  virtual void setLightPointMaxDistance(DtUniqueID uniqueId, float maxDistance);
230 
232  virtual void setCellPageOutTime(double val);
238  virtual double cellPageOutTime(void) const;
240 
244  virtual void tick(void) override;
245 
250  virtual void slot_releaseResources();
251 
255  virtual void slot_postTick();
256 
259  virtual void slot_postInit();
260 
262  virtual void excludeTextureFromLimits(const std::string& textureFileAbolutePath);
263 
265  virtual void excludeModelDefinitionFromLimits(const std::string& modelDefinition);
266 
268  virtual DtIndirectLimitTextureStrategy* limitTextureStrategy(DtModelSetId modelSet);
269 
272  virtual bool isCopyingData(void) const;
273 
275 
276  virtual bool areRegisteredModelTextureVariants(DtModelSetId modelSet, const std::string& fileName) const;
277 
278  virtual void registerModelTextureVariants(DtModelSetId modelSet, const DtModelDefinition* modelDefinition
279  , const std::vector<std::string>& variantPaths);
280 
281  virtual void setModelTextureVariant(DtUniqueID uniqueId, const std::string& variant);
283 
286 
288  boost::signalslib::signal<void(DtModel*, DtUniqueID)> signal_instanceAdded;
289 
291 
292  protected:
293 
311  virtual int addInstanceWithPageOutRetry(DtIndirectGeometryGrid* grid , const Vector3_int& cellId
312  , DtIndirectEntityGeometry*& indirectGeometry , int modelId, float modelScale, float modelRadius
313  , int lightPointGroupId , bool trackLifeTime, const std::string& trackName , bool defaultVisibility);
314 
317  virtual DtIndirectEntityManagerInstanceMoveInfo* createMoveInfoIfNecessary(const DtVector& position
318  , DtIndirectEntityManagerInstance& currentEntityManagerInstance
319  , DtUniqueID uniqueId);
320 
322  virtual osgSim::DOFTransform* findMasterDof(DtUniqueID uniqueID, osgSim::DOFTransform* dof) const;
323 
325  virtual DtIndirectEntityGeometry* findIndirectGeometryAndInstanceId(DtUniqueID uniqueID, int& instanceId) const;
326 
328  virtual void calculateAndSetInstanceMatrixTransform(const DtVector& position
329  , const DtTaitBryan& orientation, const DtVector& positionOffset, const DtTaitBryan& orientationOffset
330  , DtIndirectEntityGeometry* indirectGeometry, int instanceId);
331 
333  virtual void reset();
334 
335  protected:
337  virtual void tickEntityMoves(void);
338 
340  virtual void tickPaging(void);
341 
343  virtual bool instanceIsBeingMovedTo(const Vector3_int& cellId);
344 
346  void setupRootNodes();
347 
350  virtual void setupReductionExcludeTextures();
351 
353  virtual void updateStats();
354 
356  virtual void disableModelSet(DtModelSetId modelSet);
358  virtual bool modelSetDisabled(DtModelSetId modelSet) const;
359 
361  virtual void setAlpha2Coverage(osg::Node* node, bool on);
362 
364  virtual void clearMasterMappingsMap(void);
365 
367  virtual bool parseNodeAndRegisterMasterMappings(osg::Node* modelNodeMaster, const std::string& modelName);
368  protected:
369 
370 
373 
374  boost::signalslib::connection myPostInitializeConnection;
375 
380  typedef std::unordered_map<DtModelSetId, DtIndirectGeometryGrid* > MapModelSetToDtIndirectGeometryGrids;
382 
384  using MapUniqueIdsToEntityManagerInstances = tbb::concurrent_hash_map<DtUniqueID, DtIndirectEntityManagerInstance>;
386 
387  typedef std::unordered_map< osgSim::MultiSwitch*, osg::ref_ptr<osgSim::MultiSwitch> > MapMultiSwitchesToMultiSwitches;
388  typedef std::unordered_map<DtUniqueID, MapMultiSwitchesToMultiSwitches > MapInstanceMultiSwitchesToMasterMultiSwitches;
389 
390  std::unordered_map<std::string, DtIndirectModelMasterMappings*> myModelNameToModelMasterMappings;
391 
393 
394  typedef std::unordered_map< osgSim::DOFTransform*, osg::ref_ptr<osgSim::DOFTransform> > MapDofToDof;
395  typedef std::unordered_map<DtUniqueID, MapDofToDof > MapInstanceDofToMasterDof;
396 
398 
399  typedef std::unordered_map< osg::Sequence*, osg::ref_ptr<osg::Sequence> > MapSequenceToSequence;
400  typedef std::unordered_map<DtUniqueID, MapSequenceToSequence > MapInstanceSequenceToMasterSequence;
401 
403 
406  using InstancesBeingMovedMap = tbb::concurrent_hash_map<DtUniqueID, DtIndirectEntityManagerInstanceMoveInfo*>;
408 
413 
418  using IndirectEntityGeometryMap = tbb::concurrent_unordered_map<unsigned int, DtIndirectEntityGeometry*>;
420 
422  typedef std::unordered_map<Vector3_int, DtIndirectGridCellTime, DtIndirectCellHasher> CellIdsWithZeroInstancesUpTime;
423 
425  typedef std::unordered_map<DtModelSetId, CellIdsWithZeroInstancesUpTime> GridToCellIdsWithZeroInstancesUpTime;
426 
429 
430  // The time after which inactive cells are removed
432 
434 
437  std::vector<DtInstanceDofBatchEntry> myReusableResolvedEntries;
438 
439  std::set<int> myDisabledModelSets;
440 
442  {
444  std::unordered_map<std::string, int> myVariantToModelId;
445  };
446 
447  std::unordered_map < DtModelSetId, std::unordered_map<std::string, ModelVariantInformation> > myModelSetToModelVariantInformationMap;
448  };
449 }
MapUniqueIdsToEntityManagerInstances myMapUniqueIdsToEntityManagerInstances
Definition: DtOsgIndirectEntityManager.h:385
internal structure for mapping a DtOsgArticulatedModel/DtOsgSimpleModel object to a corresponding ins...
Definition: DtIndirectEntityManagerInstance.h:30
std::unordered_map< DtModelSetId, std::unordered_map< std::string, ModelVariantInformation > > myModelSetToModelVariantInformationMap
Definition: DtOsgIndirectEntityManager.h:447
DtSignalConnectionManager myConnections
manager for connections
Definition: DtOsgIndirectEntityManager.h:372
class to encapsulate moving of instance from one indirect geometry to another in an entity manager/gr...
Definition: DtIndirectEntityManagerInstanceMoveInfo.h:30
std::unordered_map< osgSim::DOFTransform *, osg::ref_ptr< osgSim::DOFTransform > > MapDofToDof
Definition: DtOsgIndirectEntityManager.h:394
Contains the DtIndirectEntityManagerInstance class declaration.
#define DT_DLL_VRVOSG
Definition: vrvOsg.h:23
tbb::concurrent_hash_map< DtUniqueID, DtIndirectEntityManagerInstanceMoveInfo * > InstancesBeingMovedMap
move info for the instances being moved Use concurrent hash map here as it supports concurrent erase ...
Definition: DtOsgIndirectEntityManager.h:406
OsgEarth-free batch-entry structs shared by the articulated-model / indirect-entity batch update path...
std::unordered_map< DtModelSetId, DtIndirectGeometryGrid * > MapModelSetToDtIndirectGeometryGrids
There is one grid per model set type in the manager Each grid contains a list of &#39;cells&#39; Each cell co...
Definition: DtOsgIndirectEntityManager.h:380
MapInstanceMultiSwitchesToMasterMultiSwitches myMapInstanceMultiSwitchesToMasterMultiSwitches
Definition: DtOsgIndirectEntityManager.h:392
singleton class that acts as a bridge between the
Definition: DtOsgIndirectEntityManager.h:70
std::unordered_map< int, MultiSwitchList > MapStateNumberToMultiSwitchList
Definition: DtArticulatedModelParser.h:47
A model definition Interaction any number of named parameters, and also can be used to store cached d...
Definition: DtModelDefinition.h:44
3 dimensional vector
std::unordered_map< osg::Sequence *, osg::ref_ptr< osg::Sequence > > MapSequenceToSequence
Definition: DtOsgIndirectEntityManager.h:399
std::vector< DtInstanceDofBatchEntry > myReusableResolvedEntries
Reusable vector for resolved DOF batch entries. Cleared each call, preserves capacity. Main-thread only – not thread-safe.
Definition: DtOsgIndirectEntityManager.h:437
tbb::concurrent_hash_map< DtUniqueID, DtIndirectEntityManagerInstance > MapUniqueIdsToEntityManagerInstances
map of unique ids to the corresponding DtOsgIndirectEntityManagerInstances
Definition: DtOsgIndirectEntityManager.h:384
Inherited from DtIndirectGeometry additionally implements: -removal of instances -ability to set/get ...
Definition: DtIndirectEntityGeometry.h:42
std::unordered_map< DtModelSetId, CellIdsWithZeroInstancesUpTime > GridToCellIdsWithZeroInstancesUpTime
map of each grid (model set) to inactive cells in that grid
Definition: DtOsgIndirectEntityManager.h:425
std::unordered_map< std::string, AnimationList > AnimationMap
Definition: DtArticulatedModelParser.h:50
Contains makVrv::DtVirtualBaseClass class.
Axis Aligned Bounding Box class.
The base class for simple OSG based model instances. This call can&#39;t be instantiated itself...
Definition: DtOsgModelInstance.h:77
InstancesBeingMovedMap myInstanceMovesToDelete
Container for moves that need to be deleted. The DTOR for DtOsgIndirectEntityManagerInstanceMoveInfo ...
Definition: DtOsgIndirectEntityManager.h:412
InstancesBeingMovedMap myInstancesBeingMoved
Definition: DtOsgIndirectEntityManager.h:407
GridToCellIdsWithZeroInstancesUpTime myGridToCellIdsWithZeroInstancesUpTime
map of each grid (model set) to inactive cells in that grid
Definition: DtOsgIndirectEntityManager.h:428
Contains the DtIndirectEntityManager class declaration.
std::set< int > myDisabledModelSets
Definition: DtOsgIndirectEntityManager.h:439
boost::signalslib::signal< void(DtModel *, DtUniqueID)> signal_instanceAdded
Emitted when a new instance of a model is added to the entity manager.
Definition: DtOsgIndirectEntityManager.h:288
boost::signalslib::connection myPostInitializeConnection
Definition: DtOsgIndirectEntityManager.h:374
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
Vector3_64 myLastObserverLocation
Definition: DtOsgIndirectEntityManager.h:433
Contains makVrv::DtIndirectGridCellTime class.
MapInstanceSequenceToMasterSequence myMapInstanceSequenceToMasterSequence
Definition: DtOsgIndirectEntityManager.h:402
MapModelSetToDtIndirectGeometryGrids myMapModelSetToDtIndirectGeometryGrids
Definition: DtOsgIndirectEntityManager.h:381
Definition: DtOsgIndirectEntityManager.h:73
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
The indirect system uses this in conjunction with the system wide limits (for entity/terrain) to clam...
Definition: DtIndirectLimitTextureStrategy.h:65
tbb::concurrent_unordered_map< unsigned int, DtIndirectEntityGeometry * > IndirectEntityGeometryMap
A map that holds all indirect geometries in one location so that they can be ticked, and this can be done across multiple threads. Use unordered map here as it supports concurrent traversal and insertion but does not support concurrent erase. Removal from this map only occurs in DtOsgIndirectEntityManager::tickPaging() which is single threaded.
Definition: DtOsgIndirectEntityManager.h:418
std::unordered_map< Vector3_int, DtIndirectGridCellTime, DtIndirectCellHasher > CellIdsWithZeroInstancesUpTime
map of inactive cells to their start and current time
Definition: DtOsgIndirectEntityManager.h:422
std::unordered_map< DtUniqueID, MapMultiSwitchesToMultiSwitches > MapInstanceMultiSwitchesToMasterMultiSwitches
Definition: DtOsgIndirectEntityManager.h:388
std::unordered_map< DtUniqueID, MapDofToDof > MapInstanceDofToMasterDof
Definition: DtOsgIndirectEntityManager.h:395
Base class to provide boost signal/slot management.
std::unordered_map< int, PartTransformList > PartMap
Definition: DtArticulatedModelParser.h:44
Contains makVrv::DtArticulatedModelParser class.
double myCellPageOutTime
Definition: DtOsgIndirectEntityManager.h:431
MapInstanceDofToMasterDof myMapInstanceDofToMasterDof
Definition: DtOsgIndirectEntityManager.h:397
A model which owns a single model instance. A DtModel is a managing container for a single DtModelIns...
Definition: DtModel.h:57
Contains makVrv::DtUniqueID type.
Contains DLL export macros.
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
std::unordered_map< std::string, DtIndirectModelMasterMappings * > myModelNameToModelMasterMappings
Definition: DtOsgIndirectEntityManager.h:390
Definition: DtOsgIndirectEntityManager.h:441
int myMasterModelId
Definition: DtOsgIndirectEntityManager.h:443
vrvCore singleton base class for OSGs DtOsgIndirectEntityManager, Allows for this manager to be ticke...
Definition: DtIndirectEntityManager.h:21
DtModelSetId
Definition: DtModelSetEnums.h:19
Manages a bunch of &#39;cells&#39; for a given cell size (similar to a sparse octree) each cell has a...
Definition: DtIndirectGeometryGrid.h:62
Contains the DtIndirectGeometry class declaration.
std::unordered_map< osgSim::MultiSwitch *, osg::ref_ptr< osgSim::MultiSwitch > > MapMultiSwitchesToMultiSwitches
Definition: DtOsgIndirectEntityManager.h:387
Contains makVrv::DtIndirectCellHasher class.
std::unordered_map< DtUniqueID, MapSequenceToSequence > MapInstanceSequenceToMasterSequence
Definition: DtOsgIndirectEntityManager.h:400
std::unordered_map< std::string, int > myVariantToModelId
Definition: DtOsgIndirectEntityManager.h:444
IndirectEntityGeometryMap myIndirectEntityGeometryMap
Definition: DtOsgIndirectEntityManager.h:419

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)