Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches

#include <vpDisplayPCL.h>

Public Member Functions

 vpDisplayPCL (int posx=0, int posy=0, const std::string &window_name="")
 vpDisplayPCL (unsigned int width, unsigned int height, int posx=0, int posy=0, const std::string &window_name="")
 ~vpDisplayPCL ()
void setVerbose (bool verbose)
void display (const bool &blocking=false)
void startThread (const bool &colorThread=false)
void startThread (std::mutex &mutex, pcl::PointCloud< pcl::PointXYZ >::Ptr pointcloud, const std::string &name="", const vpColor &color=vpColor::red)
void startThread (std::mutex &mutex, pcl::PointCloud< pcl::PointXYZRGB >::Ptr pointcloud)
void addPointCloud (std::mutex &mutex, pcl::PointCloud< pcl::PointXYZ >::Ptr pointcloud, const std::string &name="", const vpColor &color=vpColor::red)
void addPointCloud (std::mutex &mutex, pcl::PointCloud< pcl::PointXYZRGB >::Ptr pointcloud)
void setPosition (int posx, int posy)
void setWindowName (const std::string &window_name)
void stop ()

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.

Warning
MacOS currently can only use the monothread method display, otherwise they get the error uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow should only be instantiated on the main thread!'
On Ubuntu 22.04 and 24.04, you can face the following error:
Thread 2 "tutorial-pcl-vi" received signal SIGSEGV, Segmentation fault.
0x00007ffff7304b10 in _XEventsQueued () from /lib/x86_64-linux-gnu/libX11.so.6
0x00007ffff7304b10 in _XEventsQueued () at /lib/x86_64-linux-gnu/libX11.so.6
0x00007ffff72f11a1 in XPending () at /lib/x86_64-linux-gnu/libX11.so.6
0x00007fffecf65b8f in vtkXRenderWindowInteractor::StartEventLoop() () at /lib/x86_64-linux-gnu/libvtkRenderingUI-9.1.so.1
0x00007ffff6ee3f8c in pcl::visualization::PCLVisualizer::spinOnce(int, bool) () at /lib/x86_64-linux-gnu/libpcl_visualization.so.1.12
0x00007ffff7fa5c49 in vpPclVisualizer::loopThread() (this=0x7fffffffd720) at /usr/include/c++/11/bits/shared_ptr_base.h:1295
This is a known compatibility issue between PCL library and VTK library.

The vpDisplayPCL can be used in monothread mode, or you may try to install PCL from source and then recompile ViSP.

Warning
When the PCL library relies on the VTK library and X11 library as backends for the viewer, you may face the following error if you create either two viewers in threaded mode or one viewer in threaded mode and another one in the main thread:
X Error of failed request: BadAccess (attempt to access private resource denied)
Major opcode of failed request: 152 (GLX)
Minor opcode of failed request: 5 (X_GLXMakeCurrent)
Serial number of failed request: 407
Current serial number in output stream: 407
It seems to be due to the fact that the X server resources are reserved by one thread, preventing any other thread to access them.

Tutorials & Examples

Tutorials
If you want detailed explanation on how to use this class, you may have a look at:

Examples
ClassUsingDisplayPCL.h, grabRealSense2.cpp, testRealSense2_D435_pcl.cpp, tutorial-hsv-segmentation-pcl-viewer.cpp, and visp-read-rs-dataset.cpp.

Definition at line 96 of file vpDisplayPCL.h.

Constructor & Destructor Documentation

◆ vpDisplayPCL() [1/2]

BEGIN_VISP_NAMESPACE vpDisplayPCL::vpDisplayPCL ( int posx = 0,
int posy = 0,
const std::string & window_name = "" )

Default constructor. By default, viewer size is set to 640 x 480.

Parameters
[in]posxHorizontal position of the viewer on screen.
[in]posyVertical position of the viewer on screen.
[in]window_nameName of the viewer window.

Definition at line 54 of file vpDisplayPCL.cpp.

◆ vpDisplayPCL() [2/2]

vpDisplayPCL::vpDisplayPCL ( unsigned int width,
unsigned int height,
int posx = 0,
int posy = 0,
const std::string & window_name = "" )

Constructor able to initialize the display window size.

Parameters
[in]width: Point cloud viewer width.
[in]height: Point cloud viewer height.
[in]posx: Position along X-axis.
[in]posy: Position along Y-axis.
[in]window_name: Window name.

Definition at line 67 of file vpDisplayPCL.cpp.

◆ ~vpDisplayPCL()

vpDisplayPCL::~vpDisplayPCL ( )

Destructor that stops and join the viewer thread if not already done.

See also
stop(), startThread()

Definition at line 77 of file vpDisplayPCL.cpp.

References stop().

Member Function Documentation

◆ addPointCloud() [1/2]

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

Parameters
[in]mutexMutex that protects the point-cloud.
[in]pointcloudThe point-cloud to display.
[in]nameThe name of the point cloud to be displayed in the legend.
[in]colorThe color in which you want the point cloud to be displayed.

Definition at line 400 of file vpDisplayPCL.cpp.

◆ addPointCloud() [2/2]

void vpDisplayPCL::addPointCloud ( std::mutex & mutex,
pcl::PointCloud< pcl::PointXYZRGB >::Ptr pointcloud )

Insert a colored point cloud to display.

Parameters
[in]mutexMutex that protects the point-cloud.
[in]pointcloudThe point-cloud to display.

Definition at line 413 of file vpDisplayPCL.cpp.

◆ display()

void vpDisplayPCL::display ( const bool & blocking = false)

Monothread display method.

Warning
MacOS currently can only use this monothread method, otherwise they get the error uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow should only be instantiated on the main thread!'
Because pcl::visualization::PCLVisualizer is not multi-thread friendly, calling this method stops the display thread if it was running.
Parameters
[in]blockingIf true, the program execution will be stopped until a key is pressed. If false, will refresh the display and then the program execution will automatically resume.

Definition at line 124 of file vpDisplayPCL.cpp.

References stop().

◆ setPosition()

void vpDisplayPCL::setPosition ( int posx,
int posy )

Set the position of the viewer window. This function has to be called prior startThread().

Parameters
[in]posx: Position along x.
[in]posy: Position along y.
See also
setWindowName()
Examples
visp-read-rs-dataset.cpp.

Definition at line 429 of file vpDisplayPCL.cpp.

◆ setVerbose()

void vpDisplayPCL::setVerbose ( bool verbose)

Enable/disable verbose mode.

Parameters
[in]verbose: When true verbose mode is enable.

Definition at line 469 of file vpDisplayPCL.cpp.

◆ setWindowName()

void vpDisplayPCL::setWindowName ( const std::string & window_name)

Set the name of the viewer windows. This function has to be called prior startThread().

Parameters
[in]window_name: Window name to set.
See also
setPosition()
Examples
visp-read-rs-dataset.cpp.

Definition at line 443 of file vpDisplayPCL.cpp.

◆ startThread() [1/3]

void vpDisplayPCL::startThread ( const bool & colorThread = false)

Start the viewer thread able to display a point cloud.

Parameters
[in]colorThreadIf true, assumes that the point clouds contain RGB information. If false, assumes that the point clouds contain only XYZ information and display them along with a legend using monochromic colors.
Examples
grabRealSense2.cpp, testRealSense2_D435_pcl.cpp, and visp-read-rs-dataset.cpp.

Definition at line 332 of file vpDisplayPCL.cpp.

References vpException::fatalError.

◆ startThread() [2/3]

void vpDisplayPCL::startThread ( std::mutex & mutex,
pcl::PointCloud< pcl::PointXYZ >::Ptr pointcloud,
const std::string & name = "",
const vpColor & color = vpColor::red )

Start the viewer thread able to display a point cloud.

Parameters
[in,out]mutex: Shared mutex.
[in]pointcloud: Point cloud to display.
[in]nameThe name of the point cloud to be displayed in the legend.
[in]colorThe color in which you want the point cloud to be displayed.
See also
stop()

Definition at line 357 of file vpDisplayPCL.cpp.

References vpException::fatalError.

◆ startThread() [3/3]

void vpDisplayPCL::startThread ( std::mutex & mutex,
pcl::PointCloud< pcl::PointXYZRGB >::Ptr pointcloud_color )

Start the viewer thread able to display a textured point cloud.

Parameters
[in,out]mutex: Shared mutex.
[in]pointcloud_color: Textured point cloud to display.
See also
stop()

Definition at line 378 of file vpDisplayPCL.cpp.

References vpException::fatalError.

◆ stop()

void vpDisplayPCL::stop ( )

Stop the viewer thread and join.

Definition at line 451 of file vpDisplayPCL.cpp.

Referenced by display(), and ~vpDisplayPCL().