GEOS  3.8.0dev
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 #ifndef GEOS_PLANARGRAPH_PLANARGRAPH_H
20 #define GEOS_PLANARGRAPH_PLANARGRAPH_H
21 
22 #include <geos/export.h>
23 #include <geos/planargraph/NodeMap.h> // for composition
24 
25 #include <vector> // for typedefs
26 
27 #ifdef _MSC_VER
28 #pragma warning(push)
29 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
30 #endif
31 
32 // Forward declarations
33 namespace geos {
34 namespace geom {
35 class Coordinate;
36 }
37 namespace planargraph {
38 class DirectedEdge;
39 class Edge;
40 class Node;
41 }
42 }
43 
44 namespace geos {
45 namespace planargraph { // geos.planargraph
46 
60 class GEOS_DLL PlanarGraph {
61 
62 protected:
63 
64  std::vector<Edge*> edges;
65  std::vector<DirectedEdge*> dirEdges;
66  NodeMap nodeMap;
67 
77  void
78  add(Node* node)
79  {
80  nodeMap.add(node);
81  }
82 
92  void add(Edge* edge);
93 
101  void
102  add(DirectedEdge* dirEdge)
103  {
104  dirEdges.push_back(dirEdge);
105  }
106 
107 public:
108 
109  typedef std::vector<Edge*> EdgeContainer;
110  typedef EdgeContainer::iterator EdgeIterator;
111 
112 
118 
119  virtual
120  ~PlanarGraph() {}
121 
127  Node*
129  {
130  return nodeMap.find(pt);
131  }
132 
137  NodeMap::container::iterator
139  {
140  return nodeMap.begin();
141  }
142 
143  NodeMap::container::iterator
144  nodeBegin()
145  {
146  return nodeMap.begin();
147  }
148 
149  NodeMap::container::const_iterator
150  nodeBegin() const
151  {
152  return nodeMap.begin();
153  }
154 
155  NodeMap::container::iterator
156  nodeEnd()
157  {
158  return nodeMap.end();
159  }
160 
161  NodeMap::container::const_iterator
162  nodeEnd() const
163  {
164  return nodeMap.end();
165  }
166 
173  void
174  getNodes(std::vector<Node*>& nodes)
175  {
176  nodeMap.getNodes(nodes);
177  }
178 
187  std::vector<DirectedEdge*>::iterator
189  {
190  return dirEdges.begin();
191  }
192 
194  std::vector<Edge*>::iterator
196  {
197  return edges.begin();
198  }
199 
201  //
205  std::vector<Edge*>::iterator
207  {
208  return edges.begin();
209  }
210 
212  //
216  std::vector<Edge*>::iterator
218  {
219  return edges.end();
220  }
221 
227  std::vector<Edge*>*
229  {
230  return &edges;
231  }
232 
242  void remove(Edge* edge);
243 
253  void remove(DirectedEdge* de);
254 
260  void remove(Node* node);
261 
267  std::vector<Node*>* findNodesOfDegree(std::size_t degree);
268 
275  void findNodesOfDegree(std::size_t degree, std::vector<Node*>& to);
276 };
277 
278 } // namespace geos::planargraph
279 } // namespace geos
280 
281 #ifdef _MSC_VER
282 #pragma warning(pop)
283 #endif
284 
285 #endif // GEOS_PLANARGRAPH_PLANARGRAPH_H
void getNodes(std::vector< Node * > &nodes)
Returns the Nodes in this PlanarGraph.
Definition: planargraph/PlanarGraph.h:174
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:188
std::vector< Edge * >::iterator edgeEnd()
Returns an iterator to one-past last Edge in this graph.
Definition: planargraph/PlanarGraph.h:217
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Represents a directed edge in a PlanarGraph.
Definition: planargraph/DirectedEdge.h:46
void add(Node *node)
Adds a node to the std::map, replacing any that is already at that location.
Definition: planargraph/PlanarGraph.h:78
std::vector< Edge * > * getEdges()
Returns the Edges that have been added to this PlanarGraph.
Definition: planargraph/PlanarGraph.h:228
void add(DirectedEdge *dirEdge)
Adds the Edge to this PlanarGraph.
Definition: planargraph/PlanarGraph.h:102
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
Represents an undirected edge of a PlanarGraph.
Definition: planargraph/Edge.h:54
std::vector< Edge * >::iterator edgeIterator()
Alias for edgeBegin()
Definition: planargraph/PlanarGraph.h:195
std::vector< Edge * >::iterator edgeBegin()
Returns an iterator to first Edge in this graph.
Definition: planargraph/PlanarGraph.h:206
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:45
NodeMap::container::iterator nodeIterator()
Returns an Iterator over the Nodes in this PlanarGraph.
Definition: planargraph/PlanarGraph.h:138
Node * findNode(const geom::Coordinate &pt)
Returns the Node at the given location, or null if no Node was there.
Definition: planargraph/PlanarGraph.h:128
Node * find(const geom::Coordinate &coord)
Returns the Node at the given location, or null if no Node was there.
A map of Node, indexed by the coordinate of the node.
Definition: planargraph/NodeMap.h:48
PlanarGraph()
Constructs a PlanarGraph without any Edges, DirectedEdges, or Nodes.
Definition: planargraph/PlanarGraph.h:117
Represents a directed graph which is embeddable in a planar surface.
Definition: planargraph/PlanarGraph.h:60