aimsdata  5.0.5
Neuroimaging data handling
lagrange.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * Lagrange's interpolation.
36  */
37 #ifndef AIMS_MATH_LAGRANGE_H
38 #define AIMS_MATH_LAGRANGE_H
39 
40 #include <cstdlib>
42 #include <aims/data/data.h>
43 #include <math.h>
44 
45 namespace aims {
46 
47 
53 template <class REAL>
56  const AimsData<REAL> &ya,
57  REAL x, REAL *dy )
58 
59 
60 {
61  int i,m,ns=0,n=std::min(xa.dimX(),ya.dimX());
62  REAL den,dif,dift,ho,hp,w;
63  REAL *c, *d, y;
64 
65  dif = fabs(x-xa(0));
66  c = new float[n];
67  d = new float[n];
68 
69  for (i=0;i<n;i++) {
70  if ((dift = fabs(x-xa(i))) < dif) {
71  ns = i;
72  dif = dift;
73  }
74  c[i] = ya(i);
75  d[i] = ya(i);
76  }
77 
78  y = ya(ns--);
79  for (m=1;m<n;m++){
80  for (i=0;i<n-m;i++){
81  ho = xa(i) - x;
82  hp = xa(i+m) - x;
83  w = c[i+1] - d[i];
84  ASSERT( (den = ho - hp) != 0.0 );
85  den = w / den;
86  d[i] = hp * den;
87  c[i] = ho * den;
88  }
89  y += (*dy=(2*ns+2 < (n-m) ? c[ns+1] : d[ns--]));
90  }
91  delete [] c;
92  delete [] d;
93  return y;
94 }
95 
96 // for backward compatibility
98  const AimsData<float> &ya,
99  float x, float *dy )
100 {
101  return AimsLagrangeInterpolationOf<float>( xa, ya, x, dy );
102 }
103 
104 } // namespace aims
105 
106 #endif
#define AIMSDATA_API
AIMSDATA_API REAL AimsLagrangeInterpolationOf(const AimsData< REAL > &xa, const AimsData< REAL > &ya, REAL x, REAL *dy)
Returns the interpolation of a function defined at (xa,ya) points at x (dy is the error) ...
Definition: lagrange.h:55
float AimsLagrangeInterpolation(const AimsData< float > &xa, const AimsData< float > &ya, float x, float *dy)
Definition: lagrange.h:97
The class for EcatSino data write operation.
Definition: border.h:44
#define ASSERT(EX)
int dimX() const