osgEarth 2.1.1
Public Types | Public Member Functions | Public Attributes

VPBDatabase Class Reference

Inheritance diagram for VPBDatabase:
Collaboration diagram for VPBDatabase:

List of all members.

Public Types

enum  DirectoryStructure { FLAT, FLAT_TASK_DIRECTORIES, NESTED_TASK_DIRECTORIES }
typedef std::map
< osgTerrain::TileID,
osg::ref_ptr
< osgTerrain::TerrainTile > > 
TileMap
typedef std::list
< osgTerrain::TileID > 
TileIDList
typedef std::set< std::string > StringSet
typedef std::map
< osgTerrain::TileID,
osg::ref_ptr
< osgTerrain::TerrainTile > > 
TileMap
typedef std::list
< osgTerrain::TileID > 
TileIDList
typedef std::set< std::string > StringSet

Public Member Functions

 VPBDatabase (const PluginOptions *in_options)
void init ()
std::string createTileName (int level, int tile_x, int tile_y)
osgTerrain::TerrainTile * getTerrainTile (const TileKey *key, ProgressCallback *progress)
void insertTile (const osgTerrain::TileID &tileID, osgTerrain::TerrainTile *tile)
osgTerrain::TerrainTile * findTile (const osgTerrain::TileID &tileID, bool insertBlankTileIfNotFound=false)
const ProfilegetProfile ()
const std::string & getExtension ()
 VPBDatabase (const VPBOptions &in_options)
void initialize (const std::string &referenceURI)
std::string createTileName (int level, int tile_x, int tile_y)
void getTerrainTile (const TileKey &key, ProgressCallback *progress, osg::ref_ptr< osgTerrain::TerrainTile > &out_tile)
void insertTile (const osgTerrain::TileID &tileID, osgTerrain::TerrainTile *tile)
void findTile (const osgTerrain::TileID &tileID, bool insertBlankTileIfNotFound, osg::ref_ptr< osgTerrain::TerrainTile > &out_tile)

Public Attributes

bool initialized
osg::ref_ptr< const PluginOptions > options
std::string url
std::string path
std::string base_name
std::string extension
int primary_split_level
int secondary_split_level
DirectoryStructure directory_structure
osg::ref_ptr< const Profileprofile
osg::ref_ptr< osg::Node > root_node
unsigned int maxNumTilesInCache
TileMap tileMap
OpenThreads::Mutex tileMapMutex
TileIDList tileFIFO
StringSet blacklistedFilenames
OpenThreads::Mutex blacklistMutex
const VPBOptions _options
URI _url
std::string _path
std::string _extension
std::string _baseNameToUse
osg::ref_ptr< const Profile_profile
osg::ref_ptr< osg::Node > _rootNode
unsigned int _maxNumTilesInCache
TileMap _tileMap
Threading::ReadWriteMutex _tileMapMutex
TileIDList _tileFIFO
StringSet _blacklistedFilenames
Threading::ReadWriteMutex _blacklistMutex
bool _initialized
Threading::Mutex _initializeMutex

Detailed Description

Definition at line 140 of file Copy of ReaderWriterVPB.cpp.


Member Typedef Documentation

typedef std::set<std::string> VPBDatabase::StringSet

Definition at line 540 of file Copy of ReaderWriterVPB.cpp.

typedef std::set<std::string> VPBDatabase::StringSet

Definition at line 508 of file ReaderWriterVPB.cpp.

typedef std::list<osgTerrain::TileID> VPBDatabase::TileIDList

Definition at line 505 of file ReaderWriterVPB.cpp.

typedef std::list<osgTerrain::TileID> VPBDatabase::TileIDList

Definition at line 537 of file Copy of ReaderWriterVPB.cpp.

typedef std::map<osgTerrain::TileID, osg::ref_ptr<osgTerrain::TerrainTile> > VPBDatabase::TileMap

Definition at line 501 of file ReaderWriterVPB.cpp.

typedef std::map<osgTerrain::TileID, osg::ref_ptr<osgTerrain::TerrainTile> > VPBDatabase::TileMap

Definition at line 533 of file Copy of ReaderWriterVPB.cpp.


Member Enumeration Documentation

Enumerator:
FLAT 
FLAT_TASK_DIRECTORIES 
NESTED_TASK_DIRECTORIES 

Definition at line 144 of file Copy of ReaderWriterVPB.cpp.


Constructor & Destructor Documentation

VPBDatabase::VPBDatabase ( const PluginOptions *  in_options) [inline]

Definition at line 151 of file Copy of ReaderWriterVPB.cpp.

VPBDatabase::VPBDatabase ( const VPBOptions in_options) [inline]

Definition at line 146 of file ReaderWriterVPB.cpp.

                                                :
        _options( in_options ),
        //_directory_structure( FLAT_TASK_DIRECTORIES ),
        _profile( osgEarth::Registry::instance()->getGlobalGeodeticProfile() ),
        _maxNumTilesInCache( 128 ),
        _initialized( false )
    {
        }

Member Function Documentation

std::string VPBDatabase::createTileName ( int  level,
int  tile_x,
int  tile_y 
) [inline]

Definition at line 297 of file Copy of ReaderWriterVPB.cpp.

    {
        init();
        std::stringstream buf;
        if (directory_structure==FLAT)
        {
             buf<<path<<"/"<<base_name<<"_L"<<level<<"_X"<<tile_x/2<<"_Y"<<tile_y/2<<"_subtile."<<extension;
        }
        else
        {
            if (level<primary_split_level)
            {
                buf<<path<<"/"<<base_name<<"_root_L0_X0_Y0/"<<
                     base_name<<"_L"<<level<<"_X"<<tile_x/2<<"_Y"<<tile_y/2<<"_subtile."<<extension;

            }
            else if (level<secondary_split_level)
            {
                tile_x /= 2;
                tile_y /= 2;

                int split_x = tile_x >> (level - primary_split_level);
                int split_y = tile_y >> (level - primary_split_level);

                buf<<path<<"/"<<base_name<<"_subtile_L"<<primary_split_level<<"_X"<<split_x<<"_Y"<<split_y<<"/"<<
                     base_name<<"_L"<<level<<"_X"<<tile_x<<"_Y"<<tile_y<<"_subtile."<<extension;
            }
            else if (directory_structure==NESTED_TASK_DIRECTORIES)
            {
                tile_x /= 2;
                tile_y /= 2;

                int split_x = tile_x >> (level - primary_split_level);
                int split_y = tile_y >> (level - primary_split_level);

                int secondary_split_x = tile_x >> (level - secondary_split_level);
                int secondary_split_y = tile_y >> (level - secondary_split_level);

                buf<<path<<"/"<<base_name<<"_subtile_L"<<primary_split_level<<"_X"<<split_x<<"_Y"<<split_y<<"/"<<
                     base_name<<"_subtile_L"<<secondary_split_level<<"_X"<<secondary_split_x<<"_Y"<<secondary_split_y<<"/"<< 
                     base_name<<"_L"<<level<<"_X"<<tile_x<<"_Y"<<tile_y<<"_subtile."<<extension;
            }
            else
            {
                tile_x /= 2;
                tile_y /= 2;

                int split_x = tile_x >> (level - secondary_split_level);
                int split_y = tile_y >> (level - secondary_split_level);

                buf<<path<<"/"<<base_name<<"_subtile_L"<<secondary_split_level<<"_X"<<split_x<<"_Y"<<split_y<<"/"<<
                     base_name<<"_L"<<level<<"_X"<<tile_x<<"_Y"<<tile_y<<"_subtile."<<extension;
            }
        }
        
        osg::notify(osg::INFO)<<"VPBDatabase::createTileName(), buf.str()=="<<buf.str()<<std::endl;
        
        return buf.str();
    }

Here is the call graph for this function:

std::string VPBDatabase::createTileName ( int  level,
int  tile_x,
int  tile_y 
) [inline]

Definition at line 277 of file ReaderWriterVPB.cpp.

    {
        std::stringstream buf;
        if ( _options.directoryStructure() == VPBOptions::DS_FLAT )
        {
             buf<<_path<<"/"<<_baseNameToUse<<"_L"<<level<<"_X"<<tile_x/2<<"_Y"<<tile_y/2<<"_subtile."<<_extension;
        }
        else
        {
            int psl = _options.primarySplitLevel().value();
            int ssl = _options.secondarySplitLevel().value();

            if (level<psl)
            {
                buf<<_path<<"/"<<_baseNameToUse<<"_root_L0_X0_Y0/"<<
                     _baseNameToUse<<"_L"<<level<<"_X"<<tile_x/2<<"_Y"<<tile_y/2<<"_subtile."<<_extension;

            }
            else if (level<ssl)
            {
                tile_x /= 2;
                tile_y /= 2;

                int split_x = tile_x >> (level - psl);
                int split_y = tile_y >> (level - psl);

                buf<<_path<<"/"<<_baseNameToUse<<"_subtile_L"<<psl<<"_X"<<split_x<<"_Y"<<split_y<<"/"<<
                     _baseNameToUse<<"_L"<<level<<"_X"<<tile_x<<"_Y"<<tile_y<<"_subtile."<<_extension;
            }
            else if ( _options.directoryStructure() == VPBOptions::DS_TASK )
            {
                tile_x /= 2;
                tile_y /= 2;

                int split_x = tile_x >> (level - psl);
                int split_y = tile_y >> (level - psl);

                int secondary_split_x = tile_x >> (level - ssl);
                int secondary_split_y = tile_y >> (level - ssl);

                buf<<_path<<"/"<<_baseNameToUse<<"_subtile_L"<<psl<<"_X"<<split_x<<"_Y"<<split_y<<"/"<<
                     _baseNameToUse<<"_subtile_L"<<ssl<<"_X"<<secondary_split_x<<"_Y"<<secondary_split_y<<"/"<< 
                     _baseNameToUse<<"_L"<<level<<"_X"<<tile_x<<"_Y"<<tile_y<<"_subtile."<<_extension;
            }
            else
            {
                tile_x /= 2;
                tile_y /= 2;

                int split_x = tile_x >> (level - ssl);
                int split_y = tile_y >> (level - ssl);

                buf<<_path<<"/"<<_baseNameToUse<<"_subtile_L"<<ssl<<"_X"<<split_x<<"_Y"<<split_y<<"/"<<
                     _baseNameToUse<<"_L"<<level<<"_X"<<tile_x<<"_Y"<<tile_y<<"_subtile."<<_extension;
            }
        }
        
                std::string bufStr;
                bufStr = buf.str();
        OE_DEBUG<<"VPB: VPBDatabase::createTileName(), buf.str()=="<< bufStr <<std::endl;
        
                return bufStr;
    }
osgTerrain::TerrainTile* VPBDatabase::findTile ( const osgTerrain::TileID &  tileID,
bool  insertBlankTileIfNotFound = false 
) [inline]

Definition at line 491 of file Copy of ReaderWriterVPB.cpp.

    {
        init();
        {
            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(tileMapMutex);
            TileMap::iterator itr = tileMap.find(tileID);
            if (itr!=tileMap.end()) return itr->second.get();
        }

        if (insertBlankTileIfNotFound) insertTile(tileID, 0);

        return 0;
    }
void VPBDatabase::findTile ( const osgTerrain::TileID &  tileID,
bool  insertBlankTileIfNotFound,
osg::ref_ptr< osgTerrain::TerrainTile > &  out_tile 
) [inline]

Definition at line 472 of file ReaderWriterVPB.cpp.

    {
        // read with a shared lock
        {
            Threading::ScopedReadLock sharedLock( _tileMapMutex );
            TileMap::iterator itr = _tileMap.find(tileID);
            if (itr != _tileMap.end())
                out_tile = itr->second.get();
        }

        // upgrade lock and write:
        if (insertBlankTileIfNotFound) 
            insertTile(tileID, 0);

        //return 0;
    }
const std::string& VPBDatabase::getExtension ( ) [inline]

Definition at line 511 of file Copy of ReaderWriterVPB.cpp.

    {
        init();
        return extension;
    }
const Profile* VPBDatabase::getProfile ( ) [inline]

Definition at line 505 of file Copy of ReaderWriterVPB.cpp.

    {
        init();
        return profile.get();
    }
osgTerrain::TerrainTile* VPBDatabase::getTerrainTile ( const TileKey key,
ProgressCallback progress 
) [inline]

Definition at line 357 of file Copy of ReaderWriterVPB.cpp.

    {
        init();
        int level = key->getLevelOfDetail();
        unsigned int tile_x, tile_y;
        key->getTileXY( tile_x, tile_y );
        
        int max_x = (2 << level) - 1;
        int max_y = (1 << level) - 1;
        
        tile_y = max_y - tile_y;

        osgTerrain::TileID tileID(level, tile_x, tile_y);

        osg::ref_ptr<osgTerrain::TerrainTile> tile = findTile(tileID, false);
        if (tile.valid()) return tile.get();
        
        osg::notify(osg::INFO)<<"Max_x = "<<max_x<<std::endl;
        osg::notify(osg::INFO)<<"Max_y = "<<max_y<<std::endl;

        osg::notify(osg::INFO)<<"base_name = "<<base_name<<" psl="<<primary_split_level<<" ssl="<<secondary_split_level<<std::endl;
        osg::notify(osg::INFO)<<"level = "<<level<<", x = "<<tile_x<<", tile_y = "<<tile_y<<std::endl;
        osg::notify(osg::INFO)<<"tile_name "<<createTileName(level, tile_x, tile_y)<<std::endl;
        osg::notify(osg::INFO)<<"thread "<<OpenThreads::Thread::CurrentThread()<<std::endl;

        std::string filename = createTileName(level, tile_x, tile_y);
        
        {
            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(blacklistMutex);
            if (blacklistedFilenames.count(filename)==1)
            {
                osg::notify(osg::INFO)<<"file has been found in black list : "<<filename<<std::endl;

                insertTile(tileID, 0);
                return 0;
            }
        }
        

        osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions = new osgDB::ReaderWriter::Options;
        localOptions->setPluginData("osgearth_vpb Plugin",(void*)(1));

        //osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filename, localOptions.get());
        osg::ref_ptr<osg::Node> node;
        if (osgDB::containsServerAddress( filename ) )
        {
            node = HTTPClient::readNodeFile( filename, localOptions.get(), progress );
        }
        else
        {
            node = osgDB::readNodeFile( filename, localOptions.get() );
        }

        if (node.valid())
        {
            osg::notify(osg::INFO)<<"Loaded model "<<filename<<std::endl;
            CollectTiles ct;
            node->accept(ct);

            int base_x = (tile_x / 2) * 2;
            int base_y = (tile_y / 2) * 2;
            
            double min_x, max_x, min_y, max_y;
            ct.getRange(min_x, min_y, max_x, max_y);

            double center_x = (min_x + max_x)*0.5;
            double center_y = (min_y + max_y)*0.5;

            osg::Vec3d local(0.5,0.5,0.0);
            for(unsigned int i=0; i<ct._terrainTiles.size(); ++i)
            {
                osgTerrain::TerrainTile* tile = ct._terrainTiles[i].get();
                osgTerrain::Locator* locator = tile->getLocator();
                if (locator)
                {
                    osg::Vec3d projected = local * locator->getTransform();
                    
                    int local_x = base_x + ((projected.x() > center_x) ? 1 : 0);
                    int local_y = base_y + ((projected.y() > center_y) ? 1 : 0);
                    osgTerrain::TileID local_tileID(level, local_x, local_y);
                    
                    tile->setTileID(local_tileID);
                    insertTile(local_tileID, tile);
                }

            }

        }
        else
        {
            //Only blacklist if the request wasn't cancelled by the callback.
            if (!progress || (!progress->isCanceled()))
            {
                osg::notify(osg::INFO)<<"Black listing : "<<filename<<std::endl;
                OpenThreads::ScopedLock<OpenThreads::Mutex> lock(blacklistMutex);
                blacklistedFilenames.insert(filename);
            }
        }
        
        return findTile(tileID, true);
    }

Here is the call graph for this function:

void VPBDatabase::getTerrainTile ( const TileKey key,
ProgressCallback progress,
osg::ref_ptr< osgTerrain::TerrainTile > &  out_tile 
) [inline]

Definition at line 341 of file ReaderWriterVPB.cpp.

    {
        int level = key.getLevelOfDetail();
        unsigned int tile_x, tile_y;
        key.getTileXY( tile_x, tile_y );
        
        //int max_x = (2 << level) - 1;
        int max_y = (1 << level) - 1;
        
        tile_y = max_y - tile_y;

        osgTerrain::TileID tileID(level, tile_x, tile_y);

        findTile(tileID, false, out_tile);
        if (out_tile.valid()) 
            return;

        std::string filename = createTileName(level, tile_x, tile_y);
        
        bool foundInBlacklist = false;
        {
            Threading::ScopedReadLock sharedLock( _blacklistMutex );
            foundInBlacklist = _blacklistedFilenames.count(filename) == 1;
        }
        if ( foundInBlacklist )
        {
            OE_DEBUG << LC << "file has been found in black list : "<<filename<<std::endl;
            insertTile(tileID, 0);
            return; //return 0;
        }

        //    OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_blacklistMutex);
        //    if (_blacklistedFilenames.count(filename)==1)
        //    {
        //        OE_DEBUG<<"VPB: file has been found in black list : "<<filename<<std::endl;
        //        insertTile(tileID, 0);
        //        return 0;
        //    }
        //}
        

        osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions = new osgDB::ReaderWriter::Options;
        localOptions->setPluginData("osgearth_vpb Plugin",(void*)(1));


        //osg::ref_ptr<osg::Node> node = osgDB::readNodeFile(filename, localOptions.get());
        osg::ref_ptr<osg::Node> node;
        HTTPClient::ResultCode result = HTTPClient::readNodeFile( filename, node, localOptions.get(), progress );
        if ( result == HTTPClient::RESULT_OK && node.valid() )
        {
            //OE_INFO << LC << "Loaded model "<<filename<<std::endl;
            CollectTiles ct;
            node->accept(ct);

            int base_x = (tile_x / 2) * 2;
            int base_y = (tile_y / 2) * 2;
            
            double min_x, max_x, min_y, max_y;
            ct.getRange(min_x, min_y, max_x, max_y);

            double center_x = (min_x + max_x)*0.5;
            double center_y = (min_y + max_y)*0.5;

            osg::Vec3d local(0.5,0.5,0.0);
            for(unsigned int i=0; i<ct._terrainTiles.size(); ++i)
            {
                osgTerrain::TerrainTile* tile = ct._terrainTiles[i].get();
                osgTerrain::Locator* locator = tile->getLocator();
                if (locator)
                {
                    osg::Vec3d projected = local * locator->getTransform();
                    
                    int local_x = base_x + ((projected.x() > center_x) ? 1 : 0);
                    int local_y = base_y + ((projected.y() > center_y) ? 1 : 0);
                    osgTerrain::TileID local_tileID(level, local_x, local_y);
                    
                    tile->setTileID(local_tileID);
                    insertTile(local_tileID, tile);

                    if ( local_tileID == tileID )
                        out_tile = tile;
                }

            }

        }
        else
        {
            // in the case of an "unrecoverable" error, black-list the URL for this tile.
            if ( ! HTTPClient::isRecoverable( result ) )
            {
                Threading::ScopedWriteLock exclusiveLock( _blacklistMutex );
                _blacklistedFilenames.insert( filename );
            }
        }
        
        //TODO: just return it instead...
        //findTile(tileID, false, out_tile);
    }

Here is the call graph for this function:

void VPBDatabase::init ( ) [inline]

Definition at line 163 of file Copy of ReaderWriterVPB.cpp.

    {
        if ( initialized ) return;
        initialized = true;

        unsigned int numTilesWideAtLod0, numTilesHighAtLod0;
        profile->getNumTiles(0, numTilesWideAtLod0, numTilesHighAtLod0);

        if ( options.valid() )
        {
            const Config& conf = options->config();

            url = conf.value( PROPERTY_URL );
            primary_split_level = conf.value<int>( PROPERTY_PRIMARY_SPLIT_LEVEL, -1 );
            secondary_split_level = conf.value<int>( PROPERTY_SECONDARY_SPLIT_LEVEL, -1 );

            std::string dir_string = conf.value( PROPERTY_DIRECTORY_STRUCTURE );
            if (dir_string=="nested" || dir_string=="nested_task_directories" ) directory_structure = NESTED_TASK_DIRECTORIES;
            if (dir_string=="task" || dir_string=="flat_task_directories") directory_structure = FLAT_TASK_DIRECTORIES;
            if (dir_string=="flat") directory_structure = FLAT;
            
            base_name = conf.value( PROPERTY_BASE_NAME );
        }

        // validate dataset
        if (!url.empty())
        {
            osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions = new osgDB::ReaderWriter::Options;
            localOptions->setPluginData("osgearth_vpb Plugin",(void*)(1));
            root_node = osgDB::readNodeFile(url, localOptions.get());


            if (root_node.valid())
            {
                path = osgDB::getFilePath(url);
                if ( base_name.empty() )
                    base_name = osgDB::getStrippedName(url);
                extension = osgDB::getFileExtension(url);
                
                osg::notify(osg::INFO)<<"VPBasebase constructor: Loaded root "<<url<<", path="<<path<<" base_name="<<base_name<<" extension="<<extension<<std::endl;
                
                std::string srs = profile->getSRS()->getInitString(); //.srs();
                
                osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(root_node.get());
                if (csn)
                {
                    osg::notify(osg::INFO)<<"CordinateSystemNode found, coordinate system is : "<<csn->getCoordinateSystem()<<std::endl;
                    
                    srs = csn->getCoordinateSystem();
                }

                CollectTiles ct;
                root_node->accept(ct);

                    
                osgTerrain::Locator* locator = ct.getLocator();
                if (locator)
                {
                    double min_x, max_x, min_y, max_y;
                    ct.getRange(min_x, min_y, max_x, max_y);

                    osg::notify(osg::INFO)<<"range("<<min_x<<", "<<min_y<<", "<<max_x<<", "<<max_y<<std::endl;

                    srs = locator->getCoordinateSystem();
                
                    //osgEarth::Profile::ProfileType ptype = osgEarth::Profile::TYPE_UNKNOWN;

                    //switch(locator->getCoordinateSystemType())
                    //{
                    //    case(osgTerrain::Locator::GEOCENTRIC):
                    //        ptype = Profile::TYPE_GEODETIC; //profile.setProfileType(osgEarth::Profile::GLOBAL_GEODETIC);
                    //        break;
                    //    case(osgTerrain::Locator::GEOGRAPHIC):
                    //        ptype = Profile::TYPE_LOCAL; //profile.setProfileType(osgEarth::Profile::PROJECTED);
                    //        break;
                    //    case(osgTerrain::Locator::PROJECTED):
                    //        ptype = Profile::TYPE_LOCAL; //profile.setProfileType(osgEarth::Profile::PROJECTED);
                    //        break;
                    //}

                    double aspectRatio = (max_x-min_x)/(max_y-min_y);
                    
                    osg::notify(osg::INFO)<<"aspectRatio = "<<aspectRatio<<std::endl;

                    if (aspectRatio>1.0)
                    {
                        numTilesWideAtLod0 = static_cast<unsigned int>(floor(aspectRatio+0.499999));
                        numTilesHighAtLod0 = 1;
                    }
                    else
                    {
                        numTilesWideAtLod0 = 1;
                        numTilesHighAtLod0 = static_cast<unsigned int>(floor(1.0/aspectRatio+0.499999));
                    }
                    
                    osg::notify(osg::INFO)<<"computed numTilesWideAtLod0 = "<<numTilesWideAtLod0<<std::endl;
                    osg::notify(osg::INFO)<<"computed numTilesHightAtLod0 = "<<numTilesHighAtLod0<<std::endl;
                    
                    if ( options.valid() )
                    {
                        if ( options->getPluginData( PROPERTY_NUM_TILES_WIDE_AT_LOD0 ) )
                            numTilesWideAtLod0 = atoi( (const char*)options->getPluginData( PROPERTY_NUM_TILES_WIDE_AT_LOD0 ) );

                        if ( options->getPluginData( PROPERTY_NUM_TILES_HIGH_AT_LOD0 ) )
                            numTilesHighAtLod0 = atoi( (const char*)options->getPluginData( PROPERTY_NUM_TILES_HIGH_AT_LOD0 ) );
                    }

                    osg::notify(osg::INFO)<<"final numTilesWideAtLod0 = "<<numTilesWideAtLod0<<std::endl;
                    osg::notify(osg::INFO)<<"final numTilesHightAtLod0 = "<<numTilesHighAtLod0<<std::endl;
                   
                    profile = osgEarth::Profile::create( 
                        srs,
                        osg::RadiansToDegrees(min_x), 
                        osg::RadiansToDegrees(min_y), 
                        osg::RadiansToDegrees(max_x), 
                        osg::RadiansToDegrees(max_y),
                        numTilesWideAtLod0,
                        numTilesHighAtLod0 );
                }
                
            }
            else
            {
                osg::notify(osg::NOTICE)<<"Unable to read file "<<url<<std::endl;
                url = "";
            }
        }
        else 
        {
            osg::notify(osg::NOTICE)<<"No data referenced "<<std::endl;
        }

    }

Here is the call graph for this function:

void VPBDatabase::initialize ( const std::string &  referenceURI) [inline]

Definition at line 155 of file ReaderWriterVPB.cpp.

        {
        Threading::ScopedMutexLock lock( _initializeMutex );

        if ( _initialized )
            return;

        unsigned int numTilesWideAtLod0, numTilesHighAtLod0;
        _profile->getNumTiles(0, numTilesWideAtLod0, numTilesHighAtLod0);

        // validate dataset
        _url = _options.url().value();

        if ( !_url.empty() )
        {
                        //If the path doesn't contain a server address, get the full path to the file.
                        if (!osgDB::containsServerAddress( *_url ))
                        {
                //todo: obselete..?
                _url = URI(_url.full(), referenceURI);
                                //_url = osgEarth::getFullPath(referenceURI, _url);
                        }
                        
            osg::ref_ptr<osgDB::ReaderWriter::Options> localOptions = new osgDB::ReaderWriter::Options;
            localOptions->setPluginData("osgearth_vpb Plugin",(void*)(1));
            //_rootNode = osgDB::readNodeFile( _url, localOptions.get() );

            HTTPClient::ResultCode rc = HTTPClient::readNodeFile( _url.full(), _rootNode, localOptions.get() );

            if ( rc == HTTPClient::RESULT_OK && _rootNode.valid() )
            {
                _baseNameToUse = _options.baseName().value();

                _path = osgDB::getFilePath( *_url );
                if ( _baseNameToUse.empty() )
                    _baseNameToUse = osgDB::getStrippedName( *_url );
                _extension = osgDB::getFileExtension( *_url );
                
                OE_INFO << LC << "Loaded root "<< _url.full() <<", path="<<_path<<" base_name="<<_baseNameToUse<<" extension="<<_extension<<std::endl;
                
                std::string srs = _profile->getSRS()->getInitString(); //.srs();
                
                osg::CoordinateSystemNode* csn = dynamic_cast<osg::CoordinateSystemNode*>(_rootNode.get());
                if (csn)
                {
                    OE_INFO << LC << "CSN found: "<<csn->getCoordinateSystem()<<std::endl;
                    
                    srs = csn->getCoordinateSystem();
                }

                CollectTiles ct;
                _rootNode->accept(ct);

                    
                osgTerrain::Locator* locator = ct.getLocator();
                if (locator)
                {
                    double min_x, max_x, min_y, max_y;
                    ct.getRange(min_x, min_y, max_x, max_y);

                    OE_DEBUG << LC << "range("<<min_x<<", "<<min_y<<", "<<max_x<<", "<<max_y<< ")" <<std::endl;
                                        OE_DEBUG << LC << "range("<<osg::RadiansToDegrees(min_x)<<", "<<osg::RadiansToDegrees(min_y)<<", "
                                                <<osg::RadiansToDegrees(max_x)<<", "<<osg::RadiansToDegrees(max_y)<< ")" <<std::endl;

                    srs = locator->getCoordinateSystem();

                    double aspectRatio = (max_x-min_x)/(max_y-min_y);
                    
                    OE_DEBUG << LC << "aspectRatio = "<<aspectRatio<<std::endl;

                    if (aspectRatio>1.0)
                    {
                        numTilesWideAtLod0 = static_cast<unsigned int>(floor(aspectRatio+0.499999));
                        numTilesHighAtLod0 = 1;
                    }
                    else
                    {
                        numTilesWideAtLod0 = 1;
                        numTilesHighAtLod0 = static_cast<unsigned int>(floor(1.0/aspectRatio+0.499999));
                    }
                    
                    OE_DEBUG << LC << "computed numTilesWideAtLod0 = "<<numTilesWideAtLod0<<std::endl;
                    OE_DEBUG << LC << "computed numTilesHightAtLod0 = "<<numTilesHighAtLod0<<std::endl;
                    
                    //if ( _options.valid() )
                    {
                        if ( _options.numTilesWideAtLod0().isSet() )
                            numTilesWideAtLod0 = _options.numTilesWideAtLod0().value();

                        if ( _options.numTilesHighAtLod0().isSet() )
                            numTilesHighAtLod0 = _options.numTilesHighAtLod0().value();
                    }

                    OE_DEBUG << LC << "final numTilesWideAtLod0 = "<<numTilesWideAtLod0<<std::endl;
                    OE_DEBUG << LC << "final numTilesHightAtLod0 = "<<numTilesHighAtLod0<<std::endl;
                   
                    _profile = osgEarth::Profile::create( 
                        srs,
                        osg::RadiansToDegrees(min_x), 
                        osg::RadiansToDegrees(min_y), 
                        osg::RadiansToDegrees(max_x), 
                        osg::RadiansToDegrees(max_y),
                        "",
                        numTilesWideAtLod0,
                        numTilesHighAtLod0 );
                }
                
            }
            else
            {
                OE_WARN << LC << HTTPClient::getResultCodeString(rc) << ": " << *_url << std::endl;
                _url = URI();
            }
        }
        else 
        {
            OE_WARN<<"VPB: No data referenced "<<std::endl;
        }
        
        _initialized = true;
    }

Here is the call graph for this function:

void VPBDatabase::insertTile ( const osgTerrain::TileID &  tileID,
osgTerrain::TerrainTile *  tile 
) [inline]

Definition at line 441 of file ReaderWriterVPB.cpp.

    {
        Threading::ScopedWriteLock exclusiveLock( _tileMapMutex );

        if ( _tileMap.find(tileID) == _tileMap.end() )
        {
            _tileMap[tileID] = tile;

            _tileFIFO.push_back(tileID);

            if (_tileFIFO.size() > _maxNumTilesInCache)
            {
                osgTerrain::TileID tileToRemove = _tileFIFO.front();
                _tileFIFO.pop_front();
                _tileMap.erase(tileToRemove);

                OE_DEBUG << LC << "Pruned tileID ("<<TileKey::getLOD(tileID)<<", "<<tileID.x<<", "<<tileID.y<<")"<<std::endl;
            }

            OE_DEBUG << LC << "insertTile ("
                << TileKey::getLOD(tileID)<<", "<<tileID.x<<", "<<tileID.y<<") " 
                << " tileFIFO.size()=="<<_tileFIFO.size()<<std::endl;
        }
        else
        {
            OE_DEBUG << LC << "insertTile ("
                << TileKey::getLOD(tileID)<<", "<<tileID.x<<", "<<tileID.y<<") " 
                << " ...already in cache!"<<std::endl;
        }
    }

Here is the call graph for this function:

void VPBDatabase::insertTile ( const osgTerrain::TileID &  tileID,
osgTerrain::TerrainTile *  tile 
) [inline]

Definition at line 459 of file Copy of ReaderWriterVPB.cpp.

    {
        init();
        OpenThreads::ScopedLock<OpenThreads::Mutex> lock(tileMapMutex);

        if ( tileMap.find(tileID) == tileMap.end() )
        {
            tileMap[tileID] = tile;

            tileFIFO.push_back(tileID);

            if (tileFIFO.size()>maxNumTilesInCache)
            {
                osgTerrain::TileID tileToRemove = tileFIFO.front();
                tileFIFO.pop_front();
                tileMap.erase(tileToRemove);

                            osg::notify(osg::INFO)<<"Pruned tileID ("<<TileKey::getLOD(tileID)<<", "<<tileID.x<<", "<<tileID.y<<")"<<std::endl;
            }

            osg::notify(osg::INFO)<<"insertTile ("
                << TileKey::getLOD(tileID)<<", "<<tileID.x<<", "<<tileID.y<<") " 
                << " tileFIFO.size()=="<<tileFIFO.size()<<std::endl;
        }
        else
        {
            osg::notify(osg::INFO)<<"insertTile ("
                << TileKey::getLOD(tileID)<<", "<<tileID.x<<", "<<tileID.y<<") " 
                << " ...already in cache!"<<std::endl;
        }
    }

Here is the call graph for this function:


Member Data Documentation

Definition at line 494 of file ReaderWriterVPB.cpp.

Definition at line 509 of file ReaderWriterVPB.cpp.

Definition at line 510 of file ReaderWriterVPB.cpp.

Definition at line 492 of file ReaderWriterVPB.cpp.

Definition at line 512 of file ReaderWriterVPB.cpp.

Definition at line 513 of file ReaderWriterVPB.cpp.

Definition at line 499 of file ReaderWriterVPB.cpp.

Definition at line 489 of file ReaderWriterVPB.cpp.

std::string VPBDatabase::_path

Definition at line 491 of file ReaderWriterVPB.cpp.

osg::ref_ptr<const Profile> VPBDatabase::_profile

Definition at line 496 of file ReaderWriterVPB.cpp.

osg::ref_ptr<osg::Node> VPBDatabase::_rootNode

Definition at line 497 of file ReaderWriterVPB.cpp.

Definition at line 506 of file ReaderWriterVPB.cpp.

Definition at line 502 of file ReaderWriterVPB.cpp.

Definition at line 503 of file ReaderWriterVPB.cpp.

Definition at line 490 of file ReaderWriterVPB.cpp.

Definition at line 522 of file Copy of ReaderWriterVPB.cpp.

Definition at line 541 of file Copy of ReaderWriterVPB.cpp.

OpenThreads::Mutex VPBDatabase::blacklistMutex

Definition at line 542 of file Copy of ReaderWriterVPB.cpp.

Definition at line 526 of file Copy of ReaderWriterVPB.cpp.

Definition at line 523 of file Copy of ReaderWriterVPB.cpp.

Definition at line 517 of file Copy of ReaderWriterVPB.cpp.

Definition at line 531 of file Copy of ReaderWriterVPB.cpp.

osg::ref_ptr<const PluginOptions> VPBDatabase::options

Definition at line 519 of file Copy of ReaderWriterVPB.cpp.

std::string VPBDatabase::path

Definition at line 521 of file Copy of ReaderWriterVPB.cpp.

Definition at line 524 of file Copy of ReaderWriterVPB.cpp.

osg::ref_ptr<const Profile> VPBDatabase::profile

Definition at line 528 of file Copy of ReaderWriterVPB.cpp.

osg::ref_ptr<osg::Node> VPBDatabase::root_node

Definition at line 529 of file Copy of ReaderWriterVPB.cpp.

Definition at line 525 of file Copy of ReaderWriterVPB.cpp.

Definition at line 538 of file Copy of ReaderWriterVPB.cpp.

Definition at line 534 of file Copy of ReaderWriterVPB.cpp.

OpenThreads::Mutex VPBDatabase::tileMapMutex

Definition at line 535 of file Copy of ReaderWriterVPB.cpp.

std::string VPBDatabase::url

Definition at line 520 of file Copy of ReaderWriterVPB.cpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines