correspondence_rejection_sample_consensus.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_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_
#define PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_
#include <pcl/registration/correspondence_rejection.h>
#include <pcl/sample_consensus/ransac.h>
#include <pcl/sample_consensus/sac_model_registration.h>
#include <pcl/common/transforms.h>
namespace pcl
{
namespace registration
{
/** \brief CorrespondenceRejectorSampleConsensus implements a correspondence rejection
* using Random Sample Consensus to identify inliers (and reject outliers)
* \author Dirk Holz
* \ingroup registration
*/
template <typename PointT>
class CorrespondenceRejectorSampleConsensus: public CorrespondenceRejector
{
typedef pcl::PointCloud<PointT> PointCloud;
typedef typename PointCloud::Ptr PointCloudPtr;
typedef typename PointCloud::ConstPtr PointCloudConstPtr;
public:
using CorrespondenceRejector::input_correspondences_;
using CorrespondenceRejector::rejection_name_;
using CorrespondenceRejector::getClassName;
typedef boost::shared_ptr<CorrespondenceRejectorSampleConsensus> Ptr;
typedef boost::shared_ptr<const CorrespondenceRejectorSampleConsensus> ConstPtr;
/** \brief Empty constructor. Sets the inlier threshold to 5cm (0.05m),
* and the maximum number of iterations to 1000.
*/
CorrespondenceRejectorSampleConsensus ()
: inlier_threshold_ (0.05)
, max_iterations_ (1000) // std::numeric_limits<int>::max ()
, input_ ()
, input_transformed_ ()
, target_ ()
, best_transformation_ ()
, refine_ (false)
, save_inliers_ (false)
{
rejection_name_ = "CorrespondenceRejectorSampleConsensus";
}
/** \brief Empty destructor. */
virtual ~CorrespondenceRejectorSampleConsensus () {}
/** \brief Get a list of valid correspondences after rejection from the original set of correspondences.
* \param[in] original_correspondences the set of initial correspondences given
* \param[out] remaining_correspondences the resultant filtered set of remaining correspondences
*/
inline void
getRemainingCorrespondences (const pcl::Correspondences& original_correspondences,
pcl::Correspondences& remaining_correspondences);
/** \brief Provide a source point cloud dataset (must contain XYZ data!)
* \param[in] cloud a cloud containing XYZ data
*/
PCL_DEPRECATED ("[pcl::registration::CorrespondenceRejectorSampleConsensus::setInputCloud] setInputCloud is deprecated. Please use setInputSource instead.")
virtual void
setInputCloud (const PointCloudConstPtr &cloud);
/** \brief Get a pointer to the input point cloud dataset target. */
PCL_DEPRECATED ("[pcl::registration::CorrespondenceRejectorSampleConsensus::getInputCloud] getInputCloud is deprecated. Please use getInputSource instead.")
PointCloudConstPtr const
getInputCloud ();
/** \brief Provide a source point cloud dataset (must contain XYZ data!)
* \param[in] cloud a cloud containing XYZ data
*/
virtual inline void
setInputSource (const PointCloudConstPtr &cloud)
{
input_ = cloud;
}
/** \brief Get a pointer to the input point cloud dataset target. */
inline PointCloudConstPtr const
getInputSource () { return (input_); }
/** \brief Provide a target point cloud dataset (must contain XYZ data!)
* \param[in] cloud a cloud containing XYZ data
*/
PCL_DEPRECATED ("[pcl::registration::CorrespondenceRejectorSampleConsensus::setTargetCloud] setTargetCloud is deprecated. Please use setInputTarget instead.")
virtual void
setTargetCloud (const PointCloudConstPtr &cloud);
/** \brief Provide a target point cloud dataset (must contain XYZ data!)
* \param[in] cloud a cloud containing XYZ data
*/
virtual inline void
setInputTarget (const PointCloudConstPtr &cloud) { target_ = cloud; }
/** \brief Get a pointer to the input point cloud dataset target. */
inline PointCloudConstPtr const
getInputTarget () { return (target_ ); }
/** \brief See if this rejector requires source points */
bool
requiresSourcePoints () const
{ return (true); }
/** \brief Blob method for setting the source cloud */
void
setSourcePoints (pcl::PCLPointCloud2::ConstPtr cloud2)
{
PointCloudPtr cloud (new PointCloud);
fromPCLPointCloud2 (*cloud2, *cloud);
setInputSource (cloud);
}
/** \brief See if this rejector requires a target cloud */
bool
requiresTargetPoints () const
{ return (true); }
/** \brief Method for setting the target cloud */
void
setTargetPoints (pcl::PCLPointCloud2::ConstPtr cloud2)
{
PointCloudPtr cloud (new PointCloud);
fromPCLPointCloud2 (*cloud2, *cloud);
setInputTarget (cloud);
}
/** \brief Set the maximum distance between corresponding points.
* Correspondences with distances below the threshold are considered as inliers.
* \param[in] threshold Distance threshold in the same dimension as source and target data sets.
*/
inline void
setInlierThreshold (double threshold) { inlier_threshold_ = threshold; };
/** \brief Get the maximum distance between corresponding points.
* \return Distance threshold in the same dimension as source and target data sets.
*/
inline double
getInlierThreshold () { return inlier_threshold_; };
/** \brief Set the maximum number of iterations.
* \param[in] max_iterations Maximum number if iterations to run
*/
PCL_DEPRECATED ("[pcl::registration::CorrespondenceRejectorSampleConsensus::setMaxIterations] setMaxIterations is deprecated. Please use setMaximumIterations instead.")
void
setMaxIterations (int max_iterations);
/** \brief Set the maximum number of iterations.
* \param[in] max_iterations Maximum number if iterations to run
*/
inline void
setMaximumIterations (int max_iterations) { max_iterations_ = std::max (max_iterations, 0); }
/** \brief Get the maximum number of iterations.
* \return max_iterations Maximum number if iterations to run
*/
PCL_DEPRECATED ("[pcl::registration::CorrespondenceRejectorSampleConsensus::getMaxIterations] getMaxIterations is deprecated. Please use getMaximumIterations instead.")
int
getMaxIterations ();
/** \brief Get the maximum number of iterations.
* \return max_iterations Maximum number if iterations to run
*/
inline int
getMaximumIterations () { return (max_iterations_); }
/** \brief Get the best transformation after RANSAC rejection.
* \return The homogeneous 4x4 transformation yielding the largest number of inliers.
*/
inline Eigen::Matrix4f
getBestTransformation () { return best_transformation_; };
/** \brief Specify whether the model should be refined internally using the variance of the inliers
* \param[in] refine true if the model should be refined, false otherwise
*/
inline void
setRefineModel (const bool refine)
{
refine_ = refine;
}
/** \brief Get the internal refine parameter value as set by the user using setRefineModel */
inline bool
getRefineModel () const
{
return (refine_);
}
/** \brief Get the inlier indices found by the correspondence rejector. This information is only saved if setSaveInliers(true) was called in advance.
* \param[out] inlier_indices Indices for the inliers
*/
inline void
getInliersIndices (std::vector<int> &inlier_indices) { inlier_indices = inlier_indices_; }
/** \brief Set whether to save inliers or not
* \param[in] s True to save inliers / False otherwise
*/
inline void
setSaveInliers (bool s) { save_inliers_ = s; }
/** \brief Get whether the rejector is configured to save inliers */
inline bool
getSaveInliers () { return save_inliers_; }
protected:
/** \brief Apply the rejection algorithm.
* \param[out] correspondences the set of resultant correspondences.
*/
inline void
applyRejection (pcl::Correspondences &correspondences)
{
getRemainingCorrespondences (*input_correspondences_, correspondences);
}
double inlier_threshold_;
int max_iterations_;
PointCloudConstPtr input_;
PointCloudPtr input_transformed_;
PointCloudConstPtr target_;
Eigen::Matrix4f best_transformation_;
bool refine_;
std::vector<int> inlier_indices_;
bool save_inliers_;
public:
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
};
}
}
#include <pcl/registration/impl/correspondence_rejection_sample_consensus.hpp>
#endif // PCL_REGISTRATION_CORRESPONDENCE_REJECTION_SAMPLE_CONSENSUS_H_
pcl::fromPCLPointCloud2
void fromPCLPointCloud2(const pcl::PCLPointCloud2 &msg, pcl::PointCloud< PointT > &cloud, const MsgFieldMap &field_map)
Convert a PCLPointCloud2 binary data blob into a pcl::PointCloud<T> object using a field_map...
Definition: conversions.h:169
pcl::registration::CorrespondenceRejectorSampleConsensus::getInlierThreshold
double getInlierThreshold()
Get the maximum distance between corresponding points.
Definition: correspondence_rejection_sample_consensus.h:182
pcl::registration::CorrespondenceRejectorSampleConsensus::requiresSourcePoints
bool requiresSourcePoints() const
See if this rejector requires source points.
Definition: correspondence_rejection_sample_consensus.h:145
pcl::registration::CorrespondenceRejectorSampleConsensus::setTargetCloud
virtual void setTargetCloud(const PointCloudConstPtr &cloud)
Provide a target point cloud dataset (must contain XYZ data!)
Definition: correspondence_rejection_sample_consensus.hpp:62
pcl::registration::CorrespondenceRejectorSampleConsensus::input_transformed_
PointCloudPtr input_transformed_
Definition: correspondence_rejection_sample_consensus.h:265
pcl
Definition: cloud_iterator.h:46
pcl::registration::CorrespondenceRejector
CorrespondenceRejector represents the base class for correspondence rejection methods ...
Definition: correspondence_rejection.h:59
pcl::registration::CorrespondenceRejectorSampleConsensus::~CorrespondenceRejectorSampleConsensus
virtual ~CorrespondenceRejectorSampleConsensus()
Empty destructor.
Definition: correspondence_rejection_sample_consensus.h:90
pcl::registration::CorrespondenceRejectorSampleConsensus::getInliersIndices
void getInliersIndices(std::vector< int > &inlier_indices)
Get the inlier indices found by the correspondence rejector.
Definition: correspondence_rejection_sample_consensus.h:236
pcl::registration::CorrespondenceRejectorSampleConsensus::getInputCloud
PointCloudConstPtr const getInputCloud()
Get a pointer to the input point cloud dataset target.
Definition: correspondence_rejection_sample_consensus.hpp:55
pcl::registration::CorrespondenceRejectorSampleConsensus::setMaxIterations
void setMaxIterations(int max_iterations)
Set the maximum number of iterations.
Definition: correspondence_rejection_sample_consensus.hpp:70
pcl::registration::CorrespondenceRejectorSampleConsensus::getMaxIterations
int getMaxIterations()
Get the maximum number of iterations.
Definition: correspondence_rejection_sample_consensus.hpp:78
pcl::registration::CorrespondenceRejectorSampleConsensus::refine_
bool refine_
Definition: correspondence_rejection_sample_consensus.h:270
pcl::registration::CorrespondenceRejectorSampleConsensus::setTargetPoints
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2)
Method for setting the target cloud.
Definition: correspondence_rejection_sample_consensus.h:164
pcl::registration::CorrespondenceRejectorSampleConsensus::CorrespondenceRejectorSampleConsensus
CorrespondenceRejectorSampleConsensus()
Empty constructor.
Definition: correspondence_rejection_sample_consensus.h:76
pcl::PointCloud::Ptr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::registration::CorrespondenceRejector::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: correspondence_rejection.h:135
pcl::registration::CorrespondenceRejectorSampleConsensus::Ptr
boost::shared_ptr< CorrespondenceRejectorSampleConsensus > Ptr
Definition: correspondence_rejection_sample_consensus.h:70
pcl::registration::CorrespondenceRejectorSampleConsensus::getBestTransformation
Eigen::Matrix4f getBestTransformation()
Get the best transformation after RANSAC rejection.
Definition: correspondence_rejection_sample_consensus.h:214
pcl::registration::CorrespondenceRejectorSampleConsensus::target_
PointCloudConstPtr target_
Definition: correspondence_rejection_sample_consensus.h:266
pcl::registration::CorrespondenceRejectorSampleConsensus::getMaximumIterations
int getMaximumIterations()
Get the maximum number of iterations.
Definition: correspondence_rejection_sample_consensus.h:208
pcl::registration::CorrespondenceRejectorSampleConsensus::setInputTarget
virtual void setInputTarget(const PointCloudConstPtr &cloud)
Provide a target point cloud dataset (must contain XYZ data!)
Definition: correspondence_rejection_sample_consensus.h:136
pcl::registration::CorrespondenceRejectorSampleConsensus::setMaximumIterations
void setMaximumIterations(int max_iterations)
Set the maximum number of iterations.
Definition: correspondence_rejection_sample_consensus.h:195
pcl::Correspondences
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Definition: correspondence.h:92
pcl::registration::CorrespondenceRejectorSampleConsensus::getInputSource
PointCloudConstPtr const getInputSource()
Get a pointer to the input point cloud dataset target.
Definition: correspondence_rejection_sample_consensus.h:123
pcl::PointCloud::ConstPtr
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::registration::CorrespondenceRejectorSampleConsensus::setInlierThreshold
void setInlierThreshold(double threshold)
Set the maximum distance between corresponding points.
Definition: correspondence_rejection_sample_consensus.h:176
pcl::PCLPointCloud2::ConstPtr
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
Definition: PCLPointCloud2.h:52
pcl::registration::CorrespondenceRejectorSampleConsensus::best_transformation_
Eigen::Matrix4f best_transformation_
Definition: correspondence_rejection_sample_consensus.h:268
pcl::registration::CorrespondenceRejectorSampleConsensus::setInputCloud
virtual void setInputCloud(const PointCloudConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!)
Definition: correspondence_rejection_sample_consensus.hpp:47
pcl::registration::CorrespondenceRejectorSampleConsensus::setSourcePoints
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2)
Blob method for setting the source cloud.
Definition: correspondence_rejection_sample_consensus.h:150
pcl::registration::CorrespondenceRejectorSampleConsensus::requiresTargetPoints
bool requiresTargetPoints() const
See if this rejector requires a target cloud.
Definition: correspondence_rejection_sample_consensus.h:159
pcl::registration::CorrespondenceRejectorSampleConsensus::input_
PointCloudConstPtr input_
Definition: correspondence_rejection_sample_consensus.h:264
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: projection_matrix.h:53
pcl::registration::CorrespondenceRejectorSampleConsensus
CorrespondenceRejectorSampleConsensus implements a correspondence rejection using Random Sample Conse...
Definition: correspondence_rejection_sample_consensus.h:59
pcl::registration::CorrespondenceRejectorSampleConsensus::getInputTarget
PointCloudConstPtr const getInputTarget()
Get a pointer to the input point cloud dataset target.
Definition: correspondence_rejection_sample_consensus.h:140
pcl::registration::CorrespondenceRejectorSampleConsensus::inlier_indices_
std::vector< int > inlier_indices_
Definition: correspondence_rejection_sample_consensus.h:271
pcl::registration::CorrespondenceRejectorSampleConsensus::applyRejection
void applyRejection(pcl::Correspondences &correspondences)
Apply the rejection algorithm.
Definition: correspondence_rejection_sample_consensus.h:255
pcl::registration::CorrespondenceRejectorSampleConsensus::max_iterations_
int max_iterations_
Definition: correspondence_rejection_sample_consensus.h:262
pcl::registration::CorrespondenceRejectorSampleConsensus::inlier_threshold_
double inlier_threshold_
Definition: correspondence_rejection_sample_consensus.h:260
pcl::registration::CorrespondenceRejector::input_correspondences_
CorrespondencesConstPtr input_correspondences_
The input correspondences.
Definition: correspondence_rejection.h:191
pcl::registration::CorrespondenceRejectorSampleConsensus::setInputSource
virtual void setInputSource(const PointCloudConstPtr &cloud)
Provide a source point cloud dataset (must contain XYZ data!)
Definition: correspondence_rejection_sample_consensus.h:116
pcl::registration::CorrespondenceRejectorSampleConsensus::setSaveInliers
void setSaveInliers(bool s)
Set whether to save inliers or not.
Definition: correspondence_rejection_sample_consensus.h:242
pcl::registration::CorrespondenceRejector::rejection_name_
std::string rejection_name_
The name of the rejection method.
Definition: correspondence_rejection.h:188
pcl::registration::CorrespondenceRejectorSampleConsensus::getSaveInliers
bool getSaveInliers()
Get whether the rejector is configured to save inliers.
Definition: correspondence_rejection_sample_consensus.h:246
pcl::registration::CorrespondenceRejectorSampleConsensus::save_inliers_
bool save_inliers_
Definition: correspondence_rejection_sample_consensus.h:272
pcl::registration::CorrespondenceRejectorSampleConsensus::ConstPtr
boost::shared_ptr< const CorrespondenceRejectorSampleConsensus > ConstPtr
Definition: correspondence_rejection_sample_consensus.h:71
pcl::registration::CorrespondenceRejectorSampleConsensus::getRemainingCorrespondences
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences)
Get a list of valid correspondences after rejection from the original set of correspondences.
Definition: correspondence_rejection_sample_consensus.hpp:85
pcl::registration::CorrespondenceRejectorSampleConsensus::getRefineModel
bool getRefineModel() const
Get the internal refine parameter value as set by the user using setRefineModel.
Definition: correspondence_rejection_sample_consensus.h:227
pcl::registration::CorrespondenceRejectorSampleConsensus::setRefineModel
void setRefineModel(const bool refine)
Specify whether the model should be refined internally using the variance of the inliers.
Definition: correspondence_rejection_sample_consensus.h:220