EdgeRing.h

00001 /**********************************************************************
00002  *
00003  * GEOS - Geometry Engine Open Source
00004  * http://geos.osgeo.org
00005  *
00006  * Copyright (C) 2011 Sandro Santilli <strk@keybit.net>
00007  * Copyright (C) 2005-2006 Refractions Research Inc.
00008  * Copyright (C) 2001-2002 Vivid Solutions Inc.
00009  *
00010  * This is free software; you can redistribute and/or modify it under
00011  * the terms of the GNU Lesser General Public Licence as published
00012  * by the Free Software Foundation. 
00013  * See the COPYING file for more information.
00014  *
00015  **********************************************************************
00016  *
00017  * Last port: geomgraph/EdgeRing.java r428 (JTS-1.12+)
00018  *
00019  **********************************************************************/
00020 
00021 
00022 #ifndef GEOS_GEOMGRAPH_EDGERING_H
00023 #define GEOS_GEOMGRAPH_EDGERING_H
00024 
00025 #include <geos/export.h>
00026 #include <geos/geomgraph/Label.h> // for composition
00027 
00028 #include <geos/inline.h>
00029 
00030 #include <vector>
00031 #include <cassert> // for testInvariant
00032 #include <iosfwd> // for operator<<
00033 
00034 #ifdef _MSC_VER
00035 #pragma warning(push)
00036 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00037 #endif
00038 
00039 // Forward declarations
00040 namespace geos {
00041         namespace geom {
00042                 class GeometryFactory;
00043                 class LinearRing;
00044                 class Polygon;
00045                 class Coordinate;
00046                 class CoordinateSequence;
00047         }
00048         namespace geomgraph {
00049                 class DirectedEdge;
00050                 //class Label;
00051                 class Edge;
00052         }
00053 }
00054 
00055 namespace geos {
00056 namespace geomgraph { // geos.geomgraph
00057 
00059 class GEOS_DLL EdgeRing {
00060 
00061 public:
00062         friend std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
00063 
00064         EdgeRing(DirectedEdge *newStart,
00065                         const geom::GeometryFactory *newGeometryFactory);
00066 
00067         virtual ~EdgeRing();
00068 
00069         bool isIsolated();
00070 
00071         bool isHole();
00072 
00073         /*
00074          * Return a pointer to the LinearRing owned by
00075          * this object. Make a copy if you need it beyond
00076          * this objects's lifetime.
00077          */
00078         geom::LinearRing* getLinearRing();
00079 
00080         Label& getLabel();
00081 
00082         bool isShell();
00083 
00084         EdgeRing *getShell();
00085 
00086         void setShell(EdgeRing *newShell);
00087 
00088         void addHole(EdgeRing *edgeRing);
00089 
00095         geom::Polygon* toPolygon(const geom::GeometryFactory* geometryFactory);
00096 
00102         void computeRing();
00103 
00104         virtual DirectedEdge* getNext(DirectedEdge *de)=0;
00105 
00106         virtual void setEdgeRing(DirectedEdge *de, EdgeRing *er)=0;
00107 
00111         std::vector<DirectedEdge*>& getEdges();
00112 
00113         int getMaxNodeDegree();
00114 
00115         void setInResult();
00116 
00121         bool containsPoint(const geom::Coordinate& p);
00122 
00123         void testInvariant()
00124         {
00125                 // pts are never NULL
00126                 assert(pts);
00127 
00128 #ifndef NDEBUG
00129                 // If this is not an hole, check that
00130                 // each hole is not null and 
00131                 // has 'this' as it's shell
00132                 if ( ! shell )
00133                 {
00134                         for (std::vector<EdgeRing*>::const_iterator
00135                                 it=holes.begin(), itEnd=holes.end();
00136                                 it != itEnd;
00137                                 ++it)
00138                         {
00139                                 EdgeRing* hole=*it;
00140                                 assert(hole);
00141                                 assert(hole->getShell()==this);
00142                         }
00143                 }
00144 #endif // ndef NDEBUG
00145         }
00146 
00147 protected:
00148 
00149         DirectedEdge *startDe; // the directed edge which starts the list of edges for this EdgeRing
00150 
00151         const geom::GeometryFactory *geometryFactory;
00152 
00154         void computePoints(DirectedEdge *newStart);
00155 
00156         void mergeLabel(const Label& deLabel);
00157 
00170         void mergeLabel(const Label& deLabel, int geomIndex);
00171 
00172         void addPoints(Edge *edge, bool isForward, bool isFirstEdge);
00173 
00175         std::vector<EdgeRing*> holes;
00176 
00177 private:
00178 
00179         int maxNodeDegree;
00180 
00182         std::vector<DirectedEdge*> edges;
00183 
00184         geom::CoordinateSequence* pts;
00185 
00186         // label stores the locations of each geometry on the
00187         // face surrounded by this ring
00188         Label label;
00189 
00190         geom::LinearRing *ring;  // the ring created for this EdgeRing
00191 
00192         bool isHoleVar;
00193 
00195         EdgeRing *shell;  
00196 
00197         void computeMaxNodeDegree();
00198 
00199 };
00200 
00201 std::ostream& operator<< (std::ostream& os, const EdgeRing& er);
00202 
00203 } // namespace geos.geomgraph
00204 } // namespace geos
00205 
00206 #ifdef _MSC_VER
00207 #pragma warning(pop)
00208 #endif
00209 
00210 #endif // ifndef GEOS_GEOMGRAPH_EDGERING_H
00211 

Generated on 10 Sep 2013 for GEOS by  doxygen 1.4.7