function.h
Go to the documentation of this file.00001 #ifndef __UTIL__FUNCTION_HPP__
00002 #define __UTIL__FUNCTION_HPP__
00003
00009 #include <config.h>
00010
00011 #include <string>
00012 #include <vector>
00013 #include <util/watchdog.h>
00014 #include <util/vector.h>
00015
00016 namespace util {
00024 class Function : public FileObject {
00025 public:
00026 Function();
00027 Function(std::string filename);
00028 Function(const Function& copy);
00029 Function& operator=(const Function&);
00030 #ifdef USE_CXX0X
00031 Function(Function&& copy) = default;
00032 Function& operator=(Function&&) = default;
00033 #endif
00034 double operator()(double x);
00035 const util::Vector<2,double>& getMax() const;
00036 const util::Vector<2,double>& getMin() const;
00037 void reread();
00038 void setSamples (size_t n);
00039 bool error();
00044 void scaleX(double s) { scaling_x = 1/s; }
00049 void scaleY(double s) { scaling_y = s; }
00051 double scaleX() const { return 1/scaling_x; }
00053 double scaleY() const { return scaling_y; }
00061 void shiftX(double s) { shift_x = -s; }
00069 void shiftY(double s) { shift_y = s; }
00071 double shiftX() const { return -shift_x; }
00073 double shiftY() const { return shift_y; }
00074 void normalizeY(bool shift = true);
00075 void normalizeX(bool shift = true);
00076
00077 private:
00078 std::vector<util::Vector<2,double> > pts;
00079 util::Vector<2,double> max;
00080 util::Vector<2,double> min;
00081 unsigned int samples;
00082 double scaling_x, scaling_y;
00083 double shift_x, shift_y;
00084
00085 util::Vector<2,double> P(double x) const;
00086 double N(int, int, double) const;
00087 double Nk1(int, double) const;
00088 double Nkt(int, int, double) const;
00089 int Uk(int) const;
00090 double getVal(double x) const;
00091
00092 struct CacheVal {
00093 bool valid;
00094 double val;
00095 };
00096 bool cache_valid;
00097 std::vector <CacheVal> cache;
00098 void init();
00099 bool error_occured;
00100 };
00101 }
00102
00103 #endif