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  {
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
armarx::aron::data::ConstVariantVisitor
Definition: VariantVisitor.h:39
armarx::aron::data::filter
Definition: WhitelistFilter.cpp:5
armarx::aron::data::LongPtr
std::shared_ptr< Long > LongPtr
Definition: forward_declarations.h:26
armarx::aron::data::NDArrayPtr
std::shared_ptr< NDArray > NDArrayPtr
Definition: NDArray.h:46
armarx::aron::data::DoublePtr
std::shared_ptr< Double > DoublePtr
Definition: forward_declarations.h:32
armarx::starts_with
bool starts_with(const std::string &haystack, const std::string &needle)
Definition: StringHelpers.cpp:47
armarx::aron::Path
The Path class.
Definition: Path.h:35
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
All.h
armarx::aron::data::filter::WhitelistFilter
Definition: WhitelistFilter.h:35
armarx::aron::data::filter::WhitelistFilter::Normalization
Definition: WhitelistFilter.h:38
armarx::aron::data::DictPtr
std::shared_ptr< Dict > DictPtr
Definition: Dict.h:41
armarx::ctrlutil::v
double v(double t, double v0, double a0, double j)
Definition: CtrlUtil.h:39
armarx::aron::data::filter::WhitelistFilter::visitAronVariant
void visitAronVariant(const data::DictPtr &) override
Definition: WhitelistFilter.cpp:48
armarx::aron::data::filter::WhitelistFilter::data
aron::data::VariantPtr data
Definition: WhitelistFilter.h:81
armarx::aron::data::filter::WhitelistFilter::WhitelistFilter
WhitelistFilter(const std::vector< std::string > &whitelist, const std::map< std::string, Normalization > &normalization={})
Definition: WhitelistFilter.cpp:7
VariantVisitor.h
armarx::aron::data::FloatPtr
std::shared_ptr< Float > FloatPtr
Definition: forward_declarations.h:29
armarx::aron::data::StringPtr
std::shared_ptr< String > StringPtr
Definition: forward_declarations.h:35
armarx::aron::data::filter::WhitelistFilter::Normalization::max
float max
Definition: WhitelistFilter.h:41
T
float T
Definition: UnscentedKalmanFilterTest.cpp:38
armarx::aron::data::IntPtr
std::shared_ptr< Int > IntPtr
Definition: forward_declarations.h:23
armarx::aron::data::ListPtr
std::shared_ptr< List > ListPtr
Definition: List.h:40
armarx::aron::data::filter::WhitelistFilter::Normalization::min
float min
Definition: WhitelistFilter.h:40
armarx::aron::Path::toString
std::string toString() const
Definition: Path.cpp:127
armarx::aron::data::BoolPtr
std::shared_ptr< Bool > BoolPtr
Definition: forward_declarations.h:38
norm
double norm(const Point &a)
Definition: point.hpp:102