MRPT  1.9.9
test.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-2018, 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 <mrpt/poses/CPosePDFSOG.h>
14 #include <mrpt/system/os.h>
16 #include <iostream>
17 
18 using namespace mrpt;
19 using namespace mrpt::poses;
20 using namespace mrpt::opengl;
21 using namespace mrpt::gui;
22 using namespace mrpt::io;
23 using namespace mrpt::system;
24 using namespace mrpt::serialization;
25 using namespace std;
26 
27 /* ------------------------------------------------------------------------
28  Test_SoG_Merge
29  ------------------------------------------------------------------------ */
30 void Test_SoG_Merge()
31 {
32  CPosePDFSOG pdf;
33 
35  m.mean = CPose2D(1.1, -0.1, DEG2RAD(-2));
36 
37  m.cov.unit();
38  m.cov(0, 0) = m.cov(1, 1) = square(0.1);
39  m.cov(2, 2) = square(DEG2RAD(2));
40  m.log_w = 0;
41 
42  pdf.clear();
43  pdf.push_back(m);
44 
45  m.mean = CPose2D(1.1, 0.1, DEG2RAD(2));
46  pdf.push_back(m);
47 
48  m.mean = CPose2D(2, 0, DEG2RAD(20));
49  pdf.push_back(m);
50 
51  cout << "Initial PDF: mean: " << pdf.getMeanVal() << endl;
52  cout << pdf.getCovariance() << endl << endl;
53 
54 #if MRPT_HAS_WXWIDGETS
55  CDisplayWindow3D win_before("Before merge");
56  CDisplayWindow3D win_after("After merge");
57 #endif
58 
59  {
60  COpenGLScene scene;
61  CSetOfObjects::Ptr o = mrpt::make_aligned_shared<CSetOfObjects>();
62  pdf.getAs3DObject(o);
63  scene.insert(o);
64  scene.insert(
65  mrpt::make_aligned_shared<CGridPlaneXY>(-5, 5, -5, 5, 0, 1));
66 
67  CFileGZOutputStream f("sog_before.3Dscene");
68  archiveFrom(f) << scene;
69 
70 #if MRPT_HAS_WXWIDGETS
71  COpenGLScene::Ptr sc = win_before.get3DSceneAndLock();
72  *sc = scene;
73  win_before.unlockAccess3DScene();
74  win_before.setCameraZoom(5);
75  win_before.setCameraPointingToPoint(1, 0, 0);
76  win_before.forceRepaint();
77 #endif
78  }
79 
80  cout << "Merging...";
81  pdf.mergeModes(0.9, true);
82  cout << " # modes after: " << pdf.size() << endl;
83 
84  cout << "Final PDF: mean: " << pdf.getMeanVal() << endl;
85  cout << pdf.getCovariance() << endl << endl;
86 
87  {
88  COpenGLScene scene;
89  CSetOfObjects::Ptr o = mrpt::make_aligned_shared<CSetOfObjects>();
90  pdf.getAs3DObject(o);
91  scene.insert(o);
92  scene.insert(
93  mrpt::make_aligned_shared<CGridPlaneXY>(-5, 5, -5, 5, 0, 1));
94 
95  CFileGZOutputStream f("sog_after.3Dscene");
96  archiveFrom(f) << scene;
97 
98 #if MRPT_HAS_WXWIDGETS
99  COpenGLScene::Ptr sc = win_after.get3DSceneAndLock();
100  *sc = scene;
101  win_after.unlockAccess3DScene();
102  win_after.setCameraZoom(5);
103  win_after.setCameraPointingToPoint(1, 0, 0);
104  win_after.forceRepaint();
105 #endif
106  }
107 
108 #if MRPT_HAS_WXWIDGETS
109  cout << "Push any key to exit..." << endl;
111 #endif
112 }
113 
114 // ------------------------------------------------------
115 // MAIN
116 // ------------------------------------------------------
117 int main(int argc, char** argv)
118 {
119  try
120  {
121  Test_SoG_Merge();
122 
123  return 0;
124  }
125  catch (std::exception& e)
126  {
127  std::cout << "Exception: " << e.what() << std::endl;
128  return -1;
129  }
130  catch (...)
131  {
132  printf("Untyped exception!");
133  return -1;
134  }
135 }
void clear()
Clear the list of modes.
Definition: CPosePDFSOG.cpp:39
void mergeModes(double max_KLd=0.5, bool verbose=false)
Merge very close modes so the overall number of modes is reduced while preserving the total distribut...
The struct for each mode:
Definition: CPosePDFSOG.h:42
int getch() noexcept
An OS-independent version of getch, which waits until a key is pushed.
Definition: os.cpp:370
Declares a class that represents a Probability Density function (PDF) of a 2D pose ...
Definition: CPosePDFSOG.h:35
double DEG2RAD(const double x)
Degrees to radians.
STL namespace.
void getCovariance(mrpt::math::CMatrixDouble &cov) const
Returns the estimate of the covariance matrix (STATE_LEN x STATE_LEN covariance matrix) ...
TDATA getMeanVal() const
Returns the mean, or mathematical expectation of the probability density distribution (PDF)...
void push_back(const TGaussianMode &m)
Inserts a copy of the given mode into the SOG.
Definition: CPosePDFSOG.h:118
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT&#39;s CStream, std::istream, std::ostream, std::stringstream
Definition: CArchive.h:555
T square(const T x)
Inline function for the square of a number.
mrpt::math::CMatrixDouble33 cov
Definition: CPosePDFSOG.h:46
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle...
Definition: CPose2D.h:38
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives...
Definition: COpenGLScene.h:59
void getAs3DObject(OPENGL_SETOFOBJECTSPTR &out_obj) const
Returns a 3D representation of this PDF (it doesn&#39;t clear the current contents of out_obj...
Definition: CPosePDF.h:114
void Test_SoG_Merge()
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
size_t size() const
Return the number of Gaussian modes.
Definition: CPosePDFSOG.h:85
Saves data to a file and transparently compress the data using the given compression level...
void insert(const CRenderizable::Ptr &newObject, const std::string &viewportName=std::string("main"))
Insert a new object into the scene, in the given viewport (by default, into the "main" viewport)...
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020