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] 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_