QGIS API Documentation  2.99.0-Master (69af2f5)
DualEdgeTriangulation.h
Go to the documentation of this file.
1 /***************************************************************************
2  DualEdgeTriangulation.h - description
3  -------------------
4  copyright : (C) 2004 by Marco Hugentobler
5  email : [email protected]
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #ifndef DUALEDGETRIANGULATION_H
18 #define DUALEDGETRIANGULATION_H
19 
20 #include "Triangulation.h"
21 #include "qgis_sip.h"
22 #include "HalfEdge.h"
23 #include <QVector>
24 #include <QList>
25 #include <QSet>
26 #include <QColor>
27 #include <QFile>
28 #include <QTextStream>
29 #include <QMessageBox>
30 #include <cfloat>
31 #include <QBuffer>
32 #include <QStringList>
33 #include <QProgressDialog>
34 #include <QCursor>
35 #include "qgis_analysis.h"
36 
39 class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
40 {
41  public:
43  DualEdgeTriangulation( int nop, Triangulation *decorator );
44  virtual ~DualEdgeTriangulation();
45  void setDecorator( Triangulation *d ) {mDecorator = d;}
47  void addLine( Line3D *line SIP_TRANSFER, bool breakline ) override;
49  int addPoint( QgsPoint *p SIP_TRANSFER ) override;
51  virtual void performConsistencyTest() override;
53  virtual bool calcNormal( double x, double y, Vector3D *result SIP_OUT ) override;
55  virtual bool calcPoint( double x, double y, QgsPoint *result SIP_OUT ) override;
57  //virtual void draw(QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height) const;
59  virtual QgsPoint *getPoint( unsigned int i ) const override;
61  int getOppositePoint( int p1, int p2 ) override;
63  virtual bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, int *n1 SIP_OUT, QgsPoint *p2 SIP_OUT, int *n2 SIP_OUT, QgsPoint *p3 SIP_OUT, int *n3 SIP_OUT ) SIP_PYNAME( getTriangleVertices ) override;
65  virtual bool getTriangle( double x, double y, QgsPoint *p1 SIP_OUT, QgsPoint *p2 SIP_OUT, QgsPoint *p3 SIP_OUT ) override;
67  QList<int> *getSurroundingTriangles( int pointno ) override;
69  virtual double getXMax() const override { return xMax; }
71  virtual double getXMin() const override { return xMin; }
73  virtual double getYMax() const override { return yMax; }
75  virtual double getYMin() const override { return yMin; }
77  virtual int getNumberOfPoints() const override;
81  virtual void setEdgeColor( int r, int g, int b ) override;
83  virtual void setForcedEdgeColor( int r, int g, int b ) override;
85  virtual void setBreakEdgeColor( int r, int g, int b ) override;
87  void setTriangleInterpolator( TriangleInterpolator *interpolator ) override;
89  void eliminateHorizontalTriangles() override;
91  virtual void ruppertRefinement() override;
93  bool pointInside( double x, double y ) override;
95  //bool readFromTAFF(QString fileName);
97  //bool saveToTAFF(QString fileName) const;
99  virtual bool swapEdge( double x, double y ) override;
101  virtual QList<int> *getPointsAroundEdge( double x, double y ) override;
102 
105  virtual bool saveAsShapefile( const QString &fileName ) const override;
106 
107  protected:
109  double xMax;
111  double xMin;
113  double yMax;
115  double yMin;
117  static const unsigned int DEFAULT_STORAGE_FOR_POINTS = 100000;
119  QVector<QgsPoint *> mPointVector;
121  static const unsigned int DEFAULT_STORAGE_FOR_HALF_EDGES = 300006;
123  QVector<HalfEdge *> mHalfEdge;
125  TriangleInterpolator *mTriangleInterpolator = nullptr;
129  QColor mEdgeColor;
135  Triangulation *mDecorator = nullptr;
137  unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced );
139  int insertForcedSegment( int p1, int p2, bool breakline );
141  //const static double leftOfTresh=0.00001;
143  static const int MAX_BASE_ITERATIONS = 300000;
145  int baseEdgeOfPoint( int point );
147  int baseEdgeOfTriangle( QgsPoint *point );
149  bool checkSwap( unsigned int edge, unsigned int recursiveDeep );
151  void doSwap( unsigned int edge, unsigned int recursiveDeep );
153  void doOnlySwap( unsigned int edge );
155  unsigned int mEdgeInside;
157  unsigned int mEdgeOutside;
159  unsigned int mEdgeWithPoint;
161  unsigned int mUnstableEdge;
165  bool swapPossible( unsigned int edge );
167  void triangulatePolygon( QList<int> *poly, QList<int> *free, int mainedge );
169  bool halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const;
171  double swapMinAngle( int edge ) const;
173  int splitHalfEdge( int edge, float position );
175  bool edgeOnConvexHull( int edge );
177  void evaluateInfluenceRegion( QgsPoint *point, int edge, QSet<int> &set );
178 };
179 
180 #ifndef SIP_RUN
181 
183  : xMax( 0 )
184  , xMin( 0 )
185  , yMax( 0 )
186  , yMin( 0 )
187  , mTriangleInterpolator( nullptr )
188  , mForcedCrossBehavior( Triangulation::DeleteFirst )
189  , mEdgeColor( 0, 255, 0 )
190  , mForcedEdgeColor( 0, 0, 255 )
191  , mBreakEdgeColor( 100, 100, 0 )
192  , mDecorator( this )
193  , mEdgeInside( 0 )
194  , mEdgeOutside( 0 )
195  , mEdgeWithPoint( 0 )
196  , mUnstableEdge( 0 )
197  , mTwiceInsPoint( 0 )
198 {
201 }
202 
204  : xMax( 0 )
205  , xMin( 0 )
206  , yMax( 0 )
207  , yMin( 0 )
208  , mTriangleInterpolator( nullptr )
210  , mEdgeColor( 0, 255, 0 )
211  , mForcedEdgeColor( 0, 0, 255 )
212  , mBreakEdgeColor( 100, 100, 0 )
213  , mDecorator( decorator ? decorator : this )
214  , mEdgeInside( 0 )
215  , mEdgeOutside( 0 )
216  , mEdgeWithPoint( 0 )
217  , mUnstableEdge( 0 )
218  , mTwiceInsPoint( 0 )
219 {
220  mPointVector.reserve( nop );
221  mHalfEdge.reserve( nop );
222 }
223 
225 {
226  return mPointVector.count();
227 }
228 
229 inline QgsPoint *DualEdgeTriangulation::getPoint( unsigned int i ) const
230 {
231  return mPointVector.at( i );
232 }
233 
234 inline bool DualEdgeTriangulation::halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const
235 {
236  return (
237  ( getPoint( mHalfEdge[edge]->getPoint() )->x() >= xlowleft &&
238  getPoint( mHalfEdge[edge]->getPoint() )->x() <= xupright &&
239  getPoint( mHalfEdge[edge]->getPoint() )->y() >= ylowleft &&
240  getPoint( mHalfEdge[edge]->getPoint() )->y() <= yupright ) ||
241  ( getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->x() >= xlowleft &&
242  getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->x() <= xupright &&
243  getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->y() >= ylowleft &&
244  getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->y() <= yupright )
245  );
246 }
247 
248 #endif
249 #endif
250 
251 
252 
Triangulation * mDecorator
Pointer to the decorator using this triangulation. It it is used directly, mDecorator equals this...
virtual bool calcPoint(double x, double y, QgsPoint *result)=0
Calculates x-, y and z-value of the point on the surface and assigns it to &#39;result&#39;.
static const unsigned int DEFAULT_STORAGE_FOR_HALF_EDGES
Default value for the number of storable HalfEdges at the beginning.
virtual int addPoint(QgsPoint *p)=0
Adds a point to the triangulation Ownership is transferred to this class.
virtual bool swapEdge(double x, double y)=0
Reads the content of a taff-file.
virtual void setBreakEdgeColor(int r, int g, int b)=0
Sets the color of the breaklines.
The status of the first inserted forced line is reset to that of a normal edge (so that the second in...
Definition: Triangulation.h:37
virtual void setEdgeColor(int r, int g, int b)=0
Sets the color of the normal edges.
int mTwiceInsPoint
If a point has been inserted twice, its number is stored in this member.
bool halfEdgeBBoxTest(int edge, double xlowleft, double ylowleft, double xupright, double yupright) const
Tests, if the bounding box of the halfedge with index i intersects the specified bounding box...
virtual bool saveAsShapefile(const QString &fileName) const =0
Saves the triangulation as a (line) shapefile.
double yMin
Y-coordinate of the lower left corner of the bounding box.
virtual int getNumberOfPoints() const override
Returns the number of points.
virtual void performConsistencyTest()=0
Performs a consistency check, remove this later.
virtual QgsPoint * getPoint(unsigned int i) const =0
Returns a pointer to the point with number i. Any virtual points must have the number -1...
virtual void ruppertRefinement()=0
Adds points to make the triangles better shaped (algorithm of ruppert)
This class represents a line.
Definition: Line3D.h:26
double xMax
X-coordinate of the upper right corner of the bounding box.
unsigned int mUnstableEdge
If an instability occurs in &#39;baseEdgeOfTriangle&#39;, mUnstableEdge is set to the value of the current ed...
DualEdgeTriangulation is an implementation of a triangulation class based on the dual edge data struc...
QVector< HalfEdge * > mHalfEdge
Stores pointers to the HalfEdges.
virtual bool pointInside(double x, double y)=0
Returns true, if the point with coordinates x and y is inside the convex hull and false otherwise...
Class Vector3D represents a 3D-Vector, capable to store x-,y- and z-coordinates in double values...
Definition: Vector3D.h:29
virtual double getYMax() const override
Returns the largest y-coordinate value of the bounding box.
This is an interface for interpolator classes for triangulations.
double yMax
Y-coordinate of the upper right corner of the bounding box.
void setDecorator(Triangulation *d)
virtual QList< int > * getSurroundingTriangles(int pointno)=0
Returns a pointer to a value list with the information of the triangles surrounding (counterclockwise...
QColor mForcedEdgeColor
Color to paint the forced edges.
#define SIP_TRANSFER
Definition: qgis_sip.h:24
virtual double getYMin() const override
Returns the smallest x-coordinate value of the bounding box.
virtual double getXMax() const override
Returns the largest x-coordinate value of the bounding box.
virtual int getNumberOfPoints() const =0
Returns the number of points.
virtual void addLine(Line3D *line, bool breakline)=0
Adds a line (e.g.
virtual void setForcedEdgeColor(int r, int g, int b)=0
Sets the color of the forced edges.
Interface for Triangulation classes.
Definition: Triangulation.h:30
QColor mBreakEdgeColor
Color to paint the breaklines.
Point geometry type, with support for z-dimension and m-values.
Definition: qgspoint.h:36
unsigned int mEdgeWithPoint
If an inserted point is exactly on an existing edge, &#39;baseEdgeOfTriangle&#39; returns -20 and sets the va...
virtual double getXMin() const override
Returns the smallest x-coordinate value of the bounding box.
Triangulation::ForcedCrossBehavior mForcedCrossBehavior
Member to store the behavior in case of crossing forced segments.
unsigned int mEdgeInside
Number of an edge which does not point to the virtual point. It continuously updated for a fast searc...
TriangleInterpolator * mTriangleInterpolator
Association to an interpolator object.
virtual bool calcNormal(double x, double y, Vector3D *result)=0
Calculates the normal at a point on the surface and assigns it to &#39;result&#39;.
virtual QList< int > * getPointsAroundEdge(double x, double y)=0
Returns a value list with the numbers of the four points, which would be affected by an edge swap...
#define SIP_OUT
Definition: qgis_sip.h:39
virtual void setForcedCrossBehavior(Triangulation::ForcedCrossBehavior b)=0
Draws the points, edges and the forced lines.
QVector< QgsPoint * > mPointVector
Stores pointers to all points in the triangulations (including the points contained in the lines) ...
static const unsigned int DEFAULT_STORAGE_FOR_POINTS
Default value for the number of storable points at the beginning.
virtual bool getTriangle(double x, double y, QgsPoint *p1, int *n1, QgsPoint *p2, int *n2, QgsPoint *p3, int *n3)=0
Finds out in which triangle the point with coordinates x and y is and assigns the numbers of the vert...
virtual void eliminateHorizontalTriangles()=0
Eliminates the horizontal triangles by swapping.
QColor mEdgeColor
Color to paint the normal edges.
double xMin
X-coordinate of the lower left corner of the bounding box.
virtual int getOppositePoint(int p1, int p2)=0
Returns the number of the point opposite to the triangle points p1, p2 (which have to be on a halfedg...
ForcedCrossBehavior
Enumeration describing the behavior, if two forced lines cross.
Definition: Triangulation.h:34
virtual QgsPoint * getPoint(unsigned int i) const override
Draws the points, edges and the forced lines.
unsigned int mEdgeOutside
Number of an edge on the outside of the convex hull. It is updated in method &#39;baseEdgeOfTriangle&#39; to ...
#define SIP_PYNAME(name)
Definition: qgis_sip.h:62
virtual void setTriangleInterpolator(TriangleInterpolator *interpolator)=0
Sets an interpolator object.