pointfilter.h
Go to the documentation of this file.
1 
8 #ifndef POINT_FILTER_H
9 #define POINT_FILTER_H
10 
11 #include <string>
12 #include <map>
13 
14 class Checker;
15 
16 
24 {
25 public:
26  // Default empty constructor
27  PointFilter();
29  PointFilter(const std::string& params);
30  ~PointFilter();
31 
32  PointFilter& setRange(double maxDist, double minDist);
33  PointFilter& setHeight(double top, double bottom);
34 
36  std::string getParams();
37 
39  inline bool check(double* point);
40 private:
42  std::map<std::string, std::string> m_params;
43 
45  bool m_changed;
46 
49 
51  void createCheckers();
52 
53  // factory magic
54  template<typename T> friend struct CheckerFactory;
55  static std::map<std::string, Checker* (*)(const std::string&)>* factory;
56 };
57 
58 class Checker {
59 public:
60  Checker();
61  ~Checker();
62 
64  virtual bool test(double* point) = 0;
65 
68 };
69 
71 template<typename T>
74  CheckerFactory(const std::string& key) { (*PointFilter::factory)[key] = CheckerFactory<T>::create; }
76  static Checker* create(const std::string& value) { try { return new T(value); } catch(...) { return 0; } }
77 };
78 
79 class CheckerRangeMax : public Checker {
80 public:
81  CheckerRangeMax(const std::string& value);
82  virtual bool test(double* point);
83 private:
84  double m_max;
85 };
86 
87 class CheckerRangeMin : public Checker {
88 public:
89  CheckerRangeMin(const std::string& value);
90  virtual bool test(double* point);
91 private:
92  double m_min;
93 };
94 
95 class CheckerHeightTop : public Checker {
96 public:
97  CheckerHeightTop(const std::string& value);
98  virtual bool test(double* point);
99 private:
100  double m_top;
101 };
102 
103 class CheckerHeightBottom : public Checker {
104 public:
105  CheckerHeightBottom(const std::string& value);
106  virtual bool test(double* point);
107 private:
108  double m_bottom;
109 };
110 
111 #include "pointfilter.icc"
112 
113 #endif //POINT_FILTER_H
CheckerFactory(const std::string &key)
Instanciate in the source code with the to be created class as template argument and associated key s...
Definition: pointfilter.h:74
bool m_changed
If either not created yet or parameters get changed, this flag will cause check to create a new Check...
Definition: pointfilter.h:45
static Checker * create(const std::string &value)
Automated create function, safely returning a nullpointer if the constructor throws for unwanted valu...
Definition: pointfilter.h:76
Factory integrating the create-function and adding it to the lookup map in an easy template...
Definition: pointfilter.h:72
std::string getParams()
Serialization function to convert it into a string, usable in the constructor.
bool check(double *point)
Check a point, returning success if all contained Checker functions accept that point (implemented in...
std::map< std::string, std::string > m_params
Storage for parameter keys and values.
Definition: pointfilter.h:42
Checker * m_checker
created in the first check call with the changed flag set
Definition: pointfilter.h:48
static std::map< std::string, Checker *(*)(const std::string &)> * factory
Definition: pointfilter.h:55
Checker * m_next
Next test in chain.
Definition: pointfilter.h:67
PointFilter & setRange(double maxDist, double minDist)
PointFilter & setHeight(double top, double bottom)
void createCheckers()
Allocation of the checkers.


lvr2
Author(s): Thomas Wiemann , Sebastian Pütz , Alexander Mock , Lars Kiesow , Lukas Kalbertodt , Tristan Igelbrink , Johan M. von Behren , Dominik Feldschnieders , Alexander Löhr
autogenerated on Mon Feb 28 2022 22:46:08