Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
distances.h
Go to the documentation of this file.
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  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: distances.h 4367 2012-02-10 01:31:51Z rusu $
37  *
38  */
39 #ifndef PCL_REGISTRATION_DISTANCES_H
40 #define PCL_REGISTRATION_DISTANCES_H
41 
42 #include <Eigen/Core>
43 #include <vector>
44 
45 namespace pcl
46 {
47  namespace distances
48  {
49 
54  inline double
55  computeMedian (double *fvec, int m)
56  {
57  // Copy the values to vectors for faster sorting
58  std::vector<double> data (m);
59  memcpy (&data[0], fvec, sizeof (double) * m);
60 
61  std::nth_element(data.begin(), data.begin() + (data.size () >> 1), data.end());
62  return (data[data.size () >> 1]);
63  }
64 
70  inline double
71  huber (const Eigen::Vector4f &p_src, const Eigen::Vector4f &p_tgt, double sigma)
72  {
73  Eigen::Array4f diff = (p_tgt.array () - p_src.array ()).abs ();
74  double norm = 0.0;
75  for (int i = 0; i < 3; ++i)
76  {
77  if (diff[i] < sigma)
78  norm += diff[i] * diff[i];
79  else
80  norm += 2.0 * sigma * diff[i] - sigma * sigma;
81  }
82  return (norm);
83  }
84 
89  inline double
90  huber (double diff, double sigma)
91  {
92  double norm = 0.0;
93  if (diff < sigma)
94  norm += diff * diff;
95  else
96  norm += 2.0 * sigma * diff - sigma * sigma;
97  return (norm);
98  }
99 
106  inline double
107  gedikli (double val, double clipping, double slope = 4)
108  {
109  return (1.0 / (1.0 + pow (fabs(val) / clipping, slope)));
110  }
111 
116  inline double
117  l1 (const Eigen::Vector4f &p_src, const Eigen::Vector4f &p_tgt)
118  {
119  return ((p_src.array () - p_tgt.array ()).abs ().sum ());
120  }
121 
126  inline double
127  l2 (const Eigen::Vector4f &p_src, const Eigen::Vector4f &p_tgt)
128  {
129  return ((p_src - p_tgt).norm ());
130  }
131 
136  inline double
137  l2Sqr (const Eigen::Vector4f &p_src, const Eigen::Vector4f &p_tgt)
138  {
139  return ((p_src - p_tgt).squaredNorm ());
140  }
141  }
142 }
143 
144 #endif