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");
71 return std::vector<float> (k_indices.size (), 1.0f);
86 template <
typename NormalT>
inline bool
90 const std::vector<float>& k_sqr_distances,
94 point.normal_x = 0.0f;
95 point.normal_y = 0.0f;
96 point.normal_z = 0.0f;
99 if (k_indices.size () != k_sqr_distances.size ())
101 PCL_ERROR(
"[pcl::refineNormal] inequal size of neighbor indices and distances!\n");
106 const std::vector<float> weights =
assignNormalWeights (cloud, index, k_indices, k_sqr_distances);
112 for (std::size_t i = 0; i < k_indices.size (); ++i) {
114 const NormalT& pointi = cloud[k_indices[i]];
117 if (std::isfinite (pointi.normal_x) && std::isfinite (pointi.normal_y) && std::isfinite (pointi.normal_z))
119 const float& weighti = weights[i];
120 nx += weighti * pointi.normal_x;
121 ny += weighti * pointi.normal_y;
122 nz += weighti * pointi.normal_z;
127 const float norm = std::sqrt (nx * nx + ny * ny + nz * nz);
128 if (std::isfinite (norm) && norm > std::numeric_limits<float>::epsilon ())
130 point.normal_x = nx / norm;
131 point.normal_y = ny / norm;
132 point.normal_z = nz / norm;
193 template<
typename NormalT>
219 NormalRefinement (
const std::vector< Indices >& k_indices,
const std::vector< std::vector<float> >& k_sqr_distances) :
233 setCorrespondences (
const std::vector< Indices >& k_indices,
const std::vector< std::vector<float> >& k_sqr_distances)
235 k_indices_ = k_indices;
236 k_sqr_distances_ = k_sqr_distances;
244 getCorrespondences (std::vector< Indices >& k_indices, std::vector< std::vector<float> >& k_sqr_distances)
246 k_indices.assign (k_indices_.begin (), k_indices_.end ());
247 k_sqr_distances.assign (k_sqr_distances_.begin (), k_sqr_distances_.end ());
256 max_iterations_ = max_iterations;
265 return max_iterations_;
274 convergence_threshold_ = convergence_threshold;
283 return convergence_threshold_;
295 std::vector< Indices > k_indices_;
298 std::vector< std::vector<float> > k_sqr_distances_;
301 unsigned int max_iterations_;
304 float convergence_threshold_;
308 #ifdef PCL_NO_PRECOMPILE
309 #include <pcl/filters/impl/normal_refinement.hpp>
311 #define PCL_INSTANTIATE_NormalRefinement(T) template class PCL_EXPORTS pcl::NormalRefinement<T>;
Filter represents the base filter class.
std::string filter_name_
The filter name.
Normal vector refinement class
void setConvergenceThreshold(float convergence_threshold)
Set convergence threshold.
void getCorrespondences(std::vector< Indices > &k_indices, std::vector< std::vector< float > > &k_sqr_distances)
Get correspondences (copy)
float getConvergenceThreshold()
Get convergence threshold.
void applyFilter(PointCloud &output) override
Filter a Point Cloud.
NormalRefinement(const std::vector< Indices > &k_indices, const std::vector< std::vector< float > > &k_sqr_distances)
Constructor for setting correspondences, sets default convergence parameters.
unsigned int getMaxIterations()
Get maximum iterations.
void setMaxIterations(unsigned int max_iterations)
Set maximum iterations.
void setCorrespondences(const std::vector< Indices > &k_indices, const std::vector< std::vector< float > > &k_sqr_distances)
Set correspondences calculated from nearest neighbor search.
NormalRefinement()
Empty constructor, sets default convergence parameters.
typename PointCloud::Ptr PointCloudPtr
typename PointCloud::ConstPtr PointCloudConstPtr
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
std::vector< float > assignNormalWeights(const PointCloud< NormalT > &cloud, index_t index, const Indices &k_indices, const std::vector< float > &k_sqr_distances)
Assign weights of nearby normals used for refinement.
bool refineNormal(const PointCloud< NormalT > &cloud, int index, const Indices &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 ignore(const T &...)
Utility function to eliminate unused variable warnings.
detail::int_type_t< detail::index_type_size, detail::index_type_signed > index_t
Type used for an index in PCL.
IndicesAllocator<> Indices
Type used for indices in PCL.
Defines all the PCL and non-PCL macros used.
A point structure representing normal coordinates and the surface curvature estimate.