Point Cloud Library (PCL)  1.7.0
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 #ifndef PCL_FEATURES_3DSC_H_
42 #define PCL_FEATURES_3DSC_H_
43 
44 #include <pcl/point_types.h>
45 #include <pcl/features/boost.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  typedef boost::shared_ptr<ShapeContext3DEstimation<PointInT, PointNT, PointOutT> > Ptr;
76  typedef boost::shared_ptr<const ShapeContext3DEstimation<PointInT, PointNT, PointOutT> > ConstPtr;
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  azimuth_bins_(12),
101  elevation_bins_(11),
102  radius_bins_(15),
103  min_radius_(0.1),
106  rng_alg_ (),
107  rng_ (new boost::uniform_01<boost::mt19937> (rng_alg_))
108  {
109  feature_name_ = "ShapeContext3DEstimation";
110  search_radius_ = 2.5;
111 
112  // Create a random number generator object
113  if (random)
114  rng_->base ().seed (static_cast<unsigned> (std::time(0)));
115  else
116  rng_->base ().seed (12345u);
117  }
118 
120 
121  //inline void
122  //setAzimuthBins (size_t bins) { azimuth_bins_ = bins; }
123 
124  /** \return the number of bins along the azimuth */
125  inline size_t
126  getAzimuthBins () { return (azimuth_bins_); }
127 
128  //inline void
129  //setElevationBins (size_t bins) { elevation_bins_ = bins; }
130 
131  /** \return The number of bins along the elevation */
132  inline size_t
134 
135  //inline void
136  //setRadiusBins (size_t bins) { radius_bins_ = bins; }
137 
138  /** \return The number of bins along the radii direction */
139  inline size_t
140  getRadiusBins () { return (radius_bins_); }
141 
142  /** \brief The minimal radius value for the search sphere (rmin) in the original paper
143  * \param[in] radius the desired minimal radius
144  */
145  inline void
146  setMinimalRadius (double radius) { min_radius_ = radius; }
147 
148  /** \return The minimal sphere radius */
149  inline double
150  getMinimalRadius () { return (min_radius_); }
151 
152  /** \brief This radius is used to compute local point density
153  * density = number of points within this radius
154  * \param[in] radius value of the point density search radius
155  */
156  inline void
157  setPointDensityRadius (double radius) { point_density_radius_ = radius; }
158 
159  /** \return The point density search radius */
160  inline double
162 
163  protected:
164  /** \brief Initialize computation by allocating all the intervals and the volume lookup table. */
165  bool
166  initCompute ();
167 
168  /** \brief Estimate a descriptor for a given point.
169  * \param[in] index the index of the point to estimate a descriptor for
170  * \param[in] normals a pointer to the set of normals
171  * \param[in] rf the reference frame
172  * \param[out] desc the resultant estimated descriptor
173  * \return true if the descriptor was computed successfully, false if there was an error
174  * (e.g. the nearest neighbor didn't return any neighbors)
175  */
176  bool
177  computePoint (size_t index, const pcl::PointCloud<PointNT> &normals, float rf[9], std::vector<float> &desc);
178 
179  /** \brief Estimate the actual feature.
180  * \param[out] output the resultant feature
181  */
182  void
183  computeFeature (PointCloudOut &output);
184 
185  /** \brief Values of the radii interval */
186  std::vector<float> radii_interval_;
187 
188  /** \brief Theta divisions interval */
189  std::vector<float> theta_divisions_;
190 
191  /** \brief Phi divisions interval */
192  std::vector<float> phi_divisions_;
193 
194  /** \brief Volumes look up table */
195  std::vector<float> volume_lut_;
196 
197  /** \brief Bins along the azimuth dimension */
199 
200  /** \brief Bins along the elevation dimension */
202 
203  /** \brief Bins along the radius dimension */
204  size_t radius_bins_;
205 
206  /** \brief Minimal radius value */
207  double min_radius_;
208 
209  /** \brief Point density radius */
211 
212  /** \brief Descriptor length */
214 
215  /** \brief Boost-based random number generator algorithm. */
216  boost::mt19937 rng_alg_;
217 
218  /** \brief Boost-based random number generator distribution. */
219  boost::shared_ptr<boost::uniform_01<boost::mt19937> > rng_;
220 
221  /** \brief Shift computed descriptor "L" times along the azimuthal direction
222  * \param[in] block_size the size of each azimuthal block
223  * \param[in] desc at input desc == original descriptor and on output it contains
224  * shifted descriptor resized descriptor_length_ * azimuth_bins_
225  */
226  //void
227  //shiftAlongAzimuth (size_t block_size, std::vector<float>& desc);
228 
229  /** \brief Boost-based random number generator. */
230  inline double
231  rnd ()
232  {
233  return ((*rng_) ());
234  }
235  };
236 }
237 
238 #ifdef PCL_NO_PRECOMPILE
239 #include <pcl/features/impl/3dsc.hpp>
240 #endif
241 
242 #endif //#ifndef PCL_3DSC_H_