Main MRPT website > C++ reference
MRPT logo
lightweight_geom_data.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef LIGHTWEIGHT_GEOM_DATA_H
29 #define LIGHTWEIGHT_GEOM_DATA_H
30 
31 #include <mrpt/utils/utils_defs.h>
33 #include <mrpt/utils/TPixelCoord.h>
34 
35 #include <mrpt/math/math_frwds.h> // Fordward declarations
36 
37 
38 
39 namespace mrpt {
40  namespace poses {
41  template <class DERIVEDCLASS> class CPoseOrPoint;
42  class CPoint2D;
43  class CPoint3D;
44  class CPose2D;
45  class CPose3D;
46  }
47  namespace utils { class CStream; }
48 }
49 
50 namespace mrpt {
51 namespace math {
52  using namespace mrpt::utils; // For "square"
53 
54  struct TPoint2D;
55  struct TPose2D;
56  struct TPoint3D;
57  struct TPose3D;
58  struct TPose3DQuat;
59 
60  /** \addtogroup geometry_grp
61  * @{ */
62 
63 
64  //Pragma defined to ensure no structure packing
65 #pragma pack(push,1)
66  //Set of typedefs for lightweight geometric items.
67  /**
68  * Lightweight 2D point. Allows coordinate access using [] operator.
69  * \sa mrpt::poses::CPoint2D
70  */
71 //#define TOBJECTS_USE_UNIONS
73  /**
74  * X coordinate.
75  */
76  double x;
77  /**
78  * Y coordinate.
79  */
80  double y;
81  /**
82  * Constructor from TPose2D, discarding phi.
83  * \sa TPose2D
84  */
85  explicit TPoint2D(const TPose2D &p);
86  /**
87  * Constructor from TPoint3D, discarding z.
88  * \sa TPoint3D
89  */
90  explicit TPoint2D(const TPoint3D &p);
91  /**
92  * Constructor from TPose3D, discarding z and the angular coordinates.
93  * \sa TPose3D
94  */
95  explicit TPoint2D(const TPose3D &p);
96  /**
97  * Constructor from CPoseOrPoint, perhaps losing 3D information
98  * \sa CPoseOrPoint,CPoint3D,CPose2D,CPose3D
99  */
100  template <class DERIVEDCLASS>
101  explicit TPoint2D(const mrpt::poses::CPoseOrPoint<DERIVEDCLASS> &p) :x(p.x()),y(p.y()) {}
102 
103  /** Implicit transformation constructor from TPixelCoordf */
104  inline TPoint2D(const mrpt::utils::TPixelCoordf &p) :x(p.x),y(p.y) {}
105 
106  /** Implicit constructor from CPoint2D */
108  /**
109  * Constructor from coordinates.
110  */
111  inline TPoint2D(double xx,double yy):x(xx),y(yy) {}
112  /**
113  * Default fast constructor. Initializes to garbage.
114  */
115  inline TPoint2D() {}
116  /**
117  * Unsafe coordinate access using operator[]. Intended for loops.
118  */
119  inline double &operator[](size_t i) {
120  return (&x)[i];
121  }
122  /**
123  * Unsafe coordinate access using operator[]. Intended for loops.
124  */
125  inline const double &operator[](size_t i) const {
126  return (&x)[i];
127  }
128  /**
129  * Transformation into vector.
130  */
131  inline void getAsVector(vector_double &v) const {
132  v.resize(2);
133  v[0]=x; v[1]=y;
134  }
135 
136  bool operator<(const TPoint2D &p) const;
137 
138  inline TPoint2D &operator+=(const TPoint2D &p) {
139  x+=p.x;
140  y+=p.y;
141  return *this;
142  }
143 
144  inline TPoint2D &operator-=(const TPoint2D &p) {
145  x-=p.x;
146  y-=p.y;
147  return *this;
148  }
149 
150  inline TPoint2D &operator*=(double d) {
151  x*=d;
152  y*=d;
153  return *this;
154  }
155 
156  inline TPoint2D &operator/=(double d) {
157  x/=d;
158  y/=d;
159  return *this;
160  }
161 
162  inline TPoint2D operator+(const TPoint2D &p) const {
163  TPoint2D r(*this);
164  return r+=p;
165  }
166 
167  inline TPoint2D operator-(const TPoint2D &p) const {
168  TPoint2D r(*this);
169  return r-=p;
170  }
171 
172  inline TPoint2D operator*(double d) const {
173  TPoint2D r(*this);
174  return r*=d;
175  }
176 
177  inline TPoint2D operator/(double d) const {
178  TPoint2D r(*this);
179  return r/=d;
180  }
181  /** Returns a human-readable textual representation of the object (eg: "[0.02 1.04]" )
182  * \sa fromString
183  */
184  void asString(std::string &s) const { s = mrpt::format("[%f %f]",x,y); }
185  inline std::string asString() const { std::string s; asString(s); return s; }
186 
187  /** Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04]" )
188  * \sa asString
189  * \exception std::exception On invalid format
190  */
191  void fromString(const std::string &s);
192  static size_t size() { return 2; }
193  };
194 
195  /**
196  * Lightweight 2D pose. Allows coordinate access using [] operator.
197  * \sa mrpt::poses::CPose2D
198  */
200  /**
201  * X coordinate.
202  */
203  double x;
204  /**
205  * Y coordinate.
206  */
207  double y;
208  /**
209  * Phi coordinate.
210  */
211  double phi;
212  /**
213  * Implicit constructor from TPoint2D. Zeroes the phi coordinate.
214  * \sa TPoint2D
215  */
216  TPose2D(const TPoint2D &p);
217  /**
218  * Constructor from TPoint3D, losing information. Zeroes the phi coordinate.
219  * \sa TPoint3D
220  */
221  explicit TPose2D(const TPoint3D &p);
222  /**
223  * Constructor from TPose3D, losing information. The phi corresponds to the original pose's yaw.
224  * \sa TPose3D
225  */
226  explicit TPose2D(const TPose3D &p);
227  /**
228  * Implicit constructor from heavyweight type.
229  * \sa mrpt::poses::CPose2D
230  */
231  TPose2D(const mrpt::poses::CPose2D &p);
232  /**
233  * Constructor from coordinates.
234  */
235  inline TPose2D(double xx,double yy,double pphi):x(xx),y(yy),phi(pphi) {}
236  /**
237  * Default fast constructor. Initializes to garbage.
238  */
239  inline TPose2D() {}
240  /**
241  * Unsafe coordinate access using operator[]. Intended for loops.
242  */
243  inline double &operator[](size_t i) {
244  return (&x)[i];
245  }
246  /**
247  * Unsafe coordinate access using operator[]. Intended for loops.
248  */
249  inline const double &operator[](size_t i) const {
250  return (&x)[i];
251  }
252  /**
253  * Transformation into vector.
254  */
255  inline void getAsVector(vector_double &v) const {
256  v.resize(3);
257  v[0]=x; v[1]=y; v[2]=phi;
258  }
259  /** Returns a human-readable textual representation of the object (eg: "[x y yaw]", yaw in degrees)
260  * \sa fromString
261  */
262  void asString(std::string &s) const { s = mrpt::format("[%f %f %f]",x,y,RAD2DEG(phi)); }
263  inline std::string asString() const { std::string s; asString(s); return s; }
264 
265  /** Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -45.0]" )
266  * \sa asString
267  * \exception std::exception On invalid format
268  */
269  void fromString(const std::string &s);
270  static size_t size() { return 3; }
271  };
272 
273  /** Lightweight 3D point (float version).
274  * \sa mrpt::poses::CPoint3D, mrpt::math::TPoint3D
275  */
277  {
278  float x;
279  float y;
280  float z;
281 
282  inline TPoint3Df() { }
283  inline TPoint3Df(const float xx,const float yy,const float zz) : x(xx), y(yy),z(zz) { }
284  inline TPoint3Df & operator +=(const TPoint3Df &p) { x+=p.x; y+=p.y; z+=p.z; return *this; }
285  inline TPoint3Df operator *(const float s) { return TPoint3Df(x*s,y*s,z*s); }
286  };
287 
288  /**
289  * Lightweight 3D point. Allows coordinate access using [] operator.
290  * \sa mrpt::poses::CPoint3D, mrpt::math::TPoint3Df
291  */
293  double x; //!< X coordinate
294  double y; //!< Y coordinate
295  double z; //!< Z coordinate
296 
297  /** Constructor from coordinates. */
298  inline TPoint3D(double xx,double yy,double zz):x(xx),y(yy),z(zz) {}
299  /** Default fast constructor. Initializes to garbage. */
300  inline TPoint3D() {}
301  /** Explicit constructor from coordinates. */
302  explicit inline TPoint3D(const TPoint3Df &p):x(p.x),y(p.y),z(p.z) {}
303 
304  /** Implicit constructor from TPoint2D. Zeroes the z.
305  * \sa TPoint2D
306  */
307  TPoint3D(const TPoint2D &p);
308  /**
309  * Constructor from TPose2D, losing information. Zeroes the z.
310  * \sa TPose2D
311  */
312  explicit TPoint3D(const TPose2D &p);
313  /**
314  * Constructor from TPose3D, losing information.
315  * \sa TPose3D
316  */
317  explicit TPoint3D(const TPose3D &p);
318  /**
319  * Implicit constructor from heavyweight type.
320  * \sa mrpt::poses::CPoint3D
321  */
323  /**
324  * Constructor from heavyweight 3D pose.
325  * \sa mrpt::poses::CPose3D.
326  */
327  explicit TPoint3D(const mrpt::poses::CPose3D &p);
328  /**
329  * Unsafe coordinate access using operator[]. Intended for loops.
330  */
331  inline double &operator[](size_t i) {
332  return (&x)[i];
333  }
334  /**
335  * Unsafe coordinate access using operator[]. Intended for loops.
336  */
337  inline const double &operator[](size_t i) const {
338  return (&x)[i];
339  }
340  /**
341  * Point-to-point distance.
342  */
343  inline double distanceTo(const TPoint3D &p) const {
344  return sqrt(square(p.x-x)+square(p.y-y)+square(p.z-z));
345  }
346  /**
347  * Point-to-point distance, squared.
348  */
349  inline double sqrDistanceTo(const TPoint3D &p) const {
350  return square(p.x-x)+square(p.y-y)+square(p.z-z);
351  }
352  /**
353  * Point norm.
354  */
355  inline double norm() const {
356  return sqrt(square(x)+square(y)+square(z));
357  }
358  /**
359  * Point scale.
360  */
361  inline TPoint3D &operator*=(const double f) {
362  x*=f;y*=f;z*=f;
363  return *this;
364  }
365  /**
366  * Transformation into vector.
367  */
368  void getAsVector(vector_double &v) const {
369  v.resize(3);
370  v[0]=x; v[1]=y; v[2]=z;
371  }
372  /**
373  * Translation.
374  */
375  inline TPoint3D &operator+=(const TPoint3D &p) {
376  x+=p.x;
377  y+=p.y;
378  z+=p.z;
379  return *this;
380  }
381  /**
382  * Difference between points.
383  */
384  inline TPoint3D &operator-=(const TPoint3D &p) {
385  x-=p.x;
386  y-=p.y;
387  z-=p.z;
388  return *this;
389  }
390  /**
391  * Points addition.
392  */
393  inline TPoint3D operator+(const TPoint3D &p) const {
394  return TPoint3D(x+p.x,y+p.y,z+p.z);
395  }
396  /**
397  * Points substraction.
398  */
399  inline TPoint3D operator-(const TPoint3D &p) const {
400  return TPoint3D(x-p.x,y-p.y,z-p.z);
401  }
402 
403  inline TPoint3D operator*(double d) const {
404  return TPoint3D(x*d,y*d,z*d);
405  }
406 
407  inline TPoint3D operator/(double d) const {
408  return TPoint3D(x/d,y/d,z/d);
409  }
410 
411  bool operator<(const TPoint3D &p) const;
412 
413  /** Returns a human-readable textual representation of the object (eg: "[0.02 1.04 -0.8]" )
414  * \sa fromString
415  */
416  void asString(std::string &s) const { s = mrpt::format("[%f %f %f]",x,y,z); }
417  inline std::string asString() const { std::string s; asString(s); return s; }
418 
419  /** Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -0.8]" )
420  * \sa asString
421  * \exception std::exception On invalid format
422  */
423  void fromString(const std::string &s);
424  static size_t size() { return 3; }
425  };
426 
427  /**
428  * Lightweight 3D pose (three spatial coordinates, plus three angular coordinates). Allows coordinate access using [] operator.
429  * \sa mrpt::poses::CPose3D
430  */
432  /**
433  * X coordinate.
434  */
435  double x;
436  /**
437  * Y coordinate.
438  */
439  double y;
440  /**
441  * Z coordinate.
442  */
443  double z;
444  /**
445  * Yaw coordinate (rotation angle over Z axis).
446  */
447  double yaw;
448  /**
449  * Pitch coordinate (rotation angle over Y axis).
450  */
451  double pitch;
452  /**
453  * Roll coordinate (rotation angle over X coordinate).
454  */
455  double roll;
456  /**
457  * Implicit constructor from TPoint2D. Zeroes all the unprovided information.
458  * \sa TPoint2D
459  */
460  TPose3D(const TPoint2D &p);
461  /**
462  * Implicit constructor from TPose2D. Gets the yaw from the 2D pose's phi, zeroing all the unprovided information.
463  * \sa TPose2D
464  */
465  TPose3D(const TPose2D &p);
466  /**
467  * Implicit constructor from TPoint3D. Zeroes angular information.
468  * \sa TPoint3D
469  */
470  TPose3D(const TPoint3D &p);
471  /**
472  * Implicit constructor from heavyweight type.
473  * \sa mrpt::poses::CPose3D
474  */
475  TPose3D(const mrpt::poses::CPose3D &p);
476  /**
477  * Constructor from coordinates.
478  */
479  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) {}
480  /**
481  * Default fast constructor. Initializes to garbage.
482  */
483  inline TPose3D() {}
484  /**
485  * Unsafe coordinate access using operator[]. Intended for loops.
486  */
487  inline double &operator[](size_t i) {
488  return (&x)[i];
489  }
490  /**
491  * Unsafe coordinate access using operator[]. Intended for loops.
492  */
493  inline const double &operator[](size_t i) const {
494  return (&x)[i];
495  }
496  /**
497  * Pose's spatial coordinates norm.
498  */
499  double norm() const {
500  return sqrt(square(x)+square(y)+square(z));
501  }
502  /**
503  * Gets the pose as a vector of doubles.
504  */
505  void getAsVector(vector_double &v) const {
506  v.resize(6);
507  v[0]=x; v[1]=y; v[2]=z; v[3]=yaw; v[4]=pitch; v[5]=roll;
508  }
509  /** Returns a human-readable textual representation of the object (eg: "[x y z yaw pitch roll]", angles in degrees.)
510  * \sa fromString
511  */
512  void asString(std::string &s) const { s = mrpt::format("[%f %f %f %f %f %f]",x,y,z,RAD2DEG(yaw),RAD2DEG(pitch),RAD2DEG(roll)); }
513  inline std::string asString() const { std::string s; asString(s); return s; }
514 
515  /** Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -0.8]" )
516  * \sa asString
517  * \exception std::exception On invalid format
518  */
519  void fromString(const std::string &s);
520  static size_t size() { return 6; }
521  };
522 
523  /** Lightweight 3D pose (three spatial coordinates, plus a quaternion ). Allows coordinate access using [] operator.
524  * \sa mrpt::poses::CPose3DQuat
525  */
527  double x; //!< Translation in x
528  double y; //!< Translation in y
529  double z; //!< Translation in z
530  double qr; //!< Quaternion part, r
531  double qx; //!< Quaternion part, x
532  double qy; //!< Quaternion part, y
533  double qz; //!< Quaternion part, z
534 
535  /** Constructor from coordinates. */
536  inline TPose3DQuat(double _x,double _y,double _z,double _qr,double _qx, double _qy, double _qz):x(_x),y(_y),z(_z),qr(_qr),qx(_qx),qy(_qy),qz(_qz) { }
537  /** Default fast constructor. Initializes to garbage. */
538  inline TPose3DQuat() {}
539  /** Constructor from a CPose3DQuat */
541 
542  /** Unsafe coordinate access using operator[]. Intended for loops. */
543  inline double &operator[](size_t i) {
544  return (&x)[i];
545  }
546  /** Unsafe coordinate access using operator[]. Intended for loops. */
547  inline const double &operator[](size_t i) const {
548  return (&x)[i];
549  }
550  /** Pose's spatial coordinates norm. */
551  double norm() const {
552  return sqrt(square(x)+square(y)+square(z));
553  }
554  /** Gets the pose as a vector of doubles. */
555  void getAsVector(vector_double &v) const {
556  v.resize(7);
557  for (size_t i=0;i<7;i++) v[i]=(*this)[i];
558  }
559  /** Returns a human-readable textual representation of the object as "[x y z qr qx qy qz]"
560  * \sa fromString
561  */
562  void asString(std::string &s) const { s = mrpt::format("[%f %f %f %f %f %f %f]",x,y,z,qr,qx,qy,qz); }
563  inline std::string asString() const { std::string s; asString(s); return s; }
564 
565  /** Set the current object value from a string generated by 'asString' (eg: "[0.02 1.04 -0.8 1.0 0.0 0.0 0.0]" )
566  * \sa asString
567  * \exception std::exception On invalid format
568  */
569  void fromString(const std::string &s);
570  static size_t size() { return 7; }
571  };
572 #pragma pack(pop)
573 
574  // Text streaming functions:
575  std::ostream BASE_IMPEXP & operator << (std::ostream& o, const TPoint2D & p);
576  std::ostream BASE_IMPEXP & operator << (std::ostream& o, const TPoint3D & p);
577  std::ostream BASE_IMPEXP & operator << (std::ostream& o, const TPose2D & p);
578  std::ostream BASE_IMPEXP & operator << (std::ostream& o, const TPose3D & p);
579  std::ostream BASE_IMPEXP & operator << (std::ostream& o, const TPose3DQuat & p);
580 
581 
582  /**
583  * Unary minus operator for 3D points.
584  */
585  inline TPoint3D operator-(const TPoint3D &p1) {
586  return TPoint3D(-p1.x,-p1.y,-p1.z);
587  }
588  /**
589  * Exact comparison between 2D points.
590  */
591  inline bool operator==(const TPoint2D &p1,const TPoint2D &p2) {
592  return (p1.x==p2.x)&&(p1.y==p2.y);
593  }
594  /**
595  * Exact comparison between 2D points.
596  */
597  inline bool operator!=(const TPoint2D &p1,const TPoint2D &p2) {
598  return (p1.x!=p2.x)||(p1.y!=p2.y);
599  }
600  /**
601  * Exact comparison between 3D points.
602  */
603  inline bool operator==(const TPoint3D &p1,const TPoint3D &p2) {
604  return (p1.x==p2.x)&&(p1.y==p2.y)&&(p1.z==p2.z);
605  }
606  /**
607  * Exact comparison between 3D points.
608  */
609  inline bool operator!=(const TPoint3D &p1,const TPoint3D &p2) {
610  return (p1.x!=p2.x)||(p1.y!=p2.y)||(p1.z!=p2.z);
611  }
612  /**
613  * Exact comparison between 2D poses, taking possible cycles into account.
614  */
615  inline bool operator==(const TPose2D &p1,const TPose2D &p2) {
616  return (p1.x==p2.x)&&(p1.y==p2.y)&&(mrpt::math::wrapTo2Pi(p1.phi)==mrpt::math::wrapTo2Pi(p2.phi));
617  }
618  /**
619  * Exact comparison between 2D poses, taking possible cycles into account.
620  */
621  inline bool operator!=(const TPose2D &p1,const TPose2D &p2) {
622  return (p1.x!=p2.x)||(p1.y!=p2.y)||(mrpt::math::wrapTo2Pi(p1.phi)!=mrpt::math::wrapTo2Pi(p2.phi));
623  }
624  /**
625  * Exact comparison between 3D poses, taking possible cycles into account.
626  */
627  inline bool operator==(const TPose3D &p1,const TPose3D &p2) {
629  }
630  /**
631  * Exact comparison between 3D poses, taking possible cycles into account.
632  */
633  inline bool operator!=(const TPose3D &p1,const TPose3D &p2) {
635  }
636  //Forward declarations
641 
642  //Pragma defined to ensure no structure packing
643 #pragma pack(push,1)
644  /**
645  * 2D segment, consisting of two points.
646  * \sa TSegment3D,TLine2D,TPolygon2D,TPoint2D
647  */
649  public:
650  /**
651  * Origin point.
652  */
654  /**
655  * Destiny point.
656  */
658  /**
659  * Segment length.
660  */
661  double length() const;
662  /**
663  * Distance to point.
664  */
665  double distance(const TPoint2D &point) const;
666  /**
667  * Distance with sign to point (sign indicates which side the point is).
668  */
669  double signedDistance(const TPoint2D &point) const;
670  /**
671  * Check whether a point is inside a segment.
672  */
673  bool contains(const TPoint2D &point) const;
674  /**
675  * Unsafe point access using [] operator, intended for loops.
676  */
677  inline TPoint2D &operator[](size_t i) {
678  return (&point1)[i];
679  }
680  /**
681  * Unsafe point access using [] operator, intended for loops.
682  */
683  inline const TPoint2D &operator[](size_t i) const {
684  return (&point1)[i];
685  }
686  /**
687  * Project into 3D space, setting the z to 0.
688  */
689  void generate3DObject(TSegment3D &s) const;
690  /**
691  * Segment's central point.
692  */
693  inline void getCenter(TPoint2D &p) const {
694  p.x=(point1.x+point2.x)/2;
695  p.y=(point1.y+point2.y)/2;
696  }
697  /**
698  * Constructor from both points.
699  */
700  TSegment2D(const TPoint2D &p1,const TPoint2D &p2):point1(p1),point2(p2) {}
701  /**
702  * Fast default constructor. Initializes to garbage.
703  */
705  /**
706  * Explicit constructor from 3D object, discarding the z.
707  */
708  explicit TSegment2D(const TSegment3D &s);
709 
710  bool operator<(const TSegment2D &s) const;
711  };
712  /**
713  * 3D segment, consisting of two points.
714  * \sa TSegment2D,TLine3D,TPlane,TPolygon3D,TPoint3D
715  */
717  public:
718  /**
719  * Origin point.
720  */
722  /**
723  * Destiny point.
724  */
726  /**
727  * Segment length.
728  */
729  double length() const;
730  /**
731  * Distance to point.
732  */
733  double distance(const TPoint3D &point) const;
734  /**
735  * Check whether a point is inside the segment.
736  */
737  bool contains(const TPoint3D &point) const;
738  /**
739  * Unsafe point access using [] operator, intended for loops.
740  */
741  inline TPoint3D &operator[](size_t i) {
742  return (&point1)[i];
743  }
744  /**
745  * Unsafe point access using [] operator, intended for loops.
746  */
747  inline const TPoint3D &operator[](size_t i) const {
748  return (&point1)[i];
749  }
750  /**
751  * Projection into 2D space, discarding the z.
752  */
753  inline void generate2DObject(TSegment2D &s) const {
754  s=TSegment2D(*this);
755  }
756  /**
757  * Segment's central point.
758  */
759  inline void getCenter(TPoint3D &p) const {
760  p.x=(point1.x+point2.x)/2;
761  p.y=(point1.y+point2.y)/2;
762  p.z=(point1.z+point2.z)/2;
763  }
764  /**
765  * Constructor from both points.
766  */
767  TSegment3D(const TPoint3D &p1,const TPoint3D &p2):point1(p1),point2(p2) {}
768  /**
769  * Fast default constructor. Initializes to garbage.
770  */
772  /**
773  * Constructor from 2D object. Sets the z to zero.
774  */
775  TSegment3D(const TSegment2D &s):point1(s.point1),point2(s.point2) {}
776 
777  bool operator<(const TSegment3D &s) const;
778  };
779 #pragma pack(pop)
780 
781  inline bool operator==(const TSegment2D &s1,const TSegment2D &s2) {
782  return (s1.point1==s2.point1)&&(s1.point2==s2.point2);
783  }
784 
785  inline bool operator!=(const TSegment2D &s1,const TSegment2D &s2) {
786  return (s1.point1!=s1.point1)||(s1.point2!=s2.point2);
787  }
788 
789  inline bool operator==(const TSegment3D &s1,const TSegment3D &s2) {
790  return (s1.point1==s2.point1)&&(s1.point2==s2.point2);
791  }
792 
793  inline bool operator!=(const TSegment3D &s1,const TSegment3D &s2) {
794  return (s1.point1!=s1.point1)||(s1.point2!=s2.point2);
795  }
796 
797  /**
798  * 2D line without bounds, represented by its equation \f$Ax+By+C=0\f$.
799  * \sa TLine3D,TSegment2D,TPolygon2D,TPoint2D
800  */
802  public:
803  /**
804  * Line coefficients, stored as an array: \f$\left[A,B,C\right]\f$.
805  */
806  double coefs[3];
807  /**
808  * Evaluate point in the line's equation.
809  */
810  double evaluatePoint(const TPoint2D &point) const;
811  /**
812  * Check whether a point is inside the line.
813  */
814  bool contains(const TPoint2D &point) const;
815  /**
816  * Distance from a given point.
817  */
818  double distance(const TPoint2D &point) const;
819  /**
820  * Distance with sign from a given point (sign indicates side).
821  */
822  double signedDistance(const TPoint2D &point) const;
823  /**
824  * Get line's normal vector.
825  */
826  void getNormalVector(double (&vector)[2]) const;
827  /**
828  * Unitarize line's normal vector.
829  */
830  void unitarize();
831  /**
832  * Get line's normal vector after unitarizing line.
833  */
834  inline void getUnitaryNormalVector(double (&vector)[2]) {
835  unitarize();
836  getNormalVector(vector);
837  }
838  /**
839  * Get line's director vector.
840  */
841  void getDirectorVector(double (&vector)[2]) const;
842  /**
843  * Unitarize line and then get director vector.
844  */
845  inline void getUnitaryDirectorVector(double (&vector)[2]) {
846  unitarize();
847  getDirectorVector(vector);
848  }
849  /**
850  * Project into 3D space, setting the z to 0.
851  */
852  void generate3DObject(TLine3D &l) const;
853  /**
854  * Get a pose2D whose X axis corresponds to the line.
855  * \sa mrpt::poses::CPose2D.
856  */
857  void getAsPose2D(mrpt::poses::CPose2D &outPose) const;
858  /**
859  * Get a pose2D whose X axis corresponds to the line, forcing the base point to one given.
860  * \throw logic_error if the point is not inside the line.
861  * \sa mrpt::poses::CPose2D.
862  */
863  void getAsPose2DForcingOrigin(const TPoint2D &origin,mrpt::poses::CPose2D &outPose) const;
864  /**
865  * Constructor from two points, through which the line will pass.
866  * \throw logic_error if both points are the same
867  */
868  TLine2D(const TPoint2D &p1,const TPoint2D &p2) throw(std::logic_error);
869  /**
870  * Constructor from a segment.
871  */
872  explicit TLine2D(const TSegment2D &s);
873  /**
874  * Fast default constructor. Initializes to garbage.
875  */
876  TLine2D() {}
877  /**
878  * Constructor from line's coefficients.
879  */
880  inline TLine2D(double A,double B,double C) {
881  coefs[0]=A;
882  coefs[1]=B;
883  coefs[2]=C;
884  }
885  /**
886  * Construction from 3D object, discarding the Z.
887  * \throw std::logic_error if the line is normal to the XY plane.
888  */
889  explicit TLine2D(const TLine3D &l);
890  };
891 
892  /**
893  * 3D line, represented by a base point and a director vector.
894  * \sa TLine2D,TSegment3D,TPlane,TPolygon3D,TPoint3D
895  */
897  public:
898  /**
899  * Base point.
900  */
902  /**
903  * Director vector.
904  */
905  double director[3];
906  /**
907  * Check whether a point is inside the line.
908  */
909  bool contains(const TPoint3D &point) const;
910  /**
911  * Distance between the line and a point.
912  */
913  double distance(const TPoint3D &point) const;
914  /**
915  * Unitarize director vector.
916  */
917  void unitarize();
918  /**
919  * Get director vector.
920  */
921  inline void getDirectorVector(double (&vector)[3]) const {
922  for (size_t i=0;i<3;i++) vector[i]=director[i];
923  }
924  /**
925  * Unitarize and then get director vector.
926  */
927  inline void getUnitaryDirectorVector(double (&vector)[3]) {
928  unitarize();
929  getDirectorVector(vector);
930  }
931  /**
932  * Project into 2D space, discarding the Z coordinate.
933  * \throw std::logic_error if the line's director vector is orthogonal to the XY plane.
934  */
935  inline void generate2DObject(TLine2D &l) const {
936  l=TLine2D(*this);
937  }
938  /**
939  * Constructor from two points, through which the line will pass.
940  * \throw std::logic_error if both points are the same.
941  */
942  TLine3D(const TPoint3D &p1,const TPoint3D &p2) throw(std::logic_error);
943  /**
944  * Constructor from 3D segment.
945  */
946  explicit TLine3D(const TSegment3D &s);
947  /**
948  * Fast default constructor. Initializes to garbage.
949  */
950  TLine3D() {}
951  /**
952  * Implicit constructor from 2D object. Zeroes the z.
953  */
954  TLine3D(const TLine2D &l);
955  };
956 
957  /**
958  * 3D Plane, represented by its equation \f$Ax+By+Cz+D=0\f$
959  * \sa TSegment3D,TLine3D,TPolygon3D,TPoint3D
960  */
962  public:
963  /**
964  * Plane coefficients, stored as an array: \f$\left[A,B,C,D\right]\f$
965  */
966  double coefs[4];
967  /**
968  * Evaluate a point in the plane's equation.
969  */
970  double evaluatePoint(const TPoint3D &point) const;
971  /**
972  * Check whether a point is contained into the plane.
973  */
974  bool contains(const TPoint3D &point) const;
975  /**
976  * Check whether a segment is fully contained into the plane.
977  */
978  inline bool contains(const TSegment3D &segment) const {
979  return contains(segment.point1)&&contains(segment.point2);
980  }
981  /**
982  * Check whether a line is fully contained into the plane.
983  */
984  bool contains(const TLine3D &line) const;
985  /**
986  * Distance to 3D point.
987  */
988  double distance(const TPoint3D &point) const;
989  /**
990  * Distance to 3D line. Will be zero if the line is not parallel to the plane.
991  */
992  double distance(const TLine3D &line) const;
993  /**
994  * Get plane's normal vector.
995  */
996  void getNormalVector(double (&vec)[3]) const;
997  /**
998  * Unitarize normal vector.
999  */
1000  void unitarize();
1001  /**
1002  * Unitarize, then get normal vector.
1003  */
1004  inline void getUnitaryNormalVector(double (&vec)[3]) {
1005  unitarize();
1006  getNormalVector(vec);
1007  }
1008  /**
1009  * Gets a pose whose XY plane corresponds to this plane.
1010  */
1011  void getAsPose3D(mrpt::poses::CPose3D &outPose);
1012  /**
1013  * Gets a pose whose XY plane corresponds to this plane.
1014  */
1015  inline void getAsPose3D(mrpt::poses::CPose3D &outPose) const {
1016  TPlane p=*this;
1017  p.getAsPose3D(outPose);
1018  }
1019  /**
1020  * Gets a pose whose XY plane corresponds to this, forcing an exact point as its spatial coordinates.
1021  * \throw std::logic_error if the point is not inside the plane.
1022  */
1023  void getAsPose3DForcingOrigin(const TPoint3D &newOrigin,mrpt::poses::CPose3D &pose);
1024  /**
1025  * Gets a pose whose XY plane corresponds to this, forcing an exact point as its spatial coordinates.
1026  * \throw std::logic_error if the point is not inside the plane.
1027  */
1028  inline void getAsPose3DForcingOrigin(const TPoint3D &newOrigin,mrpt::poses::CPose3D &pose) const {
1029  TPlane p=*this;
1030  p.getAsPose3DForcingOrigin(newOrigin,pose);
1031  }
1032  /**
1033  * Gets a plane which contains these three points.
1034  * \throw std::logic_error if the points are linearly dependants.
1035  */
1036  TPlane(const TPoint3D &p1,const TPoint3D &p2,const TPoint3D &p3) throw(std::logic_error);
1037  /**
1038  * Gets a plane which contains this point and this line.
1039  * \throw std::logic_error if the point is inside the line.
1040  */
1041  TPlane(const TPoint3D &p1,const TLine3D &r2) throw(std::logic_error);
1042  /**
1043  * Gets a plane which contains the two lines.
1044  * \throw std::logic_error if the lines do not cross.
1045  */
1046  TPlane(const TLine3D &r1,const TLine3D &r2) throw(std::logic_error);
1047  /**
1048  * Fast default constructor. Initializes to garbage.
1049  */
1050  TPlane() {}
1051  /**
1052  * Constructor from plane coefficients.
1053  */
1054  inline TPlane(double A,double B,double C,double D) {
1055  coefs[0]=A;
1056  coefs[1]=B;
1057  coefs[2]=C;
1058  coefs[3]=D;
1059  }
1060  /**
1061  * Constructor from an array of coefficients.
1062  */
1063  inline TPlane(const double (&vec)[4]) {
1064  for (size_t i=0;i<4;i++) coefs[i]=vec[i];
1065  }
1066  };
1067 
1068  typedef TPlane TPlane3D;
1069 
1070  /**
1071  * 2D polygon, inheriting from std::vector<TPoint2D>.
1072  * \sa TPolygon3D,TSegment2D,TLine2D,TPoint2D, CPolygon
1073  */
1074  class BASE_IMPEXP TPolygon2D:public std::vector<TPoint2D> {
1075  public:
1076  /**
1077  * Distance to a point.
1078  */
1079  double distance(const TPoint2D &point) const;
1080  /**
1081  * Check whether a point is inside the polygon.
1082  */
1083  bool contains(const TPoint2D &point) const;
1084  /**
1085  * Gets as set of segments, instead of points.
1086  */
1087  void getAsSegmentList(std::vector<TSegment2D> &v) const;
1088  /**
1089  * Projects into 3D space, zeroing the z.
1090  */
1091  void generate3DObject(TPolygon3D &p) const;
1092  /**
1093  * Polygon's central point.
1094  */
1095  void getCenter(TPoint2D &p) const;
1096  /**
1097  * Checks whether is convex.
1098  */
1099  bool isConvex() const;
1100  /**
1101  * Erase repeated vertices.
1102  * \sa removeRedundantVertices
1103  */
1104  void removeRepeatedVertices();
1105  /**
1106  * Erase every redundant vertex from the polygon, saving space.
1107  * \sa removeRepeatedVertices
1108  */
1109  void removeRedundantVertices();
1110  /**
1111  * Gets plot data, ready to use on a 2D plot.
1112  * \sa mrpt::gui::CDisplayWindowPlots
1113  */
1114  void getPlotData(std::vector<double> &x,std::vector<double> &y) const;
1115  /**
1116  * Default constructor.
1117  */
1118  TPolygon2D():std::vector<TPoint2D>() {}
1119  /**
1120  * Constructor for a given number of vertices, intializing them as garbage.
1121  */
1122  explicit TPolygon2D(size_t N):std::vector<TPoint2D>(N) {}
1123  /**
1124  * Implicit constructor from a vector of 2D points.
1125  */
1126  TPolygon2D(const std::vector<TPoint2D> &v):std::vector<TPoint2D>(v) {}
1127  /**
1128  * Constructor from a 3D object.
1129  */
1130  explicit TPolygon2D(const TPolygon3D &p);
1131  /**
1132  * Static method to create a regular polygon, given its size and radius.
1133  * \throw std::logic_error if radius is near zero or the number of edges is less than three.
1134  */
1135  static void createRegularPolygon(size_t numEdges,double radius,TPolygon2D &poly);
1136  /**
1137  * Static method to create a regular polygon from its size and radius. The center will correspond to the given pose.
1138  * \throw std::logic_error if radius is near zero or the number of edges is less than three.
1139  */
1140  static inline void createRegularPolygon(size_t numEdges,double radius,TPolygon2D &poly,const mrpt::poses::CPose2D &pose);
1141  };
1142 
1143  /**
1144  * 3D polygon, inheriting from std::vector<TPoint3D>
1145  * \sa TPolygon2D,TSegment3D,TLine3D,TPlane,TPoint3D
1146  */
1147  class BASE_IMPEXP TPolygon3D:public std::vector<TPoint3D> {
1148  public:
1149  /**
1150  * Distance to point.
1151  */
1152  double distance(const TPoint3D &point) const;
1153  /**
1154  * Check whether a point is inside the polygon.
1155  */
1156  bool contains(const TPoint3D &point) const;
1157  /**
1158  * Gets as set of segments, instead of set of points.
1159  */
1160  void getAsSegmentList(std::vector<TSegment3D> &v) const;
1161  /**
1162  * Gets a plane which contains the polygon. Returns false if the polygon is skew and cannot be fit inside a plane.
1163  */
1164  bool getPlane(TPlane &p) const;
1165  /**
1166  * Gets the best fitting plane, disregarding whether the polygon actually fits inside or not.
1167  * \sa getBestFittingPlane
1168  */
1169  void getBestFittingPlane(TPlane &p) const;
1170  /**
1171  * Projects into a 2D space, discarding the z.
1172  * \get getPlane,isSkew
1173  */
1174  inline void generate2DObject(TPolygon2D &p) const {
1175  p=TPolygon2D(*this);
1176  }
1177  /**
1178  * Get polygon's central point.
1179  */
1180  void getCenter(TPoint3D &p) const;
1181  /**
1182  * Check whether the polygon is skew. Returns true if there doesn't exist a plane in which the polygon can fit.
1183  * \sa getBestFittingPlane
1184  */
1185  bool isSkew() const;
1186  /**
1187  * Remove polygon's repeated vertices.
1188  */
1189  void removeRepeatedVertices();
1190  /**
1191  * Erase every redundant vertex, thus saving space.
1192  */
1193  void removeRedundantVertices();
1194  /**
1195  * Default constructor. Creates a polygon with no vertices.
1196  */
1197  TPolygon3D():std::vector<TPoint3D>() {}
1198  /**
1199  * Constructor for a given size. Creates a polygon with a fixed number of vertices, which are initialized to garbage.
1200  */
1201  explicit TPolygon3D(size_t N):std::vector<TPoint3D>(N) {}
1202  /**
1203  * Implicit constructor from a 3D points vector.
1204  */
1205  TPolygon3D(const std::vector<TPoint3D> &v):std::vector<TPoint3D>(v) {}
1206  /**
1207  * Constructor from a 2D object. Zeroes the z.
1208  */
1209  TPolygon3D(const TPolygon2D &p);
1210  /**
1211  * Static method to create a regular polygon, given its size and radius.
1212  * \throw std::logic_error if number of edges is less than three, or radius is near zero.
1213  */
1214  static void createRegularPolygon(size_t numEdges,double radius,TPolygon3D &poly);
1215  /**
1216  * Static method to create a regular polygon, given its size and radius. The center will be located on the given pose.
1217  * \throw std::logic_error if number of edges is less than three, or radius is near zero.
1218  */
1219  static inline void createRegularPolygon(size_t numEdges,double radius,TPolygon3D &poly,const mrpt::poses::CPose3D &pose);
1220  };
1221 
1222  /**
1223  * Object type identifier for TPoint2D or TPoint3D.
1224  * \sa TObject2D,TObject3D
1225  */
1226  const unsigned char GEOMETRIC_TYPE_POINT=0;
1227  /**
1228  * Object type identifier for TSegment2D or TSegment3D.
1229  * \sa TObject2D,TObject3D
1230  */
1231  const unsigned char GEOMETRIC_TYPE_SEGMENT=1;
1232  /**
1233  * Object type identifier for TLine2D or TLine3D.
1234  * \sa TObject2D,TObject3D
1235  */
1236  const unsigned char GEOMETRIC_TYPE_LINE=2;
1237  /**
1238  * Object type identifier for TPolygon2D or TPolygon3D.
1239  * \sa TObject2D,TObject3D
1240  */
1241  const unsigned char GEOMETRIC_TYPE_POLYGON=3;
1242  /**
1243  * Object type identifier for TPlane.
1244  * \sa TObject3D
1245  */
1246  const unsigned char GEOMETRIC_TYPE_PLANE=4;
1247  /**
1248  * Object type identifier for empty TObject2D or TObject3D.
1249  * \sa TObject2D,TObject3D
1250  */
1251  const unsigned char GEOMETRIC_TYPE_UNDEFINED=255;
1252 
1253  /**
1254  * Standard type for storing any lightweight 2D type. Do not inherit from this class.
1255  * \sa TPoint2D,TSegment2D,TLine2D,TPolygon2D
1256  */
1257 #ifdef TOBJECTS_USE_UNIONS
1258  struct BASE_IMPEXP TObject2D {
1259  private:
1260  /**
1261  * Object type identifier.
1262  */
1263  unsigned char type;
1264  /**
1265  * Union type storing pointers to every allowed type.
1266  */
1267  union {
1268  TPoint2D *point;
1269  TSegment2D *segment;
1270  TLine2D *line;
1271  TPolygon2D *polygon;
1272  } data;
1273  /**
1274  * Destroys the object, releasing the pointer to the content (if any).
1275  */
1276  void destroy() {
1277  switch(type) {
1278  case GEOMETRIC_TYPE_POINT:
1279  delete data.point;
1280  break;
1282  delete data.segment;
1283  break;
1284  case GEOMETRIC_TYPE_LINE:
1285  delete data.line;
1286  break;
1288  delete data.polygon;
1289  break;
1290  }
1292  }
1293  public:
1294  /**
1295  * Implicit constructor from point.
1296  */
1297  TObject2D(const TPoint2D &p):type(GEOMETRIC_TYPE_POINT) {
1298  data.point=new TPoint2D(p);
1299  }
1300  /**
1301  * Implicit constructor from segment.
1302  */
1303  TObject2D(const TSegment2D &s):type(GEOMETRIC_TYPE_SEGMENT) {
1304  data.segment=new TSegment2D(s);
1305  }
1306  /**
1307  * Implicit constructor from line.
1308  */
1309  TObject2D(const TLine2D &r):type(GEOMETRIC_TYPE_LINE) {
1310  data.line=new TLine2D(r);
1311  }
1312  /**
1313  * Implicit constructor from polygon.
1314  */
1315  TObject2D(const TPolygon2D &p):type(GEOMETRIC_TYPE_POLYGON) {
1316  data.polygon=new TPolygon2D(p);
1317  }
1318  /**
1319  * Implicit constructor from polygon.
1320  */
1322  /**
1323  * Object destruction.
1324  */
1325  ~TObject2D() {
1326  destroy();
1327  }
1328  /**
1329  * Checks whether content is a point.
1330  */
1331  inline bool isPoint() const {
1332  return type==GEOMETRIC_TYPE_POINT;
1333  }
1334  /**
1335  * Checks whether content is a segment.
1336  */
1337  inline bool isSegment() const {
1338  return type==GEOMETRIC_TYPE_SEGMENT;
1339  }
1340  /**
1341  * Checks whether content is a line.
1342  */
1343  inline bool isLine() const {
1344  return type==GEOMETRIC_TYPE_LINE;
1345  }
1346  /**
1347  * Checks whether content is a polygon.
1348  */
1349  inline bool isPolygon() const {
1350  return type==GEOMETRIC_TYPE_POLYGON;
1351  }
1352  /**
1353  * Gets content type.
1354  */
1355  inline unsigned char getType() const {
1356  return type;
1357  }
1358  /**
1359  * Gets the content as a point, returning false if the type is inadequate.
1360  */
1361  inline bool getPoint(TPoint2D &p) const {
1362  if (isPoint()) {
1363  p=*(data.point);
1364  return true;
1365  } else return false;
1366  }
1367  /**
1368  * Gets the content as a segment, returning false if the type is inadequate.
1369  */
1370  inline bool getSegment(TSegment2D &s) const {
1371  if (isSegment()) {
1372  s=*(data.segment);
1373  return true;
1374  } else return false;
1375  }
1376  /**
1377  * Gets the content as a line, returning false if the type is inadequate.
1378  */
1379  inline bool getLine(TLine2D &r) const {
1380  if (isLine()) {
1381  r=*(data.line);
1382  return true;
1383  } else return false;
1384  }
1385  /**
1386  * Gets the content as a polygon, returning false if the type is inadequate.
1387  */
1388  inline bool getPolygon(TPolygon2D &p) const {
1389  if (isPolygon()) {
1390  p=*(data.polygon);
1391  return true;
1392  } else return false;
1393  }
1394  /**
1395  * Assign another TObject2D. Pointers are not shared.
1396  */
1397  void operator=(const TObject2D &obj) {
1398  if (this==&obj) return;
1399  destroy();
1400  switch (type=obj.type) {
1401  case GEOMETRIC_TYPE_POINT:
1402  data.point=new TPoint2D(*(obj.data.point));
1403  break;
1405  data.segment=new TSegment2D(*(obj.data.segment));
1406  break;
1407  case GEOMETRIC_TYPE_LINE:
1408  data.line=new TLine2D(*(obj.data.line));
1409  break;
1411  data.polygon=new TPolygon2D(*(obj.data.polygon));
1412  break;
1413  }
1414  }
1415  /**
1416  * Assign a point to this object.
1417  */
1418  inline void operator=(const TPoint2D &p) {
1419  destroy();
1420  type=GEOMETRIC_TYPE_POINT;
1421  data.point=new TPoint2D(p);
1422  }
1423  /**
1424  * Assign a segment to this object.
1425  */
1426  inline void operator=(const TSegment2D &s) {
1427  destroy();
1429  data.segment=new TSegment2D(s);
1430  }
1431  /**
1432  * Assign a line to this object.
1433  */
1434  inline void operator=(const TLine2D &l) {
1435  destroy();
1436  type=GEOMETRIC_TYPE_LINE;
1437  data.line=new TLine2D(l);
1438  }
1439  /**
1440  * Assign a polygon to this object.
1441  */
1442  inline void operator=(const TPolygon2D &p) {
1443  destroy();
1445  data.polygon=new TPolygon2D(p);
1446  }
1447  /**
1448  * Project into 3D space.
1449  */
1450  void generate3DObject(TObject3D &obj) const;
1451  /**
1452  * Constructor from another TObject2D.
1453  */
1454  TObject2D(const TObject2D &obj):type(GEOMETRIC_TYPE_UNDEFINED) {
1455  operator=(obj);
1456  }
1457  /**
1458  * Static method to retrieve all the points in a vector of TObject2D.
1459  */
1460  static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts);
1461  /**
1462  * Static method to retrieve all the segments in a vector of TObject2D.
1463  */
1464  static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms);
1465  /**
1466  * Static method to retrieve all the lines in a vector of TObject2D.
1467  */
1468  static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins);
1469  /**
1470  * Static method to retrieve all the polygons in a vector of TObject2D.
1471  */
1472  static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys);
1473  /**
1474  * Static method to retrieve all the points in a vector of TObject2D, returning the remainder objects in another parameter.
1475  */
1476  static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts,std::vector<TObject2D> &remainder);
1477  /**
1478  * Static method to retrieve all the segments in a vector of TObject2D, returning the remainder objects in another parameter.
1479  */
1480  static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms,std::vector<TObject2D> &remainder);
1481  /**
1482  * Static method to retrieve all the lines in a vector of TObject2D, returning the remainder objects in another parameter.
1483  */
1484  static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins,std::vector<TObject2D> &remainder);
1485  /**
1486  * Static method to retrieve all the polygons in a vector of TObject2D, returning the remainder objects in another parameter.
1487  */
1488  static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys,std::vector<TObject2D> &remainder);
1489  };
1490  /**
1491  * Standard object for storing any 3D lightweight object. Do not inherit from this class.
1492  * \sa TPoint3D,TSegment3D,TLine3D,TPlane,TPolygon3D
1493  */
1494  struct BASE_IMPEXP TObject3D {
1495  private:
1496  /**
1497  * Object type identifier.
1498  */
1499  unsigned char type;
1500  /**
1501  * Union containing pointer to actual data.
1502  */
1503  union {
1504  TPoint3D *point;
1505  TSegment3D *segment;
1506  TLine3D *line;
1507  TPolygon3D *polygon;
1508  TPlane *plane;
1509  } data;
1510  /**
1511  * Destroys the object and releases the pointer, if any.
1512  */
1513  void destroy() {
1514  switch (type) {
1515  case GEOMETRIC_TYPE_POINT:
1516  delete data.point;
1517  break;
1519  delete data.segment;
1520  break;
1521  case GEOMETRIC_TYPE_LINE:
1522  delete data.line;
1523  break;
1525  delete data.polygon;
1526  break;
1527  case GEOMETRIC_TYPE_PLANE:
1528  delete data.plane;
1529  break;
1531  break;
1532  default:
1533  THROW_EXCEPTION("Invalid TObject2D object");
1534  }
1536  }
1537  public:
1538  /**
1539  * Constructor from point.
1540  */
1541  TObject3D(const TPoint3D &p):type(GEOMETRIC_TYPE_POINT) {
1542  data.point=new TPoint3D(p);
1543  }
1544  /**
1545  * Constructor from segment.
1546  */
1547  TObject3D(const TSegment3D &s):type(GEOMETRIC_TYPE_SEGMENT) {
1548  data.segment=new TSegment3D(s);
1549  }
1550  /**
1551  * Constructor from line.
1552  */
1553  TObject3D(const TLine3D &r):type(GEOMETRIC_TYPE_LINE) {
1554  data.line=new TLine3D(r);
1555  }
1556  /**
1557  * Constructor from polygon.
1558  */
1559  TObject3D(const TPolygon3D &p):type(GEOMETRIC_TYPE_POLYGON) {
1560  data.polygon=new TPolygon3D(p);
1561  }
1562  /**
1563  * Constructor from plane.
1564  */
1565  TObject3D(const TPlane &p):type(GEOMETRIC_TYPE_PLANE) {
1566  data.plane=new TPlane(p);
1567  }
1568  /**
1569  * Empty constructor.
1570  */
1572  /**
1573  * Destructor.
1574  */
1575  ~TObject3D() {
1576  destroy();
1577  }
1578  /**
1579  * Checks whether content is a point.
1580  */
1581  inline bool isPoint() const {
1582  return type==GEOMETRIC_TYPE_POINT;
1583  }
1584  /**
1585  * Checks whether content is a segment.
1586  */
1587  inline bool isSegment() const {
1588  return type==GEOMETRIC_TYPE_SEGMENT;
1589  }
1590  /**
1591  * Checks whether content is a line.
1592  */
1593  inline bool isLine() const {
1594  return type==GEOMETRIC_TYPE_LINE;
1595  }
1596  /**
1597  * Checks whether content is a polygon.
1598  */
1599  inline bool isPolygon() const {
1600  return type==GEOMETRIC_TYPE_POLYGON;
1601  }
1602  /**
1603  * Checks whether content is a plane.
1604  */
1605  inline bool isPlane() const {
1606  return type==GEOMETRIC_TYPE_PLANE;
1607  }
1608  /**
1609  * Gets object type.
1610  */
1611  inline unsigned char getType() const {
1612  return type;
1613  }
1614  /**
1615  * Gets the content as a point, returning false if the type is not adequate.
1616  */
1617  inline bool getPoint(TPoint3D &p) const {
1618  if (isPoint()) {
1619  p=*(data.point);
1620  return true;
1621  } else return false;
1622  }
1623  /**
1624  * Gets the content as a segment, returning false if the type is not adequate.
1625  */
1626  inline bool getSegment(TSegment3D &s) const {
1627  if (isSegment()) {
1628  s=*(data.segment);
1629  return true;
1630  } else return false;
1631  }
1632  /**
1633  * Gets the content as a line, returning false if the type is not adequate.
1634  */
1635  inline bool getLine(TLine3D &r) const {
1636  if (isLine()) {
1637  r=*(data.line);
1638  return true;
1639  } else return false;
1640  }
1641  /**
1642  * Gets the content as a polygon, returning false if the type is not adequate.
1643  */
1644  inline bool getPolygon(TPolygon3D &p) const {
1645  if (isPolygon()) {
1646  p=*(data.polygon);
1647  return true;
1648  } else return false;
1649  }
1650  /**
1651  * Gets the content as a plane, returning false if the type is not adequate.
1652  */
1653  inline bool getPlane(TPlane &p) const {
1654  if (isPlane()) {
1655  p=*(data.plane);
1656  return true;
1657  } else return false;
1658  }
1659  /**
1660  * Assigns another object, creating a new pointer if needed.
1661  */
1662  void operator=(const TObject3D &obj) {
1663  if (this==&obj) return;
1664  destroy();
1665  switch (type=obj.type) {
1666  case GEOMETRIC_TYPE_POINT:
1667  data.point=new TPoint3D(*(obj.data.point));
1668  break;
1670  data.segment=new TSegment3D(*(obj.data.segment));
1671  break;
1672  case GEOMETRIC_TYPE_LINE:
1673  data.line=new TLine3D(*(obj.data.line));
1674  break;
1676  data.polygon=new TPolygon3D(*(obj.data.polygon));
1677  break;
1678  case GEOMETRIC_TYPE_PLANE:
1679  data.plane=new TPlane(*(obj.data.plane));
1680  break;
1682  break;
1683  default:
1684  THROW_EXCEPTION("Invalid TObject3D object");
1685  }
1686  }
1687  /**
1688  * Assigns a point to this object.
1689  */
1690  inline void operator=(const TPoint3D &p) {
1691  destroy();
1692  type=GEOMETRIC_TYPE_POINT;
1693  data.point=new TPoint3D(p);
1694  }
1695  /**
1696  * Assigns a segment to this object.
1697  */
1698  inline void operator=(const TSegment3D &s) {
1699  destroy();
1701  data.segment=new TSegment3D(s);
1702  }
1703  /**
1704  * Assigns a line to this object.
1705  */
1706  inline void operator=(const TLine3D &l) {
1707  destroy();
1708  type=GEOMETRIC_TYPE_LINE;
1709  data.line=new TLine3D(l);
1710  }
1711  /**
1712  * Assigns a polygon to this object.
1713  */
1714  inline void operator=(const TPolygon3D &p) {
1715  destroy();
1717  data.polygon=new TPolygon3D(p);
1718  }
1719  /**
1720  * Assigns a plane to this object.
1721  */
1722  inline void operator=(const TPlane &p) {
1723  destroy();
1724  type=GEOMETRIC_TYPE_PLANE;
1725  data.plane=new TPlane(p);
1726  }
1727  /**
1728  * Projects into 2D space.
1729  * \throw std::logic_error if the 3D object loses its properties when projecting into 2D space (for example, it's a plane or a vertical line).
1730  */
1731  inline void generate2DObject(TObject2D &obj) const {
1732  switch (type) {
1733  case GEOMETRIC_TYPE_POINT:
1734  obj=TPoint2D(*(data.point));
1735  break;
1737  obj=TSegment2D(*(data.segment));
1738  break;
1739  case GEOMETRIC_TYPE_LINE:
1740  obj=TLine2D(*(data.line));
1741  break;
1743  obj=TPolygon2D(*(data.polygon));
1744  break;
1745  case GEOMETRIC_TYPE_PLANE:
1746  throw std::logic_error("Too many dimensions");
1747  default:
1748  obj=TObject2D();
1749  break;
1750  }
1751  }
1752  /**
1753  * Constructs from another object.
1754  */
1755  TObject3D(const TObject3D &obj):type(GEOMETRIC_TYPE_UNDEFINED) {
1756  operator=(obj);
1757  }
1758  /**
1759  * Static method to retrieve every point included in a vector of objects.
1760  */
1761  static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts);
1762  /**
1763  * Static method to retrieve every segment included in a vector of objects.
1764  */
1765  static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms);
1766  /**
1767  * Static method to retrieve every line included in a vector of objects.
1768  */
1769  static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins);
1770  /**
1771  * Static method to retrieve every plane included in a vector of objects.
1772  */
1773  static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns);
1774  /**
1775  * Static method to retrieve every polygon included in a vector of objects.
1776  */
1777  static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys);
1778  /**
1779  * Static method to retrieve every point included in a vector of objects, returning the remaining objects in another argument.
1780  */
1781  static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts,std::vector<TObject3D> &remainder);
1782  /**
1783  * Static method to retrieve every segment included in a vector of objects, returning the remaining objects in another argument.
1784  */
1785  static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms,std::vector<TObject3D> &remainder);
1786  /**
1787  * Static method to retrieve every line included in a vector of objects, returning the remaining objects in another argument.
1788  */
1789  static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins,std::vector<TObject3D> &remainder);
1790  /**
1791  * Static method to retrieve every plane included in a vector of objects, returning the remaining objects in another argument.
1792  */
1793  static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns,std::vector<TObject3D> &remainder);
1794  /**
1795  * Static method to retrieve every polygon included in a vector of objects, returning the remaining objects in another argument.
1796  */
1797  static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TObject3D> &remainder);
1798  };
1799 #else
1801  private:
1802  /**
1803  * Object type identifier.
1804  */
1805  unsigned char type;
1806  /**
1807  * Union type storing pointers to every allowed type.
1808  */
1809  struct {
1814  } data;
1815  /**
1816  * Destroys the object, releasing the pointer to the content (if any).
1817  */
1818  inline void destroy() {
1819  if (type==GEOMETRIC_TYPE_POLYGON) delete data.polygon;
1821  }
1822  public:
1823  /**
1824  * Implicit constructor from point.
1825  */
1826  inline TObject2D(const TPoint2D &p):type(GEOMETRIC_TYPE_POINT) {
1827  data.point=p;
1828  }
1829  /**
1830  * Implicit constructor from segment.
1831  */
1833  data.segment=s;
1834  }
1835  /**
1836  * Implicit constructor from line.
1837  */
1838  inline TObject2D(const TLine2D &r):type(GEOMETRIC_TYPE_LINE) {
1839  data.line=r;
1840  }
1841  /**
1842  * Implicit constructor from polygon.
1843  */
1845  data.polygon=new TPolygon2D(p);
1846  }
1847  /**
1848  * Implicit constructor from polygon.
1849  */
1851  /**
1852  * Object destruction.
1853  */
1855  destroy();
1856  }
1857  /**
1858  * Checks whether content is a point.
1859  */
1860  inline bool isPoint() const {
1861  return type==GEOMETRIC_TYPE_POINT;
1862  }
1863  /**
1864  * Checks whether content is a segment.
1865  */
1866  inline bool isSegment() const {
1867  return type==GEOMETRIC_TYPE_SEGMENT;
1868  }
1869  /**
1870  * Checks whether content is a line.
1871  */
1872  inline bool isLine() const {
1873  return type==GEOMETRIC_TYPE_LINE;
1874  }
1875  /**
1876  * Checks whether content is a polygon.
1877  */
1878  inline bool isPolygon() const {
1879  return type==GEOMETRIC_TYPE_POLYGON;
1880  }
1881  /**
1882  * Gets content type.
1883  */
1884  inline unsigned char getType() const {
1885  return type;
1886  }
1887  /**
1888  * Gets the content as a point, returning false if the type is inadequate.
1889  */
1890  inline bool getPoint(TPoint2D &p) const {
1891  if (isPoint()) {
1892  p=data.point;
1893  return true;
1894  } else return false;
1895  }
1896  /**
1897  * Gets the content as a segment, returning false if the type is inadequate.
1898  */
1899  inline bool getSegment(TSegment2D &s) const {
1900  if (isSegment()) {
1901  s=data.segment;
1902  return true;
1903  } else return false;
1904  }
1905  /**
1906  * Gets the content as a line, returning false if the type is inadequate.
1907  */
1908  inline bool getLine(TLine2D &r) const {
1909  if (isLine()) {
1910  r=data.line;
1911  return true;
1912  } else return false;
1913  }
1914  /**
1915  * Gets the content as a polygon, returning false if the type is inadequate.
1916  */
1917  inline bool getPolygon(TPolygon2D &p) const {
1918  if (isPolygon()) {
1919  p=*(data.polygon);
1920  return true;
1921  } else return false;
1922  }
1923  /**
1924  * Assign another TObject2D. Pointers are not shared.
1925  */
1926  void operator=(const TObject2D &obj) {
1927  if (this==&obj) return;
1928  destroy();
1929  switch (type=obj.type) {
1930  case GEOMETRIC_TYPE_POINT:
1931  data.point=obj.data.point;
1932  break;
1934  data.segment=obj.data.segment;
1935  break;
1936  case GEOMETRIC_TYPE_LINE:
1937  data.line=obj.data.line;
1938  break;
1940  data.polygon=new TPolygon2D(*(obj.data.polygon));
1941  break;
1942  }
1943  }
1944  /**
1945  * Assign a point to this object.
1946  */
1947  inline void operator=(const TPoint2D &p) {
1948  destroy();
1949  type=GEOMETRIC_TYPE_POINT;
1950  data.point=p;
1951  }
1952  /**
1953  * Assign a segment to this object.
1954  */
1955  inline void operator=(const TSegment2D &s) {
1956  destroy();
1958  data.segment=s;
1959  }
1960  /**
1961  * Assign a line to this object.
1962  */
1963  inline void operator=(const TLine2D &l) {
1964  destroy();
1965  type=GEOMETRIC_TYPE_LINE;
1966  data.line=l;
1967  }
1968  /**
1969  * Assign a polygon to this object.
1970  */
1971  inline void operator=(const TPolygon2D &p) {
1972  destroy();
1974  data.polygon=new TPolygon2D(p);
1975  }
1976  /**
1977  * Project into 3D space.
1978  */
1979  void generate3DObject(TObject3D &obj) const;
1980  /**
1981  * Constructor from another TObject2D.
1982  */
1984  operator=(obj);
1985  }
1986  /**
1987  * Static method to retrieve all the points in a vector of TObject2D.
1988  */
1989  static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts);
1990  /**
1991  * Static method to retrieve all the segments in a vector of TObject2D.
1992  */
1993  static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms);
1994  /**
1995  * Static method to retrieve all the lines in a vector of TObject2D.
1996  */
1997  static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins);
1998  /**
1999  * Static method to retrieve all the polygons in a vector of TObject2D.
2000  */
2001  static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys);
2002  /**
2003  * Static method to retrieve all the points in a vector of TObject2D, returning the remainder objects in another parameter.
2004  */
2005  static void getPoints(const std::vector<TObject2D> &objs,std::vector<TPoint2D> &pnts,std::vector<TObject2D> &remainder);
2006  /**
2007  * Static method to retrieve all the segments in a vector of TObject2D, returning the remainder objects in another parameter.
2008  */
2009  static void getSegments(const std::vector<TObject2D> &objs,std::vector<TSegment2D> &sgms,std::vector<TObject2D> &remainder);
2010  /**
2011  * Static method to retrieve all the lines in a vector of TObject2D, returning the remainder objects in another parameter.
2012  */
2013  static void getLines(const std::vector<TObject2D> &objs,std::vector<TLine2D> &lins,std::vector<TObject2D> &remainder);
2014  /**
2015  * Static method to retrieve all the polygons in a vector of TObject2D, returning the remainder objects in another parameter.
2016  */
2017  static void getPolygons(const std::vector<TObject2D> &objs,std::vector<TPolygon2D> &polys,std::vector<TObject2D> &remainder);
2018  };
2019  /**
2020  * Standard object for storing any 3D lightweight object. Do not inherit from this class.
2021  * \sa TPoint3D,TSegment3D,TLine3D,TPlane,TPolygon3D
2022  */
2024  private:
2025  /**
2026  * Object type identifier.
2027  */
2028  unsigned char type;
2029  /**
2030  * Union containing pointer to actual data.
2031  */
2032  struct {
2038  } data;
2039  /**
2040  * Destroys the object and releases the pointer, if any.
2041  */
2042  void destroy() {
2043  if (type==GEOMETRIC_TYPE_POLYGON) delete data.polygon;
2045  }
2046  public:
2047  /**
2048  * Constructor from point.
2049  */
2051  data.point=p;
2052  }
2053  /**
2054  * Constructor from segment.
2055  */
2057  data.segment=s;
2058  }
2059  /**
2060  * Constructor from line.
2061  */
2063  data.line=r;
2064  }
2065  /**
2066  * Constructor from polygon.
2067  */
2069  data.polygon=new TPolygon3D(p);
2070  }
2071  /**
2072  * Constructor from plane.
2073  */
2075  data.plane=p;
2076  }
2077  /**
2078  * Empty constructor.
2079  */
2081  /**
2082  * Destructor.
2083  */
2085  destroy();
2086  }
2087  /**
2088  * Checks whether content is a point.
2089  */
2090  inline bool isPoint() const {
2091  return type==GEOMETRIC_TYPE_POINT;
2092  }
2093  /**
2094  * Checks whether content is a segment.
2095  */
2096  inline bool isSegment() const {
2097  return type==GEOMETRIC_TYPE_SEGMENT;
2098  }
2099  /**
2100  * Checks whether content is a line.
2101  */
2102  inline bool isLine() const {
2103  return type==GEOMETRIC_TYPE_LINE;
2104  }
2105  /**
2106  * Checks whether content is a polygon.
2107  */
2108  inline bool isPolygon() const {
2109  return type==GEOMETRIC_TYPE_POLYGON;
2110  }
2111  /**
2112  * Checks whether content is a plane.
2113  */
2114  inline bool isPlane() const {
2115  return type==GEOMETRIC_TYPE_PLANE;
2116  }
2117  /**
2118  * Gets object type.
2119  */
2120  inline unsigned char getType() const {
2121  return type;
2122  }
2123  /**
2124  * Gets the content as a point, returning false if the type is not adequate.
2125  */
2126  inline bool getPoint(TPoint3D &p) const {
2127  if (isPoint()) {
2128  p=data.point;
2129  return true;
2130  } else return false;
2131  }
2132  /**
2133  * Gets the content as a segment, returning false if the type is not adequate.
2134  */
2135  inline bool getSegment(TSegment3D &s) const {
2136  if (isSegment()) {
2137  s=data.segment;
2138  return true;
2139  } else return false;
2140  }
2141  /**
2142  * Gets the content as a line, returning false if the type is not adequate.
2143  */
2144  inline bool getLine(TLine3D &r) const {
2145  if (isLine()) {
2146  r=data.line;
2147  return true;
2148  } else return false;
2149  }
2150  /**
2151  * Gets the content as a polygon, returning false if the type is not adequate.
2152  */
2153  inline bool getPolygon(TPolygon3D &p) const {
2154  if (isPolygon()) {
2155  p=*(data.polygon);
2156  return true;
2157  } else return false;
2158  }
2159  /**
2160  * Gets the content as a plane, returning false if the type is not adequate.
2161  */
2162  inline bool getPlane(TPlane &p) const {
2163  if (isPlane()) {
2164  p=data.plane;
2165  return true;
2166  } else return false;
2167  }
2168  /**
2169  * Assigns another object, creating a new pointer if needed.
2170  */
2171  void operator=(const TObject3D &obj) {
2172  if (this==&obj) return;
2173  destroy();
2174  switch (type=obj.type) {
2175  case GEOMETRIC_TYPE_POINT:
2176  data.point=obj.data.point;
2177  break;
2179  data.segment=obj.data.segment;
2180  break;
2181  case GEOMETRIC_TYPE_LINE:
2182  data.line=obj.data.line;
2183  break;
2185  data.polygon=new TPolygon3D(*(obj.data.polygon));
2186  break;
2187  case GEOMETRIC_TYPE_PLANE:
2188  data.plane=obj.data.plane;
2189  break;
2191  break;
2192  default:
2193  THROW_EXCEPTION("Invalid TObject3D object");
2194  }
2195  }
2196  /**
2197  * Assigns a point to this object.
2198  */
2199  inline void operator=(const TPoint3D &p) {
2200  destroy();
2201  type=GEOMETRIC_TYPE_POINT;
2202  data.point=p;
2203  }
2204  /**
2205  * Assigns a segment to this object.
2206  */
2207  inline void operator=(const TSegment3D &s) {
2208  destroy();
2210  data.segment=s;
2211  }
2212  /**
2213  * Assigns a line to this object.
2214  */
2215  inline void operator=(const TLine3D &l) {
2216  destroy();
2217  type=GEOMETRIC_TYPE_LINE;
2218  data.line=l;
2219  }
2220  /**
2221  * Assigns a polygon to this object.
2222  */
2223  inline void operator=(const TPolygon3D &p) {
2224  destroy();
2226  data.polygon=new TPolygon3D(p);
2227  }
2228  /**
2229  * Assigns a plane to this object.
2230  */
2231  inline void operator=(const TPlane &p) {
2232  destroy();
2233  type=GEOMETRIC_TYPE_PLANE;
2234  data.plane=p;
2235  }
2236  /**
2237  * Projects into 2D space.
2238  * \throw std::logic_error if the 3D object loses its properties when projecting into 2D space (for example, it's a plane or a vertical line).
2239  */
2240  inline void generate2DObject(TObject2D &obj) const {
2241  switch (type) {
2242  case GEOMETRIC_TYPE_POINT:
2243  obj=TPoint2D(data.point);
2244  break;
2246  obj=TSegment2D(data.segment);
2247  break;
2248  case GEOMETRIC_TYPE_LINE:
2249  obj=TLine2D(data.line);
2250  break;
2252  obj=TPolygon2D(*(data.polygon));
2253  break;
2254  case GEOMETRIC_TYPE_PLANE:
2255  throw std::logic_error("Too many dimensions");
2256  default:
2257  obj=TObject2D();
2258  break;
2259  }
2260  }
2261  /**
2262  * Constructs from another object.
2263  */
2265  operator=(obj);
2266  }
2267  /**
2268  * Static method to retrieve every point included in a vector of objects.
2269  */
2270  static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts);
2271  /**
2272  * Static method to retrieve every segment included in a vector of objects.
2273  */
2274  static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms);
2275  /**
2276  * Static method to retrieve every line included in a vector of objects.
2277  */
2278  static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins);
2279  /**
2280  * Static method to retrieve every plane included in a vector of objects.
2281  */
2282  static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns);
2283  /**
2284  * Static method to retrieve every polygon included in a vector of objects.
2285  */
2286  static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys);
2287  /**
2288  * Static method to retrieve every point included in a vector of objects, returning the remaining objects in another argument.
2289  */
2290  static void getPoints(const std::vector<TObject3D> &objs,std::vector<TPoint3D> &pnts,std::vector<TObject3D> &remainder);
2291  /**
2292  * Static method to retrieve every segment included in a vector of objects, returning the remaining objects in another argument.
2293  */
2294  static void getSegments(const std::vector<TObject3D> &objs,std::vector<TSegment3D> &sgms,std::vector<TObject3D> &remainder);
2295  /**
2296  * Static method to retrieve every line included in a vector of objects, returning the remaining objects in another argument.
2297  */
2298  static void getLines(const std::vector<TObject3D> &objs,std::vector<TLine3D> &lins,std::vector<TObject3D> &remainder);
2299  /**
2300  * Static method to retrieve every plane included in a vector of objects, returning the remaining objects in another argument.
2301  */
2302  static void getPlanes(const std::vector<TObject3D> &objs,std::vector<TPlane> &plns,std::vector<TObject3D> &remainder);
2303  /**
2304  * Static method to retrieve every polygon included in a vector of objects, returning the remaining objects in another argument.
2305  */
2306  static void getPolygons(const std::vector<TObject3D> &objs,std::vector<TPolygon3D> &polys,std::vector<TObject3D> &remainder);
2307  };
2308 
2309 #endif
2310 
2311 
2312  //Streaming functions
2313  /**
2314  * TPoint2D binary input.
2315  */
2317  /**
2318  * TPoint2D binary output.
2319  */
2321 
2322  /**
2323  * TPoint3D binary input.
2324  */
2326  /**
2327  * TPoint3D binary output.
2328  */
2330 
2331  /**
2332  * TPose2D binary input.
2333  */
2335  /**
2336  * TPose2D binary output.
2337  */
2339 
2340  /**
2341  * TPose3D binary input.
2342  */
2344  /**
2345  * TPose3D binary output.
2346  */
2348 
2349  /**
2350  * TSegment2D binary input.
2351  */
2353  return in>>s.point1>>s.point2;
2354  }
2355  /**
2356  * TSegment2D binary output.
2357  */
2359  return out<<s.point1<<s.point2;
2360  }
2361 
2362  /**
2363  * TLine2D binary input.
2364  */
2366  return in>>l.coefs[0]>>l.coefs[1]>>l.coefs[2];
2367  }
2368  /**
2369  * TLine2D binary output.
2370  */
2372  return out<<l.coefs[0]<<l.coefs[1]<<l.coefs[2];
2373  }
2374 
2375  /**
2376  * TObject2D binary input.
2377  */
2379  /**
2380  * TObject2D binary input.
2381  */
2383 
2384  /**
2385  * TSegment3D binary input.
2386  */
2388  return in>>s.point1>>s.point2;
2389  }
2390  /**
2391  * TSegment3D binary output.
2392  */
2394  return out<<s.point1<<s.point2;
2395  }
2396 
2397  /**
2398  * TLine3D binary input.
2399  */
2401  return in>>l.pBase>>l.director[0]>>l.director[1]>>l.director[2];
2402  }
2403  /**
2404  * TLine3D binary output.
2405  */
2407  return out<<l.pBase<<l.director[0]<<l.director[1]<<l.director[2];
2408  }
2409 
2410  /**
2411  * TPlane binary input.
2412  */
2414  return in>>p.coefs[0]>>p.coefs[1]>>p.coefs[2]>>p.coefs[3];
2415  }
2416  /**
2417  * TPlane binary output.
2418  */
2420  return out<<p.coefs[0]<<p.coefs[1]<<p.coefs[2]<<p.coefs[3];
2421  }
2422 
2423  /**
2424  * TObject3D binary input.
2425  */
2427  /**
2428  * TObject3D binary output.
2429  */
2431 
2432 
2433  /** @} */ // end of grouping
2434 
2435  } //end of namespace math
2436 
2437  namespace utils
2438  {
2439  using namespace ::mrpt::math;
2440 
2441  // Specialization must occur in the same namespace
2442  MRPT_DECLARE_TTYPENAME(TPoint2D)
2443  MRPT_DECLARE_TTYPENAME(TPoint3D)
2444  MRPT_DECLARE_TTYPENAME(TPose2D)
2445  MRPT_DECLARE_TTYPENAME(TPose3D)
2446  MRPT_DECLARE_TTYPENAME(TSegment2D)
2447  MRPT_DECLARE_TTYPENAME(TLine2D)
2448  MRPT_DECLARE_TTYPENAME(TPolygon2D)
2449  MRPT_DECLARE_TTYPENAME(TObject2D)
2452  MRPT_DECLARE_TTYPENAME(TPlane)
2455 
2456  } // end of namespace utils
2457 
2458 } //end of namespace
2459 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013