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) 2011 Sandro Santilli |
7
|
|
|
|
|
|
|
* Copyright (C) 2006 Refractions Research Inc. |
8
|
|
|
|
|
|
|
* Copyright (C) 2001-2002 Vivid Solutions Inc. |
9
|
|
|
|
|
|
|
* |
10
|
|
|
|
|
|
|
* This is free software; you can redistribute and/or modify it under |
11
|
|
|
|
|
|
|
* the terms of the GNU Lesser General Public Licence as published |
12
|
|
|
|
|
|
|
* by the Free Software Foundation. |
13
|
|
|
|
|
|
|
* See the COPYING file for more information. |
14
|
|
|
|
|
|
|
* |
15
|
|
|
|
|
|
|
* |
16
|
|
|
|
|
|
|
********************************************************************** |
17
|
|
|
|
|
|
|
* |
18
|
|
|
|
|
|
|
* Last port: noding/NodedSegmentString.java r320 (JTS-1.12) |
19
|
|
|
|
|
|
|
* |
20
|
|
|
|
|
|
|
**********************************************************************/ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
#ifndef GEOS_NODING_NODEDSEGMENTSTRING_H |
23
|
|
|
|
|
|
|
#define GEOS_NODING_NODEDSEGMENTSTRING_H |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#include |
26
|
|
|
|
|
|
|
#include // for inheritance |
27
|
|
|
|
|
|
|
#include // for inlines |
28
|
|
|
|
|
|
|
#include |
29
|
|
|
|
|
|
|
#include |
30
|
|
|
|
|
|
|
#include |
31
|
|
|
|
|
|
|
#include |
32
|
|
|
|
|
|
|
//#include |
33
|
|
|
|
|
|
|
#include |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
#include |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#ifdef _MSC_VER |
38
|
|
|
|
|
|
|
#pragma warning(push) |
39
|
|
|
|
|
|
|
#pragma warning(disable: 4251 4355) // warning C4355: 'this' : used in base member initializer list |
40
|
|
|
|
|
|
|
#endif |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
namespace geos { |
43
|
|
|
|
|
|
|
namespace noding { // geos::noding |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
/** \brief |
46
|
|
|
|
|
|
|
* Represents a list of contiguous line segments, |
47
|
|
|
|
|
|
|
* and supports noding the segments. |
48
|
|
|
|
|
|
|
* |
49
|
|
|
|
|
|
|
* The line segments are represented by an array of {@link Coordinate}s. |
50
|
|
|
|
|
|
|
* Intended to optimize the noding of contiguous segments by |
51
|
|
|
|
|
|
|
* reducing the number of allocated objects. |
52
|
|
|
|
|
|
|
* SegmentStrings can carry a context object, which is useful |
53
|
|
|
|
|
|
|
* for preserving topological or parentage information. |
54
|
|
|
|
|
|
|
* All noded substrings are initialized with the same context object. |
55
|
|
|
|
|
|
|
* |
56
|
|
|
|
|
|
|
*/ |
57
|
|
|
|
|
|
|
class GEOS_DLL NodedSegmentString : public NodableSegmentString |
58
|
|
|
|
|
|
|
{ |
59
|
|
|
|
|
|
|
public: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
// TODO: provide a templated method using an output iterator |
62
|
|
|
|
|
|
|
template |
63
|
|
|
|
|
|
|
static void getNodedSubstrings(II from, II too_far, |
64
|
|
|
|
|
|
|
SegmentString::NonConstVect* resultEdgelist) |
65
|
|
|
|
|
|
|
{ |
66
|
|
|
|
|
|
|
for (II i=from; i != too_far; ++i) |
67
|
|
|
|
|
|
|
{ |
68
|
|
|
|
|
|
|
NodedSegmentString * nss = dynamic_cast(*i); |
69
|
|
|
|
|
|
|
assert(nss); |
70
|
|
|
|
|
|
|
nss->getNodeList().addSplitEdges(resultEdgelist); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
template |
75
|
|
|
|
|
|
|
static void getNodedSubstrings(C *segStrings, |
76
|
|
|
|
|
|
|
SegmentString::NonConstVect* resultEdgelist) |
77
|
|
|
|
|
|
|
{ |
78
|
|
|
|
|
|
|
getNodedSubstrings(segStrings->begin(), segStrings->end(), resultEdgelist); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
static void getNodedSubstrings(const SegmentString::NonConstVect& segStrings, |
82
|
|
|
|
|
|
|
SegmentString::NonConstVect* resultEdgeList); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
/// Returns allocated object |
85
|
|
|
|
|
|
|
static SegmentString::NonConstVect* getNodedSubstrings( |
86
|
|
|
|
|
|
|
const SegmentString::NonConstVect& segStrings); |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
/** |
90
|
|
|
|
|
|
|
* Creates a new segment string from a list of vertices. |
91
|
|
|
|
|
|
|
* |
92
|
|
|
|
|
|
|
* @param newPts CoordinateSequence representing the string, |
93
|
|
|
|
|
|
|
* ownership transferred. |
94
|
|
|
|
|
|
|
* |
95
|
|
|
|
|
|
|
* @param data the user-defined data of this segment string |
96
|
|
|
|
|
|
|
* (may be null) |
97
|
|
|
|
|
|
|
*/ |
98
|
16
|
|
|
|
|
|
NodedSegmentString(geom::CoordinateSequence *newPts, const void* newContext) |
99
|
|
|
|
|
|
|
: NodableSegmentString(newContext) |
100
|
|
|
|
|
|
|
, nodeList(this) |
101
|
16
|
|
|
|
|
|
, pts(newPts) |
102
|
16
|
|
|
|
|
|
{} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
~NodedSegmentString() override |
105
|
|
|
|
|
|
|
{ |
106
|
|
|
|
|
|
|
delete pts; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
/** |
110
|
|
|
|
|
|
|
* Adds an intersection node for a given point and segment to this segment string. |
111
|
|
|
|
|
|
|
* If an intersection already exists for this exact location, the existing |
112
|
|
|
|
|
|
|
* node will be returned. |
113
|
|
|
|
|
|
|
* |
114
|
|
|
|
|
|
|
* @param intPt the location of the intersection |
115
|
|
|
|
|
|
|
* @param segmentIndex the index of the segment containing the intersection |
116
|
|
|
|
|
|
|
* @return the intersection node for the point |
117
|
|
|
|
|
|
|
*/ |
118
|
3
|
|
|
|
|
|
SegmentNode* addIntersectionNode( geom::Coordinate * intPt, std::size_t segmentIndex) |
119
|
|
|
|
|
|
|
{ |
120
|
3
|
|
|
|
|
|
std::size_t normalizedSegmentIndex = segmentIndex; |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
// normalize the intersection point location |
123
|
3
|
|
|
|
|
|
std::size_t nextSegIndex = normalizedSegmentIndex + 1; |
124
|
3
|
100
|
|
|
|
|
if (nextSegIndex < size()) |
125
|
|
|
|
|
|
|
{ |
126
|
|
|
|
|
|
|
geom::Coordinate const& nextPt = |
127
|
2
|
|
|
|
|
|
getCoordinate(static_cast(nextSegIndex)); |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
// Normalize segment index if intPt falls on vertex |
130
|
|
|
|
|
|
|
// The check for point equality is 2D only - Z values are ignored |
131
|
2
|
50
|
|
|
|
|
if ( intPt->equals2D( nextPt )) |
132
|
|
|
|
|
|
|
{ |
133
|
2
|
|
|
|
|
|
normalizedSegmentIndex = nextSegIndex; |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
// Add the intersection point to edge intersection list. |
138
|
3
|
|
|
|
|
|
SegmentNode * ei = getNodeList().add( *intPt, normalizedSegmentIndex); |
139
|
3
|
|
|
|
|
|
return ei; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
SegmentNodeList& getNodeList(); |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
const SegmentNodeList& getNodeList() const; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
unsigned int size() const override |
147
|
|
|
|
|
|
|
{ |
148
|
|
|
|
|
|
|
return static_cast(pts->size()); |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
const geom::Coordinate& getCoordinate(unsigned int i) const override; |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
geom::CoordinateSequence* getCoordinates() const override; |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
bool isClosed() const override; |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
std::ostream& print(std::ostream& os) const override; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
/** \brief |
161
|
|
|
|
|
|
|
* Gets the octant of the segment starting at vertex index. |
162
|
|
|
|
|
|
|
* |
163
|
|
|
|
|
|
|
* @param index the index of the vertex starting the segment. |
164
|
|
|
|
|
|
|
* Must not be the last index in the vertex list |
165
|
|
|
|
|
|
|
* @return the octant of the segment at the vertex |
166
|
|
|
|
|
|
|
*/ |
167
|
|
|
|
|
|
|
int getSegmentOctant(unsigned int index) const; |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
/** \brief |
170
|
|
|
|
|
|
|
* Add {SegmentNode}s for one or both |
171
|
|
|
|
|
|
|
* intersections found for a segment of an edge to the edge |
172
|
|
|
|
|
|
|
* intersection list. |
173
|
|
|
|
|
|
|
*/ |
174
|
|
|
|
|
|
|
void addIntersections(algorithm::LineIntersector *li, |
175
|
|
|
|
|
|
|
unsigned int segmentIndex, int geomIndex); |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
/** \brief |
178
|
|
|
|
|
|
|
* Add an SegmentNode for intersection intIndex. |
179
|
|
|
|
|
|
|
* |
180
|
|
|
|
|
|
|
* An intersection that falls exactly on a vertex |
181
|
|
|
|
|
|
|
* of the SegmentString is normalized |
182
|
|
|
|
|
|
|
* to use the higher of the two possible segmentIndexes |
183
|
|
|
|
|
|
|
*/ |
184
|
|
|
|
|
|
|
void addIntersection(algorithm::LineIntersector *li, |
185
|
|
|
|
|
|
|
unsigned int segmentIndex, |
186
|
|
|
|
|
|
|
int geomIndex, int intIndex); |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
/** \brief |
189
|
|
|
|
|
|
|
* Add an SegmentNode for intersection intIndex. |
190
|
|
|
|
|
|
|
* |
191
|
|
|
|
|
|
|
* An intersection that falls exactly on a vertex of the |
192
|
|
|
|
|
|
|
* edge is normalized |
193
|
|
|
|
|
|
|
* to use the higher of the two possible segmentIndexes |
194
|
|
|
|
|
|
|
*/ |
195
|
|
|
|
|
|
|
void addIntersection(const geom::Coordinate& intPt, |
196
|
|
|
|
|
|
|
unsigned int segmentIndex); |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
private: |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
SegmentNodeList nodeList; |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
geom::CoordinateSequence *pts; |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
static int safeOctant(const geom::Coordinate& p0, const geom::Coordinate& p1); |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
}; |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
} // namespace geos::noding |
210
|
|
|
|
|
|
|
} // namespace geos |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
#ifdef _MSC_VER |
213
|
|
|
|
|
|
|
#pragma warning(pop) |
214
|
|
|
|
|
|
|
#endif |
215
|
|
|
|
|
|
|
|
216
|
|
|
|
|
|
|
#endif // GEOS_NODING_NODEDSEGMENTSTRING_H |