WhitelistFilter.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Peller ( fabian dot peller at kit dot edu )
17 * @date 2023
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <algorithm>
25#include <map>
26#include <vector>
27
28#include <SimoxUtility/algorithm/string/string_tools.h>
29
32
34{
36 {
37 public:
39 {
40 float min;
41 float max;
42 };
43
44 WhitelistFilter(const std::vector<std::string>& whitelist,
45 const std::map<std::string, Normalization>& normalization = {});
46
47 void visitAronVariant(const data::DictPtr&) override;
48 void visitAronVariant(const data::ListPtr&) override;
49 void visitAronVariant(const data::NDArrayPtr&) override;
50 void visitAronVariant(const data::IntPtr&) override;
51 void visitAronVariant(const data::LongPtr&) override;
52 void visitAronVariant(const data::FloatPtr&) override;
53 void visitAronVariant(const data::DoublePtr&) override;
54 void visitAronVariant(const data::BoolPtr&) override;
55 void visitAronVariant(const data::StringPtr&) override;
56
57 private:
58 bool pathInWhitelist(const aron::Path& p) const;
59
60 // normalization
61 template <class T>
62 T
63 checkForNormalization(const aron::Path& p, const T& t)
64 {
65 for (const auto& [n, v] : normalization)
66 {
67 if (simox::alg::starts_with(p.toString(), n))
68 {
69 auto diff = v.max - v.min;
70 auto norm = (t - v.min) / diff;
71 return norm;
72 }
73 }
74 return t;
75 }
76
77 std::vector<std::string> whitelist;
78 std::map<std::string, Normalization> normalization;
79
80 public:
82 };
83} // namespace armarx::aron::data::filter
The Path class.
Definition Path.h:36
std::string toString() const
Definition Path.cpp:127
void visitAronVariant(const data::DictPtr &) override
WhitelistFilter(const std::vector< std::string > &whitelist, const std::map< std::string, Normalization > &normalization={})
std::shared_ptr< Dict > DictPtr
Definition Dict.h:42
std::shared_ptr< List > ListPtr
Definition List.h:41
std::shared_ptr< Bool > BoolPtr
std::shared_ptr< Float > FloatPtr
std::shared_ptr< Variant > VariantPtr
std::shared_ptr< NDArray > NDArrayPtr
Definition NDArray.h:46
std::shared_ptr< Long > LongPtr
std::shared_ptr< Int > IntPtr
std::shared_ptr< Double > DoublePtr
std::shared_ptr< String > StringPtr
double norm(const Point &a)
Definition point.hpp:102