3dsc.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, Willow Garage, Inc.
* Copyright (c) 2012-, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*
*/
#ifndef PCL_FEATURES_3DSC_H_
#define PCL_FEATURES_3DSC_H_
#include <pcl/point_types.h>
#include <pcl/features/boost.h>
#include <pcl/features/feature.h>
namespace pcl
{
/** \brief ShapeContext3DEstimation implements the 3D shape context descriptor as
* described in:
* - Andrea Frome, Daniel Huber, Ravi Kolluri and Thomas Bülow, Jitendra Malik
* Recognizing Objects in Range Data Using Regional Point Descriptors,
* In proceedings of the 8th European Conference on Computer Vision (ECCV),
* Prague, May 11-14, 2004
*
* The suggested PointOutT is pcl::ShapeContext1980
*
* \attention
* The convention for a 3D shape context descriptor is:
* - 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
* - it is impossible to estimate a 3D shape context descriptor for a
* point that doesn't have finite 3D coordinates. Therefore, any point
* that contains NaN data on x, y, or z, will have its boundary feature
* property set to NaN.
*
* \author Alessandro Franchi, Samuele Salti, Federico Tombari (original code)
* \author Nizar Sallem (port to PCL)
* \ingroup features
*/
template <typename PointInT, typename PointNT, typename PointOutT = pcl::ShapeContext1980>
class ShapeContext3DEstimation : public FeatureFromNormals<PointInT, PointNT, PointOutT>
{
public:
typedef boost::shared_ptr<ShapeContext3DEstimation<PointInT, PointNT, PointOutT> > Ptr;
typedef boost::shared_ptr<const ShapeContext3DEstimation<PointInT, PointNT, PointOutT> > ConstPtr;
using Feature<PointInT, PointOutT>::feature_name_;
using Feature<PointInT, PointOutT>::getClassName;
using Feature<PointInT, PointOutT>::indices_;
using Feature<PointInT, PointOutT>::search_parameter_;
using Feature<PointInT, PointOutT>::search_radius_;
using Feature<PointInT, PointOutT>::surface_;
using Feature<PointInT, PointOutT>::input_;
using Feature<PointInT, PointOutT>::searchForNeighbors;
using FeatureFromNormals<PointInT, PointNT, PointOutT>::normals_;
typedef typename Feature<PointInT, PointOutT>::PointCloudOut PointCloudOut;
typedef typename Feature<PointInT, PointOutT>::PointCloudIn PointCloudIn;
/** \brief Constructor.
* \param[in] random If true the random seed is set to current time, else it is
* set to 12345 prior to computing the descriptor (used to select X axis)
*/
ShapeContext3DEstimation (bool random = false) :
radii_interval_(0),
theta_divisions_(0),
phi_divisions_(0),
volume_lut_(0),
azimuth_bins_(12),
elevation_bins_(11),
radius_bins_(15),
min_radius_(0.1),
point_density_radius_(0.2),
descriptor_length_ (),
rng_alg_ (),
rng_ (new boost::uniform_01<boost::mt19937> (rng_alg_))
{
feature_name_ = "ShapeContext3DEstimation";
search_radius_ = 2.5;
// Create a random number generator object
if (random)
rng_->base ().seed (static_cast<unsigned> (std::time(0)));
else
rng_->base ().seed (12345u);
}
virtual ~ShapeContext3DEstimation() {}
//inline void
//setAzimuthBins (size_t bins) { azimuth_bins_ = bins; }
/** \return the number of bins along the azimuth */
inline size_t
getAzimuthBins () { return (azimuth_bins_); }
//inline void
//setElevationBins (size_t bins) { elevation_bins_ = bins; }
/** \return The number of bins along the elevation */
inline size_t
getElevationBins () { return (elevation_bins_); }
//inline void
//setRadiusBins (size_t bins) { radius_bins_ = bins; }
/** \return The number of bins along the radii direction */
inline size_t
getRadiusBins () { return (radius_bins_); }
/** \brief The minimal radius value for the search sphere (rmin) in the original paper
* \param[in] radius the desired minimal radius
*/
inline void
setMinimalRadius (double radius) { min_radius_ = radius; }
/** \return The minimal sphere radius */
inline double
getMinimalRadius () { return (min_radius_); }
/** \brief This radius is used to compute local point density
* density = number of points within this radius
* \param[in] radius value of the point density search radius
*/
inline void
setPointDensityRadius (double radius) { point_density_radius_ = radius; }
/** \return The point density search radius */
inline double
getPointDensityRadius () { return (point_density_radius_); }
protected:
/** \brief Initialize computation by allocating all the intervals and the volume lookup table. */
bool
initCompute ();
/** \brief Estimate a descriptor for a given point.
* \param[in] index the index of the point to estimate a descriptor for
* \param[in] normals a pointer to the set of normals
* \param[in] rf the reference frame
* \param[out] desc the resultant estimated descriptor
* \return true if the descriptor was computed successfully, false if there was an error
* (e.g. the nearest neighbor didn't return any neighbors)
*/
bool
computePoint (size_t index, const pcl::PointCloud<PointNT> &normals, float rf[9], std::vector<float> &desc);
/** \brief Estimate the actual feature.
* \param[out] output the resultant feature
*/
void
computeFeature (PointCloudOut &output);
/** \brief Values of the radii interval */
std::vector<float> radii_interval_;
/** \brief Theta divisions interval */
std::vector<float> theta_divisions_;
/** \brief Phi divisions interval */
std::vector<float> phi_divisions_;
/** \brief Volumes look up table */
std::vector<float> volume_lut_;
/** \brief Bins along the azimuth dimension */
size_t azimuth_bins_;
/** \brief Bins along the elevation dimension */
size_t elevation_bins_;
/** \brief Bins along the radius dimension */
size_t radius_bins_;
/** \brief Minimal radius value */
double min_radius_;
/** \brief Point density radius */
double point_density_radius_;
/** \brief Descriptor length */
size_t descriptor_length_;
/** \brief Boost-based random number generator algorithm. */
boost::mt19937 rng_alg_;
/** \brief Boost-based random number generator distribution. */
boost::shared_ptr<boost::uniform_01<boost::mt19937> > rng_;
/* \brief Shift computed descriptor "L" times along the azimuthal direction
* \param[in] block_size the size of each azimuthal block
* \param[in] desc at input desc == original descriptor and on output it contains
* shifted descriptor resized descriptor_length_ * azimuth_bins_
*/
//void
//shiftAlongAzimuth (size_t block_size, std::vector<float>& desc);
/** \brief Boost-based random number generator. */
inline double
rnd ()
{
return ((*rng_) ());
}
};
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/features/impl/3dsc.hpp>
#endif
#endif //#ifndef PCL_3DSC_H_
pcl::ShapeContext3DEstimation::radii_interval_
std::vector< float > radii_interval_
Values of the radii interval.
Definition: 3dsc.h:186
pcl::ShapeContext3DEstimation::initCompute
bool initCompute()
Initialize computation by allocating all the intervals and the volume lookup table.
Definition: 3dsc.hpp:50
pcl::ShapeContext3DEstimation::PointCloudOut
Feature< PointInT, PointOutT >::PointCloudOut PointCloudOut
Definition: 3dsc.h:88
pcl::ShapeContext3DEstimation::radius_bins_
size_t radius_bins_
Bins along the radius dimension.
Definition: 3dsc.h:204
boost
Definition: boost_graph.h:47
pcl::ShapeContext3DEstimation::ConstPtr
boost::shared_ptr< const ShapeContext3DEstimation< PointInT, PointNT, PointOutT > > ConstPtr
Definition: 3dsc.h:76
pcl::ShapeContext3DEstimation::phi_divisions_
std::vector< float > phi_divisions_
Phi divisions interval.
Definition: 3dsc.h:192
pcl::ShapeContext3DEstimation::elevation_bins_
size_t elevation_bins_
Bins along the elevation dimension.
Definition: 3dsc.h:201
pcl::Feature::feature_name_
std::string feature_name_
The feature name.
Definition: feature.h:222
pcl::ShapeContext3DEstimation::setPointDensityRadius
void setPointDensityRadius(double radius)
This radius is used to compute local point density density = number of points within this radius...
Definition: 3dsc.h:157
pcl
Definition: convolution.h:45
pcl::ShapeContext3DEstimation::theta_divisions_
std::vector< float > theta_divisions_
Theta divisions interval.
Definition: 3dsc.h:189
pcl::ShapeContext3DEstimation::getElevationBins
size_t getElevationBins()
Definition: 3dsc.h:133
pcl::ShapeContext3DEstimation::setMinimalRadius
void setMinimalRadius(double radius)
The minimal radius value for the search sphere (rmin) in the original paper.
Definition: 3dsc.h:146
pcl::ShapeContext3DEstimation
ShapeContext3DEstimation implements the 3D shape context descriptor as described in: ...
Definition: 3dsc.h:72
pcl::ShapeContext3DEstimation::point_density_radius_
double point_density_radius_
Point density radius.
Definition: 3dsc.h:210
pcl::ShapeContext3DEstimation::getAzimuthBins
size_t getAzimuthBins()
Definition: 3dsc.h:126
pcl::ShapeContext3DEstimation::min_radius_
double min_radius_
Minimal radius value.
Definition: 3dsc.h:207
pcl::FeatureFromNormals
Definition: feature.h:310
pcl::ShapeContext3DEstimation::computeFeature
void computeFeature(PointCloudOut &output)
Estimate the actual feature.
Definition: 3dsc.hpp:279
pcl::ShapeContext3DEstimation::computePoint
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
pcl::ShapeContext3DEstimation::ShapeContext3DEstimation
ShapeContext3DEstimation(bool random=false)
Constructor.
Definition: 3dsc.h:95
pcl::ShapeContext3DEstimation::PointCloudIn
Feature< PointInT, PointOutT >::PointCloudIn PointCloudIn
Definition: 3dsc.h:89
point_types.h
Defines all the PCL implemented PointT point type structures.
pcl::ShapeContext3DEstimation::~ShapeContext3DEstimation
virtual ~ShapeContext3DEstimation()
Definition: 3dsc.h:119
pcl::ShapeContext3DEstimation::rng_
boost::shared_ptr< boost::uniform_01< boost::mt19937 > > rng_
Boost-based random number generator distribution.
Definition: 3dsc.h:219
pcl::ShapeContext3DEstimation::azimuth_bins_
size_t azimuth_bins_
Bins along the azimuth dimension.
Definition: 3dsc.h:198
pcl::ShapeContext3DEstimation::volume_lut_
std::vector< float > volume_lut_
Volumes look up table.
Definition: 3dsc.h:195
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: projection_matrix.h:53
pcl::ShapeContext3DEstimation::descriptor_length_
size_t descriptor_length_
Descriptor length.
Definition: 3dsc.h:213
pcl::ShapeContext3DEstimation::getRadiusBins
size_t getRadiusBins()
Definition: 3dsc.h:140
pcl::ShapeContext3DEstimation::Ptr
boost::shared_ptr< ShapeContext3DEstimation< PointInT, PointNT, PointOutT > > Ptr
Definition: 3dsc.h:75
pcl::ShapeContext3DEstimation::rnd
double rnd()
Boost-based random number generator.
Definition: 3dsc.h:231
pcl::Feature
Feature represents the base feature class.
Definition: feature.h:105
pcl::ShapeContext3DEstimation::getPointDensityRadius
double getPointDensityRadius()
Definition: 3dsc.h:161
pcl::ShapeContext3DEstimation::rng_alg_
boost::mt19937 rng_alg_
Boost-based random number generator algorithm.
Definition: 3dsc.h:216
pcl::Feature::search_radius_
double search_radius_
The nearest neighbors search radius for each point.
Definition: feature.h:239
pcl::ShapeContext3DEstimation::getMinimalRadius
double getMinimalRadius()
Definition: 3dsc.h:150