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 #ifndef LIGHTWEIGHT_GEOM_DATA_H
00029 #define LIGHTWEIGHT_GEOM_DATA_H
00030
00031 #include <mrpt/utils/utils_defs.h>
00032 #include <mrpt/utils/stl_extensions.h>
00033 #include <mrpt/math/utils.h>
00034
00035 namespace mrpt {
00036 namespace poses {
00037 class CPoseOrPoint;
00038 class CPoint2D;
00039 class CPoint3D;
00040 class CPose2D;
00041 class CPose3D;
00042 }
00043 namespace utils { class CStream; }
00044 }
00045
00046 namespace mrpt {
00047 namespace math {
00048 using namespace mrpt::utils;
00049
00050 struct TPoint2D;
00051 struct TPose2D;
00052 struct TPoint3D;
00053 struct TPose3D;
00054
00055
00056 #pragma pack(push,1)
00057
00058
00059
00060
00061
00062
00063 struct MRPTDLLIMPEXP TPoint2D {
00064
00065
00066
00067 double x;
00068
00069
00070
00071 double y;
00072
00073
00074
00075
00076 explicit TPoint2D(const TPose2D &p);
00077
00078
00079
00080
00081 explicit TPoint2D(const TPoint3D &p);
00082
00083
00084
00085
00086 explicit TPoint2D(const TPose3D &p);
00087
00088
00089
00090
00091 explicit TPoint2D(const mrpt::poses::CPoseOrPoint &p);
00092
00093
00094
00095
00096 TPoint2D(const mrpt::poses::CPoint2D &p);
00097
00098
00099
00100 inline TPoint2D(double xx,double yy):x(xx),y(yy) {}
00101
00102
00103
00104 inline TPoint2D() {}
00105
00106
00107
00108 inline double &operator[](size_t i) {
00109 return (&x)[i];
00110 }
00111
00112
00113
00114 inline const double &operator[](size_t i) const {
00115 return (&x)[i];
00116 }
00117
00118
00119
00120 inline void getAsVector(vector_double &v) const {
00121 v.resize(2);
00122 v[0]=x; v[1]=y;
00123 }
00124
00125 bool operator<(const TPoint2D &p) const;
00126
00127 inline TPoint2D &operator+=(const TPoint2D &p) {
00128 x+=p.x;
00129 y+=p.y;
00130 return *this;
00131 }
00132
00133 inline TPoint2D &operator-=(const TPoint2D &p) {
00134 x-=p.x;
00135 y-=p.y;
00136 return *this;
00137 }
00138
00139 inline TPoint2D &operator*=(double d) {
00140 x*=d;
00141 y*=d;
00142 return *this;
00143 }
00144
00145 inline TPoint2D &operator/=(double d) {
00146 x/=d;
00147 y/=d;
00148 return *this;
00149 }
00150
00151 inline TPoint2D operator+(const TPoint2D &p) const {
00152 TPoint2D r(*this);
00153 return r+=p;
00154 }
00155
00156 inline TPoint2D operator-(const TPoint2D &p) const {
00157 TPoint2D r(*this);
00158 return r-=p;
00159 }
00160
00161 inline TPoint2D operator*(double d) const {
00162 TPoint2D r(*this);
00163 return r*=d;
00164 }
00165
00166 inline TPoint2D operator/(double d) const {
00167 TPoint2D r(*this);
00168 return r/=d;
00169 }
00170 };
00171
00172
00173
00174
00175
00176 struct MRPTDLLIMPEXP TPose2D {
00177
00178
00179
00180 double x;
00181
00182
00183
00184 double y;
00185
00186
00187
00188 double phi;
00189
00190
00191
00192
00193 TPose2D(const TPoint2D &p);
00194
00195
00196
00197
00198 explicit TPose2D(const TPoint3D &p);
00199
00200
00201
00202
00203 explicit TPose2D(const TPose3D &p);
00204
00205
00206
00207
00208 TPose2D(const mrpt::poses::CPose2D &p);
00209
00210
00211
00212 inline TPose2D(double xx,double yy,double pphi):x(xx),y(yy),phi(pphi) {}
00213
00214
00215
00216 inline TPose2D() {}
00217
00218
00219
00220 inline double &operator[](size_t i) {
00221 return (&x)[i];
00222 }
00223
00224
00225
00226 inline const double &operator[](size_t i) const {
00227 return (&x)[i];
00228 }
00229
00230
00231
00232 inline void getAsVector(vector_double &v) const {
00233 v.resize(3);
00234 v[0]=x; v[1]=y; v[2]=phi;
00235 }
00236 };
00237
00238
00239
00240
00241
00242 struct MRPTDLLIMPEXP TPoint3D {
00243
00244
00245
00246 double x;
00247
00248
00249
00250 double y;
00251
00252
00253
00254 double z;
00255
00256
00257
00258
00259 TPoint3D(const TPoint2D &p);
00260
00261
00262
00263
00264 explicit TPoint3D(const TPose2D &p);
00265
00266
00267
00268
00269 explicit TPoint3D(const TPose3D &p);
00270
00271
00272
00273
00274 TPoint3D(const mrpt::poses::CPoint3D &p);
00275
00276
00277
00278
00279 explicit TPoint3D(const mrpt::poses::CPose3D &p);
00280
00281
00282
00283 inline TPoint3D(double xx,double yy,double zz):x(xx),y(yy),z(zz) {}
00284
00285
00286
00287 inline TPoint3D() {}
00288
00289
00290
00291 inline double &operator[](size_t i) {
00292 return (&x)[i];
00293 }
00294
00295
00296
00297 inline const double &operator[](size_t i) const {
00298 return (&x)[i];
00299 }
00300
00301
00302
00303 inline double distanceTo(const TPoint3D &p) const {
00304 return sqrt(square(p.x-x)+square(p.y-y)+square(p.z-z));
00305 }
00306
00307
00308
00309 inline double sqrDistanceTo(const TPoint3D &p) const {
00310 return square(p.x-x)+square(p.y-y)+square(p.z-z);
00311 }
00312
00313
00314
00315 inline double norm() const {
00316 return sqrt(square(x)+square(y)+square(z));
00317 }
00318
00319
00320
00321 inline TPoint3D &operator*=(const double f) {
00322 x*=f;y*=f;z*=f;
00323 return *this;
00324 }
00325
00326
00327
00328 void getAsVector(vector_double &v) const {
00329 v.resize(3);
00330 v[0]=x; v[1]=y; v[2]=z;
00331 }
00332
00333
00334
00335 inline TPoint3D &operator+=(const TPoint3D &p) {
00336 x+=p.x;
00337 y+=p.y;
00338 z+=p.z;
00339 return *this;
00340 }
00341
00342
00343
00344 inline TPoint3D &operator-=(const TPoint3D &p) {
00345 x-=p.x;
00346 y-=p.y;
00347 z-=p.z;
00348 return *this;
00349 }
00350
00351
00352
00353 inline TPoint3D operator+(const TPoint3D &p) const {
00354 return TPoint3D(x+p.x,y+p.y,z+p.z);
00355 }
00356
00357
00358
00359 inline TPoint3D operator-(const TPoint3D &p) const {
00360 return TPoint3D(x-p.x,y-p.y,z-p.z);
00361 }
00362
00363 inline TPoint3D operator*(double d) const {
00364 return TPoint3D(x*d,y*d,z*d);
00365 }
00366
00367 inline TPoint3D operator/(double d) const {
00368 return TPoint3D(x/d,y/d,z/d);
00369 }
00370
00371 bool operator<(const TPoint3D &p) const;
00372 };
00373
00374
00375
00376
00377
00378 struct MRPTDLLIMPEXP TPose3D {
00379
00380
00381
00382 double x;
00383
00384
00385
00386 double y;
00387
00388
00389
00390 double z;
00391
00392
00393
00394 double yaw;
00395
00396
00397
00398 double pitch;
00399
00400
00401
00402 double roll;
00403
00404
00405
00406
00407 TPose3D(const TPoint2D &p);
00408
00409
00410
00411
00412 TPose3D(const TPose2D &p);
00413
00414
00415
00416
00417 TPose3D(const TPoint3D &p);
00418
00419
00420
00421
00422 TPose3D(const mrpt::poses::CPose3D &p);
00423
00424
00425
00426 TPose3D(double _x,double _y,double _z,double _yaw,double _pitch,double _roll):x(_x),y(_y),z(_z),yaw(_yaw),pitch(_pitch),roll(_roll) {}
00427
00428
00429
00430 inline TPose3D() {}
00431
00432
00433
00434 inline double &operator[](size_t i) {
00435 return (&x)[i];
00436 }
00437
00438
00439
00440 inline const double &operator[](size_t i) const {
00441 return (&x)[i];
00442 }
00443
00444
00445
00446 double norm() const {
00447 return sqrt(square(x)+square(y)+square(z));
00448 }
00449
00450
00451
00452 void getAsVector(vector_double &v) const {
00453 v.resize(6);
00454 v[0]=x; v[1]=y; v[2]=z; v[3]=yaw; v[4]=pitch; v[5]=roll;
00455 }
00456 };
00457 #pragma pack(pop)
00458
00459
00460
00461 inline TPoint3D operator-(const TPoint3D &p1) {
00462 return TPoint3D(-p1.x,-p1.y,-p1.z);
00463 }
00464
00465
00466
00467 inline bool operator==(const TPoint2D &p1,const TPoint2D &p2) {
00468 return (p1.x==p2.x)&&(p1.y==p2.y);
00469 }
00470
00471
00472
00473 inline bool operator!=(const TPoint2D &p1,const TPoint2D &p2) {
00474 return (p1.x!=p2.x)||(p1.y!=p2.y);
00475 }
00476
00477
00478
00479 inline bool operator==(const TPoint3D &p1,const TPoint3D &p2) {
00480 return (p1.x==p2.x)&&(p1.y==p2.y)&&(p1.z==p2.z);
00481 }
00482
00483
00484
00485 inline bool operator!=(const TPoint3D &p1,const TPoint3D &p2) {
00486 return (p1.x!=p2.x)||(p1.y!=p2.y)||(p1.z!=p2.z);
00487 }
00488
00489
00490
00491 inline bool operator==(const TPose2D &p1,const TPose2D &p2) {
00492 return (p1.x==p2.x)&&(p1.y==p2.y)&&(mrpt::math::wrapTo2Pi(p1.phi)==mrpt::math::wrapTo2Pi(p2.phi));
00493 }
00494
00495
00496
00497 inline bool operator!=(const TPose2D &p1,const TPose2D &p2) {
00498 return (p1.x!=p2.x)||(p1.y!=p2.y)||(mrpt::math::wrapTo2Pi(p1.phi)!=mrpt::math::wrapTo2Pi(p2.phi));
00499 }
00500
00501
00502
00503 inline bool operator==(const TPose3D &p1,const TPose3D &p2) {
00504 return (p1.x==p2.x)&&(p1.y==p2.y)&&(p1.z==p2.z)&&(mrpt::math::wrapTo2Pi(p1.yaw)==mrpt::math::wrapTo2Pi(p2.yaw))&&(mrpt::math::wrapTo2Pi(p1.pitch)==mrpt::math::wrapTo2Pi(p2.pitch))&&(mrpt::math::wrapTo2Pi(p1.roll)==mrpt::math::wrapTo2Pi(p2.roll));
00505 }
00506
00507
00508
00509 inline bool operator!=(const TPose3D &p1,const TPose3D &p2) {
00510 return (p1.x!=p2.x)||(p1.y!=p2.y)||(p1.z!=p2.z)||(mrpt::math::wrapTo2Pi(p1.yaw)!=mrpt::math::wrapTo2Pi(p2.yaw))||(mrpt::math::wrapTo2Pi(p1.pitch)!=mrpt::math::wrapTo2Pi(p2.pitch))||(mrpt::math::wrapTo2Pi(p1.roll)!=mrpt::math::wrapTo2Pi(p2.roll));
00511 }
00512
00513 struct MRPTDLLIMPEXP TSegment3D;
00514 struct MRPTDLLIMPEXP TLine3D;
00515 class MRPTDLLIMPEXP TPolygon3D;
00516 struct MRPTDLLIMPEXP TObject3D;
00517
00518
00519 #pragma pack(push,1)
00520
00521
00522
00523
00524 struct MRPTDLLIMPEXP TSegment2D {
00525 public:
00526
00527
00528
00529 TPoint2D point1;
00530
00531
00532
00533 TPoint2D point2;
00534
00535
00536
00537 double length() const;
00538
00539
00540
00541 double distance(const TPoint2D &point) const;
00542
00543
00544
00545 bool contains(const TPoint2D &point) const;
00546
00547
00548
00549 inline TPoint2D &operator[](size_t i) {
00550 return (&point1)[i];
00551 }
00552
00553
00554
00555 inline const TPoint2D &operator[](size_t i) const {
00556 return (&point1)[i];
00557 }
00558
00559
00560
00561 void generate3DObject(TSegment3D &s) const;
00562
00563
00564
00565 inline void getCenter(TPoint2D &p) const {
00566 p.x=(point1.x+point2.x)/2;
00567 p.y=(point1.y+point2.y)/2;
00568 }
00569
00570
00571
00572 TSegment2D(const TPoint2D &p1,const TPoint2D &p2):point1(p1),point2(p2) {}
00573
00574
00575
00576 TSegment2D() {}
00577
00578
00579
00580 explicit TSegment2D(const TSegment3D &s);
00581
00582 bool operator<(const TSegment2D &s) const;
00583 };
00584
00585
00586
00587
00588 struct MRPTDLLIMPEXP TSegment3D {
00589 public:
00590
00591
00592
00593 TPoint3D point1;
00594
00595
00596
00597 TPoint3D point2;
00598
00599
00600
00601 double length() const;
00602
00603
00604
00605 double distance(const TPoint3D &point) const;
00606
00607
00608
00609 bool contains(const TPoint3D &point) const;
00610
00611
00612
00613 inline TPoint3D &operator[](size_t i) {
00614 return (&point1)[i];
00615 }
00616
00617
00618
00619 inline const TPoint3D &operator[](size_t i) const {
00620 return (&point1)[i];
00621 }
00622
00623
00624
00625 inline void generate2DObject(TSegment2D &s) const {
00626 s=TSegment2D(*this);
00627 }
00628
00629
00630
00631 inline void getCenter(TPoint3D &p) const {
00632 p.x=(point1.x+point2.x)/2;
00633 p.y=(point1.y+point2.y)/2;
00634 p.z=(point1.z+point2.z)/2;
00635 }
00636
00637
00638
00639 TSegment3D(const TPoint3D &p1,const TPoint3D &p2):point1(p1),point2(p2) {}
00640
00641
00642
00643 TSegment3D() {}
00644
00645
00646
00647 TSegment3D(const TSegment2D &s):point1(s.point1),point2(s.point2) {}
00648
00649 bool operator<(const TSegment3D &s) const;
00650 };
00651 #pragma pack(pop)
00652
00653 inline bool operator==(const TSegment2D &s1,const TSegment2D &s2) {
00654 return (s1.point1==s2.point1)&&(s1.point2==s2.point2);
00655 }
00656
00657 inline bool operator!=(const TSegment2D &s1,const TSegment2D &s2) {
00658 return (s1.point1!=s1.point1)||(s1.point2!=s2.point2);
00659 }
00660
00661 inline bool operator==(const TSegment3D &s1,const TSegment3D &s2) {
00662 return (s1.point1==s2.point1)&&(s1.point2==s2.point2);
00663 }
00664
00665 inline bool operator!=(const TSegment3D &s1,const TSegment3D &s2) {
00666 return (s1.point1!=s1.point1)||(s1.point2!=s2.point2);
00667 }
00668
00669
00670
00671
00672
00673 struct MRPTDLLIMPEXP TLine2D {
00674 public:
00675
00676
00677
00678 double coefs[3];
00679
00680
00681
00682 double evaluatePoint(const TPoint2D &point) const;
00683
00684
00685
00686 bool contains(const TPoint2D &point) const;
00687
00688
00689
00690 double distance(const TPoint2D &point) const;
00691
00692
00693
00694 void getNormalVector(double (&vector)[2]) const;
00695
00696
00697
00698 void unitarize();
00699
00700
00701
00702 inline void getUnitaryNormalVector(double (&vector)[2]) {
00703 unitarize();
00704 getNormalVector(vector);
00705 }
00706
00707
00708
00709 void getDirectorVector(double (&vector)[2]) const;
00710
00711
00712
00713 inline void getUnitaryDirectorVector(double (&vector)[2]) {
00714 unitarize();
00715 getDirectorVector(vector);
00716 }
00717
00718
00719
00720 void generate3DObject(TLine3D &l) const;
00721
00722
00723
00724
00725 void getAsPose2D(mrpt::poses::CPose2D &outPose) const;
00726
00727
00728
00729
00730
00731 void getAsPose2DForcingOrigin(const TPoint2D &origin,mrpt::poses::CPose2D &outPose) const;
00732
00733
00734
00735
00736 TLine2D(const TPoint2D &p1,const TPoint2D &p2) throw(std::logic_error);
00737
00738
00739
00740 explicit TLine2D(const TSegment2D &s);
00741
00742
00743
00744 TLine2D() {}
00745
00746
00747
00748 inline TLine2D(double A,double B,double C) {
00749 coefs[0]=A;
00750 coefs[1]=B;
00751 coefs[2]=C;
00752 }
00753
00754
00755
00756
00757 explicit TLine2D(const TLine3D &l);
00758 };
00759
00760
00761
00762
00763
00764 struct MRPTDLLIMPEXP TLine3D {
00765 public:
00766
00767
00768
00769 TPoint3D pBase;
00770
00771
00772
00773 double director[3];
00774
00775
00776
00777 bool contains(const TPoint3D &point) const;
00778
00779
00780
00781 double distance(const TPoint3D &point) const;
00782
00783
00784
00785 void unitarize();
00786
00787
00788
00789 inline void getDirectorVector(double (&vector)[3]) const {
00790 for (size_t i=0;i<3;i++) vector[i]=director[i];
00791 }
00792
00793
00794
00795 inline void getUnitaryDirectorVector(double (&vector)[3]) {
00796 unitarize();
00797 getDirectorVector(vector);
00798 }
00799
00800
00801
00802
00803 inline void generate2DObject(TLine2D &l) const {
00804 l=TLine2D(*this);
00805 }
00806
00807
00808
00809
00810 TLine3D(const TPoint3D &p1,const TPoint3D &p2) throw(std::logic_error);
00811
00812
00813
00814 explicit TLine3D(const TSegment3D &s);
00815
00816
00817
00818 TLine3D() {}
00819
00820
00821
00822 TLine3D(const TLine2D &l);
00823 };
00824
00825
00826
00827
00828
00829 struct MRPTDLLIMPEXP TPlane {
00830 public:
00831
00832
00833
00834 double coefs[4];
00835
00836
00837
00838 double evaluatePoint(const TPoint3D &point) const;
00839
00840
00841
00842 bool contains(const TPoint3D &point) const;
00843
00844
00845
00846 inline bool contains(const TSegment3D &segment) const {
00847 return contains(segment.point1)&&contains(segment.point2);
00848 }
00849
00850
00851
00852 bool contains(const TLine3D &line) const;
00853
00854
00855
00856 double distance(const TPoint3D &point) const;
00857
00858
00859
00860 double distance(const TLine3D &line) const;
00861
00862
00863
00864 void getNormalVector(double (&vec)[3]) const;
00865
00866
00867
00868 void unitarize();
00869
00870
00871
00872 inline void getUnitaryNormalVector(double (&vec)[3]) {
00873 unitarize();
00874 getNormalVector(vec);
00875 }
00876
00877
00878
00879 void getAsPose3D(mrpt::poses::CPose3D &outPose);
00880
00881
00882
00883 inline void getAsPose3D(mrpt::poses::CPose3D &outPose) const {
00884 TPlane p=*this;
00885 p.getAsPose3D(outPose);
00886 }
00887
00888
00889
00890
00891 void getAsPose3DForcingOrigin(const TPoint3D &newOrigin,mrpt::poses::CPose3D &pose);
00892
00893
00894
00895
00896 inline void getAsPose3DForcingOrigin(const TPoint3D &newOrigin,mrpt::poses::CPose3D &pose) const {
00897 TPlane p=*this;
00898 p.getAsPose3DForcingOrigin(newOrigin,pose);
00899 }
00900
00901
00902
00903
00904 TPlane(const TPoint3D &p1,const TPoint3D &p2,const TPoint3D &p3) throw(std::logic_error);
00905
00906
00907
00908
00909 TPlane(const TPoint3D &p1,const TLine3D &r2) throw(std::logic_error);
00910
00911
00912
00913
00914 TPlane(const TLine3D &r1,const TLine3D &r2) throw(std::logic_error);
00915
00916
00917
00918 TPlane() {}
00919
00920
00921
00922 inline TPlane(double A,double B,double C,double D) {
00923 coefs[0]=A;
00924 coefs[1]=B;
00925 coefs[2]=C;
00926 coefs[3]=D;
00927 }
00928
00929
00930
00931 inline TPlane(const double (&vec)[4]) {
00932 for (size_t i=0;i<4;i++) coefs[i]=vec[i];
00933 }
00934 };
00935
00936 typedef TPlane TPlane3D;
00937
00938
00939
00940
00941
00942 class MRPTDLLIMPEXP TPolygon2D:public std::vector<TPoint2D> {
00943 public:
00944
00945
00946
00947 double distance(const TPoint2D &point) const;
00948
00949
00950
00951 bool contains(const TPoint2D &point) const;
00952
00953
00954
00955 void getAsSegmentList(std::vector<TSegment2D> &v) const;
00956
00957
00958
00959 void generate3DObject(TPolygon3D &p) const;
00960
00961
00962
00963 void getCenter(TPoint2D &p) const;
00964
00965
00966
00967 bool isConvex() const;
00968
00969
00970
00971
00972 void removeRepeatedVertices();
00973
00974
00975
00976
00977 void removeRedundantVertices();
00978
00979
00980
00981
00982 void getPlotData(std::vector<double> &x,std::vector<double> &y) const;
00983
00984
00985
00986 TPolygon2D():std::vector<TPoint2D>() {}
00987
00988
00989
00990 explicit TPolygon2D(size_t N):std::vector<TPoint2D>(N) {}
00991
00992
00993
00994 TPolygon2D(const std::vector<TPoint2D> &v):std::vector<TPoint2D>(v) {}
00995
00996
00997
00998 explicit TPolygon2D(const TPolygon3D &p);
00999
01000
01001
01002
01003 static void createRegularPolygon(size_t numEdges,double radius,TPolygon2D &poly);
01004
01005
01006
01007
01008 static inline void createRegularPolygon(size_t numEdges,double radius,TPolygon2D &poly,const mrpt::poses::CPose2D &pose);
01009 };
01010
01011
01012
01013
01014
01015 class MRPTDLLIMPEXP TPolygon3D:public std::vector<TPoint3D> {
01016 public:
01017
01018
01019
01020 double distance(const TPoint3D &point) const;
01021
01022
01023
01024 bool contains(const TPoint3D &point) const;
01025
01026
01027
01028 void getAsSegmentList(std::vector<TSegment3D> &v) const;
01029
01030
01031
01032 bool getPlane(TPlane &p) const;
01033
01034
01035
01036
01037 void getBestFittingPlane(TPlane &p) const;
01038
01039
01040
01041
01042 inline void generate2DObject(TPolygon2D &p) const {
01043 p=TPolygon2D(*this);
01044 }
01045
01046
01047
01048 void getCenter(TPoint3D &p) const;
01049
01050
01051
01052
01053 bool isSkew() const;
01054
01055
01056
01057 void removeRepeatedVertices();
01058
01059
01060
01061 void removeRedundantVertices();
01062
01063
01064
01065 TPolygon3D():std::vector<TPoint3D>() {}
01066
01067
01068
01069 explicit TPolygon3D(size_t N):std::vector<TPoint3D>(N) {}
01070
01071
01072
01073 TPolygon3D(const std::vector<TPoint3D> &v):std::vector<TPoint3D>(v) {}
01074
01075
01076
01077 TPolygon3D(const TPolygon2D &p);
01078
01079
01080
01081
01082 static void createRegularPolygon(size_t numEdges,double radius,TPolygon3D &poly);
01083
01084
01085
01086
01087 static inline void createRegularPolygon(size_t numEdges,double radius,TPolygon3D &poly,const mrpt::poses::CPose3D &pose);
01088 };
01089
01090
01091
01092
01093
01094 const unsigned char GEOMETRIC_TYPE_POINT=0;
01095
01096
01097
01098
01099 const unsigned char GEOMETRIC_TYPE_SEGMENT=1;
01100
01101
01102
01103
01104 const unsigned char GEOMETRIC_TYPE_LINE=2;
01105
01106
01107
01108
01109 const unsigned char GEOMETRIC_TYPE_POLYGON=3;
01110
01111
01112
01113
01114 const unsigned char GEOMETRIC_TYPE_PLANE=4;
01115
01116
01117
01118
01119 const unsigned char GEOMETRIC_TYPE_UNDEFINED=255;
01120
01121
01122
01123
01124
01125 #ifdef TOBJECTS_USE_UNIONS
01126 struct MRPTDLLIMPEXP TObject2D {
01127 private:
01128
01129
01130
01131 unsigned char type;
01132
01133
01134
01135 union {
01136 TPoint2D *point;
01137 TSegment2D *segment;
01138 TLine2D *line;
01139 TPolygon2D *polygon;
01140 } data;
01141
01142
01143
01144 void destroy() {
01145 switch(type) {
01146 case GEOMETRIC_TYPE_POINT:
01147 delete data.point;
01148 break;
01149 case GEOMETRIC_TYPE_SEGMENT:
01150 delete data.segment;
01151 break;
01152 case GEOMETRIC_TYPE_LINE:
01153 delete data.line;
01154 break;
01155 case GEOMETRIC_TYPE_POLYGON:
01156 delete data.polygon;
01157 break;
01158 }
01159 type=GEOMETRIC_TYPE_UNDEFINED;
01160 }
01161 public:
01162
01163
01164
01165 TObject2D(const TPoint2D &p):type(GEOMETRIC_TYPE_POINT) {
01166 data.point=new TPoint2D(p);
01167 }
01168
01169
01170
01171 TObject2D(const TSegment2D &s):type(GEOMETRIC_TYPE_SEGMENT) {
01172 data.segment=new TSegment2D(s);
01173 }
01174
01175
01176
01177 TObject2D(const TLine2D &r):type(GEOMETRIC_TYPE_LINE) {
01178 data.line=new TLine2D(r);
01179 }
01180
01181
01182
01183 TObject2D(const TPolygon2D &p):type(GEOMETRIC_TYPE_POLYGON) {
01184 data.polygon=new TPolygon2D(p);
01185 }
01186
01187
01188
01189 TObject2D():type(GEOMETRIC_TYPE_UNDEFINED) {}
01190
01191
01192
01193 ~TObject2D() {
01194 destroy();
01195 }
01196
01197
01198
01199 inline bool isPoint() const {
01200 return type==GEOMETRIC_TYPE_POINT;
01201 }
01202
01203
01204
01205 inline bool isSegment() const {
01206 return type==GEOMETRIC_TYPE_SEGMENT;
01207 }
01208
01209
01210
01211 inline bool isLine() const {
01212 return type==GEOMETRIC_TYPE_LINE;
01213 }
01214
01215
01216
01217 inline bool isPolygon() const {
01218 return type==GEOMETRIC_TYPE_POLYGON;
01219 }
01220
01221
01222
01223 inline unsigned char getType() const {
01224 return type;
01225 }
01226
01227
01228
01229 inline bool getPoint(TPoint2D &p) const {
01230 if (isPoint()) {
01231 p=*(data.point);
01232 return true;
01233 } else return false;
01234 }
01235
01236
01237
01238 inline bool getSegment(TSegment2D &s) const {
01239 if (isSegment()) {
01240 s=*(data.segment);
01241 return true;
01242 } else return false;
01243 }
01244
01245
01246
01247 inline bool getLine(TLine2D &r) const {
01248 if (isLine()) {
01249 r=*(data.line);
01250 return true;
01251 } else return false;
01252 }
01253
01254
01255
01256 inline bool getPolygon(TPolygon2D &p) const {
01257 if (isPolygon()) {
01258 p=*(data.polygon);
01259 return true;
01260 } else return false;
01261 }
01262
01263
01264
01265 void operator=(const TObject2D &obj) {
01266 if (this==&obj) return;
01267 destroy();
01268 switch (type=obj.type) {
01269 case GEOMETRIC_TYPE_POINT:
01270 data.point=new TPoint2D(*(obj.data.point));
01271 break;
01272 case GEOMETRIC_TYPE_SEGMENT:
01273 data.segment=new TSegment2D(*(obj.data.segment));
01274 break;
01275 case GEOMETRIC_TYPE_LINE:
01276 data.line=new TLine2D(*(obj.data.line));
01277 break;
01278 case GEOMETRIC_TYPE_POLYGON:
01279 data.polygon=new TPolygon2D(*(obj.data.polygon));
01280 break;
01281 }
01282 }
01283
01284
01285
01286 inline void operator=(const TPoint2D &p) {
01287 destroy();
01288 type=GEOMETRIC_TYPE_POINT;
01289 data.point=new TPoint2D(p);
01290 }
01291
01292
01293
01294 inline void operator=(const TSegment2D &s) {
01295 destroy();
01296 type=GEOMETRIC_TYPE_SEGMENT;
01297 data.segment=new TSegment2D(s);
01298 }
01299
01300
01301
01302 inline void operator=(const TLine2D &l) {
01303 destroy();
01304 type=GEOMETRIC_TYPE_LINE;
01305 data.line=new TLine2D(l);
01306 }
01307
01308
01309
01310 inline void operator=(const TPolygon2D &p) {
01311 destroy();
01312 type=GEOMETRIC_TYPE_POLYGON;
01313 data.polygon=new TPolygon2D(p);
01314 }
01315
01316
01317
01318 void generate3DObject(TObject3D &obj) const;
01319
01320
01321
01322 TObject2D(const TObject2D &obj):type(GEOMETRIC_TYPE_UNDEFINED) {
01323 operator=(obj);
01324 }
01325
01326
01327
01328 static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts);
01329
01330
01331
01332 static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms);
01333
01334
01335
01336 static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins);
01337
01338
01339
01340 static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys);
01341
01342
01343
01344 static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts,std::vector<TObject2D> &remainder);
01345
01346
01347
01348 static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms,std::vector<TObject2D> &remainder);
01349
01350
01351
01352 static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins,std::vector<TObject2D> &remainder);
01353
01354
01355
01356 static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys,std::vector<TObject2D> &remainder);
01357 };
01358
01359
01360
01361
01362 struct MRPTDLLIMPEXP TObject3D {
01363 private:
01364
01365
01366
01367 unsigned char type;
01368
01369
01370
01371 union {
01372 TPoint3D *point;
01373 TSegment3D *segment;
01374 TLine3D *line;
01375 TPolygon3D *polygon;
01376 TPlane *plane;
01377 } data;
01378
01379
01380
01381 void destroy() {
01382 switch (type) {
01383 case GEOMETRIC_TYPE_POINT:
01384 delete data.point;
01385 break;
01386 case GEOMETRIC_TYPE_SEGMENT:
01387 delete data.segment;
01388 break;
01389 case GEOMETRIC_TYPE_LINE:
01390 delete data.line;
01391 break;
01392 case GEOMETRIC_TYPE_POLYGON:
01393 delete data.polygon;
01394 break;
01395 case GEOMETRIC_TYPE_PLANE:
01396 delete data.plane;
01397 break;
01398 case GEOMETRIC_TYPE_UNDEFINED:
01399 break;
01400 default:
01401 THROW_EXCEPTION("Invalid TObject2D object");
01402 }
01403 type=GEOMETRIC_TYPE_UNDEFINED;
01404 }
01405 public:
01406
01407
01408
01409 TObject3D(const TPoint3D &p):type(GEOMETRIC_TYPE_POINT) {
01410 data.point=new TPoint3D(p);
01411 }
01412
01413
01414
01415 TObject3D(const TSegment3D &s):type(GEOMETRIC_TYPE_SEGMENT) {
01416 data.segment=new TSegment3D(s);
01417 }
01418
01419
01420
01421 TObject3D(const TLine3D &r):type(GEOMETRIC_TYPE_LINE) {
01422 data.line=new TLine3D(r);
01423 }
01424
01425
01426
01427 TObject3D(const TPolygon3D &p):type(GEOMETRIC_TYPE_POLYGON) {
01428 data.polygon=new TPolygon3D(p);
01429 }
01430
01431
01432
01433 TObject3D(const TPlane &p):type(GEOMETRIC_TYPE_PLANE) {
01434 data.plane=new TPlane(p);
01435 }
01436
01437
01438
01439 TObject3D():type(GEOMETRIC_TYPE_UNDEFINED) {}
01440
01441
01442
01443 ~TObject3D() {
01444 destroy();
01445 }
01446
01447
01448
01449 inline bool isPoint() const {
01450 return type==GEOMETRIC_TYPE_POINT;
01451 }
01452
01453
01454
01455 inline bool isSegment() const {
01456 return type==GEOMETRIC_TYPE_SEGMENT;
01457 }
01458
01459
01460
01461 inline bool isLine() const {
01462 return type==GEOMETRIC_TYPE_LINE;
01463 }
01464
01465
01466
01467 inline bool isPolygon() const {
01468 return type==GEOMETRIC_TYPE_POLYGON;
01469 }
01470
01471
01472
01473 inline bool isPlane() const {
01474 return type==GEOMETRIC_TYPE_PLANE;
01475 }
01476
01477
01478
01479 inline unsigned char getType() const {
01480 return type;
01481 }
01482
01483
01484
01485 inline bool getPoint(TPoint3D &p) const {
01486 if (isPoint()) {
01487 p=*(data.point);
01488 return true;
01489 } else return false;
01490 }
01491
01492
01493
01494 inline bool getSegment(TSegment3D &s) const {
01495 if (isSegment()) {
01496 s=*(data.segment);
01497 return true;
01498 } else return false;
01499 }
01500
01501
01502
01503 inline bool getLine(TLine3D &r) const {
01504 if (isLine()) {
01505 r=*(data.line);
01506 return true;
01507 } else return false;
01508 }
01509
01510
01511
01512 inline bool getPolygon(TPolygon3D &p) const {
01513 if (isPolygon()) {
01514 p=*(data.polygon);
01515 return true;
01516 } else return false;
01517 }
01518
01519
01520
01521 inline bool getPlane(TPlane &p) const {
01522 if (isPlane()) {
01523 p=*(data.plane);
01524 return true;
01525 } else return false;
01526 }
01527
01528
01529
01530 void operator=(const TObject3D &obj) {
01531 if (this==&obj) return;
01532 destroy();
01533 switch (type=obj.type) {
01534 case GEOMETRIC_TYPE_POINT:
01535 data.point=new TPoint3D(*(obj.data.point));
01536 break;
01537 case GEOMETRIC_TYPE_SEGMENT:
01538 data.segment=new TSegment3D(*(obj.data.segment));
01539 break;
01540 case GEOMETRIC_TYPE_LINE:
01541 data.line=new TLine3D(*(obj.data.line));
01542 break;
01543 case GEOMETRIC_TYPE_POLYGON:
01544 data.polygon=new TPolygon3D(*(obj.data.polygon));
01545 break;
01546 case GEOMETRIC_TYPE_PLANE:
01547 data.plane=new TPlane(*(obj.data.plane));
01548 break;
01549 case GEOMETRIC_TYPE_UNDEFINED:
01550 break;
01551 default:
01552 THROW_EXCEPTION("Invalid TObject3D object");
01553 }
01554 }
01555
01556
01557
01558 inline void operator=(const TPoint3D &p) {
01559 destroy();
01560 type=GEOMETRIC_TYPE_POINT;
01561 data.point=new TPoint3D(p);
01562 }
01563
01564
01565
01566 inline void operator=(const TSegment3D &s) {
01567 destroy();
01568 type=GEOMETRIC_TYPE_SEGMENT;
01569 data.segment=new TSegment3D(s);
01570 }
01571
01572
01573
01574 inline void operator=(const TLine3D &l) {
01575 destroy();
01576 type=GEOMETRIC_TYPE_LINE;
01577 data.line=new TLine3D(l);
01578 }
01579
01580
01581
01582 inline void operator=(const TPolygon3D &p) {
01583 destroy();
01584 type=GEOMETRIC_TYPE_POLYGON;
01585 data.polygon=new TPolygon3D(p);
01586 }
01587
01588
01589
01590 inline void operator=(const TPlane &p) {
01591 destroy();
01592 type=GEOMETRIC_TYPE_PLANE;
01593 data.plane=new TPlane(p);
01594 }
01595
01596
01597
01598
01599 inline void generate2DObject(TObject2D &obj) const {
01600 switch (type) {
01601 case GEOMETRIC_TYPE_POINT:
01602 obj=TPoint2D(*(data.point));
01603 break;
01604 case GEOMETRIC_TYPE_SEGMENT:
01605 obj=TSegment2D(*(data.segment));
01606 break;
01607 case GEOMETRIC_TYPE_LINE:
01608 obj=TLine2D(*(data.line));
01609 break;
01610 case GEOMETRIC_TYPE_POLYGON:
01611 obj=TPolygon2D(*(data.polygon));
01612 break;
01613 case GEOMETRIC_TYPE_PLANE:
01614 throw std::logic_error("Too many dimensions");
01615 default:
01616 obj=TObject2D();
01617 break;
01618 }
01619 }
01620
01621
01622
01623 TObject3D(const TObject3D &obj):type(GEOMETRIC_TYPE_UNDEFINED) {
01624 operator=(obj);
01625 }
01626
01627
01628
01629 static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts);
01630
01631
01632
01633 static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms);
01634
01635
01636
01637 static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins);
01638
01639
01640
01641 static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns);
01642
01643
01644
01645 static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys);
01646
01647
01648
01649 static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts,std::vector<TObject3D> &remainder);
01650
01651
01652
01653 static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms,std::vector<TObject3D> &remainder);
01654
01655
01656
01657 static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins,std::vector<TObject3D> &remainder);
01658
01659
01660
01661 static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns,std::vector<TObject3D> &remainder);
01662
01663
01664
01665 static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TObject3D> &remainder);
01666 };
01667 #else
01668 struct MRPTDLLIMPEXP TObject2D {
01669 private:
01670
01671
01672
01673 unsigned char type;
01674
01675
01676
01677 struct {
01678 TPoint2D point;
01679 TSegment2D segment;
01680 TLine2D line;
01681 TPolygon2D *polygon;
01682 } data;
01683
01684
01685
01686 inline void destroy() {
01687 if (type==GEOMETRIC_TYPE_POLYGON) delete data.polygon;
01688 type=GEOMETRIC_TYPE_UNDEFINED;
01689 }
01690 public:
01691
01692
01693
01694 inline TObject2D(const TPoint2D &p):type(GEOMETRIC_TYPE_POINT) {
01695 data.point=p;
01696 }
01697
01698
01699
01700 inline TObject2D(const TSegment2D &s):type(GEOMETRIC_TYPE_SEGMENT) {
01701 data.segment=s;
01702 }
01703
01704
01705
01706 inline TObject2D(const TLine2D &r):type(GEOMETRIC_TYPE_LINE) {
01707 data.line=r;
01708 }
01709
01710
01711
01712 inline TObject2D(const TPolygon2D &p):type(GEOMETRIC_TYPE_POLYGON) {
01713 data.polygon=new TPolygon2D(p);
01714 }
01715
01716
01717
01718 TObject2D():type(GEOMETRIC_TYPE_UNDEFINED) {}
01719
01720
01721
01722 ~TObject2D() {
01723 destroy();
01724 }
01725
01726
01727
01728 inline bool isPoint() const {
01729 return type==GEOMETRIC_TYPE_POINT;
01730 }
01731
01732
01733
01734 inline bool isSegment() const {
01735 return type==GEOMETRIC_TYPE_SEGMENT;
01736 }
01737
01738
01739
01740 inline bool isLine() const {
01741 return type==GEOMETRIC_TYPE_LINE;
01742 }
01743
01744
01745
01746 inline bool isPolygon() const {
01747 return type==GEOMETRIC_TYPE_POLYGON;
01748 }
01749
01750
01751
01752 inline unsigned char getType() const {
01753 return type;
01754 }
01755
01756
01757
01758 inline bool getPoint(TPoint2D &p) const {
01759 if (isPoint()) {
01760 p=data.point;
01761 return true;
01762 } else return false;
01763 }
01764
01765
01766
01767 inline bool getSegment(TSegment2D &s) const {
01768 if (isSegment()) {
01769 s=data.segment;
01770 return true;
01771 } else return false;
01772 }
01773
01774
01775
01776 inline bool getLine(TLine2D &r) const {
01777 if (isLine()) {
01778 r=data.line;
01779 return true;
01780 } else return false;
01781 }
01782
01783
01784
01785 inline bool getPolygon(TPolygon2D &p) const {
01786 if (isPolygon()) {
01787 p=*(data.polygon);
01788 return true;
01789 } else return false;
01790 }
01791
01792
01793
01794 void operator=(const TObject2D &obj) {
01795 if (this==&obj) return;
01796 destroy();
01797 switch (type=obj.type) {
01798 case GEOMETRIC_TYPE_POINT:
01799 data.point=obj.data.point;
01800 break;
01801 case GEOMETRIC_TYPE_SEGMENT:
01802 data.segment=obj.data.segment;
01803 break;
01804 case GEOMETRIC_TYPE_LINE:
01805 data.line=obj.data.line;
01806 break;
01807 case GEOMETRIC_TYPE_POLYGON:
01808 data.polygon=new TPolygon2D(*(obj.data.polygon));
01809 break;
01810 }
01811 }
01812
01813
01814
01815 inline void operator=(const TPoint2D &p) {
01816 destroy();
01817 type=GEOMETRIC_TYPE_POINT;
01818 data.point=p;
01819 }
01820
01821
01822
01823 inline void operator=(const TSegment2D &s) {
01824 destroy();
01825 type=GEOMETRIC_TYPE_SEGMENT;
01826 data.segment=s;
01827 }
01828
01829
01830
01831 inline void operator=(const TLine2D &l) {
01832 destroy();
01833 type=GEOMETRIC_TYPE_LINE;
01834 data.line=l;
01835 }
01836
01837
01838
01839 inline void operator=(const TPolygon2D &p) {
01840 destroy();
01841 type=GEOMETRIC_TYPE_POLYGON;
01842 data.polygon=new TPolygon2D(p);
01843 }
01844
01845
01846
01847 void generate3DObject(TObject3D &obj) const;
01848
01849
01850
01851 TObject2D(const TObject2D &obj):type(GEOMETRIC_TYPE_UNDEFINED) {
01852 operator=(obj);
01853 }
01854
01855
01856
01857 static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts);
01858
01859
01860
01861 static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms);
01862
01863
01864
01865 static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins);
01866
01867
01868
01869 static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys);
01870
01871
01872
01873 static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts,std::vector<TObject2D> &remainder);
01874
01875
01876
01877 static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms,std::vector<TObject2D> &remainder);
01878
01879
01880
01881 static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins,std::vector<TObject2D> &remainder);
01882
01883
01884
01885 static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys,std::vector<TObject2D> &remainder);
01886 };
01887
01888
01889
01890
01891 struct MRPTDLLIMPEXP TObject3D {
01892 private:
01893
01894
01895
01896 unsigned char type;
01897
01898
01899
01900 struct {
01901 TPoint3D point;
01902 TSegment3D segment;
01903 TLine3D line;
01904 TPolygon3D *polygon;
01905 TPlane plane;
01906 } data;
01907
01908
01909
01910 void destroy() {
01911 if (type==GEOMETRIC_TYPE_POLYGON) delete data.polygon;
01912 type=GEOMETRIC_TYPE_UNDEFINED;
01913 }
01914 public:
01915
01916
01917
01918 TObject3D(const TPoint3D &p):type(GEOMETRIC_TYPE_POINT) {
01919 data.point=p;
01920 }
01921
01922
01923
01924 TObject3D(const TSegment3D &s):type(GEOMETRIC_TYPE_SEGMENT) {
01925 data.segment=s;
01926 }
01927
01928
01929
01930 TObject3D(const TLine3D &r):type(GEOMETRIC_TYPE_LINE) {
01931 data.line=r;
01932 }
01933
01934
01935
01936 TObject3D(const TPolygon3D &p):type(GEOMETRIC_TYPE_POLYGON) {
01937 data.polygon=new TPolygon3D(p);
01938 }
01939
01940
01941
01942 TObject3D(const TPlane &p):type(GEOMETRIC_TYPE_PLANE) {
01943 data.plane=p;
01944 }
01945
01946
01947
01948 TObject3D():type(GEOMETRIC_TYPE_UNDEFINED) {}
01949
01950
01951
01952 ~TObject3D() {
01953 destroy();
01954 }
01955
01956
01957
01958 inline bool isPoint() const {
01959 return type==GEOMETRIC_TYPE_POINT;
01960 }
01961
01962
01963
01964 inline bool isSegment() const {
01965 return type==GEOMETRIC_TYPE_SEGMENT;
01966 }
01967
01968
01969
01970 inline bool isLine() const {
01971 return type==GEOMETRIC_TYPE_LINE;
01972 }
01973
01974
01975
01976 inline bool isPolygon() const {
01977 return type==GEOMETRIC_TYPE_POLYGON;
01978 }
01979
01980
01981
01982 inline bool isPlane() const {
01983 return type==GEOMETRIC_TYPE_PLANE;
01984 }
01985
01986
01987
01988 inline unsigned char getType() const {
01989 return type;
01990 }
01991
01992
01993
01994 inline bool getPoint(TPoint3D &p) const {
01995 if (isPoint()) {
01996 p=data.point;
01997 return true;
01998 } else return false;
01999 }
02000
02001
02002
02003 inline bool getSegment(TSegment3D &s) const {
02004 if (isSegment()) {
02005 s=data.segment;
02006 return true;
02007 } else return false;
02008 }
02009
02010
02011
02012 inline bool getLine(TLine3D &r) const {
02013 if (isLine()) {
02014 r=data.line;
02015 return true;
02016 } else return false;
02017 }
02018
02019
02020
02021 inline bool getPolygon(TPolygon3D &p) const {
02022 if (isPolygon()) {
02023 p=*(data.polygon);
02024 return true;
02025 } else return false;
02026 }
02027
02028
02029
02030 inline bool getPlane(TPlane &p) const {
02031 if (isPlane()) {
02032 p=data.plane;
02033 return true;
02034 } else return false;
02035 }
02036
02037
02038
02039 void operator=(const TObject3D &obj) {
02040 if (this==&obj) return;
02041 destroy();
02042 switch (type=obj.type) {
02043 case GEOMETRIC_TYPE_POINT:
02044 data.point=obj.data.point;
02045 break;
02046 case GEOMETRIC_TYPE_SEGMENT:
02047 data.segment=obj.data.segment;
02048 break;
02049 case GEOMETRIC_TYPE_LINE:
02050 data.line=obj.data.line;
02051 break;
02052 case GEOMETRIC_TYPE_POLYGON:
02053 data.polygon=new TPolygon3D(*(obj.data.polygon));
02054 break;
02055 case GEOMETRIC_TYPE_PLANE:
02056 data.plane=obj.data.plane;
02057 break;
02058 case GEOMETRIC_TYPE_UNDEFINED:
02059 break;
02060 default:
02061 THROW_EXCEPTION("Invalid TObject3D object");
02062 }
02063 }
02064
02065
02066
02067 inline void operator=(const TPoint3D &p) {
02068 destroy();
02069 type=GEOMETRIC_TYPE_POINT;
02070 data.point=p;
02071 }
02072
02073
02074
02075 inline void operator=(const TSegment3D &s) {
02076 destroy();
02077 type=GEOMETRIC_TYPE_SEGMENT;
02078 data.segment=s;
02079 }
02080
02081
02082
02083 inline void operator=(const TLine3D &l) {
02084 destroy();
02085 type=GEOMETRIC_TYPE_LINE;
02086 data.line=l;
02087 }
02088
02089
02090
02091 inline void operator=(const TPolygon3D &p) {
02092 destroy();
02093 type=GEOMETRIC_TYPE_POLYGON;
02094 data.polygon=new TPolygon3D(p);
02095 }
02096
02097
02098
02099 inline void operator=(const TPlane &p) {
02100 destroy();
02101 type=GEOMETRIC_TYPE_PLANE;
02102 data.plane=p;
02103 }
02104
02105
02106
02107
02108 inline void generate2DObject(TObject2D &obj) const {
02109 switch (type) {
02110 case GEOMETRIC_TYPE_POINT:
02111 obj=TPoint2D(data.point);
02112 break;
02113 case GEOMETRIC_TYPE_SEGMENT:
02114 obj=TSegment2D(data.segment);
02115 break;
02116 case GEOMETRIC_TYPE_LINE:
02117 obj=TLine2D(data.line);
02118 break;
02119 case GEOMETRIC_TYPE_POLYGON:
02120 obj=TPolygon2D(*(data.polygon));
02121 break;
02122 case GEOMETRIC_TYPE_PLANE:
02123 throw std::logic_error("Too many dimensions");
02124 default:
02125 obj=TObject2D();
02126 break;
02127 }
02128 }
02129
02130
02131
02132 TObject3D(const TObject3D &obj):type(GEOMETRIC_TYPE_UNDEFINED) {
02133 operator=(obj);
02134 }
02135
02136
02137
02138 static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts);
02139
02140
02141
02142 static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms);
02143
02144
02145
02146 static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins);
02147
02148
02149
02150 static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns);
02151
02152
02153
02154 static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys);
02155
02156
02157
02158 static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts,std::vector<TObject3D> &remainder);
02159
02160
02161
02162 static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms,std::vector<TObject3D> &remainder);
02163
02164
02165
02166 static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins,std::vector<TObject3D> &remainder);
02167
02168
02169
02170 static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns,std::vector<TObject3D> &remainder);
02171
02172
02173
02174 static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TObject3D> &remainder);
02175 };
02176
02177 #endif
02178
02179
02180
02181
02182 MRPTDLLIMPEXP mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in,mrpt::math::TPoint2D &o);
02183
02184
02185
02186 MRPTDLLIMPEXP mrpt::utils::CStream& operator<<(mrpt::utils::CStream& out,const mrpt::math::TPoint2D &o);
02187
02188
02189
02190
02191 MRPTDLLIMPEXP mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in,mrpt::math::TPoint3D &o);
02192
02193
02194
02195 MRPTDLLIMPEXP mrpt::utils::CStream& operator<<(mrpt::utils::CStream& out,const mrpt::math::TPoint3D &o);
02196
02197
02198
02199
02200 MRPTDLLIMPEXP mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in,mrpt::math::TPose2D &o);
02201
02202
02203
02204 MRPTDLLIMPEXP mrpt::utils::CStream& operator<<(mrpt::utils::CStream& out,const mrpt::math::TPose2D &o);
02205
02206
02207
02208
02209 MRPTDLLIMPEXP mrpt::utils::CStream& operator>>(mrpt::utils::CStream& in,mrpt::math::TPose3D &o);
02210
02211
02212
02213 MRPTDLLIMPEXP mrpt::utils::CStream& operator<<(mrpt::utils::CStream& out,const mrpt::math::TPose3D &o);
02214
02215
02216
02217
02218 inline mrpt::utils::CStream &operator>>(mrpt::utils::CStream &in,mrpt::math::TSegment2D &s) {
02219 return in>>s.point1>>s.point2;
02220 }
02221
02222
02223
02224 inline mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const mrpt::math::TSegment2D &s) {
02225 return out<<s.point1<<s.point2;
02226 }
02227
02228
02229
02230
02231 inline mrpt::utils::CStream &operator>>(mrpt::utils::CStream &in,mrpt::math::TLine2D &l) {
02232 return in>>l.coefs[0]>>l.coefs[1]>>l.coefs[2];
02233 }
02234
02235
02236
02237 inline mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const mrpt::math::TLine2D &l) {
02238 return out<<l.coefs[0]<<l.coefs[1]<<l.coefs[2];
02239 }
02240
02241
02242
02243
02244 MRPTDLLIMPEXP mrpt::utils::CStream &operator>>(mrpt::utils::CStream &in,mrpt::math::TObject2D &o);
02245
02246
02247
02248 MRPTDLLIMPEXP mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const mrpt::math::TObject2D &o);
02249
02250
02251
02252
02253 inline mrpt::utils::CStream &operator>>(mrpt::utils::CStream &in,mrpt::math::TSegment3D &s) {
02254 return in>>s.point1>>s.point2;
02255 }
02256
02257
02258
02259 inline mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const mrpt::math::TSegment3D &s) {
02260 return out<<s.point1<<s.point2;
02261 }
02262
02263
02264
02265
02266 inline mrpt::utils::CStream &operator>>(mrpt::utils::CStream &in,mrpt::math::TLine3D &l) {
02267 return in>>l.pBase>>l.director[0]>>l.director[1]>>l.director[2];
02268 }
02269
02270
02271
02272 inline mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const mrpt::math::TLine3D &l) {
02273 return out<<l.pBase<<l.director[0]<<l.director[1]<<l.director[2];
02274 }
02275
02276
02277
02278
02279 inline mrpt::utils::CStream &operator>>(mrpt::utils::CStream &in,mrpt::math::TPlane &p) {
02280 return in>>p.coefs[0]>>p.coefs[1]>>p.coefs[2]>>p.coefs[3];
02281 }
02282
02283
02284
02285 inline mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const mrpt::math::TPlane &p) {
02286 return out<<p.coefs[0]<<p.coefs[1]<<p.coefs[2]<<p.coefs[3];
02287 }
02288
02289
02290
02291
02292 MRPTDLLIMPEXP mrpt::utils::CStream &operator>>(mrpt::utils::CStream &in,mrpt::math::TObject3D &o);
02293
02294
02295
02296 MRPTDLLIMPEXP mrpt::utils::CStream &operator<<(mrpt::utils::CStream &out,const mrpt::math::TObject3D &o);
02297
02298 }
02299
02300 namespace utils
02301 {
02302 using namespace ::mrpt::math;
02303
02304
02305 MRPT_DECLARE_TTYPENAME(TPoint2D)
02306 MRPT_DECLARE_TTYPENAME(TPoint3D)
02307 MRPT_DECLARE_TTYPENAME(TPose2D)
02308 MRPT_DECLARE_TTYPENAME(TPose3D)
02309 MRPT_DECLARE_TTYPENAME(TSegment2D)
02310 MRPT_DECLARE_TTYPENAME(TLine2D)
02311 MRPT_DECLARE_TTYPENAME(TPolygon2D)
02312 MRPT_DECLARE_TTYPENAME(TObject2D)
02313 MRPT_DECLARE_TTYPENAME(TSegment3D)
02314 MRPT_DECLARE_TTYPENAME(TLine3D)
02315 MRPT_DECLARE_TTYPENAME(TPlane)
02316 MRPT_DECLARE_TTYPENAME(TPolygon3D)
02317 MRPT_DECLARE_TTYPENAME(TObject3D)
02318
02319 }
02320
02321 }
02322 #endif