Point Cloud Library (PCL)  1.14.0-dev
3dsc.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  * $Id$
38  *
39  */
40 
41 #pragma once
42 
43 #include <random>
44 
45 #include <pcl/point_types.h>
46 #include <pcl/features/feature.h>
47 
48 namespace pcl
49 {
50  /** \brief ShapeContext3DEstimation implements the 3D shape context descriptor as
51  * described in:
52  * - Andrea Frome, Daniel Huber, Ravi Kolluri and Thomas Bülow, Jitendra Malik
53  * Recognizing Objects in Range Data Using Regional Point Descriptors,
54  * In proceedings of the 8th European Conference on Computer Vision (ECCV),
55  * Prague, May 11-14, 2004
56  *
57  * The suggested PointOutT is pcl::ShapeContext1980
58  *
59  * \attention
60  * The convention for a 3D shape context descriptor is:
61  * - if a query point's nearest neighbors cannot be estimated, the feature descriptor will be set to NaN (not a number), and the RF to 0
62  * - it is impossible to estimate a 3D shape context descriptor for a
63  * point that doesn't have finite 3D coordinates. Therefore, any point
64  * that contains NaN data on x, y, or z, will have its boundary feature
65  * property set to NaN.
66  *
67  * \author Alessandro Franchi, Samuele Salti, Federico Tombari (original code)
68  * \author Nizar Sallem (port to PCL)
69  * \ingroup features
70  */
71  template <typename PointInT, typename PointNT, typename PointOutT = pcl::ShapeContext1980>
72  class ShapeContext3DEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
73  {
74  public:
75  using Ptr = shared_ptr<ShapeContext3DEstimation<PointInT, PointNT, PointOutT> >;
76  using ConstPtr = shared_ptr<const ShapeContext3DEstimation<PointInT, PointNT, PointOutT> >;
77 
87 
90 
91  /** \brief Constructor.
92  * \param[in] random If true the random seed is set to current time, else it is
93  * set to 12345 prior to computing the descriptor (used to select X axis)
94  */
95  ShapeContext3DEstimation (bool random = false) :
96  radii_interval_(0),
98  phi_divisions_(0),
99  volume_lut_(0),
100 
101  rng_dist_ (0.0f, 1.0f)
102  {
103  feature_name_ = "ShapeContext3DEstimation";
104  search_radius_ = 2.5;
105 
106  // Create a random number generator object
107  if (random)
108  {
109  std::random_device rd;
110  rng_.seed (rd());
111  }
112  else
113  rng_.seed (12345u);
114  }
115 
116  ~ShapeContext3DEstimation() override = default;
117 
118  //inline void
119  //setAzimuthBins (std::size_t bins) { azimuth_bins_ = bins; }
120 
121  /** \return the number of bins along the azimuth */
122  inline std::size_t
123  getAzimuthBins () { return (azimuth_bins_); }
124 
125  //inline void
126  //setElevationBins (std::size_t bins) { elevation_bins_ = bins; }
127 
128  /** \return The number of bins along the elevation */
129  inline std::size_t
131 
132  //inline void
133  //setRadiusBins (std::size_t bins) { radius_bins_ = bins; }
134 
135  /** \return The number of bins along the radii direction */
136  inline std::size_t
137  getRadiusBins () { return (radius_bins_); }
138 
139  /** \brief The minimal radius value for the search sphere (rmin) in the original paper
140  * \param[in] radius the desired minimal radius
141  */
142  inline void
143  setMinimalRadius (double radius) { min_radius_ = radius; }
144 
145  /** \return The minimal sphere radius */
146  inline double
147  getMinimalRadius () { return (min_radius_); }
148 
149  /** \brief This radius is used to compute local point density
150  * density = number of points within this radius
151  * \param[in] radius value of the point density search radius
152  */
153  inline void
154  setPointDensityRadius (double radius) { point_density_radius_ = radius; }
155 
156  /** \return The point density search radius */
157  inline double
159 
160  protected:
161  /** \brief Initialize computation by allocating all the intervals and the volume lookup table. */
162  bool
163  initCompute () override;
164 
165  /** \brief Estimate a descriptor for a given point.
166  * \param[in] index the index of the point to estimate a descriptor for
167  * \param[in] normals a pointer to the set of normals
168  * \param[out] rf the reference frame
169  * \param[out] desc the resultant estimated descriptor
170  * \return true if the descriptor was computed successfully, false if there was an error
171  * (e.g. the nearest neighbor didn't return any neighbors)
172  */
173  bool
174  computePoint (std::size_t index, const pcl::PointCloud<PointNT> &normals, float rf[9], std::vector<float> &desc);
175 
176  /** \brief Estimate the actual feature.
177  * \param[out] output the resultant feature
178  */
179  void
180  computeFeature (PointCloudOut &output) override;
181 
182  /** \brief Values of the radii interval */
183  std::vector<float> radii_interval_;
184 
185  /** \brief Theta divisions interval */
186  std::vector<float> theta_divisions_;
187 
188  /** \brief Phi divisions interval */
189  std::vector<float> phi_divisions_;
190 
191  /** \brief Volumes look up table */
192  std::vector<float> volume_lut_;
193 
194  /** \brief Bins along the azimuth dimension */
195  std::size_t azimuth_bins_{12};
196 
197  /** \brief Bins along the elevation dimension */
198  std::size_t elevation_bins_{11};
199 
200  /** \brief Bins along the radius dimension */
201  std::size_t radius_bins_{15};
202 
203  /** \brief Minimal radius value */
204  double min_radius_{0.1};
205 
206  /** \brief Point density radius */
208 
209  /** \brief Descriptor length */
210  std::size_t descriptor_length_{};
211 
212  /** \brief Random number generator algorithm. */
213  std::mt19937 rng_;
214 
215  /** \brief Random number generator distribution. */
216  std::uniform_real_distribution<float> rng_dist_;
217 
218  /* \brief Shift computed descriptor "L" times along the azimuthal direction
219  * \param[in] block_size the size of each azimuthal block
220  * \param[in] desc at input desc == original descriptor and on output it contains
221  * shifted descriptor resized descriptor_length_ * azimuth_bins_
222  */
223  //void
224  //shiftAlongAzimuth (std::size_t block_size, std::vector<float>& desc);
225 
226  /** \brief Boost-based random number generator. */
227  inline float
228  rnd ()
229  {
230  return (rng_dist_ (rng_));
231  }
232  };
233 }
234 
235 #ifdef PCL_NO_PRECOMPILE
236 #include <pcl/features/impl/3dsc.hpp>
237 #endif
Feature represents the base feature class.
Definition: feature.h:107
double search_radius_
The nearest neighbors search radius for each point.
Definition: feature.h:237
std::string feature_name_
The feature name.
Definition: feature.h:220
ShapeContext3DEstimation implements the 3D shape context descriptor as described in:
Definition: 3dsc.h:73
std::uniform_real_distribution< float > rng_dist_
Random number generator distribution.
Definition: 3dsc.h:216
void setMinimalRadius(double radius)
The minimal radius value for the search sphere (rmin) in the original paper.
Definition: 3dsc.h:143
bool computePoint(std::size_t index, const pcl::PointCloud< PointNT > &normals, float rf[9], std::vector< float > &desc)
Estimate a descriptor for a given point.
Definition: 3dsc.hpp:133
std::size_t azimuth_bins_
Bins along the azimuth dimension.
Definition: 3dsc.h:195
std::size_t getAzimuthBins()
Definition: 3dsc.h:123
bool initCompute() override
Initialize computation by allocating all the intervals and the volume lookup table.
Definition: 3dsc.hpp:53
shared_ptr< const ShapeContext3DEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition: 3dsc.h:76
std::size_t radius_bins_
Bins along the radius dimension.
Definition: 3dsc.h:201
typename Feature< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: 3dsc.h:89
std::vector< float > radii_interval_
Values of the radii interval.
Definition: 3dsc.h:183
std::size_t getElevationBins()
Definition: 3dsc.h:130
float rnd()
Boost-based random number generator.
Definition: 3dsc.h:228
std::mt19937 rng_
Random number generator algorithm.
Definition: 3dsc.h:213
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: 3dsc.h:88
double getPointDensityRadius()
Definition: 3dsc.h:158
double min_radius_
Minimal radius value.
Definition: 3dsc.h:204
void computeFeature(PointCloudOut &output) override
Estimate the actual feature.
Definition: 3dsc.hpp:255
double point_density_radius_
Point density radius.
Definition: 3dsc.h:207
std::vector< float > volume_lut_
Volumes look up table.
Definition: 3dsc.h:192
std::size_t descriptor_length_
Descriptor length.
Definition: 3dsc.h:210
std::vector< float > theta_divisions_
Theta divisions interval.
Definition: 3dsc.h:186
~ShapeContext3DEstimation() override=default
ShapeContext3DEstimation(bool random=false)
Constructor.
Definition: 3dsc.h:95
std::vector< float > phi_divisions_
Phi divisions interval.
Definition: 3dsc.h:189
std::size_t getRadiusBins()
Definition: 3dsc.h:137
std::size_t elevation_bins_
Bins along the elevation dimension.
Definition: 3dsc.h:198
shared_ptr< ShapeContext3DEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition: 3dsc.h:75
void setPointDensityRadius(double radius)
This radius is used to compute local point density density = number of points within this radius.
Definition: 3dsc.h:154
Defines all the PCL implemented PointT point type structures.