GEOS  3.8.1
QuadEdgeSubdivision.h
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/quadedge/QuadEdgeSubdivision.java r524
16  *
17  **********************************************************************/
18 
19 #ifndef GEOS_TRIANGULATE_QUADEDGE_QUADEDGESUBDIVISION_H
20 #define GEOS_TRIANGULATE_QUADEDGE_QUADEDGESUBDIVISION_H
21 
22 #include <memory>
23 #include <list>
24 #include <stack>
25 #include <unordered_set>
26 #include <vector>
27 
28 #include <geos/geom/MultiLineString.h>
29 #include <geos/triangulate/quadedge/QuadEdgeLocator.h>
30 #include <geos/triangulate/quadedge/Vertex.h>
31 
32 namespace geos {
33 
34 namespace geom {
35 
36 class CoordinateSequence;
37 class GeometryCollection;
38 class MultiLineString;
39 class GeometryFactory;
40 class Coordinate;
41 class Geometry;
42 class Envelope;
43 }
44 
45 namespace triangulate { //geos.triangulate
46 namespace quadedge { //geos.triangulate.quadedge
47 
48 class QuadEdge;
49 class TriangleVisitor;
50 
51 const double EDGE_COINCIDENCE_TOL_FACTOR = 1000;
52 
78 class GEOS_DLL QuadEdgeSubdivision {
79 public:
80  typedef std::vector<QuadEdge*> QuadEdgeList;
81 
90  static void getTriangleEdges(const QuadEdge& startQE,
91  const QuadEdge* triEdge[3]);
92 
93 private:
94  QuadEdgeList quadEdges;
95  QuadEdgeList createdEdges;
96  QuadEdge* startingEdges[3];
97  double tolerance;
98  double edgeCoincidenceTolerance;
99  Vertex frameVertex[3];
100  geom::Envelope frameEnv;
101  std::unique_ptr<QuadEdgeLocator> locator;
102  bool visit_state_clean;
103 
104 public:
113  QuadEdgeSubdivision(const geom::Envelope& env, double tolerance);
114 
115  virtual ~QuadEdgeSubdivision();
116 
117 private:
118  virtual void createFrame(const geom::Envelope& env);
119 
120  virtual void initSubdiv(QuadEdge* initEdges[3]);
121 
122 public:
128  inline double
129  getTolerance() const
130  {
131  return tolerance;
132  }
133 
139  inline const geom::Envelope&
140  getEnvelope() const
141  {
142  return frameEnv;
143  }
144 
151  inline const QuadEdgeList&
152  getEdges() const
153  {
154  return quadEdges;
155  }
156 
164  inline void
165  setLocator(std::unique_ptr<QuadEdgeLocator> p_locator)
166  {
167  this->locator = std::move(p_locator);
168  }
169 
177  virtual QuadEdge& makeEdge(const Vertex& o, const Vertex& d);
178 
189  virtual QuadEdge& connect(QuadEdge& a, QuadEdge& b);
190 
198  void remove(QuadEdge& e);
199 
220  const QuadEdge& startEdge) const;
221 
232  inline QuadEdge*
233  locate(const Vertex& v) const
234  {
235  return locator->locate(v);
236  }
237 
248  inline QuadEdge*
250  {
251  return locator->locate(Vertex(p));
252  }
253 
266 
283 
290  bool isFrameEdge(const QuadEdge& e) const;
291 
300  bool isFrameBorderEdge(const QuadEdge& e) const;
301 
308  bool isFrameVertex(const Vertex& v) const;
309 
310 
319  bool isOnEdge(const QuadEdge& e, const geom::Coordinate& p) const;
320 
329  bool isVertexOfEdge(const QuadEdge& e, const Vertex& v) const;
330 
342  std::unique_ptr<QuadEdgeList> getPrimaryEdges(bool includeFrame);
343 
344  /*****************************************************************************
345  * Visitors
346  ****************************************************************************/
347 
348  void visitTriangles(TriangleVisitor* triVisitor, bool includeFrame);
349 
350 private:
351  typedef std::stack<QuadEdge*> QuadEdgeStack;
352  typedef std::vector<std::unique_ptr<geom::CoordinateSequence>> TriList;
353 
359  QuadEdge* triEdges[3];
360 
364  void prepareVisit();
365 
377  QuadEdge** fetchTriangleToVisit(QuadEdge* edge, QuadEdgeStack& edgeStack, bool includeFrame);
378 
385  void getTriangleCoordinates(TriList* triList, bool includeFrame);
386 
387 private:
388  class TriangleCoordinatesVisitor;
389  class TriangleCircumcentreVisitor;
390 
391 public:
400  std::unique_ptr<geom::MultiLineString> getEdges(const geom::GeometryFactory& geomFact);
401 
412  std::unique_ptr<geom::GeometryCollection> getTriangles(const geom::GeometryFactory& geomFact);
413 
426  std::unique_ptr<geom::GeometryCollection> getVoronoiDiagram(const geom::GeometryFactory& geomFact);
427 
439  std::unique_ptr<geom::MultiLineString> getVoronoiDiagramEdges(const geom::GeometryFactory& geomFact);
440 
452  std::vector<std::unique_ptr<geom::Geometry>> getVoronoiCellPolygons(const geom::GeometryFactory& geomFact);
453 
465  std::vector<std::unique_ptr<geom::Geometry>> getVoronoiCellEdges(const geom::GeometryFactory& geomFact);
466 
480  std::unique_ptr<QuadEdgeSubdivision::QuadEdgeList> getVertexUniqueEdges(bool includeFrame);
481 
493  std::unique_ptr<geom::Geometry> getVoronoiCellPolygon(const QuadEdge* qe, const geom::GeometryFactory& geomFact);
494 
506  std::unique_ptr<geom::Geometry> getVoronoiCellEdge(const QuadEdge* qe, const geom::GeometryFactory& geomFact);
507 
508 };
509 
510 } //namespace geos.triangulate.quadedge
511 } //namespace geos.triangulate
512 } //namespace goes
513 
514 #endif //GEOS_TRIANGULATE_QUADEDGE_QUADEDGESUBDIVISION_H
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
A class that contains the QuadEdges representing a planar subdivision that models a triangulation.
Definition: QuadEdgeSubdivision.h:78
bool isFrameBorderEdge(const QuadEdge &e) const
Tests whether a QuadEdge is an edge on the border of the frame facets and the internal facets....
std::unique_ptr< geom::GeometryCollection > getTriangles(const geom::GeometryFactory &geomFact)
Gets the geometry for the triangles in a triangulated subdivision as a GeometryCollection of triangul...
bool isFrameEdge(const QuadEdge &e) const
Tests whether a QuadEdge is an edge incident on a frame triangle vertex.
QuadEdge * locate(const geom::Coordinate &p)
Finds a quadedge of a triangle containing a location specified by a geom::Coordinate,...
Definition: QuadEdgeSubdivision.h:249
virtual QuadEdge & connect(QuadEdge &a, QuadEdge &b)
Creates a new QuadEdge connecting the destination of a to the origin of b, in such a way that all thr...
std::unique_ptr< geom::Geometry > getVoronoiCellEdge(const QuadEdge *qe, const geom::GeometryFactory &geomFact)
Gets the Voronoi cell edge around a site specified by the origin of a QuadEdge.
static void getTriangleEdges(const QuadEdge &startQE, const QuadEdge *triEdge[3])
Gets the edges for the triangle to the left of the given QuadEdge.
const geom::Envelope & getEnvelope() const
Gets the envelope of the Subdivision (including the frame).
Definition: QuadEdgeSubdivision.h:140
bool isFrameVertex(const Vertex &v) const
Tests whether a vertex is a vertex of the outer triangle.
const QuadEdgeList & getEdges() const
Gets the collection of base QuadEdges (one for every pair of vertices which is connected).
Definition: QuadEdgeSubdivision.h:152
QuadEdge * locate(const geom::Coordinate &p0, const geom::Coordinate &p1)
Locates the edge between the given vertices, if it exists in the subdivision.
void remove(QuadEdge &e)
Deletes a quadedge from the subdivision. Linked quadedges are updated to reflect the deletion.
QuadEdge * locate(const Vertex &v) const
Finds a quadedge of a triangle containing a location specified by a Vertex, if one exists.
Definition: QuadEdgeSubdivision.h:233
QuadEdgeSubdivision(const geom::Envelope &env, double tolerance)
Creates a new instance of a quad-edge subdivision based on a frame triangle that encloses a supplied ...
std::unique_ptr< geom::Geometry > getVoronoiCellPolygon(const QuadEdge *qe, const geom::GeometryFactory &geomFact)
Gets the Voronoi cell around a site specified by the origin of a QuadEdge.
std::vector< std::unique_ptr< geom::Geometry > > getVoronoiCellEdges(const geom::GeometryFactory &geomFact)
Gets a List of LineStrings for the Voronoi cells of this triangulation.
std::unique_ptr< QuadEdgeSubdivision::QuadEdgeList > getVertexUniqueEdges(bool includeFrame)
Gets a collection of QuadEdges whose origin vertices are a unique set which includes all vertices in ...
std::unique_ptr< QuadEdgeList > getPrimaryEdges(bool includeFrame)
Gets all primary quadedges in the subdivision.
double getTolerance() const
Gets the vertex-equality tolerance value used in this subdivision.
Definition: QuadEdgeSubdivision.h:129
bool isOnEdge(const QuadEdge &e, const geom::Coordinate &p) const
Tests whether a Coordinate lies on a QuadEdge, up to a tolerance determined by the subdivision tolera...
virtual QuadEdge & makeEdge(const Vertex &o, const Vertex &d)
Creates a new quadedge, recording it in the edges list.
std::unique_ptr< geom::GeometryCollection > getVoronoiDiagram(const geom::GeometryFactory &geomFact)
Gets the cells in the Voronoi diagram for this triangulation. The cells are returned as a GeometryCol...
std::vector< std::unique_ptr< geom::Geometry > > getVoronoiCellPolygons(const geom::GeometryFactory &geomFact)
Gets a List of Polygons for the Voronoi cells of this triangulation.
std::unique_ptr< geom::MultiLineString > getVoronoiDiagramEdges(const geom::GeometryFactory &geomFact)
Gets the cells in the Voronoi diagram for this triangulation.
std::unique_ptr< geom::MultiLineString > getEdges(const geom::GeometryFactory &geomFact)
Gets the geometry for the edges in the subdivision as a MultiLineString containing 2-point lines.
QuadEdge * locateFromEdge(const Vertex &v, const QuadEdge &startEdge) const
Locates an edge of a triangle which contains a location specified by a Vertex v.
QuadEdge & insertSite(const Vertex &v)
Inserts a new site into the Subdivision, connecting it to the vertices of the containing triangle (or...
void setLocator(std::unique_ptr< QuadEdgeLocator > p_locator)
Sets the QuadEdgeLocator to use for locating containing triangles in this subdivision.
Definition: QuadEdgeSubdivision.h:165
bool isVertexOfEdge(const QuadEdge &e, const Vertex &v) const
Tests whether a Vertex is the start or end vertex of a QuadEdge, up to the subdivision tolerance dist...
A class that represents the edge data structure which implements the quadedge algebra.
Definition: QuadEdge.h:51
Definition: TriangleVisitor.h:34
Models a site (node) in a QuadEdgeSubdivision.
Definition: Vertex.h:59
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25