PagedLOD 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
  2. *
  3. * This library is open source and may be redistributed and/or modified under
  4. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  5. * (at your option) any later version. The full license is in LICENSE file
  6. * included with this distribution, and on the openscenegraph.org website.
  7. *
  8. * This library is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * OpenSceneGraph Public License for more details.
  12. */
  13. #ifndef OSG_PagedLOD
  14. #define OSG_PagedLOD 1
  15. #include <osg/LOD>
  16. namespace osg {
  17. /** PagedLOD.
  18. */
  19. class OSG_EXPORT PagedLOD : public LOD
  20. {
  21. public :
  22. /** Default constructor
  23. * The default constructor sets
  24. * - the center mode to USER_DEFINED_CENTER and
  25. * - enables the paging of external children.
  26. * @warning The center mode setting of the default constructor differs
  27. * from the setting of LOD's default constructor! Therefore,
  28. * the PagedLOD and LOD nodes may show different behaviour with
  29. * their default settings when using them with the same subgraph.
  30. * This is a result of the differences in determining the node's center.
  31. * @note Though the bounding spheres of both nodes with their default settings
  32. * will not differ if they have same subgraph.
  33. * @sa LOD::setCenter, LOD::setRadius */
  34. PagedLOD();
  35. /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
  36. PagedLOD(const PagedLOD&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
  37. META_Node(osg, PagedLOD);
  38. virtual void traverse(NodeVisitor& nv);
  39. using osg::Group::addChild;
  40. virtual bool addChild(Node *child);
  41. virtual bool addChild(Node *child, float rmin, float rmax);
  42. template<class T> bool addChild( const ref_ptr<T>& child, float rmin, float rmax) { return addChild(child.get(), rmin, rmax); }
  43. virtual bool addChild(Node *child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f);
  44. template<class T> bool addChild( const ref_ptr<T>& child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f) { return addChild(child.get(), rmin, rmax, filename, priorityOffset, priorityScale); }
  45. virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);
  46. /** Set the optional database osgDB::Options object to use when reading children.*/
  47. void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
  48. /** Get the optional database osgDB::Options object used when reading children.*/
  49. osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
  50. /** Get the optional database osgDB::Options object used when reading children.*/
  51. const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }
  52. /** Set the database path to prepend to children's filenames.*/
  53. void setDatabasePath(const std::string& path);
  54. /** Get the database path used to prepend to children's filenames.*/
  55. inline const std::string& getDatabasePath() const { return _databasePath; }
  56. struct OSG_EXPORT PerRangeData
  57. {
  58. PerRangeData();
  59. PerRangeData(const PerRangeData& prd);
  60. PerRangeData& operator = (const PerRangeData& prd);
  61. std::string _filename;
  62. float _priorityOffset;
  63. float _priorityScale;
  64. double _minExpiryTime;
  65. unsigned int _minExpiryFrames;
  66. double _timeStamp;
  67. unsigned int _frameNumber;
  68. unsigned int _frameNumberOfLastReleaseGLObjects;
  69. osg::ref_ptr<osg::Referenced> _databaseRequest;
  70. };
  71. typedef std::vector<PerRangeData> PerRangeDataList;
  72. void setFileName(unsigned int childNo, const std::string& filename) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._filename=filename; }
  73. const std::string& getFileName(unsigned int childNo) const { return _perRangeDataList[childNo]._filename; }
  74. unsigned int getNumFileNames() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
  75. void setPriorityOffset(unsigned int childNo, float priorityOffset) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityOffset=priorityOffset; }
  76. float getPriorityOffset(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityOffset; }
  77. unsigned int getNumPriorityOffsets() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
  78. void setPriorityScale(unsigned int childNo, float priorityScale) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityScale=priorityScale; }
  79. float getPriorityScale(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityScale; }
  80. unsigned int getNumPriorityScales() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
  81. /** Sets the minimum amount of time, in seconds, that must pass without a child being traversed before it can be expired. */
  82. void setMinimumExpiryTime(unsigned int childNo, double minTime) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryTime=minTime; }
  83. double getMinimumExpiryTime(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryTime; }
  84. unsigned int getNumMinimumExpiryTimes() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
  85. /** Sets the minimum number of frames that must be rendered without a child being traversed before it can be expired. */
  86. void setMinimumExpiryFrames(unsigned int childNo, unsigned int minFrames) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryFrames=minFrames; }
  87. unsigned int getMinimumExpiryFrames(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryFrames; }
  88. unsigned int getNumMinimumExpiryFrames() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
  89. void setTimeStamp(unsigned int childNo, double timeStamp) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._timeStamp=timeStamp; }
  90. double getTimeStamp(unsigned int childNo) const { return _perRangeDataList[childNo]._timeStamp; }
  91. unsigned int getNumTimeStamps() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
  92. void setFrameNumber(unsigned int childNo, unsigned int frameNumber) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._frameNumber=frameNumber; }
  93. unsigned getFrameNumber(unsigned int childNo) const { return _perRangeDataList[childNo]._frameNumber; }
  94. unsigned int getNumFrameNumbers() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
  95. /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
  96. * being carried on behalf of the DatabasePager.
  97. * Note, in normal OSG usage you should not set this value yourself, as this will be managed by
  98. * the osgDB::DatabasePager.*/
  99. osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _perRangeDataList[childNo]._databaseRequest; }
  100. /** Return the const DatabaseRequest object.*/
  101. const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _perRangeDataList[childNo]._databaseRequest; }
  102. /** Set the frame number of the last time that this PageLOD node was traversed.
  103. * Note, this frame number is automatically set by the traverse() method for all traversals (update, cull etc.).
  104. */
  105. inline void setFrameNumberOfLastTraversal(unsigned int frameNumber) { _frameNumberOfLastTraversal=frameNumber; }
  106. /** Get the frame number of the last time that this PageLOD node was traversed.*/
  107. inline unsigned int getFrameNumberOfLastTraversal() const { return _frameNumberOfLastTraversal; }
  108. /** Set the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
  109. inline void setNumChildrenThatCannotBeExpired(unsigned int num) { _numChildrenThatCannotBeExpired = num; }
  110. /** Get the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
  111. unsigned int getNumChildrenThatCannotBeExpired() const { return _numChildrenThatCannotBeExpired; }
  112. /** Set whether you want to disable the paging in of external nodes.*/
  113. void setDisableExternalChildrenPaging(bool flag) { _disableExternalChildrenPaging = flag; }
  114. bool getDisableExternalChildrenPaging() const { return _disableExternalChildrenPaging; }
  115. /** Remove the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number.
  116. * The removed children are added to the removeChildren list passed into the method,
  117. * this allows the children to be deleted later at the caller's discretion.
  118. * Return true if children are removed, false otherwise. */
  119. virtual bool removeExpiredChildren(double expiryTime, unsigned int expiryFrame, NodeList& removedChildren);
  120. protected :
  121. virtual ~PagedLOD();
  122. void expandPerRangeDataTo(unsigned int pos);
  123. ref_ptr<Referenced> _databaseOptions;
  124. std::string _databasePath;
  125. unsigned int _frameNumberOfLastTraversal;
  126. unsigned int _numChildrenThatCannotBeExpired;
  127. bool _disableExternalChildrenPaging;
  128. PerRangeDataList _perRangeDataList;
  129. };
  130. }
  131. #endif