osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthFeatures/Filter.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/Filter>
00020 #include <osgEarth/ECEF>
00021 #include <osg/MatrixTransform>
00022 
00023 using namespace osgEarth;
00024 using namespace osgEarth::Features;
00025 
00026 void
00027 FeaturesToNodeFilter::computeLocalizers( const FilterContext& context )
00028 {
00029     if ( context.getSession()->getMapInfo().isGeocentric() )
00030     {
00031         const SpatialReference* geogSRS = context.profile()->getSRS()->getGeographicSRS();
00032         GeoExtent geodExtent = context.extent()->transform( geogSRS );
00033         if ( geodExtent.width() < 180.0 )
00034         {
00035             osg::Vec3d centroid, centroidECEF;
00036             geodExtent.getCentroid( centroid.x(), centroid.y() );
00037             geogSRS->transformToECEF( centroid, centroidECEF );
00038             _local2world = ECEF::createInverseRefFrame( centroidECEF );
00039             _world2local.invert( _local2world );
00040         }
00041     }
00042 }
00043 
00044 osg::Node*
00045 FeaturesToNodeFilter::delocalize( osg::Node* node ) const
00046 {
00047     if ( !_local2world.isIdentity() ) 
00048         return delocalizeAsGroup( node );
00049     else
00050         return node;
00051 }
00052 
00053 osg::Group*
00054 FeaturesToNodeFilter::delocalizeAsGroup( osg::Node* node ) const
00055 {
00056     osg::Group* group = createDelocalizeGroup();
00057     if ( node )
00058         group->addChild( node );
00059     return group;
00060 }
00061 
00062 osg::Group*
00063 FeaturesToNodeFilter::createDelocalizeGroup() const
00064 {
00065     osg::Group* group = _local2world.isIdentity() ?
00066         new osg::Group() :
00067         new osg::MatrixTransform( _local2world );
00068 
00069     return group;
00070 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines