diff --git a/src/osgPlugins/txp/TXPNode.cpp b/src/osgPlugins/txp/TXPNode.cpp index b6161bf9f..d6f0fb2d2 100644 --- a/src/osgPlugins/txp/TXPNode.cpp +++ b/src/osgPlugins/txp/TXPNode.cpp @@ -134,8 +134,6 @@ void TXPNode::traverse(osg::NodeVisitor& nv) //std::cout<<" found " << tileMapper._tileMap.size() << std::endl; - tileMapper->checkValidityOfAllVisibleTiles(); - cv->setUserData(tileMapper.get()); #ifdef PRINT_TILEMAPP_TIMEINFO diff --git a/src/osgPlugins/txp/TileMapper.cpp b/src/osgPlugins/txp/TileMapper.cpp index 16d16dd85..c2569266e 100644 --- a/src/osgPlugins/txp/TileMapper.cpp +++ b/src/osgPlugins/txp/TileMapper.cpp @@ -11,8 +11,11 @@ * OpenSceneGraph Public License for more details. */ +/* Dec 2010 - TileMapper was fixed and simplified + Nick +*/ + #include "TileMapper.h" -//#include "TXPTileNode.h" #include "TXPPagedLOD.h" #include @@ -22,20 +25,18 @@ using namespace txp; float TileMapper::getDistanceToEyePoint(const osg::Vec3& pos, bool withLODScale) const { if (withLODScale) - return (pos-getEyeLocal()).length()*getLODScale(); + return (pos-getEyeLocal()).length()*getLODScale(); else - return (pos-getEyeLocal()).length(); + return (pos-getEyeLocal()).length(); } inline TileMapper::value_type distance(const osg::Vec3& coord,const osg::Matrix& matrix) { - //std::cout << "distance("<second; - - // note tile here, is tid's parent. - const TileStack::value_type* tile = (ts.size()>=2) ? &ts[ts.size()-2] : 0; - - if (!tile) - { - // no self!!! so we can descend safely?!! shouldn't ever get here. - //std::cout<<"TileMapper::canDescend() tile==0"<=3) ? &ts[ts.size()-3] : 0; - - - - if (!parent) - { - // no parent so we can descend safely. - return true; - } - - bool tileHasNorthNeighour = _tileMap.count(TileIdentifier(tid.x,tid.y+1,tid.lod))!=0; - bool tileHasEastNeighour = _tileMap.count(TileIdentifier(tid.x+1,tid.y,tid.lod))!=0; - bool tileHasSouthNeighour = _tileMap.count(TileIdentifier(tid.x,tid.y-1,tid.lod))!=0; - bool tileHasWestNeighour = _tileMap.count(TileIdentifier(tid.x-1,tid.y,tid.lod))!=0; - - if (tileHasNorthNeighour && tileHasEastNeighour && tileHasSouthNeighour && tileHasWestNeighour) - { - // tile has neigbours on all sides at the same lod level, so its safe to descend. - //std::cout<<"TileMapper::canDescend() has neightbours on all sides"<first; -#else - TileIdentifier parent_tid(tid.x/2,tid.y/2,tid.lod-1); -#endif - - bool parentHasNorthNeighour = _tileMap.count(TileIdentifier(parent_tid.x,parent_tid.y+1,parent_tid.lod))!=0; - bool parentHasEastNeighour = _tileMap.count(TileIdentifier(parent_tid.x+1,parent_tid.y,parent_tid.lod))!=0; - bool parentHasSouthNeighour = _tileMap.count(TileIdentifier(parent_tid.x,parent_tid.y-1,parent_tid.lod))!=0; - bool parentHasWestNeighour = _tileMap.count(TileIdentifier(parent_tid.x-1,parent_tid.y,parent_tid.lod))!=0; - - // FIXME: this guy gives us wrong parent - // Nick 2010/12/12 -#if 0 - // identify whether the tile is a NE/SE/SW/NW tile relative to its parent. - osg::Vec3 delta = tile->second->getBound().center() - parent->second->getBound().center(); - - if (delta.y()>=0.0f) // noth side - { - if (delta.x()>=0.0f) - { - // NE, only traverse if our parent doesn't have any neighbours to the north or east. - return (!parentHasNorthNeighour && !parentHasEastNeighour); - } - else - { - // NW, only traverse if our parent doesn't have any neighbours to the north or west. - return (!parentHasNorthNeighour && !parentHasWestNeighour); - } - } - else // south side - { - if (delta.x()>=0.0f) - { - // SE, only traverse if our parent doesn't have any neighbours to the south or east. - return (!parentHasSouthNeighour && !parentHasEastNeighour); - } - else - { - // SW, only traverse if our parent doesn't have any neighbours to the south or west. - return (!parentHasSouthNeighour && !parentHasWestNeighour); - } - } -#else - // identify whether the tile is a NE/SE/SW/NW tile relative to its parent. - osg::Vec3 delta(tid.x%2,tid.y%2,0); - - if (delta.y()>0.0f) // noth side - { - if (delta.x()>0.0f) - { - // NE, only traverse if our parent doesn't have any neighbours to the north or east. - return (!parentHasNorthNeighour && !parentHasEastNeighour); - } - else - { - // NW, only traverse if our parent doesn't have any neighbours to the north or west. - return (!parentHasNorthNeighour && !parentHasWestNeighour); - } - } - else // south side - { - if (delta.x()>0.0f) - { - // SE, only traverse if our parent doesn't have any neighbours to the south or east. - return (!parentHasSouthNeighour && !parentHasEastNeighour); - } - else - { - // SW, only traverse if our parent doesn't have any neighbours to the south or west. - return (!parentHasSouthNeighour && !parentHasWestNeighour); - } - } -#endif -} - -void TileMapper::checkValidityOfAllVisibleTiles() -{ - typedef std::vector ToRemoveList; - typedef std::vector ToAddList; - - ToRemoveList toRemoveList; - ToAddList toAddList; - - do - { -// std::cout<<"doing checkAllVisibleTiles() loop with "<<_tileMap.size()<first)) - { - // need to remove. - toRemoveList.push_back(itr->first); - - // trim the end of itr's TileStack and add into toAddList - toAddList.push_back(itr->second); - -// std::cout<<"Tile failed" -// <<" LOD="<first.lod -// <<" X="<first.x -// <<" Y="<first.y<pop_back(); - _blackListedNodeSet.insert(aitr->back().second); - _tileMap.insert(TileMap::value_type(aitr->back().first,*aitr)); - } - - } - while (!toRemoveList.empty()); - - -#if 0 - - if ( !_blackListedNodeSet.empty() ) - std::cout << "********** We have blacked list " << _blackListedNodeSet.size() << std::endl; - - std::cout<<"TileMap contains "<<_tileMap.size()<