Point Cloud Library (PCL) 1.15.1-dev
Loading...
Searching...
No Matches
transformation_validation_euclidean.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/registration/transformation_validation.h>
44#include <pcl/memory.h>
45#include <pcl/pcl_macros.h>
46#include <pcl/point_representation.h>
47
48namespace pcl {
49namespace registration {
50/** \brief TransformationValidationEuclidean computes an L2SQR norm between a source and
51 * target dataset.
52 *
53 * To prevent points with bad correspondences to contribute to the overall score, the
54 * class also accepts a maximum_range parameter given via \ref setMaxRange that is used
55 * as a cutoff value for nearest neighbor distance comparisons.
56 *
57 * The output score is normalized with respect to the number of valid correspondences
58 * found.
59 *
60 * Usage example:
61 * \code
62 * pcl::TransformationValidationEuclidean<pcl::PointXYZ, pcl::PointXYZ> tve;
63 * tve.setMaxRange (0.01); // 1cm
64 * double score = tve.validateTransformation (source, target, transformation);
65 * \endcode
66 *
67 * \note The class is templated on the source and target point types as well as on the
68 * output scalar of the transformation matrix (i.e., float or double). Default: float.
69 * \author Radu B. Rusu
70 * \ingroup registration
71 */
72template <typename PointSource, typename PointTarget, typename Scalar = float>
74public:
75 using Matrix4 =
77
78 using Ptr = shared_ptr<TransformationValidation<PointSource, PointTarget, Scalar>>;
79 using ConstPtr =
80 shared_ptr<const TransformationValidation<PointSource, PointTarget, Scalar>>;
81
83 using KdTreePtr = typename KdTree::Ptr;
84
87
89 typename TransformationValidation<PointSource,
92 typename TransformationValidation<PointSource,
94
95 /** \brief Constructor.
96 * Sets the \a max_range parameter to double::max, \a threshold_ to NaN
97 * and initializes the internal search \a tree to a FLANN kd-tree.
98 */
100 : max_range_(std::numeric_limits<double>::max())
101 , threshold_(std::numeric_limits<double>::quiet_NaN())
102 {}
103
105
106 /** \brief Set the maximum allowable distance between a point and its correspondence
107 * in the target in order for a correspondence to be considered \a valid. Default:
108 * double::max. \param[in] max_range the new maximum allowable distance
109 */
110 inline void
111 setMaxRange(double max_range)
112 {
113 max_range_ = max_range;
114 }
115
116 /** \brief Get the maximum allowable distance between a point and its
117 * correspondence, as set by the user.
118 */
119 inline double
121 {
122 return (max_range_);
123 }
124
125 /** \brief Provide a pointer to the search object used to find correspondences in
126 * the target cloud.
127 * \param[in] tree a pointer to the spatial search object.
128 * \param[in] force_no_recompute If set to true, this tree will NEVER be
129 * recomputed, regardless of calls to setInputTarget. Only use if you are
130 * confident that the tree will be set correctly.
131 */
132 inline void
133 setSearchMethodTarget(const KdTreePtr& tree, bool force_no_recompute = false)
134 {
135 tree_ = tree;
136 force_no_recompute_ = force_no_recompute;
137 }
138
139 /** \brief Set a threshold for which a specific transformation is considered valid.
140 *
141 * \note Since we're using MSE (Mean Squared Error) as a metric, the threshold
142 * represents the mean Euclidean distance threshold over all nearest neighbors
143 * up to max_range.
144 *
145 * \param[in] threshold the threshold for which a transformation is vali
146 */
147 inline void
148 setThreshold(double threshold)
149 {
150 threshold_ = threshold;
151 }
152
153 /** \brief Get the threshold for which a specific transformation is valid. */
154 inline double
156 {
157 return (threshold_);
158 }
159
160 /** \brief Validate the given transformation with respect to the input cloud data, and
161 * return a score.
162 *
163 * \param[in] cloud_src the source point cloud dataset
164 * \param[in] cloud_tgt the target point cloud dataset
165 * \param[out] transformation_matrix the resultant transformation matrix
166 *
167 * \return the score or confidence measure for the given
168 * transformation_matrix with respect to the input data
169 */
170 double
172 const PointCloudTargetConstPtr& cloud_tgt,
173 const Matrix4& transformation_matrix) const;
174
175 /** \brief Comparator function for deciding which score is better after running the
176 * validation on multiple transforms.
177 *
178 * \param[in] score1 the first value
179 * \param[in] score2 the second value
180 *
181 * \return true if score1 is better than score2
182 */
183 virtual bool
184 operator()(const double& score1, const double& score2) const
185 {
186 return (score1 < score2);
187 }
188
189 /** \brief Check if the score is valid for a specific transformation.
190 *
191 * \param[in] cloud_src the source point cloud dataset
192 * \param[in] cloud_tgt the target point cloud dataset
193 * \param[out] transformation_matrix the transformation matrix
194 *
195 * \return true if the transformation is valid, false otherwise.
196 */
197 virtual bool
199 const PointCloudTargetConstPtr& cloud_tgt,
200 const Matrix4& transformation_matrix) const
201 {
202 if (std::isnan(threshold_)) {
203 PCL_ERROR("[pcl::TransformationValidationEuclidean::isValid] Threshold not set! "
204 "Please use setThreshold () before continuing.\n");
205 return (false);
206 }
207
208 return (validateTransformation(cloud_src, cloud_tgt, transformation_matrix) <
209 threshold_);
210 }
211
212protected:
213 /** \brief The maximum allowable distance between a point and its correspondence in
214 * the target in order for a correspondence to be considered \a valid. Default:
215 * double::max.
216 */
218
219 /** \brief The threshold for which a specific transformation is valid.
220 * Set to NaN by default, as we must require the user to set it.
221 */
223
224 /** \brief A pointer to the spatial search object. */
226
227 /** \brief A flag which, if set, means the tree operating on the target cloud
228 * will never be recomputed*/
230
231 /** \brief Internal point representation uses only 3D coordinates for L2 */
234 using pcl::PointRepresentation<PointTarget>::trivial_;
235
236 public:
237 using Ptr = shared_ptr<MyPointRepresentation>;
238 using ConstPtr = shared_ptr<const MyPointRepresentation>;
239
241 {
242 nr_dimensions_ = 3;
243 trivial_ = true;
244 }
245
246 /** \brief Empty destructor */
247 ~MyPointRepresentation() override = default;
248
249 void
250 copyToFloatArray(const PointTarget& p, float* out) const override
251 {
252 out[0] = p.x;
253 out[1] = p.y;
254 out[2] = p.z;
255 }
256 };
257
258public:
260};
261} // namespace registration
262} // namespace pcl
263
264#include <pcl/registration/impl/transformation_validation_euclidean.hpp>
PointRepresentation provides a set of methods for converting a point structs/object into an n-dimensi...
shared_ptr< const PointRepresentation< PointT > > ConstPtr
int nr_dimensions_
The number of dimensions in this point's vector (i.e.
bool trivial_
Indicates whether this point representation is trivial.
void copyToFloatArray(const PointTarget &p, float *out) const override
Copy point data from input point to a float array.
TransformationValidationEuclidean computes an L2SQR norm between a source and target dataset.
void setThreshold(double threshold)
Set a threshold for which a specific transformation is considered valid.
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.
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...
bool force_no_recompute_
A flag which, if set, means the tree operating on the target cloud will never be recomputed.
shared_ptr< const TransformationValidation< PointSource, PointTarget, Scalar > > ConstPtr
double max_range_
The maximum allowable distance between a point and its correspondence in the target in order for a co...
double threshold_
The threshold for which a specific transformation is valid.
typename TransformationValidation< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
typename TransformationValidation< PointSource, PointTarget >::PointCloudTargetConstPtr PointCloudTargetConstPtr
typename PointRepresentation< PointTarget >::ConstPtr PointRepresentationConstPtr
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.
void setMaxRange(double max_range)
Set the maximum allowable distance between a point and its correspondence in the target in order for ...
double getMaxRange()
Get the maximum allowable distance between a point and its correspondence, as set by the user.
typename TransformationValidation< PointSource, PointTarget >::PointCloudSourceConstPtr PointCloudSourceConstPtr
double getThreshold()
Get the threshold for which a specific transformation is valid.
shared_ptr< TransformationValidation< PointSource, PointTarget, Scalar > > Ptr
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.
TransformationValidation represents the base class for methods that validate the correctness of a tra...
shared_ptr< pcl::search::Search< PointTarget > > Ptr
Definition search.h:84
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition memory.h:86
Defines functions, macros and traits for allocating and using memory.
Defines all the PCL and non-PCL macros used.