From 413064fc6ef38a9b77b5d804c7fd4bdecd6d6922 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Mon, 5 Jan 2004 20:45:28 +0000 Subject: [PATCH] Added support for priority offset and scale into PagedLOD. --- include/osg/Group | 3 ++ include/osg/LOD | 9 ++-- include/osg/PagedLOD | 79 ++++++++++++++++++++++----------- src/osg/Group.cpp | 5 +++ src/osg/LOD.cpp | 21 +++++++-- src/osg/PagedLOD.cpp | 77 ++++++++++++++++++-------------- src/osgPlugins/osg/LOD.cpp | 10 +---- src/osgPlugins/osg/PagedLOD.cpp | 5 +-- src/osgPlugins/txp/TXPNode.cpp | 2 + src/osgProducer/Viewer.cpp | 6 +-- 10 files changed, 137 insertions(+), 80 deletions(-) diff --git a/include/osg/Group b/include/osg/Group index 92a72c6da..2852fa200 100644 --- a/include/osg/Group +++ b/include/osg/Group @@ -123,6 +123,9 @@ class SG_EXPORT Group : public Node virtual ~Group(); virtual bool computeBound() const; + + virtual void childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) {} + virtual void childInserted(unsigned int /*pos*/) {} NodeList _children; diff --git a/include/osg/LOD b/include/osg/LOD index cfc5879e4..3e6cb50fc 100644 --- a/include/osg/LOD +++ b/include/osg/LOD @@ -86,15 +86,18 @@ class SG_EXPORT LOD : public Group * An LOD which has been fully set up will have getNumChildren()==getNumRanges(). */ inline unsigned int getNumRanges() const { return _rangeList.size(); } - /** return the list of MinMax ranges for each child.*/ - inline RangeList& getRangeList() { return _rangeList; } - /** return the list of MinMax ranges for each child.*/ inline const RangeList& getRangeList() const { return _rangeList; } protected : virtual ~LOD() {} + virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove); + virtual void childInserted(unsigned int pos); + + virtual void rangeRemoved(unsigned int pos, unsigned int numChildrenToRemove) {} + virtual void rangeInserted(unsigned int pos) {} + CenterMode _centerMode; Vec3 _userDefinedCenter; diff --git a/include/osg/PagedLOD b/include/osg/PagedLOD index f1040d956..1b6e2c37d 100644 --- a/include/osg/PagedLOD +++ b/include/osg/PagedLOD @@ -39,40 +39,59 @@ class SG_EXPORT PagedLOD : public LOD virtual bool addChild(Node *child, float min, float max); - virtual bool addChild(Node *child, float min, float max,const std::string& filename); + virtual bool addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f); virtual bool removeChild(Node *child); - - typedef std::vector FileNameList; - - void setFileName(unsigned int childNo, const std::string& filename); - const std::string& getFileName(unsigned int childNo) const { return _fileNameList[childNo]; } - /** returns the number of filenames currently set. */ - inline unsigned int getNumFileNames() const { return _fileNameList.size(); } - - /** return the list of filename.*/ - inline FileNameList& getFileNameList() { return _fileNameList; } + struct PerRangeData + { + PerRangeData(): + _priorityOffset(0.0f), + _priorityScale(0.0f), + _timeStamp(0.0f) {} - /** return the list of filename.*/ - inline const FileNameList& getFileNameList() const { return _fileNameList; } + PerRangeData(const PerRangeData& prd): + _filename(prd._filename), + _priorityOffset(prd._priorityOffset), + _priorityScale(prd._priorityScale), + _timeStamp(prd._timeStamp) {} + + PerRangeData& operator = (const PerRangeData& prd) + { + if (this==&prd) return *this; + _filename = prd._filename; + _priorityOffset = prd._priorityOffset; + _priorityScale = prd._priorityScale; + _timeStamp = prd._timeStamp; + } - typedef std::vector TimeStampList; + std::string _filename; + float _priorityOffset; + float _priorityScale; + double _timeStamp; + }; - void setTimeStamp(unsigned int childNo, double timeStamp); - - double getTimeStamp(unsigned int childNo) const { return _timeStampList[childNo]; } + typedef std::vector PerRangeDataList; - /** returns the number of filenames currently set. */ - inline unsigned int getNumTimeStamps() const { return _fileNameList.size(); } + 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; } + unsigned int getNumFileNames() const { return _perRangeDataList.size(); } - /** return the list of time stamps.*/ - inline TimeStampList& getTimeStampList() { return _timeStampList; } - - /** return the list of time stamps.*/ - inline const TimeStampList& getTimeStampList() const { return _timeStampList; } + + void setPriorityOffset(unsigned int childNo, float priorityOffset) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityOffset=priorityOffset; } + float getPriorityOffset(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityOffset; } + unsigned int getNumPriorityOffsets() const { return _perRangeDataList.size(); } + + void setPriorityScale(unsigned int childNo, float priorityScale) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityScale=priorityScale; } + float getPriorityScale(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityScale; } + unsigned int getNumPriorityScales() const { return _perRangeDataList.size(); } + + + void setTimeStamp(unsigned int childNo, double timeStamp) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._timeStamp=timeStamp; } + double getTimeStamp(unsigned int childNo) const { return _perRangeDataList[childNo]._timeStamp; } + unsigned int getNumTimeStamps() const { return _perRangeDataList.size(); } /** Set the object-space reference radius of the volume enclosed by the PagedLOD. @@ -100,10 +119,18 @@ class SG_EXPORT PagedLOD : public LOD virtual bool computeBound() const; + virtual void childRemoved(unsigned int pos, unsigned int numChildrenToRemove); + virtual void childInserted(unsigned int pos); + + virtual void rangeRemoved(unsigned int pos, unsigned int numChildrenToRemove); + virtual void rangeInserted(unsigned int pos); + + void expandPerRangeDataTo(unsigned int pos); + float _radius; unsigned int _numChildrenThatCannotBeExpired; - FileNameList _fileNameList; - TimeStampList _timeStampList; + + PerRangeDataList _perRangeDataList; }; } diff --git a/src/osg/Group.cpp b/src/osg/Group.cpp index 229fc9e09..bd650b7d4 100644 --- a/src/osg/Group.cpp +++ b/src/osg/Group.cpp @@ -95,6 +95,9 @@ bool Group::insertChild( unsigned int index, Node *child ) // register as parent of child. child->addParent(this); + + // tell any subclasses that a child has been inserted so that they can update themselves. + childInserted(index); dirtyBound(); @@ -168,6 +171,8 @@ bool Group::removeChild(unsigned int pos,unsigned int numChildrenToRemove) _children.erase(_children.begin()+pos,_children.begin()+endOfRemoveRange); + childRemoved(pos,endOfRemoveRange-pos); + if (appCallbackRemoved) { setNumChildrenRequiringUpdateTraversal(getNumChildrenRequiringUpdateTraversal()-appCallbackRemoved); diff --git a/src/osg/LOD.cpp b/src/osg/LOD.cpp index 662783d55..506514322 100644 --- a/src/osg/LOD.cpp +++ b/src/osg/LOD.cpp @@ -61,16 +61,31 @@ bool LOD::addChild( Node *child ) { if (Group::addChild(child)) { - float maxRange = 0.0f; - if (!_rangeList.empty()) maxRange=_rangeList.back().second; - if (_children.size()>_rangeList.size()) _rangeList.resize(_children.size(),MinMaxPair(maxRange,maxRange)); + if (_children.size()>_rangeList.size()) + { + float maxRange = !_rangeList.empty()? + maxRange=_rangeList.back().second : 0.0f; + + _rangeList.resize(_children.size(),MinMaxPair(maxRange,maxRange)); + } return true; } return false; } +void LOD::childRemoved(unsigned int /*pos*/, unsigned int /*numChildrenToRemove*/) +{ + //std::cout<<"LOD::childRemoved("<accept(nv); @@ -64,16 +63,16 @@ void PagedLOD::traverse(NodeVisitor& nv) if (numChildren>0 && ((int)numChildren-1)!=lastChildTraversed) { //std::cout<<" to child "<accept(nv); } // now request the loading of the next unload child. - if (nv.getDatabaseRequestHandler() && numChildren<_fileNameList.size()) + if (nv.getDatabaseRequestHandler() && numChildren<_perRangeDataList.size()) { float priority = (_rangeList[numChildren].second-distance)/(_rangeList[numChildren].second-_rangeList[numChildren].first); //std::cout<<" requesting child "<<_fileNameList[numChildren]<<" priotity = "<requestNodeFile(_fileNameList[numChildren],this,priority,nv.getFrameStamp()); + nv.getDatabaseRequestHandler()->requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp()); } @@ -103,12 +102,41 @@ bool PagedLOD::computeBound() const } } +void PagedLOD::childRemoved(unsigned int pos, unsigned int numChildrenToRemove) +{ + LOD::childRemoved(pos, numChildrenToRemove); + //std::cout<<"PagedLOD::childRemoved("<=_perRangeDataList.size()) _perRangeDataList.resize(pos+1); +} + bool PagedLOD::addChild( Node *child ) { if (LOD::addChild(child)) { - if (_children.size()>_fileNameList.size()) _fileNameList.resize(_children.size()); - if (_children.size()>_timeStampList.size()) _timeStampList.resize(_children.size(),0); + expandPerRangeDataTo(_children.size()); return true; } return false; @@ -118,24 +146,20 @@ bool PagedLOD::addChild(Node *child, float min, float max) { if (LOD::addChild(child,min,max)) { - if (_children.size()>_fileNameList.size()) _fileNameList.resize(_children.size()); - if (_children.size()>_timeStampList.size()) _timeStampList.resize(_children.size(),0.0); - + expandPerRangeDataTo(_children.size()); return true; } return false; } -bool PagedLOD::addChild(Node *child, float min, float max,const std::string& filename) +bool PagedLOD::addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset, float priorityScale) { if (LOD::addChild(child,min,max)) { - if (_children.size()>_fileNameList.size()) _fileNameList.resize(_children.size()); - if (_children.size()>_timeStampList.size()) _timeStampList.resize(_children.size(),0.0); - - _fileNameList[_children.size()-1] = filename; - + setFileName(_children.size()-1,filename); + setPriorityOffset(_children.size()-1,priorityOffset); + setPriorityScale(_children.size()-1,priorityScale); return true; } return false; @@ -147,31 +171,18 @@ bool PagedLOD::removeChild( Node *child ) unsigned int pos=getChildIndex(child); if (pos==_children.size()) return false; - _rangeList.erase(_rangeList.begin()+pos); - _fileNameList.erase(_fileNameList.begin()+pos); - _timeStampList.erase(_timeStampList.begin()+pos); + if (pos<_rangeList.size()) _rangeList.erase(_rangeList.begin()+pos); + if (pos<_perRangeDataList.size()) _perRangeDataList.erase(_perRangeDataList.begin()+pos); return Group::removeChild(child); } -void PagedLOD::setFileName(unsigned int childNo, const std::string& filename) -{ - if (childNo>=_fileNameList.size()) _fileNameList.resize(childNo+1); - _fileNameList[childNo] = filename; -} - -void PagedLOD::setTimeStamp(unsigned int childNo, double timeStamp) -{ - if (childNo>=_timeStampList.size()) _timeStampList.resize(childNo+1,0.0); - _timeStampList[childNo] = timeStamp; -} - void PagedLOD::removeExpiredChildren(double expiryTime,NodeList& removedChildren) { for(unsigned int i=_children.size();i>_numChildrenThatCannotBeExpired;) { --i; - if (!_fileNameList[i].empty() && _timeStampList[i]setFileName(0,pagedLODfile); + pagedLOD->setPriorityOffset(0,1.0f); + pagedLOD->setPriorityScale(0,1.0f); pagedLOD->setRange(0,0.0,info.maxRange); pagedLOD->setCenter(info.center); pagedLOD->setRadius(info.radius); diff --git a/src/osgProducer/Viewer.cpp b/src/osgProducer/Viewer.cpp index 2b7184645..896c2096b 100644 --- a/src/osgProducer/Viewer.cpp +++ b/src/osgProducer/Viewer.cpp @@ -402,12 +402,12 @@ public: double availableTime = 0.0025; // 5 ms - // compile any GL objects that are required. - _databasePager->compileRenderingObjects(*(_sceneView->getState()),availableTime); - // flush deleted GL objects. _sceneView->flushDeletedGLObjects(availableTime); + // compile any GL objects that are required. + _databasePager->compileRenderingObjects(*(_sceneView->getState()),availableTime); + }