| 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 | |
|---|
| 14 | #ifndef OSG_PagedLOD |
|---|
| 15 | #define OSG_PagedLOD 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/LOD> |
|---|
| 18 | |
|---|
| 19 | namespace osg { |
|---|
| 20 | |
|---|
| 21 | /** PagedLOD. |
|---|
| 22 | */ |
|---|
| 23 | class OSG_EXPORT PagedLOD : public LOD |
|---|
| 24 | { |
|---|
| 25 | public : |
|---|
| 26 | |
|---|
| 27 | PagedLOD(); |
|---|
| 28 | |
|---|
| 29 | /** Copy constructor using CopyOp to manage deep vs shallow copy.*/ |
|---|
| 30 | PagedLOD(const PagedLOD&,const CopyOp& copyop=CopyOp::SHALLOW_COPY); |
|---|
| 31 | |
|---|
| 32 | META_Node(osg, PagedLOD); |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | virtual void traverse(NodeVisitor& nv); |
|---|
| 37 | |
|---|
| 38 | virtual bool addChild(Node *child); |
|---|
| 39 | |
|---|
| 40 | virtual bool addChild(Node *child, float min, float max); |
|---|
| 41 | |
|---|
| 42 | virtual bool addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f); |
|---|
| 43 | |
|---|
| 44 | virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1); |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /** Set the optional database osgDB::Options object to use when reading children.*/ |
|---|
| 48 | void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; } |
|---|
| 49 | |
|---|
| 50 | /** Get the optional database osgDB::Options object used when reading children.*/ |
|---|
| 51 | osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); } |
|---|
| 52 | |
|---|
| 53 | /** Get the optional database osgDB::Options object used when reading children.*/ |
|---|
| 54 | const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); } |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | /** Set the database path to prepend to children's filenames.*/ |
|---|
| 58 | void setDatabasePath(const std::string& path); |
|---|
| 59 | |
|---|
| 60 | /** Get the database path used to prepend to children's filenames.*/ |
|---|
| 61 | inline const std::string& getDatabasePath() const { return _databasePath; } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | struct OSG_EXPORT PerRangeData |
|---|
| 65 | { |
|---|
| 66 | PerRangeData(); |
|---|
| 67 | PerRangeData(const PerRangeData& prd); |
|---|
| 68 | PerRangeData& operator = (const PerRangeData& prd); |
|---|
| 69 | |
|---|
| 70 | std::string _filename; |
|---|
| 71 | float _priorityOffset; |
|---|
| 72 | float _priorityScale; |
|---|
| 73 | double _minExpiryTime; |
|---|
| 74 | unsigned int _minExpiryFrames; |
|---|
| 75 | double _timeStamp; |
|---|
| 76 | unsigned int _frameNumber; |
|---|
| 77 | unsigned int _frameNumberOfLastReleaseGLObjects; |
|---|
| 78 | osg::ref_ptr<osg::Referenced> _databaseRequest; |
|---|
| 79 | }; |
|---|
| 80 | |
|---|
| 81 | typedef std::vector<PerRangeData> PerRangeDataList; |
|---|
| 82 | |
|---|
| 83 | void setFileName(unsigned int childNo, const std::string& filename) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._filename=filename; } |
|---|
| 84 | const std::string& getFileName(unsigned int childNo) const { return _perRangeDataList[childNo]._filename; } |
|---|
| 85 | unsigned int getNumFileNames() const { return _perRangeDataList.size(); } |
|---|
| 86 | |
|---|
| 87 | |
|---|
| 88 | void setPriorityOffset(unsigned int childNo, float priorityOffset) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityOffset=priorityOffset; } |
|---|
| 89 | float getPriorityOffset(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityOffset; } |
|---|
| 90 | unsigned int getNumPriorityOffsets() const { return _perRangeDataList.size(); } |
|---|
| 91 | |
|---|
| 92 | void setPriorityScale(unsigned int childNo, float priorityScale) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityScale=priorityScale; } |
|---|
| 93 | float getPriorityScale(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityScale; } |
|---|
| 94 | unsigned int getNumPriorityScales() const { return _perRangeDataList.size(); } |
|---|
| 95 | |
|---|
| 96 | /** Sets the minimum amount of time, in seconds, that must pass without a child being traversed before it can be expired. */ |
|---|
| 97 | void setMinimumExpiryTime(unsigned int childNo, double minTime) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryTime=minTime; } |
|---|
| 98 | double getMinimumExpiryTime(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryTime; } |
|---|
| 99 | unsigned int getNumMinimumExpiryTimes() const { return _perRangeDataList.size(); } |
|---|
| 100 | |
|---|
| 101 | /** Sets the minimum number of frames that must be rendered without a child being traversed before it can be expired. */ |
|---|
| 102 | void setMinimumExpiryFrames(unsigned int childNo, unsigned int minFrames) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryFrames=minFrames; } |
|---|
| 103 | unsigned int getMinimumExpiryFrames(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryFrames; } |
|---|
| 104 | unsigned int getNumMinimumExpiryFrames() const { return _perRangeDataList.size(); } |
|---|
| 105 | |
|---|
| 106 | |
|---|
| 107 | void setTimeStamp(unsigned int childNo, double timeStamp) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._timeStamp=timeStamp; } |
|---|
| 108 | double getTimeStamp(unsigned int childNo) const { return _perRangeDataList[childNo]._timeStamp; } |
|---|
| 109 | unsigned int getNumTimeStamps() const { return _perRangeDataList.size(); } |
|---|
| 110 | |
|---|
| 111 | void setFrameNumber(unsigned int childNo, unsigned int frameNumber) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._frameNumber=frameNumber; } |
|---|
| 112 | unsigned getFrameNumber(unsigned int childNo) const { return _perRangeDataList[childNo]._frameNumber; } |
|---|
| 113 | unsigned int getNumFrameNumbers() const { return _perRangeDataList.size(); } |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests |
|---|
| 117 | * being carried on behalf of the DatabasePager. |
|---|
| 118 | * Note, in normal OSG usage you should not set this value yourself, as this will be managed by |
|---|
| 119 | * the osgDB::DatabasePager.*/ |
|---|
| 120 | osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _perRangeDataList[childNo]._databaseRequest; } |
|---|
| 121 | |
|---|
| 122 | /** Return the const DatabaseRequest object.*/ |
|---|
| 123 | const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _perRangeDataList[childNo]._databaseRequest; } |
|---|
| 124 | |
|---|
| 125 | |
|---|
| 126 | /** Set the frame number of the last time that this PageLOD node was traversed. |
|---|
| 127 | * Note, this frame number is automatically set by the traverse() method for all traversals (update, cull etc.). |
|---|
| 128 | */ |
|---|
| 129 | inline void setFrameNumberOfLastTraversal(unsigned int frameNumber) { _frameNumberOfLastTraversal=frameNumber; } |
|---|
| 130 | |
|---|
| 131 | /** Get the frame number of the last time that this PageLOD node was traversed.*/ |
|---|
| 132 | inline unsigned int getFrameNumberOfLastTraversal() const { return _frameNumberOfLastTraversal; } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | /** Set the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/ |
|---|
| 136 | inline void setNumChildrenThatCannotBeExpired(unsigned int num) { _numChildrenThatCannotBeExpired = num; } |
|---|
| 137 | |
|---|
| 138 | /** Get the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/ |
|---|
| 139 | unsigned int getNumChildrenThatCannotBeExpired() const { return _numChildrenThatCannotBeExpired; } |
|---|
| 140 | |
|---|
| 141 | /** Set wether you want to disable the paging in of external nodes.*/ |
|---|
| 142 | void setDisableExternalChildrenPaging(bool flag) { _disableExternalChildrenPaging = flag; } |
|---|
| 143 | |
|---|
| 144 | bool getDisableExternalChildrenPaging() const { return _disableExternalChildrenPaging; } |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | /** Remove the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number. |
|---|
| 149 | * The removed children are added to the removeChildren list passed into the method, |
|---|
| 150 | * this allows the children to be deleted later at the caller's discretion. |
|---|
| 151 | * Return true if children are removed, false otherwise. */ |
|---|
| 152 | virtual bool removeExpiredChildren(double expiryTime, unsigned int expiryFrame, NodeList& removedChildren); |
|---|
| 153 | |
|---|
| 154 | protected : |
|---|
| 155 | |
|---|
| 156 | virtual ~PagedLOD(); |
|---|
| 157 | |
|---|
| 158 | void expandPerRangeDataTo(unsigned int pos); |
|---|
| 159 | |
|---|
| 160 | ref_ptr<Referenced> _databaseOptions; |
|---|
| 161 | std::string _databasePath; |
|---|
| 162 | |
|---|
| 163 | unsigned int _frameNumberOfLastTraversal; |
|---|
| 164 | unsigned int _numChildrenThatCannotBeExpired; |
|---|
| 165 | bool _disableExternalChildrenPaging; |
|---|
| 166 | |
|---|
| 167 | PerRangeDataList _perRangeDataList; |
|---|
| 168 | }; |
|---|
| 169 | |
|---|
| 170 | } |
|---|
| 171 | |
|---|
| 172 | #endif |
|---|