osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthSymbology/ModelSymbolizer.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 #include <osgEarthSymbology/ModelSymbolizer>
00020 #include <osgEarthSymbology/MarkerSymbol>
00021 #include <osgEarth/HTTPClient>
00022 #include <osg/Geode>
00023 #include <osg/Version>
00024 #include <osgDB/ReadFile>
00025 #include <osgDB/ReaderWriter>
00026 
00027 using namespace osgEarth::Symbology;
00028 
00029 ModelSymbolizer::ModelSymbolizer()
00030 {
00031 }
00032 
00033 
00034 static osg::Node* getNode(const std::string& str)
00035 {
00036     osg::ref_ptr<osg::Node> output;
00037 #if OSG_VERSION_LESS_THAN(2,9,8)
00038     osg::ref_ptr<osgDB::ReaderWriter::Options> options = new osgDB::ReaderWriter::Options;
00039     options->setObjectCacheHint(osgDB::ReaderWriter::Options::CACHE_ALL);
00040 #else
00041     osg::ref_ptr<osgDB::Options> options = new osgDB::Options;
00042     options->setObjectCacheHint(osgDB::Options::CACHE_ALL);
00043 #endif
00044     if ( HTTPClient::readNodeFile( str, output, options.get(), 0 ) == HTTPClient::RESULT_OK )
00045     {
00046         osg::notify(osg::NOTICE) << "loaded " << str << std::endl;
00047     }
00048     else
00049     {
00050         osg::notify(osg::NOTICE) << "can't load " << str << std::endl;
00051     }
00052     return output.release();
00053 }
00054 
00055 
00056 bool 
00057 ModelSymbolizer::compile(State<GeometryContent>* state,
00058                          osg::Group* attachPoint)
00059 {
00060     if ( !state || !attachPoint || !state->getContent() || !state->getStyle() )
00061         return false;
00062 
00063     const MarkerSymbol* symbol = state->getStyle()->getSymbol<MarkerSymbol>();
00064     if (!symbol)
00065         return false;
00066 
00067     std::string model = symbol->marker().value();
00068     if (model.empty())
00069         return false;
00070 
00071     osg::ref_ptr<osg::Group> newSymbolized = new osg::Group;
00072     osg::Node* node = getNode(model);
00073     if (!node)
00074         return false;
00075 
00076     newSymbolized->addChild(node);
00077     attachPoint->removeChildren(0, attachPoint->getNumChildren());
00078     attachPoint->addChild(newSymbolized.get());
00079     return true;
00080 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines