Point Cloud Library (PCL)  1.3.1
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_image_2d.h"
00045 #include "pcl/features/integral_image2D.h"
00046 
00047 namespace pcl
00048 {
00053   template <typename PointInT, typename PointOutT>
00054   class IntegralImageNormalEstimation: public Feature<PointInT, PointOutT>
00055   {
00056     using Feature<PointInT, PointOutT>::input_;
00057     using Feature<PointInT, PointOutT>::feature_name_;
00058     using Feature<PointInT, PointOutT>::tree_;
00059     using Feature<PointInT, PointOutT>::k_;
00060 
00061     public:
00062 
00063       enum NormalEstimationMethod
00064       {
00065         COVARIANCE_MATRIX,
00066         AVERAGE_3D_GRADIENT,
00067         AVERAGE_DEPTH_CHANGE
00068       };
00069 
00070       typedef typename Feature<PointInT, PointOutT>::PointCloudIn  PointCloudIn;
00071       typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
00072 
00074       IntegralImageNormalEstimation () : 
00075         normal_estimation_method_(AVERAGE_3D_GRADIENT),
00076         integral_image_x_(NULL), integral_image_y_(NULL), 
00077         integral_image_xyz_(NULL), integral_image_(NULL),
00078         integral_image_XYZ_ (true),
00079         diff_x_(NULL), diff_y_(NULL), depth_data_(NULL),
00080         use_depth_dependent_smoothing_(false),
00081         max_depth_change_factor_(20.0f*0.001f),
00082         normal_smoothing_size_(10.0f),
00083         init_covariance_matrix_(false), init_average_3d_gradient_(false), init_depth_change_(false)
00084       {
00085         feature_name_ = "IntegralImagesNormalEstimation";
00086         tree_.reset ();
00087         k_ = 1;
00088       }
00089 
00090 
00092       virtual ~IntegralImageNormalEstimation ();
00093 
00098       void 
00099       setRectSize (const int width, const int height);
00100 
00106       void
00107       computePointNormal (const int pos_x, const int pos_y, PointOutT &normal);
00108 
00113       void 
00114       setMaxDepthChangeFactor (float max_depth_change_factor)
00115       {
00116         max_depth_change_factor_ = max_depth_change_factor;
00117       }
00118 
00123       void
00124       setNormalSmoothingSize (float normal_smoothing_size)
00125       {
00126         normal_smoothing_size_ = normal_smoothing_size;
00127       }
00128 
00141       void
00142       setNormalEstimationMethod (NormalEstimationMethod normal_estimation_method)
00143       {
00144         normal_estimation_method_ = normal_estimation_method;
00145       }
00146 
00150       void
00151       setDepthDependentSmoothing (bool use_depth_dependent_smoothing)
00152       {
00153         use_depth_dependent_smoothing_ = use_depth_dependent_smoothing;
00154       }
00155 
00159       virtual inline void 
00160       setInputCloud (const typename PointCloudIn::ConstPtr &cloud) 
00161       { 
00162         input_ = cloud; 
00163 
00164         init_covariance_matrix_ = init_average_3d_gradient_ = init_depth_change_ = false;
00165 
00166         // Initialize the correct data structure based on the normal estimation method chosen 
00167         initData ();
00168       }
00169 
00170     protected:
00171 
00175       void 
00176       computeFeature (PointCloudOut &output);
00177 
00180       void 
00181       initData ();
00182       
00183     private:
00190       NormalEstimationMethod normal_estimation_method_;
00191     
00193       int rect_width_;
00195       int rect_height_;
00196 
00198       float distance_threshold_;
00199 
00201       IntegralImage2D<float, double> *integral_image_x_;
00203       IntegralImage2D<float, double> *integral_image_y_;
00205       IntegralImage2D<float, double> *integral_image_xyz_;
00207       IntegralImage2D<float, double> *integral_image_;
00209       IntegralImage2Dim<float, 3> integral_image_XYZ_;
00210 
00212       float *diff_x_;
00214       float *diff_y_;
00215 
00217       float *depth_data_;
00218 
00220       bool use_depth_dependent_smoothing_;
00221 
00223       float max_depth_change_factor_;
00224 
00226       float normal_smoothing_size_;
00227 
00229       bool init_covariance_matrix_;
00230       
00232       bool init_average_3d_gradient_;
00233 
00235       bool init_depth_change_;
00236 
00238       void
00239       initCovarianceMatrixMethod ();
00240 
00242       void
00243       initAverage3DGradientMethod ();
00244 
00246       void
00247       initAverageDepthChangeMethod ();
00248   };
00249 }
00250 
00251 #endif 
00252 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines