41 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_SPHERE_H_
42 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_SPHERE_H_
44 #include <pcl/sample_consensus/sac_model_normal_sphere.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::SampleConsensusModelNormalSphere::selectWithinDistance] No input dataset containing normals was given!\n");
59 if (!isModelValid (model_coefficients))
66 Eigen::Vector4f center = model_coefficients;
70 inliers.resize (indices_->size ());
71 error_sqr_dists_.resize (indices_->size ());
74 for (std::size_t i = 0; i < indices_->size (); ++i)
78 Eigen::Vector4f p (input_->points[(*indices_)[i]].x,
79 input_->points[(*indices_)[i]].y,
80 input_->points[(*indices_)[i]].z,
83 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0],
84 normals_->points[(*indices_)[i]].normal[1],
85 normals_->points[(*indices_)[i]].normal[2],
88 Eigen::Vector4f n_dir = p - center;
89 double d_euclid = std::abs (n_dir.norm () - model_coefficients[3]);
92 double d_normal = std::abs (
getAngle3D (n, n_dir));
93 d_normal = (std::min) (d_normal, M_PI - d_normal);
95 double distance = std::abs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid);
99 inliers[nr_p] = (*indices_)[i];
100 error_sqr_dists_[nr_p] =
static_cast<double> (
distance);
104 inliers.resize (nr_p);
105 error_sqr_dists_.resize (nr_p);
109 template <
typename Po
intT,
typename Po
intNT> std::size_t
111 const Eigen::VectorXf &model_coefficients,
const double threshold)
const
115 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::getDistancesToModel] No input dataset containing normals was given!\n");
120 if (!isModelValid (model_coefficients))
125 Eigen::Vector4f center = model_coefficients;
128 std::size_t nr_p = 0;
131 for (std::size_t i = 0; i < indices_->size (); ++i)
135 Eigen::Vector4f p (input_->points[(*indices_)[i]].x,
136 input_->points[(*indices_)[i]].y,
137 input_->points[(*indices_)[i]].z,
140 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0],
141 normals_->points[(*indices_)[i]].normal[1],
142 normals_->points[(*indices_)[i]].normal[2],
145 Eigen::Vector4f n_dir = (p-center);
146 double d_euclid = std::abs (n_dir.norm () - model_coefficients[3]);
149 double d_normal = std::abs (
getAngle3D (n, n_dir));
150 d_normal = (std::min) (d_normal, M_PI - d_normal);
152 if (std::abs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid) < threshold)
159 template <
typename Po
intT,
typename Po
intNT>
void
161 const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
const
165 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::getDistancesToModel] No input dataset containing normals was given!\n");
170 if (!isModelValid (model_coefficients))
177 Eigen::Vector4f center = model_coefficients;
180 distances.resize (indices_->size ());
183 for (std::size_t i = 0; i < indices_->size (); ++i)
187 Eigen::Vector4f p (input_->points[(*indices_)[i]].x,
188 input_->points[(*indices_)[i]].y,
189 input_->points[(*indices_)[i]].z,
192 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0],
193 normals_->points[(*indices_)[i]].normal[1],
194 normals_->points[(*indices_)[i]].normal[2],
197 Eigen::Vector4f n_dir = (p-center);
198 double d_euclid = std::abs (n_dir.norm () - model_coefficients[3]);
201 double d_normal = std::abs (
getAngle3D (n, n_dir));
202 d_normal = (std::min) (d_normal, M_PI - d_normal);
204 distances[i] = std::abs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid);
209 template <
typename Po
intT,
typename Po
intNT>
bool
215 if (radius_min_ != -std::numeric_limits<double>::max() && model_coefficients[3] < radius_min_)
217 if (radius_max_ != std::numeric_limits<double>::max() && model_coefficients[3] > radius_max_)
223 #define PCL_INSTANTIATE_SampleConsensusModelNormalSphere(PointT, PointNT) template class PCL_EXPORTS pcl::SampleConsensusModelNormalSphere<PointT, PointNT>;
225 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_SPHERE_H_