forked from MRPT/mrpt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
94 lines (78 loc) · 2.49 KB
/
test.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* +------------------------------------------------------------------------+
| Mobile Robot Programming Toolkit (MRPT) |
| https://www.mrpt.org/ |
| |
| Copyright (c) 2005-2019, Individual contributors, see AUTHORS file |
| See: https://www.mrpt.org/Authors - All rights reserved. |
| Released under BSD License. See: https://www.mrpt.org/License |
+------------------------------------------------------------------------+ */
#include <mrpt/gui/CDisplayWindow.h>
#include <mrpt/maps/COccupancyGridMap2D.h>
#include <mrpt/maps/CSimpleMap.h>
#include <mrpt/random.h>
#include <mrpt/system/filesystem.h>
#include <iostream>
using namespace mrpt;
using namespace mrpt::maps;
using namespace mrpt::random;
using namespace mrpt::gui;
using namespace mrpt::math;
using namespace mrpt::img;
using namespace std;
#include <mrpt/examples_config.h>
const string sample_simplemap_file =
MRPT_EXAMPLES_BASE_DIRECTORY +
string("../share/mrpt/datasets/localization_demo.simplemap.gz");
// ------------------------------------------------------
// TestVoronoi
// ------------------------------------------------------
void TestVoronoi()
{
if (!mrpt::system::fileExists(sample_simplemap_file))
{
cerr << "Error: file doesn't exist: " << sample_simplemap_file << endl;
return;
}
// Load simplemap:
cout << "Loading simplemap: " << sample_simplemap_file << endl;
CSimpleMap simplemap;
simplemap.loadFromFile(sample_simplemap_file);
// Load a grid map:
cout << "Building gridmap...\n";
COccupancyGridMap2D gridmap(-5, 5, -5, 5, 0.10f);
gridmap.loadFromSimpleMap(simplemap);
// Build voronoi:
cout << "Building Voronoi diagram...\n";
gridmap.buildVoronoiDiagram(0.5f, 0.3f);
// Show results:
CImage img_grid;
gridmap.getAsImage(img_grid);
CImage img_voronoi;
CMatrixDouble mat_voronoi;
gridmap.getVoronoiDiagram().getAsMatrix(mat_voronoi);
img_voronoi.setFromMatrix(mat_voronoi, false /* do normalization */);
// Show results:
CDisplayWindow win1("Grid map");
win1.showImage(img_grid);
CDisplayWindow win2("Voronoi map");
win2.showImage(img_voronoi);
mrpt::system::pause();
}
int main(int argc, char** argv)
{
try
{
TestVoronoi();
return 0;
}
catch (exception& e)
{
cout << "MRPT exception caught: " << e.what() << endl;
return -1;
}
catch (...)
{
printf("Another exception!!");
return -1;
}
}