GEOS  3.8.0
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 
219  QuadEdge* locateFromEdge(const Vertex& v,
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 
265  QuadEdge* locate(const geom::Coordinate& p0, const geom::Coordinate& p1);
266 
282  QuadEdge& insertSite(const Vertex& v);
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
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
QuadEdge * locate(const geom::Coordinate &p)
Finds a quadedge of a triangle containing a location specified by a geom::Coordinate,...
Definition: QuadEdgeSubdivision.h:249
Definition: TriangleVisitor.h:34
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
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
Models a site (node) in a QuadEdgeSubdivision.
Definition: Vertex.h:59
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:68
const QuadEdgeList & getEdges() const
Gets the collection of base QuadEdges (one for every pair of vertices which is connected).
Definition: QuadEdgeSubdivision.h:152
A class that contains the QuadEdges representing a planar subdivision that models a triangulation.
Definition: QuadEdgeSubdivision.h:78
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
const geom::Envelope & getEnvelope() const
Gets the envelope of the Subdivision (including the frame).
Definition: QuadEdgeSubdivision.h:140
void setLocator(std::unique_ptr< QuadEdgeLocator > p_locator)
Sets the QuadEdgeLocator to use for locating containing triangles in this subdivision.
Definition: QuadEdgeSubdivision.h:165
A class that represents the edge data structure which implements the quadedge algebra.
Definition: QuadEdge.h:51
double getTolerance() const
Gets the vertex-equality tolerance value used in this subdivision.
Definition: QuadEdgeSubdivision.h:129