00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGVECTOR_H_
00040 #define _OSGVECTOR_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include <OSGConfig.h>
00046 #include <OSGBase.h>
00047 #include <OSGBaseTypes.h>
00048 #include <OSGBaseFunctions.h>
00049
00050 #include <iostream>
00051
00052 OSG_BEGIN_NAMESPACE
00053
00054 template<class ValueTypeT, class StorageInterfaceT>
00055 class VectorInterface;
00056
00057 template<class ValueTypeT, class StorageInterfaceT>
00058 class PointInterface;
00059
00060
00061 #ifdef __sgi
00062 #pragma set woff 1209
00063 #endif
00064
00065
00066
00067
00068
00074 template <class ValueTypeT>
00075 class VecStorage2
00076 {
00077
00078
00079 public:
00080
00081 static const UInt32 _iSize = 2;
00082
00083
00087 VecStorage2(void);
00088
00090
00094 ~VecStorage2(void);
00095
00097
00101 void setValues (const ValueTypeT rVal1,
00102 const ValueTypeT rVal2);
00103
00104 void getSeparateValues( ValueTypeT &rVal1,
00105 ValueTypeT &rVal2) const;
00106
00107 ValueTypeT x (void ) const;
00108 ValueTypeT y (void ) const;
00109
00111
00112
00113 protected:
00114
00115 ValueTypeT _values[_iSize];
00116
00117
00118
00119 private:
00120
00122 VecStorage2(const VecStorage2 &source);
00124 void operator =(const VecStorage2 &source);
00125 };
00126
00127
00128
00129
00130
00131
00132
00133
00139 template <class ValueTypeT>
00140 class VecStorage3
00141 {
00142
00143
00144 public:
00145
00146 static const UInt32 _iSize = 3;
00147
00148
00152 VecStorage3(void);
00153
00155
00159 ~VecStorage3(void);
00160
00162
00166 void setValues (const ValueTypeT rVal1,
00167 const ValueTypeT rVal2,
00168 const ValueTypeT rVal3);
00169
00170 void getSeparateValues( ValueTypeT &rVal1,
00171 ValueTypeT &rVal2,
00172 ValueTypeT &rVal3) const;
00173
00174 ValueTypeT x (void ) const;
00175 ValueTypeT y (void ) const;
00176 ValueTypeT z (void ) const;
00177
00179
00180
00181 protected:
00182
00183 ValueTypeT _values[_iSize];
00184
00185
00186
00187 private:
00188
00190 VecStorage3(const VecStorage3 &source);
00192 void operator =(const VecStorage3 &source);
00193 };
00194
00195
00196
00197
00198
00199
00200
00201
00207 template <class ValueTypeT>
00208 class VecStorage4
00209 {
00210
00211
00212 public:
00213
00214 static const UInt32 _iSize = 4;
00215
00216
00220 VecStorage4(void);
00221
00223
00227 ~VecStorage4(void);
00228
00230
00234 void setValues (const ValueTypeT rVal1,
00235 const ValueTypeT rVal2,
00236 const ValueTypeT rVal3,
00237 const ValueTypeT rVal4);
00238
00239 void getSeparateValues( ValueTypeT &rVal1,
00240 ValueTypeT &rVal2,
00241 ValueTypeT &rVal3,
00242 ValueTypeT &rVal4) const;
00243
00244 ValueTypeT x (void ) const;
00245 ValueTypeT y (void ) const;
00246 ValueTypeT z (void ) const;
00247 ValueTypeT w (void ) const;
00248
00250
00251
00252 protected:
00253
00254 ValueTypeT _values[_iSize];
00255
00256
00257
00258 private:
00259
00261 VecStorage4(const VecStorage4 &source);
00263 void operator =(const VecStorage4 &source);
00264 };
00265
00266
00267
00268
00269
00270
00271
00272
00278 #ifdef __sgi
00279 #pragma set woff 1375
00280 #endif
00281
00282 template<class ValueTypeT, class StorageInterfaceT>
00283 class VectorInterface;
00284
00285 template<class ValueTypeT, class StorageInterfaceT>
00286 class PointInterface : public StorageInterfaceT
00287 {
00288
00289
00290 public:
00291
00292 typedef StorageInterfaceT Inherited;
00293
00294 typedef typename TypeTraits<ValueTypeT>::RealReturnType RealReturnType;
00295
00296 typedef ValueTypeT ValueType;
00297
00298 typedef VectorInterface<ValueTypeT,
00299 StorageInterfaceT> VecInterface;
00300
00301
00302 typedef PointInterface <ValueTypeT,
00303 StorageInterfaceT> Self;
00304
00305 static const PointInterface Null;
00306
00307
00311 PointInterface( void );
00312
00313 PointInterface(const ValueTypeT *pVals );
00314 PointInterface( ValueTypeT *pVals );
00315
00316 template <class ValueType2T, class StorageInterface2T>
00317 PointInterface(const PointInterface<ValueType2T, StorageInterface2T> &vec);
00318
00319 template <class ValueType2T, class StorageInterface2T>
00320 PointInterface(const VectorInterface<ValueType2T, StorageInterface2T> &vec);
00321
00322 PointInterface(const PointInterface &source);
00323
00324 PointInterface(const ValueTypeT rVal1);
00325
00326
00327
00328
00329
00330 PointInterface(const ValueTypeT rVal1, const ValueTypeT rVal2);
00331
00332 PointInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00333 const ValueTypeT rVal3);
00334
00335 PointInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00336 const ValueTypeT rVal3, const ValueTypeT rVal4);
00337
00339
00343 ~PointInterface(void);
00344
00346
00350 void setNull (void);
00351
00352 #if 0
00353
00354
00355
00356
00357
00358 void setValue(const ValueTypeT &rVal1);
00359 #endif
00360
00361 void setValue(const PointInterface &vec );
00362
00363 template <class ValueType2T, class StorageInterface2T>
00364 void setValue(const PointInterface<ValueType2T, StorageInterface2T> &vec);
00365
00366 void setValue (const ValueTypeT *pVals );
00367 void setValue ( ValueTypeT *pVals );
00368
00369 void setValueFromCString(const Char8 *szString);
00370 void setValueFromCString( Char8 *szString);
00371
00372 #ifndef OSG_DISABLE_DEPRECATED
00373 void setValue (const Char8 *szString);
00374 void setValue ( Char8 *szString);
00375 #endif
00376
00377
00379
00383 ValueTypeT *getValues(void);
00384 const ValueTypeT *getValues(void) const;
00385
00387
00391 bool isZero ( void ) const;
00392
00393 void negate ( void );
00394
00395 bool equals (const PointInterface &vec,
00396 const ValueTypeT tolerance) const;
00397
00398 VecInterface &subZero ( void );
00399 const VecInterface &subZero ( void ) const;
00400
00401 RealReturnType dist (const PointInterface &vec ) const;
00402 RealReturnType dist2 (const PointInterface &vec ) const;
00403
00404 RealReturnType maxValue( void ) const;
00405
00407
00411 void operator *=(const ValueTypeT val );
00412 void operator /=(const ValueTypeT val );
00413
00414 VecInterface operator - (const PointInterface &vec ) const;
00415
00416 PointInterface operator + (const VecInterface &vec ) const;
00417
00418 PointInterface operator - (const VecInterface &vec ) const;
00419
00420 PointInterface operator * (const ValueTypeT rVal) const;
00421
00422 PointInterface operator - ( void );
00423
00424 void operator +=(const VecInterface &vec );
00425 void operator -=(const VecInterface &vec );
00426
00428
00432 ValueTypeT &operator[](const UInt32 uiVal);
00433 const ValueTypeT &operator[](const UInt32 uiVal) const;
00434
00435
00436
00437
00438
00439
00440
00441
00442
00444
00448 PointInterface &operator =(const PointInterface &source);
00449 PointInterface &operator =(const VecInterface &source);
00450
00452
00456 bool operator < (const PointInterface &other) const;
00457
00458 bool operator == (const PointInterface &other) const;
00459 bool operator != (const PointInterface &other) const;
00460
00462
00463
00464 protected:
00465
00466
00467
00468 private:
00469 };
00470
00471
00472 template <class ValueTypeT,
00473 class StorageInterfaceT> inline
00474 PointInterface<ValueTypeT, StorageInterfaceT>
00475 operator *(const ValueTypeT val,
00476 const PointInterface<ValueTypeT,
00477 StorageInterfaceT> &vec);
00478
00479 template <class ValueTypeT,
00480 class StorageInterfaceT> inline
00481 std::ostream &operator <<( std::ostream &os,
00482 const PointInterface<ValueTypeT,
00483 StorageInterfaceT> &obj);
00484
00485
00486
00487
00488
00489
00490
00491
00497 template<class ValueTypeT, class StorageInterfaceT>
00498 class VectorInterface :
00499 public PointInterface<ValueTypeT, StorageInterfaceT>
00500 {
00501
00502
00503 public:
00504
00505 typedef PointInterface<ValueTypeT,
00506 StorageInterfaceT> Inherited;
00507
00508 typedef typename TypeTraits<ValueTypeT>::RealReturnType RealReturnType;
00509
00510 typedef ValueTypeT ValueType;
00511
00512 typedef Inherited PntInterface;
00513
00514 typedef VectorInterface<ValueTypeT,
00515 StorageInterfaceT> Self;
00516
00517 static const VectorInterface Null;
00518
00519
00523 VectorInterface( void );
00524
00525 VectorInterface(const ValueTypeT *pVals );
00526 VectorInterface( ValueTypeT *pVals );
00527
00528 template <class ValueType2T, class StorageInterface2T>
00529 VectorInterface(const PointInterface<ValueType2T, StorageInterface2T> &vec);
00530
00531 template <class ValueType2T, class StorageInterface2T>
00532 VectorInterface(const VectorInterface<ValueType2T, StorageInterface2T> &vec);
00533
00534 VectorInterface(const VectorInterface &source);
00535
00536 VectorInterface(const ValueTypeT rVal1 );
00537
00538
00539
00540
00541
00542 VectorInterface(const ValueTypeT rVal1, const ValueTypeT rVal2);
00543
00544 VectorInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00545 const ValueTypeT rVal3);
00546
00547 VectorInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00548 const ValueTypeT rVal3, const ValueTypeT rVal4);
00549
00551
00555 ~VectorInterface(void);
00556
00558
00562 RealReturnType length ( void ) const;
00563 RealReturnType squareLength ( void ) const;
00564
00565 void normalize ( void );
00566
00567 VectorInterface cross (const VectorInterface &vec ) const;
00568 VectorInterface operator % (const VectorInterface &vec ) const;
00569
00570 void crossThis (const VectorInterface &vec );
00571
00572 ValueTypeT dot (const VectorInterface &vec ) const;
00573 ValueTypeT operator * (const VectorInterface &vec ) const;
00574 ValueTypeT dot (const PntInterface &pnt ) const;
00575 ValueTypeT operator * (const PntInterface &pnt ) const;
00576
00577 RealReturnType enclosedAngle(const VectorInterface &vec ) const;
00578
00579 RealReturnType projectTo (const VectorInterface &toVec);
00580
00582
00586 PntInterface &addToZero (void);
00587 const PntInterface &addToZero (void) const;
00588
00589 VectorInterface &subZero (void);
00590 const VectorInterface &subZero (void) const;
00591
00593
00597 VectorInterface operator - (const VectorInterface &vec ) const;
00598 VectorInterface operator + (const VectorInterface &vec ) const;
00599
00600 VectorInterface operator * (const ValueTypeT rVal) const;
00601
00602 VectorInterface operator - ( void ) const;
00603
00605
00609 VectorInterface &operator =(const VectorInterface &source);
00610
00612
00616 bool operator < (const VectorInterface &other) const;
00617
00618 bool operator == (const VectorInterface &other) const;
00619 bool operator != (const VectorInterface &other) const;
00620
00622
00623
00624 protected:
00625
00626
00627
00628 private:
00629 };
00630
00631 #ifdef __sgi
00632 #pragma reset woff 1375
00633 #endif
00634
00635 template <class ValueTypeT,
00636 class StorageInterfaceT> inline
00637 VectorInterface<ValueTypeT, StorageInterfaceT>
00638 operator *(const ValueTypeT val,
00639 const VectorInterface<ValueTypeT,
00640 StorageInterfaceT> &vec);
00641
00642 template <class ValueTypeT,
00643 class StorageInterfaceT> inline
00644 std::ostream &operator <<( std::ostream &os,
00645 const VectorInterface<ValueTypeT,
00646 StorageInterfaceT> &obj);
00647
00648
00649
00650
00651
00656 typedef VectorInterface< UInt8, VecStorage2<UInt8> > Vec2ub;
00657
00662 typedef Vec2ub *Vec2ubP;
00663
00668 #ifndef OSG_NO_INT8_PNT
00669 typedef VectorInterface< Int8, VecStorage2<Int8> > Vec2b;
00670 #endif
00671
00676 #ifndef OSG_NO_INT8_PNT
00677 typedef Vec2b *Vec2bP;
00678 #endif
00679
00684 typedef VectorInterface< UInt16, VecStorage2<UInt16> > Vec2us;
00685
00690 typedef Vec2us *Vec2usP;
00691
00696 typedef VectorInterface< Int16, VecStorage2<Int16> > Vec2s;
00697
00702 typedef Vec2s *Vec2sP;
00703
00708 typedef VectorInterface< Real32, VecStorage2<Real32> > Vec2f;
00709
00714 typedef Vec2f *Vec2fP;
00715
00720 typedef VectorInterface< Real64, VecStorage2<Real64> > Vec2d;
00721
00726 typedef Vec2d *Vec2dP;
00727
00732 typedef VectorInterface< Real128, VecStorage2<Real128> > Vec2ld;
00733
00738 typedef Vec2ld *Vec2ldP;
00739
00740
00745 typedef VectorInterface< UInt8, VecStorage3<UInt8> > Vec3ub;
00746
00751 typedef Vec3ub *Vec3ubP;
00752
00757 #ifndef OSG_NO_INT8_PNT
00758 typedef VectorInterface< Int8, VecStorage3<Int8> > Vec3b;
00759 #endif
00760
00765 #ifndef OSG_NO_INT8_PNT
00766 typedef Vec3b *Vec3bP;
00767 #endif
00768
00773 typedef VectorInterface< UInt16, VecStorage3<UInt16> > Vec3us;
00774
00779 typedef Vec3us *Vec3usP;
00780
00785 typedef VectorInterface< Int16, VecStorage3<Int16> > Vec3s;
00786
00791 typedef Vec3s *Vec3sP;
00792
00797 typedef VectorInterface< Real32, VecStorage3<Real32> > Vec3f;
00798
00803 typedef Vec3f *Vec3fP;
00804
00809 typedef VectorInterface< Real64, VecStorage3<Real64> > Vec3d;
00810
00815 typedef Vec3d *Vec3dP;
00816
00821 typedef VectorInterface< Real128, VecStorage3<Real128> > Vec3ld;
00822
00827 typedef Vec3ld *Vec3ldP;
00828
00829
00834 typedef VectorInterface< UInt8, VecStorage4<UInt8> > Vec4ub;
00835
00840 typedef Vec4ub *Vec4ubP;
00841
00846 #ifndef OSG_NO_INT8_PNT
00847 typedef VectorInterface< Int8, VecStorage4<Int8> > Vec4b;
00848 #endif
00849
00854 #ifndef OSG_NO_INT8_PNT
00855 typedef Vec4b *Vec4bP;
00856 #endif
00857
00862 typedef VectorInterface< UInt16, VecStorage4<UInt16> > Vec4us;
00863
00868 typedef Vec4us *Vec4usP;
00869
00874 typedef VectorInterface< Int16, VecStorage4<Int16> > Vec4s;
00875
00880 typedef Vec4s *Vec4sP;
00881
00886 typedef VectorInterface< Real32, VecStorage4<Real32> > Vec4f;
00887
00892 typedef Vec4f *Vec4fP;
00893
00898 typedef VectorInterface< Real64, VecStorage4<Real64> > Vec4d;
00899
00904 typedef Vec4d *Vec4dP;
00905
00910 typedef VectorInterface< Real128, VecStorage4<Real128> > Vec4ld;
00911
00916 typedef Vec4ld *Vec4ldP;
00917
00918
00919
00920
00925 typedef PointInterface< UInt8, VecStorage2<UInt8> > Pnt2ub;
00926
00931 typedef Pnt2ub *Pnt2ubP;
00932
00937 #ifndef OSG_NO_INT8_PNT
00938 typedef PointInterface< Int8, VecStorage2<Int8> > Pnt2b;
00939 #endif
00940
00945 #ifndef OSG_NO_INT8_PNT
00946 typedef Pnt2b *Pnt2bP;
00947 #endif
00948
00953 typedef PointInterface< UInt16, VecStorage2<UInt16> > Pnt2us;
00954
00959 typedef Pnt2us *Pnt2usP;
00960
00965 typedef PointInterface< Int16, VecStorage2<Int16> > Pnt2s;
00966
00971 typedef Pnt2s *Pnt2sP;
00972
00977 typedef PointInterface< Real32, VecStorage2<Real32> > Pnt2f;
00978
00983 typedef Pnt2f *Pnt2fP;
00984
00989 typedef PointInterface< Real64, VecStorage2<Real64> > Pnt2d;
00990
00995 typedef Pnt2d *Pnt2dP;
00996
01001 typedef PointInterface< Real128, VecStorage2<Real128> > Pnt2ld;
01002
01007 typedef Pnt2ld *Pnt2ldP;
01008
01009
01014 typedef PointInterface< UInt8, VecStorage3<UInt8> > Pnt3ub;
01015
01020 typedef Pnt3ub *Pnt3ubP;
01021
01026 #ifndef OSG_NO_INT8_PNT
01027 typedef PointInterface< Int8, VecStorage3<Int8> > Pnt3b;
01028 #endif
01029
01034 #ifndef OSG_NO_INT8_PNT
01035 typedef Pnt3b *Pnt3bP;
01036 #endif
01037
01042 typedef PointInterface< UInt16, VecStorage3<UInt16> > Pnt3us;
01043
01048 typedef Pnt3us *Pnt3usP;
01049
01054 typedef PointInterface< Int16, VecStorage3<Int16> > Pnt3s;
01055
01060 typedef Pnt3s *Pnt3sP;
01061
01066 typedef PointInterface< Real32, VecStorage3<Real32> > Pnt3f;
01067
01072 typedef Pnt3f *Pnt3fP;
01073
01078 typedef PointInterface< Real64, VecStorage3<Real64> > Pnt3d;
01079
01084 typedef Pnt3d *Pnt3dP;
01085
01090 typedef PointInterface< Real128, VecStorage3<Real128> > Pnt3ld;
01091
01096 typedef Pnt3ld *Pnt3ldP;
01097
01098
01103 typedef PointInterface< UInt8, VecStorage4<UInt8> > Pnt4ub;
01104
01109 typedef Pnt4ub *Pnt4ubP;
01110
01115 #ifndef OSG_NO_INT8_PNT
01116 typedef PointInterface< Int8, VecStorage4<Int8> > Pnt4b;
01117 #endif
01118
01123 #ifndef OSG_NO_INT8_PNT
01124 typedef Pnt4b *Pnt4bP;
01125 #endif
01126
01131 typedef PointInterface< UInt16, VecStorage4<UInt16> > Pnt4us;
01132
01137 typedef Pnt4us *Pnt4usP;
01138
01143 typedef PointInterface< Int16, VecStorage4<Int16> > Pnt4s;
01144
01149 typedef Pnt4s *Pnt4sP;
01150
01155 typedef PointInterface< Real32, VecStorage4<Real32> > Pnt4f;
01156
01161 typedef Pnt4f *Pnt4fP;
01162
01167 typedef PointInterface< Real64, VecStorage4<Real64> > Pnt4d;
01168
01173 typedef Pnt4d *Pnt4dP;
01174
01179 typedef PointInterface< Real128, VecStorage4<Real128> > Pnt4ld;
01180
01185 typedef Pnt4ld *Pnt4ldP;
01186
01187
01188 OSG_END_NAMESPACE
01189
01190 #include <OSGVector.inl>
01191
01192
01193 #ifdef __sgi
01194 #pragma reset woff 1209
01195 #endif
01196
01197 #define OSGVECTOR_HEADER_CVSID "@(#)$Id: $"
01198
01199 #endif
01200
01201