Point Cloud Library (PCL)  1.14.1-dev
shot.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 
40 #pragma once
41 
42 #include <pcl/point_types.h>
43 #include <pcl/features/feature.h>
44 
45 #include <array> // for sRGB_LUT, sXYZ_LUT
46 
47 namespace pcl
48 {
49  /** \brief SHOTEstimation estimates the Signature of Histograms of OrienTations (SHOT) descriptor for
50  * a given point cloud dataset containing points and normals.
51  *
52  * The suggested PointOutT is pcl::SHOT352.
53  *
54  * \note If you use this code in any academic work, please cite:
55  *
56  * - F. Tombari, S. Salti, L. Di Stefano
57  * Unique Signatures of Histograms for Local Surface Description.
58  * In Proceedings of the 11th European Conference on Computer Vision (ECCV),
59  * Heraklion, Greece, September 5-11 2010.
60  * - F. Tombari, S. Salti, L. Di Stefano
61  * A Combined Texture-Shape Descriptor For Enhanced 3D Feature Matching.
62  * In Proceedings of the 18th International Conference on Image Processing (ICIP),
63  * Brussels, Belgium, September 11-14 2011.
64  *
65  * \author Samuele Salti, Federico Tombari
66  * \ingroup features
67  */
68  template <typename PointInT, typename PointNT, typename PointOutT, typename PointRFT = pcl::ReferenceFrame>
69  class SHOTEstimationBase : public FeatureFromNormals<PointInT, PointNT, PointOutT>,
70  public FeatureWithLocalReferenceFrames<PointInT, PointRFT>
71  {
72  public:
73  using Ptr = shared_ptr<SHOTEstimationBase<PointInT, PointNT, PointOutT, PointRFT> >;
74  using ConstPtr = shared_ptr<const SHOTEstimationBase<PointInT, PointNT, PointOutT, PointRFT> >;
86 
88 
89  protected:
90  /** \brief Empty constructor.
91  * \param[in] nr_shape_bins the number of bins in the shape histogram
92  */
93  SHOTEstimationBase (int nr_shape_bins = 10) :
94  nr_shape_bins_ (nr_shape_bins)
95  {
96  feature_name_ = "SHOTEstimation";
97  }
98 
99  public:
100 
101  /** \brief Empty destructor */
102  ~SHOTEstimationBase () override = default;
103 
104  /** \brief Estimate the SHOT descriptor for a given point based on its spatial neighborhood of 3D points with normals
105  * \param[in] index the index of the point in indices_
106  * \param[in] indices the k-neighborhood point indices in surface_
107  * \param[in] sqr_dists the k-neighborhood point distances in surface_
108  * \param[out] shot the resultant SHOT descriptor representing the feature at the query point
109  */
110  virtual void
111  computePointSHOT (const int index,
112  const pcl::Indices &indices,
113  const std::vector<float> &sqr_dists,
114  Eigen::VectorXf &shot) = 0;
115 
116  /** \brief Set the radius used for local reference frame estimation if the frames are not set by the user */
117  virtual void
118  setLRFRadius (float radius) { lrf_radius_ = radius; }
119 
120  /** \brief Get the radius used for local reference frame estimation */
121  virtual float
122  getLRFRadius () const { return lrf_radius_; }
123 
124  protected:
125 
126  /** \brief This method should get called before starting the actual computation. */
127  bool
128  initCompute () override;
129 
130  /** \brief Quadrilinear interpolation used when color and shape descriptions are NOT activated simultaneously
131  *
132  * \param[in] indices the neighborhood point indices
133  * \param[in] sqr_dists the neighborhood point distances
134  * \param[in] index the index of the point in indices_
135  * \param[out] binDistance the resultant distance shape histogram
136  * \param[in] nr_bins the number of bins in the shape histogram
137  * \param[out] shot the resultant SHOT histogram
138  */
139  void
140  interpolateSingleChannel (const pcl::Indices &indices,
141  const std::vector<float> &sqr_dists,
142  const int index,
143  std::vector<double> &binDistance,
144  const int nr_bins,
145  Eigen::VectorXf &shot);
146 
147  /** \brief Normalize the SHOT histogram.
148  * \param[in,out] shot the SHOT histogram
149  * \param[in] desc_length the length of the histogram
150  */
151  void
152  normalizeHistogram (Eigen::VectorXf &shot, int desc_length);
153 
154 
155  /** \brief Create a binned distance shape histogram
156  * \param[in] index the index of the point in indices_
157  * \param[in] indices the k-neighborhood point indices in surface_
158  * \param[out] bin_distance_shape the resultant histogram
159  */
160  void
161  createBinDistanceShape (int index, const pcl::Indices &indices,
162  std::vector<double> &bin_distance_shape);
163 
164  /** \brief The number of bins in each shape histogram. */
166 
167  /** \brief The radius used for the LRF computation */
168  float lrf_radius_{0.0f};
169 
170  /** \brief The squared search radius. */
171  double sqradius_{0.0};
172 
173  /** \brief 3/4 of the search radius. */
174  double radius3_4_{0.0};
175 
176  /** \brief 1/4 of the search radius. */
177  double radius1_4_{0.0};
178 
179  /** \brief 1/2 of the search radius. */
180  double radius1_2_{0.0};
181 
182  /** \brief Number of azimuthal sectors. */
183  const int nr_grid_sector_{32};
184 
185  /** \brief ... */
186  const int maxAngularSectors_{32};
187 
188  /** \brief One SHOT length. */
189  int descLength_{0};
190  };
191 
192  /** \brief SHOTEstimation estimates the Signature of Histograms of OrienTations (SHOT) descriptor for
193  * a given point cloud dataset containing points and normals.
194  *
195  * The suggested PointOutT is pcl::SHOT352
196  *
197  * \note If you use this code in any academic work, please cite:
198  *
199  * - F. Tombari, S. Salti, L. Di Stefano
200  * Unique Signatures of Histograms for Local Surface Description.
201  * In Proceedings of the 11th European Conference on Computer Vision (ECCV),
202  * Heraklion, Greece, September 5-11 2010.
203  * - F. Tombari, S. Salti, L. Di Stefano
204  * A Combined Texture-Shape Descriptor For Enhanced 3D Feature Matching.
205  * In Proceedings of the 18th International Conference on Image Processing (ICIP),
206  * Brussels, Belgium, September 11-14 2011.
207  *
208  * \author Samuele Salti, Federico Tombari
209  * \ingroup features
210  */
211  template <typename PointInT, typename PointNT, typename PointOutT = pcl::SHOT352, typename PointRFT = pcl::ReferenceFrame>
212  class SHOTEstimation : public SHOTEstimationBase<PointInT, PointNT, PointOutT, PointRFT>
213  {
214  public:
215  using Ptr = shared_ptr<SHOTEstimation<PointInT, PointNT, PointOutT, PointRFT> >;
216  using ConstPtr = shared_ptr<const SHOTEstimation<PointInT, PointNT, PointOutT, PointRFT> >;
236 
238 
239  /** \brief Empty constructor. */
240  SHOTEstimation () : SHOTEstimationBase<PointInT, PointNT, PointOutT, PointRFT> (10)
241  {
242  feature_name_ = "SHOTEstimation";
243  };
244 
245  /** \brief Empty destructor */
246  ~SHOTEstimation () override = default;
247 
248  /** \brief Estimate the SHOT descriptor for a given point based on its spatial neighborhood of 3D points with normals
249  * \param[in] index the index of the point in indices_
250  * \param[in] indices the k-neighborhood point indices in surface_
251  * \param[in] sqr_dists the k-neighborhood point distances in surface_
252  * \param[out] shot the resultant SHOT descriptor representing the feature at the query point
253  */
254  void
255  computePointSHOT (const int index,
256  const pcl::Indices &indices,
257  const std::vector<float> &sqr_dists,
258  Eigen::VectorXf &shot) override;
259  protected:
260  /** \brief Estimate the Signatures of Histograms of OrienTations (SHOT) descriptors at a set of points given by
261  * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
262  * setSearchMethod ()
263  * \param output the resultant point cloud model dataset that contains the SHOT feature estimates
264  */
265  void
266  computeFeature (pcl::PointCloud<PointOutT> &output) override;
267  };
268 
269  /** \brief SHOTColorEstimation estimates the Signature of Histograms of OrienTations (SHOT) descriptor for a given point cloud dataset
270  * containing points, normals and colors.
271  *
272  * The suggested PointOutT is pcl::SHOT1344
273  *
274  * \note If you use this code in any academic work, please cite:
275  *
276  * - F. Tombari, S. Salti, L. Di Stefano
277  * Unique Signatures of Histograms for Local Surface Description.
278  * In Proceedings of the 11th European Conference on Computer Vision (ECCV),
279  * Heraklion, Greece, September 5-11 2010.
280  * - F. Tombari, S. Salti, L. Di Stefano
281  * A Combined Texture-Shape Descriptor For Enhanced 3D Feature Matching.
282  * In Proceedings of the 18th International Conference on Image Processing (ICIP),
283  * Brussels, Belgium, September 11-14 2011.
284  *
285  * \author Samuele Salti, Federico Tombari
286  * \ingroup features
287  */
288  template <typename PointInT, typename PointNT, typename PointOutT = pcl::SHOT1344, typename PointRFT = pcl::ReferenceFrame>
289  class SHOTColorEstimation : public SHOTEstimationBase<PointInT, PointNT, PointOutT, PointRFT>
290  {
291  public:
292  using Ptr = shared_ptr<SHOTColorEstimation<PointInT, PointNT, PointOutT, PointRFT> >;
293  using ConstPtr = shared_ptr<const SHOTColorEstimation<PointInT, PointNT, PointOutT, PointRFT> >;
313 
315 
316  /** \brief Empty constructor.
317  * \param[in] describe_shape
318  * \param[in] describe_color
319  */
320  SHOTColorEstimation (bool describe_shape = true,
321  bool describe_color = true)
322  : SHOTEstimationBase<PointInT, PointNT, PointOutT, PointRFT> (10),
323  b_describe_shape_ (describe_shape),
324  b_describe_color_ (describe_color)
325  {
326  feature_name_ = "SHOTColorEstimation";
327  }
328 
329  /** \brief Empty destructor */
330  ~SHOTColorEstimation () override = default;
331 
332  /** \brief Estimate the SHOT descriptor for a given point based on its spatial neighborhood of 3D points with normals
333  * \param[in] index the index of the point in indices_
334  * \param[in] indices the k-neighborhood point indices in surface_
335  * \param[in] sqr_dists the k-neighborhood point distances in surface_
336  * \param[out] shot the resultant SHOT descriptor representing the feature at the query point
337  */
338  void
339  computePointSHOT (const int index,
340  const pcl::Indices &indices,
341  const std::vector<float> &sqr_dists,
342  Eigen::VectorXf &shot) override;
343  protected:
344  /** \brief Estimate the Signatures of Histograms of OrienTations (SHOT) descriptors at a set of points given by
345  * <setInputCloud (), setIndices ()> using the surface in setSearchSurface () and the spatial locator in
346  * setSearchMethod ()
347  * \param output the resultant point cloud model dataset that contains the SHOT feature estimates
348  */
349  void
350  computeFeature (pcl::PointCloud<PointOutT> &output) override;
351 
352  /** \brief Quadrilinear interpolation; used when color and shape descriptions are both activated
353  * \param[in] indices the neighborhood point indices
354  * \param[in] sqr_dists the neighborhood point distances
355  * \param[in] index the index of the point in indices_
356  * \param[out] binDistanceShape the resultant distance shape histogram
357  * \param[out] binDistanceColor the resultant color shape histogram
358  * \param[in] nr_bins_shape the number of bins in the shape histogram
359  * \param[in] nr_bins_color the number of bins in the color histogram
360  * \param[out] shot the resultant SHOT histogram
361  */
362  void
363  interpolateDoubleChannel (const pcl::Indices &indices,
364  const std::vector<float> &sqr_dists,
365  const int index,
366  std::vector<double> &binDistanceShape,
367  std::vector<double> &binDistanceColor,
368  const int nr_bins_shape,
369  const int nr_bins_color,
370  Eigen::VectorXf &shot);
371 
372  /** \brief Compute shape descriptor. */
374 
375  /** \brief Compute color descriptor. */
377 
378  /** \brief The number of bins in each color histogram. */
379  int nr_color_bins_{30};
380 
381  public:
382  /** \brief Converts RGB triplets to CIELab space.
383  * \param[in] R the red channel
384  * \param[in] G the green channel
385  * \param[in] B the blue channel
386  * \param[out] L the lightness
387  * \param[out] A the first color-opponent dimension
388  * \param[out] B2 the second color-opponent dimension
389  */
390  static void
391  RGB2CIELAB (unsigned char R, unsigned char G, unsigned char B, float &L, float &A, float &B2);
392 
393  static std::array<float, 256> sRGB_LUT;
394  static std::array<float, 4000> sXYZ_LUT;
395  };
396 }
397 
398 #ifdef PCL_NO_PRECOMPILE
399 #include <pcl/features/impl/shot.hpp>
400 #endif
Feature represents the base feature class.
Definition: feature.h:107
shared_ptr< Feature< PointInT, PointOutT > > Ptr
Definition: feature.h:114
std::string feature_name_
The feature name.
Definition: feature.h:220
shared_ptr< const Feature< PointInT, PointOutT > > ConstPtr
Definition: feature.h:115
FeatureWithLocalReferenceFrames provides a public interface for descriptor extractor classes which ne...
Definition: feature.h:440
SHOTColorEstimation estimates the Signature of Histograms of OrienTations (SHOT) descriptor for a giv...
Definition: shot.h:290
static std::array< float, 4000 > sXYZ_LUT
Definition: shot.h:394
bool b_describe_color_
Compute color descriptor.
Definition: shot.h:376
void interpolateDoubleChannel(const pcl::Indices &indices, const std::vector< float > &sqr_dists, const int index, std::vector< double > &binDistanceShape, std::vector< double > &binDistanceColor, const int nr_bins_shape, const int nr_bins_color, Eigen::VectorXf &shot)
Quadrilinear interpolation; used when color and shape descriptions are both activated.
Definition: shot.hpp:412
SHOTColorEstimation(bool describe_shape=true, bool describe_color=true)
Empty constructor.
Definition: shot.h:320
void computeFeature(pcl::PointCloud< PointOutT > &output) override
Estimate the Signatures of Histograms of OrienTations (SHOT) descriptors at a set of points given by ...
Definition: shot.hpp:810
bool b_describe_shape_
Compute shape descriptor.
Definition: shot.h:373
int nr_color_bins_
The number of bins in each color histogram.
Definition: shot.h:379
static std::array< float, 256 > sRGB_LUT
Definition: shot.h:393
static void RGB2CIELAB(unsigned char R, unsigned char G, unsigned char B, float &L, float &A, float &B2)
Converts RGB triplets to CIELab space.
Definition: shot.hpp:100
~SHOTColorEstimation() override=default
Empty destructor.
void computePointSHOT(const int index, const pcl::Indices &indices, const std::vector< float > &sqr_dists, Eigen::VectorXf &shot) override
Estimate the SHOT descriptor for a given point based on its spatial neighborhood of 3D points with no...
Definition: shot.hpp:628
SHOTEstimation estimates the Signature of Histograms of OrienTations (SHOT) descriptor for a given po...
Definition: shot.h:71
double radius1_2_
1/2 of the search radius.
Definition: shot.h:180
virtual float getLRFRadius() const
Get the radius used for local reference frame estimation.
Definition: shot.h:122
const int maxAngularSectors_
...
Definition: shot.h:186
bool initCompute() override
This method should get called before starting the actual computation.
Definition: shot.hpp:140
const int nr_grid_sector_
Number of azimuthal sectors.
Definition: shot.h:183
void normalizeHistogram(Eigen::VectorXf &shot, int desc_length)
Normalize the SHOT histogram.
Definition: shot.hpp:220
double radius3_4_
3/4 of the search radius.
Definition: shot.h:174
~SHOTEstimationBase() override=default
Empty destructor.
int descLength_
One SHOT length.
Definition: shot.h:189
void interpolateSingleChannel(const pcl::Indices &indices, const std::vector< float > &sqr_dists, const int index, std::vector< double > &binDistance, const int nr_bins, Eigen::VectorXf &shot)
Quadrilinear interpolation used when color and shape descriptions are NOT activated simultaneously.
Definition: shot.hpp:237
virtual void computePointSHOT(const int index, const pcl::Indices &indices, const std::vector< float > &sqr_dists, Eigen::VectorXf &shot)=0
Estimate the SHOT descriptor for a given point based on its spatial neighborhood of 3D points with no...
double sqradius_
The squared search radius.
Definition: shot.h:171
float lrf_radius_
The radius used for the LRF computation.
Definition: shot.h:168
void createBinDistanceShape(int index, const pcl::Indices &indices, std::vector< double > &bin_distance_shape)
Create a binned distance shape histogram.
Definition: shot.hpp:176
virtual void setLRFRadius(float radius)
Set the radius used for local reference frame estimation if the frames are not set by the user.
Definition: shot.h:118
int nr_shape_bins_
The number of bins in each shape histogram.
Definition: shot.h:165
SHOTEstimationBase(int nr_shape_bins=10)
Empty constructor.
Definition: shot.h:93
double radius1_4_
1/4 of the search radius.
Definition: shot.h:177
SHOTEstimation estimates the Signature of Histograms of OrienTations (SHOT) descriptor for a given po...
Definition: shot.h:213
~SHOTEstimation() override=default
Empty destructor.
SHOTEstimation()
Empty constructor.
Definition: shot.h:240
void computeFeature(pcl::PointCloud< PointOutT > &output) override
Estimate the Signatures of Histograms of OrienTations (SHOT) descriptors at a set of points given by ...
Definition: shot.hpp:743
void computePointSHOT(const int index, const pcl::Indices &indices, const std::vector< float > &sqr_dists, Eigen::VectorXf &shot) override
Estimate the SHOT descriptor for a given point based on its spatial neighborhood of 3D points with no...
Definition: shot.hpp:713
Defines all the PCL implemented PointT point type structures.
@ B
Definition: norms.h:54
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133