2004-01-07 22:10:47 +08:00
|
|
|
#include "TileMapper.h"
|
|
|
|
#include "TXPPagedLOD.h"
|
|
|
|
using namespace txp;
|
|
|
|
|
|
|
|
TXPPagedLOD::TXPPagedLOD():
|
2004-01-22 01:26:23 +08:00
|
|
|
PagedLOD()
|
2004-01-07 22:10:47 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TXPPagedLOD::TXPPagedLOD(const TXPPagedLOD& plod,const osg::CopyOp& copyop):
|
2004-01-22 01:26:23 +08:00
|
|
|
PagedLOD(plod,copyop),
|
|
|
|
_tileIdentifier(plod._tileIdentifier)
|
2004-01-07 22:10:47 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TXPPagedLOD::~TXPPagedLOD()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void TXPPagedLOD::traverse(osg::NodeVisitor& nv)
|
|
|
|
{
|
|
|
|
|
2004-01-22 01:26:23 +08:00
|
|
|
TileMapper* tileMapper = dynamic_cast<TileMapper*>(nv.getUserData());
|
|
|
|
bool forceUseOfFirstChild = tileMapper ? (tileMapper->isNodeBlackListed(this)) : false;
|
2004-01-20 18:02:45 +08:00
|
|
|
|
2004-01-07 22:10:47 +08:00
|
|
|
double timeStamp = nv.getFrameStamp()?nv.getFrameStamp()->getReferenceTime():0.0;
|
|
|
|
bool updateTimeStamp = nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR;
|
|
|
|
|
|
|
|
switch(nv.getTraversalMode())
|
|
|
|
{
|
2004-01-22 01:26:23 +08:00
|
|
|
case(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN):
|
2004-01-07 22:14:38 +08:00
|
|
|
std::for_each(_children.begin(),_children.end(),osg::NodeAcceptOp(nv));
|
2004-01-07 22:10:47 +08:00
|
|
|
break;
|
2004-01-22 01:26:23 +08:00
|
|
|
case(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN):
|
2004-01-07 22:10:47 +08:00
|
|
|
{
|
|
|
|
float distance = nv.getDistanceToEyePoint(getCenter(),true);
|
|
|
|
|
2004-01-22 01:26:23 +08:00
|
|
|
int lastChildTraversed = -1;
|
2004-01-07 22:10:47 +08:00
|
|
|
bool needToLoadChild = false;
|
2004-01-22 01:26:23 +08:00
|
|
|
|
|
|
|
unsigned maxRangeSize = _rangeList.size();
|
|
|
|
if (maxRangeSize!=0 && forceUseOfFirstChild) maxRangeSize=1;
|
|
|
|
|
|
|
|
for(unsigned int i=0;i<maxRangeSize;++i)
|
2004-01-07 22:10:47 +08:00
|
|
|
{
|
2004-01-22 01:26:23 +08:00
|
|
|
if (forceUseOfFirstChild || _rangeList[i].first<=distance && distance<_rangeList[i].second)
|
2004-01-07 22:10:47 +08:00
|
|
|
{
|
|
|
|
if (i<_children.size())
|
|
|
|
{
|
2004-01-22 01:26:23 +08:00
|
|
|
if (updateTimeStamp) _perRangeDataList[i]._timeStamp=timeStamp;
|
2004-01-07 22:10:47 +08:00
|
|
|
|
2004-01-22 01:26:23 +08:00
|
|
|
//std::cout<<"PagedLOD::traverse() - Selecting child "<<i<<std::endl;
|
|
|
|
_children[i]->accept(nv);
|
|
|
|
lastChildTraversed = (int)i;
|
2004-01-07 22:10:47 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
needToLoadChild = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needToLoadChild)
|
|
|
|
{
|
|
|
|
unsigned int numChildren = _children.size();
|
|
|
|
|
|
|
|
//std::cout<<"PagedLOD::traverse() - falling back "<<std::endl;
|
|
|
|
// select the last valid child.
|
2004-01-22 01:26:23 +08:00
|
|
|
if (numChildren>0 && ((int)numChildren-1)!=lastChildTraversed)
|
2004-01-07 22:10:47 +08:00
|
|
|
{
|
|
|
|
//std::cout<<" to child "<<numChildren-1<<std::endl;
|
|
|
|
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<_perRangeDataList.size())
|
|
|
|
{
|
|
|
|
// compute priority from where abouts in the required range the distance falls.
|
|
|
|
float priority = (_rangeList[numChildren].second-distance)/(_rangeList[numChildren].second-_rangeList[numChildren].first);
|
|
|
|
|
|
|
|
// modify the priority according to the child's priority offset and scale.
|
|
|
|
priority = _perRangeDataList[numChildren]._priorityOffset + priority * _perRangeDataList[numChildren]._priorityScale;
|
|
|
|
|
|
|
|
//std::cout<<" requesting child "<<_fileNameList[numChildren]<<" priotity = "<<priority<<std::endl;
|
|
|
|
nv.getDatabaseRequestHandler()->requestNodeFile(_perRangeDataList[numChildren]._filename,this,priority,nv.getFrameStamp());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2004-01-22 01:26:23 +08:00
|
|
|
|