From 9d48cb392f500869a9ede5e6960582a68ea0647d Mon Sep 17 00:00:00 2001 From: frozar Date: Mon, 11 Dec 2017 15:32:50 +0100 Subject: [PATCH 1/6] [VISU] Add another method 'getPointCloudRenderingProperties()' to handle color. --- .../pcl/visualization/pcl_visualizer.h | 12 +++++++ visualization/src/pcl_visualizer.cpp | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index e225c192652..ed71364d9e7 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -1179,6 +1179,18 @@ namespace pcl getPointCloudRenderingProperties (int property, double &value, const std::string &id = "cloud"); + /** \brief Get the rendering properties of a PointCloud + * \param[in] property the property type + * \param[out] val1 the resultant property value + * \param[out] val2 the resultant property value + * \param[out] val3 the resultant property value + * \param[in] id the point cloud object id (default: cloud) + * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties. + */ + bool + getPointCloudRenderingProperties (int property, double &val1, double &val2, double &val3, + const std::string &id = "cloud"); + /** \brief Set whether the point cloud is selected or not * \param[in] selected whether the cloud is selected or not (true = selected) * \param[in] id the point cloud object id (default: cloud) diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index aa46b22fedc..0cf3c49dd9d 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -1503,6 +1503,40 @@ pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int propert } return (true); } +///////////////////////////////////////////////////////////////////////////////////////////// +bool +pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int property, double &val1, double &val2, double &val3, const std::string &id) +{ + // Check to see if this ID entry already exists (has it been already added to the visualizer?) + CloudActorMap::iterator am_it = cloud_actor_map_->find (id); + + if (am_it == cloud_actor_map_->end ()) + return (false); + // Get the actor pointer + vtkLODActor* actor = vtkLODActor::SafeDownCast (am_it->second.actor); + if (!actor) + return (false); + + switch (property) + { + case PCL_VISUALIZER_COLOR: + { + double rgb[3]; + actor->GetProperty ()->GetColor (rgb); + actor->Modified (); + val1 = rgb[0]; + val2 = rgb[1]; + val3 = rgb[2]; + break; + } + default: + { + pcl::console::print_error ("[getPointCloudRenderingProperties] Unknown property (%d) specified!\n", property); + return (false); + } + } + return (true); +} ///////////////////////////////////////////////////////////////////////////////////////////// bool From 20e3a873dd650c45efec818ed11d5bdc51cac40a Mon Sep 17 00:00:00 2001 From: frozar Date: Tue, 12 Dec 2017 17:08:10 +0100 Subject: [PATCH 2/6] [VISU] Fix prototype. --- visualization/include/pcl/visualization/pcl_visualizer.h | 2 +- visualization/src/pcl_visualizer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index ed71364d9e7..8370fb18b65 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -1188,7 +1188,7 @@ namespace pcl * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties. */ bool - getPointCloudRenderingProperties (int property, double &val1, double &val2, double &val3, + getPointCloudRenderingProperties (RenderingProperties property, double &val1, double &val2, double &val3, const std::string &id = "cloud"); /** \brief Set whether the point cloud is selected or not diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 0cf3c49dd9d..75bf82436fe 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -1505,7 +1505,7 @@ pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int propert } ///////////////////////////////////////////////////////////////////////////////////////////// bool -pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int property, double &val1, double &val2, double &val3, const std::string &id) +pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (RenderingProperties property, double &val1, double &val2, double &val3, const std::string &id) { // Check to see if this ID entry already exists (has it been already added to the visualizer?) CloudActorMap::iterator am_it = cloud_actor_map_->find (id); From ae1f15aa0d5d803a537e676f8abe29d32a9b0779 Mon Sep 17 00:00:00 2001 From: frozar Date: Tue, 12 Dec 2017 17:08:45 +0100 Subject: [PATCH 3/6] [VISU] Delete useless line. --- visualization/src/pcl_visualizer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 75bf82436fe..9471fbc6a2b 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -1523,7 +1523,6 @@ pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (RenderingPr { double rgb[3]; actor->GetProperty ()->GetColor (rgb); - actor->Modified (); val1 = rgb[0]; val2 = rgb[1]; val3 = rgb[2]; From dd44e1b2f00a9a8cf6dc5b204d3ab13946937387 Mon Sep 17 00:00:00 2001 From: frozar Date: Wed, 13 Dec 2017 10:26:45 +0100 Subject: [PATCH 4/6] [VISU] Review from Sergio. --- .../include/pcl/visualization/pcl_visualizer.h | 1 + visualization/src/pcl_visualizer.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/visualization/include/pcl/visualization/pcl_visualizer.h b/visualization/include/pcl/visualization/pcl_visualizer.h index 8370fb18b65..9b4be508898 100644 --- a/visualization/include/pcl/visualization/pcl_visualizer.h +++ b/visualization/include/pcl/visualization/pcl_visualizer.h @@ -1185,6 +1185,7 @@ namespace pcl * \param[out] val2 the resultant property value * \param[out] val3 the resultant property value * \param[in] id the point cloud object id (default: cloud) + * \return True if the property is effectively retrieved. * \note The list of properties can be found in \ref pcl::visualization::LookUpTableRepresentationProperties. */ bool diff --git a/visualization/src/pcl_visualizer.cpp b/visualization/src/pcl_visualizer.cpp index 9471fbc6a2b..962ca703aee 100644 --- a/visualization/src/pcl_visualizer.cpp +++ b/visualization/src/pcl_visualizer.cpp @@ -1505,7 +1505,11 @@ pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (int propert } ///////////////////////////////////////////////////////////////////////////////////////////// bool -pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (RenderingProperties property, double &val1, double &val2, double &val3, const std::string &id) +pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (RenderingProperties property, + double &val1, + double &val2, + double &val3, + const std::string &id) { // Check to see if this ID entry already exists (has it been already added to the visualizer?) CloudActorMap::iterator am_it = cloud_actor_map_->find (id); @@ -1530,7 +1534,10 @@ pcl::visualization::PCLVisualizer::getPointCloudRenderingProperties (RenderingPr } default: { - pcl::console::print_error ("[getPointCloudRenderingProperties] Unknown property (%d) specified!\n", property); + pcl::console::print_error ("[getPointCloudRenderingProperties] " + "Property (%d) is either unknown or it requires a different " + "number of variables to retrieve its contents.\n", + property); return (false); } } From d9bd68880c7f9390300314775253f4f69cec6950 Mon Sep 17 00:00:00 2001 From: frozar Date: Wed, 13 Dec 2017 11:18:53 +0100 Subject: [PATCH 5/6] [TEST] Add a unit test for 'getPointCloudRenderingProperties()'. --- test/visualization/test_visualization.cpp | 41 +++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/test/visualization/test_visualization.cpp b/test/visualization/test_visualization.cpp index 00b43309533..3270a1298f0 100644 --- a/test/visualization/test_visualization.cpp +++ b/test/visualization/test_visualization.cpp @@ -110,8 +110,45 @@ TEST (PCL, PCLVisualizer_camera) // cerr << "reset camera viewer pose:" << endl << viewer_pose << endl; } - - +//////////////////////////////////////////////////////////////////////////////// +TEST (PCL, PCLVisualizer_getPointCloudRenderingProperties) +{ + PCLVisualizer::Ptr visualizer (new PCLVisualizer); + + std::string cloud_id = "input_cloud"; + visualizer->addPointCloud (cloud, cloud_id); + ASSERT_TRUE (visualizer->setPointCloudRenderingProperties (PCL_VISUALIZER_COLOR, + 1.d, 0.d, 0.d, cloud_id)); + double r, g, b; + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_POINT_SIZE, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_OPACITY, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_LINE_WIDTH, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_FONT_SIZE, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_REPRESENTATION, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_IMMEDIATE_RENDERING, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_SHADING, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_LUT, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_LUT_RANGE, + r, g, b, cloud_id)); + + r = 666.d; + g = 666.d; + b = 666.d; + EXPECT_TRUE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_COLOR, + r, g, b, cloud_id)); + + EXPECT_EQ (r, 1.d); + EXPECT_EQ (g, 0.d); + EXPECT_EQ (b, 0.d); +} /* ---[ */ int From 7fa84d7caefd2d9096a4ccf988e05aba918929a3 Mon Sep 17 00:00:00 2001 From: frozar Date: Thu, 14 Dec 2017 16:33:03 +0100 Subject: [PATCH 6/6] [TEST] Visu: review from Sergio. --- test/visualization/test_visualization.cpp | 60 +++++++++++------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/test/visualization/test_visualization.cpp b/test/visualization/test_visualization.cpp index 3270a1298f0..9f0b3ba27ca 100644 --- a/test/visualization/test_visualization.cpp +++ b/test/visualization/test_visualization.cpp @@ -113,41 +113,41 @@ TEST (PCL, PCLVisualizer_camera) //////////////////////////////////////////////////////////////////////////////// TEST (PCL, PCLVisualizer_getPointCloudRenderingProperties) { - PCLVisualizer::Ptr visualizer (new PCLVisualizer); + PCLVisualizer visualizer; std::string cloud_id = "input_cloud"; - visualizer->addPointCloud (cloud, cloud_id); - ASSERT_TRUE (visualizer->setPointCloudRenderingProperties (PCL_VISUALIZER_COLOR, - 1.d, 0.d, 0.d, cloud_id)); + visualizer.addPointCloud (cloud, cloud_id); + ASSERT_TRUE (visualizer.setPointCloudRenderingProperties (PCL_VISUALIZER_COLOR, + 1., 0., 0., cloud_id)); double r, g, b; - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_POINT_SIZE, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_OPACITY, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_LINE_WIDTH, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_FONT_SIZE, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_REPRESENTATION, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_IMMEDIATE_RENDERING, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_SHADING, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_LUT, - r, g, b, cloud_id)); - EXPECT_FALSE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_LUT_RANGE, - r, g, b, cloud_id)); - - r = 666.d; - g = 666.d; - b = 666.d; - EXPECT_TRUE (visualizer->getPointCloudRenderingProperties (PCL_VISUALIZER_COLOR, + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_POINT_SIZE, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_OPACITY, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_LINE_WIDTH, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_FONT_SIZE, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_REPRESENTATION, r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_IMMEDIATE_RENDERING, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_SHADING, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_LUT, + r, g, b, cloud_id)); + EXPECT_FALSE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_LUT_RANGE, + r, g, b, cloud_id)); + + r = 666.; + g = 666.; + b = 666.; + EXPECT_TRUE (visualizer.getPointCloudRenderingProperties (PCL_VISUALIZER_COLOR, + r, g, b, cloud_id)); - EXPECT_EQ (r, 1.d); - EXPECT_EQ (g, 0.d); - EXPECT_EQ (b, 0.d); + EXPECT_EQ (r, 1.); + EXPECT_EQ (g, 0.); + EXPECT_EQ (b, 0.); } /* ---[ */