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