VR-Forces 4.6.1 Class Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtHierarchicalPagedLod.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2016 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
11 #include <vrvOsg/vrvOsg.h>
12 #include <vrvOsg/DtFastGroup.h>
13 #include <osg/Vec3>
14 #include <osg/MatrixTransform>
15 #include <osgDB/Options>
16 
17 #include <boost/signals.hpp>
18 #include <boost/unordered_map.hpp>
19 
20 #include <vrvCore/DtUniqueID.h>
21 
23 
24 #define DTHIERARCHICALPAGEDLOD_LOGGING 0
25 
26 namespace makVrv
27 {
28  class DtOsgCullVisitor;
29  class DtOsgArticulatedModel;
30  class DtModelDefinition;
31 
37  {
38  public:
39 
40  typedef boost::unordered_map<DtUniqueID, DtSceneObject* > SceneObjectMap;
41 
43  DtHierarchicalPagedLod(DtDe& de, const std::string& filename,
44  float distanceNear, float distanceFar, float tileRadius,
45  float childTileRadius, const osg::Vec3d& fileCenter,
46  const osg::Vec3d& childrenCenter, bool sparseChildren,
47  bool substitutiveChildren, const osg::Matrixd& fileTranslation,
48  osgDB::Options* options);
49 
51  virtual ~DtHierarchicalPagedLod();
52 
53  virtual const char* className() const { return "DtHierarchicalPagedLod"; }
54 
59  void addChildHierarchy(DtHierarchicalPagedLod* child);
60 
62  virtual void traverse(osg::NodeVisitor& nv);
63 
65  virtual void traverseAll(osg::NodeVisitor& nv);
66 
68  virtual void traverseActive(osg::NodeVisitor& nv);
69 
72  virtual void cullActive(osg::NodeVisitor& nv);
73 
75  void cullActive2D(DtOsgCullVisitor& nv);
76 
78  void cullActive3D(osg::NodeVisitor& nv);
79 
81  virtual osg::BoundingSphere computeBound() const;
82 
85  virtual void traverseFile(osg::NodeVisitor& nv, float distance);
86 
89  virtual void traverseChildren(osg::NodeVisitor& nv);
90 
92  virtual bool fileInRange(float distance) const;
93 
95  virtual float fileRangeDistance(osg::NodeVisitor& nv) const;
96 
98  virtual float childRangeDistance(osg::NodeVisitor& nv) const;
99 
101  void pageInFile(osg::NodeVisitor& nv, float distance);
102 
105  void pageOutFile(int lastCullTime, osg::NodeList& toRemove);
106 
109  bool fileNotLoaded() const;
110 
112  bool fileIsPaging() const;
113 
115  bool fileIsLoaded() const;
116 
118  virtual bool fileInChildRange(float distance) const;
119 
121  void pageInChildren(osg::NodeVisitor& nv, float distance);
122 
124  void pageOutChildren(int lastCullTime, osg::NodeList& toRemove);
125 
127  bool childrenLoaded() const;
128 
131  osg::ref_ptr<osg::Node> fileNode();
132 
134  virtual bool addPagedInChild(Node* child);
135 
137  inline int getNumChildrenPagedIn() { return myPagedInCount; }
138 
140  void increaseCountUpToParents();
141 
143  void decreaseCountUpToParents(int amount);
144 
146  virtual void adjustLOD(Node* child);
147 
149  float fileRangeCullDistance2D(DtOsgCullVisitor& nv);
150 
152  bool fileInRange2D(float distance, float cull);
153 
155  float childRangeCullDistance2D(DtOsgCullVisitor& nv);
156 
158  bool fileInChildRange2D(float cull, float lod);
159 
161  void setThreadSafeRefUnref(bool threadSafe);
162 
164  virtual void resizeGLObjectBuffers(unsigned int maxSize);
165 
169  virtual void releaseGLObjects(osg::State* state) const;
170 
172  virtual std::string fileName() const;
173 
175  virtual const std::vector<osg::ref_ptr<DtHierarchicalPagedLod> >& children() const;
176 
179  virtual const osg::Matrix& fileTranslation() const;
180 
182  inline float getTileRadius() { return myTileRadius; }
183 
192  boost::signal<void(osg::Group* page, osg::Node* child)> signal_childPagedIn;
193 
196  boost::signal<void(osg::Group* page, osg::Node* child)> signal_childAboutToPageOut;
197 
198  protected:
199 
201  {
202  NotLoaded = 0,
204  Loaded
205  };
206 
209  class DT_DLL_VRVOSG PagedFileRoot : public osg::MatrixTransform
210  {
211  public:
212  PagedFileRoot(DtHierarchicalPagedLod& parent, const osg::Matrixd& m)
213  : osg::MatrixTransform(m)
214  , myParent(parent)
215  {
216  _parents.push_back(&parent);
217  }
218 
219  //Override Add child to inform DtHierarchicalPagedLod of page in.
220  virtual bool addChild(Node *child)
221  {
222  return myParent.addPagedInChild(child);
223  }
225  };
226 
227  osg::Vec3d myFileCenter;
228  osg::Vec3d myChildrenCenter;
229 
230  const float myRangeNear;
231  const float myRangeFar;
232  const float myTileRadius;
233  const float myChildTileRadius;
236 
237  volatile int myCullTracking;
238  std::string myFileName;
240  osg::ref_ptr<PagedFileRoot> myFileRoot;
241  std::vector<osg::ref_ptr<DtHierarchicalPagedLod> > myChildren;
242  osg::ref_ptr<osg::Referenced> myPageRef;
243  osg::ref_ptr<osgDB::Options> myOptions;
244 
245  // Am I paged in + how many children are paged in
246  // so a tile that has 4 paged in children would have a count of 5
247  // a tile with no paged in children would have a count of 1
248  // because of DtHierarchicalPagedLod::fileInRange
249  // it looks like if the children are pagedIn, the parent is pagedIn
250  // (but not always displayed)
252 
254 
255  // The metaflight proxy objects are DtOsgArticulatedModels, they are put
256  // under a DtSceneObject so that they work when instancing is off
257  // The DtSceneObject doesn't have the transform, the articulated model does
258  // Maybe this can be eliminated
260 
261 #if DTHIERARCHICALPAGEDLOD_LOGGING
262  static int myHPLODRefCount;
263 #endif
264  };
265 }

Document ID: Generated on Wed Jul 25 16:57:45 EDT 2018 from SVN revision 190790
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)