GaussianFilter.cpp
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 ArmarX
19  * @author Mirko Waechter( mirko.waechter at kit dot edu)
20  * @date 2016
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 #include "GaussianFilter.h"
25 
27 
28 namespace armarx
29 {
30  armarx::filters::GaussianFilter::GaussianFilter(int filterSizeInMs, int windowSize)
31  {
32  this->filterSizeInMs = filterSizeInMs;
33  this->windowFilterSize = windowSize;
34  }
35 
37  {
38  std::unique_lock lock(historyMutex);
39 
40  if (dataHistory.size() == 0)
41  {
42  return nullptr;
43  }
44 
45  VariantTypeId type = dataHistory.begin()->second->getType();
46 
47  if (type == VariantType::Float)
48  {
49  return new Variant(calcGaussianFilteredValue<float>(dataHistory));
50  }
51  else if (type == VariantType::Double)
52  {
53  return new Variant(calcGaussianFilteredValue<double>(dataHistory));
54  }
55  else if (type == VariantType::Int)
56  {
57  return new Variant(calcGaussianFilteredValue<int>(dataHistory));
58  }
59  else if (type == VariantType::Int)
60  {
61  return new Variant(calcGaussianFilteredValue<long>(dataHistory));
62  }
63 
65  }
66 
67  armarx::ParameterTypeList armarx::filters::GaussianFilter::getSupportedTypes(const Ice::Current&) const
68  {
69  ParameterTypeList result;
70  result.push_back(VariantType::Int);
71  result.push_back(VariantType::Long);
72  result.push_back(VariantType::Float);
73  result.push_back(VariantType::Double);
74  return result;
75  }
76 
77 
78  armarx::StringFloatDictionary armarx::filters::GaussianFilter::getProperties(const Ice::Current&) const
79  {
80  auto props = DatafieldFilter::getProperties();
81  props["filterSizeInMs"] = filterSizeInMs;
82  return props;
83  }
84 
85  void armarx::filters::GaussianFilter::setProperties(const armarx::StringFloatDictionary& newValues, const Ice::Current&)
86  {
87  auto it = newValues.find("filterSizeInMs");
88  if (it != newValues.end())
89  {
90  filterSizeInMs = it->second;
91  }
93  }
94 }
95 
armarx::Variant
The Variant class is described here: Variants.
Definition: Variant.h:224
armarx::VariantType::Float
const VariantTypeId Float
Definition: Variant.h:918
GaussianFilter.h
armarx::filters::GaussianFilter::getProperties
StringFloatDictionary getProperties(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: GaussianFilter.cpp:78
armarx::filters::GaussianFilter::setProperties
void setProperties(const StringFloatDictionary &newValues, const Ice::Current &c=Ice::emptyCurrent) override
Definition: GaussianFilter.cpp:85
IceInternal::Handle<::armarx::VariantBase >
InvalidTypeException.h
armarx::VariantType::Double
const VariantTypeId Double
Definition: Variant.h:919
armarx::filters::GaussianFilter::calculate
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: GaussianFilter.cpp:36
armarx::DatafieldFilter::setProperties
void setProperties(const armarx::StringFloatDictionary &newValues, const Ice::Current &c=Ice::emptyCurrent) override
Definition: DatafieldFilter.cpp:103
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::VariantType::Long
const VariantTypeId Long
Definition: Variant.h:917
armarx::exceptions::user::UnsupportedTypeException
Definition: InvalidTypeException.h:67
armarx::DatafieldFilter::getProperties
armarx::StringFloatDictionary getProperties(const Ice::Current &c=Ice::emptyCurrent) const override
Definition: DatafieldFilter.cpp:96
armarx::VariantTypeId
Ice::Int VariantTypeId
Definition: Variant.h:44
armarx::filters::GaussianFilter::GaussianFilter
GaussianFilter(int filterSizeInMs=200, int windowSize=20)
GaussianFilter.
Definition: GaussianFilter.cpp:30
armarx::VariantType::Int
const VariantTypeId Int
Definition: Variant.h:916
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28