Linear Methods for Image Interpolation
adaptlob.c
Go to the documentation of this file.
00001 
00016 #include <stdlib.h>
00017 #include <stdio.h>
00018 #include <math.h>
00019 
00020 #define MACHINE_PRECISION   2.2204e-16
00021 
00022 #define ALPHA   0.816496580927726
00023 #define BETA    0.447213595499958
00024 
00025 
00026 static int Termination2;
00027 
00028 static double AdaptLobStep(float (*f)(float, const void*), double a, double b,
00029     double fa, double fb, double Tol, double hmin, const void *Param);
00030 
00031 
00043 float AdaptLob(float (*f)(float, const void*), float a, float b,
00044     float Tol, const void *Param)
00045 {
00046     Termination2 = 0;
00047     return (float)AdaptLobStep(f, a, b, f(a, Param), f(b, Param),
00048         Tol, MACHINE_PRECISION*(b - a)/1024.0, Param);
00049 }
00050 
00051 
00052 static double AdaptLobStep(float (*f)(float, const void*), double a, double b,
00053     double fa, double fb, double Tol, double hmin, const void *Param)
00054 {
00055     double m, h, Q, fmll, fml, fm, fmr, fmrr;
00056 
00057 
00058     m = 0.5*(a + b);
00059     h = 0.5*(b - a);
00060 
00061     if(h < hmin || m == a || m == b)
00062     {
00063         if(Termination2 == 0)
00064         {
00065             fprintf(stderr, "Minimum step size reached.\n");
00066             Termination2 = 1;
00067         }
00068 
00069         return h*(fa + fb);
00070     }
00071 
00072     fmll = f(m - ALPHA*h, Param);
00073     fml = f(m - BETA*h, Param);
00074     fm = f(m, Param);
00075     fmr = f(m + BETA*h, Param);
00076     fmrr = f(m + ALPHA*h, Param);
00077     Q = (h/1470.0)*(77.0*(fa + fb) + 432.0*(fmll + fmrr)
00078         + 625.0*(fml + fmr) + 672.0*fm);
00079 
00080     if(fabs(Q - (h/6.0)*(fa + fb + 5.0*(fml + fmr))) <= Tol)
00081         return Q;
00082     else        /* Accumulate in double precision */
00083         return (double)AdaptLobStep(f, a, m - ALPHA*h, fa, fmll, Tol, hmin, Param)
00084             + (double)AdaptLobStep(f, m - ALPHA*h, m - BETA*h, fmll, fml, Tol, hmin, Param)
00085             + (double)AdaptLobStep(f, m - BETA*h, m, fml, fm, Tol, hmin, Param)
00086             + (double)AdaptLobStep(f, m, m + BETA*h, fm, fmr, Tol, hmin, Param)
00087             + (double)AdaptLobStep(f, m + BETA*h, m + ALPHA*h, fmr, fmrr, Tol, hmin, Param)
00088             + (double)AdaptLobStep(f, m + ALPHA*h, b, fmrr, fb, Tol, hmin, Param);
00089 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines