Added support for priority offset and scale into PagedLOD.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<std::string> 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<double> 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<PerRangeData> 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;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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("<<pos<<","<<numChildrenToRemove<<")"<<std::endl;
|
||||
}
|
||||
|
||||
void LOD::childInserted(unsigned int /*pos*/)
|
||||
{
|
||||
//std::cout<<"LOD::childInserted("<<pos<<")"<<std::endl;
|
||||
}
|
||||
|
||||
|
||||
bool LOD::addChild(Node *child, float min, float max)
|
||||
{
|
||||
if (Group::addChild(child))
|
||||
|
||||
@@ -13,8 +13,7 @@ PagedLOD::PagedLOD(const PagedLOD& plod,const CopyOp& copyop):
|
||||
LOD(plod,copyop),
|
||||
_radius(plod._radius),
|
||||
_numChildrenThatCannotBeExpired(plod._numChildrenThatCannotBeExpired),
|
||||
_fileNameList(plod._fileNameList),
|
||||
_timeStampList(plod._timeStampList)
|
||||
_perRangeDataList(plod._perRangeDataList)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -42,7 +41,7 @@ void PagedLOD::traverse(NodeVisitor& nv)
|
||||
{
|
||||
if (i<_children.size())
|
||||
{
|
||||
if (updateTimeStamp) _timeStampList[i]=timeStamp;
|
||||
if (updateTimeStamp) _perRangeDataList[i]._timeStamp=timeStamp;
|
||||
|
||||
//std::cout<<"PagedLOD::traverse() - Selecting child "<<i<<std::endl;
|
||||
_children[i]->accept(nv);
|
||||
@@ -64,16 +63,16 @@ void PagedLOD::traverse(NodeVisitor& nv)
|
||||
if (numChildren>0 && ((int)numChildren-1)!=lastChildTraversed)
|
||||
{
|
||||
//std::cout<<" to child "<<numChildren-1<<std::endl;
|
||||
if (updateTimeStamp) _timeStampList[numChildren-1]=timeStamp;
|
||||
if (updateTimeStamp) _perRangeDataList[numChildren-1]._timeStamp=timeStamp;
|
||||
_children[numChildren-1]->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 = "<<priority<<std::endl;
|
||||
nv.getDatabaseRequestHandler()->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("<<pos<<","<<numChildrenToRemove<<")"<<std::endl;
|
||||
}
|
||||
|
||||
void PagedLOD::childInserted(unsigned int pos)
|
||||
{
|
||||
LOD::childInserted(pos);
|
||||
//std::cout<<"PagedLOD::childInserted("<<pos<<")"<<std::endl;
|
||||
}
|
||||
|
||||
void PagedLOD::rangeRemoved(unsigned int pos, unsigned int numChildrenToRemove)
|
||||
{
|
||||
LOD::rangeRemoved(pos, numChildrenToRemove);
|
||||
std::cout<<"PagedLOD::rangeRemoved("<<pos<<","<<numChildrenToRemove<<")"<<std::endl;
|
||||
}
|
||||
|
||||
void PagedLOD::rangeInserted(unsigned int pos)
|
||||
{
|
||||
LOD::rangeInserted(pos);
|
||||
std::cout<<"PagedLOD::rangeInserted("<<pos<<")"<<std::endl;
|
||||
expandPerRangeDataTo(pos);
|
||||
}
|
||||
|
||||
void PagedLOD::expandPerRangeDataTo(unsigned int pos)
|
||||
{
|
||||
if (pos>=_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]<expiryTime)
|
||||
if (!_perRangeDataList[i]._filename.empty() && _perRangeDataList[i]._timeStamp<expiryTime)
|
||||
{
|
||||
//std::cout<<"Removing child "<<_children[i].get()<<std::endl;
|
||||
removedChildren.push_back(_children[i]);
|
||||
|
||||
@@ -46,15 +46,12 @@ bool LOD_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
// set up coordinates.
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
int capacity;
|
||||
|
||||
if (matchFirst)
|
||||
{
|
||||
fr += 2;
|
||||
}
|
||||
else if (fr[1].getInt(capacity))
|
||||
else
|
||||
{
|
||||
lod.getRangeList().reserve(capacity);
|
||||
fr += 3;
|
||||
}
|
||||
|
||||
@@ -86,15 +83,12 @@ bool LOD_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
// set up coordinates.
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
int capacity;
|
||||
|
||||
if (matchFirst)
|
||||
{
|
||||
fr += 2;
|
||||
}
|
||||
else if (fr[1].getInt(capacity))
|
||||
else
|
||||
{
|
||||
lod.getRangeList().reserve(capacity);
|
||||
fr += 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,15 +49,12 @@ bool PagedLOD_readLocalData(Object& obj, Input& fr)
|
||||
|
||||
// set up coordinates.
|
||||
int entry = fr[0].getNoNestedBrackets();
|
||||
int capacity;
|
||||
|
||||
if (matchFirst)
|
||||
{
|
||||
fr += 2;
|
||||
}
|
||||
else if (fr[1].getInt(capacity))
|
||||
else
|
||||
{
|
||||
lod.getFileNameList().reserve(capacity);
|
||||
fr += 3;
|
||||
}
|
||||
|
||||
|
||||
@@ -189,6 +189,8 @@ osg::Node* TXPNode::addPagedLODTile(int x, int y, int lod)
|
||||
|
||||
osg::PagedLOD* pagedLOD = new osg::PagedLOD;
|
||||
pagedLOD->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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user