VR-Forces 4.6 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 
20 
21 #define DTHIERARCHICALPAGEDLOD_LOGGING 0
22 
23 namespace makVrv
24 {
25  class DtOsgCullVisitor;
26 
32  {
33  public:
34 
36  DtHierarchicalPagedLod(const std::string& filename,
37  float distanceNear, float distanceFar, float tileRadius,
38  float childTileRadius, const osg::Vec3d& fileCenter,
39  const osg::Vec3d& childrenCenter, bool sparseChildren,
40  bool substitutiveChildren, const osg::Matrixd& fileTranslation,
41  osgDB::Options* options);
42 
44  virtual ~DtHierarchicalPagedLod();
45 
46  virtual const char* className() const { return "DtHierarchicalPagedLod"; }
47 
52  void addChildHierarchy(DtHierarchicalPagedLod* child);
53 
55  virtual void traverse(osg::NodeVisitor& nv);
56 
58  virtual void traverseAll(osg::NodeVisitor& nv);
59 
61  virtual void traverseActive(osg::NodeVisitor& nv);
62 
65  virtual void cullActive(osg::NodeVisitor& nv);
66 
68  void cullActive2D(DtOsgCullVisitor& nv);
69 
71  void cullActive3D(osg::NodeVisitor& nv);
72 
74  virtual osg::BoundingSphere computeBound() const;
75 
78  virtual void traverseFile(osg::NodeVisitor& nv, float distance);
79 
82  virtual void traverseChildren(osg::NodeVisitor& nv);
83 
85  virtual bool fileInRange(float distance) const;
86 
88  virtual float fileRangeDistance(osg::NodeVisitor& nv) const;
89 
91  virtual float childRangeDistance(osg::NodeVisitor& nv) const;
92 
94  void pageInFile(osg::NodeVisitor& nv, float distance);
95 
98  void pageOutFile(int lastCullTime, osg::NodeList& toRemove);
99 
102  bool fileNotLoaded() const;
103 
105  bool fileIsPaging() const;
106 
108  bool fileIsLoaded() const;
109 
111  virtual bool fileInChildRange(float distance) const;
112 
114  void pageInChildren(osg::NodeVisitor& nv, float distance);
115 
117  void pageOutChildren(int lastCullTime, osg::NodeList& toRemove);
118 
120  bool childrenLoaded() const;
121 
124  osg::ref_ptr<osg::Node> fileNode();
125 
127  virtual bool addPagedInChild(Node* child);
128 
130  inline int getNumChildrenPagedIn() { return myPagedInCount; }
131 
133  void increaseCountUpToParents();
134 
136  void decreaseCountUpToParents(int amount);
137 
139  virtual void adjustLOD(Node* child);
140 
142  float fileRangeCullDistance2D(DtOsgCullVisitor& nv);
143 
145  bool fileInRange2D(float distance, float cull);
146 
148  float childRangeCullDistance2D(DtOsgCullVisitor& nv);
149 
151  bool fileInChildRange2D(float cull, float lod);
152 
154  void setThreadSafeRefUnref(bool threadSafe);
155 
157  virtual void resizeGLObjectBuffers(unsigned int maxSize);
158 
162  virtual void releaseGLObjects(osg::State* state) const;
163 
165  virtual std::string fileName() const;
166 
168  virtual const std::vector<osg::ref_ptr<DtHierarchicalPagedLod> >& children() const;
169 
172  virtual const osg::Matrix& fileTranslation() const;
173 
175  inline float getTileRadius() { return myTileRadius; }
176 
185  boost::signal<void(osg::Group* page, osg::Node* child)> signal_childPagedIn;
186 
189  boost::signal<void(osg::Group* page, osg::Node* child)> signal_childAboutToPageOut;
190 
191  protected:
192 
194  {
195  NotLoaded = 0,
197  Loaded
198  };
199 
202  class DT_DLL_VRVOSG PagedFileRoot : public osg::MatrixTransform
203  {
204  public:
205  PagedFileRoot(DtHierarchicalPagedLod& parent, const osg::Matrixd& m)
206  : osg::MatrixTransform(m)
207  , myParent(parent)
208  {
209  _parents.push_back(&parent);
210  }
211 
212  //Override Add child to inform DtHierarchicalPagedLod of page in.
213  virtual bool addChild(Node *child)
214  {
215  return myParent.addPagedInChild(child);
216  }
218  };
219 
220  osg::Vec3d myFileCenter;
221  osg::Vec3d myChildrenCenter;
222 
223  const float myRangeNear;
224  const float myRangeFar;
225  const float myTileRadius;
226  const float myChildTileRadius;
229 
230  volatile int myCullTracking;
231  std::string myFileName;
233  osg::ref_ptr<PagedFileRoot> myFileRoot;
234  std::vector<osg::ref_ptr<DtHierarchicalPagedLod> > myChildren;
235  osg::ref_ptr<osg::Referenced> myPageRef;
236  osg::ref_ptr<osgDB::Options> myOptions;
237 
238  // Am I paged in + how many children are paged in
239  // so a tile that has 4 paged in children would have a count of 5
240  // a tile with no paged in children would have a count of 1
241  // because of DtHierarchicalPagedLod::fileInRange
242  // it looks like if the children are pagedIn, the parent is pagedIn
243  // (but not always displayed)
245 
246 #if DTHIERARCHICALPAGEDLOD_LOGGING
247  static int myHPLODRefCount;
248 #endif
249  };
250 }

Document ID: Generated on Thu Apr 12 03:15:37 EDT 2018 from SVN revision 187986
Copyright © 2005-2018 VT MÄK. All Rights Reserved (www.mak.com)