00001 #ifndef Impala_Visualisation_Plot_Function_h
00002 #define Impala_Visualisation_Plot_Function_h
00003
00004 #include "Visualization/Plot/Plottable.h"
00005
00006 namespace Impala
00007 {
00008 namespace Visualization
00009 {
00010 namespace Plot
00011 {
00012
00013 class Weibull : public Plottable
00014 {
00015 public:
00016
00017 Weibull(double z, double beta, double gamma, int sampleCount=100)
00018 {
00019 mBeta = beta;
00020 mGamma = gamma;
00021 mSampleCount = sampleCount;
00022 mZ = z;
00023 ComputeScaling();
00024 }
00025
00026 virtual void
00027 Draw(Plot* plot)
00028 {
00029 double l,t,r,b;
00030 plot->GetRange(l,t,r,b);
00031 double dx=(r-l)/mSampleCount;
00032
00033 SelectColor();
00034
00035 BeginSampling();
00036 glBegin(GL_LINE_STRIP);
00037 for (double x=mMinX ; x<mMaxX ; x+=dx)
00038 glVertex3d(x, Sample(x), mZ);
00039 glEnd();
00040 EndSampling();
00041 }
00042
00043 virtual void
00044 BeginSampling()
00045 {
00046 }
00047
00048 virtual double
00049 Sample(double x)
00050 {
00051 return exp(-pow(fabs((x-mMu)/mBeta), mGamma)) * mScaling;
00052 }
00053
00054 virtual void
00055 EndSampling()
00056 {
00057 }
00058
00059 void
00060 SetParams(double beta, double gamma, double mu)
00061 {
00062
00063 mBeta = beta;
00064 mGamma = gamma;
00065 mMu = mu;
00066 ComputeScaling();
00067 }
00068
00069 double
00070 GetParams(double& beta, double& gamma, double& mu)
00071 {
00072 beta = mBeta;
00073 gamma = mGamma;
00074 mu = mMu;
00075 }
00076
00077 protected:
00078
00079 int mSampleCount;
00080 double mZ;
00081 double mBeta, mGamma, mMu;
00082 double mScaling;
00083
00084 void
00085 ComputeScaling()
00086 {
00087
00088
00089
00090
00091 mScaling = mGamma;
00092 mScaling /= 2.*mBeta*pow(mGamma,1./mGamma)*GammaFunc(1./mGamma);
00093 SetDimensionsY(0, mScaling);
00094 }
00095
00096 double
00097 GammaFunc(double xx)
00098 {
00099
00100
00101 double x,y,tmp,ser;
00102 static double cof[6] =
00103 {
00104 76.18009172947146, -86.50532032941677,
00105 24.01409824083091, -1.231739572450155,
00106 0.1208650973866179e-2, -0.5395239384953e-5
00107 };
00108
00109 int j;
00110 y=x=xx;
00111 tmp=x+5.5;
00112 tmp -= (x+0.5)*log(tmp);
00113 ser=1.000000000190015;
00114 for (j=0;j<=5;j++)
00115 ser += cof[j]/++y;
00116 xx = -tmp+log(2.5066282746310005*ser/x);
00117 return exp(xx);
00118 }
00119
00120 };
00121
00122 }
00123 }
00124 }
00125
00126 #endif Impala_Visualisation_Plot_Function_h