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/FeatureCursor> 00020 00021 using namespace osgEarth::Features; 00022 using namespace osgEarth::Symbology; 00023 using namespace OpenThreads; 00024 00025 //--------------------------------------------------------------------------- 00026 00027 void 00028 FeatureCursor::fill( FeatureList& list ) 00029 { 00030 while( hasMore() ) 00031 { 00032 list.push_back( nextFeature() ); 00033 } 00034 } 00035 00036 //--------------------------------------------------------------------------- 00037 00038 FeatureListCursor::FeatureListCursor( const FeatureList& features, bool clone ) : 00039 _features( features ), 00040 _clone ( clone ) 00041 { 00042 _iter = _features.begin(); 00043 } 00044 00045 bool 00046 FeatureListCursor::hasMore() const 00047 { 00048 return _iter != _features.end(); 00049 } 00050 00051 Feature* 00052 FeatureListCursor::nextFeature() 00053 { 00054 Feature* r = _iter->get(); 00055 _iter++; 00056 return _clone ? osg::clone(r, osg::CopyOp::DEEP_COPY_ALL) : r; 00057 } 00058 00059 //--------------------------------------------------------------------------- 00060 00061 GeometryFeatureCursor::GeometryFeatureCursor( Geometry* geom ) : 00062 _geom( geom ) 00063 { 00064 //nop 00065 } 00066 00067 GeometryFeatureCursor::GeometryFeatureCursor(Geometry* geom, 00068 const FeatureProfile* fp, 00069 const FeatureFilterList& filters ) : 00070 _geom( geom ), 00071 _featureProfile( fp ), 00072 _filters( filters ) 00073 { 00074 //nop 00075 } 00076 00077 bool 00078 GeometryFeatureCursor::hasMore() const { 00079 return _geom.valid(); 00080 } 00081 00082 Feature* 00083 GeometryFeatureCursor::nextFeature() 00084 { 00085 if ( hasMore() ) 00086 { 00087 _lastFeature = new Feature(); 00088 _lastFeature->setGeometry( _geom.get() ); 00089 FilterContext cx; 00090 cx.profile() = _featureProfile.get(); 00091 FeatureList list; 00092 list.push_back( _lastFeature.get() ); 00093 for( FeatureFilterList::const_iterator i = _filters.begin(); i != _filters.end(); ++i ) { 00094 cx = i->get()->push( list, cx ); 00095 } 00096 _geom = 0L; 00097 } 00098 return _lastFeature.get(); 00099 }