00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _SB_VEC_
00024 #define _SB_VEC_
00025
00026 #include <Inventor/SbBase.h>
00027 #include <Inventor/SbMathHelper.h>
00028 #include <Inventor/STL/iostream>
00029 #include <string.h>
00030
00031 class SbVec2d;
00032 class SbVec3d;
00033 class SbVec3s;
00034 class SbVec4d;
00035 class SbPlane;
00036
00038
00039
00040
00041
00042
00043
00045
00076 class SbVec2f {
00077 public:
00078
00082 SbVec2f() { memset(vec, 0, sizeof(vec)); }
00083
00087 explicit SbVec2f(const float v[2]) { setValue(v); }
00088
00092 SbVec2f(float x, float y) { setValue(x, y); }
00093
00097 SbVec2f(float val) { setValue(val,val); }
00098
00102 inline float dot(const SbVec2f &v) const
00103 { return vec[0] * v.vec[0] + vec[1] * v.vec[1]; }
00104
00108 const float *getValue() const { return vec; }
00109
00113 void getValue(float &x, float &y) const;
00114
00118 float length() const;
00119
00124 inline float lengthSquared() const
00125 { return vec[0] * vec[0] + vec[1] * vec[1]; }
00126
00130 void negate();
00131
00135 float normalize();
00136
00140 SbVec2f &setValue(const float v[2]);
00141
00145 SbVec2f &setValue(float x, float y);
00146
00159 SbVec2f &setValue(const SbVec2d &vec2d);
00160
00162
00165 float & operator [](int i) { return (vec[i]); }
00166 const float & operator [](int i) const { return (vec[i]); }
00168
00172 SbVec2f & operator *=(float d);
00173
00177 inline SbVec2f operator *(const SbVec2f &v) const
00178 {
00179 return SbVec2f(vec[0]*v.vec[0],
00180 vec[1]*v.vec[1]);
00181 }
00182
00186 inline SbVec2f& operator *=(const SbVec2f &v)
00187 {
00188 *this = (*this)*v;
00189 return *this;
00190 }
00191
00195 SbVec2f & operator /=(float d);
00196
00200 SbVec2f & operator +=(const SbVec2f &u);
00204 SbVec2f & operator -=(const SbVec2f &u);
00205
00209 SbVec2f operator -() const;
00210
00214 friend SbVec2f operator *(const SbVec2f &v, float d);
00218 friend SbVec2f operator *(float d, const SbVec2f &v)
00219 { return v * d; }
00223 friend SbVec2f operator /(const SbVec2f &v, float d);
00224
00228 friend SbVec2f operator +(const SbVec2f &v1, const SbVec2f &v2);
00229
00233 friend SbVec2f operator -(const SbVec2f &v1, const SbVec2f &v2);
00234
00238 friend int operator ==(const SbVec2f &v1, const SbVec2f &v2);
00242 friend int operator !=(const SbVec2f &v1, const SbVec2f &v2)
00243 { return !(v1 == v2); }
00244
00248 friend inline std::ostream& operator << (std::ostream& os, const SbVec2f& v);
00249
00254 SbBool equals(const SbVec2f& v, float tolerance) const;
00255
00259 template<typename T>
00260 explicit SbVec2f(const T& v)
00261 {
00262
00263 vec[0] = float(v[0]);
00264 vec[1] = float(v[1]);
00265 }
00266
00267 private:
00268 float vec[2];
00269
00270 };
00271
00273
00274
00275
00276
00277
00278
00280
00314 class SbVec2d {
00315 public:
00316
00320 SbVec2d() { memset(vec, 0, sizeof(vec)); }
00321
00325 explicit SbVec2d(const double v[2]) { setValue(v); }
00326
00330 SbVec2d(double x, double y) { setValue(x, y); }
00331
00335 inline double dot(const SbVec2d &v) const
00336 { return vec[0] * v.vec[0] + vec[1] * v.vec[1]; }
00337
00341 const double *getValue() const { return vec; }
00342
00346 void getValue(double &x, double &y) const;
00347
00351 double length() const;
00352
00357 inline double lengthSquared() const
00358 { return vec[0] * vec[0] + vec[1] * vec[1]; }
00359
00363 void negate();
00364
00368 double normalize();
00369
00373 SbVec2d &setValue(const double v[2]);
00374
00378 SbVec2d &setValue(double x, double y);
00379
00383 SbVec2d &setValue(const SbVec2f &vec2f)
00384 { vec[0] = vec2f[0] ; vec[1] = vec2f[1] ; return (*this) ; }
00385
00387
00390 double & operator [](int i) { return (vec[i]); }
00391 const double & operator [](int i) const { return (vec[i]); }
00393
00397 SbVec2d & operator *=(double d);
00398
00402 SbVec2d & operator /=(double d);
00403
00407 SbVec2d & operator +=(const SbVec2d &u);
00411 SbVec2d & operator -=(const SbVec2d &u);
00412
00416 SbVec2d operator -() const;
00417
00421 friend SbVec2d operator *(const SbVec2d &v, double d);
00425 friend SbVec2d operator *(double d, const SbVec2d &v)
00426 { return v * d; }
00430 friend SbVec2d operator /(const SbVec2d &v, double d);
00431
00435 friend SbVec2d operator +(const SbVec2d &v1, const SbVec2d &v2);
00436
00440 friend SbVec2d operator -(const SbVec2d &v1, const SbVec2d &v2);
00441
00445 friend int operator ==(const SbVec2d &v1, const SbVec2d &v2);
00449 friend int operator !=(const SbVec2d &v1, const SbVec2d &v2)
00450 { return !(v1 == v2); }
00451
00456 SbBool equals(const SbVec2d& v, double tolerance) const;
00457
00461 friend inline std::ostream& operator << (std::ostream& os, const SbVec2d& v);
00462
00466 template<typename T>
00467 explicit SbVec2d(const T& v)
00468 {
00469
00470 vec[0] = double(v[0]);
00471 vec[1] = double(v[1]);
00472 }
00473
00474 private:
00475 double vec[2];
00476
00477 };
00478
00480
00481
00482
00483
00484
00485
00487
00517 class SbVec2i32 {
00518 public:
00522 SbVec2i32() { memset(vec, 0, sizeof(vec)); }
00526 explicit SbVec2i32(const int32_t v[2]) { setValue(v); }
00530 SbVec2i32(int32_t x, int32_t y) { setValue(x, y); }
00534 inline int32_t dot(const SbVec2i32 &v) const
00535 { return vec[0] * v.vec[0] + vec[1] * v.vec[1]; }
00539 const int32_t *getValue() const { return vec; }
00543 void getValue(int32_t &x, int32_t &y) const;
00547 void negate();
00551 SbVec2i32 &setValue(const int32_t v[2]);
00555 SbVec2i32 &setValue(int32_t x, int32_t y);
00559 int32_t & operator [](int i) { return (vec[i]); }
00563 const int32_t & operator [](int i) const { return (vec[i]); }
00567 SbVec2i32 & operator *=(int d);
00571 SbVec2i32 & operator *=(double d);
00572
00576 SbVec2i32 & operator /=(int d);
00580 SbVec2i32 & operator /=(double d)
00581 { return *this *= (1.0 / d); }
00585 SbVec2i32 & operator +=(const SbVec2i32 &u);
00589 SbVec2i32 & operator -=(const SbVec2i32 &u);
00593 SbVec2i32 operator -() const;
00597 friend SbVec2i32 operator *(const SbVec2i32 &v, int d);
00601 friend SbVec2i32 operator *(const SbVec2i32 &v, double d);
00605 friend SbVec2i32 operator *(int d, const SbVec2i32 &v)
00606 { return v * d; }
00610 friend SbVec2i32 operator *(double d, const SbVec2i32 &v)
00611 { return v * d; }
00615 friend SbVec2i32 operator /(const SbVec2i32 &v, int d);
00619 friend SbVec2i32 operator /(const SbVec2i32 &v, double d)
00620 { return v * (1.0 / d); }
00624 friend SbVec2i32 operator +(const SbVec2i32 &v1, const SbVec2i32 &v2);
00628 friend SbVec2i32 operator -(const SbVec2i32 &v1, const SbVec2i32 &v2);
00632 friend int operator ==(const SbVec2i32 &v1, const SbVec2i32 &v2);
00636 friend int operator !=(const SbVec2i32 &v1, const SbVec2i32 &v2)
00637 { return !(v1 == v2); }
00638
00642 friend inline std::ostream& operator << (std::ostream& os, const SbVec2i32& v);
00643
00647 template<typename T>
00648 explicit SbVec2i32(const T& v)
00649 {
00650
00651 vec[0] = int32_t(v[0]);
00652 vec[1] = int32_t(v[1]);
00653 }
00654
00655
00656
00657 private:
00658 int32_t vec[2];
00659 };
00660
00662
00663
00664
00665
00666
00667
00669
00700 class SbVec2s {
00701 public:
00702
00706 SbVec2s() { memset(vec, 0, sizeof(vec)); }
00707
00711 explicit SbVec2s(const short v[2]) { setValue(v); }
00712
00716 SbVec2s(short x, short y) { setValue(x, y); }
00717
00721 #ifndef OIV_DO_NOT_ALLOW_I32_TO_I16_AUTO_CAST
00722 explicit SbVec2s(const SbVec2i32 &v);
00723 #endif
00724
00728 inline int32_t dot(const SbVec2s &v) const
00729 { return vec[0] * v.vec[0] + vec[1] * v.vec[1]; }
00730
00734 const short *getValue() const { return vec; }
00735
00739 void getValue(short &x, short &y) const;
00740
00744 void negate();
00745
00749 SbVec2s &setValue(const short v[2]);
00750
00754 SbVec2s &setValue(short x, short y);
00755
00757
00760 short & operator [](int i) { return (vec[i]); }
00761 const short & operator [](int i) const { return (vec[i]); }
00763
00767 SbVec2s & operator *=(int d);
00771 SbVec2s & operator *=(double d);
00772
00776 SbVec2s & operator /=(int d);
00780 SbVec2s & operator /=(double d)
00781 { return *this *= (1.0 / d); }
00782
00786 SbVec2s & operator +=(const SbVec2s &u);
00790 SbVec2s & operator -=(const SbVec2s &u);
00791
00795 SbVec2s operator -() const;
00796
00800 #ifndef OIV_DO_NOT_ALLOW_I32_TO_I16_AUTO_CAST
00801 SbVec2s operator = (const SbVec2i32 &v);
00802 #endif
00803
00807 friend SbVec2s operator *(const SbVec2s &v, int d);
00811 friend SbVec2s operator *(const SbVec2s &v, double d);
00815 friend SbVec2s operator *(int d, const SbVec2s &v)
00816 { return v * d; }
00820 friend SbVec2s operator *(double d, const SbVec2s &v)
00821 { return v * d; }
00825 friend SbVec2s operator /(const SbVec2s &v, int d);
00829 friend SbVec2s operator /(const SbVec2s &v, double d)
00830 { return v * (1.0 / d); }
00831
00835 friend SbVec2s operator +(const SbVec2s &v1, const SbVec2s &v2);
00836
00840 friend SbVec2s operator -(const SbVec2s &v1, const SbVec2s &v2);
00841
00845 friend int operator ==(const SbVec2s &v1, const SbVec2s &v2);
00849 friend int operator !=(const SbVec2s &v1, const SbVec2s &v2)
00850 { return !(v1 == v2); }
00851
00855 friend inline std::ostream& operator << (std::ostream& os, const SbVec2s& v);
00856
00860 template<typename T>
00861 explicit SbVec2s(const T& v)
00862 {
00863
00864 vec[0] = short(v[0]);
00865 vec[1] = short(v[1]);
00866 }
00867
00868 private:
00869 short vec[2];
00870
00871 };
00872
00874
00875
00876
00877
00878
00879
00880
00881
00882
00883
00884
00885
00886
00887
00888
00889
00890
00892
00932 class SbVec3f {
00933 public:
00937 SbVec3f() { memset(vec, 0, sizeof(vec)); }
00938
00942 explicit SbVec3f(const float v[3])
00943 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
00944
00948 SbVec3f(float x, float y, float z)
00949 { vec[0] = x; vec[1] = y; vec[2] = z; }
00950
00954 SbVec3f(SbPlane &p0, SbPlane &p1, SbPlane &p2);
00955
00959 inline SbVec3f cross(const SbVec3f &v) const
00960 {
00961 return SbVec3f(
00962 vec[1] * v.vec[2] - vec[2] * v.vec[1],
00963 vec[2] * v.vec[0] - vec[0] * v.vec[2],
00964 vec[0] * v.vec[1] - vec[1] * v.vec[0]
00965 );
00966 }
00967
00971 float dot(const SbVec3f &v) const
00972 { return (vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2]); }
00973
00977 inline const float *getValue() const
00978 { return vec; }
00979
00983 void getValue(float &x, float &y, float &z) const;
00984
00988 float length() const;
00989
00994 inline float lengthSquared() const
00995 { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]; }
00996
01000 float normalize();
01001
01005 void negate();
01006
01010 inline SbVec3f &setValue(const float v[3])
01011 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
01012
01016 inline SbVec3f &setValue(float x, float y, float z)
01017 { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
01018
01022 SbVec3f &setValue(const SbVec3f &barycentic, const SbVec3f &v0, const SbVec3f &v1, const SbVec3f &v2);
01023
01027 SbVec3f &setValue(const SbVec3d &vec3d);
01028
01030
01033 float & operator [](int i) { return (vec[i]); }
01034 const float & operator [](int i) const { return (vec[i]); }
01036
01040 SbVec3f & operator *=(float d);
01041
01045 SbVec3f & operator /=(float d);
01046
01050 inline SbVec3f & operator +=(const SbVec3f &v)
01051 {
01052 vec[0] += v.vec[0];
01053 vec[1] += v.vec[1];
01054 vec[2] += v.vec[2];
01055
01056 return *this;
01057 }
01058
01062 SbVec3f & operator -=(const SbVec3f &v);
01063
01067 inline SbVec3f operator -() const
01068 { return SbVec3f(-vec[0], -vec[1], -vec[2]); }
01069
01073 inline SbVec3f operator *(const SbVec3f &v) const
01074 { return SbVec3f(vec[0]*v.vec[0], vec[1]*v.vec[1], vec[2]*v.vec[2]); }
01075
01079 inline SbVec3f& operator *=(const SbVec3f &v)
01080 {
01081 *this = (*this)*v;
01082 return *this;
01083 }
01084
01088 friend inline SbVec3f operator *(const SbVec3f &v, float d)
01089 { return SbVec3f(v.vec[0] * d, v.vec[1] * d, v.vec[2] * d); }
01090
01094 friend inline SbVec3f operator *(float d, const SbVec3f &v)
01095 { return v * d; }
01096
01100 friend inline SbVec3f operator /(const SbVec3f &v, float d)
01101 { return SbVec3f(v.vec[0] / d, v.vec[1] / d, v.vec[2] / d); }
01102
01106 friend inline SbVec3f operator +(const SbVec3f &v1, const SbVec3f &v2)
01107 { return SbVec3f(v1.vec[0] + v2.vec[0], v1.vec[1] + v2.vec[1], v1.vec[2] + v2.vec[2]); }
01108
01112 friend inline SbVec3f operator -(const SbVec3f &v1, const SbVec3f &v2)
01113 { return SbVec3f(v1.vec[0] - v2.vec[0], v1.vec[1] - v2.vec[1], v1.vec[2] - v2.vec[2]); }
01114
01118 friend inline int operator ==(const SbVec3f &v1, const SbVec3f &v2)
01119 { return (v1.vec[0] == v2.vec[0] && v1.vec[1] == v2.vec[1] && v1.vec[2] == v2.vec[2]); }
01120
01124 friend inline int operator !=(const SbVec3f &v1, const SbVec3f &v2)
01125 { return !(v1 == v2); }
01126
01130 friend inline std::ostream& operator << (std::ostream& os, const SbVec3f& v);
01131
01136 SbBool equals(const SbVec3f& v, float tolerance) const;
01137
01142 SbVec3f getClosestAxis() const;
01143
01147 template<typename T>
01148 explicit SbVec3f(const T& v)
01149 {
01150
01151 vec[0] = float(v[0]);
01152 vec[1] = float(v[1]);
01153 vec[2] = float(v[2]);
01154 }
01155
01156 private:
01157 float vec[3];
01158
01159 };
01160
01162
01163
01164
01165
01166
01167
01168
01169
01170
01171
01172
01173
01174
01175
01176
01177
01178
01180
01214 class SbVec3d {
01215 public:
01219 SbVec3d() { memset(vec, 0, sizeof(vec)); }
01220
01224 explicit SbVec3d(const double v[3])
01225 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; }
01226
01230 inline SbVec3d(double x, double y, double z)
01231 { vec[0] = x; vec[1] = y; vec[2] = z; }
01232
01236 SbVec3d(SbPlane &p0, SbPlane &p1, SbPlane &p2);
01237
01241 inline SbVec3d cross(const SbVec3d &v) const
01242 {
01243 return SbVec3d(
01244 vec[1] * v.vec[2] - vec[2] * v.vec[1],
01245 vec[2] * v.vec[0] - vec[0] * v.vec[2],
01246 vec[0] * v.vec[1] - vec[1] * v.vec[0]
01247 );
01248 }
01249
01253 inline double dot(const SbVec3d &v) const
01254 { return (vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2]); }
01255
01259 inline const double *getValue() const
01260 { return vec; }
01261
01265 void getValue(double &x, double &y, double &z) const;
01266
01270 double length() const;
01271
01276 inline double lengthSquared() const
01277 { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2]; }
01278
01282 double normalize();
01283
01287 void negate();
01288
01292 SbVec3d &setValue(const double v[3])
01293 { vec[0] = v[0]; vec[1] = v[1]; vec[2] = v[2]; return *this; }
01294
01298 SbVec3d &setValue(double x, double y, double z)
01299 { vec[0] = x; vec[1] = y; vec[2] = z; return *this; }
01300
01304 SbVec3d &setValue(const SbVec3d &barycentic,
01305 const SbVec3d &v0,
01306 const SbVec3d &v1,
01307 const SbVec3d &v2);
01308
01312 inline SbVec3d &setValue(const SbVec3f &vec3f)
01313 { vec[0] = vec3f[0] ; vec[1] = vec3f[1] ; vec[2] = vec3f[2] ; return (*this) ; }
01314
01316
01319 double & operator [](int i) { return (vec[i]); }
01320 const double & operator [](int i) const { return (vec[i]); }
01322
01326 inline SbVec3d & operator *=(double d)
01327 {
01328 vec[0] *= d;
01329 vec[1] *= d;
01330 vec[2] *= d;
01331
01332 return *this;
01333 }
01334
01338 inline SbVec3d & operator /=(double d)
01339 {
01340 vec[0] /= d;
01341 vec[1] /= d;
01342 vec[2] /= d;
01343
01344 return *this;
01345 }
01346
01350 inline SbVec3d & operator +=(const SbVec3d &v)
01351 {
01352 vec[0] += v.vec[0];
01353 vec[1] += v.vec[1];
01354 vec[2] += v.vec[2];
01355
01356 return *this;
01357 }
01358
01362 inline SbVec3d & operator -=(const SbVec3d &v)
01363 {
01364 vec[0] -= v.vec[0];
01365 vec[1] -= v.vec[1];
01366 vec[2] -= v.vec[2];
01367
01368 return *this;
01369 }
01370
01371
01375 inline SbVec3d operator -() const
01376 { return SbVec3d(-vec[0], -vec[1], -vec[2]); }
01377
01381 inline SbVec3d operator *(const SbVec3d &v) const
01382 { return SbVec3d(vec[0]*v.vec[0], vec[1]*v.vec[1], vec[2]*v.vec[2]); }
01383
01387 inline SbVec3d& operator *=(const SbVec3d &v)
01388 {
01389 *this = (*this)*v;
01390 return *this;
01391 }
01392
01396 friend inline SbVec3d operator *(const SbVec3d &v, double d)
01397 { return SbVec3d(v.vec[0] * d, v.vec[1] * d, v.vec[2] * d); }
01398
01402 friend inline SbVec3d operator *(double d, const SbVec3d &v)
01403 { return v * d; }
01404
01408 friend inline SbVec3d operator /(const SbVec3d &v, double d)
01409 { return SbVec3d(v.vec[0] / d, v.vec[1] / d, v.vec[2] / d); }
01410
01414 friend inline SbVec3d operator +(const SbVec3d &v1, const SbVec3d &v2)
01415 { return SbVec3d(v1.vec[0] + v2.vec[0], v1.vec[1] + v2.vec[1], v1.vec[2] + v2.vec[2]); }
01416
01420 friend inline SbVec3d operator -(const SbVec3d &v1, const SbVec3d &v2)
01421 { return SbVec3d(v1.vec[0] - v2.vec[0], v1.vec[1] - v2.vec[1], v1.vec[2] - v2.vec[2]); }
01422
01426 friend inline int operator ==(const SbVec3d &v1, const SbVec3d &v2)
01427 { return (v1.vec[0] == v2.vec[0] && v1.vec[1] == v2.vec[1] && v1.vec[2] == v2.vec[2]); }
01428
01432 friend int operator !=(const SbVec3d &v1, const SbVec3d &v2)
01433 { return !(v1 == v2); }
01434
01439 SbBool equals(const SbVec3d& v, double tolerance) const;
01440
01444 friend inline std::ostream& operator << (std::ostream& os, const SbVec3d& v);
01445
01450 SbVec3d getClosestAxis() const;
01451
01455 template<typename T>
01456 explicit SbVec3d(const T& v)
01457 {
01458
01459 vec[0] = double(v[0]);
01460 vec[1] = double(v[1]);
01461 vec[2] = double(v[2]);
01462 }
01463
01464 private:
01465 double vec[3];
01466
01467 };
01468
01469
01470
01471 inline SbVec3f &SbVec3f::setValue(const SbVec3d &vec3d)
01472 {
01473 vec[0] = static_cast<float>(vec3d[0]);
01474 vec[1] = static_cast<float>(vec3d[1]);
01475 vec[2] = static_cast<float>(vec3d[2]);
01476 return (*this);
01477 }
01478
01480
01481
01482
01483
01484
01485
01487
01517 class SbVec3i32 {
01518 public:
01522 SbVec3i32() { memset(vec, 0, sizeof(vec)); }
01526 explicit SbVec3i32(const int32_t v[3]) { setValue(v); }
01530 SbVec3i32(int32_t x, int32_t y, int32_t z) { setValue(x, y, z); }
01534 SbVec3i32( const SbVec3s &vec );
01538 inline int32_t dot(const SbVec3i32 &v) const
01539 {
01540 return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2];
01541 }
01542
01546 const int32_t *getValue() const { return vec; }
01550 void getValue(int32_t &x, int32_t &y, int32_t &z) const;
01554 void negate();
01558 inline SbVec3i32 &setValue(const int32_t v[3])
01559 {
01560 vec[0] = v[0];
01561 vec[1] = v[1];
01562 vec[2] = v[2];
01563
01564 return (*this);
01565 }
01566
01570 inline SbVec3i32 &setValue(int32_t x, int32_t y, int32_t z)
01571 {
01572 vec[0] = x;
01573 vec[1] = y;
01574 vec[2] = z;
01575
01576 return (*this);
01577 }
01578
01582 SbVec3i32 &setValue(const SbVec3s &v);
01586 SbVec3i32 operator = (const SbVec3s &v);
01590 int32_t & operator [](int i) { return (vec[i]); }
01594 const int32_t & operator [](int i) const { return (vec[i]); }
01598 SbVec3i32 & operator *=(int d);
01602 SbVec3i32 & operator *=(double d);
01603
01607 SbVec3i32 & operator /=(int d);
01611 SbVec3i32 & operator /=(double d)
01612 { return *this *= (1.0 / d); }
01616 inline SbVec3i32 & operator +=(const SbVec3i32 &u)
01617 {
01618 vec[0] += u.vec[0];
01619 vec[1] += u.vec[1];
01620 vec[2] += u.vec[2];
01621
01622 return *this;
01623 }
01627 inline SbVec3i32 & operator /=(const SbVec3i32 &u)
01628 {
01629 vec[0] /= u.vec[0];
01630 vec[1] /= u.vec[1];
01631 vec[2] /= u.vec[2];
01632
01633 return *this;
01634 }
01638 SbVec3i32 & operator -=(const SbVec3i32 &u);
01642 SbVec3i32 operator -() const;
01646 inline SbVec3i32 operator *(int d) const
01647 {
01648 return SbVec3i32(vec[0] * d, vec[1] * d, vec[2] * d);
01649 }
01650
01654 inline SbVec3i32 operator *(const SbVec3i32 &v) const
01655 {
01656 return SbVec3i32(vec[0]*v.vec[0],
01657 vec[1]*v.vec[1],
01658 vec[2]*v.vec[2]);
01659 }
01660
01664 inline SbVec3i32& operator *=(const SbVec3i32 &v)
01665 {
01666 *this = (*this)*v;
01667 return *this;
01668 }
01669
01673 friend SbVec3i32 operator *(const SbVec3i32 &v, double d);
01677 friend SbVec3i32 operator *(int d, const SbVec3i32 &v)
01678 { return v * d; }
01682 friend SbVec3i32 operator *(double d, const SbVec3i32 &v)
01683 { return v * d; }
01687 friend SbVec3i32 operator /(const SbVec3i32 &v, int d);
01691 friend SbVec3i32 operator /(const SbVec3i32 &v, double d)
01692 { return v * (1.0 / d); }
01696 inline SbVec3i32 operator +(const SbVec3i32 &v) const
01697 {
01698 return SbVec3i32(vec[0] + v.vec[0],
01699 vec[1] + v.vec[1],
01700 vec[2] + v.vec[2]);
01701 }
01702
01707 friend SbVec3i32 operator -(const SbVec3i32 &v1, const SbVec3i32 &v2)
01708 {
01709 return SbVec3i32(v1.vec[0] - v2.vec[0],
01710 v1.vec[1] - v2.vec[1],
01711 v1.vec[2] - v2.vec[2]);
01712 }
01713
01717 friend int operator ==(const SbVec3i32 &v1, const SbVec3i32 &v2);
01721 friend int operator !=(const SbVec3i32 &v1, const SbVec3i32 &v2)
01722 { return !(v1 == v2); }
01723
01727 friend inline std::ostream& operator << (std::ostream& os, const SbVec3i32& v);
01728
01732 template<typename T>
01733 explicit SbVec3i32(const T& v)
01734 {
01735
01736 vec[0] = int32_t(v[0]);
01737 vec[1] = int32_t(v[1]);
01738 vec[2] = int32_t(v[2]);
01739 }
01740
01744 inline int32_t getMaxComponent() const;
01745
01746 private:
01747 int32_t vec[3];
01748 };
01749
01750 int32_t
01751 SbVec3i32::getMaxComponent() const
01752 {
01753 return SbMathHelper::Max(SbMathHelper::Max(vec[0], vec[1]), vec[2]);
01754 }
01755
01757
01758
01759
01760
01761
01762
01764
01765
01766
01797 class SbVec3s {
01798 public:
01799
01803 SbVec3s() { memset(vec, 0, sizeof(vec)); }
01804
01808 explicit SbVec3s(const short v[3]) { setValue(v); }
01809
01813 SbVec3s(short x, short y, short z) { setValue(x, y, z); }
01814
01819 #ifndef OIV_DO_NOT_ALLOW_I32_TO_I16_AUTO_CAST
01820 SbVec3s(const SbVec3i32 &v);
01821 #endif
01822
01826 inline int32_t dot(const SbVec3s &v) const
01827 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2]; }
01828
01832 const short *getValue() const { return vec; }
01833
01837 void getValue(short &x, short &y, short &z) const;
01838
01842 void negate();
01843
01847 SbVec3s &setValue(const short v[3]);
01848
01852 SbVec3s &setValue(short x, short y, short z);
01853
01855
01858 short & operator [](int i) { return (vec[i]); }
01859 const short & operator [](int i) const { return (vec[i]); }
01861
01865 SbVec3s & operator *=(int d);
01869 SbVec3s & operator *=(double d);
01870
01874 SbVec3s & operator /=(int d);
01878 SbVec3s & operator /=(double d)
01879 { return *this *= (1.0 / d); }
01880
01884 SbVec3s & operator +=(const SbVec3s &u);
01888 SbVec3s & operator -=(const SbVec3s &u);
01889
01893 SbVec3s operator -() const;
01894
01899 #ifndef OIV_DO_NOT_ALLOW_I32_TO_I16_AUTO_CAST
01900 SbVec3s operator = (const SbVec3i32 &v);
01901 #endif
01902
01906 friend SbVec3s operator *(const SbVec3s &v, int d);
01910 friend SbVec3s operator *(const SbVec3s &v, double d);
01914 friend SbVec3s operator *(int d, const SbVec3s &v)
01915 { return v * d; }
01919 friend SbVec3s operator *(double d, const SbVec3s &v)
01920 { return v * d; }
01924 friend SbVec3s operator /(const SbVec3s &v, int d);
01928 friend SbVec3s operator /(const SbVec3s &v, double d)
01929 { return v * (1.0 / d); }
01930
01934 friend SbVec3s operator +(const SbVec3s &v1, const SbVec3s &v2);
01935
01939 friend SbVec3s operator -(const SbVec3s &v1, const SbVec3s &v2);
01940
01944 friend int operator ==(const SbVec3s &v1, const SbVec3s &v2);
01948 friend int operator !=(const SbVec3s &v1, const SbVec3s &v2)
01949 { return !(v1 == v2); }
01950
01954 friend inline std::ostream& operator << (std::ostream& os, const SbVec3s& v);
01955
01959 template<typename T>
01960 explicit SbVec3s(const T& v)
01961 {
01962
01963 vec[0] = short(v[0]);
01964 vec[1] = short(v[1]);
01965 vec[2] = short(v[2]);
01966 }
01967
01968
01969 private:
01970 short vec[3];
01971
01972 };
01973
01975
01976
01977
01978
01979
01981
01982
01983
02014 class SbVec4b {
02015 public:
02016
02020 SbVec4b() { memset(vec, 0, sizeof(vec)); }
02021
02025 explicit SbVec4b(const char v[4]) { setValue(v); }
02026
02030 SbVec4b(char x, char y, char z, char w) { setValue(x, y, z, w); }
02031
02035 inline int32_t dot(const SbVec4b &v) const
02036 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3]; }
02037
02042 const char *getValue() const { return vec; }
02043
02047 void getValue(char &x, char &y, char &z, char &w) const;
02048
02052 void negate();
02053
02057 SbVec4b &setValue(const char v[4]);
02058
02062 SbVec4b &setValue(char x, char y, char z, char w);
02063
02065
02068 char & operator [](int i) { return (vec[i]); }
02069 const char & operator [](int i) const { return (vec[i]); }
02071
02075 SbVec4b & operator *=(int d);
02079 SbVec4b & operator *=(double d);
02080
02084 SbVec4b & operator /=(int d);
02088 SbVec4b & operator /=(double d)
02089 { return *this *= (1.0 / d); }
02090
02094 SbVec4b & operator +=(const SbVec4b &u);
02098 SbVec4b & operator -=(const SbVec4b &u);
02099
02103 SbVec4b operator -() const;
02104
02108 friend SbVec4b operator *(const SbVec4b &v, int d);
02112 friend SbVec4b operator *(const SbVec4b &v, double d);
02116 friend SbVec4b operator *(int d, const SbVec4b &v)
02117 { return v * d; }
02121 friend SbVec4b operator *(double d, const SbVec4b &v)
02122 { return v * d; }
02126 friend SbVec4b operator /(const SbVec4b &v, int d);
02130 friend SbVec4b operator /(const SbVec4b &v, double d)
02131 { return v * (1.0 / d); }
02132
02136 friend SbVec4b operator +(const SbVec4b &v1, const SbVec4b &v2);
02137
02141 friend SbVec4b operator -(const SbVec4b &v1, const SbVec4b &v2);
02142
02146 friend int operator ==(const SbVec4b &v1, const SbVec4b &v2);
02150 friend int operator !=(const SbVec4b &v1, const SbVec4b &v2)
02151 { return !(v1 == v2); }
02152
02156 friend inline std::ostream& operator << (std::ostream& os, const SbVec4b& v);
02157
02161 template<typename T>
02162 explicit SbVec4b(const T& v)
02163 {
02164
02165 vec[0] = char(v[0]);
02166 vec[1] = char(v[1]);
02167 vec[2] = char(v[2]);
02168 vec[3] = char(v[3]);
02169 }
02170 private:
02171 char vec[4];
02172
02173 };
02174
02176
02177
02178
02179
02180
02181
02183
02214 class SbVec4f {
02215 public:
02216
02220 SbVec4f() { memset(vec, 0, sizeof(vec)); }
02221
02225 explicit SbVec4f(const float v[4]) { setValue(v); }
02226
02230 SbVec4f(float x, float y, float z, float w) { setValue(x, y, z, w); }
02231
02235 inline float dot(const SbVec4f &v) const
02236 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3] ; }
02237
02241 void getReal(SbVec3f &v) const;
02242
02246 const float *getValue() const { return vec; }
02247
02251 void getValue(float &x, float &y, float &z, float &w) const;
02252
02256 float length() const;
02257
02262 inline float lengthSquared() const
02263 { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]; }
02264
02268 void negate();
02269
02273 float normalize();
02274
02278 SbVec4f &setValue(const float v[4]);
02279
02283 SbVec4f &setValue(float x, float y, float z, float w);
02284
02288 SbVec4f &setValue(const SbVec4d &vec4d);
02289
02291
02294 float & operator [](int i) { return (vec[i]); }
02295 const float & operator [](int i) const { return (vec[i]); }
02297
02301 SbVec4f & operator *=(float d);
02302
02306 SbVec4f & operator /=(float d);
02307
02311 SbVec4f & operator +=(const SbVec4f &u);
02315 SbVec4f & operator -=(const SbVec4f &u);
02316
02320 SbVec4f operator -() const;
02321
02325 friend SbVec4f operator *(const SbVec4f &v, float d);
02329 friend SbVec4f operator *(float d, const SbVec4f &v)
02330 { return v * d; }
02334 friend SbVec4f operator /(const SbVec4f &v, float d);
02335
02339 friend SbVec4f operator +(const SbVec4f &v1, const SbVec4f &v2);
02340
02344 friend SbVec4f operator -(const SbVec4f &v1, const SbVec4f &v2);
02345
02349 friend int operator ==(const SbVec4f &v1, const SbVec4f &v2);
02353 friend int operator !=(const SbVec4f &v1, const SbVec4f &v2)
02354 { return !(v1 == v2); }
02355
02359 friend inline std::ostream& operator << (std::ostream& os, const SbVec4f& v);
02360
02365 SbBool equals(const SbVec4f& v, float tolerance) const;
02366
02370 template<typename T>
02371 explicit SbVec4f(const T& v)
02372 {
02373
02374 vec[0] = float(v[0]);
02375 vec[1] = float(v[1]);
02376 vec[2] = float(v[2]);
02377 vec[3] = float(v[3]);
02378 }
02379
02380 private:
02381 float vec[4];
02382
02383 };
02384
02386
02387
02388
02389
02390
02391
02393
02427 class SbVec4d {
02428 public:
02429
02433 SbVec4d() { memset(vec, 0, sizeof(vec)); }
02434
02438 explicit SbVec4d(const double v[4]) { setValue(v); }
02439
02443 SbVec4d(double x, double y, double z, double w) { setValue(x, y, z, w); }
02444
02448 inline double dot(const SbVec4d &v) const
02449 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3] ; }
02450
02454 void getReal(SbVec3d &v) const;
02455
02459 const double *getValue() const { return vec; }
02460
02464 void getValue(double &x, double &y, double &z, double &w) const;
02465
02469 double length() const;
02470
02475 inline double lengthSquared() const
02476 { return vec[0] * vec[0] + vec[1] * vec[1] + vec[2] * vec[2] + vec[3] * vec[3]; }
02477
02481 void negate();
02482
02486 double normalize();
02487
02491 SbVec4d &setValue(const double v[4]);
02492
02496 SbVec4d &setValue(double x, double y, double z, double w);
02497
02501 SbVec4d &setValue(const SbVec4f &vec4f)
02502 { vec[0] = vec4f[0] ; vec[1] = vec4f[1] ; vec[2] = vec4f[2] ;
02503 vec[3] = vec4f[3] ; return (*this) ;}
02504
02506
02509 double & operator [](int i) { return (vec[i]); }
02510 const double & operator [](int i) const { return (vec[i]); }
02512
02516 SbVec4d & operator *=(double d);
02517
02521 SbVec4d & operator /=(double d);
02522
02526 SbVec4d & operator +=(const SbVec4d &u);
02530 SbVec4d & operator -=(const SbVec4d &u);
02531
02535 SbVec4d operator -() const;
02536
02540 friend SbVec4d operator *(const SbVec4d &v, double d);
02544 friend SbVec4d operator *(double d, const SbVec4d &v)
02545 { return v * d; }
02549 friend SbVec4d operator /(const SbVec4d &v, double d);
02550
02554 friend SbVec4d operator +(const SbVec4d &v1, const SbVec4d &v2);
02555
02559 friend SbVec4d operator -(const SbVec4d &v1, const SbVec4d &v2);
02560
02564 friend int operator ==(const SbVec4d &v1, const SbVec4d &v2);
02568 friend int operator !=(const SbVec4d &v1, const SbVec4d &v2)
02569 { return !(v1 == v2); }
02570
02574 friend inline std::ostream& operator << (std::ostream& os, const SbVec4d& v);
02575
02580 SbBool equals(const SbVec4d& v, double tolerance) const;
02581
02585 template<typename T>
02586 explicit SbVec4d(const T& v)
02587 {
02588
02589 vec[0] = double(v[0]);
02590 vec[1] = double(v[1]);
02591 vec[2] = double(v[2]);
02592 vec[3] = double(v[3]);
02593 }
02594
02595
02596 private:
02597 double vec[4];
02598
02599 };
02600
02602
02603
02604
02605
02606
02607
02609
02639 class SbVec4i32 {
02640 public:
02644 SbVec4i32() { memset(vec, 0, sizeof(vec)); }
02648 explicit SbVec4i32(const int32_t v[4]) { setValue(v); }
02652 SbVec4i32(int32_t x, int32_t y, int32_t z, int32_t w) { setValue(x, y, z, w); }
02656 inline int32_t dot(const SbVec4i32 &v) const
02657 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3]; }
02661 const int32_t *getValue() const { return vec; }
02665 void getValue(int32_t &x, int32_t &y, int32_t &z, int32_t &w) const;
02669 void negate();
02673 SbVec4i32 &setValue(const int32_t v[4]);
02677 SbVec4i32 &setValue(int32_t x, int32_t y, int32_t z, int32_t w);
02681 int32_t & operator [](int i) { return (vec[i]); }
02685 const int32_t & operator [](int i) const { return (vec[i]); }
02689 SbVec4i32 & operator *=(int d);
02693 SbVec4i32 & operator *=(double d);
02694
02698 SbVec4i32 & operator /=(int d);
02702 SbVec4i32 & operator /=(double d)
02703 { return *this *= (1.0 / d); }
02707 SbVec4i32 & operator +=(const SbVec4i32 &u);
02711 SbVec4i32 & operator -=(const SbVec4i32 &u);
02715 SbVec4i32 operator -() const;
02719 friend SbVec4i32 operator *(const SbVec4i32 &v, int d);
02723 friend SbVec4i32 operator *(const SbVec4i32 &v, double d);
02727 friend SbVec4i32 operator *(int d, const SbVec4i32 &v)
02728 { return v * d; }
02732 friend SbVec4i32 operator *(double d, const SbVec4i32 &v)
02733 { return v * d; }
02737 friend SbVec4i32 operator /(const SbVec4i32 &v, int d);
02741 friend SbVec4i32 operator /(const SbVec4i32 &v, double d)
02742 { return v * (1.0 / d); }
02746 friend SbVec4i32 operator +(const SbVec4i32 &v1, const SbVec4i32 &v2);
02751 friend SbVec4i32 operator -(const SbVec4i32 &v1, const SbVec4i32 &v2);
02755 friend int operator ==(const SbVec4i32 &v1, const SbVec4i32 &v2);
02759 friend int operator !=(const SbVec4i32 &v1, const SbVec4i32 &v2)
02760 { return !(v1 == v2); }
02761
02765 friend inline std::ostream& operator << (std::ostream& os, const SbVec4i32& v);
02766
02770 template<typename T>
02771 explicit SbVec4i32(const T& v)
02772 {
02773
02774 vec[0] = int32_t(v[0]);
02775 vec[1] = int32_t(v[1]);
02776 vec[2] = int32_t(v[2]);
02777 vec[3] = int32_t(v[3]);
02778 }
02779
02780 private:
02781 int32_t vec[4];
02782 };
02783
02785
02786
02787
02788
02789
02791
02792
02793
02824 class SbVec4s {
02825 public:
02826
02830 SbVec4s() { memset(vec, 0, sizeof(vec)); }
02831
02835 explicit SbVec4s(const short v[4]) { setValue(v); }
02836
02840 SbVec4s(short x, short y, short z, short w) { setValue(x, y, z, w); }
02841
02845 inline int32_t dot(const SbVec4s &v) const
02846 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3]; }
02847
02851 const short *getValue() const { return vec; }
02852
02856 void getValue(short &x, short &y, short &z, short &w) const;
02857
02861 void negate();
02862
02866 SbVec4s &setValue(const short v[4]);
02867
02871 SbVec4s &setValue(short x, short y, short z, short w);
02872
02874
02877 short & operator [](int i) { return (vec[i]); }
02878 const short & operator [](int i) const { return (vec[i]); }
02880
02884 SbVec4s & operator *=(int d);
02888 SbVec4s & operator *=(double d);
02889
02893 SbVec4s & operator /=(int d);
02897 SbVec4s & operator /=(double d)
02898 { return *this *= (1.0 / d); }
02899
02903 SbVec4s & operator +=(const SbVec4s &u);
02907 SbVec4s & operator -=(const SbVec4s &u);
02908
02912 SbVec4s operator -() const;
02913
02917 friend SbVec4s operator *(const SbVec4s &v, int d);
02921 friend SbVec4s operator *(const SbVec4s &v, double d);
02925 friend SbVec4s operator *(int d, const SbVec4s &v)
02926 { return v * d; }
02930 friend SbVec4s operator *(double d, const SbVec4s &v)
02931 { return v * d; }
02935 friend SbVec4s operator /(const SbVec4s &v, int d);
02939 friend SbVec4s operator /(const SbVec4s &v, double d)
02940 { return v * (1.0 / d); }
02941
02945 friend SbVec4s operator +(const SbVec4s &v1, const SbVec4s &v2);
02946
02950 friend SbVec4s operator -(const SbVec4s &v1, const SbVec4s &v2);
02951
02955 friend int operator ==(const SbVec4s &v1, const SbVec4s &v2);
02959 friend int operator !=(const SbVec4s &v1, const SbVec4s &v2)
02960 { return !(v1 == v2); }
02961
02965 friend inline std::ostream& operator << (std::ostream& os, const SbVec4s& v);
02966
02970 template<typename T>
02971 explicit SbVec4s(const T& v)
02972 {
02973
02974 vec[0] = short(v[0]);
02975 vec[1] = short(v[1]);
02976 vec[2] = short(v[2]);
02977 vec[3] = short(v[3]);
02978 }
02979
02980
02981
02982 private:
02983 short vec[4];
02984
02985 };
02986
02988
02989
02990
02991
02992
02994
02995
02996
03027 class SbVec4ui32 {
03028 public:
03029
03033 SbVec4ui32() { memset(vec, 0, sizeof(vec)); }
03034
03038 explicit SbVec4ui32(const uint32_t v[4]) { setValue(v); }
03039
03043 SbVec4ui32(uint32_t x, uint32_t y, uint32_t z, uint32_t w)
03044 { setValue(x, y, z, w); }
03045
03049 inline int32_t dot(const SbVec4ui32 &v) const
03050 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3]; }
03051
03055 const uint32_t *getValue() const { return vec; }
03056
03060 void getValue(uint32_t &x, uint32_t &y,
03061 uint32_t &z, uint32_t &w) const;
03062
03066 SbVec4ui32 &setValue(const uint32_t v[4]);
03067
03071 SbVec4ui32 &setValue(uint32_t x, uint32_t y,
03072 uint32_t z, uint32_t w);
03073
03075
03078 uint32_t & operator [](int i) { return (vec[i]); }
03079 const uint32_t & operator [](int i) const { return (vec[i]); }
03081
03085 SbVec4ui32 & operator *=(int d);
03089 SbVec4ui32 & operator *=(double d);
03090
03094 SbVec4ui32 & operator /=(int d);
03098 SbVec4ui32 & operator /=(double d)
03099 { return *this *= (1.0 / d); }
03100
03104 SbVec4ui32 & operator +=(const SbVec4ui32 &u);
03108 SbVec4ui32 & operator -=(const SbVec4ui32 &u);
03112 friend SbVec4ui32 operator *(const SbVec4ui32 &v, int d);
03116 friend SbVec4ui32 operator *(const SbVec4ui32 &v, double d);
03120 friend SbVec4ui32 operator *(int d, const SbVec4ui32 &v)
03121 { return v * d; }
03125 friend SbVec4ui32 operator *(double d, const SbVec4ui32 &v)
03126 { return v * d; }
03130 friend SbVec4ui32 operator /(const SbVec4ui32 &v, int d);
03134 friend SbVec4ui32 operator /(const SbVec4ui32 &v, double d)
03135 { return v * (1.0 / d); }
03136
03140 friend SbVec4ui32 operator +(const SbVec4ui32 &v1, const SbVec4ui32 &v2);
03141
03145 friend SbVec4ui32 operator -(const SbVec4ui32 &v1, const SbVec4ui32 &v2);
03146
03150 friend int operator ==(const SbVec4ui32 &v1, const SbVec4ui32 &v2);
03154 friend int operator !=(const SbVec4ui32 &v1, const SbVec4ui32 &v2)
03155 { return !(v1 == v2); }
03156
03160 friend inline std::ostream& operator << (std::ostream& os, const SbVec4ui32& v);
03161
03165 template<typename T>
03166 explicit SbVec4ui32(const T& v)
03167 {
03168
03169 vec[0] = uint32_t(v[0]);
03170 vec[1] = uint32_t(v[1]);
03171 vec[2] = uint32_t(v[2]);
03172 vec[3] = uint32_t(v[3]);
03173 }
03174 private:
03175 uint32_t vec[4];
03176
03177 };
03178
03180
03181
03182
03183
03184
03186
03187
03188
03219 class SbVec4us {
03220 public:
03221
03225 SbVec4us() { memset(vec, 0, sizeof(vec)); }
03226
03230 explicit SbVec4us(const unsigned short v[4]) { setValue(v); }
03231
03235 SbVec4us(unsigned short x, unsigned short y, unsigned short z, unsigned short w)
03236 { setValue(x, y, z, w); }
03237
03241 inline int32_t dot(const SbVec4us &v) const
03242 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3]; }
03243
03247 const unsigned short *getValue() const { return vec; }
03248
03252 void getValue(unsigned short &x, unsigned short &y, unsigned short &z, unsigned short &w) const;
03253
03257 void negate();
03258
03262 SbVec4us &setValue(const unsigned short v[4]);
03263
03267 SbVec4us &setValue(unsigned short x, unsigned short y, unsigned short z, unsigned short w);
03268
03270
03273 unsigned short & operator [](int i) { return (vec[i]); }
03274 const unsigned short & operator [](int i) const { return (vec[i]); }
03276
03280 SbVec4us & operator *=(int d);
03284 SbVec4us & operator *=(double d);
03285
03289 SbVec4us & operator /=(int d);
03293 SbVec4us & operator /=(double d)
03294 { return *this *= (1.0 / d); }
03295
03299 SbVec4us & operator +=(const SbVec4us &u);
03303 SbVec4us & operator -=(const SbVec4us &u);
03304
03308 SbVec4us operator -() const;
03309
03313 friend SbVec4us operator *(const SbVec4us &v, int d);
03317 friend SbVec4us operator *(const SbVec4us &v, double d);
03321 friend SbVec4us operator *(int d, const SbVec4us &v)
03322 { return v * d; }
03326 friend SbVec4us operator *(double d, const SbVec4us &v)
03327 { return v * d; }
03331 friend SbVec4us operator /(const SbVec4us &v, int d);
03335 friend SbVec4us operator /(const SbVec4us &v, double d)
03336 { return v * (1.0 / d); }
03337
03341 friend SbVec4us operator +(const SbVec4us &v1, const SbVec4us &v2);
03342
03346 friend SbVec4us operator -(const SbVec4us &v1, const SbVec4us &v2);
03347
03351 friend int operator ==(const SbVec4us &v1, const SbVec4us &v2);
03355 friend int operator !=(const SbVec4us &v1, const SbVec4us &v2)
03356 { return !(v1 == v2); }
03357
03361 friend inline std::ostream& operator << (std::ostream& os, const SbVec4us& v);
03362
03366 template<typename T>
03367 explicit SbVec4us(const T& v)
03368 {
03369
03370 vec[0] = static_cast<unsigned short>(v[0]);
03371 vec[1] = static_cast<unsigned short>(v[1]);
03372 vec[2] = static_cast<unsigned short>(v[2]);
03373 vec[3] = static_cast<unsigned short>(v[3]);
03374 }
03375 private:
03376 unsigned short vec[4];
03377
03378 };
03379
03380
03382
03383
03384
03385
03386
03388
03389
03390
03421 class SbVec4ub {
03422 public:
03423
03427 SbVec4ub() { memset(vec, 0, sizeof(vec)); }
03428
03432 explicit SbVec4ub(const unsigned char v[4]) { setValue(v); }
03433
03437 SbVec4ub(unsigned char x, unsigned char y, unsigned char z, unsigned char w)
03438 { setValue(x, y, z, w); }
03439
03443 inline int32_t dot(const SbVec4ub &v) const
03444 { return vec[0] * v.vec[0] + vec[1] * v.vec[1] + vec[2] * v.vec[2] + vec[3] * v.vec[3]; }
03445
03449 const unsigned char *getValue() const { return vec; }
03450
03454 void getValue(unsigned char &x, unsigned char &y, unsigned char &z, unsigned char &w) const;
03455
03459 void negate();
03460
03464 SbVec4ub &setValue(const unsigned char v[4]);
03465
03469 SbVec4ub &setValue(unsigned char x, unsigned char y, unsigned char z, unsigned char w);
03470
03472
03475 unsigned char & operator [](int i) { return (vec[i]); }
03476 const unsigned char & operator [](int i) const { return (vec[i]); }
03478
03482 SbVec4ub & operator *=(int d);
03486 SbVec4ub & operator *=(double d);
03487
03491 SbVec4ub & operator /=(int d);
03495 SbVec4ub & operator /=(double d)
03496 { return *this *= (1.0 / d); }
03497
03501 SbVec4ub & operator +=(const SbVec4ub &u);
03505 SbVec4ub & operator -=(const SbVec4ub &u);
03506
03510 SbVec4ub operator -() const;
03511
03515 friend SbVec4ub operator *(const SbVec4ub &v, int d);
03519 friend SbVec4ub operator *(const SbVec4ub &v, double d);
03523 friend SbVec4ub operator *(int d, const SbVec4ub &v)
03524 { return v * d; }
03528 friend SbVec4ub operator *(double d, const SbVec4ub &v)
03529 { return v * d; }
03533 friend SbVec4ub operator /(const SbVec4ub &v, int d);
03537 friend SbVec4ub operator /(const SbVec4ub &v, double d)
03538 { return v * (1.0 / d); }
03539
03543 friend SbVec4ub operator +(const SbVec4ub &v1, const SbVec4ub &v2);
03544
03548 friend SbVec4ub operator -(const SbVec4ub &v1, const SbVec4ub &v2);
03549
03553 friend int operator ==(const SbVec4ub &v1, const SbVec4ub &v2);
03557 friend int operator !=(const SbVec4ub &v1, const SbVec4ub &v2)
03558 { return !(v1 == v2); }
03559
03563 friend inline std::ostream& operator << (std::ostream& os, const SbVec4ub& v);
03564
03568 template<typename T>
03569 explicit SbVec4ub(const T& v)
03570 {
03571
03572 vec[0] = static_cast<unsigned char>(v[0]);
03573 vec[1] = static_cast<unsigned char>(v[1]);
03574 vec[2] = static_cast<unsigned char>(v[2]);
03575 vec[3] = static_cast<unsigned char>(v[3]);
03576 }
03577
03581 inline void clamp(unsigned char a, unsigned char b)
03582 {
03583 vec[0] = SbMathHelper::Clamp(vec[0], a, b);
03584 vec[1] = SbMathHelper::Clamp(vec[1], a, b);
03585 vec[2] = SbMathHelper::Clamp(vec[2], a, b);
03586 vec[3] = SbMathHelper::Clamp(vec[3], a, b);
03587 }
03588 private:
03589 unsigned char vec[4];
03590
03591 };
03592
03596 inline std::ostream& operator << (std::ostream& os, const SbVec2s& v)
03597 {
03598 return os << "(" << v[0] << ", " << v[1] << ")";
03599 }
03600
03604 inline std::ostream& operator << (std::ostream& os, const SbVec2i32& v)
03605 {
03606 return os << "(" << v[0] << ", " << v[1] << ")";
03607 }
03608
03612 inline std::ostream& operator << (std::ostream& os, const SbVec2f& v)
03613 {
03614 return os << "(" << v[0] << ", " << v[1] << ")";
03615 }
03616
03620 inline std::ostream& operator << (std::ostream& os, const SbVec2d& v)
03621 {
03622 return os << "(" << v[0] << ", " << v[1] << ")";
03623 }
03624
03628 inline std::ostream& operator << (std::ostream& os, const SbVec3s& v)
03629 {
03630 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ")";
03631 }
03632
03636 inline std::ostream& operator << (std::ostream& os, const SbVec3i32& v)
03637 {
03638 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ")";
03639 }
03640
03644 inline std::ostream& operator << (std::ostream& os, const SbVec3d& v)
03645 {
03646 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ")";
03647 }
03648
03652 inline std::ostream& operator << (std::ostream& os, const SbVec3f& v)
03653 {
03654 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ")";
03655 }
03656
03657
03661 inline std::ostream& operator << (std::ostream& os, const SbVec4b& v)
03662 {
03663 return os << "(" << static_cast<int>(v[0]) << ", " << static_cast<int>(v[1]) << ", " << static_cast<int>(v[2]) << ", " << static_cast<int>(v[3]) << ")";
03664 }
03665
03669 inline std::ostream& operator << (std::ostream& os, const SbVec4d& v)
03670 {
03671 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")";
03672 }
03673
03677 inline std::ostream& operator << (std::ostream& os, const SbVec4f& v)
03678 {
03679 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")";
03680 }
03681
03685 inline std::ostream& operator << (std::ostream& os, const SbVec4i32& v)
03686 {
03687 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")";
03688 }
03689
03693 inline std::ostream& operator << (std::ostream& os, const SbVec4s& v)
03694 {
03695 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")";
03696 }
03697
03701 inline std::ostream& operator << (std::ostream& os, const SbVec4ub& v)
03702 {
03703 return os << "(" << static_cast<unsigned int>(v[0]) << ", " << static_cast<unsigned int>(v[1]) << ", " << static_cast<unsigned int>(v[2]) << ", " << static_cast<unsigned int>(v[3]) << ")";
03704 }
03705
03709 inline std::ostream& operator << (std::ostream& os, const SbVec4ui32& v)
03710 {
03711 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")";
03712 }
03713
03717 inline std::ostream& operator << (std::ostream& os, const SbVec4us& v)
03718 {
03719 return os << "(" << v[0] << ", " << v[1] << ", " << v[2] << ", " << v[3] << ")";
03720 }
03721
03722
03723 #endif
03724
03725
03726