34 #include <visp3/core/vpConfig.h>
36 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_VISUALIZATION) && defined(VISP_HAVE_THREADS)
38 #include <visp3/gui/vpDisplayPCL.h>
46 : m_stop(false), m_verbose(false), m_width(640), m_height(480), m_posx(posx), m_posy(posy),
47 m_window_name(window_name), m_viewer(nullptr)
59 : m_stop(false), m_verbose(false), m_width(width), m_height(height), m_posx(posx), m_posy(posy),
60 m_window_name(window_name), m_viewer(nullptr)
78 void vpDisplayPCL::run(std::mutex &pointcloud_mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud)
80 pcl::PointCloud<pcl::PointXYZ>::Ptr local_pointcloud(
new pcl::PointCloud<pcl::PointXYZ>());
81 m_viewer = pcl::visualization::PCLVisualizer::Ptr(
new pcl::visualization::PCLVisualizer());
82 m_viewer->setBackgroundColor(0, 0, 0);
83 m_viewer->initCameraParameters();
84 m_viewer->setPosition(m_posx, m_posy);
85 m_viewer->setCameraPosition(0, 0, -0.25, 0, -1, 0);
86 m_viewer->setSize(m_width, m_height);
87 m_viewer->setWindowName(m_window_name);
92 std::lock_guard<std::mutex> lock(pointcloud_mutex);
93 local_pointcloud = pointcloud->makeShared();
97 m_viewer->addPointCloud<pcl::PointXYZ>(local_pointcloud,
"sample cloud");
98 m_viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1,
"sample cloud");
103 m_viewer->updatePointCloud<pcl::PointXYZ>(local_pointcloud,
"sample cloud");
106 m_viewer->spinOnce(10);
110 std::cout <<
"End of point cloud display thread" << std::endl;
119 void vpDisplayPCL::run_color(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud_color)
121 pcl::PointCloud<pcl::PointXYZRGB>::Ptr local_pointcloud(
new pcl::PointCloud<pcl::PointXYZRGB>());
122 pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(pointcloud_color);
123 m_viewer = pcl::visualization::PCLVisualizer::Ptr(
new pcl::visualization::PCLVisualizer());
124 m_viewer->setBackgroundColor(0, 0, 0);
125 m_viewer->initCameraParameters();
126 m_viewer->setPosition(m_posx, m_posy);
127 m_viewer->setCameraPosition(0, 0, -0.25, 0, -1, 0);
128 m_viewer->setSize(m_width, m_height);
129 m_viewer->setWindowName(m_window_name);
134 std::lock_guard<std::mutex> lock(mutex);
135 local_pointcloud = pointcloud_color->makeShared();
139 m_viewer->addPointCloud<pcl::PointXYZRGB>(local_pointcloud, rgb,
"RGB sample cloud");
140 m_viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1,
"RGB sample cloud");
145 m_viewer->updatePointCloud<pcl::PointXYZRGB>(local_pointcloud, rgb,
"RGB sample cloud");
148 m_viewer->spinOnce(10);
152 std::cout <<
"End of point cloud display thread" << std::endl;
165 m_thread = std::thread(&vpDisplayPCL::run,
this, std::ref(mutex), pointcloud);
177 m_thread = std::thread(&vpDisplayPCL::run_color,
this, std::ref(mutex), pointcloud_color);
205 m_window_name = window_name;
216 if (m_thread.joinable()) {
231 #elif !defined(VISP_BUILD_SHARED_LIBS)
233 void dummy_vpDisplayPCL() { };
void setPosition(int posx, int posy)
void startThread(std::mutex &mutex, pcl::PointCloud< pcl::PointXYZ >::Ptr pointcloud)
void setWindowName(const std::string &window_name)
vpDisplayPCL(int posx=0, int posy=0, const std::string &window_name="")
void setVerbose(bool verbose)