go home Home | Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals | Related Pages
cutil_math_bugfixes.h
Go to the documentation of this file.
1 /*
2  * Copyright 1993-2007 NVIDIA Corporation. All rights reserved.
3  *
4  * NOTICE TO USER:
5  *
6  * This source code is subject to NVIDIA ownership rights under U.S. and
7  * international Copyright laws. Users and possessors of this source code
8  * are hereby granted a nonexclusive, royalty-free license to use this code
9  * in individual and commercial software.
10  *
11  * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
12  * CODE FOR ANY PURPOSE. IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
13  * IMPLIED WARRANTY OF ANY KIND. NVIDIA DISCLAIMS ALL WARRANTIES WITH
14  * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
15  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
16  * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
17  * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
18  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
19  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
20  * OR PERFORMANCE OF THIS SOURCE CODE.
21  *
22  * U.S. Government End Users. This source code is a "commercial item" as
23  * that term is defined at 48 C.F.R. 2.101 (OCT 1995), consisting of
24  * "commercial computer software" and "commercial computer software
25  * documentation" as such terms are used in 48 C.F.R. 12.212 (SEPT 1995)
26  * and is provided to the U.S. Government only as a commercial end item.
27  * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
28  * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
29  * source code with only those rights set forth herein.
30  *
31  * Any use of this source code in individual and commercial software must
32  * include, in the user documentation and internal comments to the code,
33  * the above Disclaimer and U.S. Government End Users Notice.
34  */
35 
36 /*
37  This file implements common mathematical operations on vector types
38  (float3, float4 etc.) since these are not provided as standard by CUDA.
39 
40  The syntax is modeled on the Cg standard library.
41 */
42 
43 // This software contains source code provided by NVIDIA Corporation.
44 // This header contains some bug fixes by Danny Ruijters, changed locations
45 // are marked with "Danny".
46 #ifndef CUTIL_MATH_BUGFIXES_H
47 #define CUTIL_MATH_BUGFIXES_H
48 
49 #ifdef CUTIL_MATH_H //Danny
50 // Houston, we have a problem!!!
51 // It seems that the buggy cutil_math.h has already been included, and this
52 // clashes with this header file.
53 #error cutil_math_bugfixes.h has to be included before cutil_math.h!!!
54 #endif
55 #define CUTIL_MATH_H //make sure that the buggy cutil_math.h will not be included
56 
57 #include "cuda_runtime.h"
58 
60 typedef unsigned int uint;
61 typedef unsigned short ushort;
62 
63 #ifndef __CUDACC__
64 #include <math.h>
65 
66 inline float fminf(float a, float b)
67 {
68  return a < b ? a : b;
69 }
70 
71 inline float fmaxf(float a, float b)
72 {
73  return a < b ? a : b;
74 }
75 
76 inline int max(int a, int b)
77 {
78  return a > b ? a : b;
79 }
80 
81 inline int min(int a, int b)
82 {
83  return a < b ? a : b;
84 }
85 #endif
86 
87 // float functions
89 
90 // lerp
91 inline __device__ __host__ float lerp(float a, float b, float t)
92 {
93  return a + t*(b-a);
94 }
95 
96 // clamp
97 inline __device__ __host__ float clamp(float f, float a, float b)
98 {
99  return fmaxf(a, fminf(f, b));
100 }
101 
102 // int2 functions
104 
105 // addition
106 inline __host__ __device__ int2 operator+(int2 a, int2 b)
107 {
108  return make_int2(a.x + b.x, a.y + b.y);
109 }
110 inline __host__ __device__ void operator+=(int2 &a, int2 b)
111 {
112  a.x += b.x; a.y += b.y;
113 }
114 
115 // subtract
116 inline __host__ __device__ int2 operator-(int2 a, int2 b)
117 {
118  return make_int2(a.x - b.x, a.y - b.y);
119 }
120 inline __host__ __device__ void operator-=(int2 &a, int2 b)
121 {
122  a.x -= b.x; a.y -= b.y;
123 }
124 
125 // multiply
126 inline __host__ __device__ int2 operator*(int2 a, int2 b)
127 {
128  return make_int2(a.x * b.x, a.y * b.y);
129 }
130 inline __host__ __device__ int2 operator*(int2 a, int s)
131 {
132  return make_int2(a.x * s, a.y * s);
133 }
134 inline __host__ __device__ int2 operator*(int s, int2 a)
135 {
136  return make_int2(a.x * s, a.y * s);
137 }
138 inline __host__ __device__ void operator*=(int2 &a, int s)
139 {
140  a.x *= s; a.y *= s;
141 }
142 
143 // float2 functions
145 
146 // additional constructors
147 inline __host__ __device__ float2 make_float2(float s)
148 {
149  return make_float2(s, s);
150 }
151 inline __host__ __device__ float2 make_float2(int2 a)
152 {
153  return make_float2(float(a.x), float(a.y));
154 }
155 
156 // addition
157 inline __host__ __device__ float2 operator+(float2 a, float2 b)
158 {
159  return make_float2(a.x + b.x, a.y + b.y);
160 }
161 inline __host__ __device__ void operator+=(float2 &a, float2 b)
162 {
163  a.x += b.x; a.y += b.y;
164 }
165 
166 // subtract
167 inline __host__ __device__ float2 operator-(float2 a, float2 b)
168 {
169  return make_float2(a.x - b.x, a.y - b.y);
170 }
171 inline __host__ __device__ void operator-=(float2 &a, float2 b)
172 {
173  a.x -= b.x; a.y -= b.y;
174 }
175 
176 // multiply
177 inline __host__ __device__ float2 operator*(float2 a, float2 b)
178 {
179  return make_float2(a.x * b.x, a.y * b.y);
180 }
181 inline __host__ __device__ float2 operator*(float2 a, float s)
182 {
183  return make_float2(a.x * s, a.y * s);
184 }
185 inline __host__ __device__ float2 operator*(float s, float2 a)
186 {
187  return make_float2(a.x * s, a.y * s);
188 }
189 inline __host__ __device__ void operator*=(float2 &a, float s)
190 {
191  a.x *= s; a.y *= s;
192 }
193 
194 // divide
195 inline __host__ __device__ float2 operator/(float2 a, float2 b)
196 {
197  return make_float2(a.x / b.x, a.y / b.y);
198 }
199 inline __host__ __device__ float2 operator/(float2 a, float s)
200 {
201  float inv = 1.0f / s;
202  return a * inv;
203 }
204 inline __host__ __device__ float2 operator/(float s, float2 a) //Danny
205 {
206 // float inv = 1.0f / s;
207 // return a * inv;
208  return make_float2(s / a.x, s / a.y);
209 }
210 inline __host__ __device__ void operator/=(float2 &a, float s)
211 {
212  float inv = 1.0f / s;
213  a *= inv;
214 }
215 
216 // lerp
217 inline __device__ __host__ float2 lerp(float2 a, float2 b, float t)
218 {
219  return a + t*(b-a);
220 }
221 
222 // clamp
223 inline __device__ __host__ float2 clamp(float2 v, float a, float b)
224 {
225  return make_float2(clamp(v.x, a, b), clamp(v.y, a, b));
226 }
227 
228 inline __device__ __host__ float2 clamp(float2 v, float2 a, float2 b)
229 {
230  return make_float2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
231 }
232 
233 // dot product
234 inline __host__ __device__ float dot(float2 a, float2 b)
235 {
236  return a.x * b.x + a.y * b.y;
237 }
238 
239 // length
240 inline __host__ __device__ float length(float2 v)
241 {
242  return sqrtf(dot(v, v));
243 }
244 
245 // normalize
246 inline __host__ __device__ float2 normalize(float2 v)
247 {
248  float invLen = 1.0f / sqrtf(dot(v, v));
249  return v * invLen;
250 }
251 
252 // floor
253 inline __host__ __device__ float2 floor(const float2 v)
254 {
255  return make_float2(floor(v.x), floor(v.y));
256 }
257 
258 // reflect
259 inline __host__ __device__ float2 reflect(float2 i, float2 n)
260 {
261  return i - 2.0f * n * dot(n,i);
262 }
263 
264 // float3 functions
266 
267 // additional constructors
268 inline __host__ __device__ float3 make_float3(float s)
269 {
270  return make_float3(s, s, s);
271 }
272 inline __host__ __device__ float3 make_float3(float2 a)
273 {
274  return make_float3(a.x, a.y, 0.0f);
275 }
276 inline __host__ __device__ float3 make_float3(float2 a, float s)
277 {
278  return make_float3(a.x, a.y, s);
279 }
280 inline __host__ __device__ float3 make_float3(float4 a)
281 {
282  return make_float3(a.x, a.y, a.z); // discards w
283 }
284 inline __host__ __device__ float3 make_float3(int3 a)
285 {
286  return make_float3(float(a.x), float(a.y), float(a.z));
287 }
288 
289 // min
290 static __inline__ __host__ __device__ float3 fminf(float3 a, float3 b)
291 {
292  return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z));
293 }
294 
295 // max
296 static __inline__ __host__ __device__ float3 fmaxf(float3 a, float3 b)
297 {
298  return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z));
299 }
300 
301 // addition
302 inline __host__ __device__ float3 operator+(float3 a, float3 b)
303 {
304  return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
305 }
306 inline __host__ __device__ float3 operator+(float3 a, float b)
307 {
308  return make_float3(a.x + b, a.y + b, a.z + b);
309 }
310 inline __host__ __device__ void operator+=(float3 &a, float3 b)
311 {
312  a.x += b.x; a.y += b.y; a.z += b.z;
313 }
314 
315 // subtract
316 inline __host__ __device__ float3 operator-(float3 a, float3 b)
317 {
318  return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
319 }
320 inline __host__ __device__ float3 operator-(float3 a, float b)
321 {
322  return make_float3(a.x - b, a.y - b, a.z - b);
323 }
324 inline __host__ __device__ void operator-=(float3 &a, float3 b)
325 {
326  a.x -= b.x; a.y -= b.y; a.z -= b.z;
327 }
328 
329 // multiply
330 inline __host__ __device__ float3 operator*(float3 a, float3 b)
331 {
332  return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
333 }
334 inline __host__ __device__ float3 operator*(float3 a, float s)
335 {
336  return make_float3(a.x * s, a.y * s, a.z * s);
337 }
338 inline __host__ __device__ float3 operator*(float s, float3 a)
339 {
340  return make_float3(a.x * s, a.y * s, a.z * s);
341 }
342 inline __host__ __device__ void operator*=(float3 &a, float s)
343 {
344  a.x *= s; a.y *= s; a.z *= s;
345 }
346 
347 // divide
348 inline __host__ __device__ float3 operator/(float3 a, float3 b)
349 {
350  return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
351 }
352 inline __host__ __device__ float3 operator/(float3 a, float s)
353 {
354  float inv = 1.0f / s;
355  return a * inv;
356 }
357 inline __host__ __device__ float3 operator/(float s, float3 a) //Danny
358 {
359 // float inv = 1.0f / s;
360 // return a * inv;
361  return make_float3(s / a.x, s / a.y, s / a.z);
362 }
363 inline __host__ __device__ void operator/=(float3 &a, float s)
364 {
365  float inv = 1.0f / s;
366  a *= inv;
367 }
368 
369 // lerp
370 inline __device__ __host__ float3 lerp(float3 a, float3 b, float t)
371 {
372  return a + t*(b-a);
373 }
374 
375 // clamp
376 inline __device__ __host__ float3 clamp(float3 v, float a, float b)
377 {
378  return make_float3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
379 }
380 
381 inline __device__ __host__ float3 clamp(float3 v, float3 a, float3 b)
382 {
383  return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
384 }
385 
386 // dot product
387 inline __host__ __device__ float dot(float3 a, float3 b)
388 {
389  return a.x * b.x + a.y * b.y + a.z * b.z;
390 }
391 
392 // cross product
393 inline __host__ __device__ float3 cross(float3 a, float3 b)
394 {
395  return make_float3(a.y*b.z - a.z*b.y, a.z*b.x - a.x*b.z, a.x*b.y - a.y*b.x);
396 }
397 
398 // length
399 inline __host__ __device__ float length(float3 v)
400 {
401  return sqrtf(dot(v, v));
402 }
403 
404 // normalize
405 inline __host__ __device__ float3 normalize(float3 v)
406 {
407  float invLen = 1.0f / sqrtf(dot(v, v));
408  return v * invLen;
409 }
410 
411 // floor
412 inline __host__ __device__ float3 floor(const float3 v)
413 {
414  return make_float3(floor(v.x), floor(v.y), floor(v.z));
415 }
416 
417 // reflect
418 inline __host__ __device__ float3 reflect(float3 i, float3 n)
419 {
420  return i - 2.0f * n * dot(n,i);
421 }
422 
423 // float4 functions
425 
426 // additional constructors
427 inline __host__ __device__ float4 make_float4(float s)
428 {
429  return make_float4(s, s, s, s);
430 }
431 inline __host__ __device__ float4 make_float4(float3 a)
432 {
433  return make_float4(a.x, a.y, a.z, 0.0f);
434 }
435 inline __host__ __device__ float4 make_float4(float3 a, float w)
436 {
437  return make_float4(a.x, a.y, a.z, w);
438 }
439 inline __host__ __device__ float4 make_float4(int4 a)
440 {
441  return make_float4(float(a.x), float(a.y), float(a.z), float(a.w));
442 }
443 
444 // min
445 static __inline__ __host__ __device__ float4 fminf(float4 a, float4 b)
446 {
447  return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w));
448 }
449 
450 // max
451 static __inline__ __host__ __device__ float4 fmaxf(float4 a, float4 b)
452 {
453  return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w));
454 }
455 
456 // addition
457 inline __host__ __device__ float4 operator+(float4 a, float4 b)
458 {
459  return make_float4(a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w);
460 }
461 inline __host__ __device__ void operator+=(float4 &a, float4 b)
462 {
463  a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
464 }
465 
466 // subtract
467 inline __host__ __device__ float4 operator-(float4 a, float4 b)
468 {
469  return make_float4(a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w);
470 }
471 inline __host__ __device__ void operator-=(float4 &a, float4 b)
472 {
473  a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
474 }
475 
476 // multiply
477 inline __host__ __device__ float4 operator*(float4 a, float s)
478 {
479  return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
480 }
481 inline __host__ __device__ float4 operator*(float s, float4 a)
482 {
483  return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
484 }
485 inline __host__ __device__ void operator*=(float4 &a, float s)
486 {
487  a.x *= s; a.y *= s; a.z *= s; a.w *= s;
488 }
489 
490 // divide
491 inline __host__ __device__ float4 operator/(float4 a, float4 b)
492 {
493  return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
494 }
495 inline __host__ __device__ float4 operator/(float4 a, float s)
496 {
497  float inv = 1.0f / s;
498  return a * inv;
499 }
500 inline __host__ __device__ float4 operator/(float s, float4 a) //Danny
501 {
502 // float inv = 1.0f / s;
503 // return a * inv;
504  return make_float4(s / a.x, s / a.y, s / a.z, s / a.w);
505 }
506 inline __host__ __device__ void operator/=(float4 &a, float s)
507 {
508  float inv = 1.0f / s;
509  a *= inv;
510 }
511 
512 // lerp
513 inline __device__ __host__ float4 lerp(float4 a, float4 b, float t)
514 {
515  return a + t*(b-a);
516 }
517 
518 // clamp
519 inline __device__ __host__ float4 clamp(float4 v, float a, float b)
520 {
521  return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
522 }
523 
524 inline __device__ __host__ float4 clamp(float4 v, float4 a, float4 b)
525 {
526  return make_float4(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z), clamp(v.w, a.w, b.w));
527 }
528 
529 // dot product
530 inline __host__ __device__ float dot(float4 a, float4 b)
531 {
532  return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
533 }
534 
535 // length
536 inline __host__ __device__ float length(float4 r)
537 {
538  return sqrtf(dot(r, r));
539 }
540 
541 // normalize
542 inline __host__ __device__ float4 normalize(float4 v)
543 {
544  float invLen = 1.0f / sqrtf(dot(v, v));
545  return v * invLen;
546 }
547 
548 // floor
549 inline __host__ __device__ float4 floor(const float4 v)
550 {
551  return make_float4(floor(v.x), floor(v.y), floor(v.z), floor(v.w));
552 }
553 
554 // int3 functions
556 
557 // additional constructors
558 inline __host__ __device__ int3 make_int3(int s)
559 {
560  return make_int3(s, s, s);
561 }
562 inline __host__ __device__ int3 make_int3(float3 a)
563 {
564  return make_int3(int(a.x), int(a.y), int(a.z));
565 }
566 
567 // min
568 inline __host__ __device__ int3 min(int3 a, int3 b)
569 {
570  return make_int3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
571 }
572 
573 // max
574 inline __host__ __device__ int3 max(int3 a, int3 b)
575 {
576  return make_int3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
577 }
578 
579 // addition
580 inline __host__ __device__ int3 operator+(int3 a, int3 b)
581 {
582  return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
583 }
584 inline __host__ __device__ void operator+=(int3 &a, int3 b)
585 {
586  a.x += b.x; a.y += b.y; a.z += b.z;
587 }
588 
589 // subtract
590 inline __host__ __device__ int3 operator-(int3 a, int3 b)
591 {
592  return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
593 }
594 
595 inline __host__ __device__ void operator-=(int3 &a, int3 b)
596 {
597  a.x -= b.x; a.y -= b.y; a.z -= b.z;
598 }
599 
600 // multiply
601 inline __host__ __device__ int3 operator*(int3 a, int3 b)
602 {
603  return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
604 }
605 inline __host__ __device__ int3 operator*(int3 a, int s)
606 {
607  return make_int3(a.x * s, a.y * s, a.z * s);
608 }
609 inline __host__ __device__ int3 operator*(int s, int3 a)
610 {
611  return make_int3(a.x * s, a.y * s, a.z * s);
612 }
613 inline __host__ __device__ void operator*=(int3 &a, int s)
614 {
615  a.x *= s; a.y *= s; a.z *= s;
616 }
617 
618 // divide
619 inline __host__ __device__ int3 operator/(int3 a, int3 b)
620 {
621  return make_int3(a.x / b.x, a.y / b.y, a.z / b.z);
622 }
623 inline __host__ __device__ int3 operator/(int3 a, int s)
624 {
625  return make_int3(a.x / s, a.y / s, a.z / s);
626 }
627 inline __host__ __device__ int3 operator/(int s, int3 a)
628 {
629  return make_int3(a.x / s, a.y / s, a.z / s);
630 }
631 inline __host__ __device__ void operator/=(int3 &a, int s)
632 {
633  a.x /= s; a.y /= s; a.z /= s;
634 }
635 
636 // clamp
637 inline __device__ __host__ int clamp(int f, int a, int b)
638 {
639  return max(a, min(f, b));
640 }
641 
642 inline __device__ __host__ int3 clamp(int3 v, int a, int b)
643 {
644  return make_int3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
645 }
646 
647 inline __device__ __host__ int3 clamp(int3 v, int3 a, int3 b)
648 {
649  return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
650 }
651 
652 
653 // uint3 functions
655 
656 // additional constructors
657 inline __host__ __device__ uint3 make_uint3(uint s)
658 {
659  return make_uint3(s, s, s);
660 }
661 inline __host__ __device__ uint3 make_uint3(float3 a)
662 {
663  return make_uint3(uint(a.x), uint(a.y), uint(a.z));
664 }
665 
666 // min
667 inline __host__ __device__ uint3 min(uint3 a, uint3 b)
668 {
669  return make_uint3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
670 }
671 
672 // max
673 inline __host__ __device__ uint3 max(uint3 a, uint3 b)
674 {
675  return make_uint3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
676 }
677 
678 // addition
679 inline __host__ __device__ uint3 operator+(uint3 a, uint3 b)
680 {
681  return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z);
682 }
683 inline __host__ __device__ void operator+=(uint3 &a, uint3 b)
684 {
685  a.x += b.x; a.y += b.y; a.z += b.z;
686 }
687 
688 // subtract
689 inline __host__ __device__ uint3 operator-(uint3 a, uint3 b)
690 {
691  return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z);
692 }
693 
694 inline __host__ __device__ void operator-=(uint3 &a, uint3 b)
695 {
696  a.x -= b.x; a.y -= b.y; a.z -= b.z;
697 }
698 
699 // multiply
700 inline __host__ __device__ uint3 operator*(uint3 a, uint3 b)
701 {
702  return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z);
703 }
704 inline __host__ __device__ uint3 operator*(uint3 a, uint s)
705 {
706  return make_uint3(a.x * s, a.y * s, a.z * s);
707 }
708 inline __host__ __device__ uint3 operator*(uint s, uint3 a)
709 {
710  return make_uint3(a.x * s, a.y * s, a.z * s);
711 }
712 inline __host__ __device__ void operator*=(uint3 &a, uint s)
713 {
714  a.x *= s; a.y *= s; a.z *= s;
715 }
716 
717 // divide
718 inline __host__ __device__ uint3 operator/(uint3 a, uint3 b)
719 {
720  return make_uint3(a.x / b.x, a.y / b.y, a.z / b.z);
721 }
722 inline __host__ __device__ uint3 operator/(uint3 a, uint s)
723 {
724  return make_uint3(a.x / s, a.y / s, a.z / s);
725 }
726 inline __host__ __device__ uint3 operator/(uint s, uint3 a)
727 {
728  return make_uint3(a.x / s, a.y / s, a.z / s);
729 }
730 inline __host__ __device__ void operator/=(uint3 &a, uint s)
731 {
732  a.x /= s; a.y /= s; a.z /= s;
733 }
734 
735 // clamp
736 inline __device__ __host__ uint clamp(uint f, uint a, uint b)
737 {
738  return max(a, min(f, b));
739 }
740 
741 inline __device__ __host__ uint3 clamp(uint3 v, uint a, uint b)
742 {
743  return make_uint3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
744 }
745 
746 inline __device__ __host__ uint3 clamp(uint3 v, uint3 a, uint3 b)
747 {
748  return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
749 }
750 
751 #endif
__host__ __device__ float dot(float2 a, float2 b)
float fmaxf(float a, float b)
__device__ __host__ float clamp(float f, float a, float b)
unsigned short ushort
__host__ __device__ uint3 make_uint3(uint s)
__host__ __device__ float2 floor(const float2 v)
__host__ __device__ float4 make_float4(float s)
__host__ __device__ int2 operator+(int2 a, int2 b)
__host__ __device__ void operator-=(int2 &a, int2 b)
__host__ __device__ void operator*=(int2 &a, int s)
__host__ __device__ float2 normalize(float2 v)
__host__ __device__ float2 reflect(float2 i, float2 n)
__host__ __device__ float3 cross(float3 a, float3 b)
__host__ __device__ int2 operator*(int2 a, int2 b)
__host__ __device__ float3 make_float3(float s)
__host__ __device__ float2 make_float2(float s)
__host__ __device__ float2 operator/(float2 a, float2 b)
int max(int a, int b)
__device__ __host__ float lerp(float a, float b, float t)
unsigned int uint
float fminf(float a, float b)
__host__ __device__ void operator+=(int2 &a, int2 b)
__host__ __device__ int2 operator-(int2 a, int2 b)
__host__ __device__ int3 make_int3(int s)
int min(int a, int b)
__host__ __device__ float length(float2 v)
__host__ __device__ void operator/=(float2 &a, float s)


Generated on 04-09-2015 for elastix by doxygen 1.8.9.1 elastix logo