Skip to content

Commit

Permalink
use distinct parameters for number of points and sampling radius in
Browse files Browse the repository at this point in the history
thin algorithm
  • Loading branch information
alexbruy committed May 1, 2023
1 parent 3c818f6 commit 89015d8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 14 deletions.
21 changes: 19 additions & 2 deletions src/analysis/processing/pdal/qgsalgorithmpdalthin.cpp
Expand Up @@ -61,7 +61,8 @@ void QgsPdalThinAlgorithm::initAlgorithm( const QVariantMap & )
{
addParameter( new QgsProcessingParameterPointCloudLayer( QStringLiteral( "INPUT" ), QObject::tr( "Input layer" ) ) );
addParameter( new QgsProcessingParameterEnum( QStringLiteral( "MODE" ), QObject::tr( "Mode" ), QStringList() << QObject::tr( "Every N-th" ) << QObject::tr( "Sample" ), false, 0 ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "STEP" ), QObject::tr( "Step" ), QgsProcessingParameterNumber::Integer, 20, false, 1 ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "POINTS_NUMBER" ), QObject::tr( "Number of points to skip" ), QgsProcessingParameterNumber::Integer, QVariant(), true, 1 ) );
addParameter( new QgsProcessingParameterNumber( QStringLiteral( "SAMPLING_RADIUS" ), QObject::tr( "Sampling radius (in map units)" ), QgsProcessingParameterNumber::Double, QVariant(), true, 1e-9 ) );
createCommonParameters();
addParameter( new QgsProcessingParameterPointCloudDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Thinned" ) ) );
}
Expand All @@ -79,7 +80,23 @@ QStringList QgsPdalThinAlgorithm::createArgumentLists( const QVariantMap &parame
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );

int mode = parameterAsInt( parameters, QStringLiteral( "MODE" ), context );
int step = parameterAsInt( parameters, QStringLiteral( "STEP" ), context );
double step;
if ( mode == 0 )
{
step = parameterAsInt( parameters, QStringLiteral( "POINTS_NUMBER" ), context );
if ( step == 0 )
{
throw QgsProcessingException( QObject::tr( "Point count should be greater or equal to 1 for 'Every N-th' mode." ) );
}
}
else if ( mode == 1 )
{
step = parameterAsDouble( parameters, QStringLiteral( "SAMPLING_RADIUS" ), context );
if ( step == 0 )
{
throw QgsProcessingException( QObject::tr( "Sampling radius should be greater that 0 for 'Sample' mode." ) );
}
}

QStringList args = { QStringLiteral( "thin" ),
QStringLiteral( "--input=%1" ).arg( layer->source() ),
Expand Down
32 changes: 20 additions & 12 deletions tests/src/analysis/testqgsprocessingpdalalgs.cpp
Expand Up @@ -215,37 +215,45 @@ void TestQgsProcessingPdalAlgs::thin()

const QString outputPointCloud = QDir::tempPath() + "/thinned.laz";

// default values
// default values should throw exception as we don't specify point number
// for Every N-th mode.
QVariantMap parameters;
parameters.insert( QStringLiteral( "INPUT" ), mPointCloudLayerPath );
parameters.insert( QStringLiteral( "OUTPUT" ), outputPointCloud );
QVERIFY_EXCEPTION_THROWN( alg->createArgumentLists( parameters, *context, &feedback ), QgsProcessingException );

// set points number
parameters.insert( QStringLiteral( "POINTS_NUMBER" ), 200 );
QStringList args = alg->createArgumentLists( parameters, *context, &feedback );
QCOMPARE( args, QStringList() << QStringLiteral( "thin" )
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--mode=every-nth" )
<< QStringLiteral( "--step-every-nth=20" )
<< QStringLiteral( "--step-every-nth=200" )
);

// change step
parameters.insert( QStringLiteral( "STEP" ), 200 );
// change mode to 'Sample'. As radius is not set an exception should be thrown
parameters.insert( QStringLiteral( "MODE" ), 1 );
QVERIFY_EXCEPTION_THROWN( alg->createArgumentLists( parameters, *context, &feedback ), QgsProcessingException );

// set radius
parameters.insert( QStringLiteral( "SAMPLING_RADIUS" ), 3.5 );
args = alg->createArgumentLists( parameters, *context, &feedback );
QCOMPARE( args, QStringList() << QStringLiteral( "thin" )
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--mode=every-nth" )
<< QStringLiteral( "--step-every-nth=200" )
<< QStringLiteral( "--mode=sample" )
<< QStringLiteral( "--step-sample=3.5" )
);

// change mode
parameters.insert( QStringLiteral( "MODE" ), 1 );
// remove number of points
parameters.remove( QStringLiteral( "POINTS_NUMBER" ) );
args = alg->createArgumentLists( parameters, *context, &feedback );
QCOMPARE( args, QStringList() << QStringLiteral( "thin" )
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--mode=sample" )
<< QStringLiteral( "--step-sample=200" )
<< QStringLiteral( "--step-sample=3.5" )
);

// filter exression
Expand All @@ -255,7 +263,7 @@ void TestQgsProcessingPdalAlgs::thin()
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--mode=sample" )
<< QStringLiteral( "--step-sample=200" )
<< QStringLiteral( "--step-sample=3.5" )
<< QStringLiteral( "--filter=Intensity > 50" )
);

Expand All @@ -266,7 +274,7 @@ void TestQgsProcessingPdalAlgs::thin()
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--mode=sample" )
<< QStringLiteral( "--step-sample=200" )
<< QStringLiteral( "--step-sample=3.5" )
<< QStringLiteral( "--filter=Intensity > 50" )
<< QStringLiteral( "--bounds=([1, 3], [2, 4])" )
);
Expand All @@ -278,7 +286,7 @@ void TestQgsProcessingPdalAlgs::thin()
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
<< QStringLiteral( "--output=%1" ).arg( outputPointCloud )
<< QStringLiteral( "--mode=sample" )
<< QStringLiteral( "--step-sample=200" )
<< QStringLiteral( "--step-sample=3.5" )
<< QStringLiteral( "--filter=Intensity > 50" )
<< QStringLiteral( "--bounds=([1, 3], [2, 4])" )
<< QStringLiteral( "--threads=2" )
Expand Down

0 comments on commit 89015d8

Please sign in to comment.