Main MRPT website > C++ reference for MRPT 1.9.9
pose_pdfs.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "opengl-precomp.h" // Precompiled header
11 
12 #include <mrpt/opengl/CEllipsoid.h>
17 
18 #include <mrpt/poses.h>
19 
20 using namespace mrpt;
21 using namespace mrpt::utils;
22 using namespace mrpt::math;
23 using namespace mrpt::opengl;
24 using namespace mrpt::poses;
25 
26 const double POSE_TAIL_LENGTH = 0.1;
27 const double POSE_TAIL_WIDTH = 3.0;
28 const double POSE_POINT_SIZE = 4.0;
29 const double POSE_AXIS_SCALE = 0.1;
30 
31 #define POSE_COLOR 0, 0, 1
32 #define POINT_COLOR 1, 0, 0
33 
34 /** Returns a representation of a the PDF - this is just an auxiliary function,
35  * it's more natural to call
36  * mrpt::poses::CPosePDF::getAs3DObject */
38 {
39  CSetOfObjects::Ptr outObj = mrpt::make_aligned_shared<CSetOfObjects>();
40 
41  if (IS_CLASS(&o, CPosePDFSOG))
42  {
43  const CPosePDFSOG* p = static_cast<const CPosePDFSOG*>(&o);
44 
46  mrpt::make_aligned_shared<opengl::CSetOfLines>();
47  lins->setColor(0, 0, 1, 0.6);
48  lins->setLineWidth(POSE_TAIL_WIDTH);
49 
50  for (CPosePDFSOG::const_iterator it = p->begin(); it != p->end(); ++it)
51  {
53  mrpt::make_aligned_shared<opengl::CEllipsoid>();
54 
55  ellip->setPose(CPose3D((it)->mean.x(), (it)->mean.y(), 0));
56  ellip->setCovMatrix((it)->cov, 2 /* x y */);
57  ellip->setColor(POSE_COLOR, 0.6);
58  ellip->setQuantiles(3);
59  ellip->enableDrawSolid3D(false);
60 
61  outObj->insert(ellip);
62 
63  lins->appendLine(
64  (it)->mean.x(), (it)->mean.y(), 0,
65  (it)->mean.x() + POSE_TAIL_LENGTH * cos((it)->mean.phi()),
66  (it)->mean.y() + POSE_TAIL_LENGTH * sin((it)->mean.phi()), 0);
67  }
68  outObj->insert(lins);
69  }
70  else if (IS_CLASS(&o, CPosePDFGaussian))
71  {
72  const CPosePDFGaussian* p = static_cast<const CPosePDFGaussian*>(&o);
73 
75  mrpt::make_aligned_shared<opengl::CSetOfLines>();
76  lins->setColor(POSE_COLOR, 0.6);
77  lins->setLineWidth(POSE_TAIL_WIDTH);
78 
80  mrpt::make_aligned_shared<opengl::CEllipsoid>();
81 
82  ellip->setPose(CPose3D(p->mean.x(), p->mean.y(), 0));
83  ellip->setCovMatrix(p->cov, 2 /* x y */);
84  ellip->setColor(POSE_COLOR, 0.6);
85 
86  ellip->setQuantiles(3);
87  ellip->enableDrawSolid3D(false);
88 
89  outObj->insert(ellip);
90 
91  lins->appendLine(
92  p->mean.x(), p->mean.y(), 0,
93  p->mean.x() + POSE_TAIL_LENGTH * cos(p->mean.phi()),
94  p->mean.y() + POSE_TAIL_LENGTH * sin(p->mean.phi()), 0);
95 
96  outObj->insert(lins);
97  }
98  else if (IS_CLASS(&o, CPosePDFParticles))
99  {
100  const CPosePDFParticles* p = static_cast<const CPosePDFParticles*>(&o);
101 
103  mrpt::make_aligned_shared<opengl::CPointCloud>();
104  pnts->setColor(POSE_COLOR, 0.6);
105  pnts->setPointSize(POSE_POINT_SIZE);
106 
108  mrpt::make_aligned_shared<opengl::CSetOfLines>();
109  lins->setColor(POSE_COLOR, 0.6);
110  lins->setLineWidth(POSE_TAIL_WIDTH);
111 
112  for (size_t i = 0; i < p->size(); ++i)
113  {
114  const mrpt::poses::CPose2D* po = p->m_particles[i].d.get();
115  pnts->insertPoint(po->x(), po->y(), 0);
116  lins->appendLine(
117  po->x(), po->y(), 0,
118  po->x() + POSE_TAIL_LENGTH * cos(po->phi()),
119  po->y() + POSE_TAIL_LENGTH * sin(po->phi()), 0);
120  }
121  outObj->insert(pnts);
122  outObj->insert(lins);
123  }
124 
125  return outObj;
126 }
127 
128 /** Returns a representation of a the PDF - this is just an auxiliary function,
129  * it's more natural to call
130  * mrpt::poses::CPointPDF::getAs3DObject */
132 {
133  CSetOfObjects::Ptr outObj = mrpt::make_aligned_shared<CSetOfObjects>();
134 
135  if (IS_CLASS(&o, CPointPDFSOG))
136  {
137  const CPointPDFSOG* p = static_cast<const CPointPDFSOG*>(&o);
138 
139  // For each gaussian node
141  it != p->end(); ++it)
142  {
144  mrpt::make_aligned_shared<opengl::CEllipsoid>();
145 
146  obj->setPose(it->val.mean);
147  obj->setCovMatrix(it->val.cov, it->val.cov(2, 2) == 0 ? 2 : 3);
148 
149  obj->setQuantiles(3);
150  obj->enableDrawSolid3D(false);
151  obj->setColor(POINT_COLOR);
152 
153  outObj->insert(obj);
154  } // end for each gaussian node
155  }
156  else if (IS_CLASS(&o, CPointPDFGaussian))
157  {
158  const CPointPDFGaussian* p = static_cast<const CPointPDFGaussian*>(&o);
159 
160  CEllipsoid::Ptr obj = mrpt::make_aligned_shared<CEllipsoid>();
161  obj->setLocation(p->mean);
162  obj->setCovMatrix(p->cov, p->cov(2, 2) == 0 ? 2 : 3);
163  obj->setColor(POINT_COLOR);
164  obj->setQuantiles(3);
165  obj->enableDrawSolid3D(false);
166  outObj->insert(obj);
167  }
168  else if (IS_CLASS(&o, CPointPDFParticles))
169  {
170  const CPointPDFParticles* p =
171  static_cast<const CPointPDFParticles*>(&o);
172 
174  mrpt::make_aligned_shared<mrpt::opengl::CPointCloud>();
175  const size_t N = p->size();
176 
177  obj->resize(N);
178  obj->setColor(POINT_COLOR);
179  for (size_t i = 0; i < N; i++)
180  obj->setPoint(
181  i, p->m_particles[i].d->x, p->m_particles[i].d->y,
182  p->m_particles[i].d->z);
183  outObj->insert(obj);
184  }
185 
186  return outObj;
187 }
188 
189 /** Returns a representation of a the PDF - this is just an auxiliary function,
190  * it's more natural to call
191  * mrpt::poses::CPose3DPDF::getAs3DObject */
193 {
194  CSetOfObjects::Ptr outObj = mrpt::make_aligned_shared<CSetOfObjects>();
195 
196  if (IS_CLASS(&o, CPose3DPDFSOG))
197  {
198  const CPose3DPDFSOG* p = static_cast<const CPose3DPDFSOG*>(&o);
199 
200  // For each gaussian node
201  for (CPose3DPDFSOG::const_iterator it = p->begin(); it != p->end();
202  ++it)
203  {
205  mrpt::make_aligned_shared<opengl::CEllipsoid>();
206 
207  obj->setPose(it->val.mean);
208  obj->setCovMatrix(
209  CMatrixDouble(it->val.cov), it->val.cov(2, 2) == 0 ? 2 : 3);
210 
211  obj->setQuantiles(3);
212  obj->enableDrawSolid3D(false);
213  obj->setColor(POSE_COLOR);
214 
215  outObj->insert(obj);
216 
219  axes->setPose(it->val.mean);
220  axes->setScale(POSE_AXIS_SCALE);
221  outObj->insert(axes);
222  } // end for each gaussian node
223  }
224  else if (IS_CLASS(&o, CPose3DPDFGaussian))
225  {
226  const CPose3DPDFGaussian* p =
227  static_cast<const CPose3DPDFGaussian*>(&o);
228 
230  mrpt::make_aligned_shared<opengl::CEllipsoid>();
231 
232  obj->setPose(p->mean);
233  obj->setCovMatrix(CMatrixDouble(p->cov), p->cov(2, 2) == 0 ? 2 : 3);
234 
235  obj->setQuantiles(3);
236  obj->enableDrawSolid3D(false);
237  obj->setColor(POSE_COLOR);
238 
239  outObj->insert(obj);
240 
242  axes->setPose(p->mean);
243  axes->setScale(POSE_AXIS_SCALE);
244  outObj->insert(axes);
245  }
246  else if (IS_CLASS(&o, CPose3DPDFParticles))
247  {
248  const CPose3DPDFParticles* p =
249  static_cast<const CPose3DPDFParticles*>(&o);
250 
251  for (size_t i = 0; i < p->size(); i++)
252  {
255  axes->setPose(*p->m_particles[i].d);
256  outObj->insert(axes);
257  }
258  }
259 
260  return outObj;
261 }
262 
263 /** Returns a representation of a the PDF - this is just an auxiliary function,
264  * it's more natural to call
265  * mrpt::poses::CPose3DQuatPDF::getAs3DObject */
267 {
268  CSetOfObjects::Ptr outObj = mrpt::make_aligned_shared<CSetOfObjects>();
269 
271  {
272  const CPose3DQuatPDFGaussian* p =
273  static_cast<const CPose3DQuatPDFGaussian*>(&o);
274 
276  mrpt::make_aligned_shared<opengl::CEllipsoid>();
277 
278  obj->setPose(CPose3D(p->mean));
279  obj->setCovMatrix(CMatrixDouble(p->cov), p->cov(2, 2) == 0 ? 2 : 3);
280 
281  obj->setQuantiles(3);
282  obj->enableDrawSolid3D(false);
283  obj->setColor(POSE_COLOR);
284 
285  outObj->insert(obj);
286 
288  axes->setPose(CPose3D(p->mean));
289  axes->setScale(POSE_AXIS_SCALE);
290  outObj->insert(axes);
291  }
292 
293  return outObj;
294 }
double x() const
Common members of all points & poses classes.
Definition: CPoseOrPoint.h:135
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
size_t size() const
Returns the number of particles.
const double POSE_TAIL_WIDTH
Definition: pose_pdfs.cpp:27
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
Definition: CPosePDFSOG.h:36
Declares a class that represents a Probability Density function (PDF) of a 3D point ...
Definition: CPointPDFSOG.h:36
Declares a class that represents a Probability Density function (PDF) of a 3D(6D) pose ...
Definition: CPose3DPDFSOG.h:35
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define POSE_COLOR
Definition: pose_pdfs.cpp:31
const double POSE_TAIL_LENGTH
Definition: pose_pdfs.cpp:26
GLsizei GLsizei GLuint * obj
Definition: glext.h:4070
Declares a class that represents a Probability Density function (PDF) of a 3D pose using a quaternion...
const double POSE_AXIS_SCALE
Definition: pose_pdfs.cpp:29
This base provides a set of functions for maths stuff.
Definition: CArrayNumeric.h:19
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
CMatrixTemplateNumeric< double > CMatrixDouble
Declares a matrix of double numbers (non serializable).
const double POSE_POINT_SIZE
Definition: pose_pdfs.cpp:28
TModesList::const_iterator const_iterator
Definition: CPose3DPDFSOG.h:53
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:32
Declares a class that represents a Probability Density Function (PDF) over a 2D pose (x...
Declares a class that represents a probability density function (pdf) of a 2D pose (x...
Definition: CPosePDF.h:41
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CPoint.h:17
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CSetOfObjects::Ptr posePDF2opengl(const POSE_PDF &o)
Returns a representation of a the PDF - this is just an auxiliary function, it&#39;s more natural to call...
Definition: pose_pdfs.h:24
#define POINT_COLOR
Definition: pose_pdfs.cpp:32
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:40
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
Definition: CPose3D.h:88
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
const double & phi() const
Get the phi angle of the 2D pose (in radians)
Definition: CPose2D.h:91
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
Definition: CObject.h:103
CSetOfObjects::Ptr CornerXYZSimple(float scale=1.0, float lineWidth=1.0)
Returns three arrows representing a X,Y,Z 3D corner (just thick lines instead of complex arrows for f...
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
Declares a class that represents a Probability Density function (PDF) of a 3D pose ...
std::shared_ptr< CSetOfLines > Ptr
Definition: CSetOfLines.h:37
Eigen::Matrix< typename MATRIX::Scalar, MATRIX::ColsAtCompileTime, MATRIX::ColsAtCompileTime > cov(const MATRIX &v)
Computes the covariance matrix from a list of samples in an NxM matrix, where each row is a sample...
Definition: ops_matrices.h:148
std::shared_ptr< CPointCloud > Ptr
Definition: CPointCloud.h:52
Declares a class that represents a Probability Distribution function (PDF) of a 3D point (x...
Definition: CPointPDF.h:39
GLfloat GLfloat p
Definition: glext.h:6305
A probability distribution of a 2D/3D point, represented as a set of random samples (particles)...
Declares a class that represents a Probability Density Function (PDF) of a 3D pose (6D actually)...
Definition: CPose3DPDF.h:42
CListGaussianModes::const_iterator const_iterator
Definition: CPosePDFSOG.h:69
EIGEN_STRONG_INLINE double mean() const
Computes the mean of the entire matrix.
A gaussian distribution for 3D points.
Declares a class that represents a Probability Density function (PDF) of a 3D pose.
std::shared_ptr< CEllipsoid > Ptr
Definition: CEllipsoid.h:49



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019