Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpDisplayPCL.h
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2024 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 *
30 * Description:
31 * Display a point cloud using PCL library.
32 */
33
34#ifndef VP_DISPLAY_PCL_H
35#define VP_DISPLAY_PCL_H
36
37#include <visp3/core/vpConfig.h>
38
39#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_VISUALIZATION) && defined(VISP_HAVE_THREADS)
40
41#include <mutex>
42#include <thread>
43#include <string>
44
45#include <visp3/core/vpColor.h>
46
47#include <pcl/visualization/cloud_viewer.h>
48#include <pcl/visualization/pcl_visualizer.h>
49
96class VISP_EXPORT vpDisplayPCL
97{
98public:
99 vpDisplayPCL(int posx = 0, int posy = 0, const std::string &window_name = "");
100 vpDisplayPCL(unsigned int width, unsigned int height, int posx = 0, int posy = 0, const std::string &window_name = "");
102
103 void setVerbose(bool verbose);
104 void display(const bool &blocking = false);
105 void startThread(const bool &colorThread = false);
106 void startThread(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, const std::string &name = "", const vpColor &color = vpColor::red);
107 void startThread(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud);
108 void addPointCloud(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud, const std::string &name = "", const vpColor &color = vpColor::red);
109 void addPointCloud(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud);
110 void setPosition(int posx, int posy);
111 void setWindowName(const std::string &window_name);
112 void stop();
113private:
114 void run();
115 void runColor();
116 void createViewer();
117 void insertLegend(const size_t &id);
118
119#ifndef DOXYGEN_SHOULD_SKIP_THIS
123 typedef struct PointCloudHandling
124 {
125 bool m_do_init;
126 std::string m_name;
127 static unsigned int s_nb;
128
134 std::string createName()
135 {
136 std::stringstream ss;
137 ss << "Point cloud " << s_nb;
138 return ss.str();
139 }
140
147 void init(const std::string &name)
148 {
149 if (name.empty()) {
150 m_name = createName();
151 }
152 else {
153 m_name = name;
154 }
155 m_do_init = true;
156 ++s_nb;
157 }
158
163 void init()
164 {
165 init(createName());
166 }
167
172 PointCloudHandling()
173 {
174 init();
175 }
176
182 PointCloudHandling(const std::string &name)
183 {
184 init(name);
185 }
186 } PointCloudHandling;
187
188 typedef struct XYZPointCloudHandling : public PointCloudHandling
189 {
190 pcl::PointCloud<pcl::PointXYZ>::Ptr m_pcl;
191 vpColor m_color;
192
199 XYZPointCloudHandling(pcl::PointCloud<pcl::PointXYZ>::Ptr pcl, const vpColor &color)
200 : PointCloudHandling()
201 , m_pcl(pcl)
202 , m_color(color)
203 { }
204
212 XYZPointCloudHandling(pcl::PointCloud<pcl::PointXYZ>::Ptr pcl, const std::string &name, const vpColor &color)
213 : PointCloudHandling(name)
214 , m_pcl(pcl)
215 , m_color(color)
216 { }
217 } XYZPointCloudHandling;
218
222 typedef struct ColoredPointCloudHandling : public PointCloudHandling
223 {
224 pcl::PointCloud<pcl::PointXYZRGB>::Ptr m_pcl;
225
231 ColoredPointCloudHandling(pcl::PointCloud<pcl::PointXYZRGB>::Ptr pcl)
232 : PointCloudHandling()
233 , m_pcl(pcl)
234 { }
235
242 ColoredPointCloudHandling(pcl::PointCloud<pcl::PointXYZRGB>::Ptr pcl, const std::string &name)
243 : PointCloudHandling(name)
244 , m_pcl(pcl)
245 { }
246 } ColoredPointCloudHandling;
247#endif
248
249 bool m_stop;
250 bool m_thread_running;
251 bool m_verbose;
252 std::thread m_thread;
253 std::mutex m_mutex_vector;
254 std::vector<std::pair<std::mutex &, XYZPointCloudHandling>> mv_xyz_pcl;
255 std::vector<pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ>> mv_xyz_handlers;
256 std::vector<std::pair<std::mutex &, ColoredPointCloudHandling>> mv_colored_pcl;
257 std::vector<pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB>> mv_color_handlers;
258 unsigned int m_width;
259 unsigned int m_height;
260 int m_posx;
261 int m_posy;
262 std::string m_window_name;
263 pcl::visualization::PCLVisualizer::Ptr m_viewer;
264};
265END_VISP_NAMESPACE
266#endif
267
268#endif
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157
static const vpColor red
Definition vpColor.h:198
void setPosition(int posx, int posy)
void display(const bool &blocking=false)
Monothread display method.
void setWindowName(const std::string &window_name)
vpDisplayPCL(int posx=0, int posy=0, const std::string &window_name="")
void startThread(const bool &colorThread=false)
void setVerbose(bool verbose)
void addPointCloud(std::mutex &mutex, pcl::PointCloud< pcl::PointXYZ >::Ptr pointcloud, const std::string &name="", const vpColor &color=vpColor::red)
Insert a point cloud to display.