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 "DatafieldFilter.h"
27 
28 #include <ArmarXCore/interface/observers/Filters.h>
29 
30 #include <cmath>
31 
32 namespace 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  */
43  public DatafieldFilter,
44  public GaussianFilterBase
45  {
46  public:
47  /**
48  * @brief GaussianFilter
49  * @param filterSizeInMs Width of the gauss function
50  * @param windowSize size of the filter window
51  */
52  GaussianFilter(int filterSizeInMs = 200, int windowSize = 20);
53 
54 
55  // DatafieldFilterBase interface
56  public:
57  template <typename Type>
59  {
60  const double sigma = filterSizeInMs / 2.5;
61  //-log(0.05) / pow(itemsToCheck+1+centerIndex,2) * ( sqrt(1.0/h) * sqrt(2*3.14159265));
62 
63  double weightedSum = 0;
64  double sumOfWeight = 0;
65 
66 
67  const double sqrt2PI = sqrt(2 * M_PI);
68 
69 
70  for (auto it = map.begin();
71  it != map.end();
72  it++
73  )
74  {
75  double value;
76  value = VariantPtr::dynamicCast(it->second)->get<Type>();
77  double diff = 0.001 * (it->first - map.rbegin()->first);
78 
79  double squared = diff * diff;
80  const double gaussValue = exp(-squared / (2 * sigma * sigma)) / (sigma * sqrt2PI);
81  sumOfWeight += gaussValue;
82  weightedSum += gaussValue * value;
83 
84  }
85 
86  double result;
87  result = weightedSum / sumOfWeight;
88  return result;
89  }
90 
91  VariantBasePtr calculate(const Ice::Current& c = Ice::emptyCurrent) const override;
92 
93  /**
94  * @brief This filter supports: Int, Long, Float, Double
95  * @return List of VariantTypes
96  */
97  ParameterTypeList getSupportedTypes(const Ice::Current& c = Ice::emptyCurrent) const override;
98 
99 
100 
101  // DatafieldFilterBase interface
102  public:
103  StringFloatDictionary getProperties(const Ice::Current& c = Ice::emptyCurrent) const override;
104  void setProperties(const StringFloatDictionary& newValues, const Ice::Current& c = Ice::emptyCurrent) override;
105  };
106 
107 }
GfxTL::sqrt
VectorXD< D, T > sqrt(const VectorXD< D, T > &a)
Definition: VectorXD.h:662
armarx::DatafieldFilter
The DatafieldFilter class is the base class for all filters and filter implementation should derive f...
Definition: DatafieldFilter.h:45
armarx::TimeVariantBaseMap
std::deque< std::pair< long, VariantBasePtr > > TimeVariantBaseMap
Definition: DatafieldFilter.h:36
armarx::filters::GaussianFilter::getProperties
StringFloatDictionary getProperties(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: GaussianFilter.cpp:78
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::filters::GaussianFilter::setProperties
void setProperties(const StringFloatDictionary &newValues, const Ice::Current &c=Ice::emptyCurrent) override
Definition: GaussianFilter.cpp:85
armarx::filters::GaussianFilter
The GaussianFilter class provides a filter implemtentation with gaussian weighted values for datafiel...
Definition: GaussianFilter.h:42
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::filters
Definition: AverageFilter.h:31
cxxopts::value
std::shared_ptr< Value > value()
Definition: cxxopts.hpp:926
M_PI
#define M_PI
Definition: MathTools.h:17
DatafieldFilter.h
armarx::filters::GaussianFilter::calculate
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: GaussianFilter.cpp:36
armarx::filters::GaussianFilter::getSupportedTypes
ParameterTypeList getSupportedTypes(const Ice::Current &c=Ice::emptyCurrent) const override
This filter supports: Int, Long, Float, Double.
Definition: GaussianFilter.cpp:67
armarx::aron::similarity::FloatSimilarity::Type
Type
The Type enum.
Definition: FloatSimilarity.h:8
armarx::filters::GaussianFilter::GaussianFilter
GaussianFilter(int filterSizeInMs=200, int windowSize=20)
GaussianFilter.
Definition: GaussianFilter.cpp:30
armarx::filters::GaussianFilter::calcGaussianFilteredValue
Type calcGaussianFilteredValue(const TimeVariantBaseMap &map) const
Definition: GaussianFilter.h:58