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 }
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:33
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
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
Definition: filesystem.cpp:127
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:290
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...
GLsizei const GLchar ** string
Definition: glext.h:4101
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
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:130



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020