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 #include <stdio.h>
00040
00041 OSG_BEGIN_NAMESPACE
00042
00043
00044
00045
00046
00055 #if defined(__hpux)
00056 template <class ValueTypeT>
00057 const UInt32 VecStorage2<ValueTypeT>::_iSize;
00058 #endif
00059
00060
00061 template <class ValueTypeT> inline
00062 VecStorage2<ValueTypeT>::VecStorage2(void)
00063 {
00064 for(UInt32 i = 0; i < _iSize; i++)
00065 {
00066 _values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00067 }
00068 }
00069
00070
00071 template <class ValueTypeT> inline
00072 VecStorage2<ValueTypeT>::~VecStorage2(void)
00073 {
00074 }
00075
00076
00077 template <class ValueTypeT> inline
00078 void VecStorage2<ValueTypeT>::setValues(const ValueTypeT rVal1,
00079 const ValueTypeT rVal2)
00080 {
00081 _values[0] = rVal1;
00082 _values[1] = rVal2;
00083 }
00084
00085
00086 template <class ValueTypeT> inline
00087 void VecStorage2<ValueTypeT>::getSeparateValues(ValueTypeT &rVal1,
00088 ValueTypeT &rVal2) const
00089 {
00090 rVal1 = _values[0];
00091 rVal2 = _values[1];
00092 }
00093
00094
00095 template <class ValueTypeT> inline
00096 ValueTypeT VecStorage2<ValueTypeT>::x(void) const
00097 {
00098 return _values[0];
00099 }
00100
00101
00102 template <class ValueTypeT> inline
00103 ValueTypeT VecStorage2<ValueTypeT>::y(void) const
00104 {
00105 return _values[1];
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00123 #if defined(__hpux)
00124 template <class ValueTypeT>
00125 const UInt32 VecStorage3<ValueTypeT>::_iSize;
00126 #endif
00127
00128
00129 template <class ValueTypeT> inline
00130 VecStorage3<ValueTypeT>::VecStorage3(void)
00131 {
00132 for(UInt32 i = 0; i < _iSize; i++)
00133 {
00134 _values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00135 }
00136 }
00137
00138
00139 template <class ValueTypeT> inline
00140 VecStorage3<ValueTypeT>::~VecStorage3(void)
00141 {
00142 }
00143
00144
00145 template <class ValueTypeT> inline
00146 void VecStorage3<ValueTypeT>::setValues(const ValueTypeT rVal1,
00147 const ValueTypeT rVal2,
00148 const ValueTypeT rVal3)
00149 {
00150 _values[0] = rVal1;
00151 _values[1] = rVal2;
00152 _values[2] = rVal3;
00153 }
00154
00155
00156 template <class ValueTypeT> inline
00157 void VecStorage3<ValueTypeT>::getSeparateValues(ValueTypeT &rVal1,
00158 ValueTypeT &rVal2,
00159 ValueTypeT &rVal3) const
00160 {
00161 rVal1 = _values[0];
00162 rVal2 = _values[1];
00163 rVal3 = _values[2];
00164 }
00165
00166
00167 template <class ValueTypeT> inline
00168 ValueTypeT VecStorage3<ValueTypeT>::x(void) const
00169 {
00170 return _values[0];
00171 }
00172
00173
00174 template <class ValueTypeT> inline
00175 ValueTypeT VecStorage3<ValueTypeT>::y(void) const
00176 {
00177 return _values[1];
00178 }
00179
00180
00181 template <class ValueTypeT> inline
00182 ValueTypeT VecStorage3<ValueTypeT>::z(void) const
00183 {
00184 return _values[2];
00185 }
00186
00187
00188
00189
00190
00191
00192
00193
00202 #if defined(__hpux)
00203 template <class ValueTypeT> inline
00204 const UInt32 VecStorage4<ValueTypeT>::_iSize;
00205 #endif
00206
00207
00208 template <class ValueTypeT> inline
00209 VecStorage4<ValueTypeT>::VecStorage4(void)
00210 {
00211 for(UInt32 i = 0; i < _iSize; i++)
00212 {
00213 _values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00214 }
00215 }
00216
00217
00218 template <class ValueTypeT> inline
00219 VecStorage4<ValueTypeT>::~VecStorage4(void)
00220 {
00221 }
00222
00223
00224 template <class ValueTypeT> inline
00225 void VecStorage4<ValueTypeT>::setValues(const ValueTypeT rVal1,
00226 const ValueTypeT rVal2,
00227 const ValueTypeT rVal3,
00228 const ValueTypeT rVal4)
00229 {
00230 _values[0] = rVal1;
00231 _values[1] = rVal2;
00232 _values[2] = rVal3;
00233 _values[3] = rVal4;
00234 }
00235
00236
00237 template <class ValueTypeT> inline
00238 void VecStorage4<ValueTypeT>::getSeparateValues(ValueTypeT &rVal1,
00239 ValueTypeT &rVal2,
00240 ValueTypeT &rVal3,
00241 ValueTypeT &rVal4) const
00242 {
00243 rVal1 = _values[0];
00244 rVal2 = _values[1];
00245 rVal3 = _values[2];
00246 rVal4 = _values[3];
00247 }
00248
00249
00250 template <class ValueTypeT> inline
00251 ValueTypeT VecStorage4<ValueTypeT>::x(void) const
00252 {
00253 return _values[0];
00254 }
00255
00256
00257 template <class ValueTypeT> inline
00258 ValueTypeT VecStorage4<ValueTypeT>::y(void) const
00259 {
00260 return _values[1];
00261 }
00262
00263
00264 template <class ValueTypeT> inline
00265 ValueTypeT VecStorage4<ValueTypeT>::z(void) const
00266 {
00267 return _values[2];
00268 }
00269
00270
00271 template <class ValueTypeT> inline
00272 ValueTypeT VecStorage4<ValueTypeT>::w(void) const
00273 {
00274 return _values[3];
00275 }
00276
00277
00278
00279
00280
00281
00282
00299 #ifndef darwin
00300 template <class ValueTypeT,
00301 class StorageInterfaceT>
00302 const PointInterface<ValueTypeT, StorageInterfaceT>
00303 PointInterface<ValueTypeT, StorageInterfaceT>::Null;
00304 #endif
00305
00306
00307 template <class ValueTypeT,
00308 class StorageInterfaceT> inline
00309 PointInterface<ValueTypeT, StorageInterfaceT>::PointInterface(void) :
00310 Inherited()
00311 {
00312 }
00313
00319 template <class ValueTypeT,
00320 class StorageInterfaceT> inline
00321 PointInterface<ValueTypeT,
00322 StorageInterfaceT>::PointInterface(const ValueTypeT *pVals) :
00323 Inherited()
00324 {
00325 if(pVals == NULL)
00326 {
00327 for(UInt32 i = 0; i < Self::_iSize; i++)
00328 {
00329 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00330 }
00331 }
00332 else
00333 {
00334 for(UInt32 i = 0; i < Self::_iSize; i++)
00335 {
00336 Self::_values[i] = pVals[i];
00337 }
00338 }
00339 }
00340
00346 template <class ValueTypeT,
00347 class StorageInterfaceT> inline
00348 PointInterface<ValueTypeT,
00349 StorageInterfaceT>::PointInterface(ValueTypeT *pVals) :
00350 Inherited()
00351 {
00352 if(pVals == NULL)
00353 {
00354 for(UInt32 i = 0; i < Self::_iSize; i++)
00355 {
00356 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00357 }
00358 }
00359 else
00360 {
00361 for(UInt32 i = 0; i < Self::_iSize; i++)
00362 {
00363 Self::_values[i] = pVals[i];
00364 }
00365 }
00366 }
00367
00368 #if 0
00369
00391 #ifdef __sgi
00392 #pragma set woff 1209
00393 #endif
00394
00395 template <class ValueTypeT,
00396 class StorageInterfaceT>
00397 template <class VectorT> inline
00398 PointInterface<ValueTypeT,
00399 StorageInterfaceT>::PointInterface(const VectorT &vec) :
00400 Inherited()
00401 {
00402 if(Self::_iSize <= VectorT::_iSize)
00403 {
00404 for(UInt32 i = 0; i < Self::_iSize; i++)
00405 {
00406 Self::_values[i] = vec.getValues()[i];
00407 }
00408 }
00409 else
00410 {
00411 UInt32 i;
00412 for(i = 0; i < VectorT::_iSize; i++)
00413 {
00414 Self::_values[i] = vec.getValues()[i];
00415 }
00416 for(i = VectorT::_iSize; i < Self::_iSize; i++)
00417 {
00418 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00419 }
00420 }
00421 }
00422
00423 #ifdef __sgi
00424 #pragma reset woff 1209
00425 #endif
00426
00427 #endif
00428
00429
00430 template <class ValueTypeT,
00431 class StorageInterfaceT> inline
00432 PointInterface<ValueTypeT, StorageInterfaceT>::PointInterface(
00433 const PointInterface &source) :
00434
00435 Inherited()
00436 {
00437 for(UInt32 i = 0; i < Self::_iSize; i++)
00438 {
00439 Self::_values[i] = source._values[i];
00440 }
00441 }
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462 #ifdef __sgi
00463 #pragma set woff 1209
00464 #endif
00465
00467
00468 template <class ValueTypeT,
00469 class StorageInterfaceT> inline
00470 PointInterface<ValueTypeT,
00471 StorageInterfaceT>::PointInterface(const ValueTypeT rVal1,
00472 const ValueTypeT rVal2) :
00473 Inherited()
00474 {
00475 Self::_values[0] = rVal1;
00476
00477 if(Self::_iSize == 2)
00478 {
00479 Self::_values[1] = rVal2;
00480 }
00481 else if(Self::_iSize >= 3)
00482 {
00483 Self::_values[1] = rVal2;
00484
00485 for(UInt32 i = 2; i < Self::_iSize; i++)
00486 {
00487 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00488 }
00489 }
00490 }
00491
00492 #ifdef __sgi
00493 #pragma reset woff 1209
00494
00495 #pragma set woff 1209
00496 #endif
00497
00499
00500 template <class ValueTypeT,
00501 class StorageInterfaceT> inline
00502 PointInterface<ValueTypeT,
00503 StorageInterfaceT>::PointInterface(const ValueTypeT rVal1,
00504 const ValueTypeT rVal2,
00505 const ValueTypeT rVal3) :
00506 Inherited()
00507 {
00508 Self::_values[0] = rVal1;
00509
00510 if(Self::_iSize == 2)
00511 {
00512 Self::_values[1] = rVal2;
00513 }
00514 else if(Self::_iSize == 3)
00515 {
00516 Self::_values[1] = rVal2;
00517 Self::_values[2] = rVal3;
00518 }
00519 else if(Self::_iSize >= 4)
00520 {
00521 Self::_values[1] = rVal2;
00522 Self::_values[2] = rVal3;
00523
00524 for(UInt32 i = 3; i < Self::_iSize; i++)
00525 {
00526 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00527 }
00528 }
00529 }
00530
00531 #ifdef __sgi
00532 #pragma reset woff 1209
00533
00534 #pragma set woff 1209
00535 #endif
00536
00538
00539 template <class ValueTypeT,
00540 class StorageInterfaceT> inline
00541 PointInterface<ValueTypeT,
00542 StorageInterfaceT>::PointInterface(const ValueTypeT rVal1,
00543 const ValueTypeT rVal2,
00544 const ValueTypeT rVal3,
00545 const ValueTypeT rVal4) :
00546 Inherited()
00547 {
00548 Self::_values[0] = rVal1;
00549
00550 if(Self::_iSize == 2)
00551 {
00552 Self::_values[1] = rVal2;
00553 }
00554 else if(Self::_iSize == 3)
00555 {
00556 Self::_values[1] = rVal2;
00557 Self::_values[2] = rVal3;
00558 }
00559 else if(Self::_iSize == 4)
00560 {
00561 Self::_values[1] = rVal2;
00562 Self::_values[2] = rVal3;
00563 Self::_values[3] = rVal4;
00564 }
00565 else if(Self::_iSize >= 5)
00566 {
00567 Self::_values[1] = rVal2;
00568 Self::_values[2] = rVal3;
00569 Self::_values[3] = rVal4;
00570
00571 for(UInt32 i = 4; i < Self::_iSize; i++)
00572 {
00573 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00574 }
00575 }
00576 }
00577
00578 #ifdef __sgi
00579 #pragma reset woff 1209
00580 #endif
00581
00582
00583
00584
00585 template <class ValueTypeT,
00586 class StorageInterfaceT> inline
00587 PointInterface<ValueTypeT, StorageInterfaceT>::~PointInterface(void)
00588 {
00589 }
00590
00591
00592
00593
00594 template <class ValueTypeT,
00595 class StorageInterfaceT> inline
00596 void PointInterface<ValueTypeT, StorageInterfaceT>::setNull(void)
00597 {
00598 for(UInt32 i = 0; i < Self::_iSize; i++)
00599 {
00600 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00601 }
00602 }
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616 template <class ValueTypeT,
00617 class StorageInterfaceT> inline
00618 void PointInterface<ValueTypeT,
00619 StorageInterfaceT>::setValue(const PointInterface &vec)
00620 {
00621 for(UInt32 i = 0; i < Self::_iSize; i++)
00622 {
00623 Self::_values[i] = vec._values[i];
00624 }
00625 }
00626
00627 #if 0
00628
00651 #ifdef __sgi
00652 #pragma set woff 1209
00653 #endif
00654
00655 template <class ValueTypeT,
00656 class StorageInterfaceT>
00657 template <class VectorT> inline
00658 void PointInterface<ValueTypeT,
00659 StorageInterfaceT>::setValue(const VectorT &vec)
00660 {
00661 for(UInt32 i = 0;
00662 i < (Self::_iSize < VectorT::_iSize ?
00663 Self::_iSize : VectorT::_iSize);
00664 ++i)
00665 {
00666 Self::_values[i] = vec.getValues()[i];
00667 }
00668 }
00669
00670 #ifdef __sgi
00671 #pragma reset woff 1209
00672 #endif
00673 #endif
00674
00676
00677 template <class ValueTypeT,
00678 class StorageInterfaceT> inline
00679 void PointInterface<ValueTypeT,
00680 StorageInterfaceT>::setValue(const ValueTypeT *pVals)
00681 {
00682 for(UInt32 i = 0; i < Self::_iSize; i++)
00683 {
00684 Self::_values[i] = pVals[i];
00685 }
00686 }
00687
00689
00690 template <class ValueTypeT,
00691 class StorageInterfaceT> inline
00692 void PointInterface<ValueTypeT,
00693 StorageInterfaceT>::setValue(ValueTypeT *pVals)
00694 {
00695 setValue(static_cast<const ValueTypeT *>(pVals));
00696 }
00697
00702 template <class ValueTypeT,
00703 class StorageInterfaceT> inline
00704 void PointInterface<ValueTypeT,
00705 StorageInterfaceT>::setValueFromCString(
00706 const Char8 *szString)
00707 {
00708 UInt32 i;
00709 UInt32 numOfToken = Self::_iSize;
00710
00711 Char8 *c = const_cast<Char8 *>(szString);
00712 Char8 *tokenC = 0;
00713
00714 Char8 token[256];
00715
00716 if(szString == NULL || (*szString) == '\0')
00717 {
00718 for(i = 0; i < Self::_iSize; i++)
00719 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00720
00721 return;
00722 }
00723
00724 for (i = 0; i < numOfToken; c++)
00725 {
00726 switch (*c)
00727 {
00728 case '\0':
00729 if(tokenC)
00730 {
00731 *tokenC = 0;
00732 Self::_values[i++] =
00733 TypeTraits<ValueTypeT>::getFromString(token);
00734 }
00735
00736 while (i < numOfToken)
00737 {
00738 Self::_values[i++] =
00739 TypeTraits<ValueTypeT>::getZeroElement();
00740 }
00741 break;
00742
00743 case ' ' :
00744 case '\t':
00745 case '\n':
00746 case ',':
00747 if(tokenC)
00748 {
00749 *tokenC = 0;
00750 Self::_values[i++] =
00751 TypeTraits<ValueTypeT>::getFromString(token);
00752 tokenC = 0;
00753 }
00754 break;
00755 default:
00756 if(!tokenC)
00757 {
00758 tokenC = token;
00759 }
00760 *tokenC++ = *c;
00761 break;
00762 }
00763 }
00764 }
00765
00770 template <class ValueTypeT,
00771 class StorageInterfaceT> inline
00772 void PointInterface<ValueTypeT,
00773 StorageInterfaceT>::setValueFromCString(Char8 *szString)
00774 {
00775 setValueFromCString(static_cast<const Char8 *>(szString));
00776 }
00777
00778
00779 #ifndef OSG_DISABLE_DEPRECATED
00780 template <class ValueTypeT,
00781 class StorageInterfaceT> inline
00782 void PointInterface<ValueTypeT,
00783 StorageInterfaceT>::setValue(const Char8 *szString)
00784 {
00785 setValueFromCString(szString);
00786 }
00787
00788 template <class ValueTypeT,
00789 class StorageInterfaceT> inline
00790 void PointInterface<ValueTypeT,
00791 StorageInterfaceT>::setValue(Char8 *szString)
00792 {
00793 setValueFromCString(szString);
00794 }
00795 #endif
00796
00797
00798
00799
00801
00802 template <class ValueTypeT,
00803 class StorageInterfaceT> inline
00804 ValueTypeT *PointInterface<ValueTypeT,
00805 StorageInterfaceT>::getValues(void)
00806 {
00807 return Self::_values;
00808 }
00809
00811
00812 template <class ValueTypeT,
00813 class StorageInterfaceT> inline
00814 const ValueTypeT *PointInterface<ValueTypeT,
00815 StorageInterfaceT>::getValues(void) const
00816 {
00817 return Self::_values;
00818 }
00819
00820
00821
00822
00824
00825 template <class ValueTypeT,
00826 class StorageInterfaceT> inline
00827 bool PointInterface<ValueTypeT,
00828 StorageInterfaceT>::isZero(void) const
00829 {
00830 bool returnValue = true;
00831
00832 for(UInt32 i = 0; i < Self::_iSize; i++)
00833 {
00834 returnValue &= ((Self::_values[i] <= Eps) &&
00835 (Self::_values[i] >= -Eps));
00836 }
00837
00838 return returnValue;
00839 }
00840
00842
00843 template <class ValueTypeT,
00844 class StorageInterfaceT> inline
00845 void PointInterface<ValueTypeT, StorageInterfaceT>::negate(void)
00846 {
00847 for(UInt32 i = 0; i < Self::_iSize; i++)
00848 {
00849 Self::_values[i] = -Self::_values[i];
00850 }
00851 }
00852
00854
00855 template <class ValueTypeT,
00856 class StorageInterfaceT> inline
00857 bool PointInterface<ValueTypeT, StorageInterfaceT>::equals(
00858 const PointInterface &vec,
00859 const ValueTypeT tolerance) const
00860 {
00861 bool returnValue = true;
00862
00863 for(UInt32 i = 0; i < Self::_iSize; i++)
00864 {
00865 returnValue &=
00866 ( (Self::_values[i] - vec ._values[i] <= tolerance) &&
00867 (vec ._values[i] - Self::_values[i] <= tolerance));
00868 }
00869
00870 return returnValue;
00871 }
00872
00874
00875 template <class ValueTypeT,
00876 class StorageInterfaceT> inline
00877 typename PointInterface<ValueTypeT,
00878 StorageInterfaceT>::VecInterface &
00879 PointInterface<ValueTypeT,
00880 StorageInterfaceT>::subZero(void)
00881 {
00882 return *(static_cast<VecInterface *>(this));
00883 }
00884
00886
00887 template <class ValueTypeT,
00888 class StorageInterfaceT> inline
00889 const typename PointInterface<ValueTypeT,
00890 StorageInterfaceT>::VecInterface &
00891 PointInterface<ValueTypeT,
00892 StorageInterfaceT>::subZero(void) const
00893 {
00894 return *(static_cast<const VecInterface *>(this));
00895 }
00896
00897
00899
00900 template <class ValueTypeT,
00901 class StorageInterfaceT> inline
00902 typename PointInterface<ValueTypeT,
00903 StorageInterfaceT>::RealReturnType
00904 PointInterface<ValueTypeT, StorageInterfaceT>::dist(const PointInterface &vec)
00905 const
00906 {
00907 return osgsqrt(dist2(vec));
00908 }
00909
00911
00912 template <class ValueTypeT,
00913 class StorageInterfaceT> inline
00914 typename PointInterface<ValueTypeT,
00915 StorageInterfaceT>::RealReturnType
00916 PointInterface<ValueTypeT, StorageInterfaceT>::dist2(const PointInterface &vec)
00917 const
00918 {
00919 RealReturnType returnValue = 0;
00920 RealReturnType tmp;
00921
00922 for(UInt32 i = 0; i < Self::_iSize; i++)
00923 {
00924 tmp = Self::_values[i] - vec._values[i];
00925
00926 returnValue += tmp * tmp;
00927 }
00928
00929 return returnValue;
00930 }
00931
00933
00934 template <class ValueTypeT,
00935 class StorageInterfaceT> inline
00936 typename PointInterface<ValueTypeT,
00937 StorageInterfaceT>::RealReturnType
00938 PointInterface<ValueTypeT, StorageInterfaceT>::maxValue(void)
00939 const
00940 {
00941 RealReturnType returnValue = TypeTraits<RealReturnType>::getMin();
00942
00943 for(UInt32 i = 0; i < Self::_iSize; i++)
00944 {
00945 if(Self::_values[i] > returnValue)
00946 returnValue = Self::_values[i];
00947 }
00948
00949 return returnValue;
00950 }
00951
00952
00953
00954
00956
00957 template <class ValueTypeT,
00958 class StorageInterfaceT> inline
00959 void PointInterface<ValueTypeT,
00960 StorageInterfaceT>::operator *=(const ValueTypeT val)
00961 {
00962 for(UInt32 i = 0; i < Self::_iSize; i++)
00963 {
00964 Self::_values[i] *= val;
00965 }
00966 }
00967
00969
00970 template <class ValueTypeT,
00971 class StorageInterfaceT> inline
00972 void PointInterface<ValueTypeT,
00973 StorageInterfaceT>::operator /=(const ValueTypeT val)
00974 {
00975 for(UInt32 i = 0; i < Self::_iSize; i++)
00976 {
00977 Self::_values[i] /= val;
00978 }
00979 }
00980
00981
00983
00984 template <class ValueTypeT,
00985 class StorageInterfaceT> inline
00986 typename PointInterface<ValueTypeT, StorageInterfaceT>::VecInterface
00987 PointInterface<ValueTypeT, StorageInterfaceT>::operator -(
00988 const PointInterface &vec) const
00989 {
00990 VecInterface returnValue(*this);
00991
00992 for(UInt32 i = 0; i < Self::_iSize; i++)
00993 {
00994 returnValue[i] -= vec[i];
00995 }
00996
00997 return returnValue;
00998 }
00999
01001
01002 template <class ValueTypeT,
01003 class StorageInterfaceT> inline
01004 PointInterface<ValueTypeT, StorageInterfaceT>
01005 PointInterface<ValueTypeT, StorageInterfaceT>::operator + (
01006 const VecInterface &vec) const
01007 {
01008 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01009
01010 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01011 {
01012 returnValue[i] = Self::_values[i] + vec[i];
01013 }
01014
01015 return returnValue;
01016 }
01017
01019
01020 template <class ValueTypeT,
01021 class StorageInterfaceT> inline
01022 PointInterface<ValueTypeT, StorageInterfaceT>
01023 PointInterface<ValueTypeT, StorageInterfaceT>::operator - (
01024 const VecInterface &vec) const
01025 {
01026 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01027
01028 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01029 {
01030 returnValue[i] = Self::_values[i] - vec[i];
01031 }
01032
01033 return returnValue;
01034 }
01035
01037
01038 template <class ValueTypeT,
01039 class StorageInterfaceT> inline
01040 PointInterface <ValueTypeT, StorageInterfaceT>
01041 PointInterface<ValueTypeT, StorageInterfaceT>::operator * (
01042 const ValueTypeT rVal) const
01043 {
01044 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01045
01046 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01047 {
01048 returnValue[i] = Self::_values[i] * rVal;
01049 }
01050
01051 return returnValue;
01052 }
01053
01054
01055 #if 0
01056
01057
01058 template <class ValueTypeT,
01059 class StorageInterfaceT> inline
01060 PointInterface <ValueTypeT, StorageInterfaceT>
01061 operator * (
01062 const PointInterface <ValueTypeT, StorageInterfaceT> &vec,
01063 const ValueTypeT rVal)
01064 {
01065 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01066
01067 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01068 {
01069 returnValue[i] = vec._values[i] * rVal;
01070 }
01071
01072 return returnValue;
01073 }
01074 #endif
01075
01077
01078 template <class ValueTypeT,
01079 class StorageInterfaceT> inline
01080 PointInterface<ValueTypeT, StorageInterfaceT>
01081 PointInterface<ValueTypeT, StorageInterfaceT>::operator -(void)
01082 {
01083 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01084
01085 for(UInt32 i = 0; i < Self::_iSize; i++)
01086 {
01087 returnValue._values[i] = - Self::_values[i];
01088 }
01089
01090 return returnValue;
01091 }
01092
01094
01095 template <class ValueTypeT,
01096 class StorageInterfaceT> inline
01097 void PointInterface<ValueTypeT, StorageInterfaceT>::operator +=(
01098 const VecInterface &vec)
01099 {
01100 for(UInt32 i = 0; i < Self::_iSize; i++)
01101 {
01102 Self::_values[i] += vec._values[i];
01103 }
01104 }
01105
01107
01108 template <class ValueTypeT,
01109 class StorageInterfaceT> inline
01110 void PointInterface<ValueTypeT, StorageInterfaceT>::operator -=(
01111 const VecInterface &vec)
01112 {
01113 for(UInt32 i = 0; i < Self::_iSize; i++)
01114 {
01115 Self::_values[i] -= vec._values[i];
01116 }
01117 }
01118
01119
01120
01121
01122 template <class ValueTypeT,
01123 class StorageInterfaceT> inline
01124 ValueTypeT &PointInterface<ValueTypeT,
01125 StorageInterfaceT>::operator[](const UInt32 uiVal)
01126 {
01127 return Self::_values[uiVal];
01128 }
01129
01130 template <class ValueTypeT,
01131 class StorageInterfaceT> inline
01132 const ValueTypeT &
01133 PointInterface<ValueTypeT,
01134 StorageInterfaceT>::operator[](const UInt32 uiVal) const
01135 {
01136 return Self::_values[uiVal];
01137 }
01138
01139 #if 0
01140 template <class ValueTypeT,
01141 class StorageInterfaceT> inline
01142 PointInterface<ValueTypeT, StorageInterfaceT>::operator
01143 ValueTypeT *(void)
01144 {
01145 return Self::_values;
01146 }
01147
01148 template <class ValueTypeT,
01149 class StorageInterfaceT> inline
01150 PointInterface<ValueTypeT, StorageInterfaceT>::operator
01151 const ValueTypeT *(void)
01152 {
01153 return Self::_values;
01154 }
01155 #endif
01156
01157
01158
01159
01160 template <class ValueTypeT,
01161 class StorageInterfaceT> inline
01162 PointInterface<ValueTypeT, StorageInterfaceT> &
01163 PointInterface<ValueTypeT, StorageInterfaceT>::operator =(
01164 const PointInterface &source)
01165 {
01166 if(this == &source)
01167 return *this;
01168
01169 for(UInt32 i = 0; i < Self::_iSize; i++)
01170 {
01171 Self::_values[i] = source._values[i];
01172 }
01173
01174 return *this;
01175 }
01176
01177 template <class ValueTypeT,
01178 class StorageInterfaceT> inline
01179 PointInterface<ValueTypeT, StorageInterfaceT> &
01180 PointInterface<ValueTypeT,
01181 StorageInterfaceT>::operator =(const VecInterface &source)
01182 {
01183 static PointInterface<ValueTypeT, StorageInterfaceT> dummy;
01184 PointInterface<ValueTypeT,
01185 StorageInterfaceT>::error_cannot_assign_vector;
01186 return dummy;
01187 }
01188
01189
01190
01191
01192 template <class ValueTypeT,
01193 class StorageInterfaceT> inline
01194 bool PointInterface<ValueTypeT, StorageInterfaceT>::operator < (
01195 const PointInterface &other) const
01196 {
01197 bool ret = true;
01198
01199 for(UInt32 i = 0; i < Self::_iSize; i++)
01200 {
01201 if(Self::_values[i] > other._values[i])
01202 {
01203 ret = false;
01204 break;
01205 }
01206 if(Self::_values[i] < other._values[i])
01207 {
01208 break;
01209 }
01210 }
01211
01212 return ret;
01213 }
01214
01216
01217 template <class ValueTypeT,
01218 class StorageInterfaceT> inline
01219 bool PointInterface<ValueTypeT, StorageInterfaceT>::operator == (
01220 const PointInterface &other) const
01221 {
01222
01223 return Self::equals(other, ValueTypeT(Eps));
01224 }
01225
01227
01228 template <class ValueTypeT,
01229 class StorageInterfaceT> inline
01230 bool PointInterface<ValueTypeT, StorageInterfaceT>::operator != (
01231 const PointInterface &other) const
01232 {
01233 return ! (*this == other);
01234 }
01235
01236
01237
01238
01240
01241 template <class ValueTypeT,
01242 class StorageInterfaceT> inline
01243 PointInterface<ValueTypeT, StorageInterfaceT>
01244 operator *(const ValueTypeT val,
01245 const PointInterface<ValueTypeT,
01246 StorageInterfaceT> &vec)
01247 {
01248 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01249
01250 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01251 {
01252 returnValue[i] = vec[i] * val;
01253 }
01254
01255 return returnValue;
01256 }
01257
01259
01260 template <class ValueTypeT,
01261 class StorageInterfaceT> inline
01262 std::ostream &operator <<( std::ostream &os,
01263 const PointInterface<ValueTypeT,
01264 StorageInterfaceT> &obj)
01265 {
01266 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01267 {
01268 os << obj[i];
01269
01270 if(i != StorageInterfaceT::_iSize - 1)
01271 os << ", ";
01272 }
01273
01274 return os;
01275 }
01276
01277
01278
01279
01280
01281
01282
01283
01296 template <class ValueTypeT,
01297 class StorageInterfaceT>
01298 const VectorInterface<ValueTypeT, StorageInterfaceT>
01299 VectorInterface<ValueTypeT, StorageInterfaceT>::Null;
01300
01301
01302
01303
01304 template <class ValueTypeT,
01305 class StorageInterfaceT> inline
01306 VectorInterface<ValueTypeT, StorageInterfaceT>::VectorInterface(void) :
01307 Inherited()
01308 {
01309 for(UInt32 i = 0; i < Self::_iSize; i++)
01310 {
01311 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
01312 }
01313 }
01314
01315
01321 template <class ValueTypeT,
01322 class StorageInterfaceT> inline
01323 VectorInterface<ValueTypeT,
01324 StorageInterfaceT>::VectorInterface(const ValueTypeT *pVals) :
01325 Inherited(pVals)
01326 {
01327 }
01328
01334 template <class ValueTypeT,
01335 class StorageInterfaceT> inline
01336 VectorInterface<ValueTypeT,
01337 StorageInterfaceT>::VectorInterface(ValueTypeT *pVals) :
01338 Inherited(pVals)
01339 {
01340 }
01341
01342 #if 0
01343
01364 #ifdef __sgi
01365 #pragma set woff 1209
01366 #endif
01367
01368 template <class ValueTypeT,
01369 class StorageInterfaceT>
01370 template <class VectorT > inline
01371 VectorInterface<ValueTypeT,
01372 StorageInterfaceT>::VectorInterface(const VectorT &vec) :
01373 Inherited()
01374 {
01375 if(Self::_iSize <= VectorT::_iSize)
01376 {
01377 for(UInt32 i = 0; i < Self::_iSize; i++)
01378 {
01379 Self::_values[i] = vec.getValues()[i];
01380 }
01381 }
01382 else
01383 {
01384 UInt32 i;
01385 for(i = 0; i < VectorT::_iSize; i++)
01386 {
01387 Self::_values[i] = vec.getValues()[i];
01388 }
01389 for(i = VectorT::_iSize; i < Self::_iSize; i++)
01390 {
01391 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
01392 }
01393 }
01394 }
01395
01396 #ifdef __sgi
01397 #pragma reset woff 1209
01398 #endif
01399 #endif
01400
01401 template <class ValueTypeT,
01402 class StorageInterfaceT> inline
01403 VectorInterface<ValueTypeT, StorageInterfaceT>::VectorInterface(
01404 const VectorInterface &source) :
01405
01406 Inherited(source)
01407 {
01408 }
01409
01410
01411
01412
01413
01414
01415
01416
01417
01418
01419
01420
01421
01422
01423
01424
01425
01426
01427 template <class ValueTypeT,
01428 class StorageInterfaceT> inline
01429 VectorInterface<ValueTypeT,
01430 StorageInterfaceT>::VectorInterface(const ValueTypeT rVal1,
01431 const ValueTypeT rVal2) :
01432
01433 Inherited(rVal1, rVal2)
01434 {
01435 }
01436
01437 template <class ValueTypeT,
01438 class StorageInterfaceT> inline
01439 VectorInterface<ValueTypeT,
01440 StorageInterfaceT>::VectorInterface(const ValueTypeT rVal1,
01441 const ValueTypeT rVal2,
01442 const ValueTypeT rVal3) :
01443
01444 Inherited(rVal1, rVal2, rVal3)
01445 {
01446 }
01447
01448 template <class ValueTypeT,
01449 class StorageInterfaceT> inline
01450 VectorInterface<ValueTypeT,
01451 StorageInterfaceT>::VectorInterface(const ValueTypeT rVal1,
01452 const ValueTypeT rVal2,
01453 const ValueTypeT rVal3,
01454 const ValueTypeT rVal4) :
01455
01456 Inherited(rVal1, rVal2, rVal3, rVal4)
01457 {
01458 }
01459
01460
01461
01462
01463
01464 template <class ValueTypeT,
01465 class StorageInterfaceT> inline
01466 VectorInterface<ValueTypeT,
01467 StorageInterfaceT>::~VectorInterface(void)
01468 {
01469 }
01470
01471
01472
01473
01475
01476 template <class ValueTypeT,
01477 class StorageInterfaceT> inline
01478 typename VectorInterface<ValueTypeT, StorageInterfaceT>::RealReturnType
01479 VectorInterface<ValueTypeT, StorageInterfaceT>::length(void) const
01480 {
01481 return osgsqrt(Self::squareLength());
01482 }
01483
01485
01486 template <class ValueTypeT,
01487 class StorageInterfaceT> inline
01488 typename VectorInterface<ValueTypeT, StorageInterfaceT>::RealReturnType
01489 VectorInterface<ValueTypeT, StorageInterfaceT>::squareLength(void) const
01490 {
01491 RealReturnType rTmpVal = RealReturnType(Self::_values[0] *
01492 Self::_values[0] );
01493
01494 for(UInt32 i = 1; i < Self::_iSize; i++)
01495 {
01496 rTmpVal += Self::_values[i] * Self::_values[i];
01497 }
01498
01499 return rTmpVal;
01500 }
01501
01503
01504 template <class ValueTypeT,
01505 class StorageInterfaceT> inline
01506 void VectorInterface<ValueTypeT, StorageInterfaceT>::normalize(void)
01507 {
01508 ValueTypeT rLength = ValueTypeT(length());
01509
01510 if(osgabs(rLength) < Eps)
01511 {
01512 rLength = TypeTraits<ValueTypeT>::getOneElement();
01513 }
01514 else
01515 {
01516 rLength = TypeTraits<ValueTypeT>::getOneElement() / rLength;
01517 }
01518
01519 for(UInt32 i = 0; i < Self::_iSize; i++)
01520 {
01521 Self::_values[i] *= rLength;
01522 }
01523 }
01524
01525 #ifdef __sgi
01526 #pragma set woff 1209
01527 #endif
01528
01533 template <class ValueTypeT,
01534 class StorageInterfaceT> inline
01535 VectorInterface<ValueTypeT, StorageInterfaceT>
01536 VectorInterface<ValueTypeT,
01537 StorageInterfaceT>::cross(const VectorInterface &vec) const
01538 {
01539 VectorInterface<ValueTypeT, StorageInterfaceT> returnValue;
01540
01541 if(Self::_iSize >= 3)
01542 {
01543 returnValue[0] =
01544 Self::_values[1] * vec._values[2] -
01545 Self::_values[2] * vec._values[1];
01546 returnValue[1] =
01547 Self::_values[2] * vec._values[0] -
01548 Self::_values[0] * vec._values[2];
01549 returnValue[2] =
01550 Self::_values[0] * vec._values[1] -
01551 Self::_values[1] * vec._values[0];
01552 }
01553 else
01554 {
01555
01556 fprintf(stderr, "cross only implemented for size 3\n");
01557 }
01558
01559