GEOS  3.9.0dev
NodedSegmentString.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2020 Paul Ramsey <pramsey@cleverelephant.ca>
7  * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
8  * Copyright (C) 2006 Refractions Research Inc.
9  * Copyright (C) 2001-2002 Vivid Solutions Inc.
10  *
11  * This is free software; you can redistribute and/or modify it under
12  * the terms of the GNU Lesser General Public Licence as published
13  * by the Free Software Foundation.
14  * See the COPYING file for more information.
15  *
16  *
17  **********************************************************************
18  *
19  * Last port: noding/NodedSegmentString.java r320 (JTS-1.12)
20  *
21  **********************************************************************/
22 
23 #ifndef GEOS_NODING_NODEDSEGMENTSTRING_H
24 #define GEOS_NODING_NODEDSEGMENTSTRING_H
25 
26 #include <geos/export.h>
27 #include <geos/noding/NodableSegmentString.h> // for inheritance
28 #include <geos/geom/CoordinateSequence.h> // for inlines
29 #include <geos/algorithm/LineIntersector.h>
30 #include <geos/noding/SegmentNode.h>
31 #include <geos/noding/SegmentNodeList.h>
32 #include <geos/noding/SegmentString.h>
33 #include <geos/geom/Coordinate.h>
34 
35 #include <cstddef>
36 
37 #ifdef _MSC_VER
38 #pragma warning(push)
39 #pragma warning(disable: 4251 4355) // warning C4355: 'this' : used in base member initializer list
40 #endif
41 
42 namespace geos {
43 namespace noding { // geos::noding
44 
57 class GEOS_DLL NodedSegmentString : public NodableSegmentString {
58 public:
59 
60  // TODO: provide a templated method using an output iterator
61  template <class II>
62  static void
63  getNodedSubstrings(II from, II too_far,
64  SegmentString::NonConstVect* resultEdgelist)
65  {
66  for(II i = from; i != too_far; ++i) {
67  NodedSegmentString* nss = dynamic_cast<NodedSegmentString*>(*i);
68  assert(nss);
69  nss->getNodeList().addSplitEdges(resultEdgelist);
70  }
71  }
72 
73  template <class C>
74  static void
75  getNodedSubstrings(C* segStrings,
76  SegmentString::NonConstVect* resultEdgelist)
77  {
78  getNodedSubstrings(segStrings->begin(), segStrings->end(), resultEdgelist);
79  }
80 
81  static void getNodedSubstrings(const SegmentString::NonConstVect& segStrings,
82  SegmentString::NonConstVect* resultEdgeList);
83 
85  static SegmentString::NonConstVect* getNodedSubstrings(
86  const SegmentString::NonConstVect& segStrings);
87 
88  std::unique_ptr<std::vector<geom::Coordinate>> getNodedCoordinates();
89 
90 
100  NodedSegmentString(geom::CoordinateSequence* newPts, const void* newContext)
101  : NodableSegmentString(newContext)
102  , nodeList(this)
103  , pts(newPts)
104  {}
105 
107  : NodableSegmentString(ss->getData())
108  , nodeList(this)
109  , pts(ss->getCoordinates()->clone())
110  {}
111 
112  ~NodedSegmentString() override = default;
113 
124  SegmentNode*
125  addIntersectionNode(geom::Coordinate* intPt, std::size_t segmentIndex)
126  {
127  std::size_t normalizedSegmentIndex = segmentIndex;
128 
129  // normalize the intersection point location
130  std::size_t nextSegIndex = normalizedSegmentIndex + 1;
131  if(nextSegIndex < size()) {
132  geom::Coordinate const& nextPt =
133  getCoordinate(nextSegIndex);
134 
135  // Normalize segment index if intPt falls on vertex
136  // The check for point equality is 2D only - Z values are ignored
137  if(intPt->equals2D(nextPt)) {
138  normalizedSegmentIndex = nextSegIndex;
139  }
140  }
141 
142  // Add the intersection point to edge intersection list.
143  SegmentNode* ei = getNodeList().add(*intPt, normalizedSegmentIndex);
144  return ei;
145  }
146 
147  SegmentNodeList& getNodeList();
148 
149  const SegmentNodeList& getNodeList() const;
150 
151  size_t
152  size() const override
153  {
154  return pts->size();
155  }
156 
157  const geom::Coordinate& getCoordinate(size_t i) const override;
158 
159  geom::CoordinateSequence* getCoordinates() const override;
160  geom::CoordinateSequence* releaseCoordinates();
161 
162  bool isClosed() const override;
163 
164  std::ostream& print(std::ostream& os) const override;
165 
166 
174  int getSegmentOctant(size_t index) const;
175 
181  void addIntersections(algorithm::LineIntersector* li,
182  size_t segmentIndex, size_t geomIndex);
183 
191  void addIntersection(algorithm::LineIntersector* li,
192  size_t segmentIndex,
193  size_t geomIndex, size_t intIndex);
194 
202  void addIntersection(const geom::Coordinate& intPt,
203  size_t segmentIndex);
204 
205 
206 private:
207 
208  SegmentNodeList nodeList;
209 
210  std::unique_ptr<geom::CoordinateSequence> pts;
211 
212  static int safeOctant(const geom::Coordinate& p0, const geom::Coordinate& p1);
213 
214 };
215 
216 } // namespace geos::noding
217 } // namespace geos
218 
219 #ifdef _MSC_VER
220 #pragma warning(pop)
221 #endif
222 
223 #endif // GEOS_NODING_NODEDSEGMENTSTRING_H
An interface for classes which support adding nodes to a segment string.
Definition: NodableSegmentString.h:37
SegmentNode * addIntersectionNode(geom::Coordinate *intPt, std::size_t segmentIndex)
Adds an intersection node for a given point and segment to this segment string.
Definition: NodedSegmentString.h:125
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
An interface for classes which represent a sequence of contiguous line segments.
Definition: SegmentString.h:46
Represents a list of contiguous line segments, and supports noding the segments.
Definition: NodedSegmentString.h:57
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition: LineIntersector.h:49
void addSplitEdges(std::vector< SegmentString * > &edgeList)
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:26
A list of the SegmentNode present along a NodedSegmentString.
Definition: SegmentNodeList.h:56
NodedSegmentString(geom::CoordinateSequence *newPts, const void *newContext)
Creates a new segment string from a list of vertices.
Definition: NodedSegmentString.h:100
The internal representation of a list of coordinates inside a Geometry.
Definition: CoordinateSequence.h:58
Represents an intersection point between two NodedSegmentString.
Definition: SegmentNode.h:47