GEOS 3.11.2
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 void prepare() const;
65
66 // the parent edge
67 const NodedSegmentString& edge;
68
75 void checkSplitEdgesCorrectness(const std::vector<SegmentString*>& splitEdges) const;
76
85 std::unique_ptr<SegmentString> createSplitEdge(const SegmentNode* ei0, const SegmentNode* ei1) const;
86
97 std::unique_ptr<geom::CoordinateSequence> createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1) const;
98
107 void addCollapsedNodes();
108
113 void findCollapsesFromExistingVertices(
114 std::vector<std::size_t>& collapsedVertexIndexes) const;
115
123 void findCollapsesFromInsertedNodes(
124 std::vector<std::size_t>& collapsedVertexIndexes) const;
125
126 static bool findCollapseIndex(const SegmentNode& ei0, const SegmentNode& ei1,
127 size_t& collapsedVertexIndex);
128
129 void addEdgeCoordinates(const SegmentNode* ei0, const SegmentNode* ei1, std::vector<geom::Coordinate>& coordList) const;
130
131public:
132
133 // Declare type as noncopyable
134 SegmentNodeList(const SegmentNodeList& other) = delete;
135 SegmentNodeList& operator=(const SegmentNodeList& rhs) = delete;
136
137 friend std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
138
139 using container = decltype(nodeMap);
140 using iterator = container::iterator;
141 using const_iterator = container::const_iterator;
142
143 explicit SegmentNodeList(const NodedSegmentString* newEdge): edge(*newEdge) {}
144
145 explicit SegmentNodeList(const NodedSegmentString& newEdge): edge(newEdge) {}
146
147 ~SegmentNodeList() = default;
148
149 const NodedSegmentString&
150 getEdge() const
151 {
152 return edge;
153 }
154
162 void add(const geom::Coordinate& intPt, std::size_t segmentIndex);
163
164 void
165 add(const geom::Coordinate* intPt, std::size_t segmentIndex)
166 {
167 add(*intPt, segmentIndex);
168 }
169
171 size_t
172 size() const
173 {
174 prepare();
175 return nodeMap.size();
176 }
177
178 iterator begin() {
179 prepare();
180 return nodeMap.begin();
181 }
182
183 const_iterator begin() const {
184 prepare();
185 return nodeMap.begin();
186 }
187
188 iterator end() {
189 prepare();
190 return nodeMap.end();
191 }
192
193 const_iterator end() const {
194 prepare();
195 return nodeMap.end();
196 }
197
202
209 void addSplitEdges(std::vector<SegmentString*>& edgeList);
210
211 void
212 addSplitEdges(std::vector<SegmentString*>* edgeList)
213 {
214 assert(edgeList);
215 addSplitEdges(*edgeList);
216 }
217
227 std::vector<geom::Coordinate> getSplitCoordinates();
228
229
230};
231
232std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
233
234} // namespace geos::noding
235} // namespace geos
236
237#ifdef _MSC_VER
238#pragma warning(pop)
239#endif
240
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:58
Represents a list of contiguous line segments, and supports noding the segments.
Definition NodedSegmentString.h:59
A list of the SegmentNode present along a NodedSegmentString.
Definition SegmentNodeList.h:54
std::vector< geom::Coordinate > getSplitCoordinates()
void add(const geom::Coordinate &intPt, std::size_t segmentIndex)
void addSplitEdges(std::vector< SegmentString * > &edgeList)
size_t size() const
Return the number of nodes in this list.
Definition SegmentNodeList.h:172
Represents an intersection point between two NodedSegmentString.
Definition SegmentNode.h:44
Basic namespace for all GEOS functionalities.
Definition geos.h:39