Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
integral_image_normal.h
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  */
37 
38 #ifndef PCL_INTEGRALIMAGE_BASED_NORMAL_ESTIMATOR_H_
39 #define PCL_INTEGRALIMAGE_BASED_NORMAL_ESTIMATOR_H_
40 
41 #include <pcl/point_cloud.h>
42 #include <pcl/point_types.h>
43 #include <pcl/features/feature.h>
45 
46 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3
47 #pragma GCC diagnostic ignored "-Weffc++"
48 #endif
49 namespace pcl
50 {
54  template <typename PointInT, typename PointOutT>
55  class IntegralImageNormalEstimation: public Feature<PointInT, PointOutT>
56  {
61 
62  public:
63 
66  {
69  };
70 
83  {
88  };
89 
92 
95  : normal_estimation_method_(AVERAGE_3D_GRADIENT)
96  , border_policy_ (BORDER_POLICY_IGNORE)
97  , rect_width_ (0), rect_width_2_ (0), rect_width_4_ (0)
98  , rect_height_ (0), rect_height_2_ (0), rect_height_4_ (0)
99  , distance_threshold_ (0)
100  , integral_image_DX_ (false)
101  , integral_image_DY_ (false)
102  , integral_image_depth_ (false)
103  , integral_image_XYZ_ (true)
104  , diff_x_ (NULL)
105  , diff_y_ (NULL)
106  , depth_data_ (NULL)
107  , distance_map_ (NULL)
108  , use_depth_dependent_smoothing_ (false)
109  , max_depth_change_factor_ (20.0f*0.001f)
110  , normal_smoothing_size_ (10.0f)
111  , init_covariance_matrix_ (false)
112  , init_average_3d_gradient_ (false)
113  , init_simple_3d_gradient_ (false)
114  , init_depth_change_ (false)
115  , vpx_ (0.0f)
116  , vpy_ (0.0f)
117  , vpz_ (0.0f)
118  , use_sensor_origin_ (true)
119  {
120  feature_name_ = "IntegralImagesNormalEstimation";
121  tree_.reset ();
122  k_ = 1;
123  }
124 
127 
132  void
133  setRectSize (const int width, const int height);
134 
138  void
139  setBorderPolicy (const BorderPolicy border_policy)
140  {
141  border_policy_ = border_policy;
142  }
143 
150  void
151  computePointNormal (const int pos_x, const int pos_y, const unsigned point_index, PointOutT &normal);
152 
159  void
160  computePointNormalMirror (const int pos_x, const int pos_y, const unsigned point_index, PointOutT &normal);
161 
166  void
167  setMaxDepthChangeFactor (float max_depth_change_factor)
168  {
169  max_depth_change_factor_ = max_depth_change_factor;
170  }
171 
176  void
177  setNormalSmoothingSize (float normal_smoothing_size)
178  {
179  normal_smoothing_size_ = normal_smoothing_size;
180  }
181 
194  void
196  {
197  normal_estimation_method_ = normal_estimation_method;
198  }
199 
203  void
204  setDepthDependentSmoothing (bool use_depth_dependent_smoothing)
205  {
206  use_depth_dependent_smoothing_ = use_depth_dependent_smoothing;
207  }
208 
212  virtual inline void
213  setInputCloud (const typename PointCloudIn::ConstPtr &cloud)
214  {
215  input_ = cloud;
216  if (!cloud->isOrganized ())
217  {
218  PCL_ERROR ("[pcl::IntegralImageNormalEstimation::setInputCloud] Input dataset is not organized (height = 1).\n");
219  return;
220  }
221 
222  init_covariance_matrix_ = init_average_3d_gradient_ = init_depth_change_ = false;
223 
224  if (use_sensor_origin_)
225  {
226  vpx_ = input_->sensor_origin_.coeff (0);
227  vpy_ = input_->sensor_origin_.coeff (1);
228  vpz_ = input_->sensor_origin_.coeff (2);
229  }
230 
231  // Initialize the correct data structure based on the normal estimation method chosen
232  initData ();
233  }
234 
237  inline float*
239  {
240  return (distance_map_);
241  }
242 
248  inline void
249  setViewPoint (float vpx, float vpy, float vpz)
250  {
251  vpx_ = vpx;
252  vpy_ = vpy;
253  vpz_ = vpz;
254  use_sensor_origin_ = false;
255  }
256 
265  inline void
266  getViewPoint (float &vpx, float &vpy, float &vpz)
267  {
268  vpx = vpx_;
269  vpy = vpy_;
270  vpz = vpz_;
271  }
272 
277  inline void
279  {
280  use_sensor_origin_ = true;
281  if (input_)
282  {
283  vpx_ = input_->sensor_origin_.coeff (0);
284  vpy_ = input_->sensor_origin_.coeff (1);
285  vpz_ = input_->sensor_origin_.coeff (2);
286  }
287  else
288  {
289  vpx_ = 0;
290  vpy_ = 0;
291  vpz_ = 0;
292  }
293  }
294 
295  protected:
296 
300  void
301  computeFeature (PointCloudOut &output);
302 
304  void
305  initData ();
306 
307  private:
314  NormalEstimationMethod normal_estimation_method_;
315 
317  BorderPolicy border_policy_;
318 
320  int rect_width_;
321  int rect_width_2_;
322  int rect_width_4_;
324  int rect_height_;
325  int rect_height_2_;
326  int rect_height_4_;
327 
329  float distance_threshold_;
330 
332  IntegralImage2D<float, 3> integral_image_DX_;
334  IntegralImage2D<float, 3> integral_image_DY_;
336  IntegralImage2D<float, 1> integral_image_depth_;
338  IntegralImage2D<float, 3> integral_image_XYZ_;
339 
341  float *diff_x_;
343  float *diff_y_;
344 
346  float *depth_data_;
347 
349  float *distance_map_;
350 
352  bool use_depth_dependent_smoothing_;
353 
355  float max_depth_change_factor_;
356 
358  float normal_smoothing_size_;
359 
361  bool init_covariance_matrix_;
362 
364  bool init_average_3d_gradient_;
365 
367  bool init_simple_3d_gradient_;
368 
370  bool init_depth_change_;
371 
374  float vpx_, vpy_, vpz_;
375 
377  bool use_sensor_origin_;
378 
380  bool
381  initCompute ();
382 
384  void
385  initCovarianceMatrixMethod ();
386 
388  void
389  initAverage3DGradientMethod ();
390 
392  void
393  initAverageDepthChangeMethod ();
394 
396  void
397  initSimple3DGradientMethod ();
398 
399  private:
403  void
404  computeFeatureEigen (pcl::PointCloud<Eigen::MatrixXf> &) {}
405  public:
406  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
407  };
408 }
409 #if defined BUILD_Maintainer && defined __GNUC__ && __GNUC__ == 4 && __GNUC_MINOR__ > 3
410 #pragma GCC diagnostic warning "-Weffc++"
411 #endif
412 
413 
414 #endif
415