1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
23class OSG_EXPORT PagedLOD : public LOD
27 /** Default constructor
28 * The default constructor sets
29 * - the center mode to USER_DEFINED_CENTER and
30 * - enables the paging of external children.
31 * @warning The center mode setting of the default constructor differs
32 * from the setting of LOD's default constructor! Therefore,
33 * the PagedLOD and LOD nodes may show different behaviour with
34 * their default settings when using them with the same subgraph.
35 * This is a result of the differences in determining the node's center.
36 * @note Though the bounding spheres of both nodes with their default settings
37 * will not differ if they have same subgraph.
38 * @sa LOD::setCenter, LOD::setRadius */
41 /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
42 PagedLOD(const PagedLOD&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
44 META_Node(osg, PagedLOD);
46 virtual void traverse(NodeVisitor& nv);
48 using osg::Group::addChild;
50 virtual bool addChild(Node *child);
52 virtual bool addChild(Node *child, float rmin, float rmax);
54 template<class T> bool addChild( const ref_ptr<T>& child, float rmin, float rmax) { return addChild(child.get(), rmin, rmax); }
56 virtual bool addChild(Node *child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f);
58 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); }
60 virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);
63 /** Set the optional database osgDB::Options object to use when reading children.*/
64 void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
66 /** Get the optional database osgDB::Options object used when reading children.*/
67 osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
69 /** Get the optional database osgDB::Options object used when reading children.*/
70 const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }
73 /** Set the database path to prepend to children's filenames.*/
74 void setDatabasePath(const std::string& path);
76 /** Get the database path used to prepend to children's filenames.*/
77 inline const std::string& getDatabasePath() const { return _databasePath; }
80 struct OSG_EXPORT PerRangeData
83 PerRangeData(const PerRangeData& prd);
84 PerRangeData& operator = (const PerRangeData& prd);
86 std::string _filename;
87 float _priorityOffset;
89 double _minExpiryTime;
90 unsigned int _minExpiryFrames;
92 unsigned int _frameNumber;
93 unsigned int _frameNumberOfLastReleaseGLObjects;
94 osg::ref_ptr<osg::Referenced> _databaseRequest;
97 typedef std::vector<PerRangeData> PerRangeDataList;
99 void setFileName(unsigned int childNo, const std::string& filename) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._filename=filename; }
100 const std::string& getFileName(unsigned int childNo) const { return _perRangeDataList[childNo]._filename; }
101 unsigned int getNumFileNames() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
104 void setPriorityOffset(unsigned int childNo, float priorityOffset) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityOffset=priorityOffset; }
105 float getPriorityOffset(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityOffset; }
106 unsigned int getNumPriorityOffsets() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
108 void setPriorityScale(unsigned int childNo, float priorityScale) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityScale=priorityScale; }
109 float getPriorityScale(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityScale; }
110 unsigned int getNumPriorityScales() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
112 /** Sets the minimum amount of time, in seconds, that must pass without a child being traversed before it can be expired. */
113 void setMinimumExpiryTime(unsigned int childNo, double minTime) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryTime=minTime; }
114 double getMinimumExpiryTime(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryTime; }
115 unsigned int getNumMinimumExpiryTimes() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
117 /** Sets the minimum number of frames that must be rendered without a child being traversed before it can be expired. */
118 void setMinimumExpiryFrames(unsigned int childNo, unsigned int minFrames) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryFrames=minFrames; }
119 unsigned int getMinimumExpiryFrames(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryFrames; }
120 unsigned int getNumMinimumExpiryFrames() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
123 void setTimeStamp(unsigned int childNo, double timeStamp) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._timeStamp=timeStamp; }
124 double getTimeStamp(unsigned int childNo) const { return _perRangeDataList[childNo]._timeStamp; }
125 unsigned int getNumTimeStamps() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
127 void setFrameNumber(unsigned int childNo, unsigned int frameNumber) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._frameNumber=frameNumber; }
128 unsigned getFrameNumber(unsigned int childNo) const { return _perRangeDataList[childNo]._frameNumber; }
129 unsigned int getNumFrameNumbers() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
132 /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
133 * being carried on behalf of the DatabasePager.
134 * Note, in normal OSG usage you should not set this value yourself, as this will be managed by
135 * the osgDB::DatabasePager.*/
136 osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _perRangeDataList[childNo]._databaseRequest; }
138 /** Return the const DatabaseRequest object.*/
139 const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _perRangeDataList[childNo]._databaseRequest; }
142 /** Set the frame number of the last time that this PageLOD node was traversed.
143 * Note, this frame number is automatically set by the traverse() method for all traversals (update, cull etc.).
145 inline void setFrameNumberOfLastTraversal(unsigned int frameNumber) { _frameNumberOfLastTraversal=frameNumber; }
147 /** Get the frame number of the last time that this PageLOD node was traversed.*/
148 inline unsigned int getFrameNumberOfLastTraversal() const { return _frameNumberOfLastTraversal; }
151 /** Set the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
152 inline void setNumChildrenThatCannotBeExpired(unsigned int num) { _numChildrenThatCannotBeExpired = num; }
154 /** Get the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
155 unsigned int getNumChildrenThatCannotBeExpired() const { return _numChildrenThatCannotBeExpired; }
157 /** Set whether you want to disable the paging in of external nodes.*/
158 void setDisableExternalChildrenPaging(bool flag) { _disableExternalChildrenPaging = flag; }
160 bool getDisableExternalChildrenPaging() const { return _disableExternalChildrenPaging; }
164 /** Remove the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number.
165 * The removed children are added to the removeChildren list passed into the method,
166 * this allows the children to be deleted later at the caller's discretion.
167 * Return true if children are removed, false otherwise. */
168 virtual bool removeExpiredChildren(double expiryTime, unsigned int expiryFrame, NodeList& removedChildren);
174 void expandPerRangeDataTo(unsigned int pos);
176 ref_ptr<Referenced> _databaseOptions;
177 std::string _databasePath;
179 unsigned int _frameNumberOfLastTraversal;
180 unsigned int _numChildrenThatCannotBeExpired;
181 bool _disableExternalChildrenPaging;
183 PerRangeDataList _perRangeDataList;