Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
tutorial-display-pcl.cpp
1
2#include <visp3/core/vpConfig.h>
3
4// System include
5#include <iostream>
6
7#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_VISUALIZATION)
8
9// ViSP include
10#include <visp3/core/vpIoTools.h>
11
13// Tutorial include
14#include "ClassUsingDisplayPCL.h"
16
17#ifdef ENABLE_VISP_NAMESPACE
18using namespace VISP_NAMESPACE_NAME;
19#endif
20
22
26typedef enum DisplayMode
27{
28 MONOTHREAD = 0,
29 THREADED = 1,
30 MODE_COUNT = 2
31} DisplayMode;
32
39std::string displayModeToString(const DisplayMode &mode)
40{
41 switch (mode) {
42 case MONOTHREAD:
43 return "monothread";
44 case THREADED:
45 return "threaded";
46 default:
47 break;
48 }
49 return "unknown";
50}
51
59DisplayMode displayModeFromString(const std::string &name)
60{
61 DisplayMode res = DisplayMode::MODE_COUNT;
62 bool wasFound = false;
63 std::string lowerCaseName = vpIoTools::toLowerCase(name);
64 unsigned int i = 0;
65 while ((i < DisplayMode::MODE_COUNT) && (!wasFound)) {
66 DisplayMode candidate = (DisplayMode)i;
67 if (lowerCaseName == displayModeToString(candidate)) {
68 res = candidate;
69 wasFound = true;
70 }
71 ++i;
72 }
73 return res;
74}
75
84std::string getAvailableDisplayMode(const std::string &prefix = "< ", const std::string &sep = " , ", const std::string &suffix = " >")
85{
86 std::string modes(prefix);
87 for (unsigned int i = 0; i < DisplayMode::MODE_COUNT - 1; ++i) {
88 DisplayMode candidate = (DisplayMode)i;
89 modes += displayModeToString(candidate) + sep;
90 }
91 DisplayMode candidate = (DisplayMode)(DisplayMode::MODE_COUNT - 1);
92 modes += displayModeToString(candidate) + suffix;
93 return modes;
94}
96
97int main(int argc, char *argv[])
98{
100 const double def_addedNoise = 0.; // Standard deviation of the noise added to the points.
101 const unsigned int def_order = 2; // Order of the polynomial surface used for the example.
102 const std::pair<double, double> def_xlim = std::pair<double, double>(-2.5, 2.5); // Min and max X-axis coordinates.
103 const std::pair<double, double> def_ylim = std::pair<double, double>(-2.5, 2.5); // Min and max Y-axis coordinates.
104 const std::pair<unsigned int, unsigned int> def_reso = std::pair<unsigned int, unsigned int>(50, 50); // Number of points along the X-axis and Y-axis reciprocally.
105 const DisplayMode def_mode = DisplayMode::MONOTHREAD; // Display mode that should be used.
107
109 double opt_addedNoise = def_addedNoise;
110 unsigned int opt_order = def_order;
111 std::pair<double, double> opt_xlim = def_xlim;
112 std::pair<double, double> opt_ylim = def_ylim;
113 std::pair<unsigned int, unsigned int> opt_reso = def_reso;
114 DisplayMode opt_mode = def_mode;
115
116 for (int i = 1; i < argc; i++) {
117 if (std::string(argv[i]) == "--noise" && i + 1 < argc) {
118 opt_addedNoise = atof(argv[i + 1]);
119 i++;
120 }
121 else if (std::string(argv[i]) == "--order" && i + 1 < argc) {
122 opt_order = atoi(argv[i + 1]);
123 i++;
124 }
125 else if (std::string(argv[i]) == "--x-lim" && i + 2 < argc) {
126 opt_xlim.first = atof(argv[i + 1]);
127 opt_xlim.second = atof(argv[i + 2]);
128 i += 2;
129 }
130 else if (std::string(argv[i]) == "--y-lim" && i + 2 < argc) {
131 opt_ylim.first = atof(argv[i + 1]);
132 opt_ylim.second = atof(argv[i + 2]);
133 i += 2;
134 }
135 else if (std::string(argv[i]) == "--reso" && i + 2 < argc) {
136 opt_reso.first = atoi(argv[i + 1]);
137 opt_reso.second = atoi(argv[i + 2]);
138 i += 2;
139 }
140 else if (std::string(argv[i]) == "--display-mode" && i + 1 < argc) {
141 opt_mode = displayModeFromString(std::string(argv[i + 1]));
142 i++;
143 }
144 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
146 std::cout << "NAME" << std::endl;
147 std::cout << "\t" << argv[0] << " Test programm for the PCL-based point-cloud visualizer." << std::endl
148 << std::endl;
149 std::cout << "SYNOPSIS" << std::endl;
150 std::cout << "\t" << argv[0]
151 << "\t[--noise <stdev_noise>] (default: " + std::to_string(def_addedNoise) << ")\n"
152 << "\t[--order <surface-order>](default: " + std::to_string(def_order) << ")\n"
153 << "\t[--x-lim <xmin xmax>](default: [" + std::to_string(def_xlim.first) + ";" + std::to_string(def_xlim.second) << "])\n"
154 << "\t[--y-lim <ymin ymax>](default: [" + std::to_string(def_ylim.first) + ";" + std::to_string(def_ylim.second) << "])\n"
155 << "\t[--reso <x_resolution y_resolution>](default: [" + std::to_string(def_reso.first) + ";" + std::to_string(def_reso.second) << "])\n"
156 << "\t[--display-mode " << getAvailableDisplayMode() << "](default: " << displayModeToString(def_mode) << ")\n"
157 << "\t[--help] [-h]" << std::endl
158 << std::endl;
160 return EXIT_SUCCESS;
161 }
162 else {
163 std::cerr << "Option '" << argv[i] << "' is not known. Please run '" << argv[0] << " --help' to have the list of options." << std::endl;
164 return EXIT_FAILURE;
165 }
166 }
168
169 std::cout << "Parameters:" << std::endl;
170 std::cout << "\tSurface order: " << opt_order << std::endl;
171 std::cout << "\tX-axis limits: [" << opt_xlim.first << " ; " << opt_xlim.first << "]" << std::endl;
172 std::cout << "\tY-axis limits: [" << opt_ylim.first << " ; " << opt_ylim.first << "]" << std::endl;
173 std::cout << "\tGrid resolution: [" << opt_reso.first << " x " << opt_reso.first << "]" << std::endl;
174 std::cout << "\tNoise standard deviation: " << opt_addedNoise << std::endl;
175 std::cout << "\tDisplay mode: " << displayModeToString(opt_mode) << std::endl;
176
177 bool useMonothread;
178
179 if (opt_mode == DisplayMode::THREADED) {
180 useMonothread = false;
182 ClassUsingDisplayPCL demo(opt_xlim, opt_ylim, opt_reso);
183 demo.runDemo(opt_addedNoise, opt_order, useMonothread);
185 }
186
187 if (opt_mode == DisplayMode::MONOTHREAD) {
188 useMonothread = true;
190 ClassUsingDisplayPCL demo(opt_xlim, opt_ylim, opt_reso);
191 demo.runDemo(opt_addedNoise, opt_order, useMonothread);
193 }
194
195 return 0;
196}
197#else
198
199int main()
200{
201 std::cout << "ViSP seems to have been compiled without PCL visualization module." << std::endl;
202 std::cout << "Please install PCL visualization module and recompile ViSP." << std::endl;
203 return EXIT_SUCCESS;
204}
205#endif
static std::string toLowerCase(const std::string &input)
Return a lower-case version of the string input . Numbers and special characters stay the same.