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/ScaleFilter> 00020 #include <osgEarth/GeoData> 00021 00022 using namespace osgEarth; 00023 using namespace osgEarth::Features; 00024 using namespace osgEarth::Symbology; 00025 00026 ScaleFilter::ScaleFilter() : 00027 _scale( 0.0 ) 00028 { 00029 //NOP 00030 } 00031 00032 ScaleFilter::ScaleFilter( double scale ) : 00033 _scale( scale ) 00034 { 00035 //NOP 00036 } 00037 00038 FilterContext 00039 ScaleFilter::push( FeatureList& input, FilterContext& cx ) 00040 { 00041 for( FeatureList::iterator i = input.begin(); i != input.end(); ++i ) 00042 { 00043 Feature* input = i->get(); 00044 if ( input && input->getGeometry() ) 00045 { 00046 Bounds envelope = input->getGeometry()->getBounds(); 00047 00048 // now scale and shift everything 00049 GeometryIterator scale_iter( input->getGeometry() ); 00050 while( scale_iter.hasMore() ) 00051 { 00052 Geometry* geom = scale_iter.next(); 00053 for( osg::Vec3dArray::iterator v = geom->begin(); v != geom->end(); v++ ) 00054 { 00055 double xr = (v->x() - envelope.xMin()) / envelope.width(); 00056 v->x() += (xr - 0.5) * _scale; 00057 00058 double yr = (v->y() - envelope.yMin()) / envelope.height(); 00059 v->y() += (yr - 0.5) * _scale; 00060 } 00061 } 00062 } 00063 } 00064 00065 return cx; 00066 } 00067