35 #ifndef DOXYGEN_SHOULD_SKIP_THIS
37 #include <visp3/core/vpConfig.h>
38 #if defined(VISP_HAVE_PCL) && defined(VISP_HAVE_PCL_IO) && defined(VISP_HAVE_THREADS)
40 #include <visp3/gui/vpPclViewer.h>
41 #include <visp3/gui/vpColorBlindFriendlyPalette.h>
42 #include <visp3/core/vpIoTools.h>
45 #include <pcl/io/pcd_io.h>
52 const unsigned int gc_nbColorMax = 7;
65 ,
const int &posU,
const int &posV
66 ,
const std::string &outFolder,
const double &ignoreThreshold)
69 , m_hasToSavePCDs(false)
70 , m_outFolder(outFolder)
72 setOutFolder(outFolder);
73 setIgnoreThreshold(ignoreThreshold);
92 for (
unsigned int id = 0;
id <
m_vpmutex.size();
id++) {
127 if (ignoreThreshold < 0. || ignoreThreshold > 1.) {
133 void vpPclViewer::updateSurface(
const pclPointCloudPointXYZRGB::Ptr &surface,
const unsigned int &
id,
const bool &hasToKeepColor)
137 if (hasToKeepColor) {
154 const vpColVector &weights,
const bool &hasToKeepColor)
158 if (hasToKeepColor) {
175 unsigned int nbPoints = surface->size();
180 bool use_weights = (weights.
size() > 0);
183 for (
unsigned int index = 0; index < nbPoints; index++) {
184 bool addPoint =
false;
208 std::stringstream err_msg;
209 err_msg <<
"[vpPclViewer ::updateSurface] ID " <<
m_vmeshid[id] <<
" not found !" << std::endl;
215 unsigned int vpPclViewer::addSurface(
const pclPointCloudPointXYZRGB::Ptr &surface,
const std::string &name,
const std::vector<unsigned char> &v_color)
218 return addSurface(surface, emptyWeights, name, v_color);
221 unsigned int vpPclViewer::addSurface(
const pclPointCloudPointXYZRGB::Ptr &surface,
const vpColVector &weights,
const std::string &name,
const std::vector<unsigned char> &v_color)
223 static unsigned int nbSurfaces = 0;
231 unsigned int nbPoints = surface->size();
235 std::vector<unsigned char> v_RGB;
236 if (v_color.size() < 3) {
240 v_RGB = color.to_RGB();
247 std::vector<double> v_RGBdouble = {
256 bool use_weigths = weights.
size() > 0;
261 for (
unsigned int index = 0; index < nbPoints; index++) {
262 bool shouldPointBeVisible =
false;
270 shouldPointBeVisible =
true;
278 if (shouldPointBeVisible) {
301 m_vmeshid.push_back(
"point_cloud" + std::to_string(
id));
310 nbSurfaces = (nbSurfaces + 1) % gc_nbColorMax;
320 newLegend.m_posU = 10;
321 newLegend.m_posV = 10;
322 newLegend.m_size = 16;
324 newLegend.m_posV =
m_vlegends[
id - 1].m_posV + newLegend.m_size;
326 newLegend.m_rRatio =
s_vhandler[id][0] / 255.0;
327 newLegend.m_gRatio =
s_vhandler[id][1] / 255.0;
328 newLegend.m_bRatio =
s_vhandler[id][2] / 255.0;
332 sp_viewer->addText(newLegend.m_text, newLegend.m_posU, newLegend.m_posV, newLegend.m_rRatio, newLegend.m_gRatio, newLegend.m_bRatio);
362 sp_viewer->spinOnce(timeout, waitForDrawing);
399 unsigned int iter = 0;
403 for (
unsigned int id = 0;
id <
m_vmeshid.size();
id++) {
407 unsigned int nbWeights =
m_vweights[id].size();
408 useWeights = (nbWeights > 0);
411 for (
unsigned int index = 0; index < nbPoints; index++) {
459 unsigned int nbPoints = surface->
size();
464 for (
unsigned int index = 0; index < nbPoints; index++) {
481 unsigned int nbPoints = surface->
size();
490 #elif !defined(VISP_BUILD_SHARED_LIBS)
492 void dummy_vpPCLPointCLoudVisualization() { };
unsigned int size() const
Return the number of elements of the 2D array.
Implementation of column vector and the associated operations.
Class that furnishes a set of colors that color blind people should be able to distinguish one from a...
error that can be emitted by ViSP classes.
@ 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()
Blocking-mode display of the viewer.
pcl::PointCloud< pclPointXYZRGB > pclPointCloudPointXYZRGB
static pcl::visualization::PCLVisualizer::Ptr sp_viewer
void loopThread()
The internal loop of the non-blocking drawing thread.
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.
static double s_ignoreThresh
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
pcl::PointXYZRGB pclPointXYZRGB
void refresh(const int &timeout=100, const bool &waitForDrawing=true)
Refresh the display.
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.
static std::vector< std::vector< double > > s_vhandler
struct vpPclViewer::legendParams legendParams
Structure that contains all the required parameters to display a legend on the viewer.
void updateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id, const bool &hasToKeepColor=false)
Update the surface known by id by the viewer.
unsigned int 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.
std::vector< legendParams > m_vlegends
void threadUpdateSurfaceOriginalColor(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id)
Method to update a point cloud known by the viewer when the drawing thread is running....
void stopThread()
Stop the drawing thread that permits to have a non-blocking display.
void threadUpdateSurface(const pclPointCloudPointXYZRGB::Ptr &surface, const unsigned int &id)
Method to update a point cloud known by the viewer when the drawing thread is running....
std::vector< pclPointCloudPointXYZRGB::Ptr > m_vPointClouds
void setIgnoreThreshold(const double &thresh)
Set the threshold below which a point must be displayed in black.