GaussianFilter.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
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
25#pragma once
26#include <cmath>
27
28#include <ArmarXCore/interface/observers/Filters.h>
29
30#include "DatafieldFilter.h"
31
32namespace armarx::filters
33{
34
35
36 /**
37 * @class GaussianFilter
38 * @ingroup ObserverFilters
39 * @brief The GaussianFilter class provides a filter implemtentation
40 * with gaussian weighted values for datafields of type float, int, long and double.
41 */
42 class GaussianFilter : public DatafieldFilter, public GaussianFilterBase
43 {
44 public:
45 /**
46 * @brief GaussianFilter
47 * @param filterSizeInMs Width of the gauss function
48 * @param windowSize size of the filter window
49 */
50 GaussianFilter(int filterSizeInMs = 200, int windowSize = 20);
51
52
53 // DatafieldFilterBase interface
54 public:
55 template <typename Type>
56 Type
58 {
59 const double sigma = filterSizeInMs / 2.5;
60 //-log(0.05) / pow(itemsToCheck+1+centerIndex,2) * ( sqrt(1.0/h) * sqrt(2*3.14159265));
61
62 double weightedSum = 0;
63 double sumOfWeight = 0;
64
65
66 const double sqrt2PI = sqrt(2 * M_PI);
67
68
69 for (auto it = map.begin(); it != map.end(); it++)
70 {
71 double value;
72 value = VariantPtr::dynamicCast(it->second)->get<Type>();
73 double diff = 0.001 * (it->first - map.rbegin()->first);
74
75 double squared = diff * diff;
76 const double gaussValue = exp(-squared / (2 * sigma * sigma)) / (sigma * sqrt2PI);
77 sumOfWeight += gaussValue;
78 weightedSum += gaussValue * value;
79 }
80
81 double result;
82 result = weightedSum / sumOfWeight;
83 return result;
84 }
85
86 VariantBasePtr calculate(const Ice::Current& c = Ice::emptyCurrent) const override;
87
88 /**
89 * @brief This filter supports: Int, Long, Float, Double
90 * @return List of VariantTypes
91 */
92 ParameterTypeList
93 getSupportedTypes(const Ice::Current& c = Ice::emptyCurrent) const override;
94
95
96 // DatafieldFilterBase interface
97 public:
98 StringFloatDictionary
99 getProperties(const Ice::Current& c = Ice::emptyCurrent) const override;
100 void setProperties(const StringFloatDictionary& newValues,
101 const Ice::Current& c = Ice::emptyCurrent) override;
102 };
103
104} // namespace armarx::filters
#define M_PI
Definition MathTools.h:17
constexpr T c
void setProperties(const StringFloatDictionary &newValues, const Ice::Current &c=Ice::emptyCurrent) override
GaussianFilter(int filterSizeInMs=200, int windowSize=20)
GaussianFilter.
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
StringFloatDictionary getProperties(const Ice::Current &c=Ice::emptyCurrent) const override
ParameterTypeList getSupportedTypes(const Ice::Current &c=Ice::emptyCurrent) const override
This filter supports: Int, Long, Float, Double.
Type calcGaussianFilteredValue(const TimeVariantBaseMap &map) const
std::deque< std::pair< long, VariantBasePtr > > TimeVariantBaseMap
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr