41 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PLANE_H_ 42 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PLANE_H_ 44 #include <pcl/sample_consensus/sac_model_normal_plane.h> 47 template <
typename Po
intT,
typename Po
intNT>
void 49 const Eigen::VectorXf &model_coefficients,
const double threshold, std::vector<int> &inliers)
53 PCL_ERROR (
"[pcl::SampleConsensusModelNormalPlane::selectWithinDistance] No input dataset containing normals was given!\n");
59 if (!isModelValid (model_coefficients))
66 Eigen::Vector4f coeff = model_coefficients;
70 inliers.resize (indices_->size ());
71 error_sqr_dists_.resize (indices_->size ());
74 for (
size_t i = 0; i < indices_->size (); ++i)
76 const PointT &pt = input_->points[(*indices_)[i]];
77 const PointNT &nt = normals_->points[(*indices_)[i]];
80 Eigen::Vector4f p (pt.x, pt.y, pt.z, 0);
81 Eigen::Vector4f n (nt.normal_x, nt.normal_y, nt.normal_z, 0);
82 double d_euclid = fabs (coeff.dot (p) + model_coefficients[3]);
85 double d_normal = fabs (
getAngle3D (n, coeff));
86 d_normal = (std::min) (d_normal, M_PI - d_normal);
89 double weight = normal_distance_weight_ * (1.0 - nt.curvature);
91 double distance = fabs (weight * d_normal + (1.0 - weight) * d_euclid);
92 if (distance < threshold)
95 inliers[nr_p] = (*indices_)[i];
96 error_sqr_dists_[nr_p] = distance;
100 inliers.resize (nr_p);
101 error_sqr_dists_.resize (nr_p);
105 template <
typename Po
intT,
typename Po
intNT>
int 107 const Eigen::VectorXf &model_coefficients,
const double threshold)
111 PCL_ERROR (
"[pcl::SampleConsensusModelNormalPlane::countWithinDistance] No input dataset containing normals was given!\n");
116 if (!isModelValid (model_coefficients))
120 Eigen::Vector4f coeff = model_coefficients;
126 for (
size_t i = 0; i < indices_->size (); ++i)
128 const PointT &pt = input_->points[(*indices_)[i]];
129 const PointNT &nt = normals_->points[(*indices_)[i]];
132 Eigen::Vector4f p (pt.x, pt.y, pt.z, 0);
133 Eigen::Vector4f n (nt.normal_x, nt.normal_y, nt.normal_z, 0);
134 double d_euclid = fabs (coeff.dot (p) + model_coefficients[3]);
137 double d_normal = fabs (
getAngle3D (n, coeff));
138 d_normal = (std::min) (d_normal, M_PI - d_normal);
141 double weight = normal_distance_weight_ * (1.0 - nt.curvature);
143 if (fabs (weight * d_normal + (1.0 - weight) * d_euclid) < threshold)
150 template <
typename Po
intT,
typename Po
intNT>
void 152 const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
156 PCL_ERROR (
"[pcl::SampleConsensusModelNormalPlane::getDistancesToModel] No input dataset containing normals was given!\n");
161 if (!isModelValid (model_coefficients))
168 Eigen::Vector4f coeff = model_coefficients;
171 distances.resize (indices_->size ());
174 for (
size_t i = 0; i < indices_->size (); ++i)
176 const PointT &pt = input_->points[(*indices_)[i]];
177 const PointNT &nt = normals_->points[(*indices_)[i]];
180 Eigen::Vector4f p (pt.x, pt.y, pt.z, 0);
181 Eigen::Vector4f n (nt.normal_x, nt.normal_y, nt.normal_z, 0);
182 double d_euclid = fabs (coeff.dot (p) + model_coefficients[3]);
185 double d_normal = fabs (
getAngle3D (n, coeff));
186 d_normal = (std::min) (d_normal, M_PI - d_normal);
189 double weight = normal_distance_weight_ * (1.0 - nt.curvature);
191 distances[i] = fabs (weight * d_normal + (1.0 - weight) * d_euclid);
195 #define PCL_INSTANTIATE_SampleConsensusModelNormalPlane(PointT, PointNT) template class PCL_EXPORTS pcl::SampleConsensusModelNormalPlane<PointT, PointNT>; 197 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_PLANE_H_ double getAngle3D(const Eigen::Vector4f &v1, const Eigen::Vector4f &v2)
Compute the smallest angle between two vectors in the [ 0, PI ) interval in 3D.
virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold)
Count all the points which respect the given model coefficients as inliers.
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, std::vector< int > &inliers)
Select all the points which respect the given model coefficients as inliers.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances)
Compute all distances from the cloud data to a given plane model.
A point structure representing Euclidean xyz coordinates, and the RGB color.