Skip to content
Permalink
Browse files

[opencl] Ruggedness index OpenCL program

  • Loading branch information
elpaso committed Aug 8, 2018
1 parent d492bbc commit 164bcc2becb0cbcd07f425530f52b88f40021ff3
Showing with 55 additions and 1 deletion.
  1. +51 −0 resources/opencl_programs/ruggedness.cl
  2. +4 −1 src/analysis/raster/qgsruggednessfilter.h
@@ -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);
}
}
@@ -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" );
}

};

0 comments on commit 164bcc2

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