Point Cloud Library (PCL)  1.7.0
linear_least_squares_normal.h
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  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  */
38 
39 #ifndef PCL_FEATURES_LINEAR_LEAST_SQUARES_NORMAL_H_
40 #define PCL_FEATURES_LINEAR_LEAST_SQUARES_NORMAL_H_
41 
42 #include <pcl/point_cloud.h>
43 #include <pcl/point_types.h>
44 #include <pcl/features/feature.h>
45 
46 namespace pcl
47 {
48  /** \brief Surface normal estimation on dense data using a least-squares estimation based on a first-order Taylor approximation.
49  * \author Stefan Holzer, Cedric Cagniart
50  */
51  template <typename PointInT, typename PointOutT>
52  class LinearLeastSquaresNormalEstimation : public Feature<PointInT, PointOutT>
53  {
54  public:
55  typedef boost::shared_ptr<LinearLeastSquaresNormalEstimation<PointInT, PointOutT> > Ptr;
56  typedef boost::shared_ptr<const LinearLeastSquaresNormalEstimation<PointInT, PointOutT> > ConstPtr;
63 
64  /** \brief Constructor */
66  use_depth_dependent_smoothing_(false),
67  max_depth_change_factor_(1.0f),
68  normal_smoothing_size_(9.0f)
69  {
70  feature_name_ = "LinearLeastSquaresNormalEstimation";
71  tree_.reset ();
72  k_ = 1;
73  };
74 
75  /** \brief Destructor */
77 
78  /** \brief Computes the normal at the specified position.
79  * \param[in] pos_x x position (pixel)
80  * \param[in] pos_y y position (pixel)
81  * \param[out] normal the output estimated normal
82  */
83  void
84  computePointNormal (const int pos_x, const int pos_y, PointOutT &normal);
85 
86  /** \brief Set the normal smoothing size
87  * \param[in] normal_smoothing_size factor which influences the size of the area used to smooth normals
88  * (depth dependent if useDepthDependentSmoothing is true)
89  */
90  void
91  setNormalSmoothingSize (float normal_smoothing_size)
92  {
93  normal_smoothing_size_ = normal_smoothing_size;
94  }
95 
96  /** \brief Set whether to use depth depending smoothing or not
97  * \param[in] use_depth_dependent_smoothing decides whether the smoothing is depth dependent
98  */
99  void
100  setDepthDependentSmoothing (bool use_depth_dependent_smoothing)
101  {
102  use_depth_dependent_smoothing_ = use_depth_dependent_smoothing;
103  }
104 
105  /** \brief The depth change threshold for computing object borders
106  * \param[in] max_depth_change_factor the depth change threshold for computing object borders based on
107  * depth changes
108  */
109  void
110  setMaxDepthChangeFactor (float max_depth_change_factor)
111  {
112  max_depth_change_factor_ = max_depth_change_factor;
113  }
114 
115  /** \brief Provide a pointer to the input dataset (overwrites the PCLBase::setInputCloud method)
116  * \param[in] cloud the const boost shared pointer to a PointCloud message
117  */
118  virtual inline void
119  setInputCloud (const typename PointCloudIn::ConstPtr &cloud)
120  {
121  input_ = cloud;
122  }
123 
124  protected:
125  /** \brief Computes the normal for the complete cloud.
126  * \param[out] output the resultant normals
127  */
128  void
129  computeFeature (PointCloudOut &output);
130 
131  private:
132 
133  /** the threshold used to detect depth discontinuities */
134  //float distance_threshold_;
135 
136  /** \brief Smooth data based on depth (true/false). */
137  bool use_depth_dependent_smoothing_;
138 
139  /** \brief Threshold for detecting depth discontinuities */
140  float max_depth_change_factor_;
141 
142  /** \brief */
143  float normal_smoothing_size_;
144  };
145 }
146 
147 #ifdef PCL_NO_PRECOMPILE
148 #include <pcl/features/impl/linear_least_squares_normal.hpp>
149 #endif
150 
151 #endif
152