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 PointInterface : public StorageInterfaceT
00284 {
00285
00286
00287 public:
00288
00289 typedef StorageInterfaceT Inherited;
00290
00291 typedef typename TypeTraits<ValueTypeT>::RealReturnType RealReturnType;
00292
00293 typedef ValueTypeT ValueType;
00294
00295 typedef VectorInterface<ValueTypeT,
00296 StorageInterfaceT> VecInterface;
00297
00298
00299 typedef PointInterface <ValueTypeT,
00300 StorageInterfaceT> Self;
00301
00302 static const PointInterface Null;
00303
00304
00308 PointInterface( void );
00309
00310 explicit PointInterface(const ValueTypeT *pVals );
00311 explicit PointInterface( ValueTypeT *pVals );
00312
00313
00314
00315 template<class VectorT>
00316 #ifndef OSG_MICROSOFT_COMPILER_HACKS
00317 explicit
00318 #endif
00319 PointInterface(const VectorT &vec )
00320 {
00321 if(Self::_iSize <= VectorT::_iSize)
00322 {
00323 for(UInt32 i = 0; i < Self::_iSize; i++)
00324 {
00325 Self::_values[i] = vec.getValues()[i];
00326 }
00327 }
00328 else
00329 {
00330 UInt32 i;
00331 for(i = 0; i < VectorT::_iSize; i++)
00332 {
00333 Self::_values[i] = vec.getValues()[i];
00334 }
00335 for(i = VectorT::_iSize; i < Self::_iSize; i++)
00336 {
00337 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00338 }
00339 }
00340 }
00341
00342 PointInterface(const PointInterface &source);
00343
00344 #if 0
00345
00346
00347
00348
00349
00350 PointInterface(const ValueTypeT rVal1);
00351 #endif
00352
00353
00354
00355
00356
00357 PointInterface(const ValueTypeT rVal1, const ValueTypeT rVal2);
00358
00359 PointInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00360 const ValueTypeT rVal3);
00361
00362 PointInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00363 const ValueTypeT rVal3, const ValueTypeT rVal4);
00364
00366
00370 ~PointInterface(void);
00371
00373
00377 void setNull (void);
00378
00379 #if 0
00380
00381
00382
00383
00384
00385 void setValue(const ValueTypeT &rVal1);
00386 #endif
00387
00388 void setValue(const PointInterface &vec );
00389
00390
00391
00392 template<class VectorT>
00393 void setValue(const VectorT &vec )
00394 {
00395 for(UInt32 i = 0;
00396 i < (Self::_iSize < VectorT::_iSize ?
00397 Self::_iSize : VectorT::_iSize);
00398 ++i)
00399 {
00400 Self::_values[i] = vec.getValues()[i];
00401 }
00402 }
00403
00404 void setValue (const ValueTypeT *pVals );
00405 void setValue ( ValueTypeT *pVals );
00406
00407 void setValueFromCString(const Char8 *szString);
00408 void setValueFromCString( Char8 *szString);
00409
00410 #ifndef OSG_DISABLE_DEPRECATED
00411 void setValue (const Char8 *szString);
00412 void setValue ( Char8 *szString);
00413 #endif
00414
00415
00417
00421 ValueTypeT *getValues(void);
00422 const ValueTypeT *getValues(void) const;
00423
00425
00429 bool isZero ( void ) const;
00430
00431 void negate ( void );
00432
00433 bool equals (const PointInterface &vec,
00434 const ValueTypeT tolerance) const;
00435
00436 VecInterface &subZero ( void );
00437 const VecInterface &subZero ( void ) const;
00438
00439 RealReturnType dist (const PointInterface &vec ) const;
00440 RealReturnType dist2 (const PointInterface &vec ) const;
00441
00442 RealReturnType maxValue( void ) const;
00443
00445
00449 void operator *=(const ValueTypeT val );
00450 void operator /=(const ValueTypeT val );
00451
00452 VecInterface operator - (const PointInterface &vec ) const;
00453
00454 PointInterface operator + (const VecInterface &vec ) const;
00455
00456 PointInterface operator - (const VecInterface &vec ) const;
00457
00458 PointInterface operator * (const ValueTypeT rVal) const;
00459
00460 PointInterface operator - ( void );
00461
00462 void operator +=(const VecInterface &vec );
00463 void operator -=(const VecInterface &vec );
00464
00466
00470 ValueTypeT &operator[](const UInt32 uiVal);
00471 const ValueTypeT &operator[](const UInt32 uiVal) const;
00472
00473
00474
00475
00476
00477
00478
00479
00480
00482
00486 PointInterface &operator =(const PointInterface &source);
00487 PointInterface &operator =(const VecInterface &source);
00488
00490
00494 bool operator < (const PointInterface &other) const;
00495
00496 bool operator == (const PointInterface &other) const;
00497 bool operator != (const PointInterface &other) const;
00498
00500
00501
00502 protected:
00503
00504
00505
00506 private:
00507 };
00508
00509
00510 template <class ValueTypeT,
00511 class StorageInterfaceT> inline
00512 PointInterface<ValueTypeT, StorageInterfaceT>
00513 operator *(const ValueTypeT val,
00514 const PointInterface<ValueTypeT,
00515 StorageInterfaceT> &vec);
00516
00517 template <class ValueTypeT,
00518 class StorageInterfaceT> inline
00519 std::ostream &operator <<( std::ostream &os,
00520 const PointInterface<ValueTypeT,
00521 StorageInterfaceT> &obj);
00522
00523
00524
00525
00526
00527
00528
00529
00535 template<class ValueTypeT, class StorageInterfaceT>
00536 class VectorInterface :
00537 public PointInterface<ValueTypeT, StorageInterfaceT>
00538 {
00539
00540
00541 public:
00542
00543 typedef PointInterface<ValueTypeT,
00544 StorageInterfaceT> Inherited;
00545
00546 typedef typename TypeTraits<ValueTypeT>::RealReturnType RealReturnType;
00547
00548 typedef ValueTypeT ValueType;
00549
00550 typedef Inherited PntInterface;
00551
00552 typedef VectorInterface<ValueTypeT,
00553 StorageInterfaceT> Self;
00554
00555 static const VectorInterface Null;
00556
00557
00561 VectorInterface( void );
00562
00563 explicit VectorInterface(const ValueTypeT *pVals );
00564 explicit VectorInterface( ValueTypeT *pVals );
00565
00566
00567
00568 template<class VectorT>
00569 #ifndef OSG_MICROSOFT_COMPILER_HACKS
00570 explicit
00571 #endif
00572 VectorInterface(const VectorT &vec )
00573 {
00574 if(Self::_iSize <= VectorT::_iSize)
00575 {
00576 for(UInt32 i = 0; i < Self::_iSize; i++)
00577 {
00578 Self::_values[i] = vec.getValues()[i];
00579 }
00580 }
00581 else
00582 {
00583 UInt32 i;
00584 for(i = 0; i < VectorT::_iSize; i++)
00585 {
00586 Self::_values[i] = vec.getValues()[i];
00587 }
00588 for(i = VectorT::_iSize; i < Self::_iSize; i++)
00589 {
00590 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00591 }
00592 }
00593 }
00594
00595 VectorInterface(const VectorInterface &source);
00596
00597 #if 0
00598
00599
00600
00601
00602
00603 VectorInterface(const ValueTypeT rVal1 );
00604 #endif
00605
00606
00607
00608
00609
00610 VectorInterface(const ValueTypeT rVal1, const ValueTypeT rVal2);
00611
00612 VectorInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00613 const ValueTypeT rVal3);
00614
00615 VectorInterface(const ValueTypeT rVal1, const ValueTypeT rVal2,
00616 const ValueTypeT rVal3, const ValueTypeT rVal4);
00617
00619
00623 ~VectorInterface(void);
00624
00626
00630 RealReturnType length ( void ) const;
00631 RealReturnType squareLength ( void ) const;
00632
00633 void normalize ( void );
00634
00635 VectorInterface cross (const VectorInterface &vec ) const;
00636 VectorInterface operator % (const VectorInterface &vec ) const;
00637
00638 void crossThis (const VectorInterface &vec );
00639
00640 ValueTypeT dot (const VectorInterface &vec ) const;
00641 ValueTypeT operator * (const VectorInterface &vec ) const;
00642 ValueTypeT dot (const PntInterface &pnt ) const;
00643 ValueTypeT operator * (const PntInterface &pnt ) const;
00644
00645 RealReturnType enclosedAngle(const VectorInterface &vec ) const;
00646
00647 RealReturnType projectTo (const VectorInterface &toVec);
00648
00650
00654 PntInterface &addToZero (void);
00655 const PntInterface &addToZero (void) const;
00656
00657 VectorInterface &subZero (void);
00658 const VectorInterface &subZero (void) const;
00659
00661
00665 VectorInterface operator - (const VectorInterface &vec ) const;
00666 VectorInterface operator + (const VectorInterface &vec ) const;
00667
00668 VectorInterface operator * (const ValueTypeT rVal) const;
00669
00670 VectorInterface operator - ( void ) const;
00671
00673
00677 VectorInterface &operator =(const VectorInterface &source);
00678
00680
00684 bool operator < (const VectorInterface &other) const;
00685
00686 bool operator == (const VectorInterface &other) const;
00687 bool operator != (const VectorInterface &other) const;
00688
00690
00691
00692 protected:
00693
00694
00695
00696 private:
00697 };
00698
00699 #ifdef __sgi
00700 #pragma reset woff 1375
00701 #endif
00702
00703 template <class ValueTypeT,
00704 class StorageInterfaceT> inline
00705 VectorInterface<ValueTypeT, StorageInterfaceT>
00706 operator *(const ValueTypeT val,
00707 const VectorInterface<ValueTypeT,
00708 StorageInterfaceT> &vec);
00709
00710 template <class ValueTypeT,
00711 class StorageInterfaceT> inline
00712 std::ostream &operator <<( std::ostream &os,
00713 const VectorInterface<ValueTypeT,
00714 StorageInterfaceT> &obj);
00715
00716
00717
00718
00719
00724 typedef VectorInterface< UInt8, VecStorage2<UInt8> > Vec2ub;
00725
00730 typedef Vec2ub *Vec2ubP;
00731
00736 #ifndef OSG_NO_INT8_PNT
00737 typedef VectorInterface< Int8, VecStorage2<Int8> > Vec2b;
00738 #endif
00739
00744 #ifndef OSG_NO_INT8_PNT
00745 typedef Vec2b *Vec2bP;
00746 #endif
00747
00752 typedef VectorInterface< UInt16, VecStorage2<UInt16> > Vec2us;
00753
00758 typedef Vec2us *Vec2usP;
00759
00764 typedef VectorInterface< Int16, VecStorage2<Int16> > Vec2s;
00765
00770 typedef Vec2s *Vec2sP;
00771
00776 typedef VectorInterface< Real32, VecStorage2<Real32> > Vec2f;
00777
00782 typedef Vec2f *Vec2fP;
00783
00788 typedef VectorInterface< Real64, VecStorage2<Real64> > Vec2d;
00789
00794 typedef Vec2d *Vec2dP;
00795
00800 typedef VectorInterface< Real128, VecStorage2<Real128> > Vec2ld;
00801
00806 typedef Vec2ld *Vec2ldP;
00807
00808
00813 typedef VectorInterface< UInt8, VecStorage3<UInt8> > Vec3ub;
00814
00819 typedef Vec3ub *Vec3ubP;
00820
00825 #ifndef OSG_NO_INT8_PNT
00826 typedef VectorInterface< Int8, VecStorage3<Int8> > Vec3b;
00827 #endif
00828
00833 #ifndef OSG_NO_INT8_PNT
00834 typedef Vec3b *Vec3bP;
00835 #endif
00836
00841 typedef VectorInterface< UInt16, VecStorage3<UInt16> > Vec3us;
00842
00847 typedef Vec3us *Vec3usP;
00848
00853 typedef VectorInterface< Int16, VecStorage3<Int16> > Vec3s;
00854
00859 typedef Vec3s *Vec3sP;
00860
00865 typedef VectorInterface< Real32, VecStorage3<Real32> > Vec3f;
00866
00871 typedef Vec3f *Vec3fP;
00872
00877 typedef VectorInterface< Real64, VecStorage3<Real64> > Vec3d;
00878
00883 typedef Vec3d *Vec3dP;
00884
00889 typedef VectorInterface< Real128, VecStorage3<Real128> > Vec3ld;
00890
00895 typedef Vec3ld *Vec3ldP;
00896
00897
00902 typedef VectorInterface< UInt8, VecStorage4<UInt8> > Vec4ub;
00903
00908 typedef Vec4ub *Vec4ubP;
00909
00914 #ifndef OSG_NO_INT8_PNT
00915 typedef VectorInterface< Int8, VecStorage4<Int8> > Vec4b;
00916 #endif
00917
00922 #ifndef OSG_NO_INT8_PNT
00923 typedef Vec4b *Vec4bP;
00924 #endif
00925
00930 typedef VectorInterface< UInt16, VecStorage4<UInt16> > Vec4us;
00931
00936 typedef Vec4us *Vec4usP;
00937
00942 typedef VectorInterface< Int16, VecStorage4<Int16> > Vec4s;
00943
00948 typedef Vec4s *Vec4sP;
00949
00954 typedef VectorInterface< Real32, VecStorage4<Real32> > Vec4f;
00955
00960 typedef Vec4f *Vec4fP;
00961
00966 typedef VectorInterface< Real64, VecStorage4<Real64> > Vec4d;
00967
00972 typedef Vec4d *Vec4dP;
00973
00978 typedef VectorInterface< Real128, VecStorage4<Real128> > Vec4ld;
00979
00984 typedef Vec4ld *Vec4ldP;
00985
00986
00987
00988
00993 typedef PointInterface< UInt8, VecStorage2<UInt8> > Pnt2ub;
00994
00999 typedef Pnt2ub *Pnt2ubP;
01000
01005 #ifndef OSG_NO_INT8_PNT
01006 typedef PointInterface< Int8, VecStorage2<Int8> > Pnt2b;
01007 #endif
01008
01013 #ifndef OSG_NO_INT8_PNT
01014 typedef Pnt2b *Pnt2bP;
01015 #endif
01016
01021 typedef PointInterface< UInt16, VecStorage2<UInt16> > Pnt2us;
01022
01027 typedef Pnt2us *Pnt2usP;
01028
01033 typedef PointInterface< Int16, VecStorage2<Int16> > Pnt2s;
01034
01039 typedef Pnt2s *Pnt2sP;
01040
01045 typedef PointInterface< Real32, VecStorage2<Real32> > Pnt2f;
01046
01051 typedef Pnt2f *Pnt2fP;
01052
01057 typedef PointInterface< Real64, VecStorage2<Real64> > Pnt2d;
01058
01063 typedef Pnt2d *Pnt2dP;
01064
01069 typedef PointInterface< Real128, VecStorage2<Real128> > Pnt2ld;
01070
01075 typedef Pnt2ld *Pnt2ldP;
01076
01077
01082 typedef PointInterface< UInt8, VecStorage3<UInt8> > Pnt3ub;
01083
01088 typedef Pnt3ub *Pnt3ubP;
01089
01094 #ifndef OSG_NO_INT8_PNT
01095 typedef PointInterface< Int8, VecStorage3<Int8> > Pnt3b;
01096 #endif
01097
01102 #ifndef OSG_NO_INT8_PNT
01103 typedef Pnt3b *Pnt3bP;
01104 #endif
01105
01110 typedef PointInterface< UInt16, VecStorage3<UInt16> > Pnt3us;
01111
01116 typedef Pnt3us *Pnt3usP;
01117
01122 typedef PointInterface< Int16, VecStorage3<Int16> > Pnt3s;
01123
01128 typedef Pnt3s *Pnt3sP;
01129
01134 typedef PointInterface< Real32, VecStorage3<Real32> > Pnt3f;
01135
01140 typedef Pnt3f *Pnt3fP;
01141
01146 typedef PointInterface< Real64, VecStorage3<Real64> > Pnt3d;
01147
01152 typedef Pnt3d *Pnt3dP;
01153
01158 typedef PointInterface< Real128, VecStorage3<Real128> > Pnt3ld;
01159
01164 typedef Pnt3ld *Pnt3ldP;
01165
01166
01171 typedef PointInterface< UInt8, VecStorage4<UInt8> > Pnt4ub;
01172
01177 typedef Pnt4ub *Pnt4ubP;
01178
01183 #ifndef OSG_NO_INT8_PNT
01184 typedef PointInterface< Int8, VecStorage4<Int8> > Pnt4b;
01185 #endif
01186
01191 #ifndef OSG_NO_INT8_PNT
01192 typedef Pnt4b *Pnt4bP;
01193 #endif
01194
01199 typedef PointInterface< UInt16, VecStorage4<UInt16> > Pnt4us;
01200
01205 typedef Pnt4us *Pnt4usP;
01206
01211 typedef PointInterface< Int16, VecStorage4<Int16> > Pnt4s;
01212
01217 typedef Pnt4s *Pnt4sP;
01218
01223 typedef PointInterface< Real32, VecStorage4<Real32> > Pnt4f;
01224
01229 typedef Pnt4f *Pnt4fP;
01230
01235 typedef PointInterface< Real64, VecStorage4<Real64> > Pnt4d;
01236
01241 typedef Pnt4d *Pnt4dP;
01242
01247 typedef PointInterface< Real128, VecStorage4<Real128> > Pnt4ld;
01248
01253 typedef Pnt4ld *Pnt4ldP;
01254
01255
01256 OSG_END_NAMESPACE
01257
01258 #include <OSGVector.inl>
01259
01260
01261 #ifdef __sgi
01262 #pragma reset woff 1209
01263 #endif
01264
01265 #define OSGVECTOR_HEADER_CVSID "@(#)$Id: $"
01266
01267 #endif
01268
01269