Point Cloud Library (PCL)  1.9.1-dev
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 #ifndef PCL_REGISTRATION_TRANSFORMATION_VALIDATION_EUCLIDEAN_IMPL_H_
41 #define PCL_REGISTRATION_TRANSFORMATION_VALIDATION_EUCLIDEAN_IMPL_H_
42 
43 /////////////////////////////////////////////////////////////////////////////////////////////////////////
44 template <typename PointSource, typename PointTarget, typename Scalar> double
46  const PointCloudSourceConstPtr &cloud_src,
47  const PointCloudTargetConstPtr &cloud_tgt,
48  const Matrix4 &transformation_matrix) const
49 {
50  double fitness_score = 0.0;
51 
52  // Transform the input dataset using the final transformation
53  pcl::PointCloud<PointSource> input_transformed;
54  //transformPointCloud (*cloud_src, input_transformed, transformation_matrix);
55  input_transformed.resize (cloud_src->size ());
56  for (size_t i = 0; i < cloud_src->size (); ++i)
57  {
58  const PointSource &src = cloud_src->points[i];
59  PointTarget &tgt = input_transformed.points[i];
60  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));
61  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));
62  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));
63  }
64 
66  if (!force_no_recompute_)
67  {
68  tree_->setPointRepresentation (point_rep);
69  tree_->setInputCloud (cloud_tgt);
70  }
71 
72  std::vector<int> nn_indices (1);
73  std::vector<float> nn_dists (1);
74 
75  // For each point in the source dataset
76  int nr = 0;
77  for (size_t i = 0; i < input_transformed.points.size (); ++i)
78  {
79  // Find its nearest neighbor in the target
80  tree_->nearestKSearch (input_transformed.points[i], 1, nn_indices, nn_dists);
81 
82  // Deal with occlusions (incomplete targets)
83  if (nn_dists[0] > max_range_)
84  continue;
85 
86  // Calculate the fitness score
87  fitness_score += nn_dists[0];
88  ++nr;
89  }
90 
91  if (nr > 0)
92  return (fitness_score / nr);
93  return (std::numeric_limits<double>::max ());
94 }
95 
96 #endif // PCL_REGISTRATION_TRANSFORMATION_VALIDATION_EUCLIDEAN_IMPL_H_
97 
std::vector< PointT, Eigen::aligned_allocator< PointT > > points
The point data.
Definition: point_cloud.h:423
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, Scalar >::Matrix4 Matrix4
typename TransformationValidation< PointSource, PointTarget >::PointCloudSourceConstPtr PointCloudSourceConstPtr
typename TransformationValidation< PointSource, PointTarget >::PointCloudTargetConstPtr PointCloudTargetConstPtr
void resize(size_t n)
Resize the cloud.
Definition: point_cloud.h:468