Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-pcl-viewer.cpp
1
2#include <visp3/core/vpConfig.h>
3
4// System include
5#include <iostream>
6
7#if defined(VISP_HAVE_PCL) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
8
9// ViSP include
10#include <visp3/core/vpIoTools.h>
11
13// Tutorial include
14#include "ClassUsingPclViewer.h"
16
18
22typedef enum DisplayMode
23{
24 BLOCKING = 0,
25 THREADED = 1,
26 BOTH = 2,
27 MODE_COUNT = 3
28} DisplayMode;
29
36std::string displayModeToString(const DisplayMode &mode)
37{
38 switch (mode) {
39 case BLOCKING:
40 return "blocking";
41 case THREADED:
42 return "threaded";
43 case BOTH:
44 return "both";
45 default:
46 break;
47 }
48 return "unknown";
49}
50
58DisplayMode displayModeFromString(const std::string &name)
59{
60 DisplayMode res = DisplayMode::MODE_COUNT;
61 bool wasFound = false;
62 std::string lowerCaseName = vpIoTools::toLowerCase(name);
63 for (unsigned int i = 0; i < DisplayMode::MODE_COUNT && !wasFound; i++) {
64 DisplayMode candidate = (DisplayMode)i;
65 if (lowerCaseName == displayModeToString(candidate)) {
66 res = candidate;
67 wasFound = true;
68 }
69 }
70 return res;
71}
72
81std::string getAvailableDisplayMode(const std::string &prefix = "< ", const std::string &sep = " , ", const std::string &suffix = " >")
82{
83 std::string modes(prefix);
84 for (unsigned int i = 0; i < DisplayMode::MODE_COUNT - 1; i++) {
85 DisplayMode candidate = (DisplayMode)i;
86 modes += displayModeToString(candidate) + sep;
87 }
88 DisplayMode candidate = (DisplayMode)(DisplayMode::MODE_COUNT - 1);
89 modes += displayModeToString(candidate) + suffix;
90 return modes;
91}
93
94int main(int argc, char *argv [])
95{
97 const double def_addedNoise = 0.; // Standard deviation of the noise added to the points.
98 const unsigned int def_order = 2; // Order of the polynomial surface used for the example.
99 const std::pair<double, double> def_xlim = std::pair<double, double>(-2.5, 2.5); // Min and max X-axis coordinates.
100 const std::pair<double, double> def_ylim = std::pair<double, double>(-2.5, 2.5); // Min and max Y-axis coordinates.
101 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.
102 const DisplayMode def_mode = DisplayMode::BLOCKING; // Display mode that should be used.
104
106 double opt_addedNoise = def_addedNoise;
107 unsigned int opt_order = def_order;
108 std::pair<double, double> opt_xlim = def_xlim;
109 std::pair<double, double> opt_ylim = def_ylim;
110 std::pair<unsigned int, unsigned int> opt_reso = def_reso;
111 DisplayMode opt_mode = def_mode;
112
113 for (int i = 1; i < argc; i++) {
114 if (std::string(argv[i]) == "--noise" && i + 1 < argc) {
115 opt_addedNoise = atof(argv[i + 1]);
116 i++;
117 }
118 else if (std::string(argv[i]) == "--order" && i + 1 < argc) {
119 opt_order = atoi(argv[i + 1]);
120 i++;
121 }
122 else if (std::string(argv[i]) == "--x-lim" && i + 2 < argc) {
123 opt_xlim.first = atof(argv[i + 1]);
124 opt_xlim.second = atof(argv[i + 2]);
125 i += 2;
126 }
127 else if (std::string(argv[i]) == "--y-lim" && i + 2 < argc) {
128 opt_ylim.first = atof(argv[i + 1]);
129 opt_ylim.second = atof(argv[i + 2]);
130 i += 2;
131 }
132 else if (std::string(argv[i]) == "--reso" && i + 2 < argc) {
133 opt_reso.first = atoi(argv[i + 1]);
134 opt_reso.second = atoi(argv[i + 2]);
135 i += 2;
136 }
137 else if (std::string(argv[i]) == "--display-mode" && i + 1 < argc) {
138 opt_mode = displayModeFromString(std::string(argv[i + 1]));
139 i++;
140 }
141 else if (std::string(argv[i]) == "--help" || std::string(argv[i]) == "-h") {
143 std::cout << "NAME" << std::endl;
144 std::cout << "\t" << argv[0] << " Test programm for the PCL-based point-cloud visualizer." << std::endl
145 << std::endl;
146 std::cout << "SYNOPSIS" << std::endl;
147 std::cout << "\t" << argv[0]
148 << "\t[--noise <stdev_noise>] (default: " + std::to_string(def_addedNoise) << ")\n"
149 << "\t[--order <surface-order>](default: " + std::to_string(def_order) << ")\n"
150 << "\t[--x-lim <xmin xmax>](default: [" + std::to_string(def_xlim.first) + ";" + std::to_string(def_xlim.second) << "])\n"
151 << "\t[--y-lim <ymin ymax>](default: [" + std::to_string(def_ylim.first) + ";" + std::to_string(def_ylim.second) << "])\n"
152 << "\t[--reso <x_resolution y_resolution>](default: [" + std::to_string(def_reso.first) + ";" + std::to_string(def_reso.second) << "])\n"
153 << "\t[--display-mode " << getAvailableDisplayMode() << "](default: " << displayModeToString(def_mode) << ")\n"
154 << "\t[--help] [-h]" << std::endl
155 << std::endl;
157 return EXIT_SUCCESS;
158 }
159 }
161
162 std::cout << "Parameters:" << std::endl;
163 std::cout << "\tSurface order: " << opt_order << std::endl;
164 std::cout << "\tX-axis limits: [" << opt_xlim.first << " ; " << opt_xlim.first << "]" << std::endl;
165 std::cout << "\tY-axis limits: [" << opt_ylim.first << " ; " << opt_ylim.first << "]" << std::endl;
166 std::cout << "\tGrid resolution: [" << opt_reso.first << " x " << opt_reso.first << "]" << std::endl;
167 std::cout << "\tNoise standard deviation: " << opt_addedNoise << std::endl;
168 std::cout << "\tDisplay mode: " << displayModeToString(opt_mode) << std::endl;
169
171 if (opt_mode == DisplayMode::BLOCKING || opt_mode == DisplayMode::BOTH) {
172 ClassUsingPclViewer demo(opt_xlim, opt_ylim, opt_reso);
173 demo.blockingMode(opt_addedNoise, opt_order);
174 }
176
178 if (opt_mode == DisplayMode::THREADED || opt_mode == DisplayMode::BOTH) {
179 ClassUsingPclViewer demo(opt_xlim, opt_ylim, opt_reso);
180 demo.threadedMode(opt_addedNoise, opt_order);
181 }
183
184 return 0;
185}
186#else
187
188int main()
189{
190 std::cout << "ViSP seems to have been compiled without PCL library." << std::endl;
191 std::cout << "Please install PCL library and recompile ViSP." << std::endl;
192 return EXIT_SUCCESS;
193}
194#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.