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<unsigned int> uipoint;
00576
00577
00578
00579
00580 typedef tpoint<double> dpoint;
00581
00582
00583
00584
00585 typedef tpoint<float> fpoint;
00586
00587
00588
00589
00590
00591
00592
00593 template <class T>
00594 bool read(ioHandler& handler,tpoint<T>& p,const bool complete=true) {
00595 bool b(true);
00596
00597 if (complete) {
00598 b = b && handler.readBegin();
00599 }
00600
00601 b = b && handler.read(p.x);
00602 b = b && handler.readDataSeparator();
00603 b = b && handler.read(p.y);
00604
00605 if (complete) {
00606 b = b && handler.readEnd();
00607 }
00608
00609 return b;
00610 };
00611
00612
00613
00614
00615
00616
00617
00618 template<class T>
00619 bool write(ioHandler& handler,const tpoint<T>& p,const bool complete=true) {
00620 bool b(true);
00621
00622 if (complete) {
00623 b = b && handler.writeBegin();
00624 }
00625
00626 b = b && handler.write(p.x);
00627 b = b && handler.writeDataSeparator();
00628 b = b && handler.write(p.y);
00629
00630 if (complete) {
00631 b = b && handler.writeEnd();
00632 }
00633
00634 return b;
00635 };
00636
00637
00638
00639
00640
00641
00642
00643
00644
00645
00646 template <class T>
00647 class tpoint3D {
00648 public:
00649
00650
00651
00652
00653 typedef T value_type;
00654
00655
00656
00657
00658 typedef int size_type;
00659
00660
00661
00662
00663 T x;
00664
00665
00666
00667
00668 T y;
00669
00670
00671
00672
00673 T z;
00674
00675
00676
00677
00678 explicit tpoint3D(const T newx=0,
00679 const T newy=0,
00680 const T newz=0) : x(newx),y(newy),z(newz) {};
00681
00682
00683
00684
00685 template <class U>
00686 tpoint3D(const tpoint3D<U>& p)
00687 : x(static_cast<T>(p.x)),y(static_cast<T>(p.y)),z(static_cast<T>(p.z)) {
00688 };
00689
00690
00691
00692
00693 template <class U>
00694 tpoint3D<T>& castFrom(const tpoint3D<U>& p) {
00695 x = static_cast<T>(p.x);
00696 y = static_cast<T>(p.y);
00697 z = static_cast<T>(p.z);
00698 return (*this);
00699 };
00700
00701
00702
00703
00704 inline tpoint3D<T>& set(const T tx,const T ty,const T tz) {
00705 x = tx;
00706 y = ty;
00707 z = tz;
00708 return *this;
00709 }
00710
00711
00712
00713
00714 inline T distanceTo(const tpoint3D<T>& c) const;
00715
00716
00717
00718
00719
00720
00721 inline T distanceSqr(const tpoint3D<T>& c) const;
00722
00723
00724
00725
00726 inline T absSqr() const;
00727
00728
00729
00730
00731 template <class U>
00732 inline tpoint3D<T>& multiply(const U c) {
00733 x = static_cast<T>(x*c);
00734 y = static_cast<T>(y*c);
00735 z = static_cast<T>(z*c);
00736 return (*this);
00737 };
00738
00739
00740
00741
00742 template <class U>
00743 inline tpoint3D<T>& multiply(const tpoint3D<T>& other,const U c) {
00744 x = static_cast<T>(other.x*c);
00745 y = static_cast<T>(other.y*c);
00746 z = static_cast<T>(other.z*c);
00747 return (*this);
00748 };
00749
00750
00751
00752
00753 template <class U>
00754 inline tpoint3D<T> operator*(const U c) const {
00755 return tpoint3D<T>(static_cast<T>(x*c),
00756 static_cast<T>(y*c),
00757 static_cast<T>(z*c));
00758 };
00759
00760
00761
00762
00763 template <class U>
00764 inline tpoint3D<T>& operator*=(const U c) {
00765 x = static_cast<T>(x*c);
00766 y = static_cast<T>(y*c);
00767 z = static_cast<T>(z*c);
00768 return (*this);
00769 };
00770
00771
00772
00773
00774 inline tpoint3D<T> operator*(const tpoint3D<T>& c) const;
00775
00776
00777
00778
00779 inline tpoint3D<T>& operator*=(const tpoint3D<T>& c);
00780
00781
00782
00783
00784
00785 inline tpoint3D<T>& emultiply(const tpoint3D<T>& a,const tpoint3D<T>& b);
00786
00787
00788
00789
00790
00791 inline tpoint3D<T>& emultiply(const tpoint3D<T>& c);
00792
00793
00794
00795
00796 template<class U>
00797 inline tpoint3D<T>& divide(const U c) {
00798 x = static_cast<T>(x/c);
00799 y = static_cast<T>(y/c);
00800 z = static_cast<T>(z/c);
00801 return (*this);
00802 };
00803
00804
00805
00806
00807 template<class U>
00808 inline tpoint3D<T>& divide(const tpoint3D<T>& other,const U c) {
00809 x = static_cast<T>(other.x/c);
00810 y = static_cast<T>(other.y/c);
00811 z = static_cast<T>(other.z/c);
00812 return (*this);
00813 };
00814
00815
00816
00817
00818 template <class U>
00819 inline tpoint3D<T> operator/(const U c) const {
00820 return tpoint3D<T>(static_cast<T>(x/c),
00821 static_cast<T>(y/c),
00822 static_cast<T>(z/c));
00823 };
00824
00825
00826
00827
00828 template <class U>
00829 inline tpoint3D<T>& operator/=(const U c) {
00830 x = static_cast<T>(x/c);
00831 y = static_cast<T>(y/c);
00832 z = static_cast<T>(z/c);
00833 return (*this);
00834 };
00835
00836
00837
00838
00839
00840 inline tpoint3D<T> operator/(const tpoint3D<T>& c) const;
00841
00842
00843
00844
00845 inline tpoint3D<T>& operator/=(const tpoint3D<T>& c);
00846
00847
00848
00849
00850 inline tpoint3D<T>& edivide(const tpoint3D<T>& c);
00851
00852
00853
00854
00855 inline tpoint3D<T>& edivide(const tpoint3D<T>& a,const tpoint3D<T>& b);
00856
00857
00858
00859
00860 inline tpoint3D<T> operator%(const int c) const;
00861
00862
00863
00864
00865
00866 inline tpoint3D<T>& add(const tpoint3D<T>& p);
00867
00868
00869
00870
00871 inline tpoint3D<T>& add(const tpoint3D<T>& p1,
00872 const tpoint3D<T>& p2);
00873
00874
00875
00876
00877 inline tpoint3D<T> operator+(const tpoint3D<T>& p) const;
00878
00879
00880
00881
00882 inline tpoint3D<T>& operator+=(const tpoint3D<T>& p);
00883
00884
00885
00886
00887 inline tpoint3D<T>& subtract(const tpoint3D<T>& p);
00888
00889
00890
00891
00892 inline tpoint3D<T>& subtract(const tpoint3D<T>& p1,
00893 const tpoint3D<T>& p2);
00894
00895
00896
00897
00898 inline tpoint3D<T> operator-(const tpoint3D<T>& p) const;
00899
00900
00901
00902
00903 inline tpoint3D<T> operator-=(const tpoint3D<T>& p);
00904
00905
00906
00907
00908 inline T dot(const tpoint3D<T>& p) const;
00909
00910
00911
00912
00913 inline tpoint3D<T>& copy(const tpoint3D<T>& p);
00914
00915
00916
00917
00918 inline tpoint3D<T>& operator=(const tpoint3D<T>& p) {return copy(p);};
00919
00920
00921
00922
00923 inline bool operator==(const tpoint3D<T>& p) const;
00924
00925
00926
00927
00928 inline bool operator!=(const tpoint3D<T>& p) const;
00929
00930
00931
00932
00933
00934
00935
00936
00937 inline bool operator<(const tpoint3D<T>& p) const;
00938
00939
00940
00941
00942
00943
00944
00945
00946 inline bool operator>(const tpoint3D<T>& p) const;
00947
00948
00949
00950
00951
00952
00953
00954
00955
00956
00957
00958
00959
00960 inline T& operator[](const int i) {
00961 assert(i<3);
00962 switch (i) {
00963 case 0: return x;
00964 case 1: return y;
00965 case 2: return z;
00966 default: return x;
00967 }
00968 return x;
00969 }
00970
00971
00972
00973
00974
00975
00976
00977
00978
00979 inline const T& operator[](const int i) const {
00980 assert(i<3);
00981 switch (i) {
00982 case 0: return x;
00983 case 1: return y;
00984 case 2: return z;
00985 default: return x;
00986 }
00987 return x;
00988 }
00989
00990
00991
00992
00993 inline int size() const {
00994 return 3;
00995 }
00996
00997
00998 };
00999
01000
01001
01002 template <class T>
01003 inline tpoint3D<T>& tpoint3D<T>::edivide(const tpoint3D<T>& c) {
01004 x/=c.x;
01005 y/=c.y;
01006 z/=c.z;
01007 return *this;
01008 }
01009
01010 template <class T>
01011 inline tpoint3D<T>& tpoint3D<T>::edivide(const tpoint3D<T>& a,
01012 const tpoint3D<T>& b) {
01013 x=a.x/b.x;
01014 y=a.y/b.y;
01015 z=a.z/b.z;
01016 return *this;
01017 }
01018
01019 template <class T>
01020 inline tpoint3D<T> tpoint3D<T>::operator/(const tpoint3D<T>& c) const {
01021 return tpoint3D<T>(x/c.x,y/c.y,z/c.z);
01022 }
01023
01024
01025
01026
01027 template <class T>
01028 inline tpoint3D<T>& tpoint3D<T>::operator/=(const tpoint3D<T>& c) {
01029 x = static_cast<T>(x/c.x);
01030 y = static_cast<T>(y/c.y);
01031 z = static_cast<T>(z/c.z);
01032 return (*this);
01033 };
01034
01035 template <class T>
01036 inline tpoint3D<T>& tpoint3D<T>::emultiply(const tpoint3D<T>& c) {
01037 x*=c.x;
01038 y*=c.y;
01039 z*=c.z;
01040 return *this;
01041 }
01042
01043 template <class T>
01044 inline tpoint3D<T>& tpoint3D<T>::emultiply(const tpoint3D<T>& a,
01045 const tpoint3D<T>& b) {
01046 x=a.x*b.x;
01047 y=a.y*b.y;
01048 z=a.z*b.z;
01049 return *this;
01050 }
01051
01052
01053 template <class T>
01054 inline tpoint3D<T> tpoint3D<T>::operator%(const int c) const {
01055 return tpoint3D<T>(static_cast<int>(x)%c,
01056 static_cast<int>(y)%c,
01057 static_cast<int>(z)%c);
01058 }
01059
01060 template <class T>
01061 inline tpoint3D<T>& tpoint3D<T>::add(const tpoint3D<T>& p) {
01062 x+=p.x;
01063 y+=p.y;
01064 z+=p.z;
01065 return (*this);
01066 }
01067
01068 template <class T>
01069 inline tpoint3D<T>& tpoint3D<T>::add(const tpoint3D<T>& p1,
01070 const tpoint3D<T>& p2) {
01071 x = p1.x + p2.x;
01072 y = p1.y + p2.y;
01073 z = p1.z + p2.z;
01074
01075 return (*this);
01076 }
01077
01078 template <class T>
01079 inline tpoint3D<T> tpoint3D<T>::operator+(const tpoint3D<T>& p) const {
01080 return tpoint3D<T>(x+p.x,y+p.y,z+p.z);
01081 }
01082
01083 template <class T>
01084 inline tpoint3D<T>& tpoint3D<T>::operator+=(const tpoint3D<T>& p) {
01085 return add(p);
01086 }
01087
01088 template <class T>
01089 inline tpoint3D<T>& tpoint3D<T>::subtract(const tpoint3D<T>& p) {
01090 x-=p.x;
01091 y-=p.y;
01092 z-=p.z;
01093 return (*this);
01094 }
01095
01096 template <class T>
01097 inline tpoint3D<T>& tpoint3D<T>::subtract(const tpoint3D<T>& p1,
01098 const tpoint3D<T>& p2) {
01099 x = p1.x - p2.x;
01100 y = p1.y - p2.y;
01101 z = p1.z - p2.z;
01102
01103 return (*this);
01104 }
01105
01106 template <class T>
01107 inline tpoint3D<T> tpoint3D<T>::operator-(const tpoint3D<T>& p) const {
01108 return tpoint3D<T>(x-p.x,y-p.y,z-p.z);
01109 }
01110
01111 template <class T>
01112 inline tpoint3D<T> tpoint3D<T>::operator-=(const tpoint3D<T>& p) {
01113 return subtract(p);
01114 }
01115
01116 template <class T>
01117 inline tpoint3D<T> tpoint3D<T>::operator*(const tpoint3D<T>& c) const {
01118 return tpoint3D<T>(c.x*x,c.y*x,c.z*z);
01119 }
01120
01121
01122 template <class T>
01123 inline tpoint3D<T>& tpoint3D<T>::operator*=(const tpoint3D<T>& c) {
01124 x*=c.x;
01125 y*=c.y;
01126 z*=c.z;
01127 return *this;
01128 }
01129
01130
01131
01132 template <class T>
01133 inline T tpoint3D<T>::dot(const tpoint3D<T>& p) const {
01134 return static_cast<T>((x*p.x) + (y*p.y) + (z*p.z));
01135 }
01136
01137 template <class T>
01138 inline T tpoint3D<T>::absSqr() const {
01139 return static_cast<T>((x*x) + (y*y) + (z*z));
01140 }
01141
01142 template <class T>
01143 inline T tpoint3D<T>::distanceTo(const tpoint3D<T>& c) const {
01144 tpoint3D<T> t((*this)-c);
01145 return sqrt(t.absSqr());
01146 }
01147
01148 template <class T>
01149 inline T tpoint3D<T>::distanceSqr(const tpoint3D<T>& c) const {
01150 tpoint3D<T> t((*this)-c);
01151 return t.absSqr();
01152 }
01153
01154 template <class T>
01155 inline tpoint3D<T>& tpoint3D<T>::copy(const tpoint3D<T>& p) {
01156 x = p.x;
01157 y = p.y;
01158 z = p.z;
01159 return (*this);
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 == z));
01165 }
01166
01167 template <class T>
01168 inline bool tpoint3D<T>::operator!=(const tpoint3D<T>& p) const {
01169 return ((p.y != y) || (p.x != x) || (p.z != p.z));
01170 }
01171
01172 template <class T>
01173 inline bool tpoint3D<T>::operator<(const tpoint3D<T>& p) const {
01174 return ((z < p.z) ||
01175 ((z==p.z) && ((y < p.y) ||
01176 ((y == p.y) && (x < p.x)))));
01177 }
01178
01179 template <class T>
01180 inline bool tpoint3D<T>::operator>(const tpoint3D<T>& p) const {
01181 return ((z > p.z) ||
01182 ((z==p.z) && ((y > p.y) ||
01183 ((y == p.y) && (x > p.x)))));
01184 }
01185
01186
01187
01188
01189
01190
01191 typedef tpoint3D<int> point3D;
01192
01193
01194
01195
01196 typedef tpoint3D<int> ipoint3D;
01197
01198
01199
01200
01201 typedef tpoint3D<float> fpoint3D;
01202
01203
01204
01205 typedef tpoint3D<double> dpoint3D;
01206
01207
01208
01209
01210
01211
01212
01213 template <class T>
01214 bool read(ioHandler& handler,tpoint3D<T>& p,const bool complete=true) {
01215 bool b(true);
01216
01217 if (complete) {
01218 b = b && handler.readBegin();
01219 }
01220
01221 b = b && handler.read(p.x);
01222 b = b && handler.readDataSeparator();
01223 b = b && handler.read(p.y);
01224 b = b && handler.readDataSeparator();
01225 b = b && handler.read(p.z);
01226
01227 if (complete) {
01228 b = b && handler.readEnd();
01229 }
01230
01231 return b;
01232 };
01233
01234
01235
01236
01237
01238
01239
01240 template<class T>
01241 bool write(ioHandler& handler,const tpoint3D<T>& p,const bool complete=true) {
01242 bool b(true);
01243
01244 if (complete) {
01245 b = b && handler.writeBegin();
01246 }
01247 b = b && handler.write(p.x);
01248 b = b && handler.writeDataSeparator();
01249 b = b && handler.write(p.y);
01250 b = b && handler.writeDataSeparator();
01251 b = b && handler.write(p.z);
01252
01253 if (complete) {
01254 b = b && handler.writeEnd();
01255 }
01256
01257 return b;
01258 };
01259 }
01260
01261 namespace std {
01262
01263
01264 template <class T>
01265 inline ostream& operator<<(ostream& s,const lti::tpoint<T>& p) {
01266 s << "(" << p.x << ","
01267 << p.y << ")";
01268 return s;
01269 };
01270
01271
01272 template <class T>
01273 inline istream& operator>>(istream& s,lti::tpoint<T>& p) {
01274 char c;
01275 s >> c
01276 >> p.x >> c
01277 >> p.y >> c;
01278
01279 return s;
01280 };
01281
01282
01283 template <class T>
01284 inline ostream& operator<<(ostream& s,const lti::tpoint3D<T>& p) {
01285 s << "("
01286 << p.x << ","
01287 << p.y << ","
01288 << p.z << ")";
01289 return s;
01290 };
01291
01292
01293 template <class T>
01294 inline istream& operator>>(istream& s,lti::tpoint3D<T>& p) {
01295 char c;
01296 s >> c
01297 >> p.x >> c
01298 >> p.y >> c
01299 >> p.z >> c;
01300
01301 return s;
01302 };
01303 }
01304
01305 #endif