GEOS  3.8.0dev
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 <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 
79 class GEOS_DLL QuadEdgeSubdivision {
80 public:
81  typedef std::vector<QuadEdge*> QuadEdgeList;
82 
92  static void getTriangleEdges(const QuadEdge& startQE,
93  const QuadEdge* triEdge[3]);
94 
95 private:
96  QuadEdgeList quadEdges;
97  QuadEdgeList createdEdges;
98  QuadEdge* startingEdges[3];
99  double tolerance;
100  double edgeCoincidenceTolerance;
101  Vertex frameVertex[3];
102  geom::Envelope frameEnv;
103  std::unique_ptr<QuadEdgeLocator> locator;
104 
105 public:
116  QuadEdgeSubdivision(const geom::Envelope& env, double tolerance);
117 
118  virtual ~QuadEdgeSubdivision();
119 
120 private:
121  virtual void createFrame(const geom::Envelope& env);
122 
123  virtual void initSubdiv(QuadEdge* initEdges[3]);
124 
125 public:
132  inline double
133  getTolerance() const
134  {
135  return tolerance;
136  }
137 
143  inline const geom::Envelope&
144  getEnvelope() const
145  {
146  return frameEnv;
147  }
148 
155  inline const QuadEdgeList&
156  getEdges() const
157  {
158  return quadEdges;
159  }
160 
168  inline void
169  setLocator(std::unique_ptr<QuadEdgeLocator> p_locator)
170  {
171  this->locator = std::move(p_locator);
172  }
173 
181  virtual QuadEdge& makeEdge(const Vertex& o, const Vertex& d);
182 
192  virtual QuadEdge& connect(QuadEdge& a, QuadEdge& b);
193 
201  void remove(QuadEdge& e);
202 
221  QuadEdge* locateFromEdge(const Vertex& v,
222  const QuadEdge& startEdge) const;
223 
233  inline QuadEdge*
234  locate(const Vertex& v) const
235  {
236  return locator->locate(v);
237  }
238 
248  inline QuadEdge*
250  {
251  return locator->locate(Vertex(p));
252  }
253 
264  QuadEdge* locate(const geom::Coordinate& p0, const geom::Coordinate& p1);
265 
282  QuadEdge& insertSite(const Vertex& v);
283 
291  bool isFrameEdge(const QuadEdge& e) const;
292 
302  bool isFrameBorderEdge(const QuadEdge& e) const;
303 
311  bool isFrameVertex(const Vertex& v) const;
312 
313 
324  bool isOnEdge(const QuadEdge& e, const geom::Coordinate& p) const;
325 
334  bool isVertexOfEdge(const QuadEdge& e, const Vertex& v) const;
335 
346  std::unique_ptr<QuadEdgeList> getPrimaryEdges(bool includeFrame);
347 
348  /*****************************************************************************
349  * Visitors
350  ****************************************************************************/
351 
352  void visitTriangles(TriangleVisitor* triVisitor, bool includeFrame);
353 
354 private:
355  typedef std::stack<QuadEdge*> QuadEdgeStack;
356  typedef std::set<QuadEdge*> QuadEdgeSet;
357  typedef std::list< geom::CoordinateSequence*> TriList;
358 
364  QuadEdge* triEdges[3];
365 
377  QuadEdge** fetchTriangleToVisit(QuadEdge* edge, QuadEdgeStack& edgeStack, bool includeFrame,
378  QuadEdgeSet& visitedEdges);
379 
387  void getTriangleCoordinates(TriList* triList, bool includeFrame);
388 
389 private:
390  class TriangleCoordinatesVisitor;
391  class TriangleCircumcentreVisitor;
392 
393 public:
401  std::unique_ptr<geom::MultiLineString> getEdges(const geom::GeometryFactory& geomFact);
402 
410  std::unique_ptr<geom::GeometryCollection> getTriangles(const geom::GeometryFactory& geomFact);
411 
422  std::unique_ptr<geom::GeometryCollection> getVoronoiDiagram(const geom::GeometryFactory& geomFact);
423 
434  std::unique_ptr<geom::MultiLineString> getVoronoiDiagramEdges(const geom::GeometryFactory& geomFact);
435 
446  std::unique_ptr< std::vector<geom::Geometry*> > getVoronoiCellPolygons(const geom::GeometryFactory& geomFact);
447 
458  std::unique_ptr< std::vector<geom::Geometry*> > getVoronoiCellEdges(const geom::GeometryFactory& geomFact);
459 
476  std::unique_ptr<QuadEdgeSubdivision::QuadEdgeList> getVertexUniqueEdges(bool includeFrame);
477 
489  std::unique_ptr<geom::Geometry> getVoronoiCellPolygon(QuadEdge* qe, const geom::GeometryFactory& geomFact);
490 
502  std::unique_ptr<geom::Geometry> getVoronoiCellEdge(QuadEdge* qe, const geom::GeometryFactory& geomFact);
503 
504 };
505 
506 } //namespace geos.triangulate.quadedge
507 } //namespace geos.triangulate
508 } //namespace goes
509 
510 #endif //GEOS_TRIANGULATE_QUADEDGE_QUADEDGESUBDIVISION_H
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:59
QuadEdge * locate(const geom::Coordinate &p)
Definition: QuadEdgeSubdivision.h:249
Definition: TriangleVisitor.h:34
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:60
QuadEdge * locate(const Vertex &v) const
Definition: QuadEdgeSubdivision.h:234
Supplies a set of utility methods for building Geometry objects from CoordinateSequence or other Geom...
Definition: GeometryFactory.h:67
Definition: QuadEdgeSubdivision.h:79
Basic namespace for all GEOS functionalities.
Definition: IndexedNestedRingTester.h:25
void setLocator(std::unique_ptr< QuadEdgeLocator > p_locator)
Definition: QuadEdgeSubdivision.h:169
double getTolerance() const
Definition: QuadEdgeSubdivision.h:133
const QuadEdgeList & getEdges() const
Definition: QuadEdgeSubdivision.h:156
Definition: QuadEdge.h:51
const geom::Envelope & getEnvelope() const
Definition: QuadEdgeSubdivision.h:144