41 #include <pcl/common/utils.h>
42 #include <pcl/filters/filter.h>
55 template <
typename NormalT>
inline std::vector<float>
59 const std::vector<float>& k_sqr_distances)
63 if (k_indices.size () != k_sqr_distances.size ())
64 PCL_ERROR(
"[pcl::assignNormalWeights] inequal size of neighbor indices and distances!\n");
67 return (std::vector<float> (k_indices.size (), 1.0f));
82 template <
typename NormalT>
inline bool
86 const std::vector<float>& k_sqr_distances,
90 point.normal_x = 0.0f;
91 point.normal_y = 0.0f;
92 point.normal_z = 0.0f;
95 if (k_indices.size () != k_sqr_distances.size ())
97 PCL_ERROR(
"[pcl::refineNormal] inequal size of neighbor indices and distances!\n");
102 const std::vector<float> weights =
assignNormalWeights (cloud, index, k_indices, k_sqr_distances);
108 for (std::size_t i = 0; i < k_indices.size (); ++i) {
110 const NormalT& pointi = cloud[k_indices[i]];
113 if (std::isfinite (pointi.normal_x) && std::isfinite (pointi.normal_y) && std::isfinite (pointi.normal_z))
115 const float& weighti = weights[i];
116 nx += weighti * pointi.normal_x;
117 ny += weighti * pointi.normal_y;
118 nz += weighti * pointi.normal_z;
123 const float norm = std::sqrt (nx * nx + ny * ny + nz * nz);
124 if (std::isfinite (norm) && norm > std::numeric_limits<float>::epsilon ())
126 point.normal_x = nx / norm;
127 point.normal_y = ny / norm;
128 point.normal_z = nz / norm;
189 template<
typename NormalT>
215 NormalRefinement (
const std::vector< Indices >& k_indices,
const std::vector< std::vector<float> >& k_sqr_distances) :
229 setCorrespondences (
const std::vector< Indices >& k_indices,
const std::vector< std::vector<float> >& k_sqr_distances)
231 k_indices_ = k_indices;
232 k_sqr_distances_ = k_sqr_distances;
240 getCorrespondences (std::vector< Indices >& k_indices, std::vector< std::vector<float> >& k_sqr_distances)
242 k_indices.assign (k_indices_.begin (), k_indices_.end ());
243 k_sqr_distances.assign (k_sqr_distances_.begin (), k_sqr_distances_.end ());
252 max_iterations_ = max_iterations;
261 return max_iterations_;
270 convergence_threshold_ = convergence_threshold;
279 return convergence_threshold_;
291 std::vector< Indices > k_indices_;
294 std::vector< std::vector<float> > k_sqr_distances_;
297 unsigned int max_iterations_;
300 float convergence_threshold_;
304 #ifdef PCL_NO_PRECOMPILE
305 #include <pcl/filters/impl/normal_refinement.hpp>
307 #define PCL_INSTANTIATE_NormalRefinement(T) template class PCL_EXPORTS pcl::NormalRefinement<T>;