Point Cloud Library (PCL)  1.11.1
transformation_validation_euclidean.hpp
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 #ifndef PCL_REGISTRATION_TRANSFORMATION_VALIDATION_EUCLIDEAN_IMPL_H_
42 #define PCL_REGISTRATION_TRANSFORMATION_VALIDATION_EUCLIDEAN_IMPL_H_
43 
44 
45 namespace pcl
46 {
47 
48 namespace registration
49 {
50 
51 template <typename PointSource, typename PointTarget, typename Scalar> double
53  const PointCloudSourceConstPtr &cloud_src,
54  const PointCloudTargetConstPtr &cloud_tgt,
55  const Matrix4 &transformation_matrix) const
56 {
57  double fitness_score = 0.0;
58 
59  // Transform the input dataset using the final transformation
60  pcl::PointCloud<PointSource> input_transformed;
61  //transformPointCloud (*cloud_src, input_transformed, transformation_matrix);
62  input_transformed.resize (cloud_src->size ());
63  for (std::size_t i = 0; i < cloud_src->size (); ++i)
64  {
65  const PointSource &src = (*cloud_src)[i];
66  PointTarget &tgt = input_transformed[i];
67  tgt.x = static_cast<float> (transformation_matrix (0, 0) * src.x + transformation_matrix (0, 1) * src.y + transformation_matrix (0, 2) * src.z + transformation_matrix (0, 3));
68  tgt.y = static_cast<float> (transformation_matrix (1, 0) * src.x + transformation_matrix (1, 1) * src.y + transformation_matrix (1, 2) * src.z + transformation_matrix (1, 3));
69  tgt.z = static_cast<float> (transformation_matrix (2, 0) * src.x + transformation_matrix (2, 1) * src.y + transformation_matrix (2, 2) * src.z + transformation_matrix (2, 3));
70  }
71 
73  if (!force_no_recompute_)
74  {
75  tree_->setPointRepresentation (point_rep);
76  tree_->setInputCloud (cloud_tgt);
77  }
78 
79  std::vector<int> nn_indices (1);
80  std::vector<float> nn_dists (1);
81 
82  // For each point in the source dataset
83  int nr = 0;
84  for (const auto& point: input_transformed)
85  {
86  // Find its nearest neighbor in the target
87  tree_->nearestKSearch (point, 1, nn_indices, nn_dists);
88 
89  // Deal with occlusions (incomplete targets)
90  if (nn_dists[0] > max_range_)
91  continue;
92 
93  // Calculate the fitness score
94  fitness_score += nn_dists[0];
95  ++nr;
96  }
97 
98  if (nr > 0)
99  return (fitness_score / nr);
100  return (std::numeric_limits<double>::max ());
101 }
102 
103 } // namespace registration
104 } // namespace pcl
105 
106 #endif // PCL_REGISTRATION_TRANSFORMATION_VALIDATION_EUCLIDEAN_IMPL_H_
107 
void resize(std::size_t count)
Resizes the container to contain count elements.
Definition: point_cloud.h:478
typename TransformationValidation< PointSource, PointTarget, Scalar >::Matrix4 Matrix4
typename TransformationValidation< PointSource, PointTarget >::PointCloudTargetConstPtr PointCloudTargetConstPtr
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.
typename TransformationValidation< PointSource, PointTarget >::PointCloudSourceConstPtr PointCloudSourceConstPtr