Quantum GIS API Documentation  1.7.5-Wroclaw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 : mhugent@geo.unizh.ch
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 "MathUtils.h"
25 #include "TriangleInterpolator.h"
26 //#include <qapp.h>
27 #include <QColor>
28 #include <QFile>
29 #include <QTextStream>
30 #include <QMessageBox>
31 #include <iostream>
32 #include <cfloat>
33 #include <QBuffer>
34 #include <QStringList>
35 #include <QProgressDialog>
36 #include <QCursor>
37 #include <set>
38 
40 class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
41 {
42  public:
44  DualEdgeTriangulation( int nop, Triangulation* decorator );
45  virtual ~DualEdgeTriangulation();
46  void setDecorator( Triangulation* d ) {mDecorator = d;}
48  void addLine( Line3D* line, bool breakline );
50  int addPoint( Point3D* p );
52  virtual void performConsistencyTest();
54  virtual bool calcNormal( double x, double y, Vector3D* result );
56  virtual bool calcPoint( double x, double y, Point3D* result );
58  //virtual void draw(QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height) const;
60  virtual Point3D* getPoint( unsigned int i ) const;
62  int getOppositePoint( int p1, int p2 );
64  virtual bool getTriangle( double x, double y, Point3D* p1, int* n1, Point3D* p2, int* n2, Point3D* p3, int* n3 );
66  virtual bool getTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 );
68  QList<int>* getSurroundingTriangles( int pointno );
70  virtual double getXMax() const;
72  virtual double getXMin() const;
74  virtual double getYMax() const;
76  virtual double getYMin() const;
78  virtual int getNumberOfPoints() const;
80  void removeLine( int i );
82  void removePoint( int i );
86  virtual void setEdgeColor( int r, int g, int b );
88  virtual void setForcedEdgeColor( int r, int g, int b );
90  virtual void setBreakEdgeColor( int r, int g, int b );
92  void setTriangleInterpolator( TriangleInterpolator* interpolator );
96  virtual void ruppertRefinement();
98  bool pointInside( double x, double y );
100  //bool readFromTAFF(QString fileName);
102  //bool saveToTAFF(QString fileName) const;
104  virtual bool swapEdge( double x, double y );
106  virtual QList<int>* getPointsAroundEdge( double x, double y );
109  virtual bool saveAsShapefile( const QString& fileName ) const;
110 
111  protected:
113  double xMax;
115  double xMin;
117  double yMax;
119  double yMin;
121  const static unsigned int mDefaultStorageForPoints = 100000;
123  QVector<Point3D*> mPointVector;
125  const static unsigned int mDefaultStorageForHalfEdges = 300006;
127  QVector<HalfEdge*> mHalfEdge;
133  QColor mEdgeColor;
141  unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced );
143  int insertForcedSegment( int p1, int p2, bool breakline );
145  //const static double leftOfTresh=0.00001;
147  const static int nBaseOfRuns = 300000;
149  int baseEdgeOfPoint( int point );
151  int baseEdgeOfTriangle( Point3D* point );
153  bool checkSwap( unsigned int edge );
155  void doSwap( unsigned int edge );
157  void doOnlySwap( unsigned int edge );
159  unsigned int mEdgeInside;
161  unsigned int mEdgeOutside;
163  unsigned int mEdgeWithPoint;
165  unsigned int mUnstableEdge;
169  bool swapPossible( unsigned int edge );
171  void triangulatePolygon( QList<int>* poly, QList<int>* free, int mainedge );
173  bool halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const;
175  double swapMinAngle( int edge ) const;
177  int splitHalfEdge( int edge, float position );
179  bool edgeOnConvexHull( int edge );
181  void evaluateInfluenceRegion( Point3D* point, int edge, std::set<int>* set );
182 };
183 
184 inline DualEdgeTriangulation::DualEdgeTriangulation() : xMax( 0 ), xMin( 0 ), yMax( 0 ), yMin( 0 ), mTriangleInterpolator( 0 ), mForcedCrossBehaviour( Triangulation::DELETE_FIRST ), mEdgeColor( 0, 255, 0 ), mForcedEdgeColor( 0, 0, 255 ), mBreakEdgeColor( 100, 100, 0 ), mDecorator( this )
185 {
188 }
189 
190 inline DualEdgeTriangulation::DualEdgeTriangulation( int nop, Triangulation* decorator ): xMax( 0 ), xMin( 0 ), yMax( 0 ), yMin( 0 ), mTriangleInterpolator( 0 ), mForcedCrossBehaviour( Triangulation::DELETE_FIRST ), mEdgeColor( 0, 255, 0 ), mForcedEdgeColor( 0, 0, 255 ), mBreakEdgeColor( 100, 100, 0 ), mDecorator( decorator )
191 {
192  mPointVector.reserve( nop );
193  mHalfEdge.reserve( nop );
194  if ( !mDecorator )
195  {
196  mDecorator = this;
197  }
198 }
199 
200 inline double DualEdgeTriangulation::getXMax() const
201 {
202  return xMax;
203 }
204 
205 inline double DualEdgeTriangulation::getXMin() const
206 {
207  return xMin;
208 }
209 
210 inline double DualEdgeTriangulation::getYMax() const
211 {
212  return yMax;
213 }
214 
215 inline double DualEdgeTriangulation::getYMin() const
216 {
217  return yMin;
218 }
219 
221 {
222  return (( int )( mPointVector.count() ) );
223 }
224 
225 inline Point3D* DualEdgeTriangulation::getPoint( unsigned int i ) const
226 {
227  return mPointVector.at( i );
228 }
229 
230 inline bool DualEdgeTriangulation::halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const
231 {
232  return (( getPoint( mHalfEdge[edge]->getPoint() )->getX() >= xlowleft && getPoint( mHalfEdge[edge]->getPoint() )->getX() <= xupright && getPoint( mHalfEdge[edge]->getPoint() )->getY() >= ylowleft && getPoint( mHalfEdge[edge]->getPoint() )->getY() <= yupright ) || ( getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getX() >= xlowleft && getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getX() <= xupright && getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getY() >= ylowleft && getPoint( mHalfEdge[mHalfEdge[edge]->getDual()]->getPoint() )->getY() <= yupright ) );
233 }
234 
235 #endif
236 
237 
238