From 2682870e76f30add7abd8ce340957980bea4e50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Agostinho?= Date: Tue, 21 Nov 2017 18:47:07 +0000 Subject: [PATCH 1/4] Defined new pragma and pragma_warning macros --- common/include/pcl/pcl_macros.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/common/include/pcl/pcl_macros.h b/common/include/pcl/pcl_macros.h index 925da2a28d2..4f45aac49e3 100644 --- a/common/include/pcl/pcl_macros.h +++ b/common/include/pcl/pcl_macros.h @@ -289,6 +289,25 @@ log2f (float x) #define PCLAPI(rettype) PCL_EXTERN_C PCL_EXPORTS rettype PCL_CDECL #endif +// Macro for pragma operator +#if (defined (__GNUC__) || defined(__clang__)) + #define PCL_PRAGMA(x) _Pragma (#x) +#elif _MSC_VER + #define PCL_PRAGMA(x) __pragma (#x) +#else + #define PCL_PRAGMA +#endif + +// Macro for emitting pragma warning +#if (defined (__GNUC__) || defined(__clang__)) + #define PCL_PRAGMA_WARNING(x) PCL_PRAGMA (GCC warning x) +#elif _MSC_VER + #define PCL_PRAGMA_WARNING(x) PCL_PRAGMA (warning (x)) +#else + #define PCL_PRAGMA_WARNING +#endif + + // Macro to deprecate old functions // // Usage: From 06111caed38410491b11bb53adbd0d688891f244 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Agostinho?= Date: Tue, 21 Nov 2017 18:52:50 +0000 Subject: [PATCH 2/4] Deprecation of some EuclideanClusterComparator methods - Restored the previous ECC API - Defined a "protected" base class which will replace the original in a future release. --- .../tools/impl/organized_segmentation.hpp | 3 +- .../pcl/apps/organized_segmentation_demo.h | 2 +- apps/src/ni_linemod.cpp | 2 +- apps/src/organized_segmentation_demo.cpp | 2 +- apps/src/pcd_select_object_plane.cpp | 2 +- apps/src/stereo_ground_segmentation.cpp | 2 +- .../euclidean_cluster_comparator.h | 109 ++++++++++++++---- 7 files changed, 94 insertions(+), 28 deletions(-) diff --git a/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp b/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp index 3de132f462e..9a7d0d980ea 100644 --- a/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp +++ b/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp @@ -108,7 +108,8 @@ (*plane_labels)[i] = (label_indices[i].indices.size () > (size_t) min_plane_size); typename PointCloud::CloudVectorType clusters; - typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator = boost::make_shared > (); + typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator = + boost::make_shared > (); euclidean_cluster_comparator->setInputCloud (input_cloud); euclidean_cluster_comparator->setLabels (labels); euclidean_cluster_comparator->setExcludeLabels (plane_labels); diff --git a/apps/include/pcl/apps/organized_segmentation_demo.h b/apps/include/pcl/apps/organized_segmentation_demo.h index 2d873a347ab..d2c11796849 100644 --- a/apps/include/pcl/apps/organized_segmentation_demo.h +++ b/apps/include/pcl/apps/organized_segmentation_demo.h @@ -139,7 +139,7 @@ class OrganizedSegmentationDemo : public QMainWindow pcl::RGBPlaneCoefficientComparator::Ptr rgb_comparator_; pcl::RGBPlaneCoefficientComparator rgb_comp_; pcl::EdgeAwarePlaneComparator::Ptr edge_aware_comparator_; - pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_; + pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_; public Q_SLOTS: void toggleCapturePressed() diff --git a/apps/src/ni_linemod.cpp b/apps/src/ni_linemod.cpp index c3784347bfd..97886eeb3c0 100644 --- a/apps/src/ni_linemod.cpp +++ b/apps/src/ni_linemod.cpp @@ -249,7 +249,7 @@ class NILinemod exppd.segment (*points_above_plane); // Use an organized clustering segmentation to extract the individual clusters - EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); + EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); euclidean_cluster_comparator->setInputCloud (cloud); euclidean_cluster_comparator->setDistanceThreshold (0.03f, false); // Set the entire scene to false, and the inliers of the objects located on top of the plane to true diff --git a/apps/src/organized_segmentation_demo.cpp b/apps/src/organized_segmentation_demo.cpp index f89b120cb2a..95e5f83ebf2 100644 --- a/apps/src/organized_segmentation_demo.cpp +++ b/apps/src/organized_segmentation_demo.cpp @@ -254,7 +254,7 @@ OrganizedSegmentationDemo::OrganizedSegmentationDemo (pcl::Grabber& grabber) : g euclidean_comparator_.reset (new pcl::EuclideanPlaneCoefficientComparator ()); rgb_comparator_.reset (new pcl::RGBPlaneCoefficientComparator ()); edge_aware_comparator_.reset (new pcl::EdgeAwarePlaneComparator ()); - euclidean_cluster_comparator_ = pcl::EuclideanClusterComparator::Ptr (new pcl::EuclideanClusterComparator ()); + euclidean_cluster_comparator_ = pcl::EuclideanClusterComparator::Ptr (new pcl::EuclideanClusterComparator ()); // Set up Organized Multi Plane Segmentation mps.setMinInliers (10000); diff --git a/apps/src/pcd_select_object_plane.cpp b/apps/src/pcd_select_object_plane.cpp index 052c1174d45..1eb5338afa8 100644 --- a/apps/src/pcd_select_object_plane.cpp +++ b/apps/src/pcd_select_object_plane.cpp @@ -194,7 +194,7 @@ class ObjectSelection if (cloud_->isOrganized ()) { // Use an organized clustering segmentation to extract the individual clusters - typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); + typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); euclidean_cluster_comparator->setInputCloud (cloud); euclidean_cluster_comparator->setDistanceThreshold (0.03f, false); // Set the entire scene to false, and the inliers of the objects located on top of the plane to true diff --git a/apps/src/stereo_ground_segmentation.cpp b/apps/src/stereo_ground_segmentation.cpp index 70ba86dfbaa..81aad6591a7 100755 --- a/apps/src/stereo_ground_segmentation.cpp +++ b/apps/src/stereo_ground_segmentation.cpp @@ -397,7 +397,7 @@ class HRCSSegmentation for (size_t i = 0; i < region_indices.size (); ++i) (*plane_labels)[i] = (region_indices[i].indices.size () > mps.getMinInliers ()); - pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_ (new pcl::EuclideanClusterComparator ()); + pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_ (new pcl::EuclideanClusterComparator ()); euclidean_cluster_comparator_->setInputCloud (cloud); euclidean_cluster_comparator_->setLabels (labels_ptr); euclidean_cluster_comparator_->setExcludeLabels (plane_labels); diff --git a/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h b/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h index d88f010bb35..7001c9c8d4e 100644 --- a/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h +++ b/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h @@ -45,13 +45,8 @@ namespace pcl { - /** \brief EuclideanClusterComparator is a comparator used for finding clusters supported by planar surfaces. - * This needs to be run as a second pass after extracting planar surfaces, using MultiPlaneSegmentation for example. - * - * \author Alex Trevor - */ template - class EuclideanClusterComparator: public Comparator + class EuclideanClusterComparator2: public Comparator { protected: @@ -65,27 +60,13 @@ namespace pcl typedef typename PointCloudL::Ptr PointCloudLPtr; typedef typename PointCloudL::ConstPtr PointCloudLConstPtr; - typedef boost::shared_ptr > Ptr; - typedef boost::shared_ptr > ConstPtr; + typedef boost::shared_ptr > Ptr; + typedef boost::shared_ptr > ConstPtr; typedef std::map ExcludeLabelMap; typedef boost::shared_ptr ExcludeLabelMapPtr; typedef boost::shared_ptr ExcludeLabelMapConstPtr; - /** \brief Empty constructor for EuclideanClusterComparator. */ - EuclideanClusterComparator () - : distance_threshold_ (0.005f) - , depth_dependent_ () - , z_axis_ () - { - } - - /** \brief Destructor for EuclideanClusterComparator. */ - virtual - ~EuclideanClusterComparator () - { - } - virtual void setInputCloud (const PointCloudConstPtr& cloud) { @@ -173,6 +154,14 @@ namespace pcl protected: + /** \brief Default constructor for EuclideanClusterComparator2. */ + EuclideanClusterComparator2 () + : distance_threshold_ (0.005f) + , depth_dependent_ () + , z_axis_ () + {} + + /** \brief Set of labels with similar size as the input point cloud, * aggregating points into groups based on a similar label identifier. * @@ -194,6 +183,82 @@ namespace pcl Eigen::Vector3f z_axis_; }; + + /** \brief EuclideanClusterComparator is a comparator used for finding clusters based on euclidian distance. + * + * \author Alex Trevor + */ + PCL_PRAGMA_WARNING ("EuclideanClusterComparator will no longer be templated on a PointNormal type in future minor release") + template + class EuclideanClusterComparator: public EuclideanClusterComparator2 + { + protected: + + using EuclideanClusterComparator2::exclude_labels_; + + public: + + typedef typename pcl::PointCloud PointCloudN; + typedef typename PointCloudN::Ptr PointCloudNPtr; + typedef typename PointCloudN::ConstPtr PointCloudNConstPtr; + + typedef boost::shared_ptr > Ptr; + typedef boost::shared_ptr > ConstPtr; + + using EuclideanClusterComparator2::setExcludeLabels; + + /** \brief Empty constructor for EuclideanClusterComparator. */ + EuclideanClusterComparator () + : normals_ () + , angular_threshold_ (0.0f) + {} + + /** \brief Provide a pointer to the input normals. + * \param[in] normals the input normal cloud + */ + inline void + PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of normals.") + setInputNormals (const PointCloudNConstPtr& normals) { normals_ = normals; } + + /** \brief Get the input normals. */ + inline PointCloudNConstPtr + PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of normals.") + getInputNormals () const { return (normals_); } + + /** \brief Set the tolerance in radians for difference in normal direction between neighboring points, to be considered part of the same plane. + * \param[in] angular_threshold the tolerance in radians + */ + inline void + PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of the angular threshold.") + setAngularThreshold (float angular_threshold) + { + angular_threshold_ = std::cos (angular_threshold); + } + + /** \brief Get the angular threshold in radians for difference in normal direction between neighboring points, to be considered part of the same plane. */ + inline float + PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of the angular threshold.") + getAngularThreshold () const { return (std::acos (angular_threshold_) ); } + + /** \brief Set labels in the label cloud to exclude. + * \param[in] exclude_labels a vector of bools corresponding to whether or not a given label should be considered + */ + void + PCL_DEPRECATED ("Use setExcludeLabels (const ExcludeLabelSetConstPtr &) instead") + setExcludeLabels (const std::vector& exclude_labels) + { + exclude_labels_ = boost::make_shared > (); + for (uint32_t i = 0; i < exclude_labels.size (); ++i) + if (exclude_labels[i]) + exclude_labels_->insert (i); + } + + protected: + + PointCloudNConstPtr normals_; + + float angular_threshold_; + }; } #endif // PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_ From 3f91a88e682dca0f287312a523e79fdf04287976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Agostinho?= Date: Tue, 21 Nov 2017 19:20:35 +0000 Subject: [PATCH 3/4] Replace exclude_labels map for a set in EuclideanClusterComparator --- .../tools/impl/organized_segmentation.hpp | 5 +++-- apps/src/ni_linemod.cpp | 5 ++--- apps/src/organized_segmentation_demo.cpp | 5 +++-- apps/src/pcd_select_object_plane.cpp | 5 ++--- apps/src/stereo_ground_segmentation.cpp | 5 +++-- .../euclidean_cluster_comparator.h | 20 +++++++++---------- 6 files changed, 23 insertions(+), 22 deletions(-) diff --git a/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp b/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp index 9a7d0d980ea..00f56616e67 100644 --- a/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp +++ b/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp @@ -103,9 +103,10 @@ std::vector boundary_indices; mps.segmentAndRefine (regions, model_coefficients, inlier_indices, labels, label_indices, boundary_indices); - boost::shared_ptr > plane_labels = boost::make_shared > (); + boost::shared_ptr > plane_labels = boost::make_shared > (); for (size_t i = 0; i < label_indices.size (); ++i) - (*plane_labels)[i] = (label_indices[i].indices.size () > (size_t) min_plane_size); + if (label_indices[i].indices.size () > (size_t) min_plane_size) + plane_labels->insert (i); typename PointCloud::CloudVectorType clusters; typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator = diff --git a/apps/src/ni_linemod.cpp b/apps/src/ni_linemod.cpp index 97886eeb3c0..d582f0a1b11 100644 --- a/apps/src/ni_linemod.cpp +++ b/apps/src/ni_linemod.cpp @@ -260,9 +260,8 @@ class NILinemod scene->points[points_above_plane->indices[i]].label = 1; euclidean_cluster_comparator->setLabels (scene); - boost::shared_ptr > exclude_labels = boost::make_shared > (); - (*exclude_labels)[0] = true; - (*exclude_labels)[1] = false; + boost::shared_ptr > exclude_labels = boost::make_shared > (); + exclude_labels->insert (0); OrganizedConnectedComponentSegmentation euclidean_segmentation (euclidean_cluster_comparator); euclidean_segmentation.setInputCloud (cloud); diff --git a/apps/src/organized_segmentation_demo.cpp b/apps/src/organized_segmentation_demo.cpp index 95e5f83ebf2..6cc273dbcdd 100644 --- a/apps/src/organized_segmentation_demo.cpp +++ b/apps/src/organized_segmentation_demo.cpp @@ -309,9 +309,10 @@ OrganizedSegmentationDemo::cloud_cb (const CloudConstPtr& cloud) if (use_clustering_ && regions.size () > 0) { - boost::shared_ptr > plane_labels = boost::make_shared > (); + boost::shared_ptr > plane_labels = boost::make_shared > (); for (size_t i = 0; i < label_indices.size (); ++i) - (*plane_labels)[i] = (label_indices[i].indices.size () > 10000); + if (label_indices[i].indices.size () > 10000) + plane_labels->insert (i); euclidean_cluster_comparator_->setInputCloud (cloud); euclidean_cluster_comparator_->setLabels (labels); diff --git a/apps/src/pcd_select_object_plane.cpp b/apps/src/pcd_select_object_plane.cpp index 1eb5338afa8..a4a26b9e82b 100644 --- a/apps/src/pcd_select_object_plane.cpp +++ b/apps/src/pcd_select_object_plane.cpp @@ -205,9 +205,8 @@ class ObjectSelection scene->points[points_above_plane->indices[i]].label = 1; euclidean_cluster_comparator->setLabels (scene); - boost::shared_ptr > exclude_labels = boost::make_shared > (); - (*exclude_labels)[0] = true; - (*exclude_labels)[1] = false; + boost::shared_ptr > exclude_labels = boost::make_shared > (); + exclude_labels->insert (0); euclidean_cluster_comparator->setExcludeLabels (exclude_labels); OrganizedConnectedComponentSegmentation euclidean_segmentation (euclidean_cluster_comparator); diff --git a/apps/src/stereo_ground_segmentation.cpp b/apps/src/stereo_ground_segmentation.cpp index 81aad6591a7..99f8874cc4b 100755 --- a/apps/src/stereo_ground_segmentation.cpp +++ b/apps/src/stereo_ground_segmentation.cpp @@ -393,9 +393,10 @@ class HRCSSegmentation pcl::PointCloud::CloudVectorType clusters; if (ground_cloud->points.size () > 0) { - boost::shared_ptr > plane_labels = boost::make_shared > (); + boost::shared_ptr > plane_labels = boost::make_shared > (); for (size_t i = 0; i < region_indices.size (); ++i) - (*plane_labels)[i] = (region_indices[i].indices.size () > mps.getMinInliers ()); + if ((region_indices[i].indices.size () > mps.getMinInliers ())) + plane_labels->insert (i); pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_ (new pcl::EuclideanClusterComparator ()); euclidean_cluster_comparator_->setInputCloud (cloud); diff --git a/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h b/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h index 7001c9c8d4e..911382989e9 100644 --- a/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h +++ b/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h @@ -63,9 +63,9 @@ namespace pcl typedef boost::shared_ptr > Ptr; typedef boost::shared_ptr > ConstPtr; - typedef std::map ExcludeLabelMap; - typedef boost::shared_ptr ExcludeLabelMapPtr; - typedef boost::shared_ptr ExcludeLabelMapConstPtr; + typedef std::set ExcludeLabelSet; + typedef boost::shared_ptr ExcludeLabelSetPtr; + typedef boost::shared_ptr ExcludeLabelSetConstPtr; virtual void setInputCloud (const PointCloudConstPtr& cloud) @@ -102,7 +102,7 @@ namespace pcl labels_ = labels; } - const ExcludeLabelMapConstPtr& + const ExcludeLabelSetConstPtr& getExcludeLabels () const { return exclude_labels_; @@ -112,7 +112,7 @@ namespace pcl * \param exclude_labels a vector of bools corresponding to whether or not a given label should be considered */ void - setExcludeLabels (const ExcludeLabelMapConstPtr &exclude_labels) + setExcludeLabels (const ExcludeLabelSetConstPtr &exclude_labels) { exclude_labels_ = exclude_labels; } @@ -130,12 +130,12 @@ namespace pcl const uint32_t &label1 = (*labels_)[idx1].label; const uint32_t &label2 = (*labels_)[idx2].label; - const std::map::const_iterator it1 = exclude_labels_->find (label1); - if ((it1 == exclude_labels_->end ()) || it1->second) + const std::set::const_iterator it1 = exclude_labels_->find (label1); + if (it1 == exclude_labels_->end ()) return false; - const std::map::const_iterator it2 = exclude_labels_->find (label2); - if ((it2 == exclude_labels_->end ()) || it2->second) + const std::set::const_iterator it2 = exclude_labels_->find (label2); + if (it2 == exclude_labels_->end ()) return false; } @@ -175,7 +175,7 @@ namespace pcl * If a label is not specified, it's assumed by default that it's * intended be excluded */ - ExcludeLabelMapConstPtr exclude_labels_; + ExcludeLabelSetConstPtr exclude_labels_; float distance_threshold_; From c3f471096f56a9054beaa072a7e3d679947a59fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Agostinho?= Date: Sat, 25 Nov 2017 16:39:37 +0000 Subject: [PATCH 4/4] New ECC deprecation strategy --- .../tools/impl/organized_segmentation.hpp | 4 +- .../pcl/apps/organized_segmentation_demo.h | 2 +- apps/src/ni_linemod.cpp | 2 +- apps/src/organized_segmentation_demo.cpp | 2 +- apps/src/pcd_select_object_plane.cpp | 2 +- apps/src/stereo_ground_segmentation.cpp | 2 +- common/include/pcl/point_traits.h | 7 + .../euclidean_cluster_comparator.h | 269 ++++++++++-------- 8 files changed, 157 insertions(+), 133 deletions(-) diff --git a/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp b/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp index 00f56616e67..b3e8e12d280 100644 --- a/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp +++ b/apps/cloud_composer/include/pcl/apps/cloud_composer/tools/impl/organized_segmentation.hpp @@ -109,8 +109,8 @@ plane_labels->insert (i); typename PointCloud::CloudVectorType clusters; - typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator = - boost::make_shared > (); + typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator = + boost::make_shared > (); euclidean_cluster_comparator->setInputCloud (input_cloud); euclidean_cluster_comparator->setLabels (labels); euclidean_cluster_comparator->setExcludeLabels (plane_labels); diff --git a/apps/include/pcl/apps/organized_segmentation_demo.h b/apps/include/pcl/apps/organized_segmentation_demo.h index d2c11796849..2d873a347ab 100644 --- a/apps/include/pcl/apps/organized_segmentation_demo.h +++ b/apps/include/pcl/apps/organized_segmentation_demo.h @@ -139,7 +139,7 @@ class OrganizedSegmentationDemo : public QMainWindow pcl::RGBPlaneCoefficientComparator::Ptr rgb_comparator_; pcl::RGBPlaneCoefficientComparator rgb_comp_; pcl::EdgeAwarePlaneComparator::Ptr edge_aware_comparator_; - pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_; + pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_; public Q_SLOTS: void toggleCapturePressed() diff --git a/apps/src/ni_linemod.cpp b/apps/src/ni_linemod.cpp index d582f0a1b11..bc84a7ad1fe 100644 --- a/apps/src/ni_linemod.cpp +++ b/apps/src/ni_linemod.cpp @@ -249,7 +249,7 @@ class NILinemod exppd.segment (*points_above_plane); // Use an organized clustering segmentation to extract the individual clusters - EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); + EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); euclidean_cluster_comparator->setInputCloud (cloud); euclidean_cluster_comparator->setDistanceThreshold (0.03f, false); // Set the entire scene to false, and the inliers of the objects located on top of the plane to true diff --git a/apps/src/organized_segmentation_demo.cpp b/apps/src/organized_segmentation_demo.cpp index 6cc273dbcdd..6d4df4803a6 100644 --- a/apps/src/organized_segmentation_demo.cpp +++ b/apps/src/organized_segmentation_demo.cpp @@ -254,7 +254,7 @@ OrganizedSegmentationDemo::OrganizedSegmentationDemo (pcl::Grabber& grabber) : g euclidean_comparator_.reset (new pcl::EuclideanPlaneCoefficientComparator ()); rgb_comparator_.reset (new pcl::RGBPlaneCoefficientComparator ()); edge_aware_comparator_.reset (new pcl::EdgeAwarePlaneComparator ()); - euclidean_cluster_comparator_ = pcl::EuclideanClusterComparator::Ptr (new pcl::EuclideanClusterComparator ()); + euclidean_cluster_comparator_ = pcl::EuclideanClusterComparator::Ptr (new pcl::EuclideanClusterComparator ()); // Set up Organized Multi Plane Segmentation mps.setMinInliers (10000); diff --git a/apps/src/pcd_select_object_plane.cpp b/apps/src/pcd_select_object_plane.cpp index a4a26b9e82b..0ea6215c02a 100644 --- a/apps/src/pcd_select_object_plane.cpp +++ b/apps/src/pcd_select_object_plane.cpp @@ -194,7 +194,7 @@ class ObjectSelection if (cloud_->isOrganized ()) { // Use an organized clustering segmentation to extract the individual clusters - typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); + typename EuclideanClusterComparator::Ptr euclidean_cluster_comparator (new EuclideanClusterComparator); euclidean_cluster_comparator->setInputCloud (cloud); euclidean_cluster_comparator->setDistanceThreshold (0.03f, false); // Set the entire scene to false, and the inliers of the objects located on top of the plane to true diff --git a/apps/src/stereo_ground_segmentation.cpp b/apps/src/stereo_ground_segmentation.cpp index 99f8874cc4b..855eab5dc81 100755 --- a/apps/src/stereo_ground_segmentation.cpp +++ b/apps/src/stereo_ground_segmentation.cpp @@ -398,7 +398,7 @@ class HRCSSegmentation if ((region_indices[i].indices.size () > mps.getMinInliers ())) plane_labels->insert (i); - pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_ (new pcl::EuclideanClusterComparator ()); + pcl::EuclideanClusterComparator::Ptr euclidean_cluster_comparator_ (new pcl::EuclideanClusterComparator ()); euclidean_cluster_comparator_->setInputCloud (cloud); euclidean_cluster_comparator_->setLabels (labels_ptr); euclidean_cluster_comparator_->setExcludeLabels (plane_labels); diff --git a/common/include/pcl/point_traits.h b/common/include/pcl/point_traits.h index 7d3d97a18cc..d30e760fefd 100644 --- a/common/include/pcl/point_traits.h +++ b/common/include/pcl/point_traits.h @@ -61,6 +61,13 @@ namespace pcl { + namespace deprecated + { + /** \class DeprecatedType + * \brief A dummy type to aid in template parameter deprecation + */ + struct T {}; + } namespace fields { diff --git a/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h b/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h index 911382989e9..d7922308fb9 100644 --- a/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h +++ b/segmentation/include/pcl/segmentation/euclidean_cluster_comparator.h @@ -42,159 +42,163 @@ #include #include +#include namespace pcl { - template - class EuclideanClusterComparator2: public Comparator + namespace experimental { - protected: + template + class EuclideanClusterComparator : public ::pcl::Comparator + { + protected: - using pcl::Comparator::input_; + using pcl::Comparator::input_; - public: - using typename Comparator::PointCloud; - using typename Comparator::PointCloudConstPtr; - - typedef typename pcl::PointCloud PointCloudL; - typedef typename PointCloudL::Ptr PointCloudLPtr; - typedef typename PointCloudL::ConstPtr PointCloudLConstPtr; - - typedef boost::shared_ptr > Ptr; - typedef boost::shared_ptr > ConstPtr; - - typedef std::set ExcludeLabelSet; - typedef boost::shared_ptr ExcludeLabelSetPtr; - typedef boost::shared_ptr ExcludeLabelSetConstPtr; - - virtual void - setInputCloud (const PointCloudConstPtr& cloud) - { - input_ = cloud; - Eigen::Matrix3f rot = input_->sensor_orientation_.toRotationMatrix (); - z_axis_ = rot.col (2); - } - - /** \brief Set the tolerance in meters for difference in perpendicular distance (d component of plane equation) to the plane between neighboring points, to be considered part of the same plane. - * \param[in] distance_threshold the tolerance in meters - * \param depth_dependent - */ - inline void - setDistanceThreshold (float distance_threshold, bool depth_dependent) - { - distance_threshold_ = distance_threshold; - depth_dependent_ = depth_dependent; - } + public: + using typename Comparator::PointCloud; + using typename Comparator::PointCloudConstPtr; - /** \brief Get the distance threshold in meters (d component of plane equation) between neighboring points, to be considered part of the same plane. */ - inline float - getDistanceThreshold () const - { - return (distance_threshold_); - } + typedef typename pcl::PointCloud PointCloudL; + typedef typename PointCloudL::Ptr PointCloudLPtr; + typedef typename PointCloudL::ConstPtr PointCloudLConstPtr; - /** \brief Set label cloud - * \param[in] labels The label cloud - */ - void - setLabels (const PointCloudLPtr& labels) - { - labels_ = labels; - } + typedef boost::shared_ptr > Ptr; + typedef boost::shared_ptr > ConstPtr; - const ExcludeLabelSetConstPtr& - getExcludeLabels () const - { - return exclude_labels_; - } + typedef std::set ExcludeLabelSet; + typedef boost::shared_ptr ExcludeLabelSetPtr; + typedef boost::shared_ptr ExcludeLabelSetConstPtr; - /** \brief Set labels in the label cloud to exclude. - * \param exclude_labels a vector of bools corresponding to whether or not a given label should be considered - */ - void - setExcludeLabels (const ExcludeLabelSetConstPtr &exclude_labels) - { - exclude_labels_ = exclude_labels; - } + /** \brief Default constructor for EuclideanClusterComparator. */ + EuclideanClusterComparator () + : distance_threshold_ (0.005f) + , depth_dependent_ () + , z_axis_ () + {} - /** \brief Compare points at two indices by their euclidean distance - * \param idx1 The first index for the comparison - * \param idx2 The second index for the comparison - */ - virtual bool - compare (int idx1, int idx2) const - { - if (labels_ && exclude_labels_) + virtual void + setInputCloud (const PointCloudConstPtr& cloud) { - assert (labels_->size () == input_->size ()); - const uint32_t &label1 = (*labels_)[idx1].label; - const uint32_t &label2 = (*labels_)[idx2].label; + input_ = cloud; + Eigen::Matrix3f rot = input_->sensor_orientation_.toRotationMatrix (); + z_axis_ = rot.col (2); + } - const std::set::const_iterator it1 = exclude_labels_->find (label1); - if (it1 == exclude_labels_->end ()) - return false; + /** \brief Set the tolerance in meters for difference in perpendicular distance (d component of plane equation) to the plane between neighboring points, to be considered part of the same plane. + * \param[in] distance_threshold the tolerance in meters + * \param depth_dependent + */ + inline void + setDistanceThreshold (float distance_threshold, bool depth_dependent) + { + distance_threshold_ = distance_threshold; + depth_dependent_ = depth_dependent; + } - const std::set::const_iterator it2 = exclude_labels_->find (label2); - if (it2 == exclude_labels_->end ()) - return false; + /** \brief Get the distance threshold in meters (d component of plane equation) between neighboring points, to be considered part of the same plane. */ + inline float + getDistanceThreshold () const + { + return (distance_threshold_); } - - float dist_threshold = distance_threshold_; - if (depth_dependent_) + + /** \brief Set label cloud + * \param[in] labels The label cloud + */ + void + setLabels (const PointCloudLPtr& labels) { - Eigen::Vector3f vec = input_->points[idx1].getVector3fMap (); - float z = vec.dot (z_axis_); - dist_threshold *= z * z; + labels_ = labels; } - const float dist = ((*input_)[idx1].getVector3fMap () - - (*input_)[idx2].getVector3fMap ()).norm (); - return (dist < dist_threshold); - } - - protected: + const ExcludeLabelSetConstPtr& + getExcludeLabels () const + { + return exclude_labels_; + } - /** \brief Default constructor for EuclideanClusterComparator2. */ - EuclideanClusterComparator2 () - : distance_threshold_ (0.005f) - , depth_dependent_ () - , z_axis_ () - {} + /** \brief Set labels in the label cloud to exclude. + * \param exclude_labels a vector of bools corresponding to whether or not a given label should be considered + */ + void + setExcludeLabels (const ExcludeLabelSetConstPtr &exclude_labels) + { + exclude_labels_ = exclude_labels; + } + /** \brief Compare points at two indices by their euclidean distance + * \param idx1 The first index for the comparison + * \param idx2 The second index for the comparison + */ + virtual bool + compare (int idx1, int idx2) const + { + if (labels_ && exclude_labels_) + { + assert (labels_->size () == input_->size ()); + const uint32_t &label1 = (*labels_)[idx1].label; + const uint32_t &label2 = (*labels_)[idx2].label; + + const std::set::const_iterator it1 = exclude_labels_->find (label1); + if (it1 == exclude_labels_->end ()) + return false; + + const std::set::const_iterator it2 = exclude_labels_->find (label2); + if (it2 == exclude_labels_->end ()) + return false; + } + + float dist_threshold = distance_threshold_; + if (depth_dependent_) + { + Eigen::Vector3f vec = input_->points[idx1].getVector3fMap (); + float z = vec.dot (z_axis_); + dist_threshold *= z * z; + } + + const float dist = ((*input_)[idx1].getVector3fMap () + - (*input_)[idx2].getVector3fMap ()).norm (); + return (dist < dist_threshold); + } - /** \brief Set of labels with similar size as the input point cloud, - * aggregating points into groups based on a similar label identifier. - * - * It needs to be set in conjunction with the \ref exclude_labels_ - * member in order to provided a masking functionality. - */ - PointCloudLPtr labels_; + protected: - /** \brief Specifies which labels should be excluded com being clustered. - * - * If a label is not specified, it's assumed by default that it's - * intended be excluded - */ - ExcludeLabelSetConstPtr exclude_labels_; - float distance_threshold_; + /** \brief Set of labels with similar size as the input point cloud, + * aggregating points into groups based on a similar label identifier. + * + * It needs to be set in conjunction with the \ref exclude_labels_ + * member in order to provided a masking functionality. + */ + PointCloudLPtr labels_; - bool depth_dependent_; + /** \brief Specifies which labels should be excluded com being clustered. + * + * If a label is not specified, it's assumed by default that it's + * intended be excluded + */ + ExcludeLabelSetConstPtr exclude_labels_; + + float distance_threshold_; + + bool depth_dependent_; + + Eigen::Vector3f z_axis_; + }; + } // namespace experimental - Eigen::Vector3f z_axis_; - }; /** \brief EuclideanClusterComparator is a comparator used for finding clusters based on euclidian distance. * * \author Alex Trevor */ - PCL_PRAGMA_WARNING ("EuclideanClusterComparator will no longer be templated on a PointNormal type in future minor release") - template - class EuclideanClusterComparator: public EuclideanClusterComparator2 + template + class EuclideanClusterComparator : public experimental::EuclideanClusterComparator { protected: - using EuclideanClusterComparator2::exclude_labels_; + using experimental::EuclideanClusterComparator::exclude_labels_; public: @@ -205,9 +209,10 @@ namespace pcl typedef boost::shared_ptr > Ptr; typedef boost::shared_ptr > ConstPtr; - using EuclideanClusterComparator2::setExcludeLabels; + using experimental::EuclideanClusterComparator::setExcludeLabels; - /** \brief Empty constructor for EuclideanClusterComparator. */ + /** \brief Default constructor for EuclideanClusterComparator. */ + PCL_DEPRECATED ("Remove PointNT from template parameters.") EuclideanClusterComparator () : normals_ () , angular_threshold_ (0.0f) @@ -217,19 +222,25 @@ namespace pcl * \param[in] normals the input normal cloud */ inline void - PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of normals.") + PCL_DEPRECATED ("EuclideadClusterComparator never actually used normals and angular threshold, " + "this function has no effect on the behavior of the comparator. Therefore it is " + "deprecated and will be removed in future releases.") setInputNormals (const PointCloudNConstPtr& normals) { normals_ = normals; } /** \brief Get the input normals. */ inline PointCloudNConstPtr - PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of normals.") + PCL_DEPRECATED ("EuclideadClusterComparator never actually used normals and angular threshold, " + "this function has no effect on the behavior of the comparator. Therefore it is " + "deprecated and will be removed in future releases.") getInputNormals () const { return (normals_); } /** \brief Set the tolerance in radians for difference in normal direction between neighboring points, to be considered part of the same plane. * \param[in] angular_threshold the tolerance in radians */ inline void - PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of the angular threshold.") + PCL_DEPRECATED ("EuclideadClusterComparator never actually used normals and angular threshold, " + "this function has no effect on the behavior of the comparator. Therefore it is " + "deprecated and will be removed in future releases.") setAngularThreshold (float angular_threshold) { angular_threshold_ = std::cos (angular_threshold); @@ -237,7 +248,9 @@ namespace pcl /** \brief Get the angular threshold in radians for difference in normal direction between neighboring points, to be considered part of the same plane. */ inline float - PCL_DEPRECATED ("EuclideanClusterComparator no longer makes use of the angular threshold.") + PCL_DEPRECATED ("EuclideadClusterComparator never actually used normals and angular threshold, " + "this function has no effect on the behavior of the comparator. Therefore it is " + "deprecated and will be removed in future releases.") getAngularThreshold () const { return (std::acos (angular_threshold_) ); } /** \brief Set labels in the label cloud to exclude. @@ -259,6 +272,10 @@ namespace pcl float angular_threshold_; }; + + template + class EuclideanClusterComparator + : public experimental::EuclideanClusterComparator {}; } #endif // PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_