MorphoGraphX
Function.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef __FUNCTION_HPP__
12 #define __FUNCTION_HPP__
13 
19 #include <Config.hpp>
20 
21 #include <string>
22 #include <vector>
23 #include <Vector.hpp>
24 
25 namespace mgx {
26 namespace util {
34 class Function {
35 public:
36  Function();
37  Function(std::string filename);
38  Function(const Function& copy);
39  Function& operator=(const Function&);
40  double operator()(double x);
41  const Vector<2, double>& getMax() const;
42  const Vector<2, double>& getMin() const;
43  void reread();
44  void setSamples(size_t n);
45  bool error();
50  void scaleX(double s) {
51  scaling_x = 1 / s;
52  }
57  void scaleY(double s) {
58  scaling_y = s;
59  }
61  double scaleX() const {
62  return 1 / scaling_x;
63  }
65  double scaleY() const {
66  return scaling_y;
67  }
75  void shiftX(double s) {
76  shift_x = -s;
77  }
85  void shiftY(double s) {
86  shift_y = s;
87  }
89  double shiftX() const {
90  return -shift_x;
91  }
93  double shiftY() const {
94  return shift_y;
95  }
96  void normalizeY(bool shift = true);
97  void normalizeX(bool shift = true);
98 
99 private:
100  std::string filename;
101  std::vector<Vector<2, double> > pts;
102  Vector<2, double> max;
103  Vector<2, double> min;
104  unsigned int samples;
105  double scaling_x, scaling_y;
106  double shift_x, shift_y;
107 
108  Vector<2, double> P(double x) const;
109  double N(int, int, double) const;
110  double Nk1(int, double) const;
111  double Nkt(int, int, double) const;
112  int Uk(int) const;
113  double getVal(double x) const; // computes the actual value for a given x
114 
115  struct CacheVal {
116  bool valid;
117  double val;
118  };
119  bool cache_valid; // whether the cache vector is resized properly or not
120  std::vector<CacheVal> cache; // stores the cached values
121  void init(); // should be executed by every constructor
122  bool error_occured; // when loading this indicates whether there was an error
123 };
124 } // namespace util
125 } // namespace mgx
126 
127 #endif
void shiftY(double s)
Shift the y axis by s.
Definition: Function.hpp:85
double scaleX() const
Get the current x scaling.
Definition: Function.hpp:61
A utility class for functions.
Definition: Function.hpp:34
void scaleY(double s)
Scale the y axis by s.
Definition: Function.hpp:57
double shiftX() const
Get the current x axis shift.
Definition: Function.hpp:89
void scaleX(double s)
Scale the x axis by s.
Definition: Function.hpp:50
This namespace contains all the API of MorphoGraphX.
Definition: Assert.hpp:26
double shiftY() const
Get the current y axis shift.
Definition: Function.hpp:93
double scaleY() const
Get the current y scaling.
Definition: Function.hpp:65
void shiftX(double s)
Shift the x axis by s.
Definition: Function.hpp:75
Defines the Vector class template This file is shared by cuda, do not include headers that nvcc can&#39;t...