Skip to content
Permalink
Browse files

Use QgsFeedback instead of QProgressDialog in tin interpolator

  • Loading branch information
nyalldawson committed Aug 18, 2017
1 parent 000c86e commit 090bb9bba4742e5cd8d2c69a59295be39c604a9d
@@ -2321,6 +2321,11 @@ QgsSymbolsListWidget {#qgis_api_break_3_0_QgsSymbolsListWidget}
- expressionContext(), setExpressionContext(), setMapCanvas() and mapCanvas() have been removed in favor of setContext()/context()


QgsTINInterpolator {#qgis_api_break_3_0_QgsTINInterpolator}
------------------

- The constructor takes a QgsFeedback argument instead of using a QProgressDialog.

QgsTolerance {#qgis_api_break_3_0_QgsTolerance}
------------

@@ -59,7 +59,7 @@ Eliminates the horizontal triangles by swapping or by insertion of new points. I
Estimates the first derivative a point. Return true in case of succes and false otherwise
:rtype: bool
%End
bool estimateFirstDerivatives( QProgressDialog *d = 0 );
bool estimateFirstDerivatives( QgsFeedback *feedback = 0 );
%Docstring
This method adds the functionality of estimating normals at the data points. Return true in the case of success and false otherwise
:rtype: bool
@@ -25,7 +25,13 @@ class QgsTINInterpolator: QgsInterpolator
Linear,
CloughTocher
};
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, bool showProgressDialog = false );

QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, QgsFeedback *feedback = 0 );
%Docstring
Constructor for QgsTINInterpolator.
The ``feedback`` object specifies an optional QgsFeedback object for progress reports and cancelation support.
Ownership of ``feedback`` is not transferred and callers must ensure that it exists for the lifetime of this object.
%End
~QgsTINInterpolator();

virtual int interpolatePoint( double x, double y, double &result );
@@ -190,7 +190,7 @@ def processAlgorithm(self, parameters, context, feedback):
else:
interpolationMethod = QgsTINInterpolator.CloughTocher

interpolator = QgsTINInterpolator(layerData, interpolationMethod)
interpolator = QgsTINInterpolator(layerData, interpolationMethod, feedback)
if triangulation is not None and triangulation != '':
interpolator.setExportTriangulationToFile(True)
interpolator.setTriangulationFilePath(triangulation)
@@ -15,9 +15,9 @@
***************************************************************************/

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

NormVecDecorator::~NormVecDecorator()
{
@@ -511,29 +511,18 @@ bool NormVecDecorator::estimateFirstDerivative( int pointno )
}

//weighted method of little
bool NormVecDecorator::estimateFirstDerivatives( QProgressDialog *d )
bool NormVecDecorator::estimateFirstDerivatives( QgsFeedback *feedback )
{
if ( d )
int numberPoints = getNumberOfPoints();
for ( int i = 0; i < numberPoints; i++ )
{
d->setMinimum( 0 );
d->setMaximum( getNumberOfPoints() );
d->setCancelButton( nullptr ); //we cannot cancel derivative estimation
d->show();
}

for ( int i = 0; i < getNumberOfPoints(); i++ )
{
if ( d )
if ( feedback )
{
d->setValue( i );
feedback->setProgress( 100.0 * static_cast< double >( i ) / numberPoints );
}
estimateFirstDerivative( i );
}

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

@@ -25,7 +25,7 @@
#include "qgslogger.h"
#include "qgis_analysis.h"

class QProgressDialog;
class QgsFeedback;

/** \ingroup analysis
* Decorator class which adds the functionality of estimating normals at the data points*/
@@ -50,7 +50,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( QProgressDialog *d = nullptr );
bool estimateFirstDerivatives( QgsFeedback *feedback = nullptr );
//! 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 normally taken from 'mNormVec', except 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
@@ -27,14 +27,15 @@
#include "qgsgeometry.h"
#include "qgsvectorlayer.h"
#include "qgswkbptr.h"
#include "qgsfeedback.h"
#include <QProgressDialog>

QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData> &inputData, TINInterpolation interpolation, bool showProgressDialog )
QgsTINInterpolator::QgsTINInterpolator( const QList<LayerData> &inputData, TINInterpolation interpolation, QgsFeedback *feedback )
: QgsInterpolator( inputData )
, mTriangulation( nullptr )
, mTriangleInterpolator( nullptr )
, mIsInitialized( false )
, mShowProgressDialog( showProgressDialog )
, mFeedback( feedback )
, mExportTriangulationToFile( false )
, mInterpolation( interpolation )
{
@@ -84,7 +85,7 @@ void QgsTINInterpolator::initialize()
//get number of features if we use a progress bar
int nFeatures = 0;
int nProcessedFeatures = 0;
if ( mShowProgressDialog )
if ( mFeedback )
{
Q_FOREACH ( const LayerData &layer, mLayerData )
{
@@ -95,14 +96,6 @@ void QgsTINInterpolator::initialize()
}
}

QProgressDialog *progressDialog = nullptr;
if ( mShowProgressDialog )
{
progressDialog = new QProgressDialog( QObject::tr( "Building triangulation..." ), QObject::tr( "Abort" ), 0, nFeatures, nullptr );
progressDialog->setWindowModality( Qt::WindowModal );
}


QgsFeature f;
Q_FOREACH ( const LayerData &layer, mLayerData )
{
@@ -118,36 +111,27 @@ void QgsTINInterpolator::initialize()

while ( fit.nextFeature( f ) )
{
if ( mShowProgressDialog )
if ( mFeedback )
{
if ( progressDialog->wasCanceled() )
if ( mFeedback->isCanceled() )
{
break;
}
progressDialog->setValue( nProcessedFeatures );
mFeedback->setProgress( 100.0 * static_cast< double >( nProcessedFeatures ) / nFeatures );
}
insertData( &f, layer.zCoordInterpolation, layer.interpolationAttribute, layer.mInputType );
++nProcessedFeatures;
}
}
}

delete progressDialog;

if ( mInterpolation == CloughTocher )
{
CloughTocherInterpolator *ctInterpolator = new CloughTocherInterpolator();
NormVecDecorator *dec = dynamic_cast<NormVecDecorator *>( mTriangulation );
if ( dec )
{
QProgressDialog *progressDialog = nullptr;
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;
dec->estimateFirstDerivatives( mFeedback );
ctInterpolator->setTriangulation( dec );
dec->setTriangleInterpolator( ctInterpolator );
mTriangleInterpolator = ctInterpolator;
@@ -25,6 +25,7 @@
class Triangulation;
class TriangleInterpolator;
class QgsFeature;
class QgsFeedback;

/** \ingroup analysis
* Interpolation in a triangular irregular network*/
@@ -37,7 +38,13 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
Linear,
CloughTocher
};
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, bool showProgressDialog = false );

/**
* Constructor for QgsTINInterpolator.
* The \a feedback object specifies an optional QgsFeedback object for progress reports and cancelation support.
* Ownership of \a feedback is not transferred and callers must ensure that it exists for the lifetime of this object.
*/
QgsTINInterpolator( const QList<QgsInterpolator::LayerData> &inputData, TINInterpolation interpolation = Linear, QgsFeedback *feedback = nullptr );
~QgsTINInterpolator();

/** Calculates interpolation value for map coordinates x, y
@@ -54,7 +61,7 @@ class ANALYSIS_EXPORT QgsTINInterpolator: public QgsInterpolator
Triangulation *mTriangulation = nullptr;
TriangleInterpolator *mTriangleInterpolator = nullptr;
bool mIsInitialized;
bool mShowProgressDialog;
QgsFeedback *mFeedback = nullptr;
//! If true: export triangulation to shapefile after initialization
bool mExportTriangulationToFile;
//! File path to export the triangulation

0 comments on commit 090bb9b

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