DatafieldFilter.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
19 * @author
20 * @date
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24#include "DatafieldFilter.h"
25
27
28namespace armarx
29{
30
31 DatafieldFilter::DatafieldFilter() : DatafieldFilterBase()
32 {
33 }
34
36 IceUtil::Shared(filter), DatafieldFilterBase(filter), dataHistory(filter.dataHistory)
37 {
38 }
39
40 void
41 DatafieldFilter::update(Ice::Long timestamp, const VariantBasePtr& value, const Ice::Current&)
42 {
43 if (!value || !value->getInitialized())
44 {
45 return;
46 }
47 bool recalculate = false;
48 {
49 std::unique_lock lock(historyMutex);
50 if (dataHistory.size() == 0 ||
51 timestamp - dataHistory.rbegin()->first >= minSampleTimeDelta)
52 {
53 if (dataHistory.size() >= (unsigned)windowFilterSize)
54 {
55 dataHistory.pop_front();
56 }
57 dataHistory.push_back(std::make_pair(timestamp, value));
58 recalculate = true;
59 }
60 }
61 if (recalculate)
62 {
63 filteredValue = calculate();
64 }
65 }
66
68 DatafieldFilter::getValue(const Ice::Current&) const
69 {
70 if (filteredValue)
71 {
72 return filteredValue;
73 }
74 else
75 {
76 return calculate();
77 }
78 }
79
80 bool
81 DatafieldFilter::checkTypeSupport(VariantTypeId variantType, const Ice::Current&) const
82 {
83 auto types = getSupportedTypes();
84
85 if (std::find(types.begin(), types.end(), variantType) != types.end())
86 {
87 return true;
88 }
89 else
90 {
91 return false;
92 }
93 }
94
95 armarx::StringFloatDictionary
96 DatafieldFilter::getProperties(const Ice::Current&) const
97 {
98 return StringFloatDictionary{{"windowFilterSize", windowFilterSize},
99 {"minSampleTimeDelta", minSampleTimeDelta}};
100 }
101
102 void
103 DatafieldFilter::setProperties(const armarx::StringFloatDictionary& newValues,
104 const Ice::Current&)
105 {
106 auto it = newValues.find("windowFilterSize");
107 if (it != newValues.end())
108 {
109 windowFilterSize = it->second;
110 }
111 it = newValues.find("minSampleTimeDelta");
112 if (it != newValues.end())
113 {
114 minSampleTimeDelta = it->second;
115 }
116 }
117
118 const TimeVariantBaseMap&
120 {
121 return dataHistory;
122 }
123
124
125} // namespace armarx
std::string timestamp()
The DatafieldFilter class is the base class for all filters and filter implementation should derive f...
void update(Ice::Long timestamp, const VariantBasePtr &value, const Ice::Current &c=Ice::emptyCurrent) override
Adds the given value to the data map, erases old values if maximum size was reached,...
const TimeVariantBaseMap & getDataHistory() const
VariantBasePtr getValue(const Ice::Current &c=Ice::emptyCurrent) const override
Retrieves the current, filtered value.
TimeVariantBaseMap dataHistory
armarx::StringFloatDictionary getProperties(const Ice::Current &c=Ice::emptyCurrent) const override
void setProperties(const armarx::StringFloatDictionary &newValues, const Ice::Current &c=Ice::emptyCurrent) override
bool checkTypeSupport(VariantTypeId variantType, const Ice::Current &c=Ice::emptyCurrent) const override
Checks whether the given type is supported.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::deque< std::pair< long, VariantBasePtr > > TimeVariantBaseMap
Ice::Int VariantTypeId
Definition Variant.h:43
::IceInternal::Handle<::armarx::VariantBase > VariantBasePtr