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>
44 vpDisplayPCL::vpDisplayPCL(
int posx,
int posy,
const std::string &window_name)
45 : m_stop(false), m_verbose(false), m_width(640), m_height(480), m_posx(posx), m_posy(posy),
46 m_window_name(window_name), m_viewer(nullptr)
57 vpDisplayPCL::vpDisplayPCL(
unsigned int width,
unsigned int height,
int posx,
int posy,
const std::string &window_name)
58 : m_stop(false), m_verbose(false), m_width(width), m_height(height), m_posx(posx), m_posy(posy),
59 m_window_name(window_name), m_viewer(nullptr)
67 vpDisplayPCL::~vpDisplayPCL()
77 void vpDisplayPCL::run(std::mutex &pointcloud_mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud)
79 pcl::PointCloud<pcl::PointXYZ>::Ptr local_pointcloud(
new pcl::PointCloud<pcl::PointXYZ>());
80 m_viewer = pcl::visualization::PCLVisualizer::Ptr(
new pcl::visualization::PCLVisualizer());
81 m_viewer->setBackgroundColor(0, 0, 0);
82 m_viewer->initCameraParameters();
83 m_viewer->setPosition(m_posx, m_posy);
84 m_viewer->setCameraPosition(0, 0, -0.25, 0, -1, 0);
85 m_viewer->setSize(m_width, m_height);
86 m_viewer->setWindowName(m_window_name);
91 std::lock_guard<std::mutex> lock(pointcloud_mutex);
92 local_pointcloud = pointcloud->makeShared();
96 m_viewer->addPointCloud<pcl::PointXYZ>(local_pointcloud,
"sample cloud");
97 m_viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1,
"sample cloud");
102 m_viewer->updatePointCloud<pcl::PointXYZ>(local_pointcloud,
"sample cloud");
105 m_viewer->spinOnce(10);
109 std::cout <<
"End of point cloud display thread" << std::endl;
118 void vpDisplayPCL::run_color(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud_color)
120 pcl::PointCloud<pcl::PointXYZRGB>::Ptr local_pointcloud(
new pcl::PointCloud<pcl::PointXYZRGB>());
121 pcl::visualization::PointCloudColorHandlerRGBField<pcl::PointXYZRGB> rgb(pointcloud_color);
122 m_viewer = pcl::visualization::PCLVisualizer::Ptr(
new pcl::visualization::PCLVisualizer());
123 m_viewer->setBackgroundColor(0, 0, 0);
124 m_viewer->initCameraParameters();
125 m_viewer->setPosition(m_posx, m_posy);
126 m_viewer->setCameraPosition(0, 0, -0.25, 0, -1, 0);
127 m_viewer->setSize(m_width, m_height);
128 m_viewer->setWindowName(m_window_name);
133 std::lock_guard<std::mutex> lock(mutex);
134 local_pointcloud = pointcloud_color->makeShared();
138 m_viewer->addPointCloud<pcl::PointXYZRGB>(local_pointcloud, rgb,
"RGB sample cloud");
139 m_viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 1,
"RGB sample cloud");
144 m_viewer->updatePointCloud<pcl::PointXYZRGB>(local_pointcloud, rgb,
"RGB sample cloud");
147 m_viewer->spinOnce(10);
151 std::cout <<
"End of point cloud display thread" << std::endl;
162 void vpDisplayPCL::startThread(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZ>::Ptr pointcloud)
164 m_thread = std::thread(&vpDisplayPCL::run,
this, std::ref(mutex), pointcloud);
174 void vpDisplayPCL::startThread(std::mutex &mutex, pcl::PointCloud<pcl::PointXYZRGB>::Ptr pointcloud_color)
176 m_thread = std::thread(&vpDisplayPCL::run_color,
this, std::ref(mutex), pointcloud_color);
188 void vpDisplayPCL::setPosition(
int posx,
int posy)
202 void vpDisplayPCL::setWindowName(
const std::string &window_name)
204 m_window_name = window_name;
210 void vpDisplayPCL::stop()
215 if (m_thread.joinable()) {
225 void vpDisplayPCL::setVerbose(
bool verbose)
230 #elif !defined(VISP_BUILD_SHARED_LIBS)
232 void dummy_vpDisplayPCL() { };
void init(unsigned int h, unsigned int w, Type value)