MorphoGraphX  2.0-1-227
Function.hpp
Go to the documentation of this file.
1 #ifndef __UTIL__FUNCTION_HPP__
2 #define __UTIL__FUNCTION_HPP__
3 
9 #include <Config.hpp>
10 
11 #include <QString>
12 
13 #include <string>
14 #include <vector>
15 #include <Vector.hpp>
16 
17 namespace mgx
18 {
26  class mgx_EXPORT Function
27  {
28  public:
29  Function();
30  Function(const QString &filename);
31  Function(const Function& copy);
32  Function& operator=(const Function&);
33 #ifdef USE_CXX0X
34  Function(Function&& copy) = default;
35  Function& operator=(Function&&) = default;
36 #endif
37  double operator()(double x);
38  const Vector<2,double>& getMax() const;
39  const Vector<2,double>& getMin() const;
40  void reRead();
41  bool setFile(const QString &file);
42  void setSamples (size_t n);
43  bool error();
44  QString fileName() { return filename; }
49  void scaleX(double s) { scaling_x = 1/s; }
54  void scaleY(double s) { scaling_y = s; }
56  double scaleX() const { return 1/scaling_x; }
58  double scaleY() const { return scaling_y; }
66  void shiftX(double s) { shift_x = -s; }
74  void shiftY(double s) { shift_y = s; }
76  double shiftX() const { return -shift_x; }
78  double shiftY() const { return shift_y; }
79  void normalizeY(bool shift = true);
80  void normalizeX(bool shift = true);
81 
82  private:
83  QString filename;
84  std::vector<Vector<2,double> > pts;
87  unsigned int samples;
88  double scaling_x, scaling_y;
89  double shift_x, shift_y;
90 
91  Vector<2,double> P(double x) const;
92  double N(int, int, double) const;
93  double Nk1(int, double) const;
94  double Nkt(int, int, double) const;
95  int Uk(int) const;
96  double getVal(double x) const; // computes the actual value for a given x
97 
98  struct CacheVal {
99  bool valid;
100  double val;
101  };
102  bool cache_valid; // whether the cache vector is resized properly or not
103  std::vector <CacheVal> cache; // stores the cached values
104  void init(); // should be executed by every constructor
105  bool error_occured; // when loading this indicates whether there was an error
106  };
107 }
108 
109 #endif
Vector.hpp
mgx::Function::fileName
QString fileName()
Definition: Function.hpp:44
n
#define n
Definition: Eigenvalues.hpp:36
mgx::Function::scaleX
void scaleX(double s)
Scale the x axis by s.
Definition: Function.hpp:49
mgx::Information::init
mgx_EXPORT void init(QMainWindow *wnd)
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::Function::scaleY
double scaleY() const
Get the current y scaling.
Definition: Function.hpp:58
mgx::Function::scaleX
double scaleX() const
Get the current x scaling.
Definition: Function.hpp:56
mgx::max
T CU_HOST_DEVICE max(const T a, const T b)
Definition: Util.hpp:34
mgx::Function::shiftX
double shiftX() const
Get the current x axis shift.
Definition: Function.hpp:76
mgx::Function::shiftX
void shiftX(double s)
Shift the x axis by s.
Definition: Function.hpp:66
mgx::Function
A utility class for functions.
Definition: Function.hpp:26
mgx::Function::shiftY
double shiftY() const
Get the current y axis shift.
Definition: Function.hpp:78
mgx::Vector< 2, double >
mgx::min
CU_HOST_DEVICE T min(const T a, const T b)
Definition: Util.hpp:26
mgx::Function::scaleY
void scaleY(double s)
Scale the y axis by s.
Definition: Function.hpp:54
mgx::Function::shiftY
void shiftY(double s)
Shift the y axis by s.
Definition: Function.hpp:74