Skip to content

Commit

Permalink
[opencl] Ruggedness index OpenCL program
Browse files Browse the repository at this point in the history
  • Loading branch information
elpaso committed Aug 8, 2018
1 parent d492bbc commit 164bcc2
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
51 changes: 51 additions & 0 deletions resources/opencl_programs/ruggedness.cl
@@ -0,0 +1,51 @@
__kernel void processNineCellWindow( __global float *scanLine1,
__global float *scanLine2,
__global float *scanLine3,
__global float *resultLine,
__global float *rasterParams )
{

// Get the index of the current element
const int i = get_global_id(0);

float x11 = scanLine1[i];
float x12 = scanLine1[i+1];
float x13 = scanLine1[i+2];
float x21 = scanLine2[i];
float x22 = scanLine2[i+1];
float x23 = scanLine2[i+2];
float x31 = scanLine3[i];
float x32 = scanLine3[i+1];
float x33 = scanLine3[i+2];

if ( x22 == rasterParams[0] )
{
resultLine[i] = rasterParams[1];
}
else
{
// Nodata handling
if ( x11 == rasterParams[0] ) x11 = x22;
if ( x12 == rasterParams[0] ) x12 = x22;
if ( x13 == rasterParams[0] ) x13 = x22;
if ( x21 == rasterParams[0] ) x21 = x22;
if ( x23 == rasterParams[0] ) x23 = x22;
if ( x31 == rasterParams[0] ) x31 = x22;
if ( x32 == rasterParams[0] ) x32 = x22;
if ( x33 == rasterParams[0] ) x33 = x22;

float diff1 = x11 - x22;
float diff2 = x21 - x22;
float diff3 = x31 - x22;
float diff4 = x12 - x22;
float diff5 = x32 - x22;
float diff6 = x13 - x22;
float diff7 = x23 - x22;
float diff8 = x33 - x22;

resultLine[i] = sqrt(diff1 * diff1 + diff2 * diff2 +
diff3 * diff3 + diff4 * diff4 +
diff5 * diff5 + diff6 * diff6 +
diff7 * diff7 + diff8 * diff8);
}
}
5 changes: 4 additions & 1 deletion src/analysis/raster/qgsruggednessfilter.h
Expand Up @@ -42,7 +42,10 @@ class ANALYSIS_EXPORT QgsRuggednessFilter: public QgsNineCellFilter
private:
QgsRuggednessFilter();

//virtual QString _openClProgramBaseName() override { return QStringLiteral( "ruggedness" ); }
virtual const QString openClProgramBaseName() const override
{
return QStringLiteral( "ruggedness" );
}

};

Expand Down

0 comments on commit 164bcc2

Please sign in to comment.