diff --git a/src/osgPlugins/txp/TXPPagedLOD.cpp b/src/osgPlugins/txp/TXPPagedLOD.cpp index da7f3dc17..170b76a92 100644 --- a/src/osgPlugins/txp/TXPPagedLOD.cpp +++ b/src/osgPlugins/txp/TXPPagedLOD.cpp @@ -6,7 +6,8 @@ TXPPagedLOD::TXPPagedLOD(): PagedLOD(), _tileX(-1), _tileY(-1), -_tileLOD(-1) +_tileLOD(-1), +_lastChildTraversed(-1) { } @@ -14,12 +15,14 @@ TXPPagedLOD::TXPPagedLOD(const TXPPagedLOD& plod,const osg::CopyOp& copyop): PagedLOD(plod,copyop), _tileX(plod._tileX), _tileY(plod._tileY), -_tileLOD(plod._tileLOD) +_tileLOD(plod._tileLOD), +_lastChildTraversed(plod._lastChildTraversed) { } TXPPagedLOD::~TXPPagedLOD() { + TileMapper::instance()->removePagedLOD(_tileX,_tileY,_tileLOD); } void TXPPagedLOD::traverse(osg::NodeVisitor& nv) @@ -37,7 +40,7 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) { float distance = nv.getDistanceToEyePoint(getCenter(),true); - int lastChildTraversed = -1; + _lastChildTraversed = -1; bool needToLoadChild = false; bool rollBack = false; for(unsigned int i=0;i<_rangeList.size();++i) @@ -66,7 +69,7 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) { if (updateTimeStamp) _perRangeDataList[i]._timeStamp=timeStamp; _children[i]->accept(nv); - lastChildTraversed = (int)i; + _lastChildTraversed = (int)i; } } else @@ -80,7 +83,7 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) { if (updateTimeStamp) _perRangeDataList[0]._timeStamp=timeStamp; _children[0]->accept(nv); - lastChildTraversed = 0; + _lastChildTraversed = 0; //std::cout << "Rolling back" << std::endl; } @@ -90,11 +93,12 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) //std::cout<<"PagedLOD::traverse() - falling back "<0 && ((int)numChildren-1)!=lastChildTraversed) + if (numChildren>0 && ((int)numChildren-1)!=_lastChildTraversed) { //std::cout<<" to child "<accept(nv); + _lastChildTraversed = numChildren-1; } // now request the loading of the next unload child. @@ -120,5 +124,3 @@ void TXPPagedLOD::traverse(osg::NodeVisitor& nv) break; } } - - diff --git a/src/osgPlugins/txp/TXPPagedLOD.h b/src/osgPlugins/txp/TXPPagedLOD.h index 5673e0962..ee3927681 100644 --- a/src/osgPlugins/txp/TXPPagedLOD.h +++ b/src/osgPlugins/txp/TXPPagedLOD.h @@ -63,14 +63,16 @@ namespace txp _neighbours.push_back(n); } - int _tileX; + int _tileX; int _tileY; int _tileLOD; + inline const int getLastTraversedChild() const { return _lastChildTraversed; } + protected: virtual ~TXPPagedLOD(); - + int _lastChildTraversed; struct Neighbour { diff --git a/src/osgPlugins/txp/TXPSeamLOD.cpp b/src/osgPlugins/txp/TXPSeamLOD.cpp index 6710e6ceb..3a5604a78 100644 --- a/src/osgPlugins/txp/TXPSeamLOD.cpp +++ b/src/osgPlugins/txp/TXPSeamLOD.cpp @@ -1,6 +1,7 @@ #include "TXPSeamLOD.h" #include "TXPArchive.h" #include "TXPTileNode.h" +#include "TXPPagedLOD.h" #include "TileMapper.h" using namespace txp; @@ -52,8 +53,14 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv) if (nv.getVisitorType()==osg::NodeVisitor::CULL_VISITOR && _children.size()==2) { - osg::PagedLOD* pagedLOD = TileMapper::instance()->getPagedLOD(_neighbourTileX,_neighbourTileY, _neighbourTileLOD); + //osg::PagedLOD* pagedLOD = TileMapper::instance()->getPagedLOD(_neighbourTileX,_neighbourTileY, _neighbourTileLOD); + TXPPagedLOD* pagedLOD = dynamic_cast(TileMapper::instance()->getPagedLOD(_neighbourTileX,_neighbourTileY, _neighbourTileLOD)); #if 1 + if (pagedLOD && pagedLOD->getLastTraversedChild()>0) + getChild(1)->accept(nv); + else + getChild(0)->accept(nv); +#else bool acceptLoRes = true; if (pagedLOD) { @@ -85,29 +92,6 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv) for (int i = _nonSeamChildrenIndex; i < (int)getNumChildren(); i++ ) getChild(i)->accept(nv); } -#else - float distance = nv.getDistanceToEyePoint(_center,true); - if (distance<=_mid) - { - // cap the lod's that can be used to what is available in the adjacent PagedLOD. - - //std::cout<<"distance to eye from center = "<getNumChildren()<getNumChildren();++i) - { - //std::cout<<" child "<getMinRange(i)<<" max = "<getMaxRange(i)<getNumChildren()>1) getChild(1)->accept(nv); // pick high res - else getChild(0)->accept(nv); // pick low res as fallback - } - else - { - getChild(0)->accept(nv); // pick low res - } #endif } else @@ -115,4 +99,3 @@ void TXPSeamLOD::traverse(osg::NodeVisitor& nv) Group::traverse(nv); } } - diff --git a/src/osgPlugins/txp/TileMapper.h b/src/osgPlugins/txp/TileMapper.h index a590e43eb..4a4503ad1 100644 --- a/src/osgPlugins/txp/TileMapper.h +++ b/src/osgPlugins/txp/TileMapper.h @@ -61,7 +61,7 @@ protected: } }; - typedef std::map< TileTriple, osg::ref_ptr > TileMap; + typedef std::map< TileTriple, osg::PagedLOD* > TileMap; OpenThreads::Mutex _mutex; TileMap _tileMap;