Quantum GIS API Documentation  1.8
src/analysis/interpolation/DualEdgeTriangulation.h
Go to the documentation of this file.
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 <QColor>
00027 #include <QFile>
00028 #include <QTextStream>
00029 #include <QMessageBox>
00030 #include <cfloat>
00031 #include <QBuffer>
00032 #include <QStringList>
00033 #include <QProgressDialog>
00034 #include <QCursor>
00035 #include <set>
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     virtual bool getTriangle( double x, double y, Point3D* p1, int* n1, Point3D* p2, int* n2, Point3D* p3, int* n3 );
00064     virtual bool getTriangle( double x, double y, Point3D* p1, Point3D* p2, Point3D* p3 );
00066     QList<int>* getSurroundingTriangles( int pointno );
00068     virtual double getXMax() const;
00070     virtual double getXMin() const;
00072     virtual double getYMax() const;
00074     virtual double getYMin() const;
00076     virtual int getNumberOfPoints() const;
00078     void removeLine( int i );
00080     void removePoint( int i );
00082     virtual void setForcedCrossBehaviour( Triangulation::forcedCrossBehaviour b );
00084     virtual void setEdgeColor( int r, int g, int b );
00086     virtual void setForcedEdgeColor( int r, int g, int b );
00088     virtual void setBreakEdgeColor( int r, int g, int b );
00090     void setTriangleInterpolator( TriangleInterpolator* interpolator );
00092     void eliminateHorizontalTriangles();
00094     virtual void ruppertRefinement();
00096     bool pointInside( double x, double y );
00098     //bool readFromTAFF(QString fileName);
00100     //bool saveToTAFF(QString fileName) const;
00102     virtual bool swapEdge( double x, double y );
00104     virtual QList<int>* getPointsAroundEdge( double x, double y );
00107     virtual bool saveAsShapefile( const QString& fileName ) const;
00108 
00109   protected:
00111     double xMax;
00113     double xMin;
00115     double yMax;
00117     double yMin;
00119     const static unsigned int mDefaultStorageForPoints = 100000;
00121     QVector<Point3D*> mPointVector;
00123     const static unsigned int mDefaultStorageForHalfEdges = 300006;
00125     QVector<HalfEdge*> mHalfEdge;
00127     TriangleInterpolator* mTriangleInterpolator;
00129     Triangulation::forcedCrossBehaviour mForcedCrossBehaviour;
00131     QColor mEdgeColor;
00133     QColor mForcedEdgeColor;
00135     QColor mBreakEdgeColor;
00137     Triangulation* mDecorator;
00139     unsigned int insertEdge( int dual, int next, int point, bool mbreak, bool forced );
00141     int insertForcedSegment( int p1, int p2, bool breakline );
00143     //const static double leftOfTresh=0.00001;
00145     const static int nBaseOfRuns = 300000;
00147     int baseEdgeOfPoint( int point );
00149     int baseEdgeOfTriangle( Point3D* point );
00151     bool checkSwap( unsigned int edge );
00153     void doSwap( unsigned int edge );
00155     void doOnlySwap( unsigned int edge );
00157     unsigned int mEdgeInside;
00159     unsigned int mEdgeOutside;
00161     unsigned int mEdgeWithPoint;
00163     unsigned int mUnstableEdge;
00165     int mTwiceInsPoint;
00167     bool swapPossible( unsigned int edge );
00169     void triangulatePolygon( QList<int>* poly, QList<int>* free, int mainedge );
00171     bool halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const;
00173     double swapMinAngle( int edge ) const;
00175     int splitHalfEdge( int edge, float position );
00177     bool edgeOnConvexHull( int edge );
00179     void evaluateInfluenceRegion( Point3D* point, int edge, std::set<int>* set );
00180 };
00181 
00182 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 )
00183 {
00184   mPointVector.reserve( mDefaultStorageForPoints );
00185   mHalfEdge.reserve( mDefaultStorageForHalfEdges );
00186 }
00187 
00188 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 )
00189 {
00190   mPointVector.reserve( nop );
00191   mHalfEdge.reserve( nop );
00192   if ( !mDecorator )
00193   {
00194     mDecorator = this;
00195   }
00196 }
00197 
00198 inline double DualEdgeTriangulation::getXMax() const
00199 {
00200   return xMax;
00201 }
00202 
00203 inline double DualEdgeTriangulation::getXMin() const
00204 {
00205   return xMin;
00206 }
00207 
00208 inline double DualEdgeTriangulation::getYMax() const
00209 {
00210   return yMax;
00211 }
00212 
00213 inline double DualEdgeTriangulation::getYMin() const
00214 {
00215   return yMin;
00216 }
00217 
00218 inline int DualEdgeTriangulation::getNumberOfPoints() const
00219 {
00220   return (( int )( mPointVector.count() ) );
00221 }
00222 
00223 inline Point3D* DualEdgeTriangulation::getPoint( unsigned int i ) const
00224 {
00225   return mPointVector.at( i );
00226 }
00227 
00228 inline bool DualEdgeTriangulation::halfEdgeBBoxTest( int edge, double xlowleft, double ylowleft, double xupright, double yupright ) const
00229 {
00230   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 ) );
00231 }
00232 
00233 #endif
00234 
00235 
00236 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines