/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield * * This library is open source and may be redistributed and/or modified under * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or * (at your option) any later version. The full license is in LICENSE file * included with this distribution, and on the openscenegraph.org website. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * OpenSceneGraph Public License for more details. */ #include "TileMapper.h" //#include "TXPTileNode.h" #include "TXPPagedLOD.h" #include using namespace txp; float TileMapper::getDistanceToEyePoint(const osg::Vec3& pos, bool withLODScale) const { if (withLODScale) return (pos-getEyeLocal()).length()*getLODScale(); else return (pos-getEyeLocal()).length(); } inline TileMapper::value_type distance(const osg::Vec3& coord,const osg::Matrix& matrix) { //std::cout << "distance("<(node.getUserData()); if (tid) { _tileStack.push_back(TileStack::value_type(*tid,&node)); _containsGeode = false; } traverse(node); if (tid) { if (_containsGeode) { insertTile(*tid); _containsGeode = false; #if 0 std::cout<<"found Group="<lod <<" X="<x <<" Y="<y <<" ptr="<<&node<second; // note tile here, is tid's parent. const TileStack::value_type* tile = (ts.size()>=2) ? &ts[ts.size()-2] : 0; // note parent here, is tid's parents parent. const TileStack::value_type* parent = (ts.size()>=3) ? &ts[ts.size()-3] : 0; if (!tile) { // no self!!! so we can descend safely?!! shouldn't ever get here. //std::cout<<"TileMapper::canDescend() tile==0"<first; 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; // 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); } } // we shouldn't get here... return true; } 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()<