Skip to content

Commit 13154cb

Browse files
author
mhugent
committed
Improved robustness of constrained triangulation. Added a progress dialog for normal vector estimation
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12221 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 4305ae2 commit 13154cb

File tree

5 files changed

+37
-10
lines changed

5 files changed

+37
-10
lines changed

src/analysis/interpolation/DualEdgeTriangulation.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ int DualEdgeTriangulation::baseEdgeOfPoint( int point )
426426
// QgsDebugMsg( "warning, endless loop" );
427427

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

455457
if ( mHalfEdge[actedge]->getPoint() == point && mHalfEdge[mHalfEdge[actedge]->getNext()]->getPoint() != -1 )//we found the edge
456458
{
459+
mEdgeInside = actedge;
457460
return actedge;
458461
break;
459462
}

src/analysis/interpolation/DualEdgeTriangulation.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
119119
/**Y-coordinate of the lower left corner of the bounding box*/
120120
double yMin;
121121
/**Default value for the number of storable points at the beginning*/
122-
const static unsigned int mDefaultStorageForPoints = 50000;
122+
const static unsigned int mDefaultStorageForPoints = 100000;
123123
/**Stores pointers to all points in the triangulations (including the points contained in the lines)*/
124124
QVector<Point3D*> mPointVector;
125125
/**Default value for the number of storable HalfEdges at the beginning*/
@@ -182,13 +182,13 @@ class ANALYSIS_EXPORT DualEdgeTriangulation: public Triangulation
182182
void evaluateInfluenceRegion( Point3D* point, int edge, std::set<int>* set );
183183
};
184184

185-
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 )
185+
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 )
186186
{
187187
mPointVector.reserve( mDefaultStorageForPoints );
188188
mHalfEdge.reserve( mDefaultStorageForHalfEdges );
189189
}
190190

191-
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 )
191+
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 )
192192
{
193193
mPointVector.reserve( nop );
194194
mHalfEdge.reserve( nop );

src/analysis/interpolation/NormVecDecorator.cc

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include "NormVecDecorator.h"
1818
#include "qgslogger.h"
19+
#include <QApplication>
20+
#include <QProgressDialog>
1921

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

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

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

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

514514
//weighted method of little
515-
bool NormVecDecorator::estimateFirstDerivatives()
515+
bool NormVecDecorator::estimateFirstDerivatives( QProgressDialog* d )
516516
{
517+
if ( d )
518+
{
519+
d->setMinimum( 0 );
520+
d->setMaximum( getNumberOfPoints() );
521+
d->setCancelButton( 0 ); //we cannot cancel derivative estimation
522+
d->show();
523+
}
524+
517525
for ( int i = 0; i < getNumberOfPoints(); i++ )
518526
{
527+
if ( d )
528+
{
529+
d->setValue( i );
530+
}
519531
estimateFirstDerivative( i );
520532
}
521-
return true;
522533

534+
if ( d )
535+
{
536+
d->setValue( getNumberOfPoints() );
537+
}
538+
return true;
523539
}
524540

525541
void NormVecDecorator::eliminateHorizontalTriangles()

src/analysis/interpolation/NormVecDecorator.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <TriangleInterpolator.h>
2222
#include <MathUtils.h>
2323
#include "qgslogger.h"
24+
class QProgressDialog;
2425

2526
/**Decorator class which adds the functionality of estimating normals at the data points*/
2627
class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
@@ -44,7 +45,7 @@ class ANALYSIS_EXPORT NormVecDecorator: public TriDecorator
4445
/**Estimates the first derivative a point. Return true in case of succes and false otherwise*/
4546
bool estimateFirstDerivative( int pointno );
4647
/**This method adds the functionality of estimating normals at the data points. Return true in the case of success and false otherwise*/
47-
bool estimateFirstDerivatives();
48+
bool estimateFirstDerivatives( QProgressDialog* d = 0 );
4849
/**Returns a pointer to the normal vector for the point with the number n*/
4950
Vector3D* getNormal( int n ) const;
5051
/**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
6465
protected:
6566
/**Is true, if the normals already have been estimated*/
6667
bool alreadyestimated;
67-
const static unsigned int mDefaultStorageForNormals = 50000;
68+
const static unsigned int mDefaultStorageForNormals = 100000;
6869
/**Association with an interpolator object*/
6970
TriangleInterpolator* mInterpolator;
7071
/**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*/

src/analysis/interpolation/qgstininterpolator.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ void QgsTINInterpolator::initialize()
142142
NormVecDecorator* dec = dynamic_cast<NormVecDecorator*>( mTriangulation );
143143
if ( dec )
144144
{
145-
dec->estimateFirstDerivatives();
145+
QProgressDialog* progressDialog = 0;
146+
if ( mShowProgressDialog ) //show a progress dialog because it can take a long time...
147+
{
148+
progressDialog = new QProgressDialog();
149+
progressDialog->setLabelText( QObject::tr( "Estimating normal derivatives..." ) );
150+
}
151+
dec->estimateFirstDerivatives( progressDialog );
152+
delete progressDialog;
146153
ctInterpolator->setTriangulation( dec );
147154
dec->setTriangleInterpolator( ctInterpolator );
148155
mTriangleInterpolator = ctInterpolator;

0 commit comments

Comments
 (0)