QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 "HalfEdge.h"
22 #include <QVector>
23 #include <QList>
24 #include <QSet>
25 #include "MathUtils.h"
26 #include "TriangleInterpolator.h"
27 #include <QColor>
28 #include <QFile>
29 #include <QTextStream>
30 #include <QMessageBox>
31 #include <cfloat>
32 #include <QBuffer>
33 #include <QStringList>
34 #include <QProgressDialog>
35 #include <QCursor>
36 
38 class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
39 {
40  public:
42  DualEdgeTriangulation( int nop, Triangulation* decorator );
43  virtual ~DualEdgeTriangulation();
44  void setDecorator( Triangulation* d ) {mDecorator = d;}
46  void addLine( Line3D* line, bool breakline ) override;
48  int addPoint( Point3D* p ) override;
50  virtual void performConsistencyTest() override;
52  virtual bool calcNormal( double x, double y, Vector3D* result ) override;
54  virtual bool calcPoint( double x, double y, Point3D* result ) override;
56  //virtual void draw(QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height) const;
58  virtual Point3D* getPoint( unsigned int i ) const override;
60  int getOppositePoint( int p1, int p2 ) override;
62 
63  virtual bool getTriangle( double x, double y, Point3D* p1, int* n1, Point3D* p2, int* n2, Point3D* p3, int* n3 ) override;
65  virtual bool getTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 ) 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;
79  void removeLine( int i );
81  void removePoint( int i );
85  virtual void setEdgeColor( int r, int g, int b ) override;
87  virtual void setForcedEdgeColor( int r, int g, int b ) override;
89  virtual void setBreakEdgeColor( int r, int g, int b ) override;
91  void setTriangleInterpolator( TriangleInterpolator* interpolator ) override;
93  void eliminateHorizontalTriangles() override;
95  virtual void ruppertRefinement() override;
97  bool pointInside( double x, double y ) override;
99  //bool readFromTAFF(QString fileName);
101  //bool saveToTAFF(QString fileName) const;
103  virtual bool swapEdge( double x, double y ) override;
105  virtual QList<int>* getPointsAroundEdge( double x, double y ) override;
108  virtual bool saveAsShapefile( const QString& fileName ) const override;
109 
110  protected:
112  double xMax;
114  double xMin;
116  double yMax;
118  double yMin;
120  const static unsigned int mDefaultStorageForPoints = 100000;
122  QVector<Point3D*> mPointVector;
124  const static unsigned int mDefaultStorageForHalfEdges = 300006;
126  QVector<HalfEdge*> mHalfEdge;
132  QColor mEdgeColor;
140  unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced );
142  int insertForcedSegment( int p1, int p2, bool breakline );
144  //const static double leftOfTresh=0.00001;
146  const static int nBaseOfRuns = 300000;
148  int baseEdgeOfPoint( int point );
150  int baseEdgeOfTriangle( Point3D* point );
152  bool checkSwap( unsigned int edge, unsigned int recursiveDeep );
154  void doSwap( unsigned int edge, unsigned int recursiveDeep );
156  void doOnlySwap( unsigned int edge );
158  unsigned int mEdgeInside;
160  unsigned int mEdgeOutside;
162  unsigned int mEdgeWithPoint;
164  unsigned int mUnstableEdge;
168  bool swapPossible( unsigned int edge );
170  void triangulatePolygon( QList<int>* poly, QList<int>* free, int mainedge );
172  bool halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const;
174  double swapMinAngle( int edge ) const;
176  int splitHalfEdge( int edge, float position );
178  bool edgeOnConvexHull( int edge );
180  void evaluateInfluenceRegion( Point3D* point, int edge, QSet<int> &set );
181 };
182 
184  : xMax( 0 )
185  , xMin( 0 )
186  , yMax( 0 )
187  , yMin( 0 )
188  , mTriangleInterpolator( 0 )
189  , mForcedCrossBehaviour( Triangulation::DELETE_FIRST )
190  , mEdgeColor( 0, 255, 0 )
191  , mForcedEdgeColor( 0, 0, 255 )
192  , mBreakEdgeColor( 100, 100, 0 )
193  , mDecorator( this )
194  , mEdgeInside( 0 )
195  , mEdgeOutside( 0 )
196  , mEdgeWithPoint( 0 )
197  , mUnstableEdge( 0 )
198  , mTwiceInsPoint( 0 )
199 {
202 }
203 
205  : xMax( 0 )
206  , xMin( 0 )
207  , yMax( 0 )
208  , yMin( 0 )
209  , mTriangleInterpolator( 0 )
210  , mForcedCrossBehaviour( Triangulation::DELETE_FIRST )
211  , mEdgeColor( 0, 255, 0 )
212  , mForcedEdgeColor( 0, 0, 255 )
213  , mBreakEdgeColor( 100, 100, 0 )
214  , mDecorator( decorator ? decorator : this )
215  , mEdgeInside( 0 )
216  , mEdgeOutside( 0 )
217  , mEdgeWithPoint( 0 )
218  , mUnstableEdge( 0 )
219  , mTwiceInsPoint( 0 )
220 {
221  mPointVector.reserve( nop );
222  mHalfEdge.reserve( nop );
223 }
224 
226 {
227  return (( int )( mPointVector.count() ) );
228 }
229 
230 inline Point3D* DualEdgeTriangulation::getPoint( unsigned int i ) const
231 {
232  return mPointVector.at( i );
233 }
234 
235 inline bool DualEdgeTriangulation::halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const
236 {
237  return (
238  ( getPoint( mHalfEdge[edge]->getPoint() )->getX() >= xlowleft &&
239  getPoint( mHalfEdge[edge]->getPoint() )->getX() <= xupright &&
240  getPoint( mHalfEdge[edge]->getPoint() )->getY() >= ylowleft &&
241  getPoint( mHalfEdge[edge]->getPoint() )->getY() <= yupright ) ||
242  ( getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getX() >= xlowleft &&
243  getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getX() <= xupright &&
244  getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getY() >= ylowleft &&
245  getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getY() <= yupright )
246  );
247 }
248 
249 #endif
250 
251 
252