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