osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthFeatures/BufferFilter.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/BufferFilter>
00020 
00021 using namespace osgEarth;
00022 using namespace osgEarth::Features;
00023 using namespace osgEarth::Symbology;
00024 
00025 bool
00026 BufferFilter::isSupported()
00027 {
00028 #ifdef OSGEARTH_HAVE_GEOS
00029     static bool s_isSupported = true;
00030 #else
00031     static bool s_isSupported = false;
00032 #endif
00033 
00034     return s_isSupported;
00035 }
00036 
00037 #define ASSERT_SUPPORT() \
00038     if ( !BufferFilter::isSupported() ) { \
00039         OE_NOTICE << "BufferFilter NOT SUPPORTED - please compile osgEarth with GEOS" << std::endl; }
00040 
00041 BufferFilter::BufferFilter() :
00042 _distance   ( 1.0 ),
00043 _numQuadSegs( 0 ),
00044 _capStyle   ( Stroke::LINECAP_DEFAULT )
00045 {
00046     //NOP
00047 }
00048 
00049 BufferFilter::BufferFilter( const BufferFilter& rhs ) :
00050 _distance   ( rhs._distance ),
00051 _numQuadSegs( rhs._numQuadSegs ),
00052 _capStyle   ( rhs._capStyle )
00053 {
00054     //NOP
00055 }
00056 
00057 FilterContext
00058 BufferFilter::push( FeatureList& input, FilterContext& context )
00059 {
00060     if ( !isSupported() )
00061     {
00062         OE_WARN << "BufferFilter support not enabled - please compile osgEarth with GEOS" << std::endl;
00063         return context;
00064     }
00065 
00066     //OE_NOTICE << "Buffer: input = " << input.size() << " features" << std::endl;
00067     for( FeatureList::iterator i = input.begin(); i != input.end(); ++i )
00068     {
00069         Feature* input = i->get();
00070         if ( !input || !input->getGeometry() )
00071             continue;
00072 
00073         osg::ref_ptr<Symbology::Geometry> output;
00074 
00075         Symbology::BufferParameters params;
00076         
00077         params._capStyle =
00078                 _capStyle == Stroke::LINECAP_ROUND  ? Symbology::BufferParameters::CAP_ROUND :
00079                 _capStyle == Stroke::LINECAP_SQUARE ? Symbology::BufferParameters::CAP_SQUARE :
00080                 _capStyle == Stroke::LINECAP_BUTT   ? Symbology::BufferParameters::CAP_FLAT :
00081                 Symbology::BufferParameters::CAP_SQUARE;
00082 
00083         params._cornerSegs = _numQuadSegs;
00084 
00085         if ( input->getGeometry()->buffer( _distance.value(), output, params ) )
00086         {
00087             input->setGeometry( output.get() );
00088         }
00089     }
00090 
00091     return context;
00092 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines