Visual Servoing Platform  version 3.6.1 under development (2024-11-15)

#include <visp3/gui/vpPclViewer.h>

Classes

struct  legendParams
 

Public Types

typedef pcl::PointXYZRGB pclPointXYZRGB
 
typedef pcl::PointCloud< pclPointXYZRGBpclPointCloudPointXYZRGB
 
typedef pclPointCloudPointXYZRGB::Ptr pclPointCloudPointXYZRGBPtr
 
typedef struct vpPclViewer::legendParams legendParams
 

Public Member Functions

 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)
 
 ~vpPclViewer ()
 
void setNameWindow (const std::string &nameWindow)
 
void setOutFolder (const std::string &outputFolder)
 
void setIgnoreThreshold (const double &thresh)
 
unsigned int addSurface (const pclPointCloudPointXYZRGB::Ptr &surface, const std::string &name="", const std::vector< unsigned char > &v_color=std::vector< unsigned char >())
 
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 >())
 
void updateSurface (const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const bool &hasToKeepColor=false)
 
void updateSurface (const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights, const bool &hasToKeepColor=false)
 
void display ()
 
void refresh (const int &timeout=100, const bool &waitForDrawing=true)
 
void launchThread ()
 
void stopThread ()
 

Protected Member Functions

void threadUpdateSurface (const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id)
 
void threadUpdateSurfaceOriginalColor (const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id)
 
void threadUpdateSurface (const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights)
 
void threadUpdateSurfaceOriginalColor (const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const vpColVector &weights)
 
void loopThread ()
 

Static Protected Member Functions

static void runThread (vpPclViewer *p_viewer)
 

Protected Attributes

std::vector< pclPointCloudPointXYZRGB::Ptr > m_vPointClouds
 
std::vector< std::string > m_vmeshid
 
std::vector< legendParamsm_vlegends
 
std::vector< std::mutex * > m_vpmutex
 
std::vector< vpColVectorm_vweights
 
std::thread m_threadDisplay
 
bool m_hasToRun
 
std::string m_title
 
bool m_hasToSavePCDs
 
std::string m_outFolder
 

Static Protected Attributes

static pcl::visualization::PCLVisualizer::Ptr sp_viewer
 
static std::vector< std::vector< double > > s_vhandler
 
static int s_width
 
static int s_height
 
static int s_posU
 
static int s_posV
 
static double s_ignoreThresh
 

Detailed Description

This class enables real time plotting of 3D point clouds. It relies on the PCL library. To see how to install PCL library, please refer to the Point Cloud Library (PCL) section. You can either plot in a non-blocking threaded manner or in a blocking manner. The point clouds can be displayed using their original colors, or using uniform colors to match a legend. Additionally, it is possible to use confidence weights to hide points that are not trusted. These weights can result from a robust estimation using for instance the vpRobust class.

Warning
If you face some runtime errors with the following class, please refer to the Known issues section to see if it is a known problem.
See also
Tutorial: Threaded PCL viewer
Examples
ClassUsingPclViewer.h.

Definition at line 68 of file vpPclViewer.h.

Member Typedef Documentation

◆ legendParams

Structure that contains all the required parameters to display a legend on the viewer.

◆ pclPointCloudPointXYZRGB

Definition at line 72 of file vpPclViewer.h.

◆ pclPointCloudPointXYZRGBPtr

typedef pclPointCloudPointXYZRGB::Ptr vpPclViewer::pclPointCloudPointXYZRGBPtr

Definition at line 73 of file vpPclViewer.h.

◆ pclPointXYZRGB

typedef pcl::PointXYZRGB vpPclViewer::pclPointXYZRGB

Definition at line 71 of file vpPclViewer.h.

Constructor & Destructor Documentation

◆ vpPclViewer()

vpPclViewer::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.

Parameters
titleThe title of the window of the viewer.
widthThe width of the window of the viewer.
heightThe height of the window of the viewer.
posUThe position on the horizontal axis of the screen of the window of the viewer.
posVThe position on the vertical axis of the screen of the window of the viewer.
outFolderIf different from the empty string, the point clouds will be saved in this folder.
ignoreThresholdA point for which the weight is below this threshold will be displayed in black.

◆ ~vpPclViewer()

vpPclViewer::~vpPclViewer ( )

Member Function Documentation

◆ addSurface() [1/2]

unsigned int vpPclViewer::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.

Parameters
surfaceThe surface that must be knwon to be displayed by the PCL viewer.
nameThe name of the surface that will be displayed in the legend. If empty, it will be automatically generated.
v_colorA vector containing the 3 RGB values.
Returns
unsigned int The ID by which is known the point cloud by the viewer.
Examples
ClassUsingPclViewer.cpp.

Referenced by ClassUsingPclViewer::blockingMode(), and ClassUsingPclViewer::threadedMode().

◆ addSurface() [2/2]

unsigned int vpPclViewer::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 vpPclViewer::s_ignoreThresh wil be displayed in black.

Parameters
surfaceThe surface that must be knwon to be displayed by the PCL viewer.
weightsThe confidence weights of each points. Must be between 0 and 1.
nameThe name of the surface that will be displayed in the legend. If empty, it will be automatically generated.
v_colorA vector containing the 3 RGB values.
Returns
unsigned int The ID by which is known the point cloud by the viewer.

◆ display()

void vpPclViewer::display ( )

Blocking-mode display of the viewer.

Examples
ClassUsingPclViewer.cpp.

Referenced by ClassUsingPclViewer::blockingMode().

◆ launchThread()

void vpPclViewer::launchThread ( )

Start the drawing thread that permits to have a non-blocking display.

Examples
ClassUsingPclViewer.cpp.

Referenced by ClassUsingPclViewer::threadedMode().

◆ loopThread()

void vpPclViewer::loopThread ( )
protected

The internal loop of the non-blocking drawing thread.

◆ refresh()

void vpPclViewer::refresh ( const int &  timeout = 100,
const bool &  waitForDrawing = true 
)

Refresh the display.

Parameters
timeoutDuration allowed for the drawing.
waitForDrawingIf true, will wait until the drawing is done. Otherwise, might return without doing nothing.

◆ runThread()

static void vpPclViewer::runThread ( vpPclViewer p_viewer)
staticprotected

Internal method that is called by vpPclViewer::launchThread to launch the drawing thread.

Parameters
p_viewerThe pointer of the vpPclViewer object that will run the thread (is equal to this ).

◆ setIgnoreThreshold()

void vpPclViewer::setIgnoreThreshold ( const double &  thresh)

Set the threshold below which a point must be displayed in black.

Parameters
threshThe threshold below which a point must be displayed in black.

◆ setNameWindow()

void vpPclViewer::setNameWindow ( const std::string &  nameWindow)

Set the name of the PCL viewer window.

Parameters
nameWindowThe name of the PCL viewer window.

◆ setOutFolder()

void vpPclViewer::setOutFolder ( const std::string &  outputFolder)

Set the path to the output folder. If different from the empty string, the point clouds will be saved in this folder.

Parameters
outputFolderThe path towards to the output folder, or empty if the point clouds must not be saved.

◆ stopThread()

void vpPclViewer::stopThread ( )

Stop the drawing thread that permits to have a non-blocking display.

◆ threadUpdateSurface() [1/2]

void vpPclViewer::threadUpdateSurface ( const pclPointCloudPointXYZRGB::Ptr &  surface,
const unsigned int &  id 
)
protected

Method to update a point cloud known by the viewer when the drawing thread is running. The updated surface will be drawn with the default color that was affected to it.

Parameters
surfaceThe updated surface.
idThe ID of the point cloud that must be updated.

◆ threadUpdateSurface() [2/2]

void vpPclViewer::threadUpdateSurface ( const pclPointCloudPointXYZRGB::Ptr &  surface,
const unsigned int &  id,
const vpColVector weights 
)
protected

Method to update a point cloud known by the viewer when the drawing thread is running. The updated surface will be drawn with the default color that was affected to it.

Parameters
surfaceThe updated surface.
idThe ID of the point cloud that must be updated.
weightsThe confidence weights of each point. Must be between 0 and 1.

◆ threadUpdateSurfaceOriginalColor() [1/2]

void vpPclViewer::threadUpdateSurfaceOriginalColor ( const pclPointCloudPointXYZRGB::Ptr &  surface,
const unsigned int &  id 
)
protected

Method to update a point cloud known by the viewer when the drawing thread is running. The updated surface will be drawn with the color it contains.

Parameters
surfaceThe updated surface.
idThe ID of the point cloud that must be updated.

◆ threadUpdateSurfaceOriginalColor() [2/2]

void vpPclViewer::threadUpdateSurfaceOriginalColor ( const pclPointCloudPointXYZRGB::Ptr &  surface,
const unsigned int &  id,
const vpColVector weights 
)
protected

Method to update a point cloud known by the viewer when the drawing thread is running. The updated surface will be drawn with the color it contains.

Parameters
surfaceThe updated surface.
idThe ID of the point cloud that must be updated.
weightsThe confidence weights of each point. Must be between 0 and 1.

◆ updateSurface() [1/2]

void vpPclViewer::updateSurface ( const pclPointCloudPointXYZRGB::Ptr &  surface,
const unsigned int &  id,
const bool &  hasToKeepColor = false 
)

Update the surface known by id by the viewer.

Parameters
surfaceThe updated surface.
idThe ID of the surface that must be updated.
hasToKeepColorIf true, will be displayed in its original color. Otherwise, will be displayed in its default color.
Examples
ClassUsingPclViewer.cpp.

Referenced by ClassUsingPclViewer::threadedMode().

◆ updateSurface() [2/2]

void vpPclViewer::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.

Parameters
surfaceThe updated surface.
idThe ID of the surface that must be updated.
weightsThe confidence weights of each points.
hasToKeepColorIf true, will be displayed in its original color. Otherwise, will be displayed in its default color.

Member Data Documentation

◆ m_hasToRun

bool vpPclViewer::m_hasToRun
protected

If true, the drawing thread is running. Otherwise, it is stopped.

Definition at line 255 of file vpPclViewer.h.

◆ m_hasToSavePCDs

bool vpPclViewer::m_hasToSavePCDs
protected

If true, the point clouds will be saved at each iteration of the drawing thread.

Definition at line 257 of file vpPclViewer.h.

◆ m_outFolder

std::string vpPclViewer::m_outFolder
protected

If non empty, the path to the folders where the point clouds will be saved.

Definition at line 258 of file vpPclViewer.h.

◆ m_threadDisplay

std::thread vpPclViewer::m_threadDisplay
protected

The non-blocking drawing thread.

Definition at line 254 of file vpPclViewer.h.

◆ m_title

std::string vpPclViewer::m_title
protected

The title of the viewer window.

Definition at line 256 of file vpPclViewer.h.

◆ m_vlegends

std::vector<legendParams> vpPclViewer::m_vlegends
protected

The list of the legend items.

Definition at line 251 of file vpPclViewer.h.

◆ m_vmeshid

std::vector<std::string> vpPclViewer::m_vmeshid
protected

The list of the point cloud names, for the legend.

Definition at line 250 of file vpPclViewer.h.

◆ m_vpmutex

std::vector<std::mutex *> vpPclViewer::m_vpmutex
protected

The list of mutexes protecting the point clouds from data race when using the drawing thread.

Definition at line 252 of file vpPclViewer.h.

◆ m_vPointClouds

std::vector<pclPointCloudPointXYZRGB::Ptr> vpPclViewer::m_vPointClouds
protected

The list of point clouds known by the viewer.

Definition at line 242 of file vpPclViewer.h.

◆ m_vweights

std::vector<vpColVector> vpPclViewer::m_vweights
protected

The list of confidence weights of each point cloud.

Definition at line 253 of file vpPclViewer.h.

◆ s_height

int vpPclViewer::s_height
staticprotected

The height of the window.

Definition at line 246 of file vpPclViewer.h.

◆ s_ignoreThresh

double vpPclViewer::s_ignoreThresh
staticprotected

The minimum value of the confidence weight of a point to allow it to be displayed.

Definition at line 249 of file vpPclViewer.h.

◆ s_posU

int vpPclViewer::s_posU
staticprotected

The position along the horizontal axis of the screen of the window.

Definition at line 247 of file vpPclViewer.h.

◆ s_posV

int vpPclViewer::s_posV
staticprotected

The position along the vertical axis of the screen of the window.

Definition at line 248 of file vpPclViewer.h.

◆ s_vhandler

std::vector<std::vector<double> > vpPclViewer::s_vhandler
staticprotected

The list of color handlers.

Definition at line 244 of file vpPclViewer.h.

◆ s_width

int vpPclViewer::s_width
staticprotected

The width of the window.

Definition at line 245 of file vpPclViewer.h.

◆ sp_viewer

pcl::visualization::PCLVisualizer::Ptr vpPclViewer::sp_viewer
staticprotected

The PCL viewer permitting the display.

Definition at line 243 of file vpPclViewer.h.