osgEarth 2.1.1
|
00001 /* -*-c++-*- */ 00002 /* osgEarth - Dynamic map generation toolkit for OpenSceneGraph 00003 * Copyright 2008-2010 Pelican Mapping 00004 * http://osgearth.org 00005 * 00006 * osgEarth is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU Lesser General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU Lesser General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU Lesser General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/> 00018 */ 00019 00020 #ifndef OSGEARTH_ENGINE_OSGTERRAIN_FILE_LOCATION_CALLBACK_H 00021 #define OSGEARTH_ENGINE_OSGTERRAIN_FILE_LOCATION_CALLBACK_H 1 00022 00023 #include "OSGTerrainEngineNode" 00024 #include <osg/Version> 00025 #include <osgEarth/Export> 00026 00027 00028 #define USE_FILELOCATIONCALLBACK OSG_MIN_VERSION_REQUIRED(2,9,5) 00029 00030 #if USE_FILELOCATIONCALLBACK 00031 00035 class FileLocationCallback : public osgDB::FileLocationCallback 00036 { 00037 public: 00038 FileLocationCallback() { } 00039 00040 virtual Location fileLocation(const std::string& filename, const osgDB::Options* options) 00041 { 00042 Location result = REMOTE_FILE; 00043 //OE_NOTICE<<"fileLocation = "<<filename<<std::endl; 00044 00045 unsigned int lod, x, y, id; 00046 sscanf(filename.c_str(), "%d_%d_%d.%d", &lod, &x, &y, &id); 00047 00048 osg::ref_ptr<OSGTerrainEngineNode> engine; 00049 OSGTerrainEngineNode::getEngineByUID( (UID)id, engine ); 00050 00051 if ( engine.valid() ) 00052 { 00053 const osgEarth::Profile* profile = engine->getMap()->getProfile(); 00054 osgEarth::TileKey mapKey( lod, x, y, profile ); 00055 00056 result = LOCAL_FILE; 00057 00058 MapFrame mapf( engine->getMap() ); 00059 for( unsigned i=0; i<4; ++i ) 00060 { 00061 TileKey childKey = mapKey.createChildKey( i ); 00062 if ( !mapf.isCached( childKey ) ) 00063 { 00064 result = REMOTE_FILE; 00065 break; 00066 } 00067 } 00068 //if ( engine->getTileFactory()->areChildrenCached( engine->getMap(), mapKey ) ) 00069 //{ 00070 // result = LOCAL_FILE; 00071 //} 00072 } 00073 00074 return result; 00075 } 00076 00077 virtual bool useFileCache() const { return false; } 00078 }; 00079 00080 #endif // USE_FILELOCATIONCALLBACK 00081 00082 #endif //OSGEARTH_ENGINE_OSGTERRAIN_FILE_LOCATION_CALLBACK_H