osgEarth 2.1.1

/home/cube/sources/osgearth/src/osgEarthDrivers/kml/KML_Polygon.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 "KML_Polygon"
00020 #include "KML_LinearRing"
00021 #include <iterator>
00022 
00023 void
00024 KML_Polygon::parseStyle(const Config& conf, KMLContext& cx, Style& style)
00025 {
00026     KML_Geometry::parseStyle(conf, cx, style);
00027 }
00028 
00029 void
00030 KML_Polygon::parseCoords( const Config& conf, KMLContext& cx )
00031 {
00032     Polygon* poly = new Polygon();
00033 
00034     Config outerConf = conf.child("outerboundaryis");
00035     if ( !outerConf.empty() )
00036     {
00037         Config outerRingConf = outerConf.child("linearring");
00038         if ( !outerRingConf.empty() )
00039         {
00040             KML_LinearRing outer;
00041             outer.parseCoords( outerRingConf, cx );
00042             if ( outer._geom.valid() )
00043             {
00044                 dynamic_cast<Ring*>(outer._geom.get())->rewind( Ring::ORIENTATION_CCW );
00045                 poly->reserve( outer._geom->size() );
00046                 std::copy( outer._geom->begin(), outer._geom->end(), std::back_inserter(*poly) );
00047             }
00048         }
00049 
00050         ConfigSet innerConfs = conf.children("innerboundaryis");
00051         for( ConfigSet::const_iterator i = innerConfs.begin(); i != innerConfs.end(); ++i )
00052         {
00053             Config innerRingConf = i->child("linearring");
00054             if ( !innerRingConf.empty() )
00055             {
00056                 KML_LinearRing inner;
00057                 inner.parseCoords( innerRingConf, cx );
00058                 if ( inner._geom.valid() )
00059                 {
00060                     Geometry* innerGeom = inner._geom.get();
00061                     dynamic_cast<Ring*>(innerGeom)->rewind( Ring::ORIENTATION_CW );
00062                     poly->getHoles().push_back( dynamic_cast<Ring*>(innerGeom) );
00063                 }
00064             }
00065         }
00066     }
00067 
00068     _geom = poly;
00069 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines