AverageFilter.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 
27 #include "DatafieldFilter.h"
28 #include <ArmarXCore/interface/observers/Filters.h>
30 
31 namespace armarx::filters
32 {
33 
34 
35  /**
36  * @class AverageFilter
37  * @ingroup ObserverFilters
38  * @brief The AverageFilter class provides a simple filter by calculating the
39  * average value of a window for datafields of type float, int, long and double.
40  */
41  class AverageFilter :
42  virtual public DatafieldFilter,
43  virtual public AverageFilterBase
44  {
45  public:
46  AverageFilter();
47 
48  // DatafieldFilterBase interface
49  public:
50  VariantBasePtr calculate(const Ice::Current& c = Ice::emptyCurrent) const override;
51 
52  /**
53  * @brief This filter supports: Int, Long, Float, Double
54  * @return List of VariantTypes
55  */
56  ParameterTypeList getSupportedTypes(const Ice::Current& c = Ice::emptyCurrent) const override;
57 
58  private:
59  template <typename Type>
60  static Type CalcAvg(const TimeVariantBaseMap& map)
61  {
62  if (map.empty())
63  {
64  return 0;
65  }
66  double sum = 0;
67 
68  for (auto& v : map)
69  {
70  VariantPtr v2 = VariantPtr::dynamicCast(v.second);
71  sum += v2->get<Type>();
72  }
73 
74  double result = sum / map.size();
75  return result;
76  }
77  };
78 
79 }
80 
81 
armarx::DatafieldFilter
The DatafieldFilter class is the base class for all filters and filter implementation should derive f...
Definition: DatafieldFilter.h:45
armarx::filters::AverageFilter::getSupportedTypes
ParameterTypeList getSupportedTypes(const Ice::Current &c=Ice::emptyCurrent) const override
This filter supports: Int, Long, Float, Double.
Definition: AverageFilter.cpp:62
armarx::filters::AverageFilter::AverageFilter
AverageFilter()
Definition: AverageFilter.cpp:28
armarx::TimeVariantBaseMap
std::deque< std::pair< long, VariantBasePtr > > TimeVariantBaseMap
Definition: DatafieldFilter.h:36
c
constexpr T c
Definition: UnscentedKalmanFilterTest.cpp:43
armarx::filters::AverageFilter
The AverageFilter class provides a simple filter by calculating the average value of a window for dat...
Definition: AverageFilter.h:41
IceInternal::Handle<::armarx::VariantBase >
armarx::filters
Definition: AverageFilter.h:31
InvalidTypeException.h
DatafieldFilter.h
armarx::aron::similarity::FloatSimilarity::Type
Type
The Type enum.
Definition: FloatSimilarity.h:8
armarx::filters::AverageFilter::calculate
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: AverageFilter.cpp:32
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39