Point Cloud Library (PCL)  1.11.1-dev
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 #pragma once
40 
41 #include <pcl/features/feature.h>
42 
43 namespace pcl
44 {
45  /** \brief Surface normal estimation on dense data using a least-squares estimation based on a first-order Taylor approximation.
46  * \author Stefan Holzer, Cedric Cagniart
47  */
48  template <typename PointInT, typename PointOutT>
49  class LinearLeastSquaresNormalEstimation : public Feature<PointInT, PointOutT>
50  {
51  public:
52  using Ptr = shared_ptr<LinearLeastSquaresNormalEstimation<PointInT, PointOutT> >;
53  using ConstPtr = shared_ptr<const LinearLeastSquaresNormalEstimation<PointInT, PointOutT> >;
60 
61  /** \brief Constructor */
63  use_depth_dependent_smoothing_(false),
64  max_depth_change_factor_(1.0f),
65  normal_smoothing_size_(9.0f)
66  {
67  feature_name_ = "LinearLeastSquaresNormalEstimation";
68  tree_.reset ();
69  k_ = 1;
70  };
71 
72  /** \brief Destructor */
74 
75  /** \brief Computes the normal at the specified position.
76  * \param[in] pos_x x position (pixel)
77  * \param[in] pos_y y position (pixel)
78  * \param[out] normal the output estimated normal
79  */
80  void
81  computePointNormal (const int pos_x, const int pos_y, PointOutT &normal);
82 
83  /** \brief Set the normal smoothing size
84  * \param[in] normal_smoothing_size factor which influences the size of the area used to smooth normals
85  * (depth dependent if useDepthDependentSmoothing is true)
86  */
87  void
88  setNormalSmoothingSize (float normal_smoothing_size)
89  {
90  normal_smoothing_size_ = normal_smoothing_size;
91  }
92 
93  /** \brief Set whether to use depth depending smoothing or not
94  * \param[in] use_depth_dependent_smoothing decides whether the smoothing is depth dependent
95  */
96  void
97  setDepthDependentSmoothing (bool use_depth_dependent_smoothing)
98  {
99  use_depth_dependent_smoothing_ = use_depth_dependent_smoothing;
100  }
101 
102  /** \brief The depth change threshold for computing object borders
103  * \param[in] max_depth_change_factor the depth change threshold for computing object borders based on
104  * depth changes
105  */
106  void
107  setMaxDepthChangeFactor (float max_depth_change_factor)
108  {
109  max_depth_change_factor_ = max_depth_change_factor;
110  }
111 
112  /** \brief Provide a pointer to the input dataset (overwrites the PCLBase::setInputCloud method)
113  * \param[in] cloud the const boost shared pointer to a PointCloud message
114  */
115  inline void
116  setInputCloud (const typename PointCloudIn::ConstPtr &cloud) override
117  {
118  input_ = cloud;
119  }
120 
121  protected:
122  /** \brief Computes the normal for the complete cloud.
123  * \param[out] output the resultant normals
124  */
125  void
126  computeFeature (PointCloudOut &output) override;
127 
128  private:
129 
130  /** the threshold used to detect depth discontinuities */
131  //float distance_threshold_;
132 
133  /** \brief Smooth data based on depth (true/false). */
134  bool use_depth_dependent_smoothing_;
135 
136  /** \brief Threshold for detecting depth discontinuities */
137  float max_depth_change_factor_;
138 
139  /** \brief */
140  float normal_smoothing_size_;
141  };
142 }
143 
144 #ifdef PCL_NO_PRECOMPILE
145 #include <pcl/features/impl/linear_least_squares_normal.hpp>
146 #endif
pcl
Definition: convolution.h:46
pcl::Feature::Ptr
shared_ptr< Feature< PointInT, PointOutT > > Ptr
Definition: feature.h:114
pcl::PCLBase< PointInT >::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:147
pcl::LinearLeastSquaresNormalEstimation::setDepthDependentSmoothing
void setDepthDependentSmoothing(bool use_depth_dependent_smoothing)
Set whether to use depth depending smoothing or not.
Definition: linear_least_squares_normal.h:97
pcl::PointCloud< PointInT >
pcl::LinearLeastSquaresNormalEstimation::LinearLeastSquaresNormalEstimation
LinearLeastSquaresNormalEstimation()
Constructor.
Definition: linear_least_squares_normal.h:62
pcl::Feature::ConstPtr
shared_ptr< const Feature< PointInT, PointOutT > > ConstPtr
Definition: feature.h:115
pcl::LinearLeastSquaresNormalEstimation::~LinearLeastSquaresNormalEstimation
~LinearLeastSquaresNormalEstimation()
Destructor.
Definition: linear_least_squares_normal.hpp:47
pcl::LinearLeastSquaresNormalEstimation::setNormalSmoothingSize
void setNormalSmoothingSize(float normal_smoothing_size)
Set the normal smoothing size.
Definition: linear_least_squares_normal.h:88
pcl::LinearLeastSquaresNormalEstimation::setInputCloud
void setInputCloud(const typename PointCloudIn::ConstPtr &cloud) override
Provide a pointer to the input dataset (overwrites the PCLBase::setInputCloud method)
Definition: linear_least_squares_normal.h:116
pcl::LinearLeastSquaresNormalEstimation::setMaxDepthChangeFactor
void setMaxDepthChangeFactor(float max_depth_change_factor)
The depth change threshold for computing object borders.
Definition: linear_least_squares_normal.h:107
pcl::Feature::tree_
KdTreePtr tree_
A pointer to the spatial search object.
Definition: feature.h:234
pcl::LinearLeastSquaresNormalEstimation
Surface normal estimation on dense data using a least-squares estimation based on a first-order Taylo...
Definition: linear_least_squares_normal.h:49
pcl::LinearLeastSquaresNormalEstimation::PointCloudOut
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: linear_least_squares_normal.h:55
pcl::Feature::k_
int k_
The number of K nearest neighbors to use for each point.
Definition: feature.h:243
pcl::LinearLeastSquaresNormalEstimation::computeFeature
void computeFeature(PointCloudOut &output) override
Computes the normal for the complete cloud.
Definition: linear_least_squares_normal.hpp:155
pcl::PointCloud< PointInT >::ConstPtr
shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition: point_cloud.h:408
pcl::Feature::feature_name_
std::string feature_name_
The feature name.
Definition: feature.h:223
pcl::LinearLeastSquaresNormalEstimation::computePointNormal
void computePointNormal(const int pos_x, const int pos_y, PointOutT &normal)
Computes the normal at the specified position.
Definition: linear_least_squares_normal.hpp:53
pcl::Feature
Feature represents the base feature class.
Definition: feature.h:106