Point Cloud Library (PCL)  1.14.1-dev
usc.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 <pcl/point_types.h>
44 #include <pcl/features/feature.h>
45 
46 namespace pcl
47 {
48  /** \brief UniqueShapeContext implements the Unique Shape Context Descriptor
49  * described here:
50  *
51  * - F. Tombari, S. Salti, L. Di Stefano,
52  * "Unique Shape Context for 3D data description",
53  * International Workshop on 3D Object Retrieval (3DOR 10) -
54  * in conjunction with ACM Multimedia 2010
55  *
56  * The suggested PointOutT is pcl::UniqueShapeContext1960
57  *
58  * \author Alessandro Franchi, Federico Tombari, Samuele Salti (original code)
59  * \author Nizar Sallem (port to PCL)
60  * \ingroup features
61  */
62  template <typename PointInT, typename PointOutT = pcl::UniqueShapeContext1960, typename PointRFT = pcl::ReferenceFrame>
63  class UniqueShapeContext : public Feature<PointInT, PointOutT>,
64  public FeatureWithLocalReferenceFrames<PointInT, PointRFT>
65  {
66  public:
77 
80  using Ptr = shared_ptr<UniqueShapeContext<PointInT, PointOutT, PointRFT> >;
81  using ConstPtr = shared_ptr<const UniqueShapeContext<PointInT, PointOutT, PointRFT> >;
82 
83 
84  /** \brief Constructor. */
87  {
88  feature_name_ = "UniqueShapeContext";
89  search_radius_ = 2.0;
90  }
91 
92  ~UniqueShapeContext() override = default;
93 
94  /** \return The number of bins along the azimuth. */
95  inline std::size_t
96  getAzimuthBins () const { return (azimuth_bins_); }
97 
98  /** \return The number of bins along the elevation */
99  inline std::size_t
100  getElevationBins () const { return (elevation_bins_); }
101 
102  /** \return The number of bins along the radii direction. */
103  inline std::size_t
104  getRadiusBins () const { return (radius_bins_); }
105 
106  /** The minimal radius value for the search sphere (rmin) in the original paper
107  * \param[in] radius the desired minimal radius
108  */
109  inline void
110  setMinimalRadius (double radius) { min_radius_ = radius; }
111 
112  /** \return The minimal sphere radius. */
113  inline double
114  getMinimalRadius () const { return (min_radius_); }
115 
116  /** This radius is used to compute local point density
117  * density = number of points within this radius
118  * \param[in] radius Value of the point density search radius
119  */
120  inline void
121  setPointDensityRadius (double radius) { point_density_radius_ = radius; }
122 
123  /** \return The point density search radius. */
124  inline double
126 
127  /** Set the local RF radius value
128  * \param[in] radius the desired local RF radius
129  */
130  inline void
131  setLocalRadius (double radius) { local_radius_ = radius; }
132 
133  /** \return The local RF radius. */
134  inline double
135  getLocalRadius () const { return (local_radius_); }
136 
137  protected:
138  /** Compute 3D shape context feature descriptor
139  * \param[in] index point index in input_
140  * \param[out] desc descriptor to compute
141  */
142  void
143  computePointDescriptor (std::size_t index, std::vector<float> &desc);
144 
145  /** \brief Initialize computation by allocating all the intervals and the volume lookup table. */
146  bool
147  initCompute () override;
148 
149  /** \brief The actual feature computation.
150  * \param[out] output the resultant features
151  */
152  void
153  computeFeature (PointCloudOut &output) override;
154 
155  /** \brief values of the radii interval. */
156  std::vector<float> radii_interval_;
157 
158  /** \brief Theta divisions interval. */
159  std::vector<float> theta_divisions_;
160 
161  /** \brief Phi divisions interval. */
162  std::vector<float> phi_divisions_;
163 
164  /** \brief Volumes look up table. */
165  std::vector<float> volume_lut_;
166 
167  /** \brief Bins along the azimuth dimension. */
168  std::size_t azimuth_bins_{14};
169 
170  /** \brief Bins along the elevation dimension. */
171  std::size_t elevation_bins_{14};
172 
173  /** \brief Bins along the radius dimension. */
174  std::size_t radius_bins_{10};
175 
176  /** \brief Minimal radius value. */
177  double min_radius_{0.1};
178 
179  /** \brief Point density radius. */
181 
182  /** \brief Descriptor length. */
183  std::size_t descriptor_length_{};
184 
185  /** \brief Radius to compute local RF. */
186  double local_radius_{2.0};
187  };
188 }
189 
190 #ifdef PCL_NO_PRECOMPILE
191 #include <pcl/features/impl/usc.hpp>
192 #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
FeatureWithLocalReferenceFrames provides a public interface for descriptor extractor classes which ne...
Definition: feature.h:440
UniqueShapeContext implements the Unique Shape Context Descriptor described here:
Definition: usc.h:65
void setPointDensityRadius(double radius)
This radius is used to compute local point density density = number of points within this radius.
Definition: usc.h:121
UniqueShapeContext()
Constructor.
Definition: usc.h:85
std::size_t getAzimuthBins() const
Definition: usc.h:96
shared_ptr< const UniqueShapeContext< PointInT, PointOutT, PointRFT > > ConstPtr
Definition: usc.h:81
std::size_t getRadiusBins() const
Definition: usc.h:104
std::size_t descriptor_length_
Descriptor length.
Definition: usc.h:183
std::size_t azimuth_bins_
Bins along the azimuth dimension.
Definition: usc.h:168
std::size_t elevation_bins_
Bins along the elevation dimension.
Definition: usc.h:171
double getPointDensityRadius() const
Definition: usc.h:125
void setMinimalRadius(double radius)
The minimal radius value for the search sphere (rmin) in the original paper.
Definition: usc.h:110
shared_ptr< UniqueShapeContext< PointInT, PointOutT, PointRFT > > Ptr
Definition: usc.h:80
double point_density_radius_
Point density radius.
Definition: usc.h:180
std::vector< float > theta_divisions_
Theta divisions interval.
Definition: usc.h:159
void computeFeature(PointCloudOut &output) override
The actual feature computation.
Definition: usc.hpp:226
std::vector< float > phi_divisions_
Phi divisions interval.
Definition: usc.h:162
double getMinimalRadius() const
Definition: usc.h:114
double getLocalRadius() const
Definition: usc.h:135
double local_radius_
Radius to compute local RF.
Definition: usc.h:186
typename Feature< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: usc.h:79
bool initCompute() override
Initialize computation by allocating all the intervals and the volume lookup table.
Definition: usc.hpp:54
void computePointDescriptor(std::size_t index, std::vector< float > &desc)
Compute 3D shape context feature descriptor.
Definition: usc.hpp:146
typename Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: usc.h:78
std::vector< float > volume_lut_
Volumes look up table.
Definition: usc.h:165
std::vector< float > radii_interval_
values of the radii interval.
Definition: usc.h:156
std::size_t getElevationBins() const
Definition: usc.h:100
double min_radius_
Minimal radius value.
Definition: usc.h:177
std::size_t radius_bins_
Bins along the radius dimension.
Definition: usc.h:174
~UniqueShapeContext() override=default
void setLocalRadius(double radius)
Set the local RF radius value.
Definition: usc.h:131
Defines all the PCL implemented PointT point type structures.