osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthFeatures/FeatureNode.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 <osgEarthFeatures/FeatureNode>
00020 #include <osgEarthFeatures/GeometryCompiler>
00021 #include <osgEarthFeatures/Session>
00022 
00023 #define LC "[FeatureNode] "
00024 
00025 using namespace osgEarth;
00026 using namespace osgEarth::Features;
00027 using namespace osgEarth::Symbology;
00028 
00029 FeatureNode::FeatureNode( MapNode* mapNode, Feature* feature, bool draped ) :
00030 DrapeableNode( mapNode, draped ),
00031 _feature     ( feature )
00032 {
00033     init();
00034 }
00035 
00036 void
00037 FeatureNode::init()
00038 {
00039     if ( _feature.valid() && _feature->getGeometry() )
00040     {
00041         GeometryCompilerOptions options;
00042         options.maxGranularity() = 1.0;
00043         GeometryCompiler compiler( options );
00044         Session* session = new Session( _mapNode->getMap() );
00045         GeoExtent extent(_mapNode->getMap()->getProfile()->getSRS(), _feature->getGeometry()->getBounds());
00046         FeatureProfile* profile = new FeatureProfile(extent);
00047         FilterContext context( session, profile, extent );
00048 
00049         // Clone the Feature before rendering as the GeometryCompiler and it's filters can change the coordinates
00050         // of the geometry when performing localization or converting to geocentric.
00051         osg::ref_ptr< Feature > clone = new osgEarth::Features::Feature(*_feature.get(), osg::CopyOp::DEEP_COPY_ALL);        
00052 
00053         osg::Node* node;
00054         if ( _style.isSet() )
00055             node = compiler.compile( clone.get(), *_style, context );
00056         else
00057             node = compiler.compile( clone.get(), *clone->style(), context );
00058 
00059         setNode( node );
00060     }
00061 }
00062 
00063 void
00064 FeatureNode::setFeature( Feature* feature )
00065 {
00066     _feature = feature;
00067     init();
00068 }
00069 
00070 void
00071 FeatureNode::setStyle( const Style& style )
00072 {
00073     _style = style;
00074     init();
00075 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines