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