GEOS 3.11.0
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 iterating infrequently,
57 // it is faster to store all the SegmentNodes in a vector and sort/remove duplicates
58 // before iteration, rather than storing them in a set and continuously maintaining
59 // a sorted order.
60 mutable std::vector<SegmentNode> nodeMap;
61 mutable bool ready = false;
62
63 void prepare() const;
64
65 // the parent edge
66 const NodedSegmentString& edge;
67
74 void checkSplitEdgesCorrectness(const std::vector<SegmentString*>& splitEdges) const;
75
84 std::unique_ptr<SegmentString> createSplitEdge(const SegmentNode* ei0, const SegmentNode* ei1) const;
85
96 std::unique_ptr<geom::CoordinateSequence> createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1) const;
97
106 void addCollapsedNodes();
107
112 void findCollapsesFromExistingVertices(
113 std::vector<std::size_t>& collapsedVertexIndexes) const;
114
122 void findCollapsesFromInsertedNodes(
123 std::vector<std::size_t>& collapsedVertexIndexes) const;
124
125 static bool findCollapseIndex(const SegmentNode& ei0, const SegmentNode& ei1,
126 size_t& collapsedVertexIndex);
127
128 void addEdgeCoordinates(const SegmentNode* ei0, const SegmentNode* ei1, std::vector<geom::Coordinate>& coordList) const;
129
130public:
131
132 // Declare type as noncopyable
133 SegmentNodeList(const SegmentNodeList& other) = delete;
134 SegmentNodeList& operator=(const SegmentNodeList& rhs) = delete;
135
136 friend std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
137
138 using container = decltype(nodeMap);
139 using iterator = container::iterator;
140 using const_iterator = container::const_iterator;
141
142 explicit SegmentNodeList(const NodedSegmentString* newEdge): edge(*newEdge) {}
143
144 explicit SegmentNodeList(const NodedSegmentString& newEdge): edge(newEdge) {}
145
146 ~SegmentNodeList() = default;
147
148 const NodedSegmentString&
149 getEdge() const
150 {
151 return edge;
152 }
153
164 void add(const geom::Coordinate& intPt, std::size_t segmentIndex);
165
166 void
167 add(const geom::Coordinate* intPt, std::size_t segmentIndex)
168 {
169 add(*intPt, segmentIndex);
170 }
171
173 size_t
174 size() const
175 {
176 prepare();
177 return nodeMap.size();
178 }
179
180 iterator begin() {
181 prepare();
182 return nodeMap.begin();
183 }
184
185 const_iterator begin() const {
186 prepare();
187 return nodeMap.begin();
188 }
189
190 iterator end() {
191 prepare();
192 return nodeMap.end();
193 }
194
195 const_iterator end() const {
196 prepare();
197 return nodeMap.end();
198 }
199
204
211 void addSplitEdges(std::vector<SegmentString*>& edgeList);
212
213 void
214 addSplitEdges(std::vector<SegmentString*>* edgeList)
215 {
216 assert(edgeList);
217 addSplitEdges(*edgeList);
218 }
219
229 std::vector<geom::Coordinate> getSplitCoordinates();
230
231
232};
233
234std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
235
236} // namespace geos::noding
237} // namespace geos
238
239#ifdef _MSC_VER
240#pragma warning(pop)
241#endif
242
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:174
Represents an intersection point between two NodedSegmentString.
Definition: SegmentNode.h:45
Basic namespace for all GEOS functionalities.
Definition: geos.h:39