MedianFilter.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 "MedianFilter.h"
25
26namespace armarx
27{
29 {
30 this->windowFilterSize = windowSize;
31 }
32
35 {
36 std::unique_lock lock(historyMutex);
37 if (dataHistory.size() == 0)
38 {
39 return nullptr;
40 }
41
42 VariantTypeId type = dataHistory.begin()->second->getType();
43
44 if (type == VariantType::Float)
45 {
46 auto values = SortVariants<float>(dataHistory);
47 return new Variant(values.at(values.size() / 2));
48 }
49 else if (type == VariantType::Double)
50 {
51 auto values = SortVariants<double>(dataHistory);
52 return new Variant(values.at(values.size() / 2));
53 }
54 else if (type == VariantType::Int)
55 {
56 auto values = SortVariants<int>(dataHistory);
57 return new Variant(values.at(values.size() / 2));
58 }
59 else if (type == VariantType::Long)
60 {
61 auto values = SortVariants<long>(dataHistory);
62 return new Variant(values.at(values.size() / 2));
63 }
64
66 }
67
68 armarx::ParameterTypeList
70 {
71 ParameterTypeList result;
72 result.push_back(VariantType::Int);
73 result.push_back(VariantType::Long);
74 result.push_back(VariantType::Float);
75 result.push_back(VariantType::Double);
76 return result;
77 }
78} // namespace armarx
TimeVariantBaseMap dataHistory
The Variant class is described here: Variants.
Definition Variant.h:224
VariantBasePtr calculate(const Ice::Current &c=Ice::emptyCurrent) const override
MedianFilter(int windowSize=11)
ParameterTypeList getSupportedTypes(const Ice::Current &c=Ice::emptyCurrent) const override
This filter supports: Int, Long, Float, Double.
static std::vector< Type > SortVariants(const TimeVariantBaseMap &map)
const VariantTypeId Int
Definition Variant.h:917
const VariantTypeId Long
Definition Variant.h:918
const VariantTypeId Double
Definition Variant.h:920
const VariantTypeId Float
Definition Variant.h:919
This file offers overloads of toIce() and fromIce() functions for STL container types.
Ice::Int VariantTypeId
Definition Variant.h:43
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr