MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Function.hpp
Go to the documentation of this file.
1 #ifndef __FUNCTION_HPP__
2 #define __FUNCTION_HPP__
3 
9 #include <Config.hpp>
10 
11 #include <string>
12 #include <vector>
13 #include <Vector.hpp>
14 
15 namespace mgx {
16 namespace util {
24 class Function {
25 public:
26  Function();
27  Function(std::string filename);
28  Function(const Function& copy);
29  Function& operator=(const Function&);
30  double operator()(double x);
31  const Vector<2, double>& getMax() const;
32  const Vector<2, double>& getMin() const;
33  void reread();
34  void setSamples(size_t n);
35  bool error();
40  void scaleX(double s) {
41  scaling_x = 1 / s;
42  }
47  void scaleY(double s) {
48  scaling_y = s;
49  }
51  double scaleX() const {
52  return 1 / scaling_x;
53  }
55  double scaleY() const {
56  return scaling_y;
57  }
65  void shiftX(double s) {
66  shift_x = -s;
67  }
75  void shiftY(double s) {
76  shift_y = s;
77  }
79  double shiftX() const {
80  return -shift_x;
81  }
83  double shiftY() const {
84  return shift_y;
85  }
86  void normalizeY(bool shift = true);
87  void normalizeX(bool shift = true);
88 
89 private:
90  std::string filename;
91  std::vector<Vector<2, double> > pts;
94  unsigned int samples;
95  double scaling_x, scaling_y;
96  double shift_x, shift_y;
97 
98  Vector<2, double> P(double x) const;
99  double N(int, int, double) const;
100  double Nk1(int, double) const;
101  double Nkt(int, int, double) const;
102  int Uk(int) const;
103  double getVal(double x) const; // computes the actual value for a given x
104 
105  struct CacheVal {
106  bool valid;
107  double val;
108  };
109  bool cache_valid; // whether the cache vector is resized properly or not
110  std::vector<CacheVal> cache; // stores the cached values
111  void init(); // should be executed by every constructor
112  bool error_occured; // when loading this indicates whether there was an error
113 };
114 } // namespace util
115 } // namespace mgx
116 
117 #endif
void shiftY(double s)
Shift the y axis by s.
Definition: Function.hpp:75
double scaleX() const
Get the current x scaling.
Definition: Function.hpp:51
A utility class for functions.
Definition: Function.hpp:24
void scaleY(double s)
Scale the y axis by s.
Definition: Function.hpp:47
double shiftX() const
Get the current x axis shift.
Definition: Function.hpp:79
void scaleX(double s)
Scale the x axis by s.
Definition: Function.hpp:40
double shiftY() const
Get the current y axis shift.
Definition: Function.hpp:83
double scaleY() const
Get the current y scaling.
Definition: Function.hpp:55
void shiftX(double s)
Shift the x axis by s.
Definition: Function.hpp:65
Defines the Vector class template This file is shared by cuda, do not include headers that nvcc can't...