2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
|
2003-07-08 22:44:00 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This library is open source and may be redistributed and/or modified under
|
|
|
|
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
|
2003-07-08 22:44:00 +08:00
|
|
|
* (at your option) any later version. The full license is in LICENSE file
|
|
|
|
* included with this distribution, and on the openscenegraph.org website.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2003-07-08 22:44:00 +08:00
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2003-07-08 22:44:00 +08:00
|
|
|
* OpenSceneGraph Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef OSG_PagedLOD
|
|
|
|
#define OSG_PagedLOD 1
|
|
|
|
|
|
|
|
#include <osg/LOD>
|
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** PagedLOD.
|
|
|
|
*/
|
2005-04-12 01:14:17 +08:00
|
|
|
class OSG_EXPORT PagedLOD : public LOD
|
2003-07-08 22:44:00 +08:00
|
|
|
{
|
|
|
|
public :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-07-10 22:53:07 +08:00
|
|
|
PagedLOD();
|
2003-07-08 22:44:00 +08:00
|
|
|
|
|
|
|
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
|
|
|
|
PagedLOD(const PagedLOD&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
|
|
|
|
|
|
|
|
META_Node(osg, PagedLOD);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
virtual void traverse(NodeVisitor& nv);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
using osg::Group::addChild;
|
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
virtual bool addChild(Node *child);
|
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
virtual bool addChild(Node *child, float rmin, float rmax);
|
|
|
|
|
|
|
|
template<class T> bool addChild( const ref_ptr<T>& child, float rmin, float rmax) { return addChild(child.get(), rmin, rmax); }
|
|
|
|
|
|
|
|
virtual bool addChild(Node *child, float rmin, float rmax, const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f);
|
2003-07-08 22:44:00 +08:00
|
|
|
|
2015-10-22 22:14:53 +08:00
|
|
|
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); }
|
2003-07-08 22:44:00 +08:00
|
|
|
|
2006-05-02 17:45:31 +08:00
|
|
|
virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);
|
2009-05-11 19:39:12 +08:00
|
|
|
|
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
/** Set the optional database osgDB::Options object to use when reading children.*/
|
2009-05-11 19:39:12 +08:00
|
|
|
void setDatabaseOptions(osg::Referenced* options) { _databaseOptions = options; }
|
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
/** Get the optional database osgDB::Options object used when reading children.*/
|
2009-05-11 19:39:12 +08:00
|
|
|
osg::Referenced* getDatabaseOptions() { return _databaseOptions.get(); }
|
|
|
|
|
2012-11-08 19:19:31 +08:00
|
|
|
/** Get the optional database osgDB::Options object used when reading children.*/
|
2009-05-11 19:39:12 +08:00
|
|
|
const osg::Referenced* getDatabaseOptions() const { return _databaseOptions.get(); }
|
2004-10-06 17:31:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
/** Set the database path to prepend to children's filenames.*/
|
|
|
|
void setDatabasePath(const std::string& path);
|
|
|
|
|
|
|
|
/** Get the database path used to prepend to children's filenames.*/
|
|
|
|
inline const std::string& getDatabasePath() const { return _databasePath; }
|
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2005-04-12 01:14:17 +08:00
|
|
|
struct OSG_EXPORT PerRangeData
|
2004-01-06 04:45:28 +08:00
|
|
|
{
|
2004-01-07 16:39:33 +08:00
|
|
|
PerRangeData();
|
|
|
|
PerRangeData(const PerRangeData& prd);
|
|
|
|
PerRangeData& operator = (const PerRangeData& prd);
|
2003-07-08 22:44:00 +08:00
|
|
|
|
2008-05-22 05:09:45 +08:00
|
|
|
std::string _filename;
|
|
|
|
float _priorityOffset;
|
|
|
|
float _priorityScale;
|
2012-02-06 20:06:40 +08:00
|
|
|
double _minExpiryTime;
|
|
|
|
unsigned int _minExpiryFrames;
|
2008-05-22 05:09:45 +08:00
|
|
|
double _timeStamp;
|
2010-12-23 04:11:05 +08:00
|
|
|
unsigned int _frameNumber;
|
|
|
|
unsigned int _frameNumberOfLastReleaseGLObjects;
|
2008-05-22 05:09:45 +08:00
|
|
|
osg::ref_ptr<osg::Referenced> _databaseRequest;
|
2004-01-06 04:45:28 +08:00
|
|
|
};
|
2003-07-08 22:44:00 +08:00
|
|
|
|
2004-01-06 04:45:28 +08:00
|
|
|
typedef std::vector<PerRangeData> PerRangeDataList;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-01-06 04:45:28 +08:00
|
|
|
void setFileName(unsigned int childNo, const std::string& filename) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._filename=filename; }
|
|
|
|
const std::string& getFileName(unsigned int childNo) const { return _perRangeDataList[childNo]._filename; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumFileNames() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
|
2004-01-06 04:45:28 +08:00
|
|
|
|
|
|
|
|
|
|
|
void setPriorityOffset(unsigned int childNo, float priorityOffset) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityOffset=priorityOffset; }
|
|
|
|
float getPriorityOffset(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityOffset; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumPriorityOffsets() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
|
2004-01-06 04:45:28 +08:00
|
|
|
|
|
|
|
void setPriorityScale(unsigned int childNo, float priorityScale) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityScale=priorityScale; }
|
|
|
|
float getPriorityScale(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityScale; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumPriorityScales() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
|
2004-01-06 04:45:28 +08:00
|
|
|
|
2012-02-06 20:06:40 +08:00
|
|
|
/** Sets the minimum amount of time, in seconds, that must pass without a child being traversed before it can be expired. */
|
|
|
|
void setMinimumExpiryTime(unsigned int childNo, double minTime) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryTime=minTime; }
|
|
|
|
double getMinimumExpiryTime(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryTime; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumMinimumExpiryTimes() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
|
2012-02-06 20:06:40 +08:00
|
|
|
|
|
|
|
/** Sets the minimum number of frames that must be rendered without a child being traversed before it can be expired. */
|
|
|
|
void setMinimumExpiryFrames(unsigned int childNo, unsigned int minFrames) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._minExpiryFrames=minFrames; }
|
|
|
|
unsigned int getMinimumExpiryFrames(unsigned int childNo) const { return _perRangeDataList[childNo]._minExpiryFrames; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumMinimumExpiryFrames() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
|
2012-02-06 20:06:40 +08:00
|
|
|
|
2004-01-06 04:45:28 +08:00
|
|
|
|
|
|
|
void setTimeStamp(unsigned int childNo, double timeStamp) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._timeStamp=timeStamp; }
|
|
|
|
double getTimeStamp(unsigned int childNo) const { return _perRangeDataList[childNo]._timeStamp; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumTimeStamps() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
|
2003-07-08 22:44:00 +08:00
|
|
|
|
2010-12-23 04:11:05 +08:00
|
|
|
void setFrameNumber(unsigned int childNo, unsigned int frameNumber) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._frameNumber=frameNumber; }
|
|
|
|
unsigned getFrameNumber(unsigned int childNo) const { return _perRangeDataList[childNo]._frameNumber; }
|
2013-05-15 00:12:21 +08:00
|
|
|
unsigned int getNumFrameNumbers() const { return static_cast<unsigned int>(_perRangeDataList.size()); }
|
2008-08-18 00:52:35 +08:00
|
|
|
|
2003-12-09 20:08:27 +08:00
|
|
|
|
2012-03-22 01:36:20 +08:00
|
|
|
/** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
|
2008-05-22 05:09:45 +08:00
|
|
|
* being carried on behalf of the DatabasePager.
|
2012-03-22 01:36:20 +08:00
|
|
|
* Note, in normal OSG usage you should not set this value yourself, as this will be managed by
|
2008-05-22 05:09:45 +08:00
|
|
|
* the osgDB::DatabasePager.*/
|
|
|
|
osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _perRangeDataList[childNo]._databaseRequest; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
|
|
|
/** Return the const DatabaseRequest object.*/
|
2008-05-22 05:09:45 +08:00
|
|
|
const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _perRangeDataList[childNo]._databaseRequest; }
|
|
|
|
|
|
|
|
|
2004-09-22 01:26:08 +08:00
|
|
|
/** Set the frame number of the last time that this PageLOD node was traversed.
|
2012-03-22 01:36:20 +08:00
|
|
|
* Note, this frame number is automatically set by the traverse() method for all traversals (update, cull etc.).
|
2004-09-22 01:26:08 +08:00
|
|
|
*/
|
2010-12-23 04:11:05 +08:00
|
|
|
inline void setFrameNumberOfLastTraversal(unsigned int frameNumber) { _frameNumberOfLastTraversal=frameNumber; }
|
2004-09-22 01:26:08 +08:00
|
|
|
|
|
|
|
/** Get the frame number of the last time that this PageLOD node was traversed.*/
|
2010-12-23 04:11:05 +08:00
|
|
|
inline unsigned int getFrameNumberOfLastTraversal() const { return _frameNumberOfLastTraversal; }
|
2004-09-22 01:26:08 +08:00
|
|
|
|
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Set the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
|
2003-12-09 20:08:27 +08:00
|
|
|
inline void setNumChildrenThatCannotBeExpired(unsigned int num) { _numChildrenThatCannotBeExpired = num; }
|
|
|
|
|
2004-09-03 03:10:33 +08:00
|
|
|
/** Get the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
|
2003-12-09 20:08:27 +08:00
|
|
|
unsigned int getNumChildrenThatCannotBeExpired() const { return _numChildrenThatCannotBeExpired; }
|
|
|
|
|
2009-07-16 18:13:41 +08:00
|
|
|
/** Set wether you want to disable the paging in of external nodes.*/
|
|
|
|
void setDisableExternalChildrenPaging(bool flag) { _disableExternalChildrenPaging = flag; }
|
|
|
|
|
|
|
|
bool getDisableExternalChildrenPaging() const { return _disableExternalChildrenPaging; }
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-08-18 00:52:35 +08:00
|
|
|
/** Remove the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number.
|
2004-09-22 01:26:08 +08:00
|
|
|
* The removed children are added to the removeChildren list passed into the method,
|
|
|
|
* this allows the children to be deleted later at the caller's discretion.
|
|
|
|
* Return true if children are removed, false otherwise. */
|
2010-12-23 04:11:05 +08:00
|
|
|
virtual bool removeExpiredChildren(double expiryTime, unsigned int expiryFrame, NodeList& removedChildren);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2003-07-08 22:44:00 +08:00
|
|
|
protected :
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2008-05-30 19:43:04 +08:00
|
|
|
virtual ~PagedLOD();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2004-01-06 04:45:28 +08:00
|
|
|
void expandPerRangeDataTo(unsigned int pos);
|
|
|
|
|
2009-05-11 19:39:12 +08:00
|
|
|
ref_ptr<Referenced> _databaseOptions;
|
2004-10-06 17:31:34 +08:00
|
|
|
std::string _databasePath;
|
|
|
|
|
2010-12-23 04:11:05 +08:00
|
|
|
unsigned int _frameNumberOfLastTraversal;
|
2004-09-22 01:26:08 +08:00
|
|
|
unsigned int _numChildrenThatCannotBeExpired;
|
2009-07-16 18:13:41 +08:00
|
|
|
bool _disableExternalChildrenPaging;
|
|
|
|
|
2004-01-06 04:45:28 +08:00
|
|
|
PerRangeDataList _perRangeDataList;
|
2003-07-08 22:44:00 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|