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 #ifndef LTI_POINT_H
00034 #define LTI_POINT_H
00035
00036 #include <iostream>
00037 #include "ltiIoHandler.h"
00038 #include "ltiAssert.h"
00039 #include "ltiConfig.h"
00040 #include "ltiMath.h"
00041
00042 namespace lti {
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 template <class T>
00056 class tpoint {
00057 public:
00058
00059
00060
00061 typedef T value_type;
00062
00063
00064
00065
00066 typedef int size_type;
00067
00068
00069
00070
00071 T x;
00072
00073
00074
00075
00076 T y;
00077
00078
00079
00080
00081 explicit tpoint(const T newx=0,const T newy=0) : x(newx),y(newy) {};
00082
00083
00084
00085
00086 template <class U>
00087 tpoint(const tpoint<U>& p)
00088 : x(static_cast<T>(p.x)),y(static_cast<T>(p.y)) {};
00089
00090
00091
00092
00093 template <class U>
00094 tpoint<T>& castFrom(const tpoint<U>& p) {
00095 x = static_cast<T>(p.x);
00096 y = static_cast<T>(p.y);
00097 return (*this);
00098 };
00099
00100
00101
00102
00103 inline tpoint<T>& set(const T tx,const T ty) {
00104 x = tx;
00105 y = ty;
00106 return *this;
00107 }
00108
00109
00110
00111
00112 inline T distanceTo(const tpoint<T>& c) const;
00113
00114
00115
00116
00117
00118
00119 inline T distanceSqr(const tpoint<T>& c) const;
00120
00121
00122
00123
00124 inline T absSqr() const;
00125
00126
00127
00128
00129 template<class U>
00130 inline tpoint<T>& multiply(const U c) {
00131 x = static_cast<T>(x*c);
00132 y = static_cast<T>(y*c);
00133 return *this;
00134 };
00135
00136
00137
00138
00139 template<class U>
00140 inline tpoint<T>& multiply(const tpoint<T>& other,const U c) {
00141 x = static_cast<T>(other.x*c);
00142 y = static_cast<T>(other.y*c);
00143 return *this;
00144 };
00145
00146
00147
00148
00149
00150 template<class U>
00151 inline tpoint<T> operator*(const U c) const {
00152 return tpoint<T>(static_cast<T>(x*c),static_cast<T>(y*c));
00153 };
00154
00155
00156
00157
00158 template<class U>
00159 inline tpoint<T>& operator*=(const U c) {
00160 x = static_cast<T>(x*c);
00161 y = static_cast<T>(y*c);
00162 return *this;
00163 };
00164
00165
00166
00167
00168 inline tpoint<T> operator*(const tpoint<T>& c) const;
00169
00170
00171
00172
00173 inline tpoint<T>& operator*=(const tpoint<T>& c);
00174
00175
00176
00177
00178
00179 inline tpoint<T>& emultiply(const tpoint<T>& a,const tpoint<T>& b);
00180
00181
00182
00183
00184
00185 inline tpoint<T>& emultiply(const tpoint<T>& c);
00186
00187
00188
00189
00190 template<class U>
00191 inline tpoint<T>& divide(const U c) {
00192 x = static_cast<T>(x/c);
00193 y = static_cast<T>(y/c);
00194 return *this;
00195 };
00196
00197
00198
00199
00200 template<class U>
00201 inline tpoint<T>& divide(const tpoint<T>& other,const U c) {
00202 x = static_cast<T>(other.x/c);
00203 y = static_cast<T>(other.y/c);
00204 return *this;
00205 };
00206
00207
00208
00209
00210 template <class U>
00211 inline tpoint<T> operator/(const U c) const {
00212 return tpoint<T>(static_cast<T>(x/c),static_cast<T>(y/c));
00213 };
00214
00215
00216
00217
00218 template <class U>
00219 inline tpoint<T>& operator/=(const U c) {
00220 x = static_cast<T>(x/c);
00221 y = static_cast<T>(y/c);
00222 return *this;
00223 };
00224
00225
00226
00227
00228 inline tpoint<T> operator/(const tpoint<T>& c) const;
00229
00230
00231
00232
00233 inline tpoint<T>& operator/=(const tpoint<T>& c);
00234
00235
00236
00237
00238 inline tpoint<T>& edivide(const tpoint<T>& c);
00239
00240
00241
00242
00243 inline tpoint<T>& edivide(const tpoint<T>& a,const tpoint<T>& b);
00244
00245
00246
00247
00248 inline tpoint<T> operator%(const int c) const;
00249
00250
00251
00252
00253
00254
00255 inline tpoint<T>& add(const tpoint<T>& p);
00256
00257
00258
00259
00260
00261
00262
00263 inline tpoint<T>& add(const tpoint<T>& a,
00264 const tpoint<T>& b);
00265
00266
00267
00268
00269 inline tpoint<T> operator+(const tpoint<T>& p) const;
00270
00271
00272
00273
00274 inline tpoint<T>& operator+=(const tpoint<T>& p);
00275
00276
00277
00278
00279 inline tpoint<T>& subtract(const tpoint<T>& p);
00280
00281
00282
00283
00284
00285
00286
00287
00288 inline tpoint<T>& subtract(const tpoint<T>& a,
00289 const tpoint<T>& b);
00290
00291
00292
00293
00294 inline tpoint<T> operator-(const tpoint<T>& p) const;
00295
00296
00297
00298
00299 inline tpoint<T>& operator-=(const tpoint<T>& p);
00300
00301
00302
00303
00304
00305
00306 inline T dot(const tpoint<T>& p) const;
00307
00308
00309
00310
00311 inline tpoint<T>& copy(const tpoint<T>& p);
00312
00313
00314
00315
00316 inline tpoint<T>& operator=(const tpoint<T>& p) {return copy(p);};
00317
00318
00319
00320
00321 inline bool operator==(const tpoint<T>& p) const;
00322
00323
00324
00325
00326 inline bool operator!=(const tpoint<T>& p) const;
00327
00328
00329
00330
00331
00332
00333
00334
00335 inline bool operator<(const tpoint<T>& p) const;
00336
00337
00338
00339
00340
00341
00342
00343
00344 inline bool operator>(const tpoint<T>& p) const;
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358 inline T& operator[](const int i) {
00359 assert(i<2);
00360 return (i>0) ? y : x;
00361 }
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371 inline const T& operator[](const int i) const {
00372 assert(i<2);
00373 return (i>0) ? y : x;
00374 }
00375
00376
00377
00378
00379 inline int size() const {
00380 return 2;
00381 }
00382
00383 };
00384
00385
00386 template <class T>
00387 inline T tpoint<T>::distanceTo(const tpoint<T>& c) const {
00388 tpoint<T> t((*this)-c);
00389 return sqrt(t.absSqr());
00390 }
00391
00392 template <class T>
00393 inline T tpoint<T>::distanceSqr(const tpoint<T>& c) const {
00394 tpoint<T> t((*this)-c);
00395 return t.absSqr();
00396 }
00397
00398 template <class T>
00399 inline tpoint<T> tpoint<T>::operator*(const tpoint<T>& c) const {
00400 return tpoint<T>(c.x*x,c.y*y);
00401 }
00402
00403
00404 template <class T>
00405 inline tpoint<T>& tpoint<T>::operator*=(const tpoint<T>& c) {
00406 x*=c.x;
00407 y*=c.y;
00408 return *this;
00409 }
00410
00411 template <class T>
00412 inline tpoint<T>& tpoint<T>::emultiply(const tpoint<T>& c) {
00413 x*=c.x;
00414 y*=c.y;
00415 return *this;
00416 }
00417
00418 template <class T>
00419 inline tpoint<T>& tpoint<T>::emultiply(const tpoint<T>& a,
00420 const tpoint<T>& b) {
00421 x=a.x*b.x;
00422 y=a.y*b.y;
00423 return *this;
00424 }
00425
00426
00427 template <class T>
00428 inline tpoint<T> tpoint<T>::operator/(const tpoint<T>& c) const {
00429 return tpoint<T>(x/c.x,y/c.y);
00430 }
00431
00432 template <class T>
00433 inline tpoint<T>& tpoint<T>::operator/=(const tpoint<T>& c) {
00434 x/=c.x;
00435 y/=c.y;
00436 return *this;
00437 }
00438
00439 template <class T>
00440 inline tpoint<T>& tpoint<T>::edivide(const tpoint<T>& c) {
00441 x/=c.x;
00442 y/=c.y;
00443 return *this;
00444 }
00445
00446 template <class T>
00447 inline tpoint<T>& tpoint<T>::edivide(const tpoint<T>& a,
00448 const tpoint<T>& b) {
00449 x=a.x/b.x;
00450 y=a.y/b.y;
00451 return *this;
00452 }
00453
00454
00455 template <class T>
00456 inline tpoint<T> tpoint<T>::operator%(const int c) const {
00457 return tpoint<T>(static_cast<int>(x)%c,static_cast<int>(y)%c);
00458 }
00459
00460 template <class T>
00461 inline tpoint<T>& tpoint<T>::add(const tpoint<T>& p) {
00462 x+=p.x;
00463 y+=p.y;
00464 return (*this);
00465 }
00466
00467 template <class T>
00468 inline tpoint<T>& tpoint<T>::add(const tpoint<T>& a,
00469 const tpoint<T>& b) {
00470 x=a.x+b.x;
00471 y=a.y+b.y;
00472
00473 return (*this);
00474 }
00475
00476
00477 template <class T>
00478 inline tpoint<T> tpoint<T>::operator+(const tpoint<T>& p) const {
00479 return tpoint<T>(x+p.x,y+p.y);
00480 }
00481
00482 template <class T>
00483 inline tpoint<T>& tpoint<T>::operator+=(const tpoint<T>& p) {
00484 return add(p);
00485 }
00486
00487 template <class T>
00488 inline tpoint<T>& tpoint<T>::subtract(const tpoint<T>& p) {
00489 x-=p.x;
00490 y-=p.y;
00491 return (*this);
00492 }
00493
00494 template <class T>
00495 inline tpoint<T>& tpoint<T>::subtract(const tpoint<T>& a,
00496 const tpoint<T>& b) {
00497 x=a.x-b.x;
00498 y=a.y-b.y;
00499
00500 return (*this);
00501 }
00502
00503 template <class T>
00504 inline tpoint<T> tpoint<T>::operator-(const tpoint<T>& p) const {
00505 return tpoint<T>(x-p.x,y-p.y);
00506 }
00507
00508 template <class T>
00509 inline tpoint<T>& tpoint<T>::operator-=(const tpoint<T>& p) {
00510 return subtract(p);
00511 }
00512
00513 template <class T>
00514 inline T tpoint<T>::dot(const tpoint<T>& p) const {
00515 return static_cast<T>((x*p.x) + (y*p.y));
00516 }
00517
00518 template <class T>
00519 inline T tpoint<T>::absSqr() const {
00520 return static_cast<T>((x*x) + (y*y));
00521 }
00522
00523 template <class T>
00524 inline tpoint<T>& tpoint<T>::copy(const tpoint<T>& p) {
00525 x = p.x;
00526 y = p.y;
00527 return (*this);
00528 }
00529
00530 template <class T>
00531 inline bool tpoint<T>::operator==(const tpoint<T>& p) const {
00532 return ((p.y == y) && (p.x == x));
00533 }
00534
00535 template <class T>
00536 inline bool tpoint<T>::operator!=(const tpoint<T>& p) const {
00537 return ((p.y != y) || (p.x != x));
00538 }
00539
00540 template <class T>
00541 inline bool tpoint<T>::operator<(const tpoint<T>& p) const {
00542 if (y < p.y) {
00543 return true;
00544 } else if (y == p.y) {
00545 return (x < p.x);
00546 }
00547 return false;
00548 }
00549
00550 template <class T>
00551 inline bool tpoint<T>::operator>(const tpoint<T>& p) const {
00552 if (y > p.y) {
00553 return true;
00554 } else if (y == p.y) {
00555 return (x > p.x);
00556 }
00557 return false;
00558 }
00559
00560
00561
00562
00563
00564
00565 typedef tpoint<int> point;
00566
00567
00568
00569
00570 typedef tpoint<int> ipoint;
00571
00572
00573
00574
00575 typedef tpoint<double> dpoint;
00576
00577
00578
00579
00580 typedef tpoint<float> fpoint;
00581
00582
00583
00584
00585
00586
00587
00588 template <class T>
00589 bool read(ioHandler& handler,tpoint<T>& p,const bool complete=true) {
00590 bool b(true);
00591
00592 if (complete) {
00593 b = b && handler.readBegin();
00594 }
00595
00596 b = b && handler.read(p.x);
00597 b = b && handler.readDataSeparator();
00598 b = b && handler.read(p.y);
00599
00600 if (complete) {
00601 b = b && handler.readEnd();
00602 }
00603
00604 return b;
00605 };
00606
00607
00608
00609
00610
00611
00612
00613 template<class T>
00614 bool write(ioHandler& handler,const tpoint<T>& p,const bool complete=true) {
00615 bool b(true);
00616
00617 if (complete) {
00618 b = b && handler.writeBegin();
00619 }
00620
00621 b = b && handler.write(p.x);
00622 b = b && handler.writeDataSeparator();
00623 b = b && handler.write(p.y);
00624
00625 if (complete) {
00626 b = b && handler.writeEnd();
00627 }
00628
00629 return b;
00630 };
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641 template <class T>
00642 class tpoint3D {
00643 public:
00644
00645
00646
00647
00648 typedef T value_type;
00649
00650
00651
00652
00653 typedef int size_type;
00654
00655
00656
00657
00658 T x;
00659
00660
00661
00662
00663 T y;
00664
00665
00666
00667
00668 T z;
00669
00670
00671
00672
00673 explicit tpoint3D(const T newx=0,
00674 const T newy=0,
00675 const T newz=0) : x(newx),y(newy),z(newz) {};
00676
00677
00678
00679
00680 template <class U>
00681 tpoint3D(const tpoint3D<U>& p)
00682 : x(static_cast<T>(p.x)),y(static_cast<T>(p.y)),z(static_cast<T>(p.z)) {
00683 };
00684
00685
00686
00687
00688 template <class U>
00689 tpoint3D<T>& castFrom(const tpoint3D<U>& p) {
00690 x = static_cast<T>(p.x);
00691 y = static_cast<T>(p.y);
00692 z = static_cast<T>(p.z);
00693 return (*this);
00694 };
00695
00696
00697
00698
00699 inline tpoint3D<T>& set(const T tx,const T ty,const T tz) {
00700 x = tx;
00701 y = ty;
00702 z = tz;
00703 return *this;
00704 }
00705
00706
00707
00708
00709 inline T distanceTo(const tpoint3D<T>& c) const;
00710
00711
00712
00713
00714
00715
00716 inline T distanceSqr(const tpoint3D<T>& c) const;
00717
00718
00719
00720
00721 inline T absSqr() const;
00722
00723
00724
00725
00726 template <class U>
00727 inline tpoint3D<T>& multiply(const U c) {
00728 x = static_cast<T>(x*c);
00729 y = static_cast<T>(y*c);
00730 z = static_cast<T>(z*c);
00731 return (*this);
00732 };
00733
00734
00735
00736
00737 template <class U>
00738 inline tpoint3D<T>& multiply(const tpoint3D<T>& other,const U c) {
00739 x = static_cast<T>(other.x*c);
00740 y = static_cast<T>(other.y*c);
00741 z = static_cast<T>(other.z*c);
00742 return (*this);
00743 };
00744
00745
00746
00747
00748 template <class U>
00749 inline tpoint3D<T> operator*(const U c) const {
00750 return tpoint3D<T>(static_cast<T>(x*c),
00751 static_cast<T>(y*c),
00752 static_cast<T>(z*c));
00753 };
00754
00755
00756
00757
00758 template <class U>
00759 inline tpoint3D<T>& operator*=(const U c) {
00760 x = static_cast<T>(x*c);
00761 y = static_cast<T>(y*c);
00762 z = static_cast<T>(z*c);
00763 return (*this);
00764 };
00765
00766
00767
00768
00769 inline tpoint3D<T> operator*(const tpoint3D<T>& c) const;
00770
00771
00772
00773
00774 inline tpoint3D<T>& operator*=(const tpoint3D<T>& c);
00775
00776
00777
00778
00779
00780 inline tpoint3D<T>& emultiply(const tpoint3D<T>& a,const tpoint3D<T>& b);
00781
00782
00783
00784
00785
00786 inline tpoint3D<T>& emultiply(const tpoint3D<T>& c);
00787
00788
00789
00790
00791 template<class U>
00792 inline tpoint3D<T>& divide(const U c) {
00793 x = static_cast<T>(x/c);
00794 y = static_cast<T>(y/c);
00795 z = static_cast<T>(z/c);
00796 return (*this);
00797 };
00798
00799
00800
00801
00802 template<class U>
00803 inline tpoint3D<T>& divide(const tpoint3D<T>& other,const U c) {
00804 x = static_cast<T>(other.x/c);
00805 y = static_cast<T>(other.y/c);
00806 z = static_cast<T>(other.z/c);
00807 return (*this);
00808 };
00809
00810
00811
00812
00813 template <class U>
00814 inline tpoint3D<T> operator/(const U c) const {
00815 return tpoint3D<T>(static_cast<T>(x/c),
00816 static_cast<T>(y/c),
00817 static_cast<T>(z/c));
00818 };
00819
00820
00821
00822
00823 template <class U>
00824 inline tpoint3D<T>& operator/=(const U c) {
00825 x = static_cast<T>(x/c);
00826 y = static_cast<T>(y/c);
00827 z = static_cast<T>(z/c);
00828 return (*this);
00829 };
00830
00831
00832
00833
00834
00835 inline tpoint3D<T> operator/(const tpoint3D<T>& c) const;
00836
00837
00838
00839
00840 inline tpoint3D<T>& operator/=(const tpoint3D<T>& c);
00841
00842
00843
00844
00845 inline tpoint3D<T>& edivide(const tpoint3D<T>& c);
00846
00847
00848
00849
00850 inline tpoint3D<T>& edivide(const tpoint3D<T>& a,const tpoint3D<T>& b);
00851
00852
00853
00854
00855 inline tpoint3D<T> operator%(const int c) const;
00856
00857
00858
00859
00860
00861 inline tpoint3D<T>& add(const tpoint3D<T>& p);
00862
00863
00864
00865
00866 inline tpoint3D<T>& add(const tpoint3D<T>& p1,
00867 const tpoint3D<T>& p2);
00868
00869
00870
00871
00872 inline tpoint3D<T> operator+(const tpoint3D<T>& p) const;
00873
00874
00875
00876
00877 inline tpoint3D<T>& operator+=(const tpoint3D<T>& p);
00878
00879
00880
00881
00882 inline tpoint3D<T>& subtract(const tpoint3D<T>& p);
00883
00884
00885
00886
00887 inline tpoint3D<T>& subtract(const tpoint3D<T>& p1,
00888 const tpoint3D<T>& p2);
00889
00890
00891
00892
00893 inline tpoint3D<T> operator-(const tpoint3D<T>& p) const;
00894
00895
00896
00897
00898 inline tpoint3D<T> operator-=(const tpoint3D<T>& p);
00899
00900
00901
00902
00903 inline T dot(const tpoint3D<T>& p) const;
00904
00905
00906
00907
00908 inline tpoint3D<T>& copy(const tpoint3D<T>& p);
00909
00910
00911
00912
00913 inline tpoint3D<T>& operator=(const tpoint3D<T>& p) {return copy(p);};
00914
00915
00916
00917
00918 inline bool operator==(const tpoint3D<T>& p) const;
00919
00920
00921
00922
00923 inline bool operator!=(const tpoint3D<T>& p) const;
00924
00925
00926
00927
00928
00929
00930
00931
00932 inline bool operator<(const tpoint3D<T>& p) const;
00933
00934
00935
00936
00937
00938
00939
00940
00941 inline bool operator>(const tpoint3D<T>& p) const;
00942
00943
00944
00945
00946
00947
00948
00949
00950
00951
00952
00953
00954
00955 inline T& operator[](const int i) {
00956 assert(i<3);
00957 switch (i) {
00958 case 0: return x;
00959 case 1: return y;
00960 case 2: return z;
00961 default: return x;
00962 }
00963 return x;
00964 }
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974 inline const T& operator[](const int i) const {
00975 assert(i<3);
00976 switch (i) {
00977 case 0: return x;
00978 case 1: return y;
00979 case 2: return z;
00980 default: return x;
00981 }
00982 return x;
00983 }
00984
00985
00986
00987
00988 inline int size() const {
00989 return 3;
00990 }
00991
00992
00993 };
00994
00995
00996
00997 template <class T>
00998 inline tpoint3D<T>& tpoint3D<T>::edivide(const tpoint3D<T>& c) {
00999 x/=c.x;
01000 y/=c.y;
01001 z/=c.z;
01002 return *this;
01003 }
01004
01005 template <class T>
01006 inline tpoint3D<T>& tpoint3D<T>::edivide(const tpoint3D<T>& a,
01007 const tpoint3D<T>& b) {
01008 x=a.x/b.x;
01009 y=a.y/b.y;
01010 z=a.z/b.z;
01011 return *this;
01012 }
01013
01014 template <class T>
01015 inline tpoint3D<T> tpoint3D<T>::operator/(const tpoint3D<T>& c) const {
01016 return tpoint3D<T>(x/c.x,y/c.y,z/c.z);
01017 }
01018
01019
01020
01021
01022 template <class T>
01023 inline tpoint3D<T>& tpoint3D<T>::operator/=(const tpoint3D<T>& c) {
01024 x = static_cast<T>(x/c.x);
01025 y = static_cast<T>(y/c.y);
01026 z = static_cast<T>(z/c.z);
01027 return (*this);
01028 };
01029
01030 template <class T>
01031 inline tpoint3D<T>& tpoint3D<T>::emultiply(const tpoint3D<T>& c) {
01032 x*=c.x;
01033 y*=c.y;
01034 z*=c.z;
01035 return *this;
01036 }
01037
01038 template <class T>
01039 inline tpoint3D<T>& tpoint3D<T>::emultiply(const tpoint3D<T>& a,
01040 const tpoint3D<T>& b) {
01041 x=a.x*b.x;
01042 y=a.y*b.y;
01043 z=a.z*b.z;
01044 return *this;
01045 }
01046
01047
01048 template <class T>
01049 inline tpoint3D<T> tpoint3D<T>::operator%(const int c) const {
01050 return tpoint3D<T>(static_cast<int>(x)%c,
01051 static_cast<int>(y)%c,
01052 static_cast<int>(z)%c);
01053 }
01054
01055 template <class T>
01056 inline tpoint3D<T>& tpoint3D<T>::add(const tpoint3D<T>& p) {
01057 x+=p.x;
01058 y+=p.y;
01059 z+=p.z;
01060 return (*this);
01061 }
01062
01063 template <class T>
01064 inline tpoint3D<T>& tpoint3D<T>::add(const tpoint3D<T>& p1,
01065 const tpoint3D<T>& p2) {
01066 x = p1.x + p2.x;
01067 y = p1.y + p2.y;
01068 z = p1.z + p2.z;
01069
01070 return (*this);
01071 }
01072
01073 template <class T>
01074 inline tpoint3D<T> tpoint3D<T>::operator+(const tpoint3D<T>& p) const {
01075 return tpoint3D<T>(x+p.x,y+p.y,z+p.z);
01076 }
01077
01078 template <class T>
01079 inline tpoint3D<T>& tpoint3D<T>::operator+=(const tpoint3D<T>& p) {
01080 return add(p);
01081 }
01082
01083 template <class T>
01084 inline tpoint3D<T>& tpoint3D<T>::subtract(const tpoint3D<T>& p) {
01085 x-=p.x;
01086 y-=p.y;
01087 z-=p.z;
01088 return (*this);
01089 }
01090
01091 template <class T>
01092 inline tpoint3D<T>& tpoint3D<T>::subtract(const tpoint3D<T>& p1,
01093 const tpoint3D<T>& p2) {
01094 x = p1.x - p2.x;
01095 y = p1.y - p2.y;
01096 z = p1.z - p2.z;
01097
01098 return (*this);
01099 }
01100
01101 template <class T>
01102 inline tpoint3D<T> tpoint3D<T>::operator-(const tpoint3D<T>& p) const {
01103 return tpoint3D<T>(x-p.x,y-p.y,z-p.z);
01104 }
01105
01106 template <class T>
01107 inline tpoint3D<T> tpoint3D<T>::operator-=(const tpoint3D<T>& p) {
01108 return subtract(p);
01109 }
01110
01111 template <class T>
01112 inline tpoint3D<T> tpoint3D<T>::operator*(const tpoint3D<T>& c) const {
01113 return tpoint3D<T>(c.x*x,c.y*x,c.z*z);
01114 }
01115
01116
01117 template <class T>
01118 inline tpoint3D<T>& tpoint3D<T>::operator*=(const tpoint3D<T>& c) {
01119 x*=c.x;
01120 y*=c.y;
01121 z*=c.z;
01122 return *this;
01123 }
01124
01125
01126
01127 template <class T>
01128 inline T tpoint3D<T>::dot(const tpoint3D<T>& p) const {
01129 return static_cast<T>((x*p.x) + (y*p.y) + (z*p.z));
01130 }
01131
01132 template <class T>
01133 inline T tpoint3D<T>::absSqr() const {
01134 return static_cast<T>((x*x) + (y*y) + (z*z));
01135 }
01136
01137 template <class T>
01138 inline T tpoint3D<T>::distanceTo(const tpoint3D<T>& c) const {
01139 tpoint3D<T> t((*this)-c);
01140 return sqrt(t.absSqr());
01141 }
01142
01143 template <class T>
01144 inline T tpoint3D<T>::distanceSqr(const tpoint3D<T>& c) const {
01145 tpoint3D<T> t((*this)-c);
01146 return t.absSqr();
01147 }
01148
01149 template <class T>
01150 inline tpoint3D<T>& tpoint3D<T>::copy(const tpoint3D<T>& p) {
01151 x = p.x;
01152 y = p.y;
01153 z = p.z;
01154 return (*this);
01155 }
01156
01157 template <class T>
01158 inline bool tpoint3D<T>::operator==(const tpoint3D<T>& p) const {
01159 return ((p.y == y) && (p.x == x) && (p.z == z));
01160 }
01161
01162 template <class T>
01163 inline bool tpoint3D<T>::operator!=(const tpoint3D<T>& p) const {
01164 return ((p.y != y) || (p.x != x) || (p.z != p.z));
01165 }
01166
01167 template <class T>
01168 inline bool tpoint3D<T>::operator<(const tpoint3D<T>& p) const {
01169 return ((z < p.z) ||
01170 ((z==p.z) && ((y < p.y) ||
01171 ((y == p.y) && (x < p.x)))));
01172 }
01173
01174 template <class T>
01175 inline bool tpoint3D<T>::operator>(const tpoint3D<T>& p) const {
01176 return ((z > p.z) ||
01177 ((z==p.z) && ((y > p.y) ||
01178 ((y == p.y) && (x > p.x)))));
01179 }
01180
01181
01182
01183
01184
01185
01186 typedef tpoint3D<int> point3D;
01187
01188
01189
01190
01191 typedef tpoint3D<int> ipoint3D;
01192
01193
01194
01195
01196 typedef tpoint3D<float> fpoint3D;
01197
01198
01199
01200 typedef tpoint3D<double> dpoint3D;
01201
01202
01203
01204
01205
01206
01207
01208 template <class T>
01209 bool read(ioHandler& handler,tpoint3D<T>& p,const bool complete=true) {
01210 bool b(true);
01211
01212 if (complete) {
01213 b = b && handler.readBegin();
01214 }
01215
01216 b = b && handler.read(p.x);
01217 b = b && handler.readDataSeparator();
01218 b = b && handler.read(p.y);
01219 b = b && handler.readDataSeparator();
01220 b = b && handler.read(p.z);
01221
01222 if (complete) {
01223 b = b && handler.readEnd();
01224 }
01225
01226 return b;
01227 };
01228
01229
01230
01231
01232
01233
01234
01235 template<class T>
01236 bool write(ioHandler& handler,const tpoint3D<T>& p,const bool complete=true) {
01237 bool b(true);
01238
01239 if (complete) {
01240 b = b && handler.writeBegin();
01241 }
01242 b = b && handler.write(p.x);
01243 b = b && handler.writeDataSeparator();
01244 b = b && handler.write(p.y);
01245 b = b && handler.writeDataSeparator();
01246 b = b && handler.write(p.z);
01247
01248 if (complete) {
01249 b = b && handler.writeEnd();
01250 }
01251
01252 return b;
01253 };
01254 }
01255
01256 namespace std {
01257
01258
01259 template <class T>
01260 inline ostream& operator<<(ostream& s,const lti::tpoint<T>& p) {
01261 s << "(" << p.x << ","
01262 << p.y << ")";
01263 return s;
01264 };
01265
01266
01267 template <class T>
01268 inline istream& operator>>(istream& s,lti::tpoint<T>& p) {
01269 char c;
01270 T x,y;
01271 s >> c
01272 >> x >> c
01273 >> y >> c;
01274 p.x = x;
01275 p.y = y;
01276
01277 return s;
01278 };
01279
01280
01281 template <class T>
01282 inline ostream& operator<<(ostream& s,const lti::tpoint3D<T>& p) {
01283 s << "("
01284 << p.x << ","
01285 << p.y << ","
01286 << p.z << ")";
01287 return s;
01288 };
01289
01290
01291 template <class T>
01292 inline istream& operator>>(istream& s,lti::tpoint3D<T>& p) {
01293 char c;
01294 T x,y,z;
01295 s >> c
01296 >> x >> c
01297 >> y >> c
01298 >> z >> c;
01299 p.x = x;
01300 p.y = y;
01301 p.z = z;
01302
01303 return s;
01304 };
01305 }
01306
01307 #endif
01308
01309
01310