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 #include <osgEarth/MaskSource> 00020 #include <osg/Notify> 00021 #include <osgDB/ReadFile> 00022 00023 using namespace osgEarth; 00024 using namespace OpenThreads; 00025 00026 /****************************************************************/ 00027 00028 void 00029 MaskSourceOptions::fromConfig( const Config& conf ) 00030 { 00031 //nop 00032 } 00033 00034 void 00035 MaskSourceOptions::mergeConfig( const Config& conf ) 00036 { 00037 DriverConfigOptions::mergeConfig( conf ); 00038 fromConfig( conf ); 00039 } 00040 00041 Config 00042 MaskSourceOptions::getConfig() const 00043 { 00044 Config conf = DriverConfigOptions::getConfig(); 00045 return conf; 00046 } 00047 00048 //------------------------------------------------------------------------ 00049 00050 MaskSource::MaskSource( const MaskSourceOptions& options ) : 00051 _options( options ) 00052 { 00053 //TODO: is this really necessary? 00054 this->setThreadSafeRefUnref( true ); 00055 } 00056 00057 //------------------------------------------------------------------------ 00058 00059 #undef LC 00060 #define LC "[MaskSourceFactory] " 00061 #define MASK_SOURCE_OPTIONS_TAG "__osgEarth::MaskSourceOptions" 00062 00063 MaskSource* 00064 MaskSourceFactory::create( const MaskSourceOptions& options ) 00065 { 00066 MaskSource* source = 0L; 00067 00068 if ( !options.getDriver().empty() ) 00069 { 00070 std::string driverExt = std::string(".osgearth_mask_") + options.getDriver(); 00071 00072 osg::ref_ptr<osgDB::ReaderWriter::Options> rwopts = new osgDB::ReaderWriter::Options(); 00073 rwopts->setPluginData( MASK_SOURCE_OPTIONS_TAG, (void*)&options ); 00074 00075 source = dynamic_cast<MaskSource*>( osgDB::readObjectFile( driverExt, rwopts.get() ) ); 00076 if ( source ) 00077 { 00078 OE_INFO << "Loaded MaskSource driver \"" << options.getDriver() << "\" OK" << std::endl; 00079 } 00080 else 00081 { 00082 OE_WARN << "FAIL, unable to load MaskSource driver for \"" << options.getDriver() << "\"" << std::endl; 00083 } 00084 } 00085 else 00086 { 00087 OE_WARN << LC << "FAIL, illegal null driver specification" << std::endl; 00088 } 00089 00090 return source; 00091 } 00092 00093 //------------------------------------------------------------------------ 00094 00095 const MaskSourceOptions& 00096 MaskSourceDriver::getMaskSourceOptions( const osgDB::ReaderWriter::Options* options ) const 00097 { 00098 return *static_cast<const MaskSourceOptions*>( options->getPluginData( MASK_SOURCE_OPTIONS_TAG ) ); 00099 }