33#ifndef DOXYGEN_SHOULD_SKIP_THIS
35#include <visp3/core/vpConfig.h>
36#if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_VISUALIZATION) && defined(VISP_HAVE_PCL_IO) && defined(VISP_HAVE_THREADS)
38#include <visp3/gui/vpPclViewer.h>
39#include <visp3/gui/vpColorBlindFriendlyPalette.h>
40#include <visp3/core/vpIoTools.h>
43#include <pcl/io/pcd_io.h>
46const std::vector<vpColorBlindFriendlyPalette::Palette> gcolor = { vpColorBlindFriendlyPalette::Palette::Green, vpColorBlindFriendlyPalette::Palette::Vermillon,vpColorBlindFriendlyPalette::Palette::Blue,
47 vpColorBlindFriendlyPalette::Palette::Black, vpColorBlindFriendlyPalette::Palette::Orange, vpColorBlindFriendlyPalette::Palette::Purple,
48 vpColorBlindFriendlyPalette::Palette::Yellow };
50const unsigned int gc_nbColorMax = 7;
53 ,
const int &posU,
const int &posV
54 ,
const std::string &outFolder,
const double &ignoreThreshold)
56 , m_ignoreThresh(0.95)
59 , m_hasToSavePCDs(false)
60 , m_outFolder(outFolder)
62 setOutFolder(outFolder);
63 setIgnoreThreshold(ignoreThreshold);
70vpPclViewer ::~vpPclViewer()
76 for (
unsigned int i = 0;
i < m_vPointClouds.size();
i++) {
77 m_vPointClouds[
i].reset();
79 m_vPointClouds.clear();
82 for (
unsigned int id = 0;
id < m_vpmutex.size();
id++) {
117 if (ignoreThreshold < 0. || ignoreThreshold > 1.) {
118 throw(vpException(
vpException::badValue,
"[vpPclViewer::setIgnoreThreshold] Fatal error: threshold must be in range [0. ; 1.]"));
124 const bool &hasToKeepColor)
128 if (hasToKeepColor) {
139 vpColVector fakeWeights;
145 const vpColVector &weights,
const bool &hasToKeepColor)
149 if (hasToKeepColor) {
162 m_vPointClouds[id].reset(
new pcl::PointCloud<pcl::PointXYZRGB>());
166 unsigned int nbPoints = surface->size();
171 bool use_weights = (weights.
size() > 0);
174 for (
unsigned int index = 0; index < nbPoints; index++) {
175 bool addPoint =
false;
183 pcl::PointXYZRGB pt = surface->at(index);
200 std::stringstream err_msg;
201 err_msg <<
"[vpPclViewer ::updateSurface] ID " <<
m_vmeshid[id] <<
" not found !" << std::endl;
208unsigned int vpPclViewer::addSurface(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr &surface,
const std::string &name,
const std::vector<unsigned char> &v_color)
210 vpColVector emptyWeights;
211 return addSurface(surface, emptyWeights, name, v_color);
214unsigned int vpPclViewer::addSurface(
const pcl::PointCloud<pcl::PointXYZRGB>::Ptr &surface,
const vpColVector &weights,
const std::string &name,
const std::vector<unsigned char> &v_color)
216 static unsigned int nbSurfaces = 0;
220 pcl::PointCloud<pcl::PointXYZRGB>::Ptr p_pointCloud(
new pcl::PointCloud<pcl::PointXYZRGB>());
224 unsigned int nbPoints = surface->size();
228 std::vector<unsigned char> v_RGB;
229 if (v_color.size() < 3) {
232 vpColorBlindFriendlyPalette
color(gcolor[nbSurfaces]);
233 v_RGB =
color.to_RGB();
240 std::vector<double> v_RGBdouble = {
241 static_cast<double>(v_RGB[0]),
242 static_cast<double>(v_RGB[1]),
243 static_cast<double>(v_RGB[2])
249 bool use_weights = weights.
size() > 0;
254 for (
unsigned int index = 0; index < nbPoints; index++) {
255 bool shouldPointBeVisible =
false;
263 shouldPointBeVisible =
true;
266 pcl::PointXYZRGB pt = surface->at(index);
271 if (shouldPointBeVisible) {
291 m_vmeshid.push_back(
"point_cloud" + std::to_string(
id));
299 nbSurfaces = (nbSurfaces + 1) % gc_nbColorMax;
309 newLegend.m_posU = 10;
310 newLegend.m_posV = 10;
311 newLegend.m_size = 16;
313 newLegend.m_posV =
m_vlegends[
id - 1].m_posV + newLegend.m_size;
315 newLegend.m_rRatio =
m_vhandler[id][0] / 255.0;
316 newLegend.m_gRatio =
m_vhandler[id][1] / 255.0;
317 newLegend.m_bRatio =
m_vhandler[id][2] / 255.0;
321 mp_viewer->addText(newLegend.m_text, newLegend.m_posU, newLegend.m_posV, newLegend.m_rRatio, newLegend.m_gRatio, newLegend.m_bRatio);
372#if (defined(_WIN32) && defined(_MSVC_LANG))
374#pragma warning(disable : 4996)
382#if (defined(_WIN32) && defined(_MSVC_LANG))
395 unsigned int iter = 0;
399 for (
unsigned int id = 0;
id <
m_vmeshid.size();
id++) {
403 unsigned int nbWeights =
m_vweights[id].size();
404 useWeights = (nbWeights > 0);
407 for (
unsigned int index = 0; index < nbPoints; index++) {
455 unsigned int nbPoints = surface->
size();
460 for (
unsigned int index = 0; index < nbPoints; index++) {
461 pcl::PointXYZRGB pt = surface->at(index);
477 unsigned int nbPoints = surface->
size();
486#elif !defined(VISP_BUILD_SHARED_LIBS)
488void dummy_vpPCLPointCLoudVisualization() { }
unsigned int size() const
Return the number of elements of the 2D array.
Implementation of column vector and the associated operations.
@ badValue
Used to indicate that a value is not in the allowed range.
@ notInitialized
Used to indicate that a parameter is not initialized.
static void runThread(vpPclViewer *p_viewer)
Internal method that is called by vpPclViewer::launchThread to launch the drawing thread.
void display(const bool &blocking=false)
Blocking-mode display of the viewer.
void loopThread()
The internal loop of the non-blocking drawing thread.
void updateSurface(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &surface, const unsigned int &id, const bool &hasToKeepColor=false)
Update the surface known by id by the viewer.
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.
std::thread m_threadDisplay
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
std::vector< std::string > m_vmeshid
std::vector< vpColVector > m_vweights
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.
void threadUpdateSurfaceOriginalColor(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &surface, const unsigned int &id)
Method to update a point cloud known by the viewer when the drawing thread is running....
void threadUpdateSurface(const pcl::PointCloud< pcl::PointXYZRGB >::Ptr &surface, const unsigned int &id)
Method to update a point cloud known by the viewer when the drawing thread is running....
std::vector< std::vector< double > > m_vhandler
unsigned int addSurface(const pcl::PointCloud< pcl::PointXYZRGB >::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< pcl::PointCloud< pcl::PointXYZRGB >::Ptr > m_vPointClouds
std::vector< legendParams > m_vlegends
void stopThread()
Stop the drawing thread that permits to have a non-blocking display.
pcl::visualization::PCLVisualizer::Ptr mp_viewer
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.