1//Camera Convert: A bunch of kernels to convert camera to ray images 2// NEEDS to include backproject.cl 3 4__kernel 5void 6persp_to_generic( __global float16 * persp_camera, // camera orign and SVD of inverse of camera matrix 7 __global float4 * ray_origins, 8 __global float4 * ray_directions, 9 __global uint4 * cam_dims) 10{ 11 uchar llid = (uchar)(get_local_id(0) + get_local_size(0)*get_local_id(1)); 12 uint i=get_global_id(0); 13 uint j=get_global_id(1); 14 uint imIndex = j*get_global_size(0)+i; 15 16 //make sure the index exists in the image, although this can be thrown away if 17 //it is guaranteed that the global_size is equal to the image size in each dim 18 uint i_min = (*cam_dims).x; 19 uint j_min = (*cam_dims).y; 20 uint i_size = (*cam_dims).z; 21 uint j_size = (*cam_dims).w; 22 23 if( i < i_size && j < j_size ) 24 { 25 float4 ray_o = convert_float4(persp_camera[2].s4567); ray_o.w = 1.0f; 26 float4 ray_d = backproject(i+i_min, j+j_min, persp_camera[0], persp_camera[1], persp_camera[2], ray_o); 27 ray_d.w = 0.0f; 28 29 //also make sure to write cone half angle 30 float4 K = persp_camera[2].s89ab; //calibration matrix [f, f, principle U, principle V]; 31 float4 ref_d = backproject_corner(K.z, K.w, persp_camera[0], persp_camera[1], persp_camera[2], ray_o); 32 ref_d.w = 0.0f; 33 34 //store half angle in ray_d.w 35 float focal_length = K.x; 36 float ca1 = dot(ray_d, ref_d); 37 ray_d.w = (float) fabs(ca1*ca1/focal_length) * .7071; 38 39 //store half angle in ray_d.w 40 ray_origins[imIndex] = ray_o; 41 ray_directions[imIndex] = ray_d; 42 } 43} 44