osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/model_simple/SimpleModelSource.cpp

Go to the documentation of this file.
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 #include "SimpleModelOptions"
00021 #include <osgEarth/ModelSource>
00022 #include <osgEarth/Registry>
00023 #include <osgEarth/Map>
00024 #include <osgEarth/FileUtils>
00025 #include <osg/Notify>
00026 #include <osgDB/FileNameUtils>
00027 
00028 using namespace osgEarth;
00029 using namespace osgEarth::Drivers;
00030 
00031 #include <osgEarth/HTTPClient>
00032 
00033 class SimpleModelSource : public ModelSource
00034 {
00035 public:
00036     SimpleModelSource( const ModelSourceOptions& options )
00037         : ModelSource( options ), _options(options) { }
00038 
00039     //override
00040     void initialize( const std::string& referenceURI, const osgEarth::Map* map )
00041     {
00042         ModelSource::initialize( referenceURI, map );
00043                        
00044         _url = *_options.url();        
00045        
00046         //_url = URI(_options.url()->base(), referenceURI);
00047         //_url = osgEarth::getFullPath( referenceURI, _options.url().value() );
00048     }
00049 
00050     // override
00051     osg::Node* createNode( ProgressCallback* progress )
00052     {
00053         osg::ref_ptr<osg::Node> result;
00054 
00055         // required if the model includes local refs, like PagedLOD or ProxyNode:
00056         osg::ref_ptr<osgDB::Options> options = new osgDB::Options();
00057         options->getDatabasePathList().push_back( osgDB::getFilePath(*_url) );
00058 
00059         HTTPClient::readNodeFile( *_url, result, options.get(), progress ); //_settings.get(), progress );
00060         return result.release();
00061     }
00062 
00063 protected:
00064     URI _url;
00065     const SimpleModelOptions _options;
00066 };
00067 
00068 
00069 class SimpleModelSourceFactory : public ModelSourceDriver
00070 {
00071 public:
00072     SimpleModelSourceFactory()
00073     {
00074         supportsExtension( "osgearth_model_simple", "osgEarth simple model plugin" );
00075     }
00076 
00077     virtual const char* className()
00078     {
00079         return "osgEarth Simple Model Plugin";
00080     }
00081 
00082     virtual ReadResult readObject(const std::string& file_name, const Options* options) const
00083     {
00084         if ( !acceptsExtension(osgDB::getLowerCaseFileExtension( file_name )))
00085             return ReadResult::FILE_NOT_HANDLED;
00086 
00087         return ReadResult( new SimpleModelSource( getModelSourceOptions(options) ) );
00088     }
00089 };
00090 
00091 REGISTER_OSGPLUGIN(osgearth_model_simple, SimpleModelSourceFactory) 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines