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.
00001 /*
00002  * Copyright 1993-2007 NVIDIA Corporation.  All rights reserved.
00003  *
00004  * NOTICE TO USER:
00005  *
00006  * This source code is subject to NVIDIA ownership rights under U.S. and
00007  * international Copyright laws.  Users and possessors of this source code
00008  * are hereby granted a nonexclusive, royalty-free license to use this code
00009  * in individual and commercial software.
00010  *
00011  * NVIDIA MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS SOURCE
00012  * CODE FOR ANY PURPOSE.  IT IS PROVIDED "AS IS" WITHOUT EXPRESS OR
00013  * IMPLIED WARRANTY OF ANY KIND.  NVIDIA DISCLAIMS ALL WARRANTIES WITH
00014  * REGARD TO THIS SOURCE CODE, INCLUDING ALL IMPLIED WARRANTIES OF
00015  * MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.
00016  * IN NO EVENT SHALL NVIDIA BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL,
00017  * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00018  * OF USE, DATA OR PROFITS,  WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
00019  * OR OTHER TORTIOUS ACTION,  ARISING OUT OF OR IN CONNECTION WITH THE USE
00020  * OR PERFORMANCE OF THIS SOURCE CODE.
00021  *
00022  * U.S. Government End Users.   This source code is a "commercial item" as
00023  * that term is defined at  48 C.F.R. 2.101 (OCT 1995), consisting  of
00024  * "commercial computer  software"  and "commercial computer software
00025  * documentation" as such terms are  used in 48 C.F.R. 12.212 (SEPT 1995)
00026  * and is provided to the U.S. Government only as a commercial end item.
00027  * Consistent with 48 C.F.R.12.212 and 48 C.F.R. 227.7202-1 through
00028  * 227.7202-4 (JUNE 1995), all U.S. Government End Users acquire the
00029  * source code with only those rights set forth herein.
00030  *
00031  * Any use of this source code in individual and commercial software must
00032  * include, in the user documentation and internal comments to the code,
00033  * the above Disclaimer and U.S. Government End Users Notice.
00034  */
00035 
00036 /*
00037   This file implements common mathematical operations on vector types
00038   (float3, float4 etc.) since these are not provided as standard by CUDA.
00039 
00040   The syntax is modeled on the Cg standard library.
00041 */
00042 
00043 // This software contains source code provided by NVIDIA Corporation.
00044 // This header contains some bug fixes by Danny Ruijters, changed locations
00045 // are marked with "Danny".
00046 #ifndef CUTIL_MATH_BUGFIXES_H
00047 #define CUTIL_MATH_BUGFIXES_H
00048 
00049 #ifdef CUTIL_MATH_H  //Danny
00050 // Houston, we have a problem!!!
00051 // It seems that the buggy cutil_math.h has already been included, and this
00052 // clashes with this header file.
00053 #error cutil_math_bugfixes.h has to be included before cutil_math.h!!!
00054 #endif
00055 #define CUTIL_MATH_H  //make sure that the buggy cutil_math.h will not be included
00056 
00057 #include "cuda_runtime.h"
00058 
00060 typedef unsigned int uint;
00061 typedef unsigned short ushort;
00062 
00063 #ifndef __CUDACC__
00064 #include <math.h>
00065 
00066 inline float fminf(float a, float b)
00067 {
00068   return a < b ? a : b;
00069 }
00070 
00071 inline float fmaxf(float a, float b)
00072 {
00073   return a < b ? a : b;
00074 }
00075 
00076 inline int max(int a, int b)
00077 {
00078   return a > b ? a : b;
00079 }
00080 
00081 inline int min(int a, int b)
00082 {
00083   return a < b ? a : b;
00084 }
00085 #endif
00086 
00087 // float functions
00089 
00090 // lerp
00091 inline __device__ __host__ float lerp(float a, float b, float t)
00092 {
00093   return a + t*(b-a);
00094 }
00095 
00096 // clamp
00097 inline __device__ __host__ float clamp(float f, float a, float b)
00098 {
00099   return fmaxf(a, fminf(f, b));
00100 }
00101 
00102 // int2 functions
00104 
00105 // addition
00106 inline __host__ __device__ int2 operator+(int2 a, int2 b)
00107 {
00108   return make_int2(a.x + b.x, a.y + b.y);
00109 }
00110 inline __host__ __device__ void operator+=(int2 &a, int2 b)
00111 {
00112   a.x += b.x; a.y += b.y;
00113 }
00114 
00115 // subtract
00116 inline __host__ __device__ int2 operator-(int2 a, int2 b)
00117 {
00118   return make_int2(a.x - b.x, a.y - b.y);
00119 }
00120 inline __host__ __device__ void operator-=(int2 &a, int2 b)
00121 {
00122   a.x -= b.x; a.y -= b.y;
00123 }
00124 
00125 // multiply
00126 inline __host__ __device__ int2 operator*(int2 a, int2 b)
00127 {
00128   return make_int2(a.x * b.x, a.y * b.y);
00129 }
00130 inline __host__ __device__ int2 operator*(int2 a, int s)
00131 {
00132   return make_int2(a.x * s, a.y * s);
00133 }
00134 inline __host__ __device__ int2 operator*(int s, int2 a)
00135 {
00136   return make_int2(a.x * s, a.y * s);
00137 }
00138 inline __host__ __device__ void operator*=(int2 &a, int s)
00139 {
00140   a.x *= s; a.y *= s;
00141 }
00142 
00143 // float2 functions
00145 
00146 // additional constructors
00147 inline __host__ __device__ float2 make_float2(float s)
00148 {
00149   return make_float2(s, s);
00150 }
00151 inline __host__ __device__ float2 make_float2(int2 a)
00152 {
00153   return make_float2(float(a.x), float(a.y));
00154 }
00155 
00156 // addition
00157 inline __host__ __device__ float2 operator+(float2 a, float2 b)
00158 {
00159   return make_float2(a.x + b.x, a.y + b.y);
00160 }
00161 inline __host__ __device__ void operator+=(float2 &a, float2 b)
00162 {
00163   a.x += b.x; a.y += b.y;
00164 }
00165 
00166 // subtract
00167 inline __host__ __device__ float2 operator-(float2 a, float2 b)
00168 {
00169   return make_float2(a.x - b.x, a.y - b.y);
00170 }
00171 inline __host__ __device__ void operator-=(float2 &a, float2 b)
00172 {
00173   a.x -= b.x; a.y -= b.y;
00174 }
00175 
00176 // multiply
00177 inline __host__ __device__ float2 operator*(float2 a, float2 b)
00178 {
00179   return make_float2(a.x * b.x, a.y * b.y);
00180 }
00181 inline __host__ __device__ float2 operator*(float2 a, float s)
00182 {
00183   return make_float2(a.x * s, a.y * s);
00184 }
00185 inline __host__ __device__ float2 operator*(float s, float2 a)
00186 {
00187   return make_float2(a.x * s, a.y * s);
00188 }
00189 inline __host__ __device__ void operator*=(float2 &a, float s)
00190 {
00191   a.x *= s; a.y *= s;
00192 }
00193 
00194 // divide
00195 inline __host__ __device__ float2 operator/(float2 a, float2 b)
00196 {
00197   return make_float2(a.x / b.x, a.y / b.y);
00198 }
00199 inline __host__ __device__ float2 operator/(float2 a, float s)
00200 {
00201   float inv = 1.0f / s;
00202   return a * inv;
00203 }
00204 inline __host__ __device__ float2 operator/(float s, float2 a)  //Danny
00205 {
00206 //  float inv = 1.0f / s;
00207 //  return a * inv;
00208   return make_float2(s / a.x, s / a.y);
00209 }
00210 inline __host__ __device__ void operator/=(float2 &a, float s)
00211 {
00212   float inv = 1.0f / s;
00213   a *= inv;
00214 }
00215 
00216 // lerp
00217 inline __device__ __host__ float2 lerp(float2 a, float2 b, float t)
00218 {
00219   return a + t*(b-a);
00220 }
00221 
00222 // clamp
00223 inline __device__ __host__ float2 clamp(float2 v, float a, float b)
00224 {
00225   return make_float2(clamp(v.x, a, b), clamp(v.y, a, b));
00226 }
00227 
00228 inline __device__ __host__ float2 clamp(float2 v, float2 a, float2 b)
00229 {
00230   return make_float2(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y));
00231 }
00232 
00233 // dot product
00234 inline __host__ __device__ float dot(float2 a, float2 b)
00235 {
00236   return a.x * b.x + a.y * b.y;
00237 }
00238 
00239 // length
00240 inline __host__ __device__ float length(float2 v)
00241 {
00242   return sqrtf(dot(v, v));
00243 }
00244 
00245 // normalize
00246 inline __host__ __device__ float2 normalize(float2 v)
00247 {
00248   float invLen = 1.0f / sqrtf(dot(v, v));
00249   return v * invLen;
00250 }
00251 
00252 // floor
00253 inline __host__ __device__ float2 floor(const float2 v)
00254 {
00255   return make_float2(floor(v.x), floor(v.y));
00256 }
00257 
00258 // reflect
00259 inline __host__ __device__ float2 reflect(float2 i, float2 n)
00260 {
00261   return i - 2.0f * n * dot(n,i);
00262 }
00263 
00264 // float3 functions
00266 
00267 // additional constructors
00268 inline __host__ __device__ float3 make_float3(float s)
00269 {
00270   return make_float3(s, s, s);
00271 }
00272 inline __host__ __device__ float3 make_float3(float2 a)
00273 {
00274   return make_float3(a.x, a.y, 0.0f);
00275 }
00276 inline __host__ __device__ float3 make_float3(float2 a, float s)
00277 {
00278   return make_float3(a.x, a.y, s);
00279 }
00280 inline __host__ __device__ float3 make_float3(float4 a)
00281 {
00282   return make_float3(a.x, a.y, a.z);  // discards w
00283 }
00284 inline __host__ __device__ float3 make_float3(int3 a)
00285 {
00286   return make_float3(float(a.x), float(a.y), float(a.z));
00287 }
00288 
00289 // min
00290 static __inline__ __host__ __device__ float3 fminf(float3 a, float3 b)
00291 {
00292   return make_float3(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z));
00293 }
00294 
00295 // max
00296 static __inline__ __host__ __device__ float3 fmaxf(float3 a, float3 b)
00297 {
00298   return make_float3(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z));
00299 }
00300 
00301 // addition
00302 inline __host__ __device__ float3 operator+(float3 a, float3 b)
00303 {
00304   return make_float3(a.x + b.x, a.y + b.y, a.z + b.z);
00305 }
00306 inline __host__ __device__ float3 operator+(float3 a, float b)
00307 {
00308   return make_float3(a.x + b, a.y + b, a.z + b);
00309 }
00310 inline __host__ __device__ void operator+=(float3 &a, float3 b)
00311 {
00312   a.x += b.x; a.y += b.y; a.z += b.z;
00313 }
00314 
00315 // subtract
00316 inline __host__ __device__ float3 operator-(float3 a, float3 b)
00317 {
00318   return make_float3(a.x - b.x, a.y - b.y, a.z - b.z);
00319 }
00320 inline __host__ __device__ float3 operator-(float3 a, float b)
00321 {
00322   return make_float3(a.x - b, a.y - b, a.z - b);
00323 }
00324 inline __host__ __device__ void operator-=(float3 &a, float3 b)
00325 {
00326   a.x -= b.x; a.y -= b.y; a.z -= b.z;
00327 }
00328 
00329 // multiply
00330 inline __host__ __device__ float3 operator*(float3 a, float3 b)
00331 {
00332   return make_float3(a.x * b.x, a.y * b.y, a.z * b.z);
00333 }
00334 inline __host__ __device__ float3 operator*(float3 a, float s)
00335 {
00336   return make_float3(a.x * s, a.y * s, a.z * s);
00337 }
00338 inline __host__ __device__ float3 operator*(float s, float3 a)
00339 {
00340   return make_float3(a.x * s, a.y * s, a.z * s);
00341 }
00342 inline __host__ __device__ void operator*=(float3 &a, float s)
00343 {
00344   a.x *= s; a.y *= s; a.z *= s;
00345 }
00346 
00347 // divide
00348 inline __host__ __device__ float3 operator/(float3 a, float3 b)
00349 {
00350   return make_float3(a.x / b.x, a.y / b.y, a.z / b.z);
00351 }
00352 inline __host__ __device__ float3 operator/(float3 a, float s)
00353 {
00354   float inv = 1.0f / s;
00355   return a * inv;
00356 }
00357 inline __host__ __device__ float3 operator/(float s, float3 a)  //Danny
00358 {
00359 //  float inv = 1.0f / s;
00360 //  return a * inv;
00361   return make_float3(s / a.x, s / a.y, s / a.z);
00362 }
00363 inline __host__ __device__ void operator/=(float3 &a, float s)
00364 {
00365   float inv = 1.0f / s;
00366   a *= inv;
00367 }
00368 
00369 // lerp
00370 inline __device__ __host__ float3 lerp(float3 a, float3 b, float t)
00371 {
00372   return a + t*(b-a);
00373 }
00374 
00375 // clamp
00376 inline __device__ __host__ float3 clamp(float3 v, float a, float b)
00377 {
00378   return make_float3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
00379 }
00380 
00381 inline __device__ __host__ float3 clamp(float3 v, float3 a, float3 b)
00382 {
00383   return make_float3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
00384 }
00385 
00386 // dot product
00387 inline __host__ __device__ float dot(float3 a, float3 b)
00388 {
00389   return a.x * b.x + a.y * b.y + a.z * b.z;
00390 }
00391 
00392 // cross product
00393 inline __host__ __device__ float3 cross(float3 a, float3 b)
00394 {
00395   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);
00396 }
00397 
00398 // length
00399 inline __host__ __device__ float length(float3 v)
00400 {
00401   return sqrtf(dot(v, v));
00402 }
00403 
00404 // normalize
00405 inline __host__ __device__ float3 normalize(float3 v)
00406 {
00407   float invLen = 1.0f / sqrtf(dot(v, v));
00408   return v * invLen;
00409 }
00410 
00411 // floor
00412 inline __host__ __device__ float3 floor(const float3 v)
00413 {
00414   return make_float3(floor(v.x), floor(v.y), floor(v.z));
00415 }
00416 
00417 // reflect
00418 inline __host__ __device__ float3 reflect(float3 i, float3 n)
00419 {
00420   return i - 2.0f * n * dot(n,i);
00421 }
00422 
00423 // float4 functions
00425 
00426 // additional constructors
00427 inline __host__ __device__ float4 make_float4(float s)
00428 {
00429   return make_float4(s, s, s, s);
00430 }
00431 inline __host__ __device__ float4 make_float4(float3 a)
00432 {
00433   return make_float4(a.x, a.y, a.z, 0.0f);
00434 }
00435 inline __host__ __device__ float4 make_float4(float3 a, float w)
00436 {
00437   return make_float4(a.x, a.y, a.z, w);
00438 }
00439 inline __host__ __device__ float4 make_float4(int4 a)
00440 {
00441   return make_float4(float(a.x), float(a.y), float(a.z), float(a.w));
00442 }
00443 
00444 // min
00445 static __inline__ __host__ __device__ float4 fminf(float4 a, float4 b)
00446 {
00447   return make_float4(fminf(a.x,b.x), fminf(a.y,b.y), fminf(a.z,b.z), fminf(a.w,b.w));
00448 }
00449 
00450 // max
00451 static __inline__ __host__ __device__ float4 fmaxf(float4 a, float4 b)
00452 {
00453   return make_float4(fmaxf(a.x,b.x), fmaxf(a.y,b.y), fmaxf(a.z,b.z), fmaxf(a.w,b.w));
00454 }
00455 
00456 // addition
00457 inline __host__ __device__ float4 operator+(float4 a, float4 b)
00458 {
00459   return make_float4(a.x + b.x, a.y + b.y, a.z + b.z,  a.w + b.w);
00460 }
00461 inline __host__ __device__ void operator+=(float4 &a, float4 b)
00462 {
00463   a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
00464 }
00465 
00466 // subtract
00467 inline __host__ __device__ float4 operator-(float4 a, float4 b)
00468 {
00469   return make_float4(a.x - b.x, a.y - b.y, a.z - b.z,  a.w - b.w);
00470 }
00471 inline __host__ __device__ void operator-=(float4 &a, float4 b)
00472 {
00473   a.x -= b.x; a.y -= b.y; a.z -= b.z; a.w -= b.w;
00474 }
00475 
00476 // multiply
00477 inline __host__ __device__ float4 operator*(float4 a, float s)
00478 {
00479   return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
00480 }
00481 inline __host__ __device__ float4 operator*(float s, float4 a)
00482 {
00483   return make_float4(a.x * s, a.y * s, a.z * s, a.w * s);
00484 }
00485 inline __host__ __device__ void operator*=(float4 &a, float s)
00486 {
00487   a.x *= s; a.y *= s; a.z *= s; a.w *= s;
00488 }
00489 
00490 // divide
00491 inline __host__ __device__ float4 operator/(float4 a, float4 b)
00492 {
00493   return make_float4(a.x / b.x, a.y / b.y, a.z / b.z, a.w / b.w);
00494 }
00495 inline __host__ __device__ float4 operator/(float4 a, float s)
00496 {
00497   float inv = 1.0f / s;
00498   return a * inv;
00499 }
00500 inline __host__ __device__ float4 operator/(float s, float4 a)  //Danny
00501 {
00502 //  float inv = 1.0f / s;
00503 //  return a * inv;
00504   return make_float4(s / a.x, s / a.y, s / a.z, s / a.w);
00505 }
00506 inline __host__ __device__ void operator/=(float4 &a, float s)
00507 {
00508   float inv = 1.0f / s;
00509   a *= inv;
00510 }
00511 
00512 // lerp
00513 inline __device__ __host__ float4 lerp(float4 a, float4 b, float t)
00514 {
00515   return a + t*(b-a);
00516 }
00517 
00518 // clamp
00519 inline __device__ __host__ float4 clamp(float4 v, float a, float b)
00520 {
00521   return make_float4(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b), clamp(v.w, a, b));
00522 }
00523 
00524 inline __device__ __host__ float4 clamp(float4 v, float4 a, float4 b)
00525 {
00526   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));
00527 }
00528 
00529 // dot product
00530 inline __host__ __device__ float dot(float4 a, float4 b)
00531 {
00532   return a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w;
00533 }
00534 
00535 // length
00536 inline __host__ __device__ float length(float4 r)
00537 {
00538   return sqrtf(dot(r, r));
00539 }
00540 
00541 // normalize
00542 inline __host__ __device__ float4 normalize(float4 v)
00543 {
00544   float invLen = 1.0f / sqrtf(dot(v, v));
00545   return v * invLen;
00546 }
00547 
00548 // floor
00549 inline __host__ __device__ float4 floor(const float4 v)
00550 {
00551   return make_float4(floor(v.x), floor(v.y), floor(v.z), floor(v.w));
00552 }
00553 
00554 // int3 functions
00556 
00557 // additional constructors
00558 inline __host__ __device__ int3 make_int3(int s)
00559 {
00560   return make_int3(s, s, s);
00561 }
00562 inline __host__ __device__ int3 make_int3(float3 a)
00563 {
00564   return make_int3(int(a.x), int(a.y), int(a.z));
00565 }
00566 
00567 // min
00568 inline __host__ __device__ int3 min(int3 a, int3 b)
00569 {
00570   return make_int3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
00571 }
00572 
00573 // max
00574 inline __host__ __device__ int3 max(int3 a, int3 b)
00575 {
00576   return make_int3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
00577 }
00578 
00579 // addition
00580 inline __host__ __device__ int3 operator+(int3 a, int3 b)
00581 {
00582   return make_int3(a.x + b.x, a.y + b.y, a.z + b.z);
00583 }
00584 inline __host__ __device__ void operator+=(int3 &a, int3 b)
00585 {
00586   a.x += b.x; a.y += b.y; a.z += b.z;
00587 }
00588 
00589 // subtract
00590 inline __host__ __device__ int3 operator-(int3 a, int3 b)
00591 {
00592   return make_int3(a.x - b.x, a.y - b.y, a.z - b.z);
00593 }
00594 
00595 inline __host__ __device__ void operator-=(int3 &a, int3 b)
00596 {
00597   a.x -= b.x; a.y -= b.y; a.z -= b.z;
00598 }
00599 
00600 // multiply
00601 inline __host__ __device__ int3 operator*(int3 a, int3 b)
00602 {
00603   return make_int3(a.x * b.x, a.y * b.y, a.z * b.z);
00604 }
00605 inline __host__ __device__ int3 operator*(int3 a, int s)
00606 {
00607   return make_int3(a.x * s, a.y * s, a.z * s);
00608 }
00609 inline __host__ __device__ int3 operator*(int s, int3 a)
00610 {
00611   return make_int3(a.x * s, a.y * s, a.z * s);
00612 }
00613 inline __host__ __device__ void operator*=(int3 &a, int s)
00614 {
00615   a.x *= s; a.y *= s; a.z *= s;
00616 }
00617 
00618 // divide
00619 inline __host__ __device__ int3 operator/(int3 a, int3 b)
00620 {
00621   return make_int3(a.x / b.x, a.y / b.y, a.z / b.z);
00622 }
00623 inline __host__ __device__ int3 operator/(int3 a, int s)
00624 {
00625   return make_int3(a.x / s, a.y / s, a.z / s);
00626 }
00627 inline __host__ __device__ int3 operator/(int s, int3 a)
00628 {
00629   return make_int3(a.x / s, a.y / s, a.z / s);
00630 }
00631 inline __host__ __device__ void operator/=(int3 &a, int s)
00632 {
00633   a.x /= s; a.y /= s; a.z /= s;
00634 }
00635 
00636 // clamp
00637 inline __device__ __host__ int clamp(int f, int a, int b)
00638 {
00639   return max(a, min(f, b));
00640 }
00641 
00642 inline __device__ __host__ int3 clamp(int3 v, int a, int b)
00643 {
00644   return make_int3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
00645 }
00646 
00647 inline __device__ __host__ int3 clamp(int3 v, int3 a, int3 b)
00648 {
00649   return make_int3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
00650 }
00651 
00652 
00653 // uint3 functions
00655 
00656 // additional constructors
00657 inline __host__ __device__ uint3 make_uint3(uint s)
00658 {
00659   return make_uint3(s, s, s);
00660 }
00661 inline __host__ __device__ uint3 make_uint3(float3 a)
00662 {
00663   return make_uint3(uint(a.x), uint(a.y), uint(a.z));
00664 }
00665 
00666 // min
00667 inline __host__ __device__ uint3 min(uint3 a, uint3 b)
00668 {
00669   return make_uint3(min(a.x,b.x), min(a.y,b.y), min(a.z,b.z));
00670 }
00671 
00672 // max
00673 inline __host__ __device__ uint3 max(uint3 a, uint3 b)
00674 {
00675   return make_uint3(max(a.x,b.x), max(a.y,b.y), max(a.z,b.z));
00676 }
00677 
00678 // addition
00679 inline __host__ __device__ uint3 operator+(uint3 a, uint3 b)
00680 {
00681   return make_uint3(a.x + b.x, a.y + b.y, a.z + b.z);
00682 }
00683 inline __host__ __device__ void operator+=(uint3 &a, uint3 b)
00684 {
00685   a.x += b.x; a.y += b.y; a.z += b.z;
00686 }
00687 
00688 // subtract
00689 inline __host__ __device__ uint3 operator-(uint3 a, uint3 b)
00690 {
00691   return make_uint3(a.x - b.x, a.y - b.y, a.z - b.z);
00692 }
00693 
00694 inline __host__ __device__ void operator-=(uint3 &a, uint3 b)
00695 {
00696   a.x -= b.x; a.y -= b.y; a.z -= b.z;
00697 }
00698 
00699 // multiply
00700 inline __host__ __device__ uint3 operator*(uint3 a, uint3 b)
00701 {
00702   return make_uint3(a.x * b.x, a.y * b.y, a.z * b.z);
00703 }
00704 inline __host__ __device__ uint3 operator*(uint3 a, uint s)
00705 {
00706   return make_uint3(a.x * s, a.y * s, a.z * s);
00707 }
00708 inline __host__ __device__ uint3 operator*(uint s, uint3 a)
00709 {
00710   return make_uint3(a.x * s, a.y * s, a.z * s);
00711 }
00712 inline __host__ __device__ void operator*=(uint3 &a, uint s)
00713 {
00714   a.x *= s; a.y *= s; a.z *= s;
00715 }
00716 
00717 // divide
00718 inline __host__ __device__ uint3 operator/(uint3 a, uint3 b)
00719 {
00720   return make_uint3(a.x / b.x, a.y / b.y, a.z / b.z);
00721 }
00722 inline __host__ __device__ uint3 operator/(uint3 a, uint s)
00723 {
00724   return make_uint3(a.x / s, a.y / s, a.z / s);
00725 }
00726 inline __host__ __device__ uint3 operator/(uint s, uint3 a)
00727 {
00728   return make_uint3(a.x / s, a.y / s, a.z / s);
00729 }
00730 inline __host__ __device__ void operator/=(uint3 &a, uint s)
00731 {
00732   a.x /= s; a.y /= s; a.z /= s;
00733 }
00734 
00735 // clamp
00736 inline __device__ __host__ uint clamp(uint f, uint a, uint b)
00737 {
00738   return max(a, min(f, b));
00739 }
00740 
00741 inline __device__ __host__ uint3 clamp(uint3 v, uint a, uint b)
00742 {
00743   return make_uint3(clamp(v.x, a, b), clamp(v.y, a, b), clamp(v.z, a, b));
00744 }
00745 
00746 inline __device__ __host__ uint3 clamp(uint3 v, uint3 a, uint3 b)
00747 {
00748   return make_uint3(clamp(v.x, a.x, b.x), clamp(v.y, a.y, b.y), clamp(v.z, a.z, b.z));
00749 }
00750 
00751 #endif


Generated on 11-05-2012 for elastix by doxygen 1.7.6.1 elastix logo