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>;
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.