Main MRPT website > C++ reference for 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 }
os.h
mrpt::poses::CPosePDFSOG::clear
void clear()
Clear the list of modes.
Definition: CPosePDFSOG.cpp:39
mrpt::poses::CPosePDF::getAs3DObject
void getAs3DObject(OPENGL_SETOFOBJECTSPTR &out_obj) const
Returns a 3D representation of this PDF (it doesn't clear the current contents of out_obj,...
Definition: CPosePDF.h:116
mrpt::io
Definition: img/CImage.h:22
mrpt::opengl::COpenGLScene::insert
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).
Definition: COpenGLScene.cpp:178
CPosePDFSOG.h
mrpt::opengl::COpenGLScene
This class allows the user to create, load, save, and render 3D scenes using OpenGL primitives.
Definition: COpenGLScene.h:59
CFileGZOutputStream.h
mrpt::math::CProbabilityDensityFunction::getMeanVal
TDATA getMeanVal() const
Returns the mean, or mathematical expectation of the probability density distribution (PDF).
Definition: CProbabilityDensityFunction.h:69
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::poses::CPosePDFSOG::push_back
void push_back(const TGaussianMode &m)
Inserts a copy of the given mode into the SOG.
Definition: CPosePDFSOG.h:120
mrpt::square
T square(const T x)
Inline function for the square of a number.
Definition: core/include/mrpt/core/bits_math.h:18
mrpt::poses
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Definition: CHierarchicalMapMHPartition.h:25
mrpt::poses::CPosePDFSOG::TGaussianMode
The struct for each mode:
Definition: CPosePDFSOG.h:44
CDisplayWindow3D.h
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::poses::CPosePDFSOG::TGaussianMode::mean
CPose2D mean
Definition: CPosePDFSOG.h:47
mrpt::io::CFileGZOutputStream
Saves data to a file and transparently compress the data using the given compression level.
Definition: io/CFileGZOutputStream.h:26
mrpt::poses::CPose2D
A class used to store a 2D pose, including the 2D coordinate point and a heading (phi) angle.
Definition: CPose2D.h:40
mrpt::opengl::CSetOfObjects::Ptr
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:30
mrpt::serialization
Definition: aligned_serialization.h:14
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::poses::CPosePDFSOG::TGaussianMode::cov
mrpt::math::CMatrixDouble33 cov
Definition: CPosePDFSOG.h:48
mrpt::serialization::archiveFrom
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
Definition: CArchive.h:561
mrpt::poses::CPosePDFSOG::size
size_t size() const
Return the number of Gaussian modes.
Definition: CPosePDFSOG.h:87
mrpt::poses::CPosePDFSOG::mergeModes
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...
Definition: CPosePDFSOG.cpp:526
mrpt::system::os::getch
int getch() noexcept
An OS-independent version of getch, which waits until a key is pushed.
Definition: os.cpp:370
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:61
mrpt::math::CProbabilityDensityFunction::getCovariance
void getCovariance(mrpt::math::CMatrixDouble &cov) const
Returns the estimate of the covariance matrix (STATE_LEN x STATE_LEN covariance matrix)
Definition: CProbabilityDensityFunction.h:80
Test_SoG_Merge
void Test_SoG_Merge()
Definition: vision_stereo_rectify/test.cpp:30
CArchive.h
CGridPlaneXY.h
mrpt::opengl
The namespace for 3D scene representation and rendering.
Definition: CGlCanvasBase.h:15
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117
mrpt::system
This namespace provides a OS-independent interface to many useful functions: filenames manipulation,...
Definition: math_frwds.h:25
mrpt::poses::CPosePDFSOG
Declares a class that represents a Probability Density function (PDF) of a 2D pose .
Definition: CPosePDFSOG.h:37
mrpt::poses::CPosePDFSOG::TGaussianMode::log_w
double log_w
The log-weight.
Definition: CPosePDFSOG.h:52
mrpt::DEG2RAD
double DEG2RAD(const double x)
Degrees to radians.
Definition: core/include/mrpt/core/bits_math.h:42



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST