SCM Repository
Annotation of /trunk/test/MIP/mip.cl
Parent Directory
|
Revision Log
Revision 310 - (view) (download)
1 : | lamonts | 302 | /* mip.cl |
2 : | * | ||
3 : | * COPYRIGHT (c) 2010 The Diderot Project (http://diderot.cs.uchicago.edu) | ||
4 : | * All rights reserved. | ||
5 : | * | ||
6 : | * An OpenCL file containing a probe kernel and mip kernel implementation | ||
7 : | */ | ||
8 : | |||
9 : | __constant float h[4][4] = { // bspln3 | ||
10 : | { 1.33333, 2.0, 1.0, 0.166667 }, // -2 .. -1 | ||
11 : | { 0.666667, 0.0, -1.0, -0.5 }, // -1 .. 0 | ||
12 : | { 0.666667, 0.0, -1.0, 0.5 }, // 0 .. 1 | ||
13 : | { 1.33333, -2.0, 1.0, -0.166667 }, // 1 .. 2 | ||
14 : | }; | ||
15 : | |||
16 : | jhr | 310 | //__constant float4 eyeVec = (float4)(25,15,10,1); |
17 : | //__constant float4 origVec = (float4)(8.83877,2.5911,7.65275,0); | ||
18 : | //__constant float4 cVec= (float4)(-0.0151831,0.0278357,0,0); | ||
19 : | //__constant float4 rVec = (float4)(0.0074887,0.00408474,-0.0305383,0); | ||
20 : | __constant float4 eyeVec = (float4)(127.331, -1322.05, 272.53, 0); | ||
21 : | __constant float4 origVec = (float4)(122.835,17.7112,188.044, 0); | ||
22 : | __constant float4 cVec= (float4)(-0.00403611,-0.029826,-0.244066, 0); | ||
23 : | __constant float4 rVec = (float4)(-0.245595,-0.0112916,0.00544129, 0); | ||
24 : | __constant float stepSize = 0.5; | ||
25 : | lamonts | 302 | __constant int s = 2; |
26 : | |||
27 : | |||
28 : | __kernel float probe(float * img, int * sAxis, float4 imgPos) { | ||
29 : | |||
30 : | float probedVal; | ||
31 : | float4 f, nf, t, hx, hy, hz; | ||
32 : | int4 n; | ||
33 : | |||
34 : | float4 d = (float4) (h[3][0],h[2][0],h[1][0],h[0][0]); | ||
35 : | float4 c = (float4) (h[3][1],h[2][1],h[1][1],h[0][1]); | ||
36 : | float4 b = (float4) (h[3][2],h[2][2],h[1][2],h[0][2]); | ||
37 : | float4 a = (float4) (h[3][3],h[2][3],h[1][3],h[0][3]); | ||
38 : | |||
39 : | f = modf(imgPos,&nf); | ||
40 : | n = convert_int4(nf); | ||
41 : | |||
42 : | |||
43 : | t = (float4) (f.x + 1, f.x, f.x -1, f.x - 2); | ||
44 : | hx = d + t * (c + t * (b + t*a)); | ||
45 : | t = (float4) (f.y + 1, f.y, f.y - 1, f.y - 2); | ||
46 : | hy = d + t * (c + t * (b + t*a)); | ||
47 : | t = (float4) (f.z + 1, f.z, f.z - 1, f.z -2); | ||
48 : | hz = d + t * (c + t * (b + t*a)); | ||
49 : | |||
50 : | jhr | 310 | float vx[4]; |
51 : | float vy[4]; | ||
52 : | lamonts | 302 | |
53 : | jhr | 310 | for(int k = 1-s; k <= s; k++) { // z is the slowest dimension |
54 : | for(int j = 1-s; j <= s; j++) { // y is the medium dimension | ||
55 : | int index = sAxis[0]*sAxis[1]*(n.z+k) + sAxis[0]*(n.y+j) + (n.x-1); | ||
56 : | float4 v = (float4)(img[index], img[index+1], img[index+2], img[index+3]); | ||
57 : | vx[j+s-1] = dot(v,hx); | ||
58 : | } | ||
59 : | vy[k+s-1] = dot ((float4) (vx[0],vx[1],vx[2],vx[3]),hy); | ||
60 : | lamonts | 302 | } |
61 : | |||
62 : | jhr | 310 | probedVal = dot((float4) (vy[0],vy[1],vy[2],vy[3]),hz); |
63 : | lamonts | 302 | |
64 : | return probedVal; | ||
65 : | |||
66 : | } | ||
67 : | __kernel void mip ( float * img, | ||
68 : | float * out, | ||
69 : | float16 transformMatrix, | ||
70 : | int2 workDim, | ||
71 : | int * sAxis){ | ||
72 : | |||
73 : | lamonts | 177 | int row = get_global_id(0), col = get_global_id(1); |
74 : | lamonts | 302 | |
75 : | if(row <= workDim.x && col <= workDim.y) | ||
76 : | { | ||
77 : | float t, probedVal, maxValue = -INFINITY; | ||
78 : | float4 imgPt; | ||
79 : | lamonts | 177 | |
80 : | lamonts | 302 | float4 pos = origVec + (float)row * rVec + (float)col * cVec; |
81 : | float4 dir = normalize(pos - eyeVec); | ||
82 : | jhr | 218 | |
83 : | lamonts | 302 | pos.w = 0.0; |
84 : | dir.w = 0.0; | ||
85 : | |||
86 : | jhr | 310 | for(t = 0.0; t < 200; t+= stepSize) |
87 : | lamonts | 302 | { |
88 : | lamonts | 177 | pos = pos + stepSize * dir; |
89 : | |||
90 : | // Transform the value to image space position. | ||
91 : | imgPt = (float4) (dot(pos,transformMatrix.s0123), | ||
92 : | jhr | 218 | dot(pos,transformMatrix.s4567), |
93 : | dot(pos,transformMatrix.s89ab), | ||
94 : | dot(pos,transformMatrix.scdef)); | ||
95 : | lamonts | 177 | |
96 : | lamonts | 302 | |
97 : | if( (imgPt.x > 1 && imgPt.x < (sAxis[0] - 2)) && | ||
98 : | (imgPt.y > 1 && imgPt.y < (sAxis[1]- 2)) && | ||
99 : | (imgPt.z > 1 && imgPt.z < (sAxis[2] - 2))) | ||
100 : | lamonts | 191 | { |
101 : | lamonts | 302 | probedVal = probe(img,sAxis,imgPt); |
102 : | jhr | 218 | if(maxValue < probedVal) |
103 : | lamonts | 203 | maxValue = probedVal; |
104 : | lamonts | 191 | } |
105 : | lamonts | 203 | } |
106 : | lamonts | 302 | out[row * workDim.x + col] = maxValue; |
107 : | lamonts | 177 | } |
108 : | } |
root@smlnj-gforge.cs.uchicago.edu | ViewVC Help |
Powered by ViewVC 1.0.0 |