40 #include <pcl/pcl_macros.h>
41 #include <pcl/common/utils.h>
42 #include <pcl/filters/filter.h>
55 template <
typename NormalT>
inline std::vector<float>
58 const std::vector<int>& k_indices,
59 const std::vector<float>& k_sqr_distances)
64 if (k_indices.size () != k_sqr_distances.size ())
65 PCL_ERROR(
"[pcl::assignNormalWeights] inequal size of neighbor indices and distances!\n");
68 return (std::vector<float> (k_indices.size (), 1.0f));
83 template <
typename NormalT>
inline bool
86 const std::vector<int>& k_indices,
87 const std::vector<float>& k_sqr_distances,
91 point.normal_x = 0.0f;
92 point.normal_y = 0.0f;
93 point.normal_z = 0.0f;
96 if (k_indices.size () != k_sqr_distances.size ())
98 PCL_ERROR(
"[pcl::refineNormal] inequal size of neighbor indices and distances!\n");
103 const std::vector<float> weights =
assignNormalWeights (cloud, index, k_indices, k_sqr_distances);
109 for (std::size_t i = 0; i < k_indices.size (); ++i) {
111 const NormalT& pointi = cloud[k_indices[i]];
114 if (std::isfinite (pointi.normal_x) && std::isfinite (pointi.normal_y) && std::isfinite (pointi.normal_z))
116 const float& weighti = weights[i];
117 nx += weighti * pointi.normal_x;
118 ny += weighti * pointi.normal_y;
119 nz += weighti * pointi.normal_z;
124 const float norm = std::sqrt (nx * nx + ny * ny + nz * nz);
125 if (std::isfinite (norm) && norm > std::numeric_limits<float>::epsilon ())
127 point.normal_x = nx / norm;
128 point.normal_y = ny / norm;
129 point.normal_z = nz / norm;
190 template<
typename NormalT>
216 NormalRefinement (
const std::vector< std::vector<int> >& k_indices,
const std::vector< std::vector<float> >& k_sqr_distances) :
230 setCorrespondences (
const std::vector< std::vector<int> >& k_indices,
const std::vector< std::vector<float> >& k_sqr_distances)
232 k_indices_ = k_indices;
233 k_sqr_distances_ = k_sqr_distances;
241 getCorrespondences (std::vector< std::vector<int> >& k_indices, std::vector< std::vector<float> >& k_sqr_distances)
243 k_indices.assign (k_indices_.begin (), k_indices_.end ());
244 k_sqr_distances.assign (k_sqr_distances_.begin (), k_sqr_distances_.end ());
253 max_iterations_ = max_iterations;
262 return max_iterations_;
271 convergence_threshold_ = convergence_threshold;
280 return convergence_threshold_;
292 std::vector< std::vector<int> > k_indices_;
295 std::vector< std::vector<float> > k_sqr_distances_;
298 unsigned int max_iterations_;
301 float convergence_threshold_;
305 #ifdef PCL_NO_PRECOMPILE
306 #include <pcl/filters/impl/normal_refinement.hpp>
308 #define PCL_INSTANTIATE_NormalRefinement(T) template class PCL_EXPORTS pcl::NormalRefinement<T>;
A point structure representing normal coordinates and the surface curvature estimate.
void ignore(const T &)
Utility function to eliminate unused variable warnings.
shared_ptr< PointCloud< PointT > > Ptr
void applyFilter(PointCloud &output) override
Filter a Point Cloud.
NormalRefinement()
Empty constructor, sets default convergence parameters.
std::vector< float > assignNormalWeights(const PointCloud< NormalT > &cloud, int index, const std::vector< int > &k_indices, const std::vector< float > &k_sqr_distances)
Assign weights of nearby normals used for refinement.
float getConvergenceThreshold()
Get convergence threshold.
Filter represents the base filter class.
Normal vector refinement class
NormalRefinement(const std::vector< std::vector< int > > &k_indices, const std::vector< std::vector< float > > &k_sqr_distances)
Constructor for setting correspondences, sets default convergence parameters.
bool refineNormal(const PointCloud< NormalT > &cloud, int index, const std::vector< int > &k_indices, const std::vector< float > &k_sqr_distances, NormalT &point)
Refine an indexed point based on its neighbors, this function only writes to the normal_* fields...
void getCorrespondences(std::vector< std::vector< int > > &k_indices, std::vector< std::vector< float > > &k_sqr_distances)
Get correspondences (copy)
void setMaxIterations(unsigned int max_iterations)
Set maximum iterations.
shared_ptr< const PointCloud< PointT > > ConstPtr
void setCorrespondences(const std::vector< std::vector< int > > &k_indices, const std::vector< std::vector< float > > &k_sqr_distances)
Set correspondences calculated from nearest neighbor search.
std::string filter_name_
The filter name.
void setConvergenceThreshold(float convergence_threshold)
Set convergence threshold.
unsigned int getMaxIterations()
Get maximum iterations.