GEOS  3.4.2
GeometryGraph.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/GeometryGraph.java r428 (JTS-1.12+)
00018  *
00019  **********************************************************************/
00020 
00021 
00022 #ifndef GEOS_GEOMGRAPH_GEOMETRYGRAPH_H
00023 #define GEOS_GEOMGRAPH_GEOMETRYGRAPH_H
00024 
00025 #include <geos/export.h>
00026 #include <map>
00027 #include <vector>
00028 #include <memory>
00029 
00030 #include <geos/geom/Coordinate.h>
00031 #include <geos/geom/CoordinateSequence.h> // for auto_ptr<CoordinateSequence>
00032 #include <geos/geomgraph/PlanarGraph.h>
00033 #include <geos/geom/LineString.h> // for LineStringLT
00034 
00035 #include <geos/inline.h>
00036 
00037 #ifdef _MSC_VER
00038 #pragma warning(push)
00039 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
00040 #endif
00041 
00042 // Forward declarations
00043 namespace geos {
00044         namespace geom {
00045                 class LineString;
00046                 class LinearRing;
00047                 class Polygon;
00048                 class Geometry;
00049                 class GeometryCollection;
00050                 class Point;
00051         }
00052         namespace algorithm {
00053                 class LineIntersector;
00054                 class BoundaryNodeRule;
00055         }
00056         namespace geomgraph {
00057                 class Edge;
00058                 class Node;
00059                 namespace index {
00060                         class SegmentIntersector;
00061                         class EdgeSetIntersector;
00062                 }
00063         }
00064 }
00065 
00066 namespace geos {
00067 namespace geomgraph { // geos.geomgraph
00068 
00072 class GEOS_DLL GeometryGraph: public PlanarGraph
00073 {
00074 using PlanarGraph::add;
00075 using PlanarGraph::findEdge;
00076 
00077 private:
00078 
00079         const geom::Geometry* parentGeom;
00080 
00089 //std::map<const geom::LineString*,Edge*,geom::LineStringLT> lineEdgeMap;
00090         std::map<const geom::LineString*, Edge*> lineEdgeMap;
00091 
00096         bool useBoundaryDeterminationRule;
00097 
00098         const algorithm::BoundaryNodeRule& boundaryNodeRule;
00099 
00104         int argIndex;
00105 
00107         std::auto_ptr< geom::CoordinateSequence > boundaryPoints;
00108 
00109         std::auto_ptr< std::vector<Node*> > boundaryNodes;
00110 
00111         bool hasTooFewPointsVar;
00112 
00113         geom::Coordinate invalidPoint; 
00114 
00116         index::EdgeSetIntersector* createEdgeSetIntersector();
00117 
00118         void add(const geom::Geometry *g);
00119                 // throw(UnsupportedOperationException);
00120 
00121         void addCollection(const geom::GeometryCollection *gc);
00122 
00123         void addPoint(const geom::Point *p);
00124 
00125         void addPolygonRing(const geom::LinearRing *lr,
00126                         int cwLeft, int cwRight);
00127 
00128         void addPolygon(const geom::Polygon *p);
00129 
00130         void addLineString(const geom::LineString *line);
00131 
00132         void insertPoint(int argIndex, const geom::Coordinate& coord,
00133                         int onLocation);
00134 
00142         void insertBoundaryPoint(int argIndex, const geom::Coordinate& coord);
00143 
00144         void addSelfIntersectionNodes(int argIndex);
00145 
00153         void addSelfIntersectionNode(int argIndex,
00154                 const geom::Coordinate& coord, int loc);
00155 
00156     // Declare type as noncopyable
00157     GeometryGraph(const GeometryGraph& other);
00158     GeometryGraph& operator=(const GeometryGraph& rhs);
00159 
00160 public:
00161 
00162         static bool isInBoundary(int boundaryCount);
00163 
00164         static int determineBoundary(int boundaryCount);
00165 
00166         static int determineBoundary(
00167                      const algorithm::BoundaryNodeRule& boundaryNodeRule,
00168                                                     int boundaryCount);
00169 
00170         GeometryGraph();
00171 
00172         GeometryGraph(int newArgIndex, const geom::Geometry *newParentGeom);
00173 
00174         GeometryGraph(int newArgIndex, const geom::Geometry *newParentGeom,
00175                       const algorithm::BoundaryNodeRule& boundaryNodeRule);
00176 
00177         virtual ~GeometryGraph();
00178 
00179 
00180         const geom::Geometry* getGeometry();
00181 
00183         std::vector<Node*>* getBoundaryNodes();
00184 
00185         void getBoundaryNodes(std::vector<Node*>&bdyNodes);
00186 
00188         geom::CoordinateSequence* getBoundaryPoints();
00189 
00190         Edge* findEdge(const geom::LineString *line);
00191 
00192         void computeSplitEdges(std::vector<Edge*> *edgelist);
00193 
00194         void addEdge(Edge *e);
00195 
00196         void addPoint(geom::Coordinate& pt);
00197 
00213         index::SegmentIntersector* computeSelfNodes(
00214                         algorithm::LineIntersector *li,
00215                         bool computeRingSelfNodes);
00216 
00217         // Quick inline calling the function above, the above should probably
00218         // be deprecated.
00219         index::SegmentIntersector* computeSelfNodes(
00220                         algorithm::LineIntersector& li,
00221                         bool computeRingSelfNodes);
00222 
00223         index::SegmentIntersector* computeEdgeIntersections(GeometryGraph *g,
00224                 algorithm::LineIntersector *li, bool includeProper);
00225 
00226         std::vector<Edge*> *getEdges();
00227 
00228         bool hasTooFewPoints();
00229 
00230         const geom::Coordinate& getInvalidPoint(); 
00231 
00232         const algorithm::BoundaryNodeRule& getBoundaryNodeRule() const
00233         { return boundaryNodeRule; }
00234 
00235 };
00236 
00237 
00238 } // namespace geos.geomgraph
00239 } // namespace geos
00240 
00241 #ifdef _MSC_VER
00242 #pragma warning(pop)
00243 #endif
00244 
00245 #ifdef GEOS_INLINE
00246 # include "geos/geomgraph/GeometryGraph.inl"
00247 #endif
00248 
00249 #endif // ifndef GEOS_GEOMGRAPH_GEOMETRYGRAPH_H