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