Quantum GIS API Documentation
1.7.4
|
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 "MathUtils.h" 00025 #include "TriangleInterpolator.h" 00026 //#include <qapp.h> 00027 #include <QColor> 00028 #include <QFile> 00029 #include <QTextStream> 00030 #include <QMessageBox> 00031 #include <iostream> 00032 #include <cfloat> 00033 #include <QBuffer> 00034 #include <QStringList> 00035 #include <QProgressDialog> 00036 #include <QCursor> 00037 #include <set> 00038 00040 class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation 00041 { 00042 public: 00043 DualEdgeTriangulation(); 00044 DualEdgeTriangulation( int nop, Triangulation* decorator ); 00045 virtual ~DualEdgeTriangulation(); 00046 void setDecorator( Triangulation* d ) {mDecorator = d;} 00048 void addLine( Line3D* line, bool breakline ); 00050 int addPoint( Point3D* p ); 00052 virtual void performConsistencyTest(); 00054 virtual bool calcNormal( double x, double y, Vector3D* result ); 00056 virtual bool calcPoint( double x, double y, Point3D* result ); 00058 //virtual void draw(QPainter* p, double xlowleft, double ylowleft, double xupright, double yupright, double width, double height) const; 00060 virtual Point3D* getPoint( unsigned int i ) const; 00062 int getOppositePoint( int p1, int p2 ); 00064 virtual bool getTriangle( double x, double y, Point3D* p1, int* n1, Point3D* p2, int* n2, Point3D* p3, int* n3 ); 00066 virtual bool getTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 ); 00068 QList<int>* getSurroundingTriangles( int pointno ); 00070 virtual double getXMax() const; 00072 virtual double getXMin() const; 00074 virtual double getYMax() const; 00076 virtual double getYMin() const; 00078 virtual int getNumberOfPoints() const; 00080 void removeLine( int i ); 00082 void removePoint( int i ); 00084 virtual void setForcedCrossBehaviour( Triangulation::forcedCrossBehaviour b ); 00086 virtual void setEdgeColor( int r, int g, int b ); 00088 virtual void setForcedEdgeColor( int r, int g, int b ); 00090 virtual void setBreakEdgeColor( int r, int g, int b ); 00092 void setTriangleInterpolator( TriangleInterpolator* interpolator ); 00094 void eliminateHorizontalTriangles(); 00096 virtual void ruppertRefinement(); 00098 bool pointInside( double x, double y ); 00100 //bool readFromTAFF(QString fileName); 00102 //bool saveToTAFF(QString fileName) const; 00104 virtual bool swapEdge( double x, double y ); 00106 virtual QList<int>* getPointsAroundEdge( double x, double y ); 00109 virtual bool saveAsShapefile( const QString& fileName ) const; 00110 00111 protected: 00113 double xMax; 00115 double xMin; 00117 double yMax; 00119 double yMin; 00121 const static unsigned int mDefaultStorageForPoints = 100000; 00123 QVector<Point3D*> mPointVector; 00125 const static unsigned int mDefaultStorageForHalfEdges = 300006; 00127 QVector<HalfEdge*> mHalfEdge; 00129 TriangleInterpolator* mTriangleInterpolator; 00131 Triangulation::forcedCrossBehaviour mForcedCrossBehaviour; 00133 QColor mEdgeColor; 00135 QColor mForcedEdgeColor; 00137 QColor mBreakEdgeColor; 00139 Triangulation* mDecorator; 00141 unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced ); 00143 int insertForcedSegment( int p1, int p2, bool breakline ); 00145 //const static double leftOfTresh=0.00001; 00147 const static int nBaseOfRuns = 300000; 00149 int baseEdgeOfPoint( int point ); 00151 int baseEdgeOfTriangle( Point3D* point ); 00153 bool checkSwap( unsigned int edge ); 00155 void doSwap( unsigned int edge ); 00157 void doOnlySwap( unsigned int edge ); 00159 unsigned int mEdgeInside; 00161 unsigned int mEdgeOutside; 00163 unsigned int mEdgeWithPoint; 00165 unsigned int mUnstableEdge; 00167 int mTwiceInsPoint; 00169 bool swapPossible( unsigned int edge ); 00171 void triangulatePolygon( QList<int>* poly, QList<int>* free, int mainedge ); 00173 bool halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const; 00175 double swapMinAngle( int edge ) const; 00177 int splitHalfEdge( int edge, float position ); 00179 bool edgeOnConvexHull( int edge ); 00181 void evaluateInfluenceRegion( Point3D* point, int edge, std::set<int>* set ); 00182 }; 00183 00184 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 ) 00185 { 00186 mPointVector.reserve( mDefaultStorageForPoints ); 00187 mHalfEdge.reserve( mDefaultStorageForHalfEdges ); 00188 } 00189 00190 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 ) 00191 { 00192 mPointVector.reserve( nop ); 00193 mHalfEdge.reserve( nop ); 00194 if ( !mDecorator ) 00195 { 00196 mDecorator = this; 00197 } 00198 } 00199 00200 inline double DualEdgeTriangulation::getXMax() const 00201 { 00202 return xMax; 00203 } 00204 00205 inline double DualEdgeTriangulation::getXMin() const 00206 { 00207 return xMin; 00208 } 00209 00210 inline double DualEdgeTriangulation::getYMax() const 00211 { 00212 return yMax; 00213 } 00214 00215 inline double DualEdgeTriangulation::getYMin() const 00216 { 00217 return yMin; 00218 } 00219 00220 inline int DualEdgeTriangulation::getNumberOfPoints() const 00221 { 00222 return (( int )( mPointVector.count() ) ); 00223 } 00224 00225 inline Point3D* DualEdgeTriangulation::getPoint( unsigned int i ) const 00226 { 00227 return mPointVector.at( i ); 00228 } 00229 00230 inline bool DualEdgeTriangulation::halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const 00231 { 00232 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 ) ); 00233 } 00234 00235 #endif 00236 00237 00238