Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7451 from elpaso/opencl-utils-2
[feature] OpenCL support
- Loading branch information
Showing
45 changed files
with
2,752 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "calcfirstder.cl" | ||
|
||
__kernel void processNineCellWindow( __global float *scanLine1, | ||
__global float *scanLine2, | ||
__global float *scanLine3, | ||
__global float *resultLine, | ||
__global float *rasterParams // mInputNodataValue, mOutputNodataValue, mZFactor, mCellSizeX, mCellSizeY | ||
) | ||
{ | ||
|
||
// Get the index of the current element | ||
const int i = get_global_id(0); | ||
|
||
if ( scanLine2[i+1] == rasterParams[0] ) | ||
{ | ||
resultLine[i] = rasterParams[1]; | ||
} | ||
else | ||
{ | ||
float derX = calcFirstDer( scanLine1[i], scanLine1[i+1], scanLine1[i+2], | ||
scanLine2[i], scanLine2[i+1], scanLine2[i+2], | ||
scanLine3[i], scanLine3[i+1], scanLine3[i+2], | ||
rasterParams[0], rasterParams[1], rasterParams[2], rasterParams[3] ); | ||
|
||
float derY = calcFirstDer( scanLine3[i], scanLine2[i], scanLine1[i], | ||
scanLine3[i+1], scanLine2[i+1], scanLine1[i+1], | ||
scanLine3[i+2], scanLine2[i+2], scanLine1[i+2], | ||
rasterParams[0], rasterParams[1], rasterParams[2], rasterParams[4]); | ||
|
||
if ( derX == rasterParams[1] || derY == rasterParams[1] || | ||
( derX == 0.0f && derY == 0.0f) ) | ||
{ | ||
resultLine[i] = rasterParams[1]; | ||
} | ||
else | ||
{ | ||
resultLine[i] = 180.0f + atan2pi( derX, derY ) * 180.0f; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include "calcfirstder.cl" | ||
|
||
// Aspect renderer for QGIS | ||
|
||
__kernel void processNineCellWindow( __global float *scanLine1, | ||
__global float *scanLine2, | ||
__global float *scanLine3, | ||
__global uchar4 *resultLine, | ||
__global float *rasterParams | ||
) { | ||
|
||
// Get the index of the current element | ||
const int i = get_global_id(0); | ||
|
||
// Do the operation | ||
//return (( (x31 - x11) + 2 * (x32 - x12) + (x33 - x13) ) / (8 * mCellSizeX)) | ||
float derX = calcFirstDer( scanLine1[i], scanLine2[i], scanLine3[i], | ||
scanLine1[i+1], scanLine2[i+1], scanLine3[i+1], | ||
scanLine1[i+2], scanLine2[i+2], scanLine3[i+2], | ||
rasterParams[0], rasterParams[1], rasterParams[2], rasterParams[3] | ||
); | ||
//return (((x11 - x13) + 2 * (x21 - x23) + (x31 - x33)) / ( 8 * mCellSizeY)); | ||
float derY = calcFirstDer( scanLine1[i+2], scanLine1[i+1], scanLine1[i], | ||
scanLine2[i+2], scanLine2[i+1], scanLine2[i], | ||
scanLine3[i+2], scanLine3[i+1], scanLine3[i], | ||
rasterParams[0], rasterParams[1], rasterParams[2], rasterParams[4] | ||
); | ||
|
||
|
||
float res; | ||
if ( derX == rasterParams[1] || derY == rasterParams[1] || | ||
( derX == 0.0f && derY == 0.0f) ) | ||
{ | ||
res = rasterParams[1]; | ||
} | ||
else | ||
{ | ||
// 180.0 / M_PI = 57.29577951308232 | ||
float aspect = atan2( derX, derY ) * 57.29577951308232; | ||
if ( aspect < 0 ) | ||
res = 90.0f - aspect; | ||
else if (aspect > 90.0f) | ||
// 360 + 90 = 450 | ||
res = 450.0f - aspect; | ||
else | ||
res = 90.0 - aspect; | ||
} | ||
|
||
res = res / 360 * 255; | ||
|
||
resultLine[i] = (uchar4)(res, res, res, 255); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// Calculate the first derivative from a 3x3 cell matrix | ||
float calcFirstDer( float x11, float x21, float x31, float x12, float x22, float x32, float x13, float x23, float x33, | ||
float inputNodataValue, float outputNodataValue, float zFactor, float mCellSize ) | ||
{ | ||
//the basic formula would be simple, but we need to test for nodata values... | ||
//X: return (( (x31 - x11) + 2 * (x32 - x12) + (x33 - x13) ) / (8 * cellSizeX)); | ||
//Y: return (((x11 - x13) + 2 * (x21 - x23) + (x31 - x33)) / ( 8 * cellSizeY)); | ||
|
||
int weight = 0; | ||
float sum = 0; | ||
|
||
|
||
//first row | ||
if ( x31 != inputNodataValue && x11 != inputNodataValue ) //the normal case | ||
{ | ||
sum += ( x31 - x11 ); | ||
weight += 2; | ||
} | ||
else if ( x31 == inputNodataValue && x11 != inputNodataValue && x21 != inputNodataValue ) //probably 3x3 window is at the border | ||
{ | ||
sum += ( x21 - x11 ); | ||
weight += 1; | ||
} | ||
else if ( x11 == inputNodataValue && x31 != inputNodataValue && x21 != inputNodataValue ) //probably 3x3 window is at the border | ||
{ | ||
sum += ( x31 - x21 ); | ||
weight += 1; | ||
} | ||
|
||
//second row | ||
if ( x32 != inputNodataValue && x12 != inputNodataValue ) //the normal case | ||
{ | ||
sum += 2.0f * ( x32 - x12 ); | ||
weight += 4; | ||
} | ||
else if ( x32 == inputNodataValue && x12 != inputNodataValue && x22 != inputNodataValue ) | ||
{ | ||
sum += 2.0f * ( x22 - x12 ); | ||
weight += 2; | ||
} | ||
else if ( x12 == inputNodataValue && x32 != inputNodataValue && x22 != inputNodataValue ) | ||
{ | ||
sum += 2.0f * ( x32 - x22 ); | ||
weight += 2; | ||
} | ||
|
||
//third row | ||
if ( x33 != inputNodataValue && x13 != inputNodataValue ) //the normal case | ||
{ | ||
sum += ( x33 - x13 ); | ||
weight += 2; | ||
} | ||
else if ( x33 == inputNodataValue && x13 != inputNodataValue && x23 != inputNodataValue ) | ||
{ | ||
sum += ( x23 - x13 ); | ||
weight += 1; | ||
} | ||
else if ( x13 == inputNodataValue && x33 != inputNodataValue && x23 != inputNodataValue ) | ||
{ | ||
sum += ( x33 - x23 ); | ||
weight += 1; | ||
} | ||
|
||
if ( weight == 0 ) | ||
{ | ||
return outputNodataValue; | ||
} | ||
|
||
return sum / ( weight * mCellSize ) * zFactor; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "calcfirstder.cl" | ||
|
||
#ifndef M_PI | ||
#define M_PI 3.14159265358979323846 | ||
#endif | ||
|
||
__kernel void processNineCellWindow( __global float *scanLine1, | ||
__global float *scanLine2, | ||
__global float *scanLine3, | ||
__global float *resultLine, | ||
__global float *rasterParams // mInputNodataValue, mOutputNodataValue, mZFactor, mCellSizeX, mCellSizeY, zenith_rad, azimuth_rad | ||
) | ||
{ | ||
|
||
// Get the index of the current element | ||
const int i = get_global_id(0); | ||
|
||
if ( scanLine2[i+1] == rasterParams[0] ) | ||
{ | ||
resultLine[i] = rasterParams[1]; | ||
} | ||
else | ||
{ | ||
|
||
float derX = calcFirstDer( scanLine1[i], scanLine1[i+1], scanLine1[i+2], | ||
scanLine2[i], scanLine2[i+1], scanLine2[i+2], | ||
scanLine3[i], scanLine3[i+1], scanLine3[i+2], | ||
rasterParams[0], rasterParams[1], rasterParams[2], rasterParams[3] ); | ||
|
||
float derY = calcFirstDer( scanLine3[i], scanLine2[i], scanLine1[i], | ||
scanLine3[i+1], scanLine2[i+1], scanLine1[i+1], | ||
scanLine3[i+2], scanLine2[i+2], scanLine1[i+2], | ||
rasterParams[0], rasterParams[1], rasterParams[2], rasterParams[4]); | ||
|
||
if ( derX == rasterParams[1] || derY == rasterParams[1] ) | ||
{ | ||
resultLine[i] = rasterParams[1]; | ||
} | ||
else | ||
{ | ||
|
||
float slope_rad = sqrt( derX * derX + derY * derY ); | ||
slope_rad = atan( slope_rad ); | ||
float aspect_rad; | ||
if ( derX == 0.0f && derY == 0.0f) | ||
aspect_rad = rasterParams[7] / 2.0f; | ||
else | ||
aspect_rad = M_PI + atan2( derX, derY ); | ||
|
||
resultLine[i] = max(0.0f, 255.0f * ( ( rasterParams[5] * cos( slope_rad ) ) + | ||
( rasterParams[6] * sin( slope_rad ) * | ||
cos( rasterParams[7] - aspect_rad ) ) ) ); | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.