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 
76  void
77  add(Node* node)
78  {
79  nodeMap.add(node);
80  }
81 
91  void add(Edge* edge);
92 
100  void
101  add(DirectedEdge* dirEdge)
102  {
103  dirEdges.push_back(dirEdge);
104  }
105 
106 public:
107 
108  typedef std::vector<Edge*> EdgeContainer;
109  typedef EdgeContainer::iterator EdgeIterator;
110 
111 
117 
118  virtual
119  ~PlanarGraph() {}
120 
126  Node*
128  {
129  return nodeMap.find(pt);
130  }
131 
136  NodeMap::container::iterator
138  {
139  return nodeMap.begin();
140  }
141 
142  NodeMap::container::iterator
143  nodeBegin()
144  {
145  return nodeMap.begin();
146  }
147 
148  NodeMap::container::const_iterator
149  nodeBegin() const
150  {
151  return nodeMap.begin();
152  }
153 
154  NodeMap::container::iterator
155  nodeEnd()
156  {
157  return nodeMap.end();
158  }
159 
160  NodeMap::container::const_iterator
161  nodeEnd() const
162  {
163  return nodeMap.end();
164  }
165 
172  void
173  getNodes(std::vector<Node*>& nodes)
174  {
175  nodeMap.getNodes(nodes);
176  }
177 
186  std::vector<DirectedEdge*>::iterator
188  {
189  return dirEdges.begin();
190  }
191 
193  std::vector<Edge*>::iterator
195  {
196  return edges.begin();
197  }
198 
200  //
204  std::vector<Edge*>::iterator
206  {
207  return edges.begin();
208  }
209 
211  //
215  std::vector<Edge*>::iterator
217  {
218  return edges.end();
219  }
220 
225  std::vector<Edge*>*
227  {
228  return &edges;
229  }
230 
240  void remove(Edge* edge);
241 
251  void remove(DirectedEdge* de);
252 
258  void remove(Node* node);
259 
265  std::vector<Node*>* findNodesOfDegree(std::size_t degree);
266 
273  void findNodesOfDegree(std::size_t degree, std::vector<Node*>& to);
274 };
275 
276 } // namespace geos::planargraph
277 } // namespace geos
278 
279 #ifdef _MSC_VER
280 #pragma warning(pop)
281 #endif
282 
283 #endif // GEOS_PLANARGRAPH_PLANARGRAPH_H
void getNodes(std::vector< Node * > &nodes)
Returns the Nodes in this PlanarGraph.
Definition: planargraph/PlanarGraph.h:173
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:187
std::vector< Edge * >::iterator edgeEnd()
Returns an iterator to one-past last Edge in this graph.
Definition: planargraph/PlanarGraph.h:216
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:77
std::vector< Edge * > * getEdges()
Definition: planargraph/PlanarGraph.h:226
void add(DirectedEdge *dirEdge)
Adds the Edge to this PlanarGraph.
Definition: planargraph/PlanarGraph.h:101
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:194
std::vector< Edge * >::iterator edgeBegin()
Returns an iterator to first Edge in this graph.
Definition: planargraph/PlanarGraph.h:205
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:137
Node * findNode(const geom::Coordinate &pt)
Returns the Node at the given location, or null if no Node was there.
Definition: planargraph/PlanarGraph.h:127
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:116
Represents a directed graph which is embeddable in a planar surface.
Definition: planargraph/PlanarGraph.h:60