Visual Servoing Platform  version 3.6.1 under development (2024-05-07)
vpPclViewer.h
1 /****************************************************************************
2  *
3  * ViSP, open source Visual Servoing Platform software.
4  * Copyright (C) 2005 - 2023 by Inria. All rights reserved.
5  *
6  * This software is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  * See the file LICENSE.txt at the root directory of this source
11  * distribution for additional information about the GNU GPL.
12  *
13  * For using ViSP with software that can not be combined with the GNU
14  * GPL, please contact Inria about acquiring a ViSP Professional
15  * Edition License.
16  *
17  * See https://visp.inria.fr for more information.
18  *
19  * This software was developed at:
20  * Inria Rennes - Bretagne Atlantique
21  * Campus Universitaire de Beaulieu
22  * 35042 Rennes Cedex
23  * France
24  *
25  * If you have questions regarding the use of this file, please contact
26  * Inria at visp@inria.fr
27  *
28  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
29  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
30  * Description:
31  * Real-time 3D point clouds plotter based on the PCL library.
32  *
33 *****************************************************************************/
34 
35 #ifndef _vpPclViewer_h_
36 #define _vpPclViewer_h_
37 
38 #include <visp3/core/vpConfig.h>
39 
40 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_VISUALIZATION) && defined(VISP_HAVE_THREADS)
41 // System
42 #include <thread>
43 #include <mutex>
44 
45 // ViSP
46 #include <visp3/core/vpColVector.h>
47 
48 // PCL
49 #include <pcl/visualization/pcl_visualizer.h>
50 
67 class VISP_EXPORT vpPclViewer
68 {
69 public:
70  typedef typename pcl::PointXYZRGB pclPointXYZRGB;
71  typedef typename pcl::PointCloud<pclPointXYZRGB> pclPointCloudPointXYZRGB;
72  typedef typename pclPointCloudPointXYZRGB::Ptr pclPointCloudPointXYZRGBPtr;
73 
77  typedef struct legendParams
78  {
79  std::string m_text;
80  unsigned int m_posU;
81  unsigned int m_posV;
82  unsigned int m_size;
83  double m_rRatio;
84  double m_gRatio;
85  double m_bRatio;
86  }legendParams;
87 
99  vpPclViewer(const std::string &title, const int &width = 640, const int &height = 480, const int &posU = 720, const int &posV = 560, const std::string &outFolder = std::string(), const double &ignoreThreshold = 0.95);
100  ~vpPclViewer();
101 
107  void setNameWindow(const std::string &nameWindow);
108 
114  void setOutFolder(const std::string &outputFolder);
115 
121  void setIgnoreThreshold(const double &thresh);
122 
131  unsigned int addSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const std::string &name = "", const std::vector<unsigned char> &v_color = std::vector<unsigned char>());
132 
143  unsigned int addSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const vpColVector &weights, const std::string &name = "", const std::vector<unsigned char> &v_color = std::vector<unsigned char>());
144 
152  void updateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const bool &hasToKeepColor = false);
153 
162  void updateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights, const bool &hasToKeepColor = false);
163 
167  void display();
168 
175  void refresh(const int &timeout = 100, const bool &waitForDrawing = true);
176 
180  void launchThread();
181 
185  void stopThread();
186 
187 protected:
195  void threadUpdateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id);
196 
204  void threadUpdateSurfaceOriginalColor(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id);
205 
214  void threadUpdateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights);
215 
224  void threadUpdateSurfaceOriginalColor(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights);
225 
226 
233  static void runThread(vpPclViewer *p_viewer);
234 
239  void loopThread();
240 
241  std::vector<pclPointCloudPointXYZRGB::Ptr> m_vPointClouds;
242  static pcl::visualization::PCLVisualizer::Ptr sp_viewer;
243  static std::vector<std::vector<double>> s_vhandler;
244  static int s_width;
245  static int s_height;
246  static int s_posU;
247  static int s_posV;
248  static double s_ignoreThresh;
249  std::vector<std::string> m_vmeshid;
250  std::vector<legendParams> m_vlegends;
251  std::vector<std::mutex *> m_vpmutex;
252  std::vector<vpColVector> m_vweights;
253  std::thread m_threadDisplay;
254  bool m_hasToRun;
255  std::string m_title;
256  bool m_hasToSavePCDs;
257  std::string m_outFolder;
258 };
259 #endif // #if defined(VISP_HAVE_PCL)
260 #endif // _vpPclVisualizer_h_
Implementation of column vector and the associated operations.
Definition: vpColVector.h:163
void display(vpImage< unsigned char > &I, const std::string &title)
Display a gray-scale image.