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/system/filesystem.h>
11 #include <mrpt/maps/CSimpleMap.h>
14 #include <mrpt/random.h>
15 #include <iostream>
16 
17 using namespace mrpt;
18 using namespace mrpt::maps;
19 using namespace mrpt::random;
20 using namespace mrpt::gui;
21 using namespace mrpt::math;
22 using namespace mrpt::img;
23 using namespace std;
24 
25 #include <mrpt/examples_config.h>
26 const string sample_simplemap_file =
27  MRPT_EXAMPLES_BASE_DIRECTORY +
28  string("../share/mrpt/datasets/localization_demo.simplemap.gz");
29 
30 // ------------------------------------------------------
31 // TestVoronoi
32 // ------------------------------------------------------
33 void TestVoronoi()
34 {
36  {
37  cerr << "Error: file doesn't exist: " << sample_simplemap_file << endl;
38  return;
39  }
40 
41  // Load simplemap:
42  cout << "Loading simplemap: " << sample_simplemap_file << endl;
43 
44  CSimpleMap simplemap;
46 
47  // Load a grid map:
48  cout << "Building gridmap...\n";
49 
50  COccupancyGridMap2D gridmap(-5, 5, -5, 5, 0.10f);
51  gridmap.loadFromSimpleMap(simplemap);
52 
53  // Build voronoi:
54  cout << "Building Voronoi diagram...\n";
55 
56  gridmap.buildVoronoiDiagram(0.5f, 0.3f);
57 
58  // Show results:
59  CImage img_grid;
60  gridmap.getAsImage(img_grid);
61 
62  CImage img_voronoi;
63  CMatrixDouble mat_voronoi;
64  gridmap.getVoronoiDiagram().getAsMatrix(mat_voronoi);
65  img_voronoi.setFromMatrix(mat_voronoi, false /* do normalization */);
66 
67  // Show results:
68  CDisplayWindow win1("Grid map");
69  win1.showImage(img_grid);
70 
71  CDisplayWindow win2("Voronoi map");
72  win2.showImage(img_voronoi);
73 
75 }
76 
77 int main(int argc, char** argv)
78 {
79  try
80  {
81  TestVoronoi();
82  return 0;
83  }
84  catch (exception& e)
85  {
86  cout << "MRPT exception caught: " << e.what() << endl;
87  return -1;
88  }
89  catch (...)
90  {
91  printf("Another exception!!");
92  return -1;
93  }
94 }
filesystem.h
COccupancyGridMap2D.h
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::maps::CSimpleMap::loadFromFile
bool loadFromFile(const std::string &filName)
Load the contents of this object from a .simplemap binary file (possibly compressed with gzip)
Definition: CSimpleMap.cpp:290
mrpt::system::fileExists
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:127
mrpt::img::CImage::setFromMatrix
void setFromMatrix(const Eigen::MatrixBase< Derived > &m, bool matrix_is_normalized=true)
Set the image from a matrix, interpreted as grayscale intensity values, in the range [0,...
Definition: img/CImage.h:891
random.h
mrpt::math::CMatrixTemplateNumeric< double >
main
int main()
Definition: vision_stereo_rectify/test.cpp:78
mrpt::img
Definition: CCanvas.h:17
mrpt::gui::CDisplayWindow
This class creates a window as a graphical user interface (GUI) for displaying images to the user.
Definition: CDisplayWindow.h:30
mrpt::gui
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:16
mrpt::img::CImage
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:130
mrpt::maps::CSimpleMap
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
Definition: CSimpleMap.h:35
mrpt::math
This base provides a set of functions for maths stuff.
Definition: math/include/mrpt/math/bits_math.h:13
mrpt::maps::COccupancyGridMap2D
A class for storing an occupancy grid map.
Definition: COccupancyGridMap2D.h:62
string
GLsizei const GLchar ** string
Definition: glext.h:4101
sample_simplemap_file
const string sample_simplemap_file
Definition: vision_stereo_rectify/test.cpp:26
TestVoronoi
void TestVoronoi()
Definition: vision_stereo_rectify/test.cpp:33
mrpt::random
A namespace of pseudo-random numbers generators of diferent distributions.
Definition: random_shuffle.h:17
mrpt::maps
Definition: CBeacon.h:24
CSimpleMap.h
CDisplayWindow.h
mrpt::system::pause
void pause(const std::string &msg=std::string("Press any key to continue...")) noexcept
Shows the message "Press any key to continue" (or other custom message) to the current standard outpu...
Definition: os.cpp:428



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