Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 #ifndef PCL_SEGMENTATION_EUCLIDEAN_CLUSTER_COMPARATOR_H_
00041 #define PCL_SEGMENTATION_EUCLIDEAN_CLUSTER_COMPARATOR_H_
00042
00043 #include <pcl/segmentation/boost.h>
00044 #include <pcl/segmentation/comparator.h>
00045
00046 namespace pcl
00047 {
00053 template<typename PointT, typename PointNT, typename PointLT>
00054 class EuclideanClusterComparator: public Comparator<PointT>
00055 {
00056 public:
00057 typedef typename Comparator<PointT>::PointCloud PointCloud;
00058 typedef typename Comparator<PointT>::PointCloudConstPtr PointCloudConstPtr;
00059
00060 typedef typename pcl::PointCloud<PointNT> PointCloudN;
00061 typedef typename PointCloudN::Ptr PointCloudNPtr;
00062 typedef typename PointCloudN::ConstPtr PointCloudNConstPtr;
00063
00064 typedef typename pcl::PointCloud<PointLT> PointCloudL;
00065 typedef typename PointCloudL::Ptr PointCloudLPtr;
00066 typedef typename PointCloudL::ConstPtr PointCloudLConstPtr;
00067
00068 typedef boost::shared_ptr<EuclideanClusterComparator<PointT, PointNT, PointLT> > Ptr;
00069 typedef boost::shared_ptr<const EuclideanClusterComparator<PointT, PointNT, PointLT> > ConstPtr;
00070
00071 using pcl::Comparator<PointT>::input_;
00072
00074 EuclideanClusterComparator ()
00075 : normals_ ()
00076 , angular_threshold_ (0.0f)
00077 , distance_threshold_ (0.005f)
00078 , depth_dependent_ ()
00079 , z_axis_ ()
00080 {
00081 }
00082
00084 virtual
00085 ~EuclideanClusterComparator ()
00086 {
00087 }
00088
00089 virtual void
00090 setInputCloud (const PointCloudConstPtr& cloud)
00091 {
00092 input_ = cloud;
00093 Eigen::Matrix3f rot = input_->sensor_orientation_.toRotationMatrix ();
00094 z_axis_ = rot.col (2);
00095 }
00096
00100 inline void
00101 setInputNormals (const PointCloudNConstPtr &normals)
00102 {
00103 normals_ = normals;
00104 }
00105
00107 inline PointCloudNConstPtr
00108 getInputNormals () const
00109 {
00110 return (normals_);
00111 }
00112
00116 virtual inline void
00117 setAngularThreshold (float angular_threshold)
00118 {
00119 angular_threshold_ = cosf (angular_threshold);
00120 }
00121
00123 inline float
00124 getAngularThreshold () const
00125 {
00126 return (acos (angular_threshold_) );
00127 }
00128
00132 inline void
00133 setDistanceThreshold (float distance_threshold, bool depth_dependent)
00134 {
00135 distance_threshold_ = distance_threshold;
00136 depth_dependent_ = depth_dependent;
00137 }
00138
00140 inline float
00141 getDistanceThreshold () const
00142 {
00143 return (distance_threshold_);
00144 }
00145
00149 void
00150 setLabels (PointCloudLPtr& labels)
00151 {
00152 labels_ = labels;
00153 }
00154
00158 void
00159 setExcludeLabels (std::vector<bool>& exclude_labels)
00160 {
00161 exclude_labels_ = boost::make_shared<std::vector<bool> >(exclude_labels);
00162 }
00163
00169 virtual bool
00170 compare (int idx1, int idx2) const
00171 {
00172 int label1 = labels_->points[idx1].label;
00173 int label2 = labels_->points[idx2].label;
00174
00175 if (label1 == -1 || label2 == -1)
00176 return false;
00177
00178 if ( (*exclude_labels_)[label1] || (*exclude_labels_)[label2])
00179 return false;
00180
00181 float dist_threshold = distance_threshold_;
00182 if (depth_dependent_)
00183 {
00184 Eigen::Vector3f vec = input_->points[idx1].getVector3fMap ();
00185 float z = vec.dot (z_axis_);
00186 dist_threshold *= z * z;
00187 }
00188
00189 float dx = input_->points[idx1].x - input_->points[idx2].x;
00190 float dy = input_->points[idx1].y - input_->points[idx2].y;
00191 float dz = input_->points[idx1].z - input_->points[idx2].z;
00192 float dist = sqrtf (dx*dx + dy*dy + dz*dz);
00193
00194 return (dist < dist_threshold);
00195 }
00196
00197 protected:
00198 PointCloudNConstPtr normals_;
00199 PointCloudLPtr labels_;
00200
00201 boost::shared_ptr<std::vector<bool> > exclude_labels_;
00202 float angular_threshold_;
00203 float distance_threshold_;
00204 bool depth_dependent_;
00205 Eigen::Vector3f z_axis_;
00206 };
00207 }
00208
00209 #endif // PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_