Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef PCL_FILTERS_NORMAL_REFINEMENT_H_
00039 #define PCL_FILTERS_NORMAL_REFINEMENT_H_
00040
00041 #include <pcl/filters/filter.h>
00042
00043 namespace pcl
00044 {
00054 template <typename NormalT> inline std::vector<float>
00055 assignNormalWeights (const PointCloud<NormalT>&,
00056 int,
00057 const std::vector<int>& k_indices,
00058 const std::vector<float>& k_sqr_distances)
00059 {
00060
00061 if (k_indices.size () != k_sqr_distances.size ())
00062 PCL_ERROR("[pcl::assignNormalWeights] inequal size of neighbor indices and distances!\n");
00063
00064
00065 return (std::vector<float> (k_indices.size (), 1.0f));
00066 }
00067
00080 template <typename NormalT> inline bool
00081 refineNormal (const PointCloud<NormalT>& cloud,
00082 int index,
00083 const std::vector<int>& k_indices,
00084 const std::vector<float>& k_sqr_distances,
00085 NormalT& point)
00086 {
00087
00088 point.normal_x = 0.0f;
00089 point.normal_y = 0.0f;
00090 point.normal_z = 0.0f;
00091
00092
00093 if (k_indices.size () != k_sqr_distances.size ())
00094 {
00095 PCL_ERROR("[pcl::refineNormal] inequal size of neighbor indices and distances!\n");
00096 return (false);
00097 }
00098
00099
00100 const std::vector<float> weights = assignNormalWeights (cloud, index, k_indices, k_sqr_distances);
00101
00102
00103 float nx = 0.0f;
00104 float ny = 0.0f;
00105 float nz = 0.0f;
00106 for (unsigned int i = 0; i < k_indices.size (); ++i) {
00107
00108 const NormalT& pointi = cloud[k_indices[i]];
00109
00110
00111 if (pcl_isfinite (pointi.normal_x) && pcl_isfinite (pointi.normal_y) && pcl_isfinite (pointi.normal_z))
00112 {
00113 const float& weighti = weights[i];
00114 nx += weighti * pointi.normal_x;
00115 ny += weighti * pointi.normal_y;
00116 nz += weighti * pointi.normal_z;
00117 }
00118 }
00119
00120
00121 const float norm = sqrtf (nx * nx + ny * ny + nz * nz);
00122 if (pcl_isfinite (norm) && norm > std::numeric_limits<float>::epsilon ())
00123 {
00124 point.normal_x = nx / norm;
00125 point.normal_y = ny / norm;
00126 point.normal_z = nz / norm;
00127
00128 return (true);
00129 }
00130
00131 return (false);
00132 }
00133
00187 template<typename NormalT>
00188 class NormalRefinement : public Filter<NormalT>
00189 {
00190 using Filter<NormalT>::input_;
00191 using Filter<NormalT>::filter_name_;
00192 using Filter<NormalT>::getClassName;
00193
00194 typedef typename Filter<NormalT>::PointCloud PointCloud;
00195 typedef typename PointCloud::Ptr PointCloudPtr;
00196 typedef typename PointCloud::ConstPtr PointCloudConstPtr;
00197
00198 public:
00201 NormalRefinement () :
00202 Filter<NormalT>::Filter ()
00203 {
00204 filter_name_ = "NormalRefinement";
00205 setMaxIterations (15);
00206 setConvergenceThreshold (0.00001f);
00207 }
00208
00213 NormalRefinement (const std::vector< std::vector<int> >& k_indices, const std::vector< std::vector<float> >& k_sqr_distances) :
00214 Filter<NormalT>::Filter ()
00215 {
00216 filter_name_ = "NormalRefinement";
00217 setCorrespondences (k_indices, k_sqr_distances);
00218 setMaxIterations (15);
00219 setConvergenceThreshold (0.00001f);
00220 }
00221
00226 inline void
00227 setCorrespondences (const std::vector< std::vector<int> >& k_indices, const std::vector< std::vector<float> >& k_sqr_distances)
00228 {
00229 k_indices_ = k_indices;
00230 k_sqr_distances_ = k_sqr_distances;
00231 }
00232
00237 inline void
00238 getCorrespondences (std::vector< std::vector<int> >& k_indices, std::vector< std::vector<float> >& k_sqr_distances)
00239 {
00240 k_indices.assign (k_indices_.begin (), k_indices_.end ());
00241 k_sqr_distances.assign (k_sqr_distances_.begin (), k_sqr_distances_.end ());
00242 }
00243
00247 inline void
00248 setMaxIterations (unsigned int max_iterations)
00249 {
00250 max_iterations_ = max_iterations;
00251 }
00252
00256 inline unsigned int
00257 getMaxIterations ()
00258 {
00259 return max_iterations_;
00260 }
00261
00265 inline void
00266 setConvergenceThreshold (float convergence_threshold)
00267 {
00268 convergence_threshold_ = convergence_threshold;
00269 }
00270
00274 inline float
00275 getConvergenceThreshold ()
00276 {
00277 return convergence_threshold_;
00278 }
00279
00280 protected:
00284 void
00285 applyFilter (PointCloud &output);
00286
00287 private:
00289 std::vector< std::vector<int> > k_indices_;
00290
00292 std::vector< std::vector<float> > k_sqr_distances_;
00293
00295 unsigned int max_iterations_;
00296
00298 float convergence_threshold_;
00299 };
00300 }
00301
00302 #ifdef PCL_NO_PRECOMPILE
00303 #include <pcl/filters/impl/normal_refinement.hpp>
00304 #else
00305 #define PCL_INSTANTIATE_NormalRefinement(T) template class PCL_EXPORTS pcl::NormalRefinement<T>;
00306 #endif
00307
00308 #endif