VR-Forces 4.10 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtSpeedTreeForest.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2021 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvSt/vrvSt.h>
15 #include <vrvCore/DtTreeRecord.h>
16 #include <vrvCore/DtForestObject.h>
17 #include <osg/ref_ptr>
18 #include <osg/PositionAttitudeTransform>
19 #include <osg/Geode>
20 #include <osg/BoundingBox>
21 
22 #include <OsgST_Forest.h>
23 
24 #include <boost/unordered_set.hpp>
25 
26 #include <tbb/mutex.h>
27 
28 namespace makOsgSpeedTree
29 {
30  class TreeInstance;
31  struct TreeInstanceDescriptor;
32 }
33 
34 namespace makVrv
35 {
36  class DtAgentUpdateResolverInterface;
37  class DtSpeedTreeModelInstance;
38  class DtSpeedTreeCore;
39  class DtEnvironmentInfo;
40  class DtOsgCullVisitorParameters;
41  class DtGlDebugGroup;
42  class DtCoordinateConverter;
43  class DtOsgRenderer;
44 
49  {
50  public:
51  friend class DtSpeedTreeForestClassesCreator;
53 
54  public:
55  //Destructor
56  virtual ~DtSpeedTreeForest();
57 
58  protected:
59 
63  DtSpeedTreeForest(DtDe& de, DtUniqueID id, const std::string& strVisManagerType);
64 
65  private:
71  DtSpeedTreeForest &operator=(const DtSpeedTreeForest &other);
72 
73  public:
74 
78  virtual void setVisible(bool isVisible);
79 
80  virtual void addUniqueTree(DtTreeRecord& record);
81  virtual void removeTree(DtUniqueID record);
82  virtual void removeAllTrees();
83 
84  virtual DtUniqueID addUniqueTreesToUniqueCell(
85  DtVectorTreeRecords& records, bool use_time_limit, bool *out_of_time = NULL);
86  virtual void removeAllUniqueTreesAndUniqueCell(DtUniqueID cellID);
87 
88  virtual void setTreeClippingPlane(float fFar);
89  virtual void getTreeClippingPlane( float& fFar );
90 
91  virtual void setTree3DLodDistances(float fNear, float fFar);
92  virtual void getTree3DLodDistances( float& fNear, float& fFar );
93 
94  virtual void setTreeBillboardDistances(float fStart, float fEnd);
95  virtual void getTreeBillboardDistances(float& fStart, float& fEnd);
96 
98  virtual void setBillboardFadeOutRange(float fRange);
100  virtual void getBillboardFadeOutRange(float& fRange);
101 
102  virtual void enableBillboardRendering(bool enable);
103  virtual bool isBillboardRenderingEnabled() const;
104 
105  virtual void enable3DTreeRendering(bool enable);
106  virtual bool is3DTreeRenderingEnabled() const;
107 
108  virtual void enableReceiveShadows(bool enable);
109  virtual bool isReceiveShadowsEnabled() const { return myReceiveShadows; }
110 
111  void setBoundingBox(const osg::BoundingBox& box);
112  const osg::BoundingBox& getBoundingBox(void) const;
113 
116  osg::ref_ptr<osg::Node> getRootNode(void);
117 
120  void programBoundCallback(osg::ref_ptr<makOsgSpeedTree::Forest> pForest,
121  const makOsgSpeedTree::TreeType* pTreeType, uint32 programID);
122 
125  virtual void slot_reloadShaders();
126 
128  virtual void slot_treeProfilingChanged(bool active);
129 
131  virtual void slot_useGlobalAmbientChanged(bool enabled);
132 
134  virtual void slot_useGlobalDiffuseChanged(bool enabled);
135 
138  virtual void slot_perPixelLightingEnabledChanged(bool enabled);
139 
141  virtual void slot_planarReflectionsShowSpeedTreesChanged(bool enabled);
142 
144  virtual void processUnitialized();
145 
147  virtual bool initialized();
148 
150  virtual tbb::mutex& mergeDrawMutex();
151 
153  virtual tbb::mutex& mergeUpdateMutex();
154 
156  osg::ref_ptr<makOsgSpeedTree::Forest>& makSpeedTreeForest();
157 
160  virtual void preCullSetup(osg::ref_ptr<makOsgSpeedTree::Forest> forest, osg::Camera* camera);
161 
162  protected:
163 
164  void init(const std::string& strVisManagerType);
165 
166  // The tree scale from the .earth file and the terrain patch
167  // are applied in DtStreamedSpeedTreeThread::handleRequest
168  // However, the user could also set the model definition
169  // scale. Store model def scale when we store the ST file name
170  // so we can multiply it into the record.scale().
172  {
173  std::string strSRTFileName;
175  };
176 
177  protected:
178  void connectSignals(void);
179 
180  osg::Vec3f computeWindDirection(float fDirection);
181 
182  void setWindStrength(float fStrength);
183  void setWindDirection(float fDirection);
184 
186  bool preUpdateCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest);
187 
188  bool preRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
189  osg::RenderInfo& renderInfo);
190  void postRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
191  osg::RenderInfo& renderInfo);
192  void provideTimeCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
193  double& fTime);
194 
195  void pushGraphicsState(osg::RenderInfo& renderInfo);
196  void popGraphicsState(osg::RenderInfo& renderInfo);
197 
199  virtual DtModelDefinition* findModelDefinition(
200  const std::string& modelDef);
201 
203  bool createTree(DtTreeRecord& record);
204 
207  void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
208  DtTreeRecord& record, const DtVector& up, DtCoordinateConverter* converter);
211  void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
212  DtTreeRecord& record, DtCoordinateConverter* converter, bool setupTopoFrame=true);
213  void applyModelDefParameters(makOsgSpeedTree::TreeInstanceDescriptor& desc,
214  DtTreeRecord& record);
215 
224  virtual const bool bindLightingAttributes(const osg::Node* node,
225  const uint32 programID, DtOsgRenderer* osgRenderer,
226  const std::string& searchNodeName);
227 
228  protected:
229  static DtOsgCullVisitorParameters* getCullParameters(
230  osg::RenderInfo& renderInfo);
231 
232  static bool isCameraOrthographic(DtOsgCullVisitorParameters* params);
233 
235  static bool isReflectionCamera(osg::Camera *camera);
236 
237  static float getZoomFactor(DtOsgCullVisitorParameters* params, DtDe& de);
238 
239  protected:
240 
241  static const float myCellSize;
242 
243  //Static members used by imgui to keep track of the ImGui state.
244  static unsigned int theLastImGuiFrameNumber;
245  static bool theEnableAsyncUpdate;
246 
247  protected:
248  makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc;
249  makOsgSpeedTree::TreeInstanceDescriptorCollection
251  makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection;
252 
253  typedef std::map<std::string, ModelDefParams> MapModelDefToSTFileName;
255 
257 
258  osg::Camera* myCamera;
259 
261 
262  boost::unordered_map<int, bool> myShaderBoundMap;
263 
264  float myFarPlane;
265 
270  osg::BoundingBox myBoundingBox;
273 
274  typedef boost::unordered_map<DtUniqueID,
275  makOsgSpeedTree::TreeInstanceCollection> MapCellsToTrees;
277 
278  typedef boost::unordered_map<DtUniqueID, makOsgSpeedTree::TreeInstance*>
281 
283  unsigned int myLastShaderHash;
284 
287 
290 
292 
294 
295  // REMOVE POST UBO CHANGE:
297 
298  osg::GLExtensions * myExt;
300 
301  // Couple mutexes to avoid thread safety issues.
302  // The merge draw mutex should be moved down into the vis manager but this
303  // was the safer and lower risk option at the moment.
307 
310 
312 
314  };
315 
320  {
321  public:
324 
325  private:
330 
331  public:
333  virtual DtForestObject* create(DtDe& de, DtUniqueID id);
334 
336  virtual DtForestObject* create(DtDe& de, DtUniqueID id, const std::string& strVisManagerType);
337  };
338 }
DtSpeedTreeForestObjectCreator is the SpeedTree implementation of a DtForestObjectCreator.
Definition: DtSpeedTreeForest.h:319
const std::string mySpeedTreeMultiViewUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:291
MapModelDefToSTFileName myMapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:254
DT_DLL_EXAMPLESCENEROOTPLUGIN void init(DtDe &anIG)
osg::GLExtensions * myExt
Definition: DtSpeedTreeForest.h:298
static bool theEnableAsyncUpdate
Definition: DtSpeedTreeForest.h:245
static unsigned int theLastImGuiFrameNumber
Definition: DtSpeedTreeForest.h:244
The DtEnvironmentInfo class is responsible for holding data related to the environment such as sky li...
Definition: DtEnvironmentInfo.h:25
The DtOsgRenderer is the component responsible for rendering 3D images onto the screen via OpenSceneG...
Definition: DtOsgRenderer.h:90
float myFarPlane
Definition: DtSpeedTreeForest.h:264
bool myShouldUpdateThisFrame
Definition: DtSpeedTreeForest.h:311
#define DT_DLL_VRVST
Definition: vrvSt.h:20
std::string strSRTFileName
Definition: DtSpeedTreeForest.h:173
DtCoordinateConverter is the base class for &#39;local (cig) to geocentric&#39; converters.
Definition: DtCoordinateConverter.h:25
bool myReloadShaders
Should we reload the SpeedTree shaders.
Definition: DtSpeedTreeForest.h:286
makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc
Definition: DtSpeedTreeForest.h:248
boost::unordered_map< DtUniqueID, makOsgSpeedTree::TreeInstanceCollection > MapCellsToTrees
Definition: DtSpeedTreeForest.h:275
const std::string mySpeedTreeDefaultUserFuncsPixelShader
Definition: DtSpeedTreeForest.h:289
makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection
Definition: DtSpeedTreeForest.h:251
Contains DLL export macros.
std::vector< DtTreeRecord * > DtVectorTreeRecords
Definition: DtTreeRecord.h:137
DtSpeedTreeCore & myCore
Definition: DtSpeedTreeForest.h:271
Contains makVrv::DtForestObject class.
DtForestObject provides a way to make lots of trees.
Definition: DtForestObject.h:26
osg::BoundingBox myBoundingBox
Definition: DtSpeedTreeForest.h:270
float modelDefScale
Definition: DtSpeedTreeForest.h:174
A model definition Interaction any number of named parameters, and also can be used to store cached d...
Definition: DtModelDefinition.h:38
MapTreeIDToTree myMapTreeIDtoTree
Definition: DtSpeedTreeForest.h:280
DtSpeedTreeCore wraps and provides the interface to makOsgSpeedTree.
Definition: DtSpeedTreeCore.h:28
static const float myCellSize
Definition: DtSpeedTreeForest.h:241
const std::string mySpeedTreeDefaultUserFuncsVertexShader
Definition: DtSpeedTreeForest.h:288
virtual bool isReceiveShadowsEnabled() const
Definition: DtSpeedTreeForest.h:109
A DtTreeRecord holds the requisite information needed to create a tree in a forest.
Definition: DtTreeRecord.h:30
boost::unordered_map< DtUniqueID, makOsgSpeedTree::TreeInstance * > MapTreeIDToTree
Definition: DtSpeedTreeForest.h:279
DtSpeedTreeForest is the SpeedTree implementation of a distributed DtForestObject.
Definition: DtSpeedTreeForest.h:48
DtEnvironmentInfo & myEnvInfo
Definition: DtSpeedTreeForest.h:272
bool myReceiveShadows
Definition: DtSpeedTreeForest.h:299
unsigned int myRestoreVisibilityNodeMask
Definition: DtSpeedTreeForest.h:313
osg::ref_ptr< osg::PositionAttitudeTransform > myPat
Definition: DtSpeedTreeForest.h:268
Class to manage disconnection of boost connections on deletion.
Definition: DtSignalConnectionManager.h:20
The osg cull vistor parameters class provides additional culling and intersector parameters for choos...
Definition: DtOsgCullVisitorParameters.h:38
DtCoordinateConverter * myMergeBackgroundConverter
Definition: DtSpeedTreeForest.h:309
DtCoordinateConverter * myMainThreadConverter
Definition: DtSpeedTreeForest.h:308
unsigned long long DtUniqueID
Definition: DtUniqueID.h:19
MapCellsToTrees myMapCellsToTrees
Definition: DtSpeedTreeForest.h:276
osg::ref_ptr< osg::Uniform > myNormalMatrixUniform
Definition: DtSpeedTreeForest.h:296
Base class to provide boost signal/slot management.
osg::Camera * myCamera
Definition: DtSpeedTreeForest.h:258
boost::unordered_map< int, bool > myShaderBoundMap
Definition: DtSpeedTreeForest.h:262
osg::ref_ptr< makOsgSpeedTree::Forest > myForest
Definition: DtSpeedTreeForest.h:269
makOsgSpeedTree::TreeInstanceDescriptorCollection myScratchTreeInstanceDescCollection
Definition: DtSpeedTreeForest.h:250
DtSignalConnectionManager myConnections
Definition: DtSpeedTreeForest.h:260
int myPreviousTU
Definition: DtSpeedTreeForest.h:256
unsigned int uint32
Definition: DtCommonTypes.h:28
The DtForestObjectCreator for the DtForestObject class.
Definition: DtForestObject.h:103
The DtDe is the core component of any VR-Vantage application.
Definition: DtDe.h:69
tbb::mutex myForestMergeDrawMutex
Definition: DtSpeedTreeForest.h:304
std::map< std::string, ModelDefParams > MapModelDefToSTFileName
Definition: DtSpeedTreeForest.h:253
Contains the DtCVMarkerSeries and DtCVMarkerSeries class declarations responsible for wrapping up to ...
osg::ref_ptr< osg::Uniform > myProjectionMatrixInverseUniform
Definition: DtSpeedTreeForest.h:293
Contains makVrv::DtTreeRecord class.
unsigned int myLastShaderHash
shader hash for the last shaders passed down to SpeedTree
Definition: DtSpeedTreeForest.h:283
osg::ref_ptr< osg::Group > myRoot
The forest is a collection of trees under a group node.
Definition: DtSpeedTreeForest.h:267
Definition: DtSpeedTreeForest.h:171
tbb::mutex myForestMergeUpdateMutex
Definition: DtSpeedTreeForest.h:306
tbb::mutex myForestAddRemoveMutex
Definition: DtSpeedTreeForest.h:305

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)