MRPT  2.0.1
TObject3D.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/TObject2D.h>
13 #include <mrpt/math/TObject3D.h>
14 #include <mrpt/math/TPoint2D.h>
15 #include <mrpt/math/TPolygon3D.h>
16 #include <mrpt/math/TSegment2D.h>
18 #include <mrpt/serialization/stl_serialization.h> // >> of TPolygon3D
19 
20 using namespace mrpt::math;
21 
23 {
24  switch (type)
25  {
27  obj = TPoint2D(data.point);
28  break;
30  obj = TSegment2D(data.segment);
31  break;
33  obj = TLine2D(data.line);
34  break;
36  obj = TPolygon2D(*(data.polygon));
37  break;
39  throw std::logic_error("Too many dimensions");
40  default:
41  obj = TObject2D();
42  break;
43  }
44 }
45 
47  const std::vector<TObject3D>& objs, std::vector<TPoint3D>& pnts)
48 {
49  for (const auto& obj : objs)
50  if (obj.isPoint()) pnts.push_back(obj.data.point);
51 }
53  const std::vector<TObject3D>& objs, std::vector<TSegment3D>& sgms)
54 {
55  for (const auto& obj : objs)
56  if (obj.isSegment()) sgms.push_back(obj.data.segment);
57 }
59  const std::vector<TObject3D>& objs, std::vector<TLine3D>& lins)
60 {
61  for (const auto& obj : objs)
62  if (obj.isLine()) lins.push_back(obj.data.line);
63 }
65  const std::vector<TObject3D>& objs, std::vector<TPlane>& plns)
66 {
67  for (const auto& obj : objs)
68  if (obj.isPlane()) plns.push_back(obj.data.plane);
69 }
71  const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys)
72 {
73  for (const auto& obj : objs)
74  if (obj.isPolygon()) polys.push_back(*(obj.data.polygon));
75 }
77  const std::vector<TObject3D>& objs, std::vector<TPoint3D>& pnts,
78  std::vector<TObject3D>& remainder)
79 {
80  for (const auto& obj : objs)
81  if (obj.isPoint())
82  pnts.push_back(obj.data.point);
83  else
84  remainder.push_back(obj);
85 }
87  const std::vector<TObject3D>& objs, std::vector<TSegment3D>& sgms,
88  std::vector<TObject3D>& remainder)
89 {
90  for (const auto& obj : objs)
91  if (obj.isSegment())
92  sgms.push_back(obj.data.segment);
93  else
94  remainder.push_back(obj);
95 }
97  const std::vector<TObject3D>& objs, std::vector<TLine3D>& lins,
98  std::vector<TObject3D>& remainder)
99 {
100  for (const auto& obj : objs)
101  if (obj.isLine())
102  lins.push_back(obj.data.line);
103  else
104  remainder.push_back(obj);
105 }
107  const std::vector<TObject3D>& objs, std::vector<TPlane>& plns,
108  std::vector<TObject3D>& remainder)
109 {
110  for (const auto& obj : objs)
111  if (obj.isPlane())
112  plns.push_back(obj.data.plane);
113  else
114  remainder.push_back(obj);
115 }
117  const std::vector<TObject3D>& objs, std::vector<TPolygon3D>& polys,
118  std::vector<TObject3D>& remainder)
119 {
120  for (const auto& obj : objs)
121  if (obj.isPolygon())
122  polys.push_back(*(obj.data.polygon));
123  else
124  remainder.push_back(obj);
125 }
126 
129 {
130  uint16_t type;
131  in >> type;
132  switch (static_cast<unsigned char>(type))
133  {
135  {
136  TPoint3D p;
137  in >> p;
138  o = p;
139  }
140  break;
142  {
143  TSegment3D s;
144  in >> s;
145  o = s;
146  }
147  break;
148  case GEOMETRIC_TYPE_LINE:
149  {
150  TLine3D l;
151  in >> l;
152  o = l;
153  }
154  break;
156  {
157  TPlane p;
158  in >> p;
159  o = p;
160  }
161  break;
163  {
164  TPolygon3D p;
165  in >> p;
166  o = p;
167  }
168  break;
170  {
171  o = TObject3D();
172  }
173  break;
174  default:
175  throw std::logic_error(
176  "Unknown TObject3D type found while reading stream");
177  }
178  return in;
179 }
180 
183 {
184  out.WriteAs<uint16_t>(o.getType());
185  switch (o.getType())
186  {
188  {
189  TPoint3D p;
190  o.getPoint(p);
191  return out << p;
192  };
194  {
195  TSegment3D s;
196  o.getSegment(s);
197  return out << s;
198  };
199  case GEOMETRIC_TYPE_LINE:
200  {
201  TLine3D l;
202  o.getLine(l);
203  return out << l;
204  };
206  {
207  TPlane p;
208  o.getPlane(p);
209  return out << p;
210  };
212  {
213  TPolygon3D p;
214  o.getPolygon(p);
215  return out << p;
216  };
217  }
218  return out;
219 }
static void getPolygons(const std::vector< TObject3D > &objs, std::vector< TPolygon3D > &polys)
Static method to retrieve every polygon included in a vector of objects.
Definition: TObject3D.cpp:70
TPoint2D_< double > TPoint2D
Lightweight 2D point.
Definition: TPoint2D.h:213
static constexpr unsigned char GEOMETRIC_TYPE_POLYGON
Object type identifier for TPolygon2D or TPolygon3D.
Definition: TPoseOrPoint.h:125
bool getSegment(TSegment3D &s) const
Gets the content as a segment, returning false if the type is not adequate.
Definition: TObject3D.h:134
static void getLines(const std::vector< TObject3D > &objs, std::vector< TLine3D > &lins)
Static method to retrieve every line included in a vector of objects.
Definition: TObject3D.cpp:58
static void getPlanes(const std::vector< TObject3D > &objs, std::vector< TPlane > &plns)
Static method to retrieve every plane included in a vector of objects.
Definition: TObject3D.cpp:64
Standard type for storing any lightweight 2D type.
Definition: TObject2D.h:24
static constexpr unsigned char GEOMETRIC_TYPE_POINT
Object type identifier for TPoint2D or TPoint3D.
Definition: TPoseOrPoint.h:110
bool getPlane(TPlane &p) const
Gets the content as a plane, returning false if the type is not adequate.
Definition: TObject3D.h:175
Standard object for storing any 3D lightweight object.
Definition: TObject3D.h:25
void generate2DObject(TObject2D &obj) const
Projects into 2D space.
Definition: TObject3D.cpp:22
mrpt::serialization::CArchive & operator>>(mrpt::serialization::CArchive &in, CMatrixD::Ptr &pObj)
static constexpr unsigned char GEOMETRIC_TYPE_PLANE
Object type identifier for TPlane.
Definition: TPoseOrPoint.h:130
bool getPolygon(TPolygon3D &p) const
Gets the content as a polygon, returning false if the type is not adequate.
Definition: TObject3D.h:161
This base provides a set of functions for maths stuff.
2D segment, consisting of two points.
Definition: TSegment2D.h:20
3D segment, consisting of two points.
Definition: TSegment3D.h:20
3D Plane, represented by its equation
Definition: TPlane.h:22
static constexpr unsigned char GEOMETRIC_TYPE_UNDEFINED
Object type identifier for empty TObject2D or TObject3D.
Definition: TPoseOrPoint.h:135
bool getPoint(TPoint3D &p) const
Gets the content as a point, returning false if the type is not adequate.
Definition: TObject3D.h:120
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:54
mrpt::vision::TStereoCalibResults out
mrpt::serialization::CArchive & operator<<(mrpt::serialization::CArchive &s, const CVectorFloat &a)
Definition: math.cpp:626
unsigned char type
Object type identifier.
Definition: TObject3D.h:31
struct mrpt::math::TObject3D::tobject3d_data_t data
bool getLine(TLine3D &r) const
Gets the content as a line, returning false if the type is not adequate.
Definition: TObject3D.h:147
static void getPoints(const std::vector< TObject3D > &objs, std::vector< TPoint3D > &pnts)
Static method to retrieve every point included in a vector of objects.
Definition: TObject3D.cpp:46
unsigned char getType() const
Gets object type.
Definition: TObject3D.h:115
static constexpr unsigned char GEOMETRIC_TYPE_SEGMENT
Object type identifier for TSegment2D or TSegment3D.
Definition: TPoseOrPoint.h:115
static void getSegments(const std::vector< TObject3D > &objs, std::vector< TSegment3D > &sgms)
Static method to retrieve every segment included in a vector of objects.
Definition: TObject3D.cpp:52
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 2.0.1 Git: 0fef1a6d7 Fri Apr 3 23:00:21 2020 +0200 at vie abr 3 23:20:28 CEST 2020