Skip to content
Permalink
Browse files

Improved robustness of constrained triangulation. Added a progress di…

…alog for normal vector estimation

git-svn-id: http://svn.osgeo.org/qgis/trunk@12221 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Nov 22, 2009
1 parent 95f1db4 commit 6444cbf448581235779f1e2b42deeed009ac2396
@@ -426,6 +426,7 @@ int DualEdgeTriangulation::baseEdgeOfPoint( int point )
// QgsDebugMsg( "warning, endless loop" );

//use the secure and slow method
//qWarning( "******************warning, using the slow method in baseEdgeOfPoint****************************************" );
for ( int i = 0;i < mHalfEdge.count();i++ )
{
if ( mHalfEdge[i]->getPoint() == point && mHalfEdge[mHalfEdge[i]->getNext()]->getPoint() != -1 )//we found it
@@ -444,6 +445,7 @@ int DualEdgeTriangulation::baseEdgeOfPoint( int point )
{
if ( mHalfEdge[i]->getPoint() == point && mHalfEdge[mHalfEdge[i]->getNext()]->getPoint() != -1 )//we found it
{
mEdgeInside = i;
return i;
}
}
@@ -454,6 +456,7 @@ int DualEdgeTriangulation::baseEdgeOfPoint( int point )

if ( mHalfEdge[actedge]->getPoint() == point && mHalfEdge[mHalfEdge[actedge]->getNext()]->getPoint() != -1 )//we found the edge
{
mEdgeInside = actedge;
return actedge;
break;
}
@@ -119,7 +119,7 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
/**Y-coordinate of the lower left corner of the bounding box*/
double yMin;
/**Default value for the number of storable points at the beginning*/
const static unsigned int mDefaultStorageForPoints = 50000;
const static unsigned int mDefaultStorageForPoints = 100000;
/**Stores pointers to all points in the triangulations (including the points contained in the lines)*/
QVector<Point3D*> mPointVector;
/**Default value for the number of storable HalfEdges at the beginning*/
@@ -182,13 +182,13 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
void evaluateInfluenceRegion( Point3D* point, int edge, std::set<int>* set );
};

inline DualEdgeTriangulation::DualEdgeTriangulation() : xMax( 0 ), xMin( 0 ), yMax( 0 ), yMin( 0 ), mTriangleInterpolator( 0 ), mForcedCrossBehaviour( Triangulation::INSERT_VERTICE ), mEdgeColor( 0, 255, 0 ), mForcedEdgeColor( 0, 0, 255 ), mBreakEdgeColor( 100, 100, 0 ), mDecorator( this )
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 )
{
mPointVector.reserve( mDefaultStorageForPoints );
mHalfEdge.reserve( mDefaultStorageForHalfEdges );
}

inline DualEdgeTriangulation::DualEdgeTriangulation( int nop, Triangulation* decorator ): xMax( 0 ), xMin( 0 ), yMax( 0 ), yMin( 0 ), mTriangleInterpolator( 0 ), mForcedCrossBehaviour( Triangulation::INSERT_VERTICE ), mEdgeColor( 0, 255, 0 ), mForcedEdgeColor( 0, 0, 255 ), mBreakEdgeColor( 100, 100, 0 ), mDecorator( decorator )
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 )
{
mPointVector.reserve( nop );
mHalfEdge.reserve( nop );
@@ -16,6 +16,8 @@

#include "NormVecDecorator.h"
#include "qgslogger.h"
#include <QApplication>
#include <QProgressDialog>

NormVecDecorator::~NormVecDecorator()
{
@@ -482,7 +484,6 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )
//insert the new calculated vector
if ( mNormVec->size() <= mNormVec->count() )//allocate more memory if neccessary
{
QgsDebugMsg( QString( "resizing mNormVec from %1 to %2" ).arg( mNormVec->size() ).arg( mNormVec->size() + 1 ) );
mNormVec->resize( mNormVec->size() + 1 );
}

@@ -502,7 +503,6 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )

if ( pointno >= mPointState->size() )
{
QgsDebugMsg( QString( "resizing mPointState from %1 to %2" ).arg( mPointState->size() ).arg( mPointState->size() + 1 ) );
mPointState->resize( mPointState->size() + 1 );
}

@@ -512,14 +512,30 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )
}

//weighted method of little
bool NormVecDecorator::estimateFirstDerivatives()
bool NormVecDecorator::estimateFirstDerivatives( QProgressDialog* d )
{
if ( d )
{
d->setMinimum( 0 );
d->setMaximum( getNumberOfPoints() );
d->setCancelButton( 0 ); //we cannot cancel derivative estimation
d->show();
}

for ( int i = 0; i < getNumberOfPoints(); i++ )
{
if ( d )
{
d->setValue( i );
}
estimateFirstDerivative( i );
}
return true;

if ( d )
{
d->setValue( getNumberOfPoints() );
}
return true;
}

void NormVecDecorator::eliminateHorizontalTriangles()
@@ -21,6 +21,7 @@
#include <TriangleInterpolator.h>
#include <MathUtils.h>
#include "qgslogger.h"
class QProgressDialog;

/**Decorator class which adds the functionality of estimating normals at the data points*/
class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
@@ -44,7 +45,7 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
/**Estimates the first derivative a point. Return true in case of succes and false otherwise*/
bool estimateFirstDerivative( int pointno );
/**This method adds the functionality of estimating normals at the data points. Return true in the case of success and false otherwise*/
bool estimateFirstDerivatives();
bool estimateFirstDerivatives( QProgressDialog* d = 0 );
/**Returns a pointer to the normal vector for the point with the number n*/
Vector3D* getNormal( int n ) const;
/**Finds out, in which triangle a point with coordinates x and y is and assigns the triangle points to p1, p2, p3 and the estimated normals to v1, v2, v3. The vectors are normaly taken from 'mNormVec', exept if p1, p2 or p3 is a point on a breakline. In this case, the normal is calculated on-the-fly. Returns false, if something went wrong and true otherwise*/
@@ -64,7 +65,7 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
protected:
/**Is true, if the normals already have been estimated*/
bool alreadyestimated;
const static unsigned int mDefaultStorageForNormals = 50000;
const static unsigned int mDefaultStorageForNormals = 100000;
/**Association with an interpolator object*/
TriangleInterpolator* mInterpolator;
/**Vector that stores the normals for the points. If 'estimateFirstDerivatives()' was called and there is a null pointer, this means, that the triangle point is on a breakline*/
@@ -142,7 +142,14 @@ void QgsTINInterpolator::initialize()
NormVecDecorator* dec = dynamic_cast<NormVecDecorator*>( mTriangulation );
if ( dec )
{
dec->estimateFirstDerivatives();
QProgressDialog* progressDialog = 0;
if ( mShowProgressDialog ) //show a progress dialog because it can take a long time...
{
progressDialog = new QProgressDialog();
progressDialog->setLabelText( QObject::tr( "Estimating normal derivatives..." ) );
}
dec->estimateFirstDerivatives( progressDialog );
delete progressDialog;
ctInterpolator->setTriangulation( dec );
dec->setTriangleInterpolator( ctInterpolator );
mTriangleInterpolator = ctInterpolator;

0 comments on commit 6444cbf

Please sign in to comment.
You can’t perform that action at this time.