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_PLANE_COEFFICIENT_COMPARATOR_H_
00041 #define PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_
00042
00043 #include <pcl/common/angles.h>
00044 #include <pcl/segmentation/comparator.h>
00045 #include <boost/make_shared.hpp>
00046
00047 namespace pcl
00048 {
00054 template<typename PointT, typename PointNT>
00055 class PlaneCoefficientComparator: public Comparator<PointT>
00056 {
00057 public:
00058 typedef typename Comparator<PointT>::PointCloud PointCloud;
00059 typedef typename Comparator<PointT>::PointCloudConstPtr PointCloudConstPtr;
00060
00061 typedef typename pcl::PointCloud<PointNT> PointCloudN;
00062 typedef typename PointCloudN::Ptr PointCloudNPtr;
00063 typedef typename PointCloudN::ConstPtr PointCloudNConstPtr;
00064
00065 typedef boost::shared_ptr<PlaneCoefficientComparator<PointT, PointNT> > Ptr;
00066 typedef boost::shared_ptr<const PlaneCoefficientComparator<PointT, PointNT> > ConstPtr;
00067
00068 using pcl::Comparator<PointT>::input_;
00069
00071 PlaneCoefficientComparator ()
00072 : normals_ ()
00073 , plane_coeff_d_ ()
00074 , angular_threshold_ (pcl::deg2rad (2.0f))
00075 , distance_threshold_ (0.02f)
00076 , depth_dependent_ (true)
00077 , z_axis_ (Eigen::Vector3f (0.0, 0.0, 1.0) )
00078 {
00079 }
00080
00084 PlaneCoefficientComparator (boost::shared_ptr<std::vector<float> >& plane_coeff_d)
00085 : normals_ ()
00086 , plane_coeff_d_ (plane_coeff_d)
00087 , angular_threshold_ (pcl::deg2rad (2.0f))
00088 , distance_threshold_ (0.02f)
00089 , depth_dependent_ (true)
00090 , z_axis_ (Eigen::Vector3f (0.0f, 0.0f, 1.0f) )
00091 {
00092 }
00093
00095 virtual
00096 ~PlaneCoefficientComparator ()
00097 {
00098 }
00099
00100 virtual void
00101 setInputCloud (const PointCloudConstPtr& cloud)
00102 {
00103 input_ = cloud;
00104 }
00105
00109 inline void
00110 setInputNormals (const PointCloudNConstPtr &normals)
00111 {
00112 normals_ = normals;
00113 }
00114
00116 inline PointCloudNConstPtr
00117 getInputNormals () const
00118 {
00119 return (normals_);
00120 }
00121
00125 void
00126 setPlaneCoeffD (boost::shared_ptr<std::vector<float> >& plane_coeff_d)
00127 {
00128 plane_coeff_d_ = plane_coeff_d;
00129 }
00130
00134 void
00135 setPlaneCoeffD (std::vector<float>& plane_coeff_d)
00136 {
00137 plane_coeff_d_ = boost::make_shared<std::vector<float> >(plane_coeff_d);
00138 }
00139
00141 const std::vector<float>&
00142 getPlaneCoeffD () const
00143 {
00144 return (plane_coeff_d_);
00145 }
00146
00150 virtual void
00151 setAngularThreshold (float angular_threshold)
00152 {
00153 angular_threshold_ = cosf (angular_threshold);
00154 }
00155
00157 inline float
00158 getAngularThreshold () const
00159 {
00160 return (acosf (angular_threshold_) );
00161 }
00162
00167 void
00168 setDistanceThreshold (float distance_threshold,
00169 bool depth_dependent = false)
00170 {
00171 distance_threshold_ = distance_threshold;
00172 depth_dependent_ = depth_dependent;
00173 }
00174
00176 inline float
00177 getDistanceThreshold () const
00178 {
00179 return (distance_threshold_);
00180 }
00181
00187 virtual bool
00188 compare (int idx1, int idx2) const
00189 {
00190 float threshold = distance_threshold_;
00191 if (depth_dependent_)
00192 {
00193 Eigen::Vector3f vec = input_->points[idx1].getVector3fMap ();
00194
00195 float z = vec.dot (z_axis_);
00196 threshold *= z * z;
00197 }
00198 return ( (fabs ((*plane_coeff_d_)[idx1] - (*plane_coeff_d_)[idx2]) < threshold)
00199 && (normals_->points[idx1].getNormalVector3fMap ().dot (normals_->points[idx2].getNormalVector3fMap () ) > angular_threshold_ ) );
00200 }
00201
00202 protected:
00203 PointCloudNConstPtr normals_;
00204 boost::shared_ptr<std::vector<float> > plane_coeff_d_;
00205 float angular_threshold_;
00206 float distance_threshold_;
00207 bool depth_dependent_;
00208 Eigen::Vector3f z_axis_;
00209
00210 public:
00211 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00212 };
00213 }
00214
00215 #endif // PCL_SEGMENTATION_PLANE_COEFFICIENT_COMPARATOR_H_