line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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 |
23
|
|
|
|
|
|
|
#include // for composition |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#include // 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
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
/** |
48
|
|
|
|
|
|
|
* \class PlanarGraph planargraph.h geos/planargraph.h |
49
|
|
|
|
|
|
|
* \brief |
50
|
|
|
|
|
|
|
* Represents a directed graph which is embeddable in a planar surface. |
51
|
|
|
|
|
|
|
* |
52
|
|
|
|
|
|
|
* This class and the other classes in this package serve as a framework for |
53
|
|
|
|
|
|
|
* building planar graphs for specific algorithms. This class must be |
54
|
|
|
|
|
|
|
* subclassed to expose appropriate methods to construct the graph. This allows |
55
|
|
|
|
|
|
|
* controlling the types of graph components (DirectedEdge, Edge and Node) |
56
|
|
|
|
|
|
|
* which can be added to the graph. An application which uses the graph |
57
|
|
|
|
|
|
|
* framework will almost always provide subclasses for one or more graph |
58
|
|
|
|
|
|
|
* components, which hold application-specific data and graph algorithms. |
59
|
|
|
|
|
|
|
*/ |
60
|
|
|
|
|
|
|
class GEOS_DLL PlanarGraph { |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
protected: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
std::vector edges; |
65
|
|
|
|
|
|
|
std::vector dirEdges; |
66
|
|
|
|
|
|
|
NodeMap nodeMap; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
/** |
69
|
|
|
|
|
|
|
* \brief |
70
|
|
|
|
|
|
|
* Adds a node to the std::map, replacing any that is already at that |
71
|
|
|
|
|
|
|
* location. |
72
|
|
|
|
|
|
|
* |
73
|
|
|
|
|
|
|
* Only subclasses can add Nodes, to ensure Nodes are |
74
|
|
|
|
|
|
|
* of the right type. |
75
|
|
|
|
|
|
|
* @return the added node |
76
|
|
|
|
|
|
|
*/ |
77
|
|
|
|
|
|
|
void add(Node *node) { |
78
|
|
|
|
|
|
|
nodeMap.add(node); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
/** |
82
|
|
|
|
|
|
|
* \brief |
83
|
|
|
|
|
|
|
* Adds the Edge and its DirectedEdges with this PlanarGraph. |
84
|
|
|
|
|
|
|
* |
85
|
|
|
|
|
|
|
* Assumes that the Edge has already been created with its associated |
86
|
|
|
|
|
|
|
* DirectEdges. |
87
|
|
|
|
|
|
|
* Only subclasses can add Edges, to ensure the edges added are of |
88
|
|
|
|
|
|
|
* the right class. |
89
|
|
|
|
|
|
|
*/ |
90
|
|
|
|
|
|
|
void add(Edge *edge); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
/** |
93
|
|
|
|
|
|
|
* \brief |
94
|
|
|
|
|
|
|
* Adds the Edge to this PlanarGraph. |
95
|
|
|
|
|
|
|
* |
96
|
|
|
|
|
|
|
* Only subclasses can add DirectedEdges, |
97
|
|
|
|
|
|
|
* to ensure the edges added are of the right class. |
98
|
|
|
|
|
|
|
*/ |
99
|
|
|
|
|
|
|
void add(DirectedEdge *dirEdge) { |
100
|
|
|
|
|
|
|
dirEdges.push_back(dirEdge); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
public: |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
typedef std::vector EdgeContainer; |
106
|
|
|
|
|
|
|
typedef EdgeContainer::iterator EdgeIterator; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
/** |
110
|
|
|
|
|
|
|
* \brief |
111
|
|
|
|
|
|
|
* Constructs a PlanarGraph without any Edges, DirectedEdges, or Nodes. |
112
|
|
|
|
|
|
|
*/ |
113
|
1
|
50
|
|
|
|
|
PlanarGraph() {} |
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
virtual ~PlanarGraph() {} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
/** |
118
|
|
|
|
|
|
|
* \brief |
119
|
|
|
|
|
|
|
* Returns the Node at the given location, |
120
|
|
|
|
|
|
|
* or null if no Node was there. |
121
|
|
|
|
|
|
|
*/ |
122
|
|
|
|
|
|
|
Node* findNode(const geom::Coordinate& pt) { |
123
|
|
|
|
|
|
|
return nodeMap.find(pt); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
/** |
127
|
|
|
|
|
|
|
* \brief |
128
|
|
|
|
|
|
|
* Returns an Iterator over the Nodes in this PlanarGraph. |
129
|
|
|
|
|
|
|
*/ |
130
|
|
|
|
|
|
|
NodeMap::container::iterator nodeIterator() { |
131
|
|
|
|
|
|
|
return nodeMap.begin(); |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
NodeMap::container::iterator nodeBegin() { |
135
|
|
|
|
|
|
|
return nodeMap.begin(); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
NodeMap::container::const_iterator nodeBegin() const { |
139
|
|
|
|
|
|
|
return nodeMap.begin(); |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
NodeMap::container::iterator nodeEnd() { |
143
|
|
|
|
|
|
|
return nodeMap.end(); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
NodeMap::container::const_iterator nodeEnd() const { |
147
|
|
|
|
|
|
|
return nodeMap.end(); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
/** |
151
|
|
|
|
|
|
|
* \brief |
152
|
|
|
|
|
|
|
* Returns the Nodes in this PlanarGraph. |
153
|
|
|
|
|
|
|
* |
154
|
|
|
|
|
|
|
* @param nodes : the nodes are push_back'ed here |
155
|
|
|
|
|
|
|
*/ |
156
|
|
|
|
|
|
|
void getNodes(std::vector& nodes) { nodeMap.getNodes(nodes); } |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
/** |
159
|
|
|
|
|
|
|
* \brief |
160
|
|
|
|
|
|
|
* Returns an Iterator over the DirectedEdges in this PlanarGraph, |
161
|
|
|
|
|
|
|
* in the order in which they were added. |
162
|
|
|
|
|
|
|
* |
163
|
|
|
|
|
|
|
* @see add(Edge) |
164
|
|
|
|
|
|
|
* @see add(DirectedEdge) |
165
|
|
|
|
|
|
|
*/ |
166
|
|
|
|
|
|
|
std::vector::iterator dirEdgeIterator() { |
167
|
|
|
|
|
|
|
return dirEdges.begin(); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
/// Alias for edgeBegin() |
171
|
|
|
|
|
|
|
std::vector::iterator edgeIterator() { |
172
|
|
|
|
|
|
|
return edges.begin(); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
/// Returns an iterator to first Edge in this graph. |
176
|
|
|
|
|
|
|
// |
177
|
|
|
|
|
|
|
/// Edges are stored in the order they were added. |
178
|
|
|
|
|
|
|
/// @see add(Edge) |
179
|
|
|
|
|
|
|
/// |
180
|
|
|
|
|
|
|
std::vector::iterator edgeBegin() { |
181
|
|
|
|
|
|
|
return edges.begin(); |
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
/// Returns an iterator to one-past last Edge in this graph. |
185
|
|
|
|
|
|
|
// |
186
|
|
|
|
|
|
|
/// Edges are stored in the order they were added. |
187
|
|
|
|
|
|
|
/// @see add(Edge) |
188
|
|
|
|
|
|
|
/// |
189
|
|
|
|
|
|
|
std::vector::iterator edgeEnd() { |
190
|
|
|
|
|
|
|
return edges.end(); |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
/** |
194
|
|
|
|
|
|
|
* \brief |
195
|
|
|
|
|
|
|
* Returns the Edges that have been added to this PlanarGraph |
196
|
|
|
|
|
|
|
* @see #add(Edge) |
197
|
|
|
|
|
|
|
*/ |
198
|
|
|
|
|
|
|
std::vector* getEdges() { |
199
|
|
|
|
|
|
|
return &edges; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
/** |
203
|
|
|
|
|
|
|
* \brief |
204
|
|
|
|
|
|
|
* Removes an Edge and its associated DirectedEdges from their |
205
|
|
|
|
|
|
|
* from-Nodes and from this PlanarGraph. |
206
|
|
|
|
|
|
|
* |
207
|
|
|
|
|
|
|
* Note: This method does not remove the Nodes associated |
208
|
|
|
|
|
|
|
* with the Edge, even if the removal of the Edge reduces the |
209
|
|
|
|
|
|
|
* degree of a Node to zero. |
210
|
|
|
|
|
|
|
*/ |
211
|
|
|
|
|
|
|
void remove(Edge *edge); |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
/** |
214
|
|
|
|
|
|
|
* \brief |
215
|
|
|
|
|
|
|
* Removes DirectedEdge from its from-Node and from this PlanarGraph. |
216
|
|
|
|
|
|
|
* |
217
|
|
|
|
|
|
|
* Note: |
218
|
|
|
|
|
|
|
* This method does not remove the Nodes associated with the |
219
|
|
|
|
|
|
|
* DirectedEdge, even if the removal of the DirectedEdge reduces |
220
|
|
|
|
|
|
|
* the degree of a Node to zero. |
221
|
|
|
|
|
|
|
*/ |
222
|
|
|
|
|
|
|
void remove(DirectedEdge *de); |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
/** |
225
|
|
|
|
|
|
|
* \brief |
226
|
|
|
|
|
|
|
* Removes a node from the graph, along with any associated |
227
|
|
|
|
|
|
|
* DirectedEdges and Edges. |
228
|
|
|
|
|
|
|
*/ |
229
|
|
|
|
|
|
|
void remove(Node *node); |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
/** |
232
|
|
|
|
|
|
|
* \brief |
233
|
|
|
|
|
|
|
* Returns all Nodes with the given number of Edges around it. |
234
|
|
|
|
|
|
|
* The return value is a newly allocated vector of existing nodes |
235
|
|
|
|
|
|
|
*/ |
236
|
|
|
|
|
|
|
std::vector* findNodesOfDegree(std::size_t degree); |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
/** |
239
|
|
|
|
|
|
|
* \brief |
240
|
|
|
|
|
|
|
* Get all Nodes with the given number of Edges around it. |
241
|
|
|
|
|
|
|
* |
242
|
|
|
|
|
|
|
* Found nodes are pushed to the given vector |
243
|
|
|
|
|
|
|
*/ |
244
|
|
|
|
|
|
|
void findNodesOfDegree(std::size_t degree, std::vector& to); |
245
|
|
|
|
|
|
|
}; |
246
|
|
|
|
|
|
|
|
247
|
|
|
|
|
|
|
} // namespace geos::planargraph |
248
|
|
|
|
|
|
|
} // namespace geos |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
#ifdef _MSC_VER |
251
|
|
|
|
|
|
|
#pragma warning(pop) |
252
|
|
|
|
|
|
|
#endif |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
#endif // GEOS_PLANARGRAPH_PLANARGRAPH_H |