MRPT  2.0.4
test.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 <mrpt/gui.h>
14 #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 
60  auto conn =
63  gasmap.setMinLoggingLevel(mrpt::system::LVL_DEBUG);
64  gasmap.setCellsConnectivity(conn);
65  gasmap.clear(); // for the connectivity to be taken into account.
66 
67  auto gl_data = mrpt::opengl::CPointCloud::Create();
68  gl_data->setPointSize(3.0f);
69 
70  for (int i = 0; i < 20; i++)
71  {
72  const double value = getRandomGenerator().drawUniform(0.01, 0.99);
73  const double x = getRandomGenerator().drawUniform(0.1, 0.95 * X_SIZE);
74  const double y = getRandomGenerator().drawUniform(0.1, 0.95 * Y_SIZE);
75 
76  printf(
77  "Observation: (x,y)=(%6.02f,%6.02f,) => value: %6.03f\n", x, y,
78  value);
79  gl_data->insertPoint(x, y, value);
80 
81  gasmap.insertIndividualReading(
82  value, TPoint2D(x, y), false /*dont update map now*/);
83  }
84 
85  // Update only once now:
86  gasmap.updateMapEstimation();
87 
88  // 3D view:
90  gasmap.getAs3DObject(glObj);
91 
92  mrpt::gui::CDisplayWindow3D win("Map", 640, 480);
93 
94  mrpt::opengl::COpenGLScene::Ptr& scene = win.get3DSceneAndLock();
95  scene->insert(mrpt::opengl::stock_objects::CornerXYZSimple(1.0f, 4.0f));
96  scene->insert(gl_data);
97  scene->insert(glObj);
98  win.unlockAccess3DScene();
99  win.repaint();
100 
101  win.waitForKey();
102 }
103 
104 int main(int argc, char** argv)
105 {
106  try
107  {
108  Example_GMRF();
109  return 0;
110  }
111  catch (exception& e)
112  {
113  cout << "MRPT exception caught: " << e.what() << endl;
114  return -1;
115  }
116  catch (...)
117  {
118  printf("Another exception!!");
119  return -1;
120  }
121 }
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:32
mrpt::opengl::CSetOfObjects::Create
static Ptr Create(Args &&... args)
Definition: CSetOfObjects.h:28
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::opengl::CPointCloud::Create
static Ptr Create(Args &&... args)
Definition: CPointCloud.h:49
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: BaseAppDataSource.h:15
stock_objects.h
CPointCloud.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:343
random.h
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::random::CRandomGenerator::drawUniform
return_t drawUniform(const double Min, const double Max)
Generate a uniformly distributed pseudo-random number using the MT19937 algorithm,...
Definition: RandomGenerators.h:142
win
mrpt::gui::CDisplayWindow3D::Ptr win
Definition: vision_stereo_rectify/test.cpp:31
argv
const char * argv[]
Definition: RawlogGrabberApp_unittest.cpp:50
mrpt::opengl::COpenGLScene::Ptr
std::shared_ptr< mrpt::opengl ::COpenGLScene > Ptr
Definition: COpenGLScene.h:58
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:89
MyConnectivityVisitor
Definition: vision_stereo_rectify/test.cpp:24
argc
const int argc
Definition: RawlogGrabberApp_unittest.cpp:51
mrpt::maps::CRandomFieldGridMap2D
CRandomFieldGridMap2D represents a 2D grid map where each cell is associated one real-valued property...
Definition: CRandomFieldGridMap2D.h:152
mrpt::math::TPoint2D
TPoint2D_< double > TPoint2D
Lightweight 2D point.
Definition: TPoint2D.h:213
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:11
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::random
A namespace of pseudo-random numbers generators of diferent distributions.
Definition: random_shuffle.h:18
mrpt::maps
Definition: CBeacon.h:21
mrpt::gui::CDisplayWindow3D
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Definition: CDisplayWindow3D.h:117



Page generated by Doxygen 1.8.17 for MRPT 2.0.4 at Sun Jul 19 15:15:43 UTC 2020