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>
48 template <
typename Po
intT,
typename Po
intNT>
void
50 const Eigen::VectorXf &model_coefficients,
const double threshold,
Indices &inliers)
54 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::selectWithinDistance] No input dataset containing normals was given! Use setInputNormals\n");
60 if (!isModelValid (model_coefficients))
67 Eigen::Vector4f center = model_coefficients;
71 error_sqr_dists_.clear ();
72 inliers.reserve (indices_->size ());
73 error_sqr_dists_.reserve (indices_->size ());
76 for (std::size_t i = 0; i < indices_->size (); ++i)
80 Eigen::Vector4f p ((*input_)[(*indices_)[i]].x,
81 (*input_)[(*indices_)[i]].y,
82 (*input_)[(*indices_)[i]].z,
85 Eigen::Vector4f n_dir = p - center;
86 const double weighted_euclid_dist = (1.0 - normal_distance_weight_) * std::abs (n_dir.norm () - model_coefficients[3]);
87 if (weighted_euclid_dist > threshold)
91 Eigen::Vector4f n ((*normals_)[(*indices_)[i]].normal[0],
92 (*normals_)[(*indices_)[i]].normal[1],
93 (*normals_)[(*indices_)[i]].normal[2],
95 double d_normal = std::abs (
getAngle3D (n, n_dir));
96 d_normal = (std::min) (d_normal,
M_PI - d_normal);
98 double distance = std::abs (normal_distance_weight_ * d_normal + weighted_euclid_dist);
102 inliers.push_back ((*indices_)[i]);
103 error_sqr_dists_.push_back (
static_cast<double> (
distance));
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! Use setInputNormals\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_)[(*indices_)[i]].x,
136 (*input_)[(*indices_)[i]].y,
137 (*input_)[(*indices_)[i]].z,
140 Eigen::Vector4f n_dir = (p-center);
141 const double weighted_euclid_dist = (1.0 - normal_distance_weight_) * std::abs (n_dir.norm () - model_coefficients[3]);
142 if (weighted_euclid_dist > threshold)
146 Eigen::Vector4f n ((*normals_)[(*indices_)[i]].normal[0],
147 (*normals_)[(*indices_)[i]].normal[1],
148 (*normals_)[(*indices_)[i]].normal[2],
150 double d_normal = std::abs (
getAngle3D (n, n_dir));
151 d_normal = (std::min) (d_normal,
M_PI - d_normal);
153 if (std::abs (normal_distance_weight_ * d_normal + weighted_euclid_dist) < threshold)
160 template <
typename Po
intT,
typename Po
intNT>
void
162 const Eigen::VectorXf &model_coefficients, std::vector<double> &distances)
const
166 PCL_ERROR (
"[pcl::SampleConsensusModelNormalSphere::getDistancesToModel] No input dataset containing normals was given! Use setInputNormals\n");
171 if (!isModelValid (model_coefficients))
178 Eigen::Vector4f center = model_coefficients;
181 distances.resize (indices_->size ());
184 for (std::size_t i = 0; i < indices_->size (); ++i)
188 Eigen::Vector4f p ((*input_)[(*indices_)[i]].x,
189 (*input_)[(*indices_)[i]].y,
190 (*input_)[(*indices_)[i]].z,
193 Eigen::Vector4f n_dir = (p-center);
194 const double weighted_euclid_dist = (1.0 - normal_distance_weight_) * std::abs (n_dir.norm () - model_coefficients[3]);
197 Eigen::Vector4f n ((*normals_)[(*indices_)[i]].normal[0],
198 (*normals_)[(*indices_)[i]].normal[1],
199 (*normals_)[(*indices_)[i]].normal[2],
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 + weighted_euclid_dist);
208 #define PCL_INSTANTIATE_SampleConsensusModelNormalSphere(PointT, PointNT) template class PCL_EXPORTS pcl::SampleConsensusModelNormalSphere<PointT, PointNT>;
void selectWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold, Indices &inliers) override
Select all the points which respect the given model coefficients as inliers.
std::size_t countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold) const override
Count all the points which respect the given model coefficients as inliers.
void getDistancesToModel(const Eigen::VectorXf &model_coefficients, std::vector< double > &distances) const override
Compute all distances from the cloud data to a given sphere model.
Define standard C methods and C++ classes that are common to all methods.
double getAngle3D(const Eigen::Vector4f &v1, const Eigen::Vector4f &v2, const bool in_degree=false)
Compute the smallest angle between two 3D vectors in radians (default) or degree.
float distance(const PointT &p1, const PointT &p2)
IndicesAllocator<> Indices
Type used for indices in PCL.