Visual Servoing Platform  version 3.6.1 under development (2024-07-27)
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 
68 class VISP_EXPORT vpPclViewer
69 {
70 public:
71  typedef typename pcl::PointXYZRGB pclPointXYZRGB;
72  typedef typename pcl::PointCloud<pclPointXYZRGB> pclPointCloudPointXYZRGB;
73  typedef typename pclPointCloudPointXYZRGB::Ptr pclPointCloudPointXYZRGBPtr;
74 
78  typedef struct legendParams
79  {
80  std::string m_text;
81  unsigned int m_posU;
82  unsigned int m_posV;
83  unsigned int m_size;
84  double m_rRatio;
85  double m_gRatio;
86  double m_bRatio;
87  }legendParams;
88 
100  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);
102 
108  void setNameWindow(const std::string &nameWindow);
109 
115  void setOutFolder(const std::string &outputFolder);
116 
122  void setIgnoreThreshold(const double &thresh);
123 
132  unsigned int addSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const std::string &name = "", const std::vector<unsigned char> &v_color = std::vector<unsigned char>());
133 
144  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>());
145 
153  void updateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const bool &hasToKeepColor = false);
154 
163  void updateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights, const bool &hasToKeepColor = false);
164 
168  void display();
169 
176  void refresh(const int &timeout = 100, const bool &waitForDrawing = true);
177 
181  void launchThread();
182 
186  void stopThread();
187 
188 protected:
196  void threadUpdateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id);
197 
205  void threadUpdateSurfaceOriginalColor(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id);
206 
215  void threadUpdateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights);
216 
225  void threadUpdateSurfaceOriginalColor(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights);
226 
227 
234  static void runThread(vpPclViewer *p_viewer);
235 
240  void loopThread();
241 
242  std::vector<pclPointCloudPointXYZRGB::Ptr> m_vPointClouds;
243  static pcl::visualization::PCLVisualizer::Ptr sp_viewer;
244  static std::vector<std::vector<double>> s_vhandler;
245  static int s_width;
246  static int s_height;
247  static int s_posU;
248  static int s_posV;
249  static double s_ignoreThresh;
250  std::vector<std::string> m_vmeshid;
251  std::vector<legendParams> m_vlegends;
252  std::vector<std::mutex *> m_vpmutex;
253  std::vector<vpColVector> m_vweights;
254  std::thread m_threadDisplay;
255  bool m_hasToRun;
256  std::string m_title;
258  std::string m_outFolder;
259 };
260 END_VISP_NAMESPACE
261 #endif // #if defined(VISP_HAVE_PCL)
262 #endif // _vpPclVisualizer_h_
Implementation of column vector and the associated operations.
Definition: vpColVector.h:191
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 >())
Add a surface to the list of point clouds known by the viewer. The points whose weights are below the...
static void runThread(vpPclViewer *p_viewer)
Internal method that is called by vpPclViewer::launchThread to launch the drawing thread.
void updateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights, const bool &hasToKeepColor=false)
Update the surface known by id by the viewer.
std::string m_title
Definition: vpPclViewer.h:256
void display()
Blocking-mode display of the viewer.
static int s_posV
Definition: vpPclViewer.h:248
void threadUpdateSurfaceOriginalColor(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights)
Method to update a point cloud known by the viewer when the drawing thread is running....
pcl::PointCloud< pclPointXYZRGB > pclPointCloudPointXYZRGB
Definition: vpPclViewer.h:72
static pcl::visualization::PCLVisualizer::Ptr sp_viewer
Definition: vpPclViewer.h:243
void loopThread()
The internal loop of the non-blocking drawing thread.
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)
Construct a new vpPclViewer object.
static double s_ignoreThresh
Definition: vpPclViewer.h:249
std::thread m_threadDisplay
Definition: vpPclViewer.h:254
void setOutFolder(const std::string &outputFolder)
Set the path to the output folder. If different from the empty string, the point clouds will be saved...
std::vector< std::mutex * > m_vpmutex
Definition: vpPclViewer.h:252
std::vector< std::string > m_vmeshid
Definition: vpPclViewer.h:250
std::vector< vpColVector > m_vweights
Definition: vpPclViewer.h:253
pcl::PointXYZRGB pclPointXYZRGB
Definition: vpPclViewer.h:71
void refresh(const int &timeout=100, const bool &waitForDrawing=true)
Refresh the display.
void launchThread()
Start the drawing thread that permits to have a non-blocking display.
void setNameWindow(const std::string &nameWindow)
Set the name of the PCL viewer window.
static std::vector< std::vector< double > > s_vhandler
Definition: vpPclViewer.h:244
bool m_hasToSavePCDs
Definition: vpPclViewer.h:257
static int s_width
Definition: vpPclViewer.h:245
pclPointCloudPointXYZRGB::Ptr pclPointCloudPointXYZRGBPtr
Definition: vpPclViewer.h:73
std::string m_outFolder
Definition: vpPclViewer.h:258
bool m_hasToRun
Definition: vpPclViewer.h:255
static int s_posU
Definition: vpPclViewer.h:247
void updateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const bool &hasToKeepColor=false)
Update the surface known by id by the viewer.
void threadUpdateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights)
Method to update a point cloud known by the viewer when the drawing thread is running....
unsigned int addSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const std::string &name="", const std::vector< unsigned char > &v_color=std::vector< unsigned char >())
Add a surface to the list of point clouds known by the viewer.
std::vector< legendParams > m_vlegends
Definition: vpPclViewer.h:251
void threadUpdateSurfaceOriginalColor(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id)
Method to update a point cloud known by the viewer when the drawing thread is running....
static int s_height
Definition: vpPclViewer.h:246
void stopThread()
Stop the drawing thread that permits to have a non-blocking display.
void threadUpdateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id)
Method to update a point cloud known by the viewer when the drawing thread is running....
std::vector< pclPointCloudPointXYZRGB::Ptr > m_vPointClouds
Definition: vpPclViewer.h:242
void setIgnoreThreshold(const double &thresh)
Set the threshold below which a point must be displayed in black.
Structure that contains all the required parameters to display a legend on the viewer.
Definition: vpPclViewer.h:79