Complete Note#1 in the http://wiki.osgeo.org/wiki/GEOS_Provenance_Review to get out...
[geos.git] / include / geos / geomgraph / PlanarGraph.h
blob065f63af4cbf431a35ea36dcb107ed0366829a1d
1 /**********************************************************************
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
6 * Copyright (C) 2005-2006 Refractions Research Inc.
7 * Copyright (C) 2001-2002 Vivid Solutions Inc.
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
14 **********************************************************************
16 * Last port: geomgraph/PlanarGraph.java r428 (JTS-1.12+)
18 **********************************************************************/
21 #ifndef GEOS_GEOMGRAPH_PLANARGRAPH_H
22 #define GEOS_GEOMGRAPH_PLANARGRAPH_H
24 #include <geos/export.h>
25 #include <map>
26 #include <vector>
27 #include <memory>
29 #include <geos/geom/Coordinate.h>
30 #include <geos/geomgraph/PlanarGraph.h>
31 #include <geos/geomgraph/NodeMap.h> // for typedefs
32 #include <geos/geomgraph/DirectedEdgeStar.h> // for inlines
34 #include <geos/inline.h>
36 // Forward declarations
37 namespace geos {
38 namespace geom {
39 class Coordinate;
41 namespace geomgraph {
42 class Edge;
43 class Node;
44 class EdgeEnd;
45 class NodeFactory;
49 namespace geos {
50 namespace geomgraph { // geos.geomgraph
52 /**
53 * \brief
54 * Represents a directed graph which is embeddable in a planar surface.
56 * The computation of the IntersectionMatrix relies on the use of a structure
57 * called a "topology graph". The topology graph contains nodes and edges
58 * corresponding to the nodes and line segments of a Geometry. Each
59 * node and edge in the graph is labeled with its topological location
60 * relative to the source geometry.
62 * Note that there is no requirement that points of self-intersection
63 * be a vertex.
64 * Thus to obtain a correct topology graph, Geometry objects must be
65 * self-noded before constructing their graphs.
67 * Two fundamental operations are supported by topology graphs:
69 * - Computing the intersections between all the edges and nodes of
70 * a single graph
71 * - Computing the intersections between the edges and nodes of two
72 * different graphs
75 class GEOS_DLL PlanarGraph {
76 public:
78 /** \brief
79 * For nodes in the collection (first..last),
80 * link the DirectedEdges at the node that are in the result.
82 * This allows clients to link only a subset of nodes in the graph,
83 * for efficiency (because they know that only a subset is of
84 * interest).
86 template <typename It>
87 static void linkResultDirectedEdges(It first, It last)
88 // throw(TopologyException);
90 for ( ; first!=last; ++first )
92 Node *node=*first;
93 assert(node);
95 EdgeEndStar* ees = node->getEdges();
96 assert(ees);
97 DirectedEdgeStar* des = dynamic_cast<DirectedEdgeStar*>(ees);
98 assert(des);
100 // this might throw an exception
101 des->linkResultDirectedEdges();
105 PlanarGraph(const NodeFactory &nodeFact);
107 PlanarGraph();
109 virtual ~PlanarGraph();
111 virtual std::vector<Edge*>::iterator getEdgeIterator();
113 virtual std::vector<EdgeEnd*>* getEdgeEnds();
115 virtual bool isBoundaryNode(int geomIndex, const geom::Coordinate& coord);
117 virtual void add(EdgeEnd *e);
119 virtual NodeMap::iterator getNodeIterator();
121 virtual void getNodes(std::vector<Node*>&);
123 virtual Node* addNode(Node *node);
125 virtual Node* addNode(const geom::Coordinate& coord);
127 /** \brief
128 * @return the node if found; null otherwise
130 virtual Node* find(geom::Coordinate& coord);
132 /** \brief
133 * Add a set of edges to the graph. For each edge two DirectedEdges
134 * will be created. DirectedEdges are NOT linked by this method.
136 virtual void addEdges(const std::vector<Edge*> &edgesToAdd);
138 virtual void linkResultDirectedEdges();
140 virtual void linkAllDirectedEdges();
142 /** \brief
143 * Returns the EdgeEnd which has edge e as its base edge
144 * (MD 18 Feb 2002 - this should return a pair of edges)
146 * @return the edge, if found
147 * <code>null</code> if the edge was not found
149 virtual EdgeEnd* findEdgeEnd(Edge *e);
151 /** \brief
152 * Returns the edge whose first two coordinates are p0 and p1
154 * @return the edge, if found
155 * <code>null</code> if the edge was not found
157 virtual Edge* findEdge(const geom::Coordinate& p0,
158 const geom::Coordinate& p1);
160 /** \brief
161 * Returns the edge which starts at p0 and whose first segment is
162 * parallel to p1
164 * @return the edge, if found
165 * <code>null</code> if the edge was not found
167 virtual Edge* findEdgeInSameDirection(const geom::Coordinate& p0,
168 const geom::Coordinate& p1);
170 virtual std::string printEdges();
172 virtual NodeMap* getNodeMap();
174 protected:
176 std::vector<Edge*> *edges;
178 NodeMap *nodes;
180 std::vector<EdgeEnd*> *edgeEndList;
182 virtual void insertEdge(Edge *e);
184 private:
186 /** \brief
187 * The coordinate pairs match if they define line segments
188 * lying in the same direction.
190 * E.g. the segments are parallel and in the same quadrant
191 * (as opposed to parallel and opposite!).
193 bool matchInSameDirection(const geom::Coordinate& p0,
194 const geom::Coordinate& p1,
195 const geom::Coordinate& ep0,
196 const geom::Coordinate& ep1);
201 } // namespace geos.geomgraph
202 } // namespace geos
204 //#ifdef GEOS_INLINE
205 //# include "geos/geomgraph/PlanarGraph.inl"
206 //#endif
208 #endif // ifndef GEOS_GEOMGRAPH_PLANARGRAPH_H