1 /*
2  * Software License Agreement (BSD License)
3  *
4  *  Point Cloud Library (PCL) - www.pointclouds.org
5  *  Copyright (c) 2012, Yani Ioannou <yani.ioannou@gmail.com>
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 A Difference of Normals (DoN) scale filter implementation for point cloud data.
46    *
47    * For each point in the point cloud two normals estimated with a differing search radius (sigma_s, sigma_l)
48    * are subtracted, the difference of these normals provides a scale-based feature which
49    * can be further used to filter the point cloud, somewhat like the Difference of Guassians
50    * in image processing, but instead on surfaces. Best results are had when the two search
51    * radii are related as sigma_l=10*sigma_s, the octaves between the two search radii
52    * can be though of as a filter bandwidth. For appropriate values and thresholds it
53    * can be used for surface edge extraction.
54    *
55    * \attention The input normals given by setInputNormalsSmall and setInputNormalsLarge have
56    * to match the input point cloud given by setInputCloud. This behavior is different than
57    * feature estimation methods that extend FeatureFromNormals, which match the normals
58    * with the search surface.
59    *
60    * \note For more information please see
61    *    <b>Yani Ioannou. Automatic Urban Modelling using Mobile Urban LIDAR Data.
62    *    Thesis (Master, Computing), Queen's University, March, 2010.</b>
63    *
64    * \author Yani Ioannou.
65    * \ingroup features
66    */
67   template <typename PointInT, typename PointNT, typename PointOutT>
68   class DifferenceOfNormalsEstimation : public Feature<PointInT, PointOutT>
69   {
70       using Feature<PointInT, PointOutT>::getClassName;
71       using Feature<PointInT, PointOutT>::feature_name_;
72       using PCLBase<PointInT>::input_;
73       using PointCloudN = pcl::PointCloud<PointNT>;
74       using PointCloudNPtr = typename PointCloudN::Ptr;
75       using PointCloudNConstPtr = typename PointCloudN::ConstPtr;
76       using PointCloudOut = typename Feature<PointInT, PointOutT>::PointCloudOut;
77     public:
78       using Ptr = shared_ptr<DifferenceOfNormalsEstimation<PointInT, PointNT, PointOutT> >;
79       using ConstPtr = shared_ptr<const DifferenceOfNormalsEstimation<PointInT, PointNT, PointOutT> >;
80 
81       /**
82         * Creates a new Difference of Normals filter.
83         */
DifferenceOfNormalsEstimation()84       DifferenceOfNormalsEstimation ()
85       {
86         feature_name_ = "DifferenceOfNormalsEstimation";
87       }
88 
~DifferenceOfNormalsEstimation()89       ~DifferenceOfNormalsEstimation ()
90       {
91         //
92       }
93 
94       /**
95        * Set the normals calculated using a smaller search radius (scale) for the DoN operator.
96        * @param normals the smaller radius (scale) of the DoN filter.
97        */
98       inline void
setNormalScaleSmall(const PointCloudNConstPtr & normals)99       setNormalScaleSmall (const PointCloudNConstPtr &normals)
100       {
101         input_normals_small_ = normals;
102       }
103 
104       /**
105        * Set the normals calculated using a larger search radius (scale) for the DoN operator.
106        * @param normals the larger radius (scale) of the DoN filter.
107        */
108       inline void
setNormalScaleLarge(const PointCloudNConstPtr & normals)109       setNormalScaleLarge (const PointCloudNConstPtr &normals)
110       {
111         input_normals_large_ = normals;
112       }
113 
114       /**
115        * Computes the DoN vector for each point in the input point cloud and outputs the vector cloud to the given output.
116        * @param output the cloud to output the DoN vector cloud to.
117        */
118       void
119       computeFeature (PointCloudOut &output) override;
120 
121       /**
122        * Initialize for computation of features.
123        * @return true if parameters (input normals, input) are sufficient to perform computation.
124        */
125       bool
126       initCompute () override;
127     private:
128       /** \brief Make the compute (&PointCloudOut); inaccessible from outside the class
129         * \param[out] output the output point cloud
130         */
131       void
compute(PointCloudOut &)132       compute (PointCloudOut &) {}
133 
134       ///The smallest radius (scale) used in the DoN filter.
135       PointCloudNConstPtr input_normals_small_;
136       ///The largest radius (scale) used in the DoN filter.
137       PointCloudNConstPtr input_normals_large_;
138     };
139 }
140 
141 #ifdef PCL_NO_PRECOMPILE
142 #include <pcl/features/impl/don.hpp>
143 #endif
144