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 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PLANE_H_
00039 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PLANE_H_
00040
00041 #include "pcl/sample_consensus/sac_model_normal_plane.h"
00042
00044
00049 template <typename PointT, typename PointNT> void
00050 pcl::SampleConsensusModelNormalPlane<PointT, PointNT>::selectWithinDistance (
00051 const Eigen::VectorXf &model_coefficients, double threshold, std::vector<int> &inliers)
00052 {
00053
00054 if (model_coefficients.size () != 4)
00055 {
00056 ROS_ERROR ("[pcl::SampleConsensusModelNormalPlane::selectWithinDistance] Invalid number of model coefficients given (%zu)!", model_coefficients.size ());
00057 return;
00058 }
00059
00060 if (!normals_)
00061 {
00062 ROS_ERROR ("[pcl::SampleConsensusModelNormalPlane::selectWithinDistance] No input dataset containing normals was given!");
00063 inliers.clear ();
00064 return;
00065 }
00066
00067
00068 if (!isModelValid (model_coefficients))
00069 {
00070 inliers.clear ();
00071 return;
00072 }
00073
00074
00075 Eigen::Vector4f coeff = model_coefficients;
00076 coeff[3] = 0;
00077
00078 int nr_p = 0;
00079 inliers.resize (indices_->size ());
00080
00081 for (size_t i = 0; i < indices_->size (); ++i)
00082 {
00083
00084
00085 Eigen::Vector4f p (input_->points[(*indices_)[i]].x, input_->points[(*indices_)[i]].y, input_->points[(*indices_)[i]].z, 0);
00086 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0], normals_->points[(*indices_)[i]].normal[1], normals_->points[(*indices_)[i]].normal[2], 0);
00087 double d_euclid = fabs (coeff.dot (p) + model_coefficients[3]);
00088
00089
00090 double d_normal = fabs (getAngle3D (n, coeff));
00091 d_normal = (std::min) (d_normal, M_PI - d_normal);
00092
00093 if (fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid) < threshold)
00094 {
00095
00096 inliers[nr_p] = (*indices_)[i];
00097 nr_p++;
00098 }
00099 }
00100 inliers.resize (nr_p);
00101 }
00102
00104
00108 template <typename PointT, typename PointNT> void
00109 pcl::SampleConsensusModelNormalPlane<PointT, PointNT>::getDistancesToModel (
00110 const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
00111 {
00112
00113 if (model_coefficients.size () != 4)
00114 {
00115 ROS_ERROR ("[pcl::SampleConsensusModelNormalPlane::selectWithinDistance] Invalid number of model coefficients given (%zu)!", model_coefficients.size ());
00116 return;
00117 }
00118
00119 if (!normals_)
00120 {
00121 ROS_ERROR ("[pcl::SampleConsensusModelNormalPlane::getDistancesToModel] No input dataset containing normals was given!");
00122 return;
00123 }
00124
00125
00126 if (!isModelValid (model_coefficients))
00127 {
00128 distances.clear ();
00129 return;
00130 }
00131
00132
00133 Eigen::Vector4f coeff = model_coefficients;
00134 coeff[3] = 0;
00135
00136 distances.resize (indices_->size ());
00137
00138
00139 for (size_t i = 0; i < indices_->size (); ++i)
00140 {
00141
00142
00143 Eigen::Vector4f p (input_->points[(*indices_)[i]].x, input_->points[(*indices_)[i]].y, input_->points[(*indices_)[i]].z, 0);
00144 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0], normals_->points[(*indices_)[i]].normal[1], normals_->points[(*indices_)[i]].normal[2], 0);
00145 double d_euclid = fabs (coeff.dot (p) + model_coefficients[3]);
00146
00147
00148 double d_normal = fabs (getAngle3D (n, coeff));
00149 d_normal = (std::min) (d_normal, M_PI - d_normal);
00150
00151 distances[i] = fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid);
00152 }
00153 }
00154
00156
00159 template <typename PointT, typename PointNT> bool
00160 pcl::SampleConsensusModelNormalPlane<PointT, PointNT>::isModelValid (const Eigen::VectorXf &model_coefficients)
00161 {
00162
00163 if (model_coefficients.size () != 4)
00164 {
00165 ROS_ERROR ("[pcl::SampleConsensusModelNormalPlane::selectWithinDistance] Invalid number of model coefficients given (%zu)!", model_coefficients.size ());
00166 return (false);
00167 }
00168
00169
00170 if (eps_angle_ > 0.0)
00171 {
00172
00173 Eigen::Vector4f coeff = model_coefficients;
00174 coeff[3] = 0;
00175
00176 Eigen::Vector4f axis (axis_[0], axis_[1], axis_[2], 0);
00177 double angle_diff = fabs (getAngle3D (axis, coeff));
00178 angle_diff = (std::min) (angle_diff, M_PI - angle_diff);
00179
00180 if (angle_diff > eps_angle_)
00181 return (false);
00182 }
00183
00184 if (eps_dist_ > 0.0)
00185 {
00186 if (fabs (-model_coefficients[3] - distance_from_origin_) > eps_dist_)
00187 return (false);
00188 }
00189
00190 return (true);
00191 }
00192
00193 #define PCL_INSTANTIATE_SampleConsensusModelNormalPlane(PointT, PointNT) template class pcl::SampleConsensusModelNormalPlane<PointT, PointNT>;
00194
00195 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PLANE_H_
00196