40 #ifndef PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_SPHERE_H_
41 #define PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_SPHERE_H_
46 template <
typename Po
intT,
typename Po
intNT>
void
48 const Eigen::VectorXf &model_coefficients,
const double threshold, std::vector<int> &inliers)
52 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::selectWithinDistance] No input dataset containing normals was given!\n");
58 if (!isModelValid (model_coefficients))
65 Eigen::Vector4f center = model_coefficients;
69 inliers.resize (indices_->size ());
71 for (
size_t i = 0; i < indices_->size (); ++i)
75 Eigen::Vector4f p (input_->points[(*indices_)[i]].x,
76 input_->points[(*indices_)[i]].y,
77 input_->points[(*indices_)[i]].z,
80 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0],
81 normals_->points[(*indices_)[i]].normal[1],
82 normals_->points[(*indices_)[i]].normal[2],
85 Eigen::Vector4f n_dir = p - center;
86 double d_euclid = fabs (n_dir.norm () - model_coefficients[3]);
89 double d_normal = fabs (
getAngle3D (n, n_dir));
90 d_normal = (std::min) (d_normal, M_PI - d_normal);
92 if (fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid) < threshold)
95 inliers[nr_p] = (*indices_)[i];
99 inliers.resize (nr_p);
103 template <
typename Po
intT,
typename Po
intNT>
int
105 const Eigen::VectorXf &model_coefficients,
const double threshold)
109 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::getDistancesToModel] No input dataset containing normals was given!\n");
114 if (!isModelValid (model_coefficients))
119 Eigen::Vector4f center = model_coefficients;
125 for (
size_t i = 0; i < indices_->size (); ++i)
129 Eigen::Vector4f p (input_->points[(*indices_)[i]].x,
130 input_->points[(*indices_)[i]].y,
131 input_->points[(*indices_)[i]].z,
134 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0],
135 normals_->points[(*indices_)[i]].normal[1],
136 normals_->points[(*indices_)[i]].normal[2],
139 Eigen::Vector4f n_dir = (p-center);
140 double d_euclid = fabs (n_dir.norm () - model_coefficients[3]);
143 double d_normal = fabs (
getAngle3D (n, n_dir));
144 d_normal = (std::min) (d_normal, M_PI - d_normal);
146 if (fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid) < threshold)
153 template <
typename Po
intT,
typename Po
intNT>
void
155 const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
159 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::getDistancesToModel] No input dataset containing normals was given!\n");
164 if (!isModelValid (model_coefficients))
171 Eigen::Vector4f center = model_coefficients;
174 distances.resize (indices_->size ());
177 for (
size_t i = 0; i < indices_->size (); ++i)
181 Eigen::Vector4f p (input_->points[(*indices_)[i]].x,
182 input_->points[(*indices_)[i]].y,
183 input_->points[(*indices_)[i]].z,
186 Eigen::Vector4f n (normals_->points[(*indices_)[i]].normal[0],
187 normals_->points[(*indices_)[i]].normal[1],
188 normals_->points[(*indices_)[i]].normal[2],
191 Eigen::Vector4f n_dir = (p-center);
192 double d_euclid = fabs (n_dir.norm () - model_coefficients[3]);
195 double d_normal = fabs (
getAngle3D (n, n_dir));
196 d_normal = (std::min) (d_normal, M_PI - d_normal);
198 distances[i] = fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid);
203 template <
typename Po
intT,
typename Po
intNT>
bool
207 if (model_coefficients.size () != 4)
209 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::selectWithinDistance] Invalid number of model coefficients given (%zu)!\n", model_coefficients.size ());
213 if (radius_min_ != -std::numeric_limits<double>::max() && model_coefficients[3] < radius_min_)
215 if (radius_max_ != std::numeric_limits<double>::max() && model_coefficients[3] > radius_max_)
221 #define PCL_INSTANTIATE_SampleConsensusModelNormalSphere(PointT, PointNT) template class PCL_EXPORTS pcl::SampleConsensusModelNormalSphere<PointT, PointNT>;
223 #endif // PCL_SAMPLE_CONSENSUS_IMPL_SAC_MODEL_NORMAL_SPHERE_H_