Image Component Library (ICL)
IterativeClosestPointCLCode.h
Go to the documentation of this file.
1 /********************************************************************
2 ** Image Component Library (ICL) **
3 ** **
4 ** Copyright (C) 2006-2015 CITEC, University of Bielefeld **
5 ** Neuroinformatics Group **
6 ** Website: www.iclcv.org and **
7 ** http://opensource.cit-ec.de/projects/icl **
8 ** **
9 ** File : ICLGeom/src/ICLGeom/IterativeClosestPointCLCode.h **
10 ** Module : ICLGeom **
11 ** Authors: Matthias Esau **
12 ** **
13 ** **
14 ** GNU LESSER GENERAL PUBLIC LICENSE **
15 ** This file may be used under the terms of the GNU Lesser General **
16 ** Public License version 3.0 as published by the **
17 ** **
18 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
19 ** included in the packaging of this file. Please review the **
20 ** following information to ensure the license requirements will **
21 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt **
22 ** **
23 ** The development of this software was supported by the **
24 ** Excellence Cluster EXC 277 Cognitive Interaction Technology. **
25 ** The Excellence Cluster EXC 277 is a grant of the Deutsche **
26 ** Forschungsgemeinschaft (DFG) in the context of the German **
27 ** Excellence Initiative. **
28 ** **
29 ********************************************************************/
30 
31 #pragma once
32 #include <string>
34 namespace icl{
35  namespace geom{
36  using namespace math;
37  void subVec4(const char * a, const char *b, char *c) {
38  struct Vec4{
39  float x;
40  float y;
41  float z;
42  float w;
43  };
44 
45  const Vec4* pa = (const Vec4*)a;
46  const Vec4* pb = (const Vec4*)b;
47  Vec4* pc = (Vec4*)c;
48  pc->x = pa->x-pb->x;
49  pc->y = pa->y-pb->y;
50  pc->z = pa->z-pb->z;
51  pc->w = 1;
52  }
53 
54  Vec4 toVectorVec4(const char* point) {
55  return *(const Vec4*)point;
56  }
57 
58  Vec4 toVectorVec8(const char* point) {
59  return *(const Vec4*)point;
60  }
61 
62  void subVec8(const char * a, const char *b, char *c) {
63  struct Vec4{
64  float x;
65  float y;
66  float z;
67  float w;
68  };
69  struct Vec8{
70  Vec4 pos;
71  Vec4 col;
72  };
73  const Vec8* pa = (const Vec8*)a;
74  const Vec8* pb = (const Vec8*)b;
75  Vec8* pc = (Vec8*)c;
76  pc->pos.x = pa->pos.x-pb->pos.x;
77  pc->pos.y = pa->pos.y-pb->pos.y;
78  pc->pos.z = pa->pos.z-pb->pos.z;
79  pc->pos.w = 1;
80  pc->col.x = pa->col.x;
81  pc->col.y = pa->col.y;
82  pc->col.z = pa->col.z;
83  pc->col.w = 1;
84  }
85 
86  const std::string IterativeClosestPointKernelCode = (
87  "#define MATRIX_SIZE 16\n"
88  "\n"
89  "__kernel void getClosestPoints(const __global char* pointsA, const __global char* pointsB, __global DistanceID* distanceAcc, __local float* distances, int typeSize, int sizeA, int sizeB, int maxX) {\n"
90  " int globalX = get_global_id(0);\n"
91  " int globalY = get_global_id(1);\n"
92  " int localX = get_local_id(0);\n"
93  " int localY = get_local_id(1);\n"
94  " int localSizeX = get_local_size(0);\n"
95  " int localGroupX = get_group_id(0);\n"
96  " //calculate distance for current pair\n"
97  " distances[localY*localSizeX+localX] = FLT_MAX;\n"
98  " if(globalX < sizeB && globalY < sizeA)\n"
99  " distances[localY*localSizeX+localX] = distanceFunc(pointsB+typeSize*globalX,pointsA+typeSize*globalY);\n"
100  "\n"
101  " //_________local_barrier______\n"
102  " barrier(CLK_LOCAL_MEM_FENCE);\n"
103  "\n"
104  " //find closest distances in local group by letting only the last vertical line of threads in a local group calculate\n"
105  " if(localX == 0 && globalY < sizeA) {\n"
106  " int localStartX = localGroupX*localSizeX;\n"
107  " DistanceID min;\n"
108  " min.distance = distances[localY*localSizeX];\n"
109  " min.id = 0;\n"
110  " for(int k = 1; k < localSizeX; k++) {\n"
111  " float distance = distances[localY*localSizeX+k];\n"
112  " if(distance < min.distance) {\n"
113  " min.distance = distance;\n"
114  " min.id = k;\n"
115  " }\n"
116  " }\n"
117  " //convert id from local to global space\n"
118  " min.id += localStartX;\n"
119  " distanceAcc[globalY*maxX+localGroupX] = min;\n"
120  " }\n"
121  "}\n"
122  "\n"
123  "__kernel void reduceClosestPoints(__global int* closestPoints, __global DistanceID* distanceAcc, int sizeA, int widthDistanceAcc) {\n"
124  " int globalX = get_global_id(0);\n"
125  "\n"
126  " //find closest point across all groups by letting only the last vertical line of threads calculate\n"
127  " if(globalX < sizeA) {\n"
128  " int startX = globalX*widthDistanceAcc;\n"
129  " int endX = startX+widthDistanceAcc;\n"
130  " DistanceID min = distanceAcc[startX];\n"
131  " for(int k = startX+1; k < endX; k++) {\n"
132  " DistanceID point = distanceAcc[k];\n"
133  " if(point.distance < min.distance) {\n"
134  " min = point;\n"
135  " }\n"
136  " }\n"
137  " closestPoints[globalX] = min.id;\n"
138  " }\n"
139  "}\n"
140  "\n"
141  "__kernel void getClosestPointsInDB(const __global char* pointsA, const __global int* closestReps, const __global char* pointsB, const __global int* pointsDB, const __global int* counters, __global int* closestPoints, __global DistanceID* distanceAcc, __local float* distances, int typeSize, int sizeA, int widthDB, int maxX) {\n"
142  " int globalX = get_global_id(0);\n"
143  " int globalY = get_global_id(1);\n"
144  " int localX = get_local_id(0);\n"
145  " int localY = get_local_id(1);\n"
146  " int localSizeX = get_local_size(0);\n"
147  " int localGroupX = get_group_id(0);\n"
148  "\n"
149  " //calculate distance for current pair\n"
150  " distances[localY*localSizeX+localX] = FLT_MAX;\n"
151  " int maxWidth;\n"
152  " if(globalY < sizeA)maxWidth = min(widthDB,counters[closestReps[globalY]]);\n"
153  " if(globalY < sizeA && globalX < maxWidth)\n"
154  " distances[localY*localSizeX+localX] = distanceFunc(pointsB+typeSize*pointsDB[closestReps[globalY]*widthDB+globalX],pointsA+typeSize*globalY);\n"
155  "\n"
156  "\n"
157  " //_________local_barrier______\n"
158  " barrier(CLK_LOCAL_MEM_FENCE);\n"
159  "\n"
160  "\n"
161  " //find closest distances in local group by letting only the first vertical line of threads in a local group calculate\n"
162  " if(localX == 0 && globalY < sizeA) {\n"
163  " int localStartX = localGroupX*localSizeX;\n"
164  " DistanceID min;\n"
165  " min.distance = distances[localY*localSizeX];\n"
166  " min.id = 0;\n"
167  " for(int k = 1; k < localSizeX; k++) {\n"
168  " float distance = distances[localY*localSizeX+k];\n"
169  " if(distance < min.distance) {\n"
170  " min.distance = distance;\n"
171  " min.id = k;\n"
172  " }\n"
173  " }\n"
174  " //convert id from local to global space\n"
175  " min.id = pointsDB[closestReps[globalY]*widthDB+(min.id+localStartX)];\n"
176  " distanceAcc[globalY*maxX+localGroupX] = min;\n"
177  " }\n"
178  "}\n"
179  "\n"
180  "\n"
181  "__kernel void initMemory(__global char* mem, int size) {\n"
182  " if(get_global_id(0) == 0) {\n"
183  " for(int i = 0; i < size; i++)mem[i] = 0;\n"
184  " }\n"
185  "}\n"
186  "\n"
187  "__kernel void buildRepDB(const __global char* points, const __global int* closestReps, __global int* counters, __global int* repDataBase, int repWidth, int typeSize, int sizePoints, int sizeReps) {\n"
188  " int globalX = get_global_id(0);\n"
189  " int localX = get_local_id(0);\n"
190  " int localSizeX = get_local_size(0);\n"
191  " int localGroupX = get_group_id(0);\n"
192  "\n"
193  " if(globalX < sizePoints) {\n"
194  " int rep = closestReps[globalX];\n"
195  " int pos = atomic_inc(counters+rep);\n"
196  " //check if the there are to many neighbours\n"
197  " if(pos < repWidth) {\n"
198  " repDataBase[repWidth*rep+pos] = globalX;\n"
199  " }\n"
200  " }\n"
201  "}\n"
202  "\n"
203  "__kernel void rotatePoints(const __global char* points, __global char* pointsRotated, const __global float* rotationMatrix, int typeSize, int sizePoints) {\n"
204  " int globalX = get_global_id(0);\n"
205  " if(globalX < sizePoints) {\n"
206  " int offset = typeSize*globalX;\n"
207  " matrixMultiply(points+offset, pointsRotated+offset, rotationMatrix);\n"
208  " }\n"
209  "}\n"
210  "\n"
211  "__kernel void getError(const __global char* pointsA, const __global char* pointsB, const __global int* closestPoints, __global float* errors, int typeSize, int sizeA) {\n"
212  " int globalX = get_global_id(0);\n"
213  " if(globalX < sizeA)errors[globalX] = distanceFunc(pointsA+globalX*typeSize,pointsB+closestPoints[globalX]*typeSize);\n"
214  "}\n"
215  "\n"
216  "__kernel void collectError(const __global float* in, __global float* out, __local float* scratch, int length) {\n"
217  " int global_index = get_global_id(0);\n"
218  " int local_index = get_local_id(0);\n"
219  " if (global_index < length) {\n"
220  " scratch[local_index] = in[global_index];\n"
221  " } else {\n"
222  " scratch[local_index] = 0;\n"
223  " }\n"
224  " barrier(CLK_LOCAL_MEM_FENCE);\n"
225  " for(int offset = get_local_size(0) / 2;\n"
226  " offset > 0;\n"
227  " offset >>= 1) {\n"
228  " if (local_index < offset) {\n"
229  " float other = scratch[local_index + offset];\n"
230  " float mine = scratch[local_index];\n"
231  " scratch[local_index] = mine+other;\n"
232  " }\n"
233  " barrier(CLK_LOCAL_MEM_FENCE);\n"
234  " }\n"
235  " if (local_index == 0) {\n"
236  " out[get_group_id(0)] = scratch[0];\n"
237  " }\n"
238  "}\n"
239  "\n"
240  "\n"
241  "__kernel void getCovarianceSum(const __global char* pointsA, const __global char* pointsB, const __global int* closestPoints, __global float* covariances, int typeSize, int sizeA) {\n"
242  " int globalX = get_global_id(0);\n"
243  " if(globalX < sizeA) getCovariance(pointsA+globalX*typeSize,pointsB+closestPoints[globalX]*typeSize,covariances+globalX*MATRIX_SIZE);\n"
244  "}\n"
245  "\n"
246  "__kernel void collectCovarianceSum(const __global float* in, __global float* out, __local float* scratch, int length) {\n"
247  " int global_index = get_global_id(0);\n"
248  " int local_index = get_local_id(0);\n"
249  " if (global_index < length) {\n"
250  " for(int i = 0; i < MATRIX_SIZE; i++)\n"
251  " scratch[local_index*MATRIX_SIZE+i] = in[global_index*MATRIX_SIZE+i];\n"
252  " } else {\n"
253  " for(int i = 0; i < MATRIX_SIZE; i++)\n"
254  " scratch[local_index*MATRIX_SIZE+i] = 0;\n"
255  " }\n"
256  " barrier(CLK_LOCAL_MEM_FENCE);\n"
257  " for(int offset = get_local_size(0) / 2;\n"
258  " offset > 0;\n"
259  " offset >>= 1) {\n"
260  " if (local_index < offset) {\n"
261  " for(int i = 0; i < MATRIX_SIZE; i++) {\n"
262  " float other = scratch[(local_index + offset)*MATRIX_SIZE+i];\n"
263  " float mine = scratch[local_index*MATRIX_SIZE+i];\n"
264  " scratch[local_index*MATRIX_SIZE+i] = mine+other;\n"
265  " }\n"
266  " }\n"
267  " barrier(CLK_LOCAL_MEM_FENCE);\n"
268  " }\n"
269  " if (local_index == 0) {\n"
270  " for(int i = 0; i < MATRIX_SIZE; i++)\n"
271  " out[get_group_id(0)*MATRIX_SIZE+i] = scratch[i];\n"
272  " }\n"
273  "}\n"
274  "\n"
275  "__kernel void sumPoints(const __global char* in, __global char* out, __local char* scratch, int typeSize, int length) {\n"
276  " int global_index = get_global_id(0);\n"
277  " int local_index = get_local_id(0);\n"
278  " int local_size = get_local_size(0);\n"
279  "\n"
280  " if (global_index < length) {\n"
281  " for(int i = 0; i < typeSize; i++)\n"
282  " scratch[local_index*typeSize+i] = in[global_index*typeSize+i];\n"
283  " } else {\n"
284  " neutralElement_local(scratch+local_index*typeSize);\n"
285  " }\n"
286  " barrier(CLK_LOCAL_MEM_FENCE);\n"
287  " for(int offset = get_local_size(0) / 2;\n"
288  " offset > 0;\n"
289  " offset >>= 1) {\n"
290  " if (local_index < offset) {\n"
291  " add_local(scratch+(local_index + offset)*typeSize,scratch+local_index*typeSize,scratch+local_index*typeSize);\n"
292  " }\n"
293  " barrier(CLK_LOCAL_MEM_FENCE);\n"
294  " }\n"
295  " if (local_index == 0) {\n"
296  " for(int i = 0; i < typeSize; i++)\n"
297  " out[get_group_id(0)*typeSize+i] = scratch[i];\n"
298  " }\n"
299  "}\n"
300  "\n"
301  "__kernel void mulPoints(const __global char* in, __global char* out, float v, int typeSize, int length) {\n"
302  " int globalX = get_global_id(0);\n"
303  " if(globalX<length)mul_global(in+globalX*typeSize,v,out+globalX*typeSize);\n"
304  "}\n"
305  "\n"
306  "__kernel void subPoints(const __global char* in, const __global char* v, __global char* out, int typeSize, int length) {\n"
307  " int globalX = get_global_id(0);\n"
308  " if(globalX< length)sub_global(in+globalX*typeSize,v,out+globalX*typeSize);\n"
309  "}\n"
310  );
311  const std::string IterativeClosestPointTypeCodeVec4 = (
312  "typedef struct Vec4_t{\n"
313  " float x;\n"
314  " float y;\n"
315  " float z;\n"
316  " float w;\n"
317  "}Vec4;\n"
318  "\n"
319  "typedef struct DistanceID_t {\n"
320  " float distance;\n"
321  " int id;\n"
322  "}DistanceID;\n"
323  "\n"
324  "void add(const char * a, const char *b, char * c) {\n"
325  " const Vec4* pa = (const Vec4*)a;\n"
326  " const Vec4* pb = (const Vec4*)b;\n"
327  " Vec4* pc = (Vec4*)c;\n"
328  " pc->x = pa->x+pb->x;\n"
329  " pc->y = pa->y+pb->y;\n"
330  " pc->z = pa->z+pb->z;\n"
331  "}\n"
332  "\n"
333  "void add_global(const __global char * a, const __global char *b, __global char * c) {\n"
334  " const __global Vec4* pa = (const __global Vec4*)a;\n"
335  " const __global Vec4* pb = (const __global Vec4*)b;\n"
336  " __global Vec4* pc = (__global Vec4*)c;\n"
337  " pc->x = pa->x+pb->x;\n"
338  " pc->y = pa->y+pb->y;\n"
339  " pc->z = pa->z+pb->z;\n"
340  " pc->w = 1;\n"
341  "}\n"
342  "\n"
343  "void add_local(const __local char * a, const __local char *b, __local char * c) {\n"
344  "// const __local Vec4* pa = (const __local Vec4*)a;\n"
345  "// const __local Vec4* pb = (const __local Vec4*)b;\n"
346  "// __local Vec4* pc = (__local Vec4*)c;\n"
347  "// pc->x = pa->x+pb->x;\n"
348  "// pc->y = pa->y+pb->y;\n"
349  "// pc->z = pa->z+pb->z;\n"
350  "\n"
351  " char ac[16];\n"
352  " char bc[16];\n"
353  " char cc[16];\n"
354  " for(int i = 0; i < 16; i++) {\n"
355  " ac[i] = a[i];\n"
356  " bc[i] = b[i];\n"
357  " }\n"
358  " add(ac,bc,cc);\n"
359  " for(int i = 0; i < 16; i++) {\n"
360  " c[i] = cc[i];\n"
361  " }\n"
362  "}\n"
363  "\n"
364  "void sub_global(const __global char * a, const __global char *b, __global char * c) {\n"
365  " const __global Vec4* pa = (const __global Vec4*)a;\n"
366  " const __global Vec4* pb = (const __global Vec4*)b;\n"
367  " __global Vec4* pc = (__global Vec4*)c;\n"
368  " pc->x = pa->x-pb->x;\n"
369  " pc->y = pa->y-pb->y;\n"
370  " pc->z = pa->z-pb->z;\n"
371  " pc->w = 1;\n"
372  "}\n"
373  "\n"
374  "void sub_local(const __local char * a, const __local char *b, __local char * c) {\n"
375  " const __local Vec4* pa = (const __local Vec4*)a;\n"
376  " const __local Vec4* pb = (const __local Vec4*)b;\n"
377  " __local Vec4* pc = (__local Vec4*)c;\n"
378  " pc->x = pa->x-pb->x;\n"
379  " pc->y = pa->y-pb->y;\n"
380  " pc->z = pa->z-pb->z;\n"
381  " pc->w = 1;\n"
382  "}\n"
383  "\n"
384  "void mul_global(const __global char * a, float b, __global char * c) {\n"
385  " const __global Vec4* pa = (const __global Vec4*)a;\n"
386  " __global Vec4* pc = (__global Vec4*)c;\n"
387  " pc->x = pa->x*b;\n"
388  " pc->y = pa->y*b;\n"
389  " pc->z = pa->z*b;\n"
390  " pc->w = pa->w;\n"
391  "}\n"
392  "\n"
393  "void mul_local(const __local char * a, float b, __local char * c) {\n"
394  " const __local Vec4* pa = (const __local Vec4*)a;\n"
395  " __local Vec4* pc = (__local Vec4*)c;\n"
396  " pc->x = pa->x*b;\n"
397  " pc->y = pa->y*b;\n"
398  " pc->z = pa->z*b;\n"
399  " pc->w = pa->w;\n"
400  "}\n"
401  "\n"
402  "\n"
403  "void neutralElement(char* e) {\n"
404  " Vec4* pe = (Vec4*)e;\n"
405  " pe->x = 0;\n"
406  " pe->y = 0;\n"
407  " pe->z = 0;\n"
408  " pe->w = 1;\n"
409  "}\n"
410  "\n"
411  "void neutralElement_global(__global char* e) {\n"
412  " __global Vec4* pe = (__global Vec4*)e;\n"
413  " pe->x = 0;\n"
414  " pe->y = 0;\n"
415  " pe->z = 0;\n"
416  " pe->w = 1;\n"
417  "}\n"
418  "\n"
419  "void neutralElement_local(__local char* e) {\n"
420  "// __local Vec4* pe = (__local Vec4*)e;\n"
421  "// pe->x = 0;\n"
422  "// pe->y = 0;\n"
423  "// pe->z = 0;\n"
424  "// pe->w = 1;\n"
425  " char elem[16];\n"
426  " neutralElement(elem);\n"
427  " for(int i = 0; i < 16; i++) {\n"
428  " e[i] = elem[i];\n"
429  " }\n"
430  "}\n"
431  "\n"
432  "\n"
433  "float distanceFunc(const __global char * a, const __global char *b) {\n"
434  " const __global Vec4* pa = (const __global Vec4*)a;\n"
435  " const __global Vec4* pb = (const __global Vec4*)b;\n"
436  " Vec4 dist;\n"
437  " dist.x = pa->x-pb->x;\n"
438  " dist.y = pa->y-pb->y;\n"
439  " dist.z = pa->z-pb->z;\n"
440  " return sqrt(dist.x*dist.x+dist.y*dist.y+dist.z*dist.z);\n"
441  "}\n"
442  "\n"
443  "void getCovariance(const __global char * a, const __global char *b, __global float* h) {\n"
444  " const __global Vec4* pa = (const __global Vec4*)a;\n"
445  " const __global Vec4* pb = (const __global Vec4*)b;\n"
446  " h[0] = pa->x*pb->x;\n"
447  " h[1] = pa->x*pb->y;\n"
448  " h[2] = pa->x*pb->z;\n"
449  " h[3] = 0;\n"
450  "\n"
451  " h[4] = pa->y*pb->x;\n"
452  " h[5] = pa->y*pb->y;\n"
453  " h[6] = pa->y*pb->z;\n"
454  " h[7] = 0;\n"
455  "\n"
456  " h[8] = pa->z*pb->x;\n"
457  " h[9] = pa->z*pb->y;\n"
458  " h[10] = pa->z*pb->z;\n"
459  " h[11] = 0;\n"
460  "\n"
461  " h[12] = 0;\n"
462  " h[13] = 0;\n"
463  " h[14] = 0;\n"
464  " h[15] = 1;\n"
465  "}\n"
466  "\n"
467  "\n"
468  "void matrixMultiply(const __global char * a, char __global *b, const __global float* m) {\n"
469  " const __global Vec4* pa = (const __global Vec4*)a;\n"
470  " __global Vec4* pb = (__global Vec4*)b;\n"
471  " pb->x = m[0]*pa->x+m[1]*pa->y+m[2]*pa->z+m[3]*pa->w;\n"
472  " pb->y = m[4]*pa->x+m[5]*pa->y+m[6]*pa->z+m[7]*pa->w;\n"
473  " pb->z = m[8]*pa->x+m[9]*pa->y+m[10]*pa->z+m[11]*pa->w;\n"
474  " pb->w = m[12]*pa->x+m[13]*pa->y+m[14]*pa->z+m[15]*pa->w;\n"
475  "}\n"
476  );
477  const std::string IterativeClosestPointTypeCodeVec8 = (
478  "typedef struct Vec4_t{\n"
479  " float x;\n"
480  " float y;\n"
481  " float z;\n"
482  " float w;\n"
483  "}Vec4;\n"
484  "\n"
485  "typedef struct Vec8_t{\n"
486  " Vec4 pos;\n"
487  " Vec4 col;\n"
488  "}Vec8;\n"
489  "\n"
490  "typedef struct DistanceID_t {\n"
491  " float distance;\n"
492  " int id;\n"
493  "}DistanceID;\n"
494  "\n"
495  "void add(const char * a, const char *b, char * c) {\n"
496  " const Vec8* pa = (const Vec8*)a;\n"
497  " const Vec8* pb = (const Vec8*)b;\n"
498  " Vec8* pc = (Vec8*)c;\n"
499  " pc->pos.x = pa->pos.x+pb->pos.x;\n"
500  " pc->pos.y = pa->pos.y+pb->pos.y;\n"
501  " pc->pos.z = pa->pos.z+pb->pos.z;\n"
502  " pc->pos.w = 1;\n"
503  " pc->col.x = pa->col.x;\n"
504  " pc->col.y = pa->col.y;\n"
505  " pc->col.z = pa->col.z;\n"
506  " pc->col.w = 1;\n"
507  "}\n"
508  "\n"
509  "void add_global(const __global char * a, const __global char *b, __global char * c) {\n"
510  " const __global Vec8* pa = (const __global Vec8*)a;\n"
511  " const __global Vec8* pb = (const __global Vec8*)b;\n"
512  " __global Vec8* pc = (__global Vec8*)c;\n"
513  " pc->pos.x = pa->pos.x+pb->pos.x;\n"
514  " pc->pos.y = pa->pos.y+pb->pos.y;\n"
515  " pc->pos.z = pa->pos.z+pb->pos.z;\n"
516  " pc->pos.w = 1;\n"
517  " pc->col.x = pa->col.x;\n"
518  " pc->col.y = pa->col.y;\n"
519  " pc->col.z = pa->col.z;\n"
520  " pc->col.w = 1;\n"
521  "}\n"
522  "\n"
523  "void add_local(const __local char * a, const __local char *b, __local char * c) {\n"
524  "// const __local Vec8* pa = (const __local Vec8*)a;\n"
525  "// const __local Vec8* pb = (const __local Vec8*)b;\n"
526  "// __local Vec8* pc = (__local Vec8*)c;\n"
527  "// pc->pos.x = pa->pos.x+pb->pos.x;\n"
528  "// pc->pos.y = pa->pos.y+pb->pos.y;\n"
529  "// pc->pos.z = pa->pos.z+pb->pos.z;\n"
530  "// pc->pos.w = 1;\n"
531  "// pc->col.x = pa->col.x;\n"
532  "// pc->col.y = pa->col.y;\n"
533  "// pc->col.z = pa->col.z;\n"
534  "// pc->col.w = 1;\n"
535  "\n"
536  " char ac[32];\n"
537  " char bc[32];\n"
538  " char cc[32];\n"
539  " for(int i = 0; i < 32; i++) {\n"
540  " ac[i] = a[i];\n"
541  " bc[i] = b[i];\n"
542  " }\n"
543  " add(ac,bc,cc);\n"
544  " for(int i = 0; i < 32; i++) {\n"
545  " c[i] = cc[i];\n"
546  " }\n"
547  "}\n"
548  "\n"
549  "void sub_global(const __global char * a, const __global char *b, __global char * c) {\n"
550  " const __global Vec8* pa = (const __global Vec8*)a;\n"
551  " const __global Vec8* pb = (const __global Vec8*)b;\n"
552  " __global Vec8* pc = (__global Vec8*)c;\n"
553  " pc->pos.x = pa->pos.x-pb->pos.x;\n"
554  " pc->pos.y = pa->pos.y-pb->pos.y;\n"
555  " pc->pos.z = pa->pos.z-pb->pos.z;\n"
556  " pc->pos.w = 1;\n"
557  " pc->col.x = pa->col.x;\n"
558  " pc->col.y = pa->col.y;\n"
559  " pc->col.z = pa->col.z;\n"
560  " pc->col.w = 1;\n"
561  "}\n"
562  "\n"
563  "void sub_local(const __local char * a, const __local char *b, __local char * c) {\n"
564  " const __local Vec8* pa = (const __local Vec8*)a;\n"
565  " const __local Vec8* pb = (const __local Vec8*)b;\n"
566  " __local Vec8* pc = (__local Vec8*)c;\n"
567  " pc->pos.x = pa->pos.x-pb->pos.x;\n"
568  " pc->pos.y = pa->pos.y-pb->pos.y;\n"
569  " pc->pos.z = pa->pos.z-pb->pos.z;\n"
570  " pc->pos.w = 1;\n"
571  " pc->col.x = pa->col.x;\n"
572  " pc->col.y = pa->col.y;\n"
573  " pc->col.z = pa->col.z;\n"
574  " pc->col.w = 1;\n"
575  "}\n"
576  "\n"
577  "void mul_global(const __global char * a, float b, __global char * c) {\n"
578  " const __global Vec8* pa = (const __global Vec8*)a;\n"
579  " __global Vec8* pc = (__global Vec8*)c;\n"
580  " pc->pos.x = pa->pos.x*b;\n"
581  " pc->pos.y = pa->pos.y*b;\n"
582  " pc->pos.z = pa->pos.z*b;\n"
583  " pc->pos.w = pa->pos.w;\n"
584  " pc->col.x = pa->col.x;\n"
585  " pc->col.y = pa->col.y;\n"
586  " pc->col.z = pa->col.z;\n"
587  " pc->col.w = 1;\n"
588  "}\n"
589  "\n"
590  "void mul_local(const __local char * a, float b, __local char * c) {\n"
591  " const __local Vec8* pa = (const __local Vec8*)a;\n"
592  " __local Vec8* pc = (__local Vec8*)c;\n"
593  " pc->pos.x = pa->pos.x*b;\n"
594  " pc->pos.y = pa->pos.y*b;\n"
595  " pc->pos.z = pa->pos.z*b;\n"
596  " pc->pos.w = pa->pos.w;\n"
597  " pc->col.x = pa->col.x;\n"
598  " pc->col.y = pa->col.y;\n"
599  " pc->col.z = pa->col.z;\n"
600  " pc->col.w = 1;\n"
601  "}\n"
602  "\n"
603  "\n"
604  "void neutralElement(char* e) {\n"
605  " Vec8* pe = (Vec8*)e;\n"
606  " pe->pos.x = 0;\n"
607  " pe->pos.y = 0;\n"
608  " pe->pos.z = 0;\n"
609  " pe->pos.w = 1;\n"
610  " pe->col.x = 0;\n"
611  " pe->col.y = 0;\n"
612  " pe->col.z = 0;\n"
613  " pe->col.w = 1;\n"
614  "}\n"
615  "\n"
616  "void neutralElement_global(__global char* e) {\n"
617  " __global Vec8* pe = (__global Vec8*)e;\n"
618  " pe->pos.x = 0;\n"
619  " pe->pos.y = 0;\n"
620  " pe->pos.z = 0;\n"
621  " pe->pos.w = 1;\n"
622  " pe->col.x = 0;\n"
623  " pe->col.y = 0;\n"
624  " pe->col.z = 0;\n"
625  " pe->col.w = 1;\n"
626  "}\n"
627  "\n"
628  "void neutralElement_local(__local char* e) {\n"
629  "// __local Vec8* pe = (__local Vec8*)e;\n"
630  "// pe->pos.x = 0;\n"
631  "// pe->pos.y = 0;\n"
632  "// pe->pos.z = 0;\n"
633  "// pe->pos.w = 1;\n"
634  "// pe->col.x = 0;\n"
635  "// pe->col.y = 0;\n"
636  "// pe->col.z = 0;\n"
637  "// pe->col.w = 1;\n"
638  " char elem[32];\n"
639  " neutralElement(elem);\n"
640  " for(int i = 0; i < 32; i++) {\n"
641  " e[i] = elem[i];\n"
642  " }\n"
643  "}\n"
644  "\n"
645  "\n"
646  "float distanceFunc(const __global char * a, const __global char *b) {\n"
647  " const __global Vec8* pa = (const __global Vec8*)a;\n"
648  " const __global Vec8* pb = (const __global Vec8*)b;\n"
649  " Vec8 dist;\n"
650  " dist.pos.x = pa->pos.x-pb->pos.x;\n"
651  " dist.pos.y = pa->pos.y-pb->pos.y;\n"
652  " dist.pos.z = pa->pos.z-pb->pos.z;\n"
653  " dist.col.x = pa->pos.x-pb->col.x;\n"
654  " dist.col.y = pa->pos.y-pb->col.y;\n"
655  " dist.col.z = pa->pos.z-pb->col.z;\n"
656  " return sqrt(dist.pos.x*dist.pos.x+dist.pos.y*dist.pos.y+dist.pos.z*dist.pos.z+dist.col.x*dist.col.x+dist.col.y*dist.col.y+dist.col.z*dist.col.z);\n"
657  "}\n"
658  "\n"
659  "void getCovariance(const __global char * a, const __global char *b, __global float* h) {\n"
660  " const __global Vec8* pa = (const __global Vec8*)a;\n"
661  " const __global Vec8* pb = (const __global Vec8*)b;\n"
662  " h[0] = pa->pos.x*pb->pos.x;\n"
663  " h[1] = pa->pos.x*pb->pos.y;\n"
664  " h[2] = pa->pos.x*pb->pos.z;\n"
665  " h[3] = 0;\n"
666  "\n"
667  " h[4] = pa->pos.y*pb->pos.x;\n"
668  " h[5] = pa->pos.y*pb->pos.y;\n"
669  " h[6] = pa->pos.y*pb->pos.z;\n"
670  " h[7] = 0;\n"
671  "\n"
672  " h[8] = pa->pos.z*pb->pos.x;\n"
673  " h[9] = pa->pos.z*pb->pos.y;\n"
674  " h[10] = pa->pos.z*pb->pos.z;\n"
675  " h[11] = 0;\n"
676  "\n"
677  " h[12] = 0;\n"
678  " h[13] = 0;\n"
679  " h[14] = 0;\n"
680  " h[15] = 1;\n"
681  "}\n"
682  "\n"
683  "\n"
684  "void matrixMultiply(const __global char * a, char __global *b, const __global float* m) {\n"
685  " const __global Vec8* pa = (const __global Vec8*)a;\n"
686  " __global Vec8* pb = (__global Vec8*)b;\n"
687  " pb->pos.x = m[0]*pa->pos.x+m[1]*pa->pos.y+m[2]*pa->pos.z+m[3]*pa->pos.w;\n"
688  " pb->pos.y = m[4]*pa->pos.x+m[5]*pa->pos.y+m[6]*pa->pos.z+m[7]*pa->pos.w;\n"
689  " pb->pos.z = m[8]*pa->pos.x+m[9]*pa->pos.y+m[10]*pa->pos.z+m[11]*pa->pos.w;\n"
690  " pb->pos.w = m[12]*pa->pos.x+m[13]*pa->pos.y+m[14]*pa->pos.z+m[15]*pa->pos.w;\n"
691  "}\n"
692  );
693  } // namespace geom
694 }
695 
const std::string IterativeClosestPointTypeCodeVec8
Definition: IterativeClosestPointCLCode.h:477
undocument this line if you encounter any issues!
Definition: Any.h:37
const std::string IterativeClosestPointTypeCodeVec4
Definition: IterativeClosestPointCLCode.h:311
void subVec4(const char *a, const char *b, char *c)
Definition: IterativeClosestPointCLCode.h:37
Vec4 toVectorVec4(const char *point)
Definition: IterativeClosestPointCLCode.h:54
Definition: IterativeClosestPoint.h:36
const ProgArg pa(const std::string &id, unsigned int subargidx=0)
returns given program argument
Definition: ProgArg.h:304
const std::string IterativeClosestPointKernelCode
Definition: IterativeClosestPointCLCode.h:86
void subVec8(const char *a, const char *b, char *c)
Definition: IterativeClosestPointCLCode.h:62
Vec4 toVectorVec8(const char *point)
Definition: IterativeClosestPointCLCode.h:58
math::Vec4 pos
Definition: IterativeClosestPoint.h:37
math::Vec4 col
Definition: IterativeClosestPoint.h:38