VR-Forces 4.3.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtSpeedTreeForest.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2015 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 
12 #include <vrvSt/vrvSt.h>
13 #include <vrvCore/DtForestObject.h>
14 #include <osg/ref_ptr>
15 #include <osg/PositionAttitudeTransform>
16 #include <osg/Geode>
17 #include <osg/BoundingBox>
18 
19 #include <vrvCore/DtTreeRecord.h>
20 
21 #include <OsgST_Forest.h>
22 
23 #include <boost/unordered_map.hpp>
24 
25 
26 
27 namespace makOsgSpeedTree
28 {
29  class TreeInstance;
30  struct TreeInstanceDescriptor;
31 }
32 
33 namespace makVrv
34 {
35  class DtAgentUpdateResolverInterface;
36  class DtSpeedTreeModelInstance;
37  class DtSpeedTreeCore;
38  class DtOsgCullVisitorParameters;
39 
44  {
45  public:
46  friend class DtSpeedTreeForestClassesCreator;
48 
49  virtual ~DtSpeedTreeForest();
50 
51  virtual void addUniqueTree(DtTreeRecord& record);
52  virtual void removeTree(DtUniqueID record);
53  virtual void removeAllTrees();
54 
55  virtual DtUniqueID addUniqueTreesToUniqueCell(
56  DtVectorTreeRecords& records);
57  virtual void removeAllUniqueTreesAndUniqueCell(DtUniqueID cellID);
58 
59  virtual void setTreeClippingPlane(float fFar);
60  virtual void getTreeClippingPlane( float& fFar );
61 
62  virtual void setTree3DLodDistances(float fNear, float fFar);
63  virtual void getTree3DLodDistances( float& fNear, float& fFar );
64 
65  virtual void setTreeBillboardDistances(float fStart, float fEnd);
66  virtual void getTreeBillboardDistances(float& fStart, float& fEnd);
67 
68  void setBoundingBox(const osg::BoundingBox& box);
69  const osg::BoundingBox& getBoundingBox(void) const;
70 
73  osg::ref_ptr<osg::Node> getRootNode(void);
74 
77  void programBoundCallback(osg::ref_ptr<makOsgSpeedTree::Forest> pForest,
78  const makOsgSpeedTree::TreeType* pTreeType, uint32 programID);
79 
80  protected:
81 
86  const std::string& strVisManagerType);
87 
88  void init(const std::string& strVisManagerType);
89 
90  // The tree scale from the .earth file and the terrain patch
91  // are applied in DtStreamedSpeedTreeThread::handleRequest
92  // However, the user could also set the model definition
93  // scale. Store model def scale when we store the ST file name
94  // so we can multiply it into the record.scale().
96  {
97  std::string strSRTFileName;
99  };
100 
101  protected:
102  void connectSignals(void);
103  void disconnectSignals(void);
104 
105  osg::Vec3f computeWindDirection(float fDirection);
106 
107  void setWindStrength(float fStrength);
108  void setWindDirection(float fDirection);
109 
110  bool preUpdateCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
111  osg::RenderInfo& renderInfo);
112  bool preRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
113  osg::RenderInfo& renderInfo);
114  void postUpdateCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
115  osg::RenderInfo& renderInfo);
116  void postRenderCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
117  osg::RenderInfo& renderInfo);
118  void provideTimeCallback(osg::ref_ptr<makOsgSpeedTree::Forest> forest,
119  double& fTime);
120 
121  void pushGraphicsState(osg::RenderInfo& renderInfo);
122  void popGraphicsState(osg::RenderInfo& renderInfo);
123 
125  virtual DtModelDefinition* findModelDefinition(
126  const std::string& modelDef);
127 
129  bool createTree(DtTreeRecord& record);
130 
131  void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
132  DtTreeRecord& record, const DtVector& up);
133  void initTreeDesc(makOsgSpeedTree::TreeInstanceDescriptor& desc,
134  DtTreeRecord& record, bool setupTopoFrame=true);
135  void applyModelDefParameters(makOsgSpeedTree::TreeInstanceDescriptor& desc,
136  DtTreeRecord& record);
137 
138  protected:
139  static DtOsgCullVisitorParameters* getCullParameters(
140  osg::RenderInfo& renderInfo);
141 
142  static bool isCameraOrthographic(DtOsgCullVisitorParameters* params);
143 
144  static float getZoomFactor(DtOsgCullVisitorParameters* params, DtDe& de);
145 
146  protected:
147 
148  static const float myCellSize;
149 
150  protected:
151 
152  makOsgSpeedTree::TreeInstanceDescriptor myScratchTreeInstanceDesc;
153  makOsgSpeedTree::TreeInstanceDescriptorCollection
155  makOsgSpeedTree::TreeInstanceCollection myScratchInstanceCollection;
156 
157  typedef std::map<std::string, ModelDefParams> MapModelDefToSTFileName;
159 
161 
162  //keeps track of the current state of vrvVisualOverride so the
163  //programBoundCallback can apply it to the uniform
164  osg::Camera* myCamera;
165 
166  std::map<int, bool> myShaderBoundMap;
167 
170 
173 
174  float myFarPlane;
175 
177  osg::ref_ptr<osg::Group> myRoot;
178  osg::ref_ptr<osg::PositionAttitudeTransform> myPat;
179  osg::ref_ptr<makOsgSpeedTree::Forest> myForest;
180  osg::BoundingBox myBoundingBox;
182 
183  typedef boost::unordered_map<DtUniqueID,
184  makOsgSpeedTree::TreeInstanceCollection> MapCellsToTrees;
186 
187  typedef boost::unordered_map<DtUniqueID, makOsgSpeedTree::TreeInstance*>
190 
192  unsigned int myLastShaderHash;
193  };
194 
198  {
199  public:
201  static DtSpeedTreeForestSignaler& instance(DtDe&);
202 
205 
207  boost::signal<void (DtSpeedTreeForest&)> signal_forestCreated;
208 
210  boost::signal<void (DtSpeedTreeForest&)> signal_forestToBeDestroyed;
211 
212  protected:
215 
216  private:
219  };
220 
225  {
226  public:
228  virtual DtForestObject* create(DtDe& de, DtUniqueID id);
229  virtual DtForestObject* create(DtDe& de, DtUniqueID id,
230  const std::string& strVisManagerType);
231 
232  private:
233 
234  };
235 }

Document ID: Generated on Wed Jul 29 00:55:00 EDT 2015 from SVN revision 155257
Copyright © 2005-2015 VT MÄK. All Rights Reserved (www.mak.com)