Skip to content

Commit 6f9a72e

Browse files
committed
Working but crashing on dealloc of command queue
1 parent 51d1bb3 commit 6f9a72e

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

src/analysis/raster/slope.cl

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#pragma OPENCL EXTENSION cl_khr_fp64 : enable
2+
3+
float calcFirstDer( float x11, float x21, float x31, float x12, float x22, float x32, float x13, float x23, float x33,
4+
float mInputNodataValue, float mOutputNodataValue, double mZFactor, double mCellSize )
5+
{
6+
//the basic formula would be simple, but we need to test for nodata values...
7+
//X: return (( (x31 - x11) + 2 * (x32 - x12) + (x33 - x13) ) / (8 * mCellSizeX));
8+
//Y: return (((x11 - x13) + 2 * (x21 - x23) + (x31 - x33)) / ( 8 * mCellSizeY));
9+
10+
int weight = 0;
11+
double sum = 0;
12+
13+
14+
//first row
15+
if ( x31 != mInputNodataValue && x11 != mInputNodataValue ) //the normal case
16+
{
17+
sum += ( x31 - x11 );
18+
weight += 2;
19+
}
20+
else if ( x31 == mInputNodataValue && x11 != mInputNodataValue && x21 != mInputNodataValue ) //probably 3x3 window is at the border
21+
{
22+
sum += ( x21 - x11 );
23+
weight += 1;
24+
}
25+
else if ( x11 == mInputNodataValue && x31 != mInputNodataValue && x21 != mInputNodataValue ) //probably 3x3 window is at the border
26+
{
27+
sum += ( x31 - x21 );
28+
weight += 1;
29+
}
30+
31+
//second row
32+
if ( x32 != mInputNodataValue && x12 != mInputNodataValue ) //the normal case
33+
{
34+
sum += 2.0f * ( x32 - x12 );
35+
weight += 4;
36+
}
37+
else if ( x32 == mInputNodataValue && x12 != mInputNodataValue && x22 != mInputNodataValue )
38+
{
39+
sum += 2.0f * ( x22 - x12 );
40+
weight += 2;
41+
}
42+
else if ( x12 == mInputNodataValue && x32 != mInputNodataValue && x22 != mInputNodataValue )
43+
{
44+
sum += 2.0f * ( x32 - x22 );
45+
weight += 2;
46+
}
47+
48+
//third row
49+
if ( x33 != mInputNodataValue && x13 != mInputNodataValue ) //the normal case
50+
{
51+
sum += ( x33 - x13 );
52+
weight += 2;
53+
}
54+
else if ( x33 == mInputNodataValue && x13 != mInputNodataValue && x23 != mInputNodataValue )
55+
{
56+
sum += ( x23 - x13 );
57+
weight += 1;
58+
}
59+
else if ( x13 == mInputNodataValue && x33 != mInputNodataValue && x23 != mInputNodataValue )
60+
{
61+
sum += ( x33 - x23 );
62+
weight += 1;
63+
}
64+
65+
if ( weight == 0 )
66+
{
67+
return mOutputNodataValue;
68+
}
69+
70+
return sum / ( weight * mCellSize ) * mZFactor;
71+
}
72+
73+
74+
__kernel void processNineCellWindow( __global float *scanLine1,
75+
__global float *scanLine2,
76+
__global float *scanLine3,
77+
__global float *resultLine,
78+
__global float *mInputNodataValue,
79+
__global float *mOutputNodataValue,
80+
__global double *mZFactor,
81+
__global double *mCellSizeX,
82+
__global double *mCellSizeY
83+
) {
84+
85+
// Get the index of the current element
86+
int i = get_global_id(0);
87+
88+
// Do the operation
89+
//return (( (x31 - x11) + 2 * (x32 - x12) + (x33 - x13) ) / (8 * mCellSizeX))
90+
float derX = calcFirstDer( scanLine1[i], scanLine2[i], scanLine3[i],
91+
scanLine1[i+1], scanLine2[i+1], scanLine3[i+1],
92+
scanLine1[i+2], scanLine2[i+2], scanLine3[i+2],
93+
*mInputNodataValue, *mOutputNodataValue, *mZFactor, *mCellSizeX
94+
);
95+
//return (((x11 - x13) + 2 * (x21 - x23) + (x31 - x33)) / ( 8 * mCellSizeY));
96+
float derY = calcFirstDer( scanLine1[i+2], scanLine1[i+1], scanLine1[i],
97+
scanLine2[i+2], scanLine2[i+1], scanLine2[i],
98+
scanLine3[i+2], scanLine3[i+1], scanLine3[i],
99+
*mInputNodataValue, *mOutputNodataValue, *mZFactor, *mCellSizeY
100+
);
101+
if ( derX == *mOutputNodataValue || derY == *mOutputNodataValue )
102+
{
103+
resultLine[i] = *mOutputNodataValue;
104+
}
105+
else
106+
{
107+
double res = sqrt( derX * derX + derY * derY );
108+
res = atanpi( res );
109+
resultLine[i] = (float)res * 180.0;
110+
}
111+
}

0 commit comments

Comments
 (0)