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_GROUND_PLANE_COMPARATOR_H_
00041 #define PCL_SEGMENTATION_GROUND_PLANE_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 GroundPlaneComparator: 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<GroundPlaneComparator<PointT, PointNT> > Ptr;
00066 typedef boost::shared_ptr<const GroundPlaneComparator<PointT, PointNT> > ConstPtr;
00067
00068 using pcl::Comparator<PointT>::input_;
00069
00071 GroundPlaneComparator ()
00072 : normals_ ()
00073 , plane_coeff_d_ ()
00074 , angular_threshold_ (cosf (pcl::deg2rad (2.0f)))
00075 , road_angular_threshold_ ( cosf(pcl::deg2rad (10.0f)))
00076 , distance_threshold_ (0.1f)
00077 , depth_dependent_ (true)
00078 , z_axis_ (Eigen::Vector3f (0.0, 0.0, 1.0) )
00079 , desired_road_axis_ (Eigen::Vector3f(0.0, -1.0, 0.0))
00080 {
00081 }
00082
00086 GroundPlaneComparator (boost::shared_ptr<std::vector<float> >& plane_coeff_d)
00087 : normals_ ()
00088 , plane_coeff_d_ (plane_coeff_d)
00089 , angular_threshold_ (cosf (pcl::deg2rad (3.0f)))
00090 , distance_threshold_ (0.1f)
00091 , depth_dependent_ (true)
00092 , z_axis_ (Eigen::Vector3f (0.0f, 0.0f, 1.0f))
00093 , road_angular_threshold_ ( cosf(pcl::deg2rad (40.0f)))
00094 , desired_road_axis_ (Eigen::Vector3f(0.0, -1.0, 0.0))
00095 {
00096 }
00097
00099 virtual
00100 ~GroundPlaneComparator ()
00101 {
00102 }
00106 virtual void
00107 setInputCloud (const PointCloudConstPtr& cloud)
00108 {
00109 input_ = cloud;
00110 }
00111
00115 inline void
00116 setInputNormals (const PointCloudNConstPtr &normals)
00117 {
00118 normals_ = normals;
00119 }
00120
00122 inline PointCloudNConstPtr
00123 getInputNormals () const
00124 {
00125 return (normals_);
00126 }
00127
00131 void
00132 setPlaneCoeffD (boost::shared_ptr<std::vector<float> >& plane_coeff_d)
00133 {
00134 plane_coeff_d_ = plane_coeff_d;
00135 }
00136
00140 void
00141 setPlaneCoeffD (std::vector<float>& plane_coeff_d)
00142 {
00143 plane_coeff_d_ = boost::make_shared<std::vector<float> >(plane_coeff_d);
00144 }
00145
00147 const std::vector<float>&
00148 getPlaneCoeffD () const
00149 {
00150 return (plane_coeff_d_);
00151 }
00152
00156 virtual void
00157 setAngularThreshold (float angular_threshold)
00158 {
00159 angular_threshold_ = cosf (angular_threshold);
00160 }
00161
00165 virtual void
00166 setGroundAngularThreshold (float angular_threshold)
00167 {
00168 road_angular_threshold_ = cosf (angular_threshold);
00169 }
00170
00174 void
00175 setExpectedGroundNormal (Eigen::Vector3f normal)
00176 {
00177 desired_road_axis_ = normal;
00178 }
00179
00180
00182 inline float
00183 getAngularThreshold () const
00184 {
00185 return (acosf (angular_threshold_) );
00186 }
00187
00192 void
00193 setDistanceThreshold (float distance_threshold,
00194 bool depth_dependent = false)
00195 {
00196 distance_threshold_ = distance_threshold;
00197 depth_dependent_ = depth_dependent;
00198 }
00199
00201 inline float
00202 getDistanceThreshold () const
00203 {
00204 return distance_threshold_;
00205 }
00206
00212 virtual bool
00213 compare (int idx1, int idx2) const
00214 {
00215
00216
00217 float threshold = distance_threshold_;
00218 if (depth_dependent_)
00219 {
00220 Eigen::Vector3f vec = input_->points[idx1].getVector3fMap ();
00221
00222 float z = vec.dot (z_axis_);
00223 threshold *= z * z;
00224 }
00225
00226 return ( (normals_->points[idx1].getNormalVector3fMap ().dot (desired_road_axis_) > road_angular_threshold_) &&
00227 (normals_->points[idx1].getNormalVector3fMap ().dot (normals_->points[idx2].getNormalVector3fMap () ) > angular_threshold_ ));
00228
00229
00230
00231
00232
00233 }
00234
00235 protected:
00236 PointCloudNConstPtr normals_;
00237 boost::shared_ptr<std::vector<float> > plane_coeff_d_;
00238 float angular_threshold_;
00239 float road_angular_threshold_;
00240 float distance_threshold_;
00241 bool depth_dependent_;
00242 Eigen::Vector3f z_axis_;
00243 Eigen::Vector3f desired_road_axis_;
00244
00245 public:
00246 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00247 };
00248 }
00249
00250 #endif // PCL_SEGMENTATION_GROUND_PLANE_COMPARATOR_H_