MedianFilter.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 <ArmarXCore/interface/observers/Filters.h>
27#include <ArmarXCore/interface/observers/ObserverInterface.h>
29
30#include "DatafieldFilter.h"
31
32namespace armarx
33{
34 template <class IceBaseClass, class DerivedClass>
35 class GenericFactory;
36}
37
38namespace armarx::filters
39{
40
41 /**
42 * @class MedianFilter
43 * @ingroup ObserverFilters
44 * @brief The MedianFilter class provides an implementation
45 * for a median for datafields of type float, int, long and double.
46 */
47 class MedianFilter : virtual public MedianFilterBase, virtual public DatafieldFilter
48 {
49 public:
50 MedianFilter(int windowSize = 11);
51
52 // DatafieldFilterBase interface
53 public:
54 VariantBasePtr calculate(const Ice::Current& c = Ice::emptyCurrent) const override;
55
56 /**
57 * @brief This filter supports: Int, Long, Float, Double
58 * @return List of VariantTypes
59 */
60 ParameterTypeList
61 getSupportedTypes(const Ice::Current& c = Ice::emptyCurrent) const override;
62
63 template <typename Type>
64 static std::vector<Type>
66 {
67 std::vector<Type> values;
68
69 for (auto v : map)
70 {
71 VariantPtr v2 = VariantPtr::dynamicCast(v.second);
72 values.push_back(v2->get<Type>());
73 }
74
75 std::sort(values.begin(), values.end());
76 return values;
77 }
78 };
79
80
81} // namespace armarx::filters
constexpr T c
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)
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< Variant > VariantPtr
Definition Variant.h:41
std::deque< std::pair< long, VariantBasePtr > > TimeVariantBaseMap
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr