Coverage Report

Created: 2024-07-27 06:14

/src/geos/include/geos/triangulate/DelaunayTriangulationBuilder.h
Line
Count
Source (jump to first uncovered line)
1
/**********************************************************************
2
 *
3
 * GEOS - Geometry Engine Open Source
4
 * http://geos.osgeo.org
5
 *
6
 * Copyright (C) 2012 Excensus LLC.
7
 *
8
 * This is free software; you can redistribute and/or modify it under
9
 * the terms of the GNU Lesser General Licence as published
10
 * by the Free Software Foundation.
11
 * See the COPYING file for more information.
12
 *
13
 **********************************************************************
14
 *
15
 * Last port: triangulate/DelaunayTriangulationBuilder.java r524
16
 *
17
 **********************************************************************/
18
19
#pragma once
20
21
#include <geos/triangulate/IncrementalDelaunayTriangulator.h>
22
#include <geos/geom/CoordinateSequence.h>
23
24
#include <memory>
25
26
namespace geos {
27
namespace geom {
28
class Geometry;
29
class MultiLineString;
30
class GeometryCollection;
31
class GeometryFactory;
32
class Envelope;
33
}
34
namespace triangulate {
35
namespace quadedge {
36
class QuadEdgeSubdivision;
37
}
38
}
39
}
40
41
namespace geos {
42
namespace triangulate { //geos.triangulate
43
44
45
/** \brief
46
 * A utility class which creates Delaunay Triangulations
47
 * from collections of points and extract the resulting
48
 * triangulation edges or triangles as geometries.
49
 *
50
 * @author JTS: Martin Davis
51
 * @author Benjamin Campbell
52
 *
53
 */
54
class GEOS_DLL DelaunayTriangulationBuilder {
55
public:
56
    /**
57
     * Extracts the unique {@link geom::Coordinate}s from the given
58
     * {@link geom::Geometry}.
59
     *
60
     * @param geom the geometry to extract from
61
     * @return a List of the unique Coordinates. Caller takes ownership of the returned object.
62
     */
63
    static std::unique_ptr<geom::CoordinateSequence> extractUniqueCoordinates(const geom::Geometry& geom);
64
65
    /**
66
     * Converts all {@link geom::Coordinate}s in a collection to
67
     * {@link quadedge::Vertex}es.
68
     *
69
     * @param coords the coordinates to convert
70
     * @return a List of Vertex objects.
71
     */
72
    static IncrementalDelaunayTriangulator::VertexList toVertices(const geom::CoordinateSequence& coords);
73
74
    /**
75
     * Returns a CoordinateSequence containing only the unique coordinates of its input.
76
     * @param seq a coordinateSequence
77
     * @return a sorted CoordinateSequence with the unique points of seq.
78
     */
79
    static std::unique_ptr<geom::CoordinateSequence> unique(const geom::CoordinateSequence* seq);
80
81
private:
82
    std::unique_ptr<geom::CoordinateSequence> siteCoords;
83
    double tolerance;
84
    std::unique_ptr<quadedge::QuadEdgeSubdivision> subdiv;
85
86
public:
87
    /**
88
     * Creates a new triangulation builder.
89
     *
90
     */
91
    DelaunayTriangulationBuilder();
92
93
0
    ~DelaunayTriangulationBuilder() = default;
94
95
    /**
96
     * Sets the sites (vertices) which will be triangulated.
97
     * All vertices of the given geometry will be used as sites.
98
     *
99
     * @param geom the geometry from which the sites will be extracted.
100
     */
101
    void setSites(const geom::Geometry& geom);
102
103
    /**
104
     * Sets the sites (vertices) which will be triangulated
105
     * from a collection of {@link geom::Coordinate}s.
106
     *
107
     * @param coords a CoordinateSequence.
108
     */
109
    void setSites(const geom::CoordinateSequence& coords);
110
111
    /**
112
     * Sets the snapping tolerance which will be used
113
     * to improved the robustness of the triangulation computation.
114
     * A tolerance of 0.0 specifies that no snapping will take place.
115
     *
116
     * @param p_tolerance the tolerance distance to use
117
     */
118
    inline void
119
    setTolerance(double p_tolerance)
120
0
    {
121
0
        this->tolerance = p_tolerance;
122
0
    }
123
124
private:
125
    void create();
126
127
public:
128
    /**
129
     * Gets the {@link quadedge::QuadEdgeSubdivision} which models the computed triangulation.
130
     *
131
     * @return the subdivision containing the triangulation
132
     */
133
    quadedge::QuadEdgeSubdivision& getSubdivision();
134
135
    /**
136
     * Gets the edges of the computed triangulation as a {@link geom::MultiLineString}.
137
     *
138
     * @param geomFact the geometry factory to use to create the output
139
     * @return the edges of the triangulation. The caller takes ownership of the returned object.
140
     */
141
    std::unique_ptr<geom::MultiLineString> getEdges(const geom::GeometryFactory& geomFact);
142
143
    /**
144
     * Gets the faces of the computed triangulation as a {@link geom::GeometryCollection}
145
     * of {@link geom::Polygon}.
146
     *
147
     * @param geomFact the geometry factory to use to create the output
148
     * @return the faces of the triangulation. The caller takes ownership of the returned object.
149
     */
150
    std::unique_ptr<geom::GeometryCollection> getTriangles(const geom::GeometryFactory& geomFact);
151
152
    /**
153
     * Computes the {@link geom::Envelope} of a collection of
154
     * {@link geom::Coordinate}s.
155
     *
156
     * @param coords a List of Coordinates
157
     * @return the envelope of the set of coordinates
158
     */
159
160
    static geom::Envelope envelope(const geom::CoordinateSequence& coords);
161
162
};
163
164
} //namespace geos.triangulate
165
} //namespace goes
166