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 
11 #include <mrpt/gui.h>
12 #include <mrpt/random.h>
15 #include <iostream>
16 
17 using namespace mrpt;
18 using namespace mrpt::maps;
19 using namespace mrpt::math;
20 using namespace mrpt::random;
21 using namespace std;
22 
23 // Example of custom connectivity pattern:
26 {
27  /** Implement the check of whether node i=(icx,icy) is connected with node
28  * j=(jcx,jcy).
29  * This visitor method will be called only for immediate neighbors.
30  * \return true if connected (and the "information" value should be also
31  * updated in out_edge_information), false otherwise.
32  */
33  bool getEdgeInformation(
34  /** The parent map on which we are running */
35  const CRandomFieldGridMap2D* parent,
36  /** (cx,cy) for node "i" */
37  size_t icx, size_t icy,
38  /** (cx,cy) for node "j" */
39  size_t jcx, size_t jcy,
40  /** Must output here the inverse of the variance of the constraint
41  edge. */
42  double& out_edge_information) override
43  {
44  out_edge_information = 1.0 / (1.0 + icx + icy);
45  return true;
46  }
47 };
48 
49 void Example_GMRF()
50 {
51  const double X_SIZE = 10.0;
52  const double Y_SIZE = 10.0;
53  const double RESOLUTION = 0.5;
54 
56  CRandomFieldGridMap2D::mrGMRF_SD /*map type*/, 0, X_SIZE, 0, Y_SIZE,
57  RESOLUTION /* resolution */
58  );
59 
63  gasmap.setMinLoggingLevel(mrpt::system::LVL_DEBUG);
64  gasmap.setCellsConnectivity(conn);
65  gasmap.clear(); // for the connectivity to be taken into account.
66 
68  mrpt::make_aligned_shared<mrpt::opengl::CPointCloud>();
69  gl_data->setPointSize(3.0f);
70 
71  for (int i = 0; i < 20; i++)
72  {
73  const double value = getRandomGenerator().drawUniform(0.01, 0.99);
74  const double x = getRandomGenerator().drawUniform(0.1, 0.95 * X_SIZE);
75  const double y = getRandomGenerator().drawUniform(0.1, 0.95 * Y_SIZE);
76 
77  printf(
78  "Observation: (x,y)=(%6.02f,%6.02f,) => value: %6.03f\n", x, y,
79  value);
80  gl_data->insertPoint(x, y, value);
81 
82  gasmap.insertIndividualReading(
83  value, TPoint2D(x, y), false /*dont update map now*/);
84  }
85 
86  // Update only once now:
87  gasmap.updateMapEstimation();
88 
89  // 3D view:
91  mrpt::make_aligned_shared<mrpt::opengl::CSetOfObjects>();
92  gasmap.getAs3DObject(glObj);
93 
94  mrpt::gui::CDisplayWindow3D win("Map", 640, 480);
95 
96  mrpt::opengl::COpenGLScene::Ptr& scene = win.get3DSceneAndLock();
97  scene->insert(mrpt::opengl::stock_objects::CornerXYZSimple(1.0f, 4.0f));
98  scene->insert(gl_data);
99  scene->insert(glObj);
100  win.unlockAccess3DScene();
101  win.repaint();
102 
103  win.waitForKey();
104 }
105 
106 int main(int argc, char** argv)
107 {
108  try
109  {
110  Example_GMRF();
111  return 0;
112  }
113  catch (exception& e)
114  {
115  cout << "MRPT exception caught: " << e.what() << endl;
116  return -1;
117  }
118  catch (...)
119  {
120  printf("Another exception!!");
121  return -1;
122  }
123 }
CGasConcentrationGridMap2D.h
Example_GMRF
void Example_GMRF()
Definition: vision_stereo_rectify/test.cpp:49
mrpt::maps::CRandomFieldGridMap2D::ConnectivityDescriptor::Ptr
std::shared_ptr< ConnectivityDescriptor > Ptr
Definition: CRandomFieldGridMap2D.h:341
mrpt::maps::CGasConcentrationGridMap2D
CGasConcentrationGridMap2D represents a PDF of gas concentrations over a 2D area.
Definition: CGasConcentrationGridMap2D.h:35
mrpt::maps::CRandomFieldGridMap2D::mrGMRF_SD
@ mrGMRF_SD
Gaussian Markov Random Field, squared differences prior weights between 4 neighboring cells (see disc...
Definition: CRandomFieldGridMap2D.h:197
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
CPointCloud.h
stock_objects.h
mrpt::opengl::stock_objects::CornerXYZSimple
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...
Definition: StockObjects.cpp:419
mrpt::opengl::CPointCloud::Ptr
std::shared_ptr< CPointCloud > Ptr
Definition: CPointCloud.h:50
random.h
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::random::CRandomGenerator::drawUniform
double drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm,...
Definition: RandomGenerators.h:111
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
mrpt::math::TPoint2D
Lightweight 2D point.
Definition: lightweight_geom_data.h:42
mrpt::opengl::CSetOfObjects::Ptr
std::shared_ptr< CSetOfObjects > Ptr
Definition: CSetOfObjects.h:30
mrpt::system::LVL_DEBUG
@ LVL_DEBUG
Definition: system/COutputLogger.h:30
mrpt::random::getRandomGenerator
CRandomGenerator & getRandomGenerator()
A static instance of a CRandomGenerator class, for use in single-thread applications.
Definition: RandomGenerator.cpp:19
MyConnectivityVisitor
Definition: vision_stereo_rectify/test.cpp:24
mrpt::maps::CRandomFieldGridMap2D
CRandomFieldGridMap2D represents a 2D grid map where each cell is associated one real-valued property...
Definition: CRandomFieldGridMap2D.h:152
value
GLsizei const GLfloat * value
Definition: glext.h:4117
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
gui.h
mrpt::maps::CRandomFieldGridMap2D::ConnectivityDescriptor
Base class for user-supplied objects capable of describing cells connectivity, used to build prior fa...
Definition: CRandomFieldGridMap2D.h:339
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< COpenGLScene > Ptr
Definition: COpenGLScene.h:61
mrpt::random
A namespace of pseudo-random numbers generators of diferent distributions.
Definition: random_shuffle.h:17
mrpt::maps
Definition: CBeacon.h:24
y
GLenum GLint GLint y
Definition: glext.h:3538
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117
x
GLenum GLint x
Definition: glext.h:3538



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