Point Cloud Library (PCL)  1.5.1
 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         SIMPLE_3D_GRADIENT
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_DX_(false)
00077       , integral_image_DY_(false)
00078       , integral_image_depth_ (false)
00079       , integral_image_XYZ_ (true)
00080       , diff_x_(NULL)
00081       , diff_y_(NULL)
00082       , depth_data_(NULL)
00083       , use_depth_dependent_smoothing_(false)
00084       , max_depth_change_factor_(20.0f*0.001f)
00085       , normal_smoothing_size_(10.0f)
00086       , init_covariance_matrix_(false)
00087       , init_average_3d_gradient_(false)
00088       , init_depth_change_(false)
00089       {
00090         feature_name_ = "IntegralImagesNormalEstimation";
00091         tree_.reset ();
00092         k_ = 1;
00093       }
00094 
00095 
00097       virtual ~IntegralImageNormalEstimation ();
00098 
00103       void
00104       setRectSize (const int width, const int height);
00105 
00112       void
00113       computePointNormal (const int pos_x, const int pos_y, const unsigned point_index, PointOutT &normal);
00114 
00119       void
00120       setMaxDepthChangeFactor (float max_depth_change_factor)
00121       {
00122         max_depth_change_factor_ = max_depth_change_factor;
00123       }
00124 
00129       void
00130       setNormalSmoothingSize (float normal_smoothing_size)
00131       {
00132         normal_smoothing_size_ = normal_smoothing_size;
00133       }
00134 
00147       void
00148       setNormalEstimationMethod (NormalEstimationMethod normal_estimation_method)
00149       {
00150         normal_estimation_method_ = normal_estimation_method;
00151       }
00152 
00156       void
00157       setDepthDependentSmoothing (bool use_depth_dependent_smoothing)
00158       {
00159         use_depth_dependent_smoothing_ = use_depth_dependent_smoothing;
00160       }
00161 
00165       virtual inline void
00166       setInputCloud (const typename PointCloudIn::ConstPtr &cloud)
00167       {
00168         input_ = cloud;
00169         if (!cloud->isOrganized ())
00170         {
00171           PCL_ERROR ("[pcl::IntegralImageNormalEstimation::setInputCloud] Input dataset is not organized (height = 1).\n");
00172           return;
00173         }
00174 
00175         init_covariance_matrix_ = init_average_3d_gradient_ = init_depth_change_ = false;
00176 
00177         // Initialize the correct data structure based on the normal estimation method chosen
00178         initData ();
00179       }
00180 
00181     protected:
00182 
00186       void
00187       computeFeature (PointCloudOut &output);
00188 
00190       void
00191       initData ();
00192 
00193     private:
00200       NormalEstimationMethod normal_estimation_method_;
00201 
00203       int rect_width_;
00204       int rect_width_2_;
00205       int rect_width_4_;
00207       int rect_height_;
00208       int rect_height_2_;
00209       int rect_height_4_;
00210 
00212       float distance_threshold_;
00213 
00215       IntegralImage2D<float, 3> integral_image_DX_;
00217       IntegralImage2D<float, 3> integral_image_DY_;
00219       IntegralImage2D<float, 1> integral_image_depth_;
00221       IntegralImage2D<float, 3> integral_image_XYZ_;
00222 
00224       float *diff_x_;
00226       float *diff_y_;
00227 
00229       float *depth_data_;
00230 
00232       bool use_depth_dependent_smoothing_;
00233 
00235       float max_depth_change_factor_;
00236 
00238       float normal_smoothing_size_;
00239 
00241       bool init_covariance_matrix_;
00242 
00244       bool init_average_3d_gradient_;
00245 
00247       bool init_simple_3d_gradient_;
00248 
00250       bool init_depth_change_;
00251 
00253       bool
00254       initCompute ();
00255 
00257       void
00258       initCovarianceMatrixMethod ();
00259 
00261       void
00262       initAverage3DGradientMethod ();
00263 
00265       void
00266       initAverageDepthChangeMethod ();
00267 
00269       void
00270       initSimple3DGradientMethod ();
00271 
00272     private:
00276       void
00277       computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &output) {}
00278     public:
00279       EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00280   };
00281 }
00282 
00283 #endif
00284