|
QGIS API Documentation
master-28efcda
|
00001 /*************************************************************************** 00002 DualEdgeTriangulation.h - description 00003 ------------------- 00004 copyright : (C) 2004 by Marco Hugentobler 00005 email : mhugent@geo.unizh.ch 00006 ***************************************************************************/ 00007 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #ifndef DUALEDGETRIANGULATION_H 00018 #define DUALEDGETRIANGULATION_H 00019 00020 #include "Triangulation.h" 00021 #include "HalfEdge.h" 00022 #include <QVector> 00023 #include <QList> 00024 #include <QSet> 00025 #include "MathUtils.h" 00026 #include "TriangleInterpolator.h" 00027 #include <QColor> 00028 #include <QFile> 00029 #include <QTextStream> 00030 #include <QMessageBox> 00031 #include <cfloat> 00032 #include <QBuffer> 00033 #include <QStringList> 00034 #include <QProgressDialog> 00035 #include <QCursor> 00036 00038 class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation 00039 { 00040 public: 00041 DualEdgeTriangulation(); 00042 DualEdgeTriangulation( int nop, Triangulation* decorator ); 00043 virtual ~DualEdgeTriangulation(); 00044 void setDecorator( Triangulation* d ) {mDecorator = d;} 00046 void addLine( Line3D* line, bool breakline ); 00048 int addPoint( Point3D* p ); 00050 virtual void performConsistencyTest(); 00052 virtual bool calcNormal( double x, double y, Vector3D* result ); 00054 virtual bool calcPoint( double x, double y, Point3D* result ); 00056 //virtual void draw(QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height) const; 00058 virtual Point3D* getPoint( unsigned int i ) const; 00060 int getOppositePoint( int p1, int p2 ); 00062 00063 virtual bool getTriangle( double x, double y, Point3D* p1, int* n1, Point3D* p2, int* n2, Point3D* p3, int* n3 ); 00065 virtual bool getTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 ); 00067 QList<int>* getSurroundingTriangles( int pointno ); 00069 virtual double getXMax() const; 00071 virtual double getXMin() const; 00073 virtual double getYMax() const; 00075 virtual double getYMin() const; 00077 virtual int getNumberOfPoints() const; 00079 void removeLine( int i ); 00081 void removePoint( int i ); 00083 virtual void setForcedCrossBehaviour( Triangulation::forcedCrossBehaviour b ); 00085 virtual void setEdgeColor( int r, int g, int b ); 00087 virtual void setForcedEdgeColor( int r, int g, int b ); 00089 virtual void setBreakEdgeColor( int r, int g, int b ); 00091 void setTriangleInterpolator( TriangleInterpolator* interpolator ); 00093 void eliminateHorizontalTriangles(); 00095 virtual void ruppertRefinement(); 00097 bool pointInside( double x, double y ); 00099 //bool readFromTAFF(QString fileName); 00101 //bool saveToTAFF(QString fileName) const; 00103 virtual bool swapEdge( double x, double y ); 00105 virtual QList<int>* getPointsAroundEdge( double x, double y ); 00108 virtual bool saveAsShapefile( const QString& fileName ) const; 00109 00110 protected: 00112 double xMax; 00114 double xMin; 00116 double yMax; 00118 double yMin; 00120 const static unsigned int mDefaultStorageForPoints = 100000; 00122 QVector<Point3D*> mPointVector; 00124 const static unsigned int mDefaultStorageForHalfEdges = 300006; 00126 QVector<HalfEdge*> mHalfEdge; 00128 TriangleInterpolator* mTriangleInterpolator; 00130 Triangulation::forcedCrossBehaviour mForcedCrossBehaviour; 00132 QColor mEdgeColor; 00134 QColor mForcedEdgeColor; 00136 QColor mBreakEdgeColor; 00138 Triangulation* mDecorator; 00140 unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced ); 00142 int insertForcedSegment( int p1, int p2, bool breakline ); 00144 //const static double leftOfTresh=0.00001; 00146 const static int nBaseOfRuns = 300000; 00148 int baseEdgeOfPoint( int point ); 00150 int baseEdgeOfTriangle( Point3D* point ); 00152 bool checkSwap( unsigned int edge ); 00154 void doSwap( unsigned int edge ); 00156 void doOnlySwap( unsigned int edge ); 00158 unsigned int mEdgeInside; 00160 unsigned int mEdgeOutside; 00162 unsigned int mEdgeWithPoint; 00164 unsigned int mUnstableEdge; 00166 int mTwiceInsPoint; 00168 bool swapPossible( unsigned int edge ); 00170 void triangulatePolygon( QList<int>* poly, QList<int>* free, int mainedge ); 00172 bool halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const; 00174 double swapMinAngle( int edge ) const; 00176 int splitHalfEdge( int edge, float position ); 00178 bool edgeOnConvexHull( int edge ); 00180 void evaluateInfluenceRegion( Point3D* point, int edge, QSet<int> &set ); 00181 }; 00182 00183 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 ) 00184 { 00185 mPointVector.reserve( mDefaultStorageForPoints ); 00186 mHalfEdge.reserve( mDefaultStorageForHalfEdges ); 00187 } 00188 00189 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 ) 00190 { 00191 mPointVector.reserve( nop ); 00192 mHalfEdge.reserve( nop ); 00193 if ( !mDecorator ) 00194 { 00195 mDecorator = this; 00196 } 00197 } 00198 00199 inline double DualEdgeTriangulation::getXMax() const 00200 { 00201 return xMax; 00202 } 00203 00204 inline double DualEdgeTriangulation::getXMin() const 00205 { 00206 return xMin; 00207 } 00208 00209 inline double DualEdgeTriangulation::getYMax() const 00210 { 00211 return yMax; 00212 } 00213 00214 inline double DualEdgeTriangulation::getYMin() const 00215 { 00216 return yMin; 00217 } 00218 00219 inline int DualEdgeTriangulation::getNumberOfPoints() const 00220 { 00221 return (( int )( mPointVector.count() ) ); 00222 } 00223 00224 inline Point3D* DualEdgeTriangulation::getPoint( unsigned int i ) const 00225 { 00226 return mPointVector.at( i ); 00227 } 00228 00229 inline bool DualEdgeTriangulation::halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const 00230 { 00231 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 ) ); 00232 } 00233 00234 #endif 00235 00236 00237