GEOS  3.11.1
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
37 namespace geos {
38 namespace geom {
39 class CoordinateSequence;
40 }
41 namespace noding {
42 class SegmentString;
43 class NodedSegmentString;
44 }
45 }
46 
47 namespace geos {
48 namespace noding { // geos::noding
49 
54 class GEOS_DLL SegmentNodeList {
55 private:
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 
130 public:
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 
161  void add(const geom::Coordinate& intPt, std::size_t segmentIndex);
162 
163  void
164  add(const geom::Coordinate* intPt, std::size_t segmentIndex)
165  {
166  add(*intPt, segmentIndex);
167  }
168 
170  size_t
171  size() const
172  {
173  prepare();
174  return nodeMap.size();
175  }
176 
177  iterator begin() {
178  prepare();
179  return nodeMap.begin();
180  }
181 
182  const_iterator begin() const {
183  prepare();
184  return nodeMap.begin();
185  }
186 
187  iterator end() {
188  prepare();
189  return nodeMap.end();
190  }
191 
192  const_iterator end() const {
193  prepare();
194  return nodeMap.end();
195  }
196 
200  void addEndpoints();
201 
208  void addSplitEdges(std::vector<SegmentString*>& edgeList);
209 
210  void
211  addSplitEdges(std::vector<SegmentString*>* edgeList)
212  {
213  assert(edgeList);
214  addSplitEdges(*edgeList);
215  }
216 
226  std::vector<geom::Coordinate> getSplitCoordinates();
227 
228 
229 };
230 
231 std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
232 
233 } // namespace geos::noding
234 } // namespace geos
235 
236 #ifdef _MSC_VER
237 #pragma warning(pop)
238 #endif
239 
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
size_t size() const
Return the number of nodes in this list.
Definition: SegmentNodeList.h:171
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25
A list of the SegmentNode present along a NodedSegmentString.
Definition: SegmentNodeList.h:54
Represents an intersection point between two NodedSegmentString.
Definition: SegmentNode.h:45