Point Cloud Library (PCL)  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
integral_image_normal.h
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2011, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  */
00037 
00038 #ifndef PCL_INTEGRALIMAGE_BASED_NORMAL_ESTIMATOR_H_
00039 #define PCL_INTEGRALIMAGE_BASED_NORMAL_ESTIMATOR_H_
00040 
00041 #include <pcl/point_cloud.h>
00042 #include <pcl/point_types.h>
00043 #include "pcl/features/feature.h"
00044 #include "pcl/features/integral_image2D.h"
00045 
00046 namespace pcl
00047 {
00052   template <typename PointInT, typename PointOutT>
00053   class IntegralImageNormalEstimation: public Feature<PointInT, PointOutT>
00054   {
00055     using Feature<PointInT, PointOutT>::input_;
00056     using Feature<PointInT, PointOutT>::feature_name_;
00057     using Feature<PointInT, PointOutT>::tree_;
00058     using Feature<PointInT, PointOutT>::k_;
00059 
00060     public:
00061 
00062       enum NormalEstimationMethod
00063       {
00064         COVARIANCE_MATRIX,
00065         AVERAGE_3D_GRADIENT,
00066         AVERAGE_DEPTH_CHANGE
00067       };
00068 
00069       typedef typename Feature<PointInT, PointOutT>::PointCloudIn  PointCloudIn;
00070       typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00071 
00073       IntegralImageNormalEstimation ()
00074       : normal_estimation_method_(AVERAGE_3D_GRADIENT)
00075       , integral_image_X_(false)
00076       , integral_image_Y_(false)
00077       , integral_image_depth_ (true)
00078       , integral_image_XYZ_ (true)
00079       , diff_x_(NULL)
00080       , diff_y_(NULL)
00081       , depth_data_(NULL)
00082       , use_depth_dependent_smoothing_(false)
00083       , max_depth_change_factor_(20.0f*0.001f)
00084       , normal_smoothing_size_(10.0f)
00085       , init_covariance_matrix_(false)
00086       , init_average_3d_gradient_(false)
00087       , init_depth_change_(false)
00088       {
00089         feature_name_ = "IntegralImagesNormalEstimation";
00090         tree_.reset ();
00091         k_ = 1;
00092       }
00093 
00094 
00096       virtual ~IntegralImageNormalEstimation ();
00097 
00102       void
00103       setRectSize (const int width, const int height);
00104 
00110       void
00111       computePointNormal (const int pos_x, const int pos_y, PointOutT &normal);
00112 
00117       void
00118       setMaxDepthChangeFactor (float max_depth_change_factor)
00119       {
00120         max_depth_change_factor_ = max_depth_change_factor;
00121       }
00122 
00127       void
00128       setNormalSmoothingSize (float normal_smoothing_size)
00129       {
00130         normal_smoothing_size_ = normal_smoothing_size;
00131       }
00132 
00145       void
00146       setNormalEstimationMethod (NormalEstimationMethod normal_estimation_method)
00147       {
00148         normal_estimation_method_ = normal_estimation_method;
00149       }
00150 
00154       void
00155       setDepthDependentSmoothing (bool use_depth_dependent_smoothing)
00156       {
00157         use_depth_dependent_smoothing_ = use_depth_dependent_smoothing;
00158       }
00159 
00163       virtual inline void
00164       setInputCloud (const typename PointCloudIn::ConstPtr &cloud)
00165       {
00166         input_ = cloud;
00167 
00168         init_covariance_matrix_ = init_average_3d_gradient_ = init_depth_change_ = false;
00169 
00170         // Initialize the correct data structure based on the normal estimation method chosen
00171         initData ();
00172       }
00173 
00174     protected:
00175 
00179       void
00180       computeFeature (PointCloudOut &output);
00181 
00184       void
00185       initData ();
00186 
00187     private:
00194       NormalEstimationMethod normal_estimation_method_;
00195 
00197       int rect_width_;
00199       int rect_height_;
00200 
00202       float distance_threshold_;
00203 
00205       IntegralImage2D<float, 3> integral_image_X_;
00207       IntegralImage2D<float, 3> integral_image_Y_;
00209       IntegralImage2D<float, 1> integral_image_depth_;
00211       IntegralImage2D<float, 3> integral_image_XYZ_;
00212 
00214       float *diff_x_;
00216       float *diff_y_;
00217 
00219       float *depth_data_;
00220 
00222       bool use_depth_dependent_smoothing_;
00223 
00225       float max_depth_change_factor_;
00226 
00228       float normal_smoothing_size_;
00229 
00231       bool init_covariance_matrix_;
00232 
00234       bool init_average_3d_gradient_;
00235 
00237       bool init_depth_change_;
00238 
00240       void
00241       initCovarianceMatrixMethod ();
00242 
00244       void
00245       initAverage3DGradientMethod ();
00246 
00248       void
00249       initAverageDepthChangeMethod ();
00250 
00251     private:
00255       void
00256       computeFeature (pcl::PointCloud<Eigen::MatrixXf> &output) {}
00257   };
00258 }
00259 
00260 #endif
00261 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines