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$
*
*/
#pragma once
#include <pcl/registration/correspondence_rejection.h>
#include <pcl/memory.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 {
using PointCloud = pcl::PointCloud<PointT>;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
public:
using CorrespondenceRejector::getClassName;
using CorrespondenceRejector::input_correspondences_;
using CorrespondenceRejector::rejection_name_;
using Ptr = shared_ptr<CorrespondenceRejectorSampleConsensus<PointT>>;
using ConstPtr = shared_ptr<const CorrespondenceRejectorSampleConsensus<PointT>>;
/** \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_()
, refine_(false)
, save_inliers_(false)
{
rejection_name_ = "CorrespondenceRejectorSampleConsensus";
}
/** \brief Empty destructor. */
~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) override;
/** \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
*/
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 override
{
return (true);
}
/** \brief Blob method for setting the source cloud */
void
setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
{
PointCloudPtr cloud(new PointCloud);
fromPCLPointCloud2(*cloud2, *cloud);
setInputSource(cloud);
}
/** \brief See if this rejector requires a target cloud */
bool
requiresTargetPoints() const override
{
return (true);
}
/** \brief Method for setting the target cloud */
void
setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
{
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
*/
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
*/
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(pcl::Indices& 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) override
{
getRemainingCorrespondences(*input_correspondences_, correspondences);
}
double inlier_threshold_;
int max_iterations_;
PointCloudConstPtr input_;
PointCloudPtr input_transformed_;
PointCloudConstPtr target_;
Eigen::Matrix4f best_transformation_;
bool refine_;
pcl::Indices inlier_indices_;
bool save_inliers_;
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
} // namespace registration
} // namespace pcl
#include <pcl/registration/impl/correspondence_rejection_sample_consensus.hpp>
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
pcl::registration::CorrespondenceRejector
CorrespondenceRejector represents the base class for correspondence rejection methods
Definition: correspondence_rejection.h:54
pcl::registration::CorrespondenceRejector::ConstPtr
shared_ptr< const CorrespondenceRejector > ConstPtr
Definition: correspondence_rejection.h:57
pcl::registration::CorrespondenceRejector::input_correspondences_
CorrespondencesConstPtr input_correspondences_
The input correspondences.
Definition: correspondence_rejection.h:200
pcl::registration::CorrespondenceRejector::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: correspondence_rejection.h:131
pcl::registration::CorrespondenceRejector::Ptr
shared_ptr< CorrespondenceRejector > Ptr
Definition: correspondence_rejection.h:56
pcl::registration::CorrespondenceRejector::rejection_name_
std::string rejection_name_
The name of the rejection method.
Definition: correspondence_rejection.h:197
pcl::registration::CorrespondenceRejectorSampleConsensus
CorrespondenceRejectorSampleConsensus implements a correspondence rejection using Random Sample Conse...
Definition: correspondence_rejection_sample_consensus.h:54
pcl::registration::CorrespondenceRejectorSampleConsensus::requiresSourcePoints
bool requiresSourcePoints() const override
See if this rejector requires source points.
Definition: correspondence_rejection_sample_consensus.h:128
pcl::registration::CorrespondenceRejectorSampleConsensus::getInlierThreshold
double getInlierThreshold()
Get the maximum distance between corresponding points.
Definition: correspondence_rejection_sample_consensus.h:173
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:98
pcl::registration::CorrespondenceRejectorSampleConsensus::max_iterations_
int max_iterations_
Definition: correspondence_rejection_sample_consensus.h:261
pcl::registration::CorrespondenceRejectorSampleConsensus::getBestTransformation
Eigen::Matrix4f getBestTransformation()
Get the best transformation after RANSAC rejection.
Definition: correspondence_rejection_sample_consensus.h:200
pcl::registration::CorrespondenceRejectorSampleConsensus::refine_
bool refine_
Definition: correspondence_rejection_sample_consensus.h:269
pcl::registration::CorrespondenceRejectorSampleConsensus::best_transformation_
Eigen::Matrix4f best_transformation_
Definition: correspondence_rejection_sample_consensus.h:267
pcl::registration::CorrespondenceRejectorSampleConsensus::getSaveInliers
bool getSaveInliers()
Get whether the rejector is configured to save inliers.
Definition: correspondence_rejection_sample_consensus.h:244
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:114
pcl::registration::CorrespondenceRejectorSampleConsensus::setInlierThreshold
void setInlierThreshold(double threshold)
Set the maximum distance between corresponding points.
Definition: correspondence_rejection_sample_consensus.h:164
pcl::registration::CorrespondenceRejectorSampleConsensus::inlier_indices_
pcl::Indices inlier_indices_
Definition: correspondence_rejection_sample_consensus.h:270
pcl::registration::CorrespondenceRejectorSampleConsensus::setMaximumIterations
void setMaximumIterations(int max_iterations)
Set the maximum number of iterations.
Definition: correspondence_rejection_sample_consensus.h:182
pcl::registration::CorrespondenceRejectorSampleConsensus::save_inliers_
bool save_inliers_
Definition: correspondence_rejection_sample_consensus.h:271
pcl::registration::CorrespondenceRejectorSampleConsensus::getRemainingCorrespondences
void getRemainingCorrespondences(const pcl::Correspondences &original_correspondences, pcl::Correspondences &remaining_correspondences) override
Get a list of valid correspondences after rejection from the original set of correspondences.
Definition: correspondence_rejection_sample_consensus.hpp:55
pcl::registration::CorrespondenceRejectorSampleConsensus::setTargetPoints
void setTargetPoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Method for setting the target cloud.
Definition: correspondence_rejection_sample_consensus.h:151
pcl::registration::CorrespondenceRejectorSampleConsensus::input_correspondences_
CorrespondencesConstPtr input_correspondences_
The input correspondences.
Definition: correspondence_rejection.h:200
pcl::registration::CorrespondenceRejectorSampleConsensus::setSaveInliers
void setSaveInliers(bool s)
Set whether to save inliers or not.
Definition: correspondence_rejection_sample_consensus.h:237
pcl::registration::CorrespondenceRejectorSampleConsensus::requiresTargetPoints
bool requiresTargetPoints() const override
See if this rejector requires a target cloud.
Definition: correspondence_rejection_sample_consensus.h:144
pcl::registration::CorrespondenceRejectorSampleConsensus::inlier_threshold_
double inlier_threshold_
Definition: correspondence_rejection_sample_consensus.h:259
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:218
pcl::registration::CorrespondenceRejectorSampleConsensus::getMaximumIterations
int getMaximumIterations()
Get the maximum number of iterations.
Definition: correspondence_rejection_sample_consensus.h:191
pcl::registration::CorrespondenceRejectorSampleConsensus::input_transformed_
PointCloudPtr input_transformed_
Definition: correspondence_rejection_sample_consensus.h:264
pcl::registration::CorrespondenceRejectorSampleConsensus::CorrespondenceRejectorSampleConsensus
CorrespondenceRejectorSampleConsensus()
Empty constructor.
Definition: correspondence_rejection_sample_consensus.h:70
pcl::registration::CorrespondenceRejectorSampleConsensus::getInputSource
PointCloudConstPtr const getInputSource()
Get a pointer to the input point cloud dataset target.
Definition: correspondence_rejection_sample_consensus.h:105
pcl::registration::CorrespondenceRejectorSampleConsensus::rejection_name_
std::string rejection_name_
The name of the rejection method.
Definition: correspondence_rejection.h:197
pcl::registration::CorrespondenceRejectorSampleConsensus::getInputTarget
PointCloudConstPtr const getInputTarget()
Get a pointer to the input point cloud dataset target.
Definition: correspondence_rejection_sample_consensus.h:121
pcl::registration::CorrespondenceRejectorSampleConsensus::input_
PointCloudConstPtr input_
Definition: correspondence_rejection_sample_consensus.h:263
pcl::registration::CorrespondenceRejectorSampleConsensus::applyRejection
void applyRejection(pcl::Correspondences &correspondences) override
Apply the rejection algorithm.
Definition: correspondence_rejection_sample_consensus.h:254
pcl::registration::CorrespondenceRejectorSampleConsensus::getInliersIndices
void getInliersIndices(pcl::Indices &inlier_indices)
Get the inlier indices found by the correspondence rejector.
Definition: correspondence_rejection_sample_consensus.h:228
pcl::registration::CorrespondenceRejectorSampleConsensus::setSourcePoints
void setSourcePoints(pcl::PCLPointCloud2::ConstPtr cloud2) override
Blob method for setting the source cloud.
Definition: correspondence_rejection_sample_consensus.h:135
pcl::registration::CorrespondenceRejectorSampleConsensus::target_
PointCloudConstPtr target_
Definition: correspondence_rejection_sample_consensus.h:265
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:210
pcl::registration::CorrespondenceRejectorSampleConsensus::~CorrespondenceRejectorSampleConsensus
~CorrespondenceRejectorSampleConsensus()
Empty destructor.
Definition: correspondence_rejection_sample_consensus.h:83
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl
Definition: convolution.h:46
pcl::Correspondences
std::vector< pcl::Correspondence, Eigen::aligned_allocator< pcl::Correspondence > > Correspondences
Definition: correspondence.h:89
pcl::Indices
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
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:166
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:36