Loading...
Searching...
No Matches
transformation_validation_euclidean.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/kdtree/kdtree.h>
#include <pcl/registration/transformation_validation.h>
#include <pcl/search/kdtree.h>
#include <pcl/memory.h>
#include <pcl/pcl_macros.h>
#include <pcl/point_representation.h>
namespace pcl {
namespace registration {
/** \brief TransformationValidationEuclidean computes an L2SQR norm between a source and
* target dataset.
*
* To prevent points with bad correspondences to contribute to the overall score, the
* class also accepts a maximum_range parameter given via \ref setMaxRange that is used
* as a cutoff value for nearest neighbor distance comparisons.
*
* The output score is normalized with respect to the number of valid correspondences
* found.
*
* Usage example:
* \code
* pcl::TransformationValidationEuclidean<pcl::PointXYZ, pcl::PointXYZ> tve;
* tve.setMaxRange (0.01); // 1cm
* double score = tve.validateTransformation (source, target, transformation);
* \endcode
*
* \note The class is templated on the source and target point types as well as on the
* output scalar of the transformation matrix (i.e., float or double). Default: float.
* \author Radu B. Rusu
* \ingroup registration
*/
template <typename PointSource, typename PointTarget, typename Scalar = float>
class TransformationValidationEuclidean {
public:
using Matrix4 =
typename TransformationValidation<PointSource, PointTarget, Scalar>::Matrix4;
using Ptr = shared_ptr<TransformationValidation<PointSource, PointTarget, Scalar>>;
using ConstPtr =
shared_ptr<const TransformationValidation<PointSource, PointTarget, Scalar>>;
using KdTree = pcl::search::KdTree<PointTarget>;
using KdTreePtr = typename KdTree::Ptr;
using PointRepresentationConstPtr = typename KdTree::PointRepresentationConstPtr;
using PointCloudSourceConstPtr =
typename TransformationValidation<PointSource,
PointTarget>::PointCloudSourceConstPtr;
using PointCloudTargetConstPtr =
typename TransformationValidation<PointSource,
PointTarget>::PointCloudTargetConstPtr;
/** \brief Constructor.
* Sets the \a max_range parameter to double::max, \a threshold_ to NaN
* and initializes the internal search \a tree to a FLANN kd-tree.
*/
TransformationValidationEuclidean()
: max_range_(std::numeric_limits<double>::max())
, threshold_(std::numeric_limits<double>::quiet_NaN())
, tree_(new pcl::search::KdTree<PointTarget>)
{}
virtual ~TransformationValidationEuclidean() = default;
/** \brief Set the maximum allowable distance between a point and its correspondence
* in the target in order for a correspondence to be considered \a valid. Default:
* double::max. \param[in] max_range the new maximum allowable distance
*/
inline void
setMaxRange(double max_range)
{
max_range_ = max_range;
}
/** \brief Get the maximum allowable distance between a point and its
* correspondence, as set by the user.
*/
inline double
getMaxRange()
{
return (max_range_);
}
/** \brief Provide a pointer to the search object used to find correspondences in
* the target cloud.
* \param[in] tree a pointer to the spatial search object.
* \param[in] force_no_recompute If set to true, this tree will NEVER be
* recomputed, regardless of calls to setInputTarget. Only use if you are
* confident that the tree will be set correctly.
*/
inline void
setSearchMethodTarget(const KdTreePtr& tree, bool force_no_recompute = false)
{
tree_ = tree;
force_no_recompute_ = force_no_recompute;
}
/** \brief Set a threshold for which a specific transformation is considered valid.
*
* \note Since we're using MSE (Mean Squared Error) as a metric, the threshold
* represents the mean Euclidean distance threshold over all nearest neighbors
* up to max_range.
*
* \param[in] threshold the threshold for which a transformation is vali
*/
inline void
setThreshold(double threshold)
{
threshold_ = threshold;
}
/** \brief Get the threshold for which a specific transformation is valid. */
inline double
getThreshold()
{
return (threshold_);
}
/** \brief Validate the given transformation with respect to the input cloud data, and
* return a score.
*
* \param[in] cloud_src the source point cloud dataset
* \param[in] cloud_tgt the target point cloud dataset
* \param[out] transformation_matrix the resultant transformation matrix
*
* \return the score or confidence measure for the given
* transformation_matrix with respect to the input data
*/
double
validateTransformation(const PointCloudSourceConstPtr& cloud_src,
const PointCloudTargetConstPtr& cloud_tgt,
const Matrix4& transformation_matrix) const;
/** \brief Comparator function for deciding which score is better after running the
* validation on multiple transforms.
*
* \param[in] score1 the first value
* \param[in] score2 the second value
*
* \return true if score1 is better than score2
*/
virtual bool
operator()(const double& score1, const double& score2) const
{
return (score1 < score2);
}
/** \brief Check if the score is valid for a specific transformation.
*
* \param[in] cloud_src the source point cloud dataset
* \param[in] cloud_tgt the target point cloud dataset
* \param[out] transformation_matrix the transformation matrix
*
* \return true if the transformation is valid, false otherwise.
*/
virtual bool
isValid(const PointCloudSourceConstPtr& cloud_src,
const PointCloudTargetConstPtr& cloud_tgt,
const Matrix4& transformation_matrix) const
{
if (std::isnan(threshold_)) {
PCL_ERROR("[pcl::TransformationValidationEuclidean::isValid] Threshold not set! "
"Please use setThreshold () before continuing.\n");
return (false);
}
return (validateTransformation(cloud_src, cloud_tgt, transformation_matrix) <
threshold_);
}
protected:
/** \brief The maximum allowable distance between a point and its correspondence in
* the target in order for a correspondence to be considered \a valid. Default:
* double::max.
*/
double max_range_;
/** \brief The threshold for which a specific transformation is valid.
* Set to NaN by default, as we must require the user to set it.
*/
double threshold_;
/** \brief A pointer to the spatial search object. */
KdTreePtr tree_;
/** \brief A flag which, if set, means the tree operating on the target cloud
* will never be recomputed*/
bool force_no_recompute_{false};
/** \brief Internal point representation uses only 3D coordinates for L2 */
class MyPointRepresentation : public pcl::PointRepresentation<PointTarget> {
using pcl::PointRepresentation<PointTarget>::nr_dimensions_;
using pcl::PointRepresentation<PointTarget>::trivial_;
public:
using Ptr = shared_ptr<MyPointRepresentation>;
using ConstPtr = shared_ptr<const MyPointRepresentation>;
MyPointRepresentation()
{
nr_dimensions_ = 3;
trivial_ = true;
}
/** \brief Empty destructor */
virtual ~MyPointRepresentation() = default;
virtual void
copyToFloatArray(const PointTarget& p, float* out) const
{
out[0] = p.x;
out[1] = p.y;
out[2] = p.z;
}
};
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
} // namespace registration
} // namespace pcl
#include <pcl/registration/impl/transformation_validation_euclidean.hpp>
pcl::PointRepresentation
PointRepresentation provides a set of methods for converting a point structs/object into an n-dimensi...
Definition point_representation.h:60
pcl::PointRepresentation< PointTarget >::nr_dimensions_
int nr_dimensions_
The number of dimensions in this point's vector (i.e.
Definition point_representation.h:63
pcl::PointRepresentation< PointTarget >::trivial_
bool trivial_
Indicates whether this point representation is trivial.
Definition point_representation.h:75
pcl::registration::TransformationValidationEuclidean::MyPointRepresentation
Internal point representation uses only 3D coordinates for L2.
Definition transformation_validation_euclidean.h:234
pcl::registration::TransformationValidationEuclidean::MyPointRepresentation::~MyPointRepresentation
virtual ~MyPointRepresentation()=default
Empty destructor.
pcl::registration::TransformationValidationEuclidean::MyPointRepresentation::MyPointRepresentation
MyPointRepresentation()
Definition transformation_validation_euclidean.h:242
pcl::registration::TransformationValidationEuclidean::MyPointRepresentation::Ptr
shared_ptr< MyPointRepresentation > Ptr
Definition transformation_validation_euclidean.h:239
pcl::registration::TransformationValidationEuclidean::MyPointRepresentation::copyToFloatArray
virtual void copyToFloatArray(const PointTarget &p, float *out) const
Copy point data from input point to a float array.
Definition transformation_validation_euclidean.h:252
pcl::registration::TransformationValidationEuclidean::MyPointRepresentation::ConstPtr
shared_ptr< const MyPointRepresentation > ConstPtr
Definition transformation_validation_euclidean.h:240
pcl::registration::TransformationValidationEuclidean
TransformationValidationEuclidean computes an L2SQR norm between a source and target dataset.
Definition transformation_validation_euclidean.h:75
pcl::registration::TransformationValidationEuclidean::setThreshold
void setThreshold(double threshold)
Set a threshold for which a specific transformation is considered valid.
Definition transformation_validation_euclidean.h:150
pcl::registration::TransformationValidationEuclidean::setSearchMethodTarget
void setSearchMethodTarget(const KdTreePtr &tree, bool force_no_recompute=false)
Provide a pointer to the search object used to find correspondences in the target cloud.
Definition transformation_validation_euclidean.h:135
pcl::registration::TransformationValidationEuclidean::operator()
virtual bool operator()(const double &score1, const double &score2) const
Comparator function for deciding which score is better after running the validation on multiple trans...
Definition transformation_validation_euclidean.h:186
pcl::registration::TransformationValidationEuclidean::force_no_recompute_
bool force_no_recompute_
A flag which, if set, means the tree operating on the target cloud will never be recomputed.
Definition transformation_validation_euclidean.h:231
pcl::registration::TransformationValidationEuclidean::ConstPtr
shared_ptr< const TransformationValidation< PointSource, PointTarget, Scalar > > ConstPtr
Definition transformation_validation_euclidean.h:82
pcl::registration::TransformationValidationEuclidean::max_range_
double max_range_
The maximum allowable distance between a point and its correspondence in the target in order for a co...
Definition transformation_validation_euclidean.h:219
pcl::registration::TransformationValidationEuclidean::threshold_
double threshold_
The threshold for which a specific transformation is valid.
Definition transformation_validation_euclidean.h:224
pcl::registration::TransformationValidationEuclidean::Matrix4
typename TransformationValidation< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
Definition transformation_validation_euclidean.h:78
pcl::registration::TransformationValidationEuclidean::PointCloudTargetConstPtr
typename TransformationValidation< PointSource, PointTarget >::PointCloudTargetConstPtr PointCloudTargetConstPtr
Definition transformation_validation_euclidean.h:94
pcl::registration::TransformationValidationEuclidean::validateTransformation
double validateTransformation(const PointCloudSourceConstPtr &cloud_src, const PointCloudTargetConstPtr &cloud_tgt, const Matrix4 &transformation_matrix) const
Validate the given transformation with respect to the input cloud data, and return a score.
Definition transformation_validation_euclidean.hpp:51
pcl::registration::TransformationValidationEuclidean::setMaxRange
void setMaxRange(double max_range)
Set the maximum allowable distance between a point and its correspondence in the target in order for ...
Definition transformation_validation_euclidean.h:113
pcl::registration::TransformationValidationEuclidean::getMaxRange
double getMaxRange()
Get the maximum allowable distance between a point and its correspondence, as set by the user.
Definition transformation_validation_euclidean.h:122
pcl::registration::TransformationValidationEuclidean::PointCloudSourceConstPtr
typename TransformationValidation< PointSource, PointTarget >::PointCloudSourceConstPtr PointCloudSourceConstPtr
Definition transformation_validation_euclidean.h:91
pcl::registration::TransformationValidationEuclidean::getThreshold
double getThreshold()
Get the threshold for which a specific transformation is valid.
Definition transformation_validation_euclidean.h:157
pcl::registration::TransformationValidationEuclidean::Ptr
shared_ptr< TransformationValidation< PointSource, PointTarget, Scalar > > Ptr
Definition transformation_validation_euclidean.h:80
pcl::registration::TransformationValidationEuclidean::tree_
KdTreePtr tree_
A pointer to the spatial search object.
Definition transformation_validation_euclidean.h:227
pcl::registration::TransformationValidationEuclidean::isValid
virtual bool isValid(const PointCloudSourceConstPtr &cloud_src, const PointCloudTargetConstPtr &cloud_tgt, const Matrix4 &transformation_matrix) const
Check if the score is valid for a specific transformation.
Definition transformation_validation_euclidean.h:200
pcl::registration::TransformationValidationEuclidean::~TransformationValidationEuclidean
virtual ~TransformationValidationEuclidean()=default
pcl::registration::TransformationValidationEuclidean::PointRepresentationConstPtr
typename KdTree::PointRepresentationConstPtr PointRepresentationConstPtr
Definition transformation_validation_euclidean.h:87
pcl::registration::TransformationValidationEuclidean::TransformationValidationEuclidean
TransformationValidationEuclidean()
Constructor.
Definition transformation_validation_euclidean.h:100
pcl::registration::TransformationValidationEuclidean::KdTreePtr
typename KdTree::Ptr KdTreePtr
Definition transformation_validation_euclidean.h:85
pcl::registration::TransformationValidation
TransformationValidation represents the base class for methods that validate the correctness of a tra...
Definition transformation_validation.h:68
pcl::registration::TransformationValidation::Matrix4
Eigen::Matrix< Scalar, 4, 4 > Matrix4
Definition transformation_validation.h:70
pcl::search::KdTree
search::KdTree is a wrapper class which inherits the pcl::KdTree class for performing search function...
Definition kdtree.h:62
pcl::search::KdTree::Ptr
shared_ptr< KdTree< PointT, Tree > > Ptr
Definition kdtree.h:75
pcl::search::KdTree::PointRepresentationConstPtr
typename PointRepresentation< PointT >::ConstPtr PointRepresentationConstPtr
Definition kdtree.h:80
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_macros.h
Defines all the PCL and non-PCL macros used.