GEOS 3.14.0dev
SegmentNodeList.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 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: noding/SegmentNodeList.java rev. 1.8 (JTS-1.10)
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/export.h>
22
23#include <cassert>
24#include <iostream>
25#include <vector>
26#include <set>
27#include <memory>
28
29#include <geos/noding/SegmentNode.h> // for composition
30
31#ifdef _MSC_VER
32#pragma warning(push)
33#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
34#endif
35
36// Forward declarations
37namespace geos {
38namespace geom {
39class CoordinateSequence;
40}
41namespace noding {
42class SegmentString;
43class NodedSegmentString;
44}
45}
46
47namespace geos {
48namespace noding { // geos::noding
49
54class GEOS_DLL SegmentNodeList {
55private:
56 // Since we are adding frequently to the SegmentNodeList and
57 // iterating infrequently, it is faster to store all the
58 // SegmentNodes in a vector and sort/remove duplicates
59 // before iteration, rather than storing them in a set
60 // and continuously maintaining a sorted order.
61 mutable std::vector<SegmentNode> nodeMap;
62 mutable bool ready = false;
63
64 bool constructZ;
65 bool constructM;
66
67 void prepare() const;
68
69 // the parent edge
70 const NodedSegmentString& edge;
71
78 void checkSplitEdgesCorrectness(const std::vector<SegmentString*>& splitEdges) const;
79
88 std::unique_ptr<SegmentString> createSplitEdge(const SegmentNode* ei0, const SegmentNode* ei1) const;
89
100 std::unique_ptr<geom::CoordinateSequence> createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1) const;
101
110 void addCollapsedNodes();
111
116 void findCollapsesFromExistingVertices(
117 std::vector<std::size_t>& collapsedVertexIndexes) const;
118
126 void findCollapsesFromInsertedNodes(
127 std::vector<std::size_t>& collapsedVertexIndexes) const;
128
129 static bool findCollapseIndex(const SegmentNode& ei0, const SegmentNode& ei1,
130 size_t& collapsedVertexIndex);
131
132 void addEdgeCoordinates(const SegmentNode* ei0, const SegmentNode* ei1, geom::CoordinateSequence& coordList) const;
133
134public:
135
136 // Declare type as noncopyable
137 SegmentNodeList(const SegmentNodeList& other) = delete;
138 SegmentNodeList& operator=(const SegmentNodeList& rhs) = delete;
139
140 friend std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
141
142 using container = decltype(nodeMap);
143 using iterator = container::iterator;
144 using const_iterator = container::const_iterator;
145
146 explicit SegmentNodeList(const NodedSegmentString& newEdge,
147 bool p_constructZ,
148 bool p_constructM)
149 : constructZ(p_constructZ)
150 , constructM(p_constructM)
151 , edge(newEdge) {}
152
153 ~SegmentNodeList() = default;
154
155 const NodedSegmentString&
156 getEdge() const
157 {
158 return edge;
159 }
160
161 bool getConstructZ() const {
162 return constructZ;
163 }
164
165 bool getConstructM() const {
166 return constructM;
167 }
168
176 template<typename CoordType>
177 void add(const CoordType& intPt, std::size_t segmentIndex) {
178 // Cast edge to SegmentString to avoid circular dependency between NodedSegmentString and SegmentNodeList
179 nodeMap.emplace_back(edge, intPt, segmentIndex, reinterpret_cast<const SegmentString&>(edge).getSegmentOctant(segmentIndex));
180 ready = false;
181 }
182
184 size_t
185 size() const
186 {
187 prepare();
188 return nodeMap.size();
189 }
190
191 iterator begin() {
192 prepare();
193 return nodeMap.begin();
194 }
195
196 const_iterator begin() const {
197 prepare();
198 return nodeMap.begin();
199 }
200
201 iterator end() {
202 prepare();
203 return nodeMap.end();
204 }
205
206 const_iterator end() const {
207 prepare();
208 return nodeMap.end();
209 }
210
215
222 void addSplitEdges(std::vector<SegmentString*>& edgeList);
223
224 void
225 addSplitEdges(std::vector<SegmentString*>* edgeList)
226 {
227 assert(edgeList);
228 addSplitEdges(*edgeList);
229 }
230
240 std::unique_ptr<geom::CoordinateSequence> getSplitCoordinates();
241
242
243};
244
245std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
246
247} // namespace geos::noding
248} // namespace geos
249
250#ifdef _MSC_VER
251#pragma warning(pop)
252#endif
253
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
Represents a list of contiguous line segments, and supports noding the segments.
Definition NodedSegmentString.h:58
A list of the SegmentNode present along a NodedSegmentString.
Definition SegmentNodeList.h:54
std::unique_ptr< geom::CoordinateSequence > getSplitCoordinates()
void addSplitEdges(std::vector< SegmentString * > &edgeList)
void add(const CoordType &intPt, std::size_t segmentIndex)
Definition SegmentNodeList.h:177
size_t size() const
Return the number of nodes in this list.
Definition SegmentNodeList.h:185
Represents an intersection point between two NodedSegmentString.
Definition SegmentNode.h:38
An interface for classes which represent a sequence of contiguous line segments.
Definition SegmentString.h:47
Basic namespace for all GEOS functionalities.
Definition geos.h:39