GEOS 3.11.1
planargraph/PlanarGraph.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2005-2006 Refractions Research Inc.
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************
14 *
15 * Last port: planargraph/PlanarGraph.java rev. 107/138 (JTS-1.10)
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/export.h>
22#include <geos/planargraph/NodeMap.h> // for composition
23
24#include <vector> // for typedefs
25
26#ifdef _MSC_VER
27#pragma warning(push)
28#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
29#endif
30
31// Forward declarations
32namespace geos {
33namespace geom {
34class Coordinate;
35}
36namespace planargraph {
37class DirectedEdge;
38class Edge;
39class Node;
40}
41}
42
43namespace geos {
44namespace planargraph { // geos.planargraph
45
59class GEOS_DLL PlanarGraph {
60
61protected:
62
63 std::vector<Edge*> edges;
64 std::vector<DirectedEdge*> dirEdges;
65 NodeMap nodeMap;
66
75 void
76 add(Node* node)
77 {
78 nodeMap.add(node);
79 }
80
90 void add(Edge* edge);
91
99 void
101 {
102 dirEdges.push_back(dirEdge);
103 }
104
105public:
106
107 typedef std::vector<Edge*> EdgeContainer;
108 typedef EdgeContainer::iterator EdgeIterator;
109
110
116
117 virtual
118 ~PlanarGraph() {}
119
125 Node*
127 {
128 return nodeMap.find(pt);
129 }
130
135 NodeMap::container::iterator
137 {
138 return nodeMap.begin();
139 }
140
141 NodeMap::container::iterator
142 nodeBegin()
143 {
144 return nodeMap.begin();
145 }
146
147 NodeMap::container::const_iterator
148 nodeBegin() const
149 {
150 return nodeMap.begin();
151 }
152
153 NodeMap::container::iterator
154 nodeEnd()
155 {
156 return nodeMap.end();
157 }
158
159 NodeMap::container::const_iterator
160 nodeEnd() const
161 {
162 return nodeMap.end();
163 }
164
171 void
172 getNodes(std::vector<Node*>& nodes)
173 {
174 nodeMap.getNodes(nodes);
175 }
176
185 std::vector<DirectedEdge*>::iterator
187 {
188 return dirEdges.begin();
189 }
190
191 std::vector<DirectedEdge*>::iterator
192 dirEdgeBegin()
193 {
194 return dirEdges.begin();
195 }
196
197 std::vector<DirectedEdge*>::iterator
198 dirEdgeEnd()
199 {
200 return dirEdges.end();
201 }
202
204 std::vector<Edge*>::iterator
206 {
207 return edges.begin();
208 }
209
211 //
215 std::vector<Edge*>::iterator
217 {
218 return edges.begin();
219 }
220
222 //
226 std::vector<Edge*>::iterator
228 {
229 return edges.end();
230 }
231
236 std::vector<Edge*>*
238 {
239 return &edges;
240 }
241
251 void remove(Edge* edge);
252
263
269 void remove(Node* node);
270
276 std::vector<Node*>* findNodesOfDegree(std::size_t degree);
277
284 void findNodesOfDegree(std::size_t degree, std::vector<Node*>& to);
285};
286
287} // namespace geos::planargraph
288} // namespace geos
289
290#ifdef _MSC_VER
291#pragma warning(pop)
292#endif
293
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Represents a directed edge in a PlanarGraph.
Definition: planargraph/DirectedEdge.h:45
Represents an undirected edge of a PlanarGraph.
Definition: planargraph/Edge.h:54
A map of Node, indexed by the coordinate of the node.
Definition: planargraph/NodeMap.h:47
Node * find(const geom::Coordinate &coord)
Returns the Node at the given location, or null if no Node was there.
void getNodes(std::vector< Node * > &nodes)
Returns the Nodes in this NodeMap, sorted in ascending order by angle with the positive x-axis.
Node * add(Node *n)
Adds a node to the std::map, replacing any that is already at that location.
A node in a PlanarGraph is a location where 0 or more Edge meet.
Definition: planargraph/Node.h:44
Represents a directed graph which is embeddable in a planar surface.
Definition: planargraph/PlanarGraph.h:59
PlanarGraph()
Constructs a PlanarGraph without any Edges, DirectedEdges, or Nodes.
Definition: planargraph/PlanarGraph.h:115
std::vector< Edge * >::iterator edgeIterator()
Alias for edgeBegin()
Definition: planargraph/PlanarGraph.h:205
std::vector< DirectedEdge * >::iterator dirEdgeIterator()
Returns an Iterator over the DirectedEdges in this PlanarGraph, in the order in which they were added...
Definition: planargraph/PlanarGraph.h:186
void remove(DirectedEdge *de)
Removes DirectedEdge from its from-Node and from this PlanarGraph.
void add(Edge *edge)
Adds the Edge and its DirectedEdges with this PlanarGraph.
Node * findNode(const geom::Coordinate &pt)
Returns the Node at the given location, or null if no Node was there.
Definition: planargraph/PlanarGraph.h:126
NodeMap::container::iterator nodeIterator()
Returns an Iterator over the Nodes in this PlanarGraph.
Definition: planargraph/PlanarGraph.h:136
std::vector< Node * > * findNodesOfDegree(std::size_t degree)
Returns all Nodes with the given number of Edges around it. The return value is a newly allocated vec...
std::vector< Edge * > * getEdges()
Definition: planargraph/PlanarGraph.h:237
std::vector< Edge * >::iterator edgeBegin()
Returns an iterator to first Edge in this graph.
Definition: planargraph/PlanarGraph.h:216
void add(DirectedEdge *dirEdge)
Adds the Edge to this PlanarGraph.
Definition: planargraph/PlanarGraph.h:100
void add(Node *node)
Adds a node to the std::map, replacing any that is already at that location.
Definition: planargraph/PlanarGraph.h:76
void remove(Edge *edge)
Removes an Edge and its associated DirectedEdges from their from-Nodes and from this PlanarGraph.
void remove(Node *node)
Removes a node from the graph, along with any associated DirectedEdges and Edges.
void findNodesOfDegree(std::size_t degree, std::vector< Node * > &to)
Get all Nodes with the given number of Edges around it.
void getNodes(std::vector< Node * > &nodes)
Returns the Nodes in this PlanarGraph.
Definition: planargraph/PlanarGraph.h:172
std::vector< Edge * >::iterator edgeEnd()
Returns an iterator to one-past last Edge in this graph.
Definition: planargraph/PlanarGraph.h:227
Basic namespace for all GEOS functionalities.
Definition: geos.h:39