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 darwinXXX
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
00314 template <class ValueTypeT,
00315 class StorageInterfaceT>
00316 template <class ValueType2T,
00317 class StorageInterface2T>
00318 inline
00319 PointInterface<ValueTypeT, StorageInterfaceT>::PointInterface(const PointInterface<ValueType2T, StorageInterface2T> &vec )
00320 {
00321 typedef PointInterface<ValueType2T, StorageInterface2T> VectorT;
00322
00323 if(Self::_iSize <= VectorT::_iSize)
00324 {
00325 for(UInt32 i = 0; i < Self::_iSize; i++)
00326 {
00327 Self::_values[i] = vec.getValues()[i];
00328 }
00329 }
00330 else
00331 {
00332 UInt32 i;
00333 for(i = 0; i < VectorT::_iSize; i++)
00334 {
00335 Self::_values[i] = vec.getValues()[i];
00336 }
00337 for(i = VectorT::_iSize; i < Self::_iSize; i++)
00338 {
00339 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00340 }
00341 }
00342 }
00343
00344 template <class ValueTypeT,
00345 class StorageInterfaceT>
00346 template <class ValueType2T,
00347 class StorageInterface2T>
00348 inline
00349 PointInterface<ValueTypeT, StorageInterfaceT>::PointInterface(const VectorInterface<ValueType2T, StorageInterface2T> &vec )
00350 {
00351 typedef VectorInterface<ValueType2T, StorageInterface2T> VectorT;
00352
00353 if(Self::_iSize <= VectorT::_iSize)
00354 {
00355 for(UInt32 i = 0; i < Self::_iSize; i++)
00356 {
00357 Self::_values[i] = vec.getValues()[i];
00358 }
00359 }
00360 else
00361 {
00362 UInt32 i;
00363 for(i = 0; i < VectorT::_iSize; i++)
00364 {
00365 Self::_values[i] = vec.getValues()[i];
00366 }
00367 for(i = VectorT::_iSize; i < Self::_iSize; i++)
00368 {
00369 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00370 }
00371 }
00372 }
00373
00374
00380 template <class ValueTypeT,
00381 class StorageInterfaceT> inline
00382 PointInterface<ValueTypeT,
00383 StorageInterfaceT>::PointInterface(const ValueTypeT *pVals) :
00384 Inherited()
00385 {
00386 if(pVals == NULL)
00387 {
00388 for(UInt32 i = 0; i < Self::_iSize; i++)
00389 {
00390 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00391 }
00392 }
00393 else
00394 {
00395 for(UInt32 i = 0; i < Self::_iSize; i++)
00396 {
00397 Self::_values[i] = pVals[i];
00398 }
00399 }
00400 }
00401
00407 template <class ValueTypeT,
00408 class StorageInterfaceT> inline
00409 PointInterface<ValueTypeT,
00410 StorageInterfaceT>::PointInterface(ValueTypeT *pVals) :
00411 Inherited()
00412 {
00413 if(pVals == NULL)
00414 {
00415 for(UInt32 i = 0; i < Self::_iSize; i++)
00416 {
00417 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00418 }
00419 }
00420 else
00421 {
00422 for(UInt32 i = 0; i < Self::_iSize; i++)
00423 {
00424 Self::_values[i] = pVals[i];
00425 }
00426 }
00427 }
00428
00429 template <class ValueTypeT,
00430 class StorageInterfaceT> inline
00431 PointInterface<ValueTypeT, StorageInterfaceT>::PointInterface(
00432 const PointInterface &source) :
00433
00434 Inherited()
00435 {
00436 for(UInt32 i = 0; i < Self::_iSize; i++)
00437 {
00438 Self::_values[i] = source._values[i];
00439 }
00440 }
00441
00442 template <class ValueTypeT,
00443 class StorageInterfaceT> inline
00444 PointInterface<ValueTypeT, StorageInterfaceT>::PointInterface(
00445 const ValueTypeT rVal1)
00446 {
00447 UInt32 i;
00448
00449 Self::_values[0] = rVal1;
00450
00451 for(i = 1; i < Self::_iSize; i++)
00452 {
00453 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00454 }
00455 }
00456
00457 #ifdef __sgi
00458 #pragma set woff 1209
00459 #endif
00460
00462
00463 template <class ValueTypeT,
00464 class StorageInterfaceT> inline
00465 PointInterface<ValueTypeT,
00466 StorageInterfaceT>::PointInterface(const ValueTypeT rVal1,
00467 const ValueTypeT rVal2) :
00468 Inherited()
00469 {
00470 Self::_values[0] = rVal1;
00471
00472 if(Self::_iSize == 2)
00473 {
00474 Self::_values[1] = rVal2;
00475 }
00476 else if(Self::_iSize >= 3)
00477 {
00478 Self::_values[1] = rVal2;
00479
00480 for(UInt32 i = 2; i < Self::_iSize; i++)
00481 {
00482 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00483 }
00484 }
00485 }
00486
00487 #ifdef __sgi
00488 #pragma reset woff 1209
00489
00490 #pragma set woff 1209
00491 #endif
00492
00494
00495 template <class ValueTypeT,
00496 class StorageInterfaceT> inline
00497 PointInterface<ValueTypeT,
00498 StorageInterfaceT>::PointInterface(const ValueTypeT rVal1,
00499 const ValueTypeT rVal2,
00500 const ValueTypeT rVal3) :
00501 Inherited()
00502 {
00503 Self::_values[0] = rVal1;
00504
00505 if(Self::_iSize == 2)
00506 {
00507 Self::_values[1] = rVal2;
00508 }
00509 else if(Self::_iSize == 3)
00510 {
00511 Self::_values[1] = rVal2;
00512 Self::_values[2] = rVal3;
00513 }
00514 else if(Self::_iSize >= 4)
00515 {
00516 Self::_values[1] = rVal2;
00517 Self::_values[2] = rVal3;
00518
00519 for(UInt32 i = 3; i < Self::_iSize; i++)
00520 {
00521 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00522 }
00523 }
00524 }
00525
00526 #ifdef __sgi
00527 #pragma reset woff 1209
00528
00529 #pragma set woff 1209
00530 #endif
00531
00533
00534 template <class ValueTypeT,
00535 class StorageInterfaceT> inline
00536 PointInterface<ValueTypeT,
00537 StorageInterfaceT>::PointInterface(const ValueTypeT rVal1,
00538 const ValueTypeT rVal2,
00539 const ValueTypeT rVal3,
00540 const ValueTypeT rVal4) :
00541 Inherited()
00542 {
00543 Self::_values[0] = rVal1;
00544
00545 if(Self::_iSize == 2)
00546 {
00547 Self::_values[1] = rVal2;
00548 }
00549 else if(Self::_iSize == 3)
00550 {
00551 Self::_values[1] = rVal2;
00552 Self::_values[2] = rVal3;
00553 }
00554 else if(Self::_iSize == 4)
00555 {
00556 Self::_values[1] = rVal2;
00557 Self::_values[2] = rVal3;
00558 Self::_values[3] = rVal4;
00559 }
00560 else if(Self::_iSize >= 5)
00561 {
00562 Self::_values[1] = rVal2;
00563 Self::_values[2] = rVal3;
00564 Self::_values[3] = rVal4;
00565
00566 for(UInt32 i = 4; i < Self::_iSize; i++)
00567 {
00568 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00569 }
00570 }
00571 }
00572
00573 #ifdef __sgi
00574 #pragma reset woff 1209
00575 #endif
00576
00577
00578
00579
00580 template <class ValueTypeT,
00581 class StorageInterfaceT> inline
00582 PointInterface<ValueTypeT, StorageInterfaceT>::~PointInterface(void)
00583 {
00584 }
00585
00586
00587
00588
00589 template <class ValueTypeT,
00590 class StorageInterfaceT> inline
00591 void PointInterface<ValueTypeT, StorageInterfaceT>::setNull(void)
00592 {
00593 for(UInt32 i = 0; i < Self::_iSize; i++)
00594 {
00595 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00596 }
00597 }
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611 template <class ValueTypeT,
00612 class StorageInterfaceT> inline
00613 void PointInterface<ValueTypeT,
00614 StorageInterfaceT>::setValue(const PointInterface &vec)
00615 {
00616 for(UInt32 i = 0; i < Self::_iSize; i++)
00617 {
00618 Self::_values[i] = vec._values[i];
00619 }
00620 }
00621
00622 template <class ValueTypeT,
00623 class StorageInterfaceT>
00624 template <class ValueType2T,
00625 class StorageInterface2T> inline
00626 void PointInterface<ValueTypeT,
00627 StorageInterfaceT>::setValue(const PointInterface<ValueType2T, StorageInterface2T> &vec )
00628 {
00629 typedef PointInterface<ValueType2T, StorageInterface2T> VectorT;
00630
00631 static const UInt32 nElementsToCopy = Self::_iSize < VectorT::_iSize ? Self::_iSize : VectorT::_iSize;
00632
00633 for(UInt32 i = 0; i < nElementsToCopy; ++i)
00634 {
00635 Self::_values[i] = vec.getValues()[i];
00636 }
00637 }
00638
00639
00640 #if 0
00641
00664 #ifdef __sgi
00665 #pragma set woff 1209
00666 #endif
00667
00668 template <class ValueTypeT,
00669 class StorageInterfaceT>
00670 template <class VectorT> inline
00671 void PointInterface<ValueTypeT,
00672 StorageInterfaceT>::setValue(const VectorT &vec)
00673 {
00674 for(UInt32 i = 0;
00675 i < (Self::_iSize < VectorT::_iSize ?
00676 Self::_iSize : VectorT::_iSize);
00677 ++i)
00678 {
00679 Self::_values[i] = vec.getValues()[i];
00680 }
00681 }
00682
00683 #ifdef __sgi
00684 #pragma reset woff 1209
00685 #endif
00686 #endif
00687
00689
00690 template <class ValueTypeT,
00691 class StorageInterfaceT> inline
00692 void PointInterface<ValueTypeT,
00693 StorageInterfaceT>::setValue(const ValueTypeT *pVals)
00694 {
00695 for(UInt32 i = 0; i < Self::_iSize; i++)
00696 {
00697 Self::_values[i] = pVals[i];
00698 }
00699 }
00700
00702
00703 template <class ValueTypeT,
00704 class StorageInterfaceT> inline
00705 void PointInterface<ValueTypeT,
00706 StorageInterfaceT>::setValue(ValueTypeT *pVals)
00707 {
00708 setValue(static_cast<const ValueTypeT *>(pVals));
00709 }
00710
00715 template <class ValueTypeT,
00716 class StorageInterfaceT> inline
00717 void PointInterface<ValueTypeT,
00718 StorageInterfaceT>::setValueFromCString(
00719 const Char8 *szString)
00720 {
00721 UInt32 i;
00722 UInt32 numOfToken = Self::_iSize;
00723
00724 Char8 *c = const_cast<Char8 *>(szString);
00725 Char8 *tokenC = 0;
00726
00727 Char8 token[256];
00728
00729 if(szString == NULL || (*szString) == '\0')
00730 {
00731 for(i = 0; i < Self::_iSize; i++)
00732 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
00733
00734 return;
00735 }
00736
00737 for (i = 0; i < numOfToken; c++)
00738 {
00739 switch (*c)
00740 {
00741 case '\0':
00742 if(tokenC)
00743 {
00744 *tokenC = 0;
00745 Self::_values[i++] =
00746 TypeTraits<ValueTypeT>::getFromString(token);
00747 }
00748
00749 while (i < numOfToken)
00750 {
00751 Self::_values[i++] =
00752 TypeTraits<ValueTypeT>::getZeroElement();
00753 }
00754 break;
00755
00756 case ' ' :
00757 case '\t':
00758 case '\n':
00759 case ',':
00760 if(tokenC)
00761 {
00762 *tokenC = 0;
00763 Self::_values[i++] =
00764 TypeTraits<ValueTypeT>::getFromString(token);
00765 tokenC = 0;
00766 }
00767 break;
00768 default:
00769 if(!tokenC)
00770 {
00771 tokenC = token;
00772 }
00773 *tokenC++ = *c;
00774 break;
00775 }
00776 }
00777 }
00778
00783 template <class ValueTypeT,
00784 class StorageInterfaceT> inline
00785 void PointInterface<ValueTypeT,
00786 StorageInterfaceT>::setValueFromCString(Char8 *szString)
00787 {
00788 setValueFromCString(static_cast<const Char8 *>(szString));
00789 }
00790
00791
00792 #ifndef OSG_DISABLE_DEPRECATED
00793 template <class ValueTypeT,
00794 class StorageInterfaceT> inline
00795 void PointInterface<ValueTypeT,
00796 StorageInterfaceT>::setValue(const Char8 *szString)
00797 {
00798 setValueFromCString(szString);
00799 }
00800
00801 template <class ValueTypeT,
00802 class StorageInterfaceT> inline
00803 void PointInterface<ValueTypeT,
00804 StorageInterfaceT>::setValue(Char8 *szString)
00805 {
00806 setValueFromCString(szString);
00807 }
00808 #endif
00809
00810
00811
00812
00814
00815 template <class ValueTypeT,
00816 class StorageInterfaceT> inline
00817 ValueTypeT *PointInterface<ValueTypeT,
00818 StorageInterfaceT>::getValues(void)
00819 {
00820 return Self::_values;
00821 }
00822
00824
00825 template <class ValueTypeT,
00826 class StorageInterfaceT> inline
00827 const ValueTypeT *PointInterface<ValueTypeT,
00828 StorageInterfaceT>::getValues(void) const
00829 {
00830 return Self::_values;
00831 }
00832
00833
00834
00835
00837
00838 template <class ValueTypeT,
00839 class StorageInterfaceT> inline
00840 bool PointInterface<ValueTypeT,
00841 StorageInterfaceT>::isZero(void) const
00842 {
00843 bool returnValue = true;
00844
00845 for(UInt32 i = 0; i < Self::_iSize; i++)
00846 {
00847 returnValue &= ((Self::_values[i] <= Eps) &&
00848 (Self::_values[i] >= -Eps));
00849 }
00850
00851 return returnValue;
00852 }
00853
00855
00856 template <class ValueTypeT,
00857 class StorageInterfaceT> inline
00858 void PointInterface<ValueTypeT, StorageInterfaceT>::negate(void)
00859 {
00860 for(UInt32 i = 0; i < Self::_iSize; i++)
00861 {
00862 Self::_values[i] = -Self::_values[i];
00863 }
00864 }
00865
00867
00868 template <class ValueTypeT,
00869 class StorageInterfaceT> inline
00870 bool PointInterface<ValueTypeT, StorageInterfaceT>::equals(
00871 const PointInterface &vec,
00872 const ValueTypeT tolerance) const
00873 {
00874 bool returnValue = true;
00875
00876 for(UInt32 i = 0; i < Self::_iSize; i++)
00877 {
00878 returnValue &=
00879 ( (Self::_values[i] - vec ._values[i] <= tolerance) &&
00880 (vec ._values[i] - Self::_values[i] <= tolerance));
00881 }
00882
00883 return returnValue;
00884 }
00885
00887
00888 template <class ValueTypeT,
00889 class StorageInterfaceT> inline
00890 typename PointInterface<ValueTypeT,
00891 StorageInterfaceT>::VecInterface &
00892 PointInterface<ValueTypeT,
00893 StorageInterfaceT>::subZero(void)
00894 {
00895 return *(static_cast<VecInterface *>(this));
00896 }
00897
00899
00900 template <class ValueTypeT,
00901 class StorageInterfaceT> inline
00902 const typename PointInterface<ValueTypeT,
00903 StorageInterfaceT>::VecInterface &
00904 PointInterface<ValueTypeT,
00905 StorageInterfaceT>::subZero(void) const
00906 {
00907 return *(static_cast<const VecInterface *>(this));
00908 }
00909
00910
00912
00913 template <class ValueTypeT,
00914 class StorageInterfaceT> inline
00915 typename PointInterface<ValueTypeT,
00916 StorageInterfaceT>::RealReturnType
00917 PointInterface<ValueTypeT, StorageInterfaceT>::dist(const PointInterface &vec)
00918 const
00919 {
00920 return osgsqrt(dist2(vec));
00921 }
00922
00924
00925 template <class ValueTypeT,
00926 class StorageInterfaceT> inline
00927 typename PointInterface<ValueTypeT,
00928 StorageInterfaceT>::RealReturnType
00929 PointInterface<ValueTypeT, StorageInterfaceT>::dist2(const PointInterface &vec)
00930 const
00931 {
00932 RealReturnType returnValue = 0;
00933 RealReturnType tmp;
00934
00935 for(UInt32 i = 0; i < Self::_iSize; i++)
00936 {
00937 tmp = Self::_values[i] - vec._values[i];
00938
00939 returnValue += tmp * tmp;
00940 }
00941
00942 return returnValue;
00943 }
00944
00946
00947 template <class ValueTypeT,
00948 class StorageInterfaceT> inline
00949 typename PointInterface<ValueTypeT,
00950 StorageInterfaceT>::RealReturnType
00951 PointInterface<ValueTypeT, StorageInterfaceT>::maxValue(void)
00952 const
00953 {
00954 RealReturnType returnValue = TypeTraits<RealReturnType>::getMin();
00955
00956 for(UInt32 i = 0; i < Self::_iSize; i++)
00957 {
00958 if(Self::_values[i] > returnValue)
00959 returnValue = Self::_values[i];
00960 }
00961
00962 return returnValue;
00963 }
00964
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
00982
00983 template <class ValueTypeT,
00984 class StorageInterfaceT> inline
00985 void PointInterface<ValueTypeT,
00986 StorageInterfaceT>::operator /=(const ValueTypeT val)
00987 {
00988 for(UInt32 i = 0; i < Self::_iSize; i++)
00989 {
00990 Self::_values[i] /= val;
00991 }
00992 }
00993
00994
00996
00997 template <class ValueTypeT,
00998 class StorageInterfaceT> inline
00999 typename PointInterface<ValueTypeT, StorageInterfaceT>::VecInterface
01000 PointInterface<ValueTypeT, StorageInterfaceT>::operator -(
01001 const PointInterface &vec) const
01002 {
01003 VecInterface returnValue(*this);
01004
01005 for(UInt32 i = 0; i < Self::_iSize; i++)
01006 {
01007 returnValue[i] -= vec[i];
01008 }
01009
01010 return returnValue;
01011 }
01012
01014
01015 template <class ValueTypeT,
01016 class StorageInterfaceT> inline
01017 PointInterface<ValueTypeT, StorageInterfaceT>
01018 PointInterface<ValueTypeT, StorageInterfaceT>::operator + (
01019 const VecInterface &vec) const
01020 {
01021 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01022
01023 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01024 {
01025 returnValue[i] = Self::_values[i] + vec[i];
01026 }
01027
01028 return returnValue;
01029 }
01030
01032
01033 template <class ValueTypeT,
01034 class StorageInterfaceT> inline
01035 PointInterface<ValueTypeT, StorageInterfaceT>
01036 PointInterface<ValueTypeT, StorageInterfaceT>::operator - (
01037 const VecInterface &vec) const
01038 {
01039 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01040
01041 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01042 {
01043 returnValue[i] = Self::_values[i] - vec[i];
01044 }
01045
01046 return returnValue;
01047 }
01048
01050
01051 template <class ValueTypeT,
01052 class StorageInterfaceT> inline
01053 PointInterface <ValueTypeT, StorageInterfaceT>
01054 PointInterface<ValueTypeT, StorageInterfaceT>::operator * (
01055 const ValueTypeT rVal) const
01056 {
01057 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01058
01059 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01060 {
01061 returnValue[i] = Self::_values[i] * rVal;
01062 }
01063
01064 return returnValue;
01065 }
01066
01067
01068 #if 0
01070
01071 template <class ValueTypeT,
01072 class StorageInterfaceT> inline
01073 PointInterface <ValueTypeT, StorageInterfaceT>
01074 operator * (
01075 const PointInterface <ValueTypeT, StorageInterfaceT> &vec,
01076 const ValueTypeT rVal)
01077 {
01078 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01079
01080 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01081 {
01082 returnValue[i] = vec._values[i] * rVal;
01083 }
01084
01085 return returnValue;
01086 }
01087 #endif
01088
01090
01091 template <class ValueTypeT,
01092 class StorageInterfaceT> inline
01093 PointInterface<ValueTypeT, StorageInterfaceT>
01094 PointInterface<ValueTypeT, StorageInterfaceT>::operator -(void)
01095 {
01096 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01097
01098 for(UInt32 i = 0; i < Self::_iSize; i++)
01099 {
01100 returnValue._values[i] = - Self::_values[i];
01101 }
01102
01103 return returnValue;
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
01120
01121 template <class ValueTypeT,
01122 class StorageInterfaceT> inline
01123 void PointInterface<ValueTypeT, StorageInterfaceT>::operator -=(
01124 const VecInterface &vec)
01125 {
01126 for(UInt32 i = 0; i < Self::_iSize; i++)
01127 {
01128 Self::_values[i] -= vec._values[i];
01129 }
01130 }
01131
01132
01133
01134
01135 template <class ValueTypeT,
01136 class StorageInterfaceT> inline
01137 ValueTypeT &PointInterface<ValueTypeT,
01138 StorageInterfaceT>::operator[](const UInt32 uiVal)
01139 {
01140 return Self::_values[uiVal];
01141 }
01142
01143 template <class ValueTypeT,
01144 class StorageInterfaceT> inline
01145 const ValueTypeT &
01146 PointInterface<ValueTypeT,
01147 StorageInterfaceT>::operator[](const UInt32 uiVal) const
01148 {
01149 return Self::_values[uiVal];
01150 }
01151
01152 #if 0
01153 template <class ValueTypeT,
01154 class StorageInterfaceT> inline
01155 PointInterface<ValueTypeT, StorageInterfaceT>::operator
01156 ValueTypeT *(void)
01157 {
01158 return Self::_values;
01159 }
01160
01161 template <class ValueTypeT,
01162 class StorageInterfaceT> inline
01163 PointInterface<ValueTypeT, StorageInterfaceT>::operator
01164 const ValueTypeT *(void)
01165 {
01166 return Self::_values;
01167 }
01168 #endif
01169
01170
01171
01172
01173 template <class ValueTypeT,
01174 class StorageInterfaceT> inline
01175 PointInterface<ValueTypeT, StorageInterfaceT> &
01176 PointInterface<ValueTypeT, StorageInterfaceT>::operator =(
01177 const PointInterface &source)
01178 {
01179 if(this == &source)
01180 return *this;
01181
01182 for(UInt32 i = 0; i < Self::_iSize; i++)
01183 {
01184 Self::_values[i] = source._values[i];
01185 }
01186
01187 return *this;
01188 }
01189
01190 template <class ValueTypeT,
01191 class StorageInterfaceT> inline
01192 PointInterface<ValueTypeT, StorageInterfaceT> &
01193 PointInterface<ValueTypeT,
01194 StorageInterfaceT>::operator =(const VecInterface &source)
01195 {
01196 static PointInterface<ValueTypeT, StorageInterfaceT> dummy;
01197 PointInterface<ValueTypeT,
01198 StorageInterfaceT>::error_cannot_assign_vector;
01199 return dummy;
01200 }
01201
01202
01203
01204
01205 template <class ValueTypeT,
01206 class StorageInterfaceT> inline
01207 bool PointInterface<ValueTypeT, StorageInterfaceT>::operator < (
01208 const PointInterface &other) const
01209 {
01210 bool ret = false;
01211
01212 for(UInt32 i = 0; i < Self::_iSize; i++)
01213 {
01214 if(Self::_values[i] > other._values[i])
01215 {
01216 break;
01217 }
01218 if(Self::_values[i] < other._values[i])
01219 {
01220 ret = true;
01221 break;
01222 }
01223 }
01224
01225 return ret;
01226 }
01227
01229
01230 template <class ValueTypeT,
01231 class StorageInterfaceT> inline
01232 bool PointInterface<ValueTypeT, StorageInterfaceT>::operator == (
01233 const PointInterface &other) const
01234 {
01235
01236 return Self::equals(other, ValueTypeT(Eps));
01237 }
01238
01240
01241 template <class ValueTypeT,
01242 class StorageInterfaceT> inline
01243 bool PointInterface<ValueTypeT, StorageInterfaceT>::operator != (
01244 const PointInterface &other) const
01245 {
01246 return ! (*this == other);
01247 }
01248
01249
01250
01251
01253
01254 template <class ValueTypeT,
01255 class StorageInterfaceT> inline
01256 PointInterface<ValueTypeT, StorageInterfaceT>
01257 operator *(const ValueTypeT val,
01258 const PointInterface<ValueTypeT,
01259 StorageInterfaceT> &vec)
01260 {
01261 PointInterface<ValueTypeT, StorageInterfaceT> returnValue;
01262
01263 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01264 {
01265 returnValue[i] = vec[i] * val;
01266 }
01267
01268 return returnValue;
01269 }
01270
01272
01273 template <class ValueTypeT,
01274 class StorageInterfaceT> inline
01275 std::ostream &operator <<( std::ostream &os,
01276 const PointInterface<ValueTypeT,
01277 StorageInterfaceT> &obj)
01278 {
01279 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01280 {
01281 os << obj[i];
01282
01283 if(i != StorageInterfaceT::_iSize - 1)
01284 os << ", ";
01285 }
01286
01287 return os;
01288 }
01289
01290
01291
01292
01293
01294
01295
01296
01309 template <class ValueTypeT,
01310 class StorageInterfaceT>
01311 const VectorInterface<ValueTypeT, StorageInterfaceT>
01312 VectorInterface<ValueTypeT, StorageInterfaceT>::Null;
01313
01314
01315
01316
01317 template <class ValueTypeT,
01318 class StorageInterfaceT> inline
01319 VectorInterface<ValueTypeT, StorageInterfaceT>::VectorInterface(void) :
01320 Inherited()
01321 {
01322 for(UInt32 i = 0; i < Self::_iSize; i++)
01323 {
01324 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
01325 }
01326 }
01327
01328
01334 template <class ValueTypeT,
01335 class StorageInterfaceT> inline
01336 VectorInterface<ValueTypeT,
01337 StorageInterfaceT>::VectorInterface(const ValueTypeT *pVals) :
01338 Inherited(pVals)
01339 {
01340 }
01341
01347 template <class ValueTypeT,
01348 class StorageInterfaceT> inline
01349 VectorInterface<ValueTypeT,
01350 StorageInterfaceT>::VectorInterface(ValueTypeT *pVals) :
01351 Inherited(pVals)
01352 {
01353 }
01354
01355
01356
01357 template <class ValueTypeT,
01358 class StorageInterfaceT>
01359 template <class ValueType2T,
01360 class StorageInterface2T>
01361 inline
01362 VectorInterface<ValueTypeT, StorageInterfaceT>::VectorInterface(const PointInterface<ValueType2T, StorageInterface2T> &vec ) :
01363 Inherited(vec)
01364 {
01365 }
01366
01367 template <class ValueTypeT,
01368 class StorageInterfaceT>
01369 template <class ValueType2T,
01370 class StorageInterface2T>
01371 inline
01372 VectorInterface<ValueTypeT, StorageInterfaceT>::VectorInterface(const VectorInterface<ValueType2T, StorageInterface2T> &vec ) :
01373 Inherited(vec)
01374 {
01375 }
01376
01377
01378 template <class ValueTypeT,
01379 class StorageInterfaceT> inline
01380 VectorInterface<ValueTypeT, StorageInterfaceT>::VectorInterface(
01381 const VectorInterface &source) :
01382
01383 Inherited(source)
01384 {
01385 }
01386
01387 template <class ValueTypeT,
01388 class StorageInterfaceT> inline
01389 VectorInterface<ValueTypeT, StorageInterfaceT>::VectorInterface(
01390 const ValueTypeT rVal1)
01391 {
01392 UInt32 i;
01393
01394 Self::_values[0] = rVal1;
01395
01396 for(i = 1; i < Self::_iSize; i++)
01397 {
01398 Self::_values[i] = TypeTraits<ValueTypeT>::getZeroElement();
01399 }
01400 }
01401
01402 template <class ValueTypeT,
01403 class StorageInterfaceT> inline
01404 VectorInterface<ValueTypeT,
01405 StorageInterfaceT>::VectorInterface(const ValueTypeT rVal1,
01406 const ValueTypeT rVal2) :
01407
01408 Inherited(rVal1, rVal2)
01409 {
01410 }
01411
01412 template <class ValueTypeT,
01413 class StorageInterfaceT> inline
01414 VectorInterface<ValueTypeT,
01415 StorageInterfaceT>::VectorInterface(const ValueTypeT rVal1,
01416 const ValueTypeT rVal2,
01417 const ValueTypeT rVal3) :
01418
01419 Inherited(rVal1, rVal2, rVal3)
01420 {
01421 }
01422
01423 template <class ValueTypeT,
01424 class StorageInterfaceT> inline
01425 VectorInterface<ValueTypeT,
01426 StorageInterfaceT>::VectorInterface(const ValueTypeT rVal1,
01427 const ValueTypeT rVal2,
01428 const ValueTypeT rVal3,
01429 const ValueTypeT rVal4) :
01430
01431 Inherited(rVal1, rVal2, rVal3, rVal4)
01432 {
01433 }
01434
01435
01436
01437
01438
01439 template <class ValueTypeT,
01440 class StorageInterfaceT> inline
01441 VectorInterface<ValueTypeT,
01442 StorageInterfaceT>::~VectorInterface(void)
01443 {
01444 }
01445
01446
01447
01448
01450
01451 template <class ValueTypeT,
01452 class StorageInterfaceT> inline
01453 typename VectorInterface<ValueTypeT, StorageInterfaceT>::RealReturnType
01454 VectorInterface<ValueTypeT, StorageInterfaceT>::length(void) const
01455 {
01456 return osgsqrt(Self::squareLength());
01457 }
01458
01460
01461 template <class ValueTypeT,
01462 class StorageInterfaceT> inline
01463 typename VectorInterface<ValueTypeT, StorageInterfaceT>::RealReturnType
01464 VectorInterface<ValueTypeT, StorageInterfaceT>::squareLength(void) const
01465 {
01466 RealReturnType rTmpVal = RealReturnType(Self::_values[0] *
01467 Self::_values[0] );
01468
01469 for(UInt32 i = 1; i < Self::_iSize; i++)
01470 {
01471 rTmpVal += Self::_values[i] * Self::_values[i];
01472 }
01473
01474 return rTmpVal;
01475 }
01476
01478
01479 template <class ValueTypeT,
01480 class StorageInterfaceT> inline
01481 void VectorInterface<ValueTypeT, StorageInterfaceT>::normalize(void)
01482 {
01483 ValueTypeT rLength = ValueTypeT(length());
01484
01485 if(osgabs(rLength) < Eps)
01486 {
01487 rLength = TypeTraits<ValueTypeT>::getOneElement();
01488 }
01489 else
01490 {
01491 rLength = TypeTraits<ValueTypeT>::getOneElement() / rLength;
01492 }
01493
01494 for(UInt32 i = 0; i < Self::_iSize; i++)
01495 {
01496 Self::_values[i] *= rLength;
01497 }
01498 }
01499
01500 #ifdef __sgi
01501 #pragma set woff 1209
01502 #endif
01503
01508 template <class ValueTypeT,
01509 class StorageInterfaceT> inline
01510 VectorInterface<ValueTypeT, StorageInterfaceT>
01511 VectorInterface<ValueTypeT,
01512 StorageInterfaceT>::cross(const VectorInterface &vec) const
01513 {
01514 VectorInterface<ValueTypeT, StorageInterfaceT> returnValue;
01515
01516 if(Self::_iSize >= 3)
01517 {
01518 returnValue[0] =
01519 Self::_values[1] * vec._values[2] -
01520 Self::_values[2] * vec._values[1];
01521 returnValue[1] =
01522 Self::_values[2] * vec._values[0] -
01523 Self::_values[0] * vec._values[2];
01524 returnValue[2] =
01525 Self::_values[0] * vec._values[1] -
01526 Self::_values[1] * vec._values[0];
01527 }
01528 else
01529 {
01530
01531 fprintf(stderr, "cross only implemented for size 3\n");
01532 }
01533
01534 return returnValue;
01535 }
01536
01537 template <class ValueTypeT,
01538 class StorageInterfaceT> inline
01539 VectorInterface<ValueTypeT, StorageInterfaceT>
01540 VectorInterface<ValueTypeT, StorageInterfaceT>::operator % (
01541 const VectorInterface &vec) const
01542 {
01543 return this->cross(vec);
01544 }
01545
01550 template <class ValueTypeT,
01551 class StorageInterfaceT> inline
01552 void VectorInterface<ValueTypeT,
01553 StorageInterfaceT>::crossThis(const VectorInterface &vec)
01554 {
01555 if(Self::_iSize >= 3)
01556 {
01557 ValueTypeT rTmp[2];
01558
01559 rTmp[0] =
01560 Self::_values[1] * vec._values[2] -
01561 Self::_values[2] * vec._values[1];
01562 rTmp[1] =
01563 Self::_values[2] * vec._values[0] -
01564 Self::_values[0] * vec._values[2];
01565
01566 Self::_values[2] =
01567 Self::_values[0] * vec._values[1] -
01568 Self::_values[1] * vec._values[0];
01569
01570 Self::_values[0] = rTmp[0];
01571 Self::_values[1] = rTmp[1];
01572 }
01573 else
01574 {
01575
01576 fprintf(stderr, "crossThis only available for size 3\n");
01577 }
01578 }
01579
01580 #ifdef __sgi
01581 #pragma reset woff 1209
01582 #endif
01583
01585
01586 template <class ValueTypeT,
01587 class StorageInterfaceT> inline
01588 ValueTypeT VectorInterface<ValueTypeT, StorageInterfaceT>::dot(
01589 const VectorInterface &vec) const
01590 {
01591 ValueTypeT rTmpVal = Self::_values[0] * vec._values[0];
01592
01593 for(UInt32 i = 1; i < Self::_iSize; i++)
01594 {
01595 rTmpVal += Self::_values[i] * vec._values[i];
01596 }
01597
01598 return rTmpVal;
01599 }
01600
01601 template <class ValueTypeT,
01602 class StorageInterfaceT> inline
01603 ValueTypeT VectorInterface<ValueTypeT, StorageInterfaceT>::operator * (
01604 const VectorInterface &vec) const
01605 {
01606 return this->dot(vec);
01607 }
01608
01609 template <class ValueTypeT,
01610 class StorageInterfaceT> inline
01611 ValueTypeT VectorInterface<ValueTypeT, StorageInterfaceT>::dot (
01612 const PntInterface &pnt) const
01613 {
01614 ValueTypeT rTmpVal = Self::_values[0] * pnt[0];
01615
01616 for(UInt32 i = 1; i < Self::_iSize; i++)
01617 {
01618 rTmpVal += Self::_values[i] * pnt[i];
01619 }
01620
01621 return rTmpVal;
01622 }
01623
01624 template <class ValueTypeT,
01625 class StorageInterfaceT> inline
01626 ValueTypeT VectorInterface<ValueTypeT, StorageInterfaceT>::operator * (
01627 const PntInterface &pnt) const
01628 {
01629 return this->dot(pnt);
01630 }
01631
01633
01634 template <class ValueTypeT,
01635 class StorageInterfaceT> inline
01636 typename VectorInterface<ValueTypeT, StorageInterfaceT>::RealReturnType
01637 VectorInterface<ValueTypeT, StorageInterfaceT>::enclosedAngle(
01638 const VectorInterface &vec) const
01639 {
01640 RealReturnType returnValue;
01641
01642 if(Self::isZero() || vec.isZero())
01643 {
01644 returnValue = TypeTraits<RealReturnType>::getZeroElement();
01645 }
01646 else
01647 {
01648 returnValue = dot(vec);
01649 returnValue /= (length() * vec.length());
01650
01651 if((returnValue - Eps) < -1.)
01652 {
01653 returnValue = Pi;
01654 }
01655 else if((returnValue + Eps) > 1.)
01656 {
01657 returnValue = TypeTraits<RealReturnType>::getZeroElement();
01658 }
01659 else
01660 {
01661 returnValue = osgacos(returnValue);
01662 }
01663 }
01664
01665 return returnValue;
01666 }
01667
01668 template <class ValueTypeT,
01669 class StorageInterfaceT> inline
01670 typename VectorInterface<ValueTypeT, StorageInterfaceT>::RealReturnType
01671 VectorInterface<ValueTypeT, StorageInterfaceT>::projectTo(
01672 const VectorInterface &toVec)
01673 {
01674 RealReturnType rDot = dot(toVec);
01675 RealReturnType rSquareDot = toVec.dot(toVec);
01676
01677 if(rSquareDot > Eps)
01678 {
01679 rDot /= rSquareDot;
01680
01681 if(osgabs(rDot) > Eps)
01682 {
01683 *this = toVec;
01684 *this *= ValueTypeT(rDot);
01685 }
01686 else
01687 {
01688 this->setNull();
01689 rDot = TypeTraits<RealReturnType>::getZeroElement();
01690 }
01691 }
01692 else
01693 {
01694 rDot = TypeTraits<RealReturnType>::getOneElement();
01695 }
01696
01697 return rDot;
01698 }
01699
01701
01702 template <class ValueTypeT,
01703 class StorageInterfaceT> inline
01704 const typename VectorInterface<ValueTypeT,
01705 StorageInterfaceT>::PntInterface &
01706 VectorInterface<ValueTypeT,
01707 StorageInterfaceT>::addToZero(void) const
01708 {
01709 return *(static_cast<const PntInterface *>(this));
01710 }
01711
01713
01714 template <class ValueTypeT,
01715 class StorageInterfaceT> inline
01716 typename VectorInterface<ValueTypeT,
01717 StorageInterfaceT>::PntInterface &
01718 VectorInterface<ValueTypeT,
01719 StorageInterfaceT>::addToZero(void)
01720 {
01721 return *(static_cast<PntInterface *>(this));
01722 }
01723
01724 template <class ValueTypeT,
01725 class StorageInterfaceT> inline
01726 VectorInterface<ValueTypeT, StorageInterfaceT> &
01727 VectorInterface<ValueTypeT, StorageInterfaceT>::subZero(void)
01728 {
01729 return *this;
01730 }
01731
01732 template <class ValueTypeT,
01733 class StorageInterfaceT> inline
01734 const VectorInterface<ValueTypeT, StorageInterfaceT> &
01735 VectorInterface<ValueTypeT, StorageInterfaceT>::subZero(void) const
01736 {
01737 return (*this);
01738 }
01739
01740
01741
01742
01744
01745 template <class ValueTypeT,
01746 class StorageInterfaceT> inline
01747 VectorInterface <ValueTypeT, StorageInterfaceT>
01748 VectorInterface<ValueTypeT, StorageInterfaceT>::operator - (
01749 const VectorInterface &vec) const
01750 {
01751 VectorInterface<ValueTypeT, StorageInterfaceT> returnValue;
01752
01753 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01754 {
01755 returnValue[i] = Self::_values[i] - vec[i];
01756 }
01757
01758 return returnValue;
01759 }
01760
01762
01763 template <class ValueTypeT,
01764 class StorageInterfaceT> inline
01765 VectorInterface <ValueTypeT, StorageInterfaceT>
01766 VectorInterface<ValueTypeT, StorageInterfaceT>::operator + (
01767 const VectorInterface &vec) const
01768 {
01769 VectorInterface<ValueTypeT, StorageInterfaceT> returnValue;
01770
01771 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01772 {
01773 returnValue[i] = Self::_values[i] + vec[i];
01774 }
01775
01776 return returnValue;
01777 }
01778
01779
01781
01782 template <class ValueTypeT,
01783 class StorageInterfaceT> inline
01784 VectorInterface <ValueTypeT, StorageInterfaceT>
01785 VectorInterface<ValueTypeT, StorageInterfaceT>::operator * (
01786 const ValueTypeT rVal) const
01787 {
01788 VectorInterface<ValueTypeT, StorageInterfaceT> returnValue;
01789
01790 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01791 {
01792 returnValue[i] = Self::_values[i] * rVal;
01793 }
01794
01795 return returnValue;
01796 }
01797
01799
01800 template <class ValueTypeT,
01801 class StorageInterfaceT> inline
01802 VectorInterface<ValueTypeT, StorageInterfaceT>
01803 VectorInterface<ValueTypeT, StorageInterfaceT>::operator -(void) const
01804 {
01805 VectorInterface<ValueTypeT, StorageInterfaceT> returnValue;
01806
01807 for(UInt32 i = 0; i < Self::_iSize; i++)
01808 {
01809 returnValue._values[i] = - Self::_values[i];
01810 }
01811
01812 return returnValue;
01813 }
01814
01815
01816
01817
01818 template <class ValueTypeT,
01819 class StorageInterfaceT> inline
01820 VectorInterface<ValueTypeT, StorageInterfaceT> &
01821 VectorInterface<ValueTypeT, StorageInterfaceT>::operator =(
01822 const VectorInterface &source)
01823 {
01824 if(this == &source)
01825 return *this;
01826
01827 *(static_cast<Inherited *>(this)) =
01828 static_cast<const Inherited &>(source);
01829
01830 return *this;
01831 }
01832
01833
01834
01835
01836 template <class ValueTypeT,
01837 class StorageInterfaceT> inline
01838 bool VectorInterface<ValueTypeT, StorageInterfaceT>::operator < (
01839 const VectorInterface &other) const
01840 {
01841 bool ret = false;
01842
01843 for(UInt32 i = 0; i < Self::_iSize; i++)
01844 {
01845 if(Self::_values[i] > other._values[i])
01846 {
01847 break;
01848 }
01849 if(Self::_values[i] < other._values[i])
01850 {
01851 ret = true;
01852 break;
01853 }
01854 }
01855
01856 return ret;
01857 }
01858
01860
01861 template <class ValueTypeT,
01862 class StorageInterfaceT> inline
01863 bool VectorInterface<ValueTypeT, StorageInterfaceT>::operator == (
01864 const VectorInterface &other) const
01865 {
01866
01867 return Self::equals(other, ValueTypeT(Eps));
01868 }
01869
01871
01872 template <class ValueTypeT,
01873 class StorageInterfaceT> inline
01874 bool VectorInterface<ValueTypeT, StorageInterfaceT>::operator != (
01875 const VectorInterface &other) const
01876 {
01877 return ! (*this == other);
01878 }
01879
01880
01881
01882
01884
01885 template <class ValueTypeT,
01886 class StorageInterfaceT> inline
01887 VectorInterface<ValueTypeT, StorageInterfaceT>
01888 operator *(const ValueTypeT val,
01889 const VectorInterface<ValueTypeT,
01890 StorageInterfaceT> &vec)
01891 {
01892 VectorInterface<ValueTypeT, StorageInterfaceT> returnValue;
01893
01894 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01895 {
01896 returnValue[i] = vec[i] * val;
01897 }
01898
01899 return returnValue;
01900 }
01901
01903
01904 template <class ValueTypeT,
01905 class StorageInterfaceT> inline
01906 std::ostream &operator <<( std::ostream &os,
01907 const VectorInterface<ValueTypeT,
01908 StorageInterfaceT> &obj)
01909 {
01910 for(UInt32 i = 0; i < StorageInterfaceT::_iSize; i++)
01911 {
01912 os << obj[i];
01913
01914 if(i != StorageInterfaceT::_iSize - 1)
01915 os << ", ";
01916 }
01917
01918 return os;
01919 }
01920
01921
01922 OSG_END_NAMESPACE
01923
01924 #define OSGVECTOR_INLINE_CVSID "@(#)$Id: $"
01925
01926