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 <osgEarthFeatures/FilterContext> 00020 00021 using namespace osgEarth; 00022 using namespace osgEarth::Features; 00023 00024 FilterContext::FilterContext(Session* session, 00025 const FeatureProfile* profile, 00026 const GeoExtent& workingExtent ) : 00027 _session ( session ), 00028 _profile ( profile ), 00029 _extent ( workingExtent, workingExtent ), 00030 _isGeocentric( false ) 00031 { 00032 _resourceCache = new ResourceCache(); 00033 } 00034 00035 FilterContext::FilterContext( const FilterContext& rhs ) : 00036 _profile ( rhs._profile.get() ), 00037 _session ( rhs._session.get() ), 00038 _isGeocentric ( rhs._isGeocentric ), 00039 _extent ( rhs._extent ), 00040 _referenceFrame ( rhs._referenceFrame ), 00041 _inverseReferenceFrame( rhs._inverseReferenceFrame ), 00042 _optimizerHints ( rhs._optimizerHints ), 00043 _resourceCache ( rhs._resourceCache ) 00044 { 00045 //nop 00046 } 00047 00048 void 00049 FilterContext::toLocal( Geometry* geom ) const 00050 { 00051 if ( hasReferenceFrame() ) 00052 { 00053 GeometryIterator gi( geom ); 00054 while( gi.hasMore() ) 00055 { 00056 Geometry* g = gi.next(); 00057 for( osg::Vec3dArray::iterator i = g->begin(); i != g->end(); ++i ) 00058 *i = *i * _referenceFrame; 00059 } 00060 } 00061 } 00062 00063 void 00064 FilterContext::toWorld( Geometry* geom ) const 00065 { 00066 if ( hasReferenceFrame() ) 00067 { 00068 GeometryIterator gi( geom ); 00069 while( gi.hasMore() ) 00070 { 00071 Geometry* g = gi.next(); 00072 for( osg::Vec3dArray::iterator i = g->begin(); i != g->end(); ++i ) 00073 *i = *i * _inverseReferenceFrame; 00074 } 00075 } 00076 } 00077 00078 osg::Vec3d 00079 FilterContext::toMap( const osg::Vec3d& point ) const 00080 { 00081 osg::Vec3d world = toWorld(point); 00082 if ( _isGeocentric ) 00083 _extent->getSRS()->transformFromECEF( world, world ); 00084 return world; 00085 } 00086 00087 osg::Vec3d 00088 FilterContext::fromMap( const osg::Vec3d& point ) const 00089 { 00090 osg::Vec3d world; 00091 if ( _isGeocentric ) 00092 _extent->getSRS()->transformToECEF( point, world ); 00093 return toLocal(world); 00094 } 00095 00096 std::string 00097 FilterContext::toString() const 00098 { 00099 std::stringstream buf; 00100 00101 buf << std::fixed 00102 << "CONTEXT: [" 00103 << "profile extent = " << profile()->getExtent().toString() 00104 << ", working extent = " << extent()->toString() 00105 << ", geocentric = " << osgEarth::toString(_isGeocentric) 00106 << "]"; 00107 00108 std::string str = buf.str(); 00109 return str; 00110 }