Skip to content

Commit b6de8f1

Browse files
committed
Added tests for opencl slope and aspect algs
1 parent be8bfee commit b6de8f1

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

tests/src/analysis/testqgsninecellfilters.cpp

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
#include "qgsruggednessfilter.h"
2222
#include "qgstotalcurvaturefilter.h"
2323
#include "qgsapplication.h"
24+
#include "qgssettings.h"
25+
26+
#ifdef HAVE_OPENCL
27+
#include "qgsopenclutils.h"
28+
#endif
2429

2530
#include <QDir>
2631

@@ -38,10 +43,14 @@ class TestNineCellFilters : public QObject
3843
void testHillshade();
3944
void testRuggedness();
4045
void testTotalCurvature();
46+
#ifdef HAVE_OPENCL
47+
void testSlopeCl();
48+
void testAspectCl();
49+
#endif
4150

4251
private:
4352

44-
template <class T> void _testAlg( const QString &name );
53+
template <class T> void _testAlg( const QString &name, bool useOpenCl = false );
4554

4655
static QString referenceFile( const QString &name )
4756
{
@@ -65,16 +74,21 @@ void TestNineCellFilters::initTestCase()
6574
}
6675

6776
template <class T>
68-
void TestNineCellFilters::_testAlg( const QString &name )
77+
void TestNineCellFilters::_testAlg( const QString &name, bool useOpenCl )
6978
{
79+
#ifdef HAVE_OPENCL
80+
QgsSettings().setValue( QStringLiteral( "useOpenCl" ), true, QgsSettings::Section::Core );
81+
QString tmpFile( tempFile( name + ( useOpenCl ? "_opencl" : "" ) ) );
82+
#else
83+
Q_UNUSED( useOpenCl );
7084
QString tmpFile( tempFile( name ) );
85+
#endif
7186
QString refFile( referenceFile( name ) );
72-
7387
QgsAlignRaster::RasterInfo in( SRC_FILE );
7488
QSize inSize( in.rasterSize() );
7589
QSizeF inCellSize( in.cellSize( ) );
76-
T slopefilter( SRC_FILE, tmpFile, "GTiff" );
77-
int res = slopefilter.processRaster();
90+
T ninecellsfilter( SRC_FILE, tmpFile, "GTiff" );
91+
int res = ninecellsfilter.processRaster();
7892
QVERIFY( res == 0 );
7993

8094
// Produced file
@@ -93,8 +107,8 @@ void TestNineCellFilters::_testAlg( const QString &name )
93107

94108
double refId1( ref.identify( 4081812, 2431750 ) );
95109
double refId2( ref.identify( 4081312, 2431350 ) );
96-
QCOMPARE( out.identify( 4081812, 2431750 ), refId1 );
97-
QCOMPARE( out.identify( 4081312, 2431350 ), refId2 );
110+
QVERIFY( qAbs( out.identify( 4081812, 2431750 ) - refId1 ) < 0.0001f );
111+
QVERIFY( qAbs( out.identify( 4081312, 2431350 ) - refId2 ) < 0.0001f );
98112

99113
}
100114

@@ -110,6 +124,18 @@ void TestNineCellFilters::testAspect()
110124
_testAlg<QgsAspectFilter>( QStringLiteral( "aspect" ) );
111125
}
112126

127+
#ifdef HAVE_OPENCL
128+
void TestNineCellFilters::testSlopeCl()
129+
{
130+
_testAlg<QgsSlopeFilter>( QStringLiteral( "slope" ), true );
131+
}
132+
133+
134+
void TestNineCellFilters::testAspectCl()
135+
{
136+
_testAlg<QgsAspectFilter>( QStringLiteral( "aspect" ), true );
137+
}
138+
#endif
113139

114140
void TestNineCellFilters::testHillshade()
115141
{
@@ -128,6 +154,7 @@ void TestNineCellFilters::testTotalCurvature()
128154
_testAlg<QgsTotalCurvatureFilter>( QStringLiteral( "totalcurvature" ) );
129155
}
130156

157+
131158
QGSTEST_MAIN( TestNineCellFilters )
132159

133160
#include "testqgsninecellfilters.moc"

0 commit comments

Comments
 (0)