MRPT  1.9.9
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-2019, 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 
12 #include <mrpt/maps/CSimpleMap.h>
13 #include <mrpt/random.h>
14 #include <mrpt/system/filesystem.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 }
A namespace of pseudo-random numbers generators of diferent distributions.
This class stores a sequence of <Probabilistic Pose,SensoryFrame> pairs, thus a "metric map" can be t...
Definition: CSimpleMap.h:32
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:128
STL namespace.
bool loadFromFile(const std::string &filName)
Load the contents of this object from a .simplemap binary file (possibly compressed with gzip) ...
Definition: CSimpleMap.cpp:297
This base provides a set of functions for maths stuff.
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
void setFromMatrix(const MAT &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:827
GLsizei const GLchar ** string
Definition: glext.h:4116
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:432
A class for storing an occupancy grid map.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Classes for creating GUI windows for 2D and 3D visualization.
Definition: about_box.h:14
const string sample_simplemap_file
void TestVoronoi()
A class for storing images as grayscale or RGB bitmaps.
Definition: img/CImage.h:147



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019