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
29namespace 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
42 IteratorType1 last1,
43 IteratorType2 first2,
44 IteratorType3 firstw)
45 {
46 float akk = 0;
47
48 for (; first1 < last1; ++first1, ++first2, ++firstw)
49 {
50 akk += std::pow((*first1 - *first2) * (*firstw), 2);
51 }
52
53 return akk;
54 }
55
56 /**
57 * @brief Returns the squared euclidean distance.
58 * @param first1 First value of the first vector.
59 * @param last1 One past the last value of the first vector.
60 * @param first2 First value of the second vector.
61 * @return The squared euclidean distance.
62 */
63 template <class IteratorType1, class IteratorType2>
64 float
65 euclideanDistanceSquared(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
66 {
67 float akk = 0;
68
69 for (; first1 < last1; ++first1, ++first2)
70 {
71 akk += std::pow(*first1 - *first2, 2);
72 }
73
74 return akk;
75 }
76
77 /**
78 * @brief Returns the euclidean distance with weighted with the given vector.
79 * @param first1 First value of the first vector.
80 * @param last1 One past the last value of the first vector.
81 * @param first2 First value of the second vector.
82 * @param firstw First weight.
83 * @return The euclidean distance with weighted with the given vector.
84 */
85 template <class IteratorType>
86 float
87 euclideanDistanceWeighted(IteratorType first1,
88 IteratorType last1,
89 IteratorType first2,
90 IteratorType firstw)
91 {
92 return std::sqrt(euclideanDistanceWeightedSquared(first1, last1, first2, firstw));
93 }
94
95 /**
96 * @brief Returns the euclidean distance.
97 * @param first1 First value of the first vector.
98 * @param last1 One past the last value of the first vector.
99 * @param first2 First value of the second vector.
100 * @return The euclidean distance.
101 */
102 template <class IteratorType1, class IteratorType2>
103 float
104 euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
105 {
106 return std::sqrt(euclideanDistanceSquared(first1, last1, first2));
107 }
108} // namespace armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
float euclideanDistance(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the euclidean distance.
Definition Metrics.h:104
float euclideanDistanceWeighted(IteratorType first1, IteratorType last1, IteratorType first2, IteratorType firstw)
Returns the euclidean distance with weighted with the given vector.
Definition Metrics.h:87
float euclideanDistanceWeightedSquared(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2, IteratorType3 firstw)
Returns the squared euclidean distance with weighted with the given vector.
Definition Metrics.h:41
float euclideanDistanceSquared(IteratorType1 first1, IteratorType1 last1, IteratorType2 first2)
Returns the squared euclidean distance.
Definition Metrics.h:65