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 
30 
32 {
34  {
35  public:
37  {
38  float min;
39  float max;
40  };
41 
42  WhitelistFilter(const std::vector<std::string>& whitelist,
43  const std::map<std::string, Normalization>& normalization = {});
44 
45  void visitAronVariant(const data::DictPtr&) override;
46  void visitAronVariant(const data::ListPtr&) override;
47  void visitAronVariant(const data::NDArrayPtr&) override;
48  void visitAronVariant(const data::IntPtr&) override;
49  void visitAronVariant(const data::LongPtr&) override;
50  void visitAronVariant(const data::FloatPtr&) override;
51  void visitAronVariant(const data::DoublePtr&) override;
52  void visitAronVariant(const data::BoolPtr&) override;
53  void visitAronVariant(const data::StringPtr&) override;
54 
55  private:
56  bool pathInWhitelist(const aron::Path& p) const;
57 
58  // normalization
59  template <class T>
60  T
61  checkForNormalization(const aron::Path& p, const T& t)
62  {
63  for (const auto& [n, v] : normalization)
64  {
66  {
67  auto diff = v.max - v.min;
68  auto norm = (t - v.min) / diff;
69  return norm;
70  }
71  }
72  return t;
73  }
74 
75  std::vector<std::string> whitelist;
76  std::map<std::string, Normalization> normalization;
77 
78  public:
80  };
81 } // 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:43
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::data::VariantPtr
std::shared_ptr< Variant > VariantPtr
Definition: forward_declarations.h:11
All.h
armarx::aron::data::filter::WhitelistFilter
Definition: WhitelistFilter.h:33
armarx::aron::data::filter::WhitelistFilter::Normalization
Definition: WhitelistFilter.h:36
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:79
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:39
T
float T
Definition: UnscentedKalmanFilterTest.cpp:35
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:38
armarx::aron::Path::toString
std::string toString() const
Definition: Path.cpp:125
armarx::aron::data::BoolPtr
std::shared_ptr< Bool > BoolPtr
Definition: forward_declarations.h:38
norm
double norm(const Point &a)
Definition: point.hpp:94