25 #include <RobotAPI/interface/observers/ObserverFilters.h>
37 public MatrixMaxFilterBase,
43 this->windowFilterSize = 1;
57 return new Variant(matrix->toEigen().maxCoeff());
61 ParameterTypeList result;
68 public MatrixMinFilterBase,
74 this->windowFilterSize = 1;
88 return new Variant(matrix->toEigen().minCoeff());
92 ParameterTypeList result;
99 public MatrixAvgFilterBase,
105 this->windowFilterSize = 1;
119 return new Variant(matrix->toEigen().mean());
123 ParameterTypeList result;
130 public MatrixPercentileFilterBase,
136 this->windowFilterSize = 1;
140 this->percentile = percentile;
141 this->windowFilterSize = 1;
155 std::vector<float> vector = matrix->toVector();
156 std::sort(vector.begin(), vector.end());
161 ParameterTypeList result;
166 static float GetPercentile(
const std::vector<float>& sortedData,
float percentile)
168 if (sortedData.size() == 0)
170 throw LocalException(
"GetPercentile not possible for empty vector");
173 float indexf = (sortedData.size() - 1) * percentile;
175 int index = (int)indexf;
176 float f = indexf -
index;
178 if (
index == (
int)sortedData.size() - 1)
180 return sortedData.at(sortedData.size() - 1);
183 return sortedData.at(
index) * (1 - f) + sortedData.at(
index + 1) * f;
188 public MatrixPercentilesFilterBase,
194 this->windowFilterSize = 1;
195 this->percentiles = 10;
199 this->percentiles = percentiles;
200 this->windowFilterSize = 1;
215 std::vector<float> vector = matrix->toVector();
216 std::sort(vector.begin(), vector.end());
217 std::vector<float> result;
218 result.push_back(vector.at(0));
220 for (
int i = 1; i < percentiles; i++)
225 result.push_back(vector.at(vector.size() - 1));
230 ParameterTypeList result;
237 public MatrixCumulativeFrequencyFilterBase,
243 this->windowFilterSize = 1;
250 this->windowFilterSize = 1;
263 std::vector<float> vector = matrix->toVector();
264 std::sort(vector.begin(), vector.end());
266 std::vector<float> resultF;
270 resultF.push_back(
v);
277 ParameterTypeList result;
281 static std::vector<int>
Calculate(
const std::vector<float>& sortedData,
float min,
float max,
int bins)
283 std::vector<int> result;
288 for (
size_t i = 0; i < sortedData.size(); i++)
290 if (sortedData.at(i) > val && nr < bins)
299 while ((
int)result.size() < bins)
301 result.push_back(lastCount);