MRPT  1.9.9
TObject2D.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "math-precomp.h" // Precompiled headers
11 
12 #include <mrpt/math/TLine3D.h>
13 #include <mrpt/math/TObject2D.h>
14 #include <mrpt/math/TObject3D.h>
15 #include <mrpt/math/TPoint3D.h>
16 #include <mrpt/math/TPolygon2D.h>
17 #include <mrpt/math/TPolygon3D.h>
18 #include <mrpt/math/TSegment3D.h>
19 #include <mrpt/serialization/CArchive.h> // impl of << operator
20 #include <mrpt/serialization/stl_serialization.h> // >> of TPolygon2D
21 
22 using namespace mrpt::math;
23 
25 {
26  switch (type)
27  {
29  obj = TPoint3D(data.point);
30  break;
32  obj = TSegment3D(data.segment);
33  break;
35  obj = TLine3D(data.line);
36  break;
38  obj = TPolygon3D(*(data.polygon));
39  break;
40  default:
41  obj = TObject3D();
42  break;
43  }
44 }
46  const std::vector<TObject2D>& objs, std::vector<TPoint2D>& pnts)
47 {
48  for (const auto& obj : objs)
49  if (obj.isPoint()) pnts.push_back(obj.data.point);
50 }
52  const std::vector<TObject2D>& objs, std::vector<TSegment2D>& sgms)
53 {
54  for (const auto& obj : objs)
55  if (obj.isSegment()) sgms.push_back(obj.data.segment);
56 }
58  const std::vector<TObject2D>& objs, std::vector<TLine2D>& lins)
59 {
60  for (const auto& obj : objs)
61  if (obj.isLine()) lins.push_back(obj.data.line);
62 }
64  const std::vector<TObject2D>& objs, std::vector<TPolygon2D>& polys)
65 {
66  for (const auto& obj : objs)
67  if (obj.isPolygon()) polys.push_back(*(obj.data.polygon));
68 }
70  const std::vector<TObject2D>& objs, std::vector<TPoint2D>& pnts,
71  std::vector<TObject2D>& remainder)
72 {
73  for (const auto& obj : objs)
74  if (obj.isPoint())
75  pnts.push_back(obj.data.point);
76  else
77  remainder.push_back(obj);
78 }
80  const std::vector<TObject2D>& objs, std::vector<TSegment2D>& sgms,
81  std::vector<TObject2D>& remainder)
82 {
83  for (const auto& obj : objs)
84  if (obj.isSegment())
85  sgms.push_back(obj.data.segment);
86  else
87  remainder.push_back(obj);
88 }
90  const std::vector<TObject2D>& objs, std::vector<TLine2D>& lins,
91  std::vector<TObject2D>& remainder)
92 {
93  for (const auto& obj : objs)
94  if (obj.isLine())
95  lins.push_back(obj.data.line);
96  else
97  remainder.push_back(obj);
98 }
100  const std::vector<TObject2D>& objs, std::vector<TPolygon2D>& polys,
101  std::vector<TObject2D>& remainder)
102 {
103  for (const auto& obj : objs)
104  if (obj.isPolygon())
105  polys.push_back(*(obj.data.polygon));
106  else
107  remainder.push_back(obj);
108 }
109 
112 {
113  uint16_t type;
114  in >> type;
115  switch (static_cast<unsigned char>(type))
116  {
118  {
119  TPoint2D p;
120  in >> p;
121  o = p;
122  }
123  break;
125  {
126  TSegment2D s;
127  in >> s;
128  o = s;
129  }
130  break;
131  case GEOMETRIC_TYPE_LINE:
132  {
133  TLine2D l;
134  in >> l;
135  o = l;
136  }
137  break;
139  {
140  TPolygon2D p;
141  in >> p;
142  o = p;
143  }
144  break;
146  {
147  o = TObject2D();
148  }
149  break;
150  default:
151  throw std::logic_error(
152  "Unknown TObject2D type found while reading stream");
153  }
154  return in;
155 }
156 
159 {
160  out.WriteAs<uint16_t>(o.getType());
161  switch (o.getType())
162  {
164  {
165  TPoint2D p;
166  o.getPoint(p);
167  return out << p;
168  };
170  {
171  TSegment2D s;
172  o.getSegment(s);
173  return out << s;
174  };
175  case GEOMETRIC_TYPE_LINE:
176  {
177  TLine2D l;
178  o.getLine(l);
179  return out << l;
180  };
182  {
183  TPolygon2D p;
184  o.getPolygon(p);
185  return out << p;
186  };
187  }
188  return out;
189 }
bool getPoint(TPoint2D &p) const
Gets the content as a point, returning false if the type is inadequate.
Definition: TObject2D.h:109
bool getPolygon(TPolygon2D &p) const
Gets the content as a polygon, returning false if the type is inadequate.
Definition: TObject2D.h:150
unsigned char getType() const
Gets content type.
Definition: TObject2D.h:105
static constexpr unsigned char GEOMETRIC_TYPE_POLYGON
Object type identifier for TPolygon2D or TPolygon3D.
Definition: TPoseOrPoint.h:125
static void getLines(const std::vector< TObject2D > &objs, std::vector< TLine2D > &lins)
Static method to retrieve all the lines in a vector of TObject2D.
Definition: TObject2D.cpp:57
Standard type for storing any lightweight 2D type.
Definition: TObject2D.h:24
bool getLine(TLine2D &r) const
Gets the content as a line, returning false if the type is inadequate.
Definition: TObject2D.h:136
static constexpr unsigned char GEOMETRIC_TYPE_POINT
Object type identifier for TPoint2D or TPoint3D.
Definition: TPoseOrPoint.h:110
Standard object for storing any 3D lightweight object.
Definition: TObject3D.h:25
bool getSegment(TSegment2D &s) const
Gets the content as a segment, returning false if the type is inadequate.
Definition: TObject2D.h:123
static void getSegments(const std::vector< TObject2D > &objs, std::vector< TSegment2D > &sgms)
Static method to retrieve all the segments in a vector of TObject2D.
Definition: TObject2D.cpp:51
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
Definition: TSegment2D.h:20
struct mrpt::math::TObject2D::tobject2d_data_t data
3D segment, consisting of two points.
Definition: TSegment3D.h:20
void generate3DObject(TObject3D &obj) const
Project into 3D space.
Definition: TObject2D.cpp:24
TPoint3D_< double > TPoint3D
Lightweight 3D point.
Definition: TPoint3D.h:268
unsigned char type
Object type identifier.
Definition: TObject2D.h:30
static constexpr unsigned char GEOMETRIC_TYPE_UNDEFINED
Object type identifier for empty TObject2D or TObject3D.
Definition: TPoseOrPoint.h:135
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
static void getPoints(const std::vector< TObject2D > &objs, std::vector< TPoint2D > &pnts)
Static method to retrieve all the points in a vector of TObject2D.
Definition: TObject2D.cpp:45
mrpt::vision::TStereoCalibResults out
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
Definition: math.cpp:626
static void getPolygons(const std::vector< TObject2D > &objs, std::vector< TPolygon2D > &polys)
Static method to retrieve all the polygons in a vector of TObject2D.
Definition: TObject2D.cpp:63
static constexpr unsigned char GEOMETRIC_TYPE_SEGMENT
Object type identifier for TSegment2D or TSegment3D.
Definition: TPoseOrPoint.h:115
static constexpr unsigned char GEOMETRIC_TYPE_LINE
Object type identifier for TLine2D or TLine3D.
Definition: TPoseOrPoint.h:120
2D polygon, inheriting from std::vector<TPoint2D>.
Definition: TPolygon2D.h:21
3D polygon, inheriting from std::vector<TPoint3D>
Definition: TPolygon3D.h:20
3D line, represented by a base point and a director vector.
Definition: TLine3D.h:19
2D line without bounds, represented by its equation .
Definition: TLine2D.h:19



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020