Metrics.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotComponents
19  * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl.txt
22  * GNU General Public License
23  */
24 #pragma once
25 
26 #include <cmath>
27 #include <iterator>
28 
29 namespace armarx
30 {
31  /**
32  * @brief Returns the squared euclidean distance with weighted with the given vector.
33  * @param first1 First value of the first vector.
34  * @param last1 One past the last value of the first vector.
35  * @param first2 First value of the second vector.
36  * @param firstw First weight.
37  * @return The squared euclidean distance with weighted with the given vector.
38  */
39  template<class IteratorType1, class IteratorType2, class IteratorType3>
40  float euclideanDistanceWeightedSquared(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2, IteratorType3 firstw)
41  {
42  float akk = 0;
43 
44  for (; first1 < last1; ++first1, ++first2, ++firstw)
45  {
46  akk += std::pow((*first1 - *first2) * (*firstw), 2);
47  }
48 
49  return akk;
50  }
51 
52  /**
53  * @brief Returns the squared euclidean distance.
54  * @param first1 First value of the first vector.
55  * @param last1 One past the last value of the first vector.
56  * @param first2 First value of the second vector.
57  * @return The squared euclidean distance.
58  */
59  template<class IteratorType1, class IteratorType2>
60  float euclideanDistanceSquared(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
61  {
62  float akk = 0;
63 
64  for (; first1 < last1; ++first1, ++first2)
65  {
66  akk += std::pow(*first1 - *first2, 2);
67  }
68 
69  return akk;
70  }
71 
72  /**
73  * @brief Returns the euclidean distance with weighted with the given vector.
74  * @param first1 First value of the first vector.
75  * @param last1 One past the last value of the first vector.
76  * @param first2 First value of the second vector.
77  * @param firstw First weight.
78  * @return The euclidean distance with weighted with the given vector.
79  */
80  template<class IteratorType>
81  float euclideanDistanceWeighted(IteratorType first1, IteratorType last1, IteratorType first2, IteratorType firstw)
82  {
83  return std::sqrt(euclideanDistanceWeightedSquared(first1, last1, first2, firstw));
84  }
85 
86  /**
87  * @brief Returns the euclidean distance.
88  * @param first1 First value of the first vector.
89  * @param last1 One past the last value of the first vector.
90  * @param first2 First value of the second vector.
91  * @return The euclidean distance.
92  */
93  template<class IteratorType1, class IteratorType2>
94  float euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
95  {
96  return std::sqrt(euclideanDistanceSquared(first1, last1, first2));
97  }
98 }
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:662
armarx::euclideanDistanceWeighted
float euclideanDistanceWeighted(IteratorType first1, IteratorType last1, IteratorType first2, IteratorType firstw)
Returns the euclidean distance with weighted with the given vector.
Definition: Metrics.h:81
armarx::euclideanDistanceWeightedSquared
float euclideanDistanceWeightedSquared(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2, IteratorType3 firstw)
Returns the squared euclidean distance with weighted with the given vector.
Definition: Metrics.h:40
armarx::euclideanDistance
float euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the euclidean distance.
Definition: Metrics.h:94
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
armarx::euclideanDistanceSquared
float euclideanDistanceSquared(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the squared euclidean distance.
Definition: Metrics.h:60