Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Related Pages

CachedFunction1D.h

00001 #ifndef CACHEDFUNCTION1D_H
00002 #define CACHEDFUNCTION1D_H
00003 
00004 #include <iostream>
00005 #include <cmath>
00006 using namespace std;
00007 
00008 
00009 namespace SctData{
00010 
00017     class CachedFunction1D{
00018     public:
00028     CachedFunction1D(double min, double max, double delta, double (*function)(double) ) throw() ;
00032     ~CachedFunction1D() throw() ;
00040     inline double eval(double x) const throw() ;
00041     private:
00043     CachedFunction1D() throw() ;
00045     CachedFunction1D& operator=(const CachedFunction1D&) throw() ;
00046     void makeTable() throw();    
00047     double min;                  
00048     double max;                  
00049     double delta;                
00050     double invdelta;             
00051     int nvalue;                  
00052     double * values;             
00053     double (*function) (double); 
00054     };
00055     
00056 // inline function
00057     double CachedFunction1D::eval(double x) const throw() {
00058     /*
00059     int ipos=(int)((x-min)*invdelta);
00060     if (ipos<0)            { return values[0];        }
00061     else if (ipos>=nvalue) { return values[nvalue-1]; }
00062     else                   { return values[ipos];     }
00063     */
00064     double pos = (x-min)*invdelta;
00065     int ipos=(int)(pos);
00066     if (ipos<0)            { return values[0];        }
00067     else if (ipos>=nvalue-1) { return values[nvalue-1]; }
00068     //interpolate
00069     double frac = pos - ipos;   
00070     double y1 = values[ipos];
00071     double y2 = values[ipos+1];
00072     //double x1 = ipos * delta + min;
00073     //double x2 = (ipos+1) * delta + min;
00074     //cout << x1 << "  "<< x2 << " "  << y1 << "  " << y2 << "  " << x << "  " << pos << "   " << ipos << "  " << frac << "  " << (x-x1)/(x2-x1) << endl;
00075     return y1 + (y2-y1) * frac;
00076     }
00077 
00078 }
00079 
00080 
00081 
00082 #endif // #ifndef CACHEDFUNCTION_H

Generated on Thu Jul 15 09:50:43 2004 for SCT DAQ/DCS Software - C++ by doxygen 1.3.5