GEOS 3.15.0dev
EdgeNodingBuilder.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 *
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: operation/overlayng/EdgeNodingBuilder.java 6ef89b096
16 *
17 **********************************************************************/
18
19#pragma once
20
21#include <geos/algorithm/CircularArcIntersector.h>
22#include <geos/algorithm/LineIntersector.h>
23#include <geos/geom/CoordinateSequence.h>
24#include <geos/geom/CircularArc.h>
25#include <geos/geom/Envelope.h>
26#include <geos/geom/Geometry.h>
27#include <geos/geom/GeometryCollection.h>
28#include <geos/geom/LinearRing.h>
29#include <geos/geom/LineString.h>
30#include <geos/geom/Polygon.h>
31#include <geos/geom/SimpleCurve.h>
32#include <geos/noding/ArcIntersectionAdder.h>
33#include <geos/noding/IntersectionAdder.h>
34#include <geos/noding/Noder.h>
35#include <geos/noding/SegmentString.h>
36#include <geos/operation/overlayng/Edge.h>
37#include <geos/operation/overlayng/EdgeSourceInfo.h>
38#include <geos/operation/overlayng/LineLimiter.h>
39#include <geos/operation/overlayng/RingClipper.h>
40
41
42#include <geos/export.h>
43#include <array>
44#include <memory>
45#include <deque>
46
47
48
49namespace geos { // geos.
50namespace operation { // geos.operation
51namespace overlayng { // geos.operation.overlayng
52
68class GEOS_DLL EdgeNodingBuilder {
75 using CompoundCurve = geos::geom::CompoundCurve;
76 using CircularString = geos::geom::CircularString;
80 using SimpleCurve = geos::geom::SimpleCurve;
81 using Curve = geos::geom::Curve;
82
83private:
84
85 // Constants
86 static constexpr int MIN_LIMIT_PTS = 20;
87 static constexpr bool IS_NODING_VALIDATED = true;
88
89 // Members
90 const PrecisionModel* pm;
91 std::vector<noding::PathString*> inputEdges;
92 noding::Noder* customNoder;
93 std::array<bool, 2> hasEdges;
94 const Envelope* clipEnv;
95 std::unique_ptr<RingClipper> clipper;
96 std::unique_ptr<LineLimiter> limiter;
97
98 // For use in createFloatingPrecisionNoder()
100 algorithm::CircularArcIntersector arcInt;
102 noding::ArcIntersectionAdder arcIntAdder;
103 std::unique_ptr<noding::Noder> internalNoder;
104 std::unique_ptr<noding::Noder> spareInternalNoder;
105 // EdgeSourceInfo*, Edge* owned by EdgeNodingBuilder, stored in deque
106 std::deque<EdgeSourceInfo> edgeSourceInfoQue;
107 std::deque<Edge> edgeQue;
108 bool inputHasZ;
109 bool inputHasM;
110 bool inputHasCurves;
111
120 noding::Noder* getNoder();
121 static std::unique_ptr<noding::Noder> createFixedPrecisionNoder(const PrecisionModel* pm);
122 std::unique_ptr<noding::Noder> createFloatingPrecisionNoder(bool doValidation);
123
124
125 void addCollection(const GeometryCollection* gc, uint8_t geomIndex);
126 void addGeometryCollection(const GeometryCollection* gc, uint8_t geomIndex, int expectedDim);
127 void addPolygon(const Surface* poly, uint8_t geomIndex);
128 void addPolygonRing(const Curve* ring, bool isHole, uint8_t geomIndex);
129 void addSimpleCurve(const SimpleCurve* line, uint8_t geomIndex);
130 void addCompoundCurve(const CompoundCurve* line, uint8_t geomIndex);
131
132 void addCurve(const std::shared_ptr<const CoordinateSequence>& pts, const std::vector<geom::CircularArc>& arcs, uint8_t geomIndex);
133 void addLine(const std::shared_ptr<const CoordinateSequence>& pts, uint8_t geomIndex);
134
135 void addEdge(const std::shared_ptr<const CoordinateSequence>& cas, const EdgeSourceInfo* info);
136 void addCurvedEdge(const std::shared_ptr<const CoordinateSequence>& cas, const std::vector<geom::CircularArc>& arcs, const EdgeSourceInfo* info);
137
138
139 // Create a EdgeSourceInfo* owned by EdgeNodingBuilder
140 const EdgeSourceInfo* createEdgeSourceInfo(uint8_t index, int depthDelta, bool isHole);
141 const EdgeSourceInfo* createEdgeSourceInfo(uint8_t index);
142
147 bool isClippedCompletely(const Envelope* env) const;
148
154 bool isToBeLimited(const LineString* line) const;
155
161 std::vector<std::unique_ptr<CoordinateSequence>>& limit(const LineString* line) const;
162
177 std::shared_ptr<const CoordinateSequence> clip(const LineString* ring) const;
178
186 static std::shared_ptr<const CoordinateSequence> removeRepeatedPoints(const LineString* line);
187
188 static int computeDepthDelta(const CoordinateSequence* ringCoords, bool isHole);
189
190 void add(const Geometry* g, uint8_t geomIndex);
191
198 std::vector<Edge*> node(const std::vector<noding::PathString*>& segStrings);
199 std::vector<Edge*> createEdges(std::vector<std::unique_ptr<noding::PathString>> &segStrings);
200
201
202public:
203
209 EdgeNodingBuilder(const PrecisionModel* p_pm, noding::Noder* p_customNoder)
210 : pm(p_pm)
211 , customNoder(p_customNoder)
212 , hasEdges{{false,false}}
213 , clipEnv(nullptr)
214 , intAdder(lineInt)
215 , arcIntAdder(arcInt)
216 , inputHasZ(false)
217 , inputHasM(false)
218 , inputHasCurves(false)
219 {};
220
221 ~EdgeNodingBuilder();
222
223 void setClipEnvelope(const Envelope* clipEnv);
224
235 bool hasEdgesFor(uint8_t geomIndex) const;
236
248 std::vector<Edge*> build(const Geometry* geom0, const Geometry* geom1);
249
250 // Declare type as noncopyable
251 EdgeNodingBuilder(const EdgeNodingBuilder& other) = delete;
252 EdgeNodingBuilder& operator=(const EdgeNodingBuilder& rhs) = delete;
253};
254
255
256} // namespace geos.operation.overlayng
257} // namespace geos.operation
258} // namespace geos
259
A LineIntersector is an algorithm that can both test whether two line segments intersect and compute ...
Definition LineIntersector.h:53
The internal representation of a list of coordinates inside a Geometry.
Definition CoordinateSequence.h:56
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Represents a collection of heterogeneous Geometry objects.
Definition GeometryCollection.h:51
Basic implementation of Geometry, constructed and destructed by GeometryFactory.
Definition Geometry.h:200
Definition LineString.h:66
Models an OGC SFS LinearRing. A LinearRing is a LineString which is both closed and simple.
Definition LinearRing.h:54
Represents a linear polygon, which may include holes.
Definition Polygon.h:61
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
Definition Surface.h:27
Computes the intersections between two line segments in SegmentString and adds them to each string.
Definition IntersectionAdder.h:54
Computes all intersections between segments in a set of SegmentString.
Definition Noder.h:45
Definition EdgeNodingBuilder.h:68
bool hasEdgesFor(uint8_t geomIndex) const
std::vector< Edge * > build(const Geometry *geom0, const Geometry *geom1)
EdgeNodingBuilder(const PrecisionModel *p_pm, noding::Noder *p_customNoder)
Definition EdgeNodingBuilder.h:209
Definition EdgeSourceInfo.h:38
Basic namespace for all GEOS functionalities.
Definition geos.h:38