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 (
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 = fabs (n_dir.norm () - model_coefficients[3]);
92 double d_normal = fabs (
getAngle3D (n, n_dir));
93 d_normal = (std::min) (d_normal, M_PI - d_normal);
95 double distance = fabs (normal_distance_weight_ * d_normal + (1 - normal_distance_weight_) * d_euclid);
96 if (distance < threshold)
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>
int 111 const Eigen::VectorXf &model_coefficients,
const double threshold)
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;
131 for (
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 = fabs (n_dir.norm () - model_coefficients[3]);
149 double d_normal = fabs (
getAngle3D (n, n_dir));
150 d_normal = (std::min) (d_normal, M_PI - d_normal);
152 if (fabs (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)
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 (
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 = fabs (n_dir.norm () - model_coefficients[3]);
201 double d_normal = fabs (
getAngle3D (n, n_dir));
202 d_normal = (std::min) (d_normal, M_PI - d_normal);
204 distances[i] = fabs (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_ virtual int countWithinDistance(const Eigen::VectorXf &model_coefficients, const double threshold)
Count all the points which respect the given model coefficients as inliers.
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. ...
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 sphere model.
SampleConsensusModel represents the base model class.
float distance(const PointT &p1, const PointT &p2)
virtual bool isModelValid(const Eigen::VectorXf &model_coefficients)
Check whether a model is valid given the user constraints.