Skip to content

Commit 3a8a7cb

Browse files
alexbruywonder-sk
authored andcommittedMar 22, 2023
add build virtual point cloud algorithm
1 parent 48387f2 commit 3a8a7cb

File tree

5 files changed

+197
-0
lines changed

5 files changed

+197
-0
lines changed
 

‎src/analysis/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ if (WITH_PDAL)
424424
processing/pdal/qgspdalalgorithmbase.cpp
425425

426426
processing/pdal/qgsalgorithmpdalboundary.cpp
427+
processing/pdal/qgsalgorithmpdalbuildvpc.cpp
427428
processing/pdal/qgsalgorithmpdalconvertformat.cpp
428429
processing/pdal/qgsalgorithmpdaldensity.cpp
429430
processing/pdal/qgsalgorithmpdalexportraster.cpp
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/***************************************************************************
2+
qgsalgorithmpdalbuildvpc.cpp
3+
---------------------
4+
begin : February 2023
5+
copyright : (C) 2023 by Alexander Bruy
6+
email : alexander dot bruy at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#include "qgsalgorithmpdalbuildvpc.h"
19+
20+
#include "qgsrunprocess.h"
21+
#include "qgspointcloudlayer.h"
22+
23+
///@cond PRIVATE
24+
25+
QString QgsPdalBuildVpcAlgorithm::name() const
26+
{
27+
return QStringLiteral( "virtualpointcloud" );
28+
}
29+
30+
QString QgsPdalBuildVpcAlgorithm::displayName() const
31+
{
32+
return QObject::tr( "Build virtual point cloud (VPC)" );
33+
}
34+
35+
QString QgsPdalBuildVpcAlgorithm::group() const
36+
{
37+
return QObject::tr( "Point cloud data management" );
38+
}
39+
40+
QString QgsPdalBuildVpcAlgorithm::groupId() const
41+
{
42+
return QStringLiteral( "pointclouddatamanagement" );
43+
}
44+
45+
QStringList QgsPdalBuildVpcAlgorithm::tags() const
46+
{
47+
return QObject::tr( "collect,merge,combine,point cloud,virtual,vpc" ).split( ',' );
48+
}
49+
50+
QString QgsPdalBuildVpcAlgorithm::shortHelpString() const
51+
{
52+
return QObject::tr( "This algorithm creates a virtual point cloud from input data." );
53+
}
54+
55+
QgsPdalBuildVpcAlgorithm *QgsPdalBuildVpcAlgorithm::createInstance() const
56+
{
57+
return new QgsPdalBuildVpcAlgorithm();
58+
}
59+
60+
void QgsPdalBuildVpcAlgorithm::initAlgorithm( const QVariantMap & )
61+
{
62+
addParameter( new QgsProcessingParameterMultipleLayers( QStringLiteral( "LAYERS" ), QObject::tr( "Input layers" ), QgsProcessing::TypePointCloud ) );
63+
addParameter( new QgsProcessingParameterFileDestination( QStringLiteral( "OUTPUT" ), QObject::tr( "Virtual point cloud file" ), QObject::tr( "VPC files (*.vpc *.VPC)" ) ) );
64+
}
65+
66+
QStringList QgsPdalBuildVpcAlgorithm::createArgumentLists( const QVariantMap &parameters, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
67+
{
68+
Q_UNUSED( feedback );
69+
70+
const QList< QgsMapLayer * > layers = parameterAsLayerList( parameters, QStringLiteral( "LAYERS" ), context );
71+
if ( layers.empty() )
72+
{
73+
feedback->reportError( QObject::tr( "No layers selected" ), true );
74+
}
75+
76+
const QString outputFile = parameterAsFileOutput( parameters, QStringLiteral( "OUTPUT" ), context );
77+
setOutputValue( QStringLiteral( "OUTPUT" ), outputFile );
78+
79+
QStringList args;
80+
args.reserve( layers.count() + 2 );
81+
82+
args << QStringLiteral( "build_vpc" )
83+
<< QStringLiteral( "--output=%1" ).arg( outputFile );
84+
85+
addThreadsParameter( args );
86+
87+
for ( const QgsMapLayer *layer : std::as_const( layers ) )
88+
{
89+
args << layer->source();
90+
}
91+
92+
return args;
93+
}
94+
95+
///@endcond
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/***************************************************************************
2+
qgsalgorithmpdalbuildvpc.h
3+
---------------------
4+
begin : February 2023
5+
copyright : (C) 2023 by Alexander Bruy
6+
email : alexander dot bruy at gmail dot com
7+
***************************************************************************/
8+
9+
/***************************************************************************
10+
* *
11+
* This program is free software; you can redistribute it and/or modify *
12+
* it under the terms of the GNU General Public License as published by *
13+
* the Free Software Foundation; either version 2 of the License, or *
14+
* (at your option) any later version. *
15+
* *
16+
***************************************************************************/
17+
18+
#ifndef QGSALGORITHMPDALBUILDVPC_H
19+
#define QGSALGORITHMPDALBUILDVPC_H
20+
21+
#define SIP_NO_FILE
22+
23+
#include "qgis_sip.h"
24+
#include "qgspdalalgorithmbase.h"
25+
26+
///@cond PRIVATE
27+
28+
/**
29+
* Native build virtual point cloud (VPC) algorithm.
30+
*/
31+
class QgsPdalBuildVpcAlgorithm : public QgsPdalAlgorithmBase
32+
{
33+
34+
public:
35+
36+
QgsPdalBuildVpcAlgorithm() = default;
37+
void initAlgorithm( const QVariantMap &configuration = QVariantMap() ) override;
38+
QString name() const override;
39+
QString displayName() const override;
40+
QString group() const override;
41+
QString groupId() const override;
42+
QStringList tags() const override;
43+
QString shortHelpString() const override;
44+
QgsPdalBuildVpcAlgorithm *createInstance() const override SIP_FACTORY;
45+
46+
QStringList createArgumentLists( const QVariantMap &parameters,
47+
QgsProcessingContext &context, QgsProcessingFeedback *feedback ) override;
48+
49+
friend class TestQgsProcessingPdalAlgs;
50+
};
51+
52+
///@endcond PRIVATE
53+
54+
#endif // QGSALGORITHMPDALBUILDVPC_H

‎src/analysis/processing/pdal/qgspdalalgorithms.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "qgsapplication.h"
2121

2222
#include "qgsalgorithmpdalboundary.h"
23+
#include "qgsalgorithmpdalbuildvpc.h"
2324
#include "qgsalgorithmpdalconvertformat.h"
2425
#include "qgsalgorithmpdaldensity.h"
2526
#include "qgsalgorithmpdalexportraster.h"
@@ -88,6 +89,7 @@ void QgsPdalAlgorithms::loadAlgorithms()
8889
const QgsScopedRuntimeProfile profile( QObject::tr( "QGIS PDAL provider" ) );
8990

9091
addAlgorithm( new QgsPdalBoundaryAlgorithm() );
92+
addAlgorithm( new QgsPdalBuildVpcAlgorithm() );
9193
addAlgorithm( new QgsPdalConvertFormatAlgorithm() );
9294
addAlgorithm( new QgsPdalDensityAlgorithm() );
9395
addAlgorithm( new QgsPdalExportRasterAlgorithm() );

‎tests/src/analysis/testqgsprocessingpdalalgs.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class TestQgsProcessingPdalAlgs: public QObject
3535
void cleanup() {} // will be called after every testfunction.
3636

3737
void boundary();
38+
void buildVpc();
3839
void convertFormat();
3940
void density();
4041
void exportRaster();
@@ -697,5 +698,49 @@ void TestQgsProcessingPdalAlgs::merge()
697698
);
698699
}
699700

701+
void TestQgsProcessingPdalAlgs::buildVpc()
702+
{
703+
QgsPdalAlgorithmBase *alg = const_cast<QgsPdalAlgorithmBase *>( static_cast< const QgsPdalAlgorithmBase * >( QgsApplication::processingRegistry()->algorithmById( QStringLiteral( "pdal:virtualpointcloud" ) ) ) );
704+
705+
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
706+
context->setProject( QgsProject::instance() );
707+
708+
QgsProcessingFeedback feedback;
709+
710+
const QString pointCloud1 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/rgb.copc.laz";
711+
const QString pointCloud2 = QString( TEST_DATA_DIR ) + "/point_clouds/copc/rgb16.copc.laz";
712+
const QString outputFile = QDir::tempPath() + "/test.vpc";
713+
714+
// single layer
715+
QVariantMap parameters;
716+
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 );
717+
parameters.insert( QStringLiteral( "OUTPUT" ), outputFile );
718+
719+
QStringList args = alg->createArgumentLists( parameters, *context, &feedback );
720+
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
721+
<< QStringLiteral( "--output=%1" ).arg( outputFile )
722+
<< pointCloud1
723+
);
724+
725+
// multiple layers
726+
parameters.insert( QStringLiteral( "LAYERS" ), QStringList() << pointCloud1 << pointCloud2 );
727+
args = alg->createArgumentLists( parameters, *context, &feedback );
728+
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
729+
<< QStringLiteral( "--output=%1" ).arg( outputFile )
730+
<< pointCloud1
731+
<< pointCloud2
732+
);
733+
734+
// set max threads to 2, a --threads argument should be added
735+
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
736+
args = alg->createArgumentLists( parameters, *context, &feedback );
737+
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
738+
<< QStringLiteral( "--output=%1" ).arg( outputFile )
739+
<< QStringLiteral( "--threads=2" )
740+
<< pointCloud1
741+
<< pointCloud2
742+
);
743+
}
744+
700745
QGSTEST_MAIN( TestQgsProcessingPdalAlgs )
701746
#include "testqgsprocessingpdalalgs.moc"

0 commit comments

Comments
 (0)
Please sign in to comment.