GEOS  3.10.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 <geos/inline.h>
24 
25 #include <cassert>
26 #include <iostream>
27 #include <vector>
28 #include <set>
29 #include <memory>
30 
31 #include <geos/noding/SegmentNode.h> // for composition
32 
33 #ifdef _MSC_VER
34 #pragma warning(push)
35 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
36 #endif
37 
38 // Forward declarations
39 namespace geos {
40 namespace geom {
41 class CoordinateSequence;
42 }
43 namespace noding {
44 class SegmentString;
45 class NodedSegmentString;
46 }
47 }
48 
49 namespace geos {
50 namespace noding { // geos::noding
51 
56 class GEOS_DLL SegmentNodeList {
57 private:
58  // Since we are adding frequently to the SegmentNodeList and iterating infrequently,
59  // it is faster to store all the SegmentNodes in a vector and sort/remove duplicates
60  // before iteration, rather than storing them in a set and continuously maintaining
61  // a sorted order.
62  mutable std::vector<SegmentNode> nodeMap;
63  mutable bool ready = false;
64 
65  void prepare() const;
66 
67  // the parent edge
68  const NodedSegmentString& edge;
69 
76  void checkSplitEdgesCorrectness(const std::vector<SegmentString*>& splitEdges) const;
77 
86  std::unique_ptr<SegmentString> createSplitEdge(const SegmentNode* ei0, const SegmentNode* ei1) const;
87 
98  std::unique_ptr<geom::CoordinateSequence> createSplitEdgePts(const SegmentNode* ei0, const SegmentNode* ei1) const;
99 
108  void addCollapsedNodes();
109 
114  void findCollapsesFromExistingVertices(
115  std::vector<std::size_t>& collapsedVertexIndexes) const;
116 
124  void findCollapsesFromInsertedNodes(
125  std::vector<std::size_t>& collapsedVertexIndexes) const;
126 
127  static bool findCollapseIndex(const SegmentNode& ei0, const SegmentNode& ei1,
128  size_t& collapsedVertexIndex);
129 
130  void addEdgeCoordinates(const SegmentNode* ei0, const SegmentNode* ei1, std::vector<geom::Coordinate>& coordList) const;
131 
132 public:
133 
134  // Declare type as noncopyable
135  SegmentNodeList(const SegmentNodeList& other) = delete;
136  SegmentNodeList& operator=(const SegmentNodeList& rhs) = delete;
137 
138  friend std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
139 
140  using container = decltype(nodeMap);
141  using iterator = container::iterator;
142  using const_iterator = container::const_iterator;
143 
144  explicit SegmentNodeList(const NodedSegmentString* newEdge): edge(*newEdge) {}
145 
146  explicit SegmentNodeList(const NodedSegmentString& newEdge): edge(newEdge) {}
147 
148  ~SegmentNodeList() = default;
149 
150  const NodedSegmentString&
151  getEdge() const
152  {
153  return edge;
154  }
155 
166  void add(const geom::Coordinate& intPt, std::size_t segmentIndex);
167 
168  void
169  add(const geom::Coordinate* intPt, std::size_t segmentIndex)
170  {
171  add(*intPt, segmentIndex);
172  }
173 
175  size_t
176  size() const
177  {
178  prepare();
179  return nodeMap.size();
180  }
181 
182  iterator begin() {
183  prepare();
184  return nodeMap.begin();
185  }
186 
187  const_iterator begin() const {
188  prepare();
189  return nodeMap.begin();
190  }
191 
192  iterator end() {
193  prepare();
194  return nodeMap.end();
195  }
196 
197  const_iterator end() const {
198  prepare();
199  return nodeMap.end();
200  }
201 
205  void addEndpoints();
206 
213  void addSplitEdges(std::vector<SegmentString*>& edgeList);
214 
215  void
216  addSplitEdges(std::vector<SegmentString*>* edgeList)
217  {
218  assert(edgeList);
219  addSplitEdges(*edgeList);
220  }
221 
231  std::vector<geom::Coordinate> getSplitCoordinates();
232 
233 
234 };
235 
236 std::ostream& operator<< (std::ostream& os, const SegmentNodeList& l);
237 
238 } // namespace geos::noding
239 } // namespace geos
240 
241 #ifdef _MSC_VER
242 #pragma warning(pop)
243 #endif
244 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
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:56
void add(const geom::Coordinate &intPt, std::size_t segmentIndex)
void addSplitEdges(std::vector< SegmentString * > &edgeList)
std::vector< geom::Coordinate > getSplitCoordinates()
size_t size() const
Return the number of nodes in this list.
Definition: SegmentNodeList.h:176
Represents an intersection point between two NodedSegmentString.
Definition: SegmentNode.h:47
Basic namespace for all GEOS functionalities.
Definition: Angle.h:26