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>
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
50 namespace geomgraph
{ // geos.geomgraph
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
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
71 * - Computing the intersections between the edges and nodes of two
75 class GEOS_DLL PlanarGraph
{
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
86 template <typename It
>
87 static void linkResultDirectedEdges(It first
, It last
)
88 // throw(TopologyException);
90 for ( ; first
!=last
; ++first
)
95 EdgeEndStar
* ees
= node
->getEdges();
97 DirectedEdgeStar
* des
= dynamic_cast<DirectedEdgeStar
*>(ees
);
100 // this might throw an exception
101 des
->linkResultDirectedEdges();
105 PlanarGraph(const NodeFactory
&nodeFact
);
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
);
128 * @return the node if found; null otherwise
130 virtual Node
* find(geom::Coordinate
& coord
);
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();
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
);
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
);
161 * Returns the edge which starts at p0 and whose first segment is
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();
176 std::vector
<Edge
*> *edges
;
180 std::vector
<EdgeEnd
*> *edgeEndList
;
182 virtual void insertEdge(Edge
*e
);
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
205 //# include "geos/geomgraph/PlanarGraph.inl"
208 #endif // ifndef GEOS_GEOMGRAPH_PLANARGRAPH_H