Linear Methods for Image Interpolation
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
adaptlob.c
Go to the documentation of this file.
1 
16 #include <stdlib.h>
17 #include <stdio.h>
18 #include <math.h>
19 
20 #define MACHINE_PRECISION 2.2204e-16
21 
22 #define ALPHA 0.816496580927726
23 #define BETA 0.447213595499958
24 
25 
26 static int Termination2;
27 
28 static double AdaptLobStep(float (*f)(float, const void*), double a, double b,
29  double fa, double fb, double Tol, double hmin, const void *Param);
30 
31 
43 float AdaptLob(float (*f)(float, const void*), float a, float b,
44  float Tol, const void *Param)
45 {
46  Termination2 = 0;
47  return (float)AdaptLobStep(f, a, b, f(a, Param), f(b, Param),
48  Tol, MACHINE_PRECISION*(b - a)/1024.0, Param);
49 }
50 
51 
52 static double AdaptLobStep(float (*f)(float, const void*), double a, double b,
53  double fa, double fb, double Tol, double hmin, const void *Param)
54 {
55  double m, h, Q, fmll, fml, fm, fmr, fmrr;
56 
57 
58  m = 0.5*(a + b);
59  h = 0.5*(b - a);
60 
61  if(h < hmin || m == a || m == b)
62  {
63  if(Termination2 == 0)
64  {
65  fprintf(stderr, "Minimum step size reached.\n");
66  Termination2 = 1;
67  }
68 
69  return h*(fa + fb);
70  }
71 
72  fmll = f(m - ALPHA*h, Param);
73  fml = f(m - BETA*h, Param);
74  fm = f(m, Param);
75  fmr = f(m + BETA*h, Param);
76  fmrr = f(m + ALPHA*h, Param);
77  Q = (h/1470.0)*(77.0*(fa + fb) + 432.0*(fmll + fmrr)
78  + 625.0*(fml + fmr) + 672.0*fm);
79 
80  if(fabs(Q - (h/6.0)*(fa + fb + 5.0*(fml + fmr))) <= Tol)
81  return Q;
82  else /* Accumulate in double precision */
83  return (double)AdaptLobStep(f, a, m - ALPHA*h, fa, fmll, Tol, hmin, Param)
84  + (double)AdaptLobStep(f, m - ALPHA*h, m - BETA*h, fmll, fml, Tol, hmin, Param)
85  + (double)AdaptLobStep(f, m - BETA*h, m, fml, fm, Tol, hmin, Param)
86  + (double)AdaptLobStep(f, m, m + BETA*h, fm, fmr, Tol, hmin, Param)
87  + (double)AdaptLobStep(f, m + BETA*h, m + ALPHA*h, fmr, fmrr, Tol, hmin, Param)
88  + (double)AdaptLobStep(f, m + ALPHA*h, b, fmrr, fb, Tol, hmin, Param);
89 }