aimsalgo  5.0.5
Neuroimaging image processing
tabulSpline.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 
36 #ifndef AIMS_FFD_TABULSPLINE_H
37 #define AIMS_FFD_TABULSPLINE_H
38 #include <cstdlib>
40 #include <aims/vector/vector.h>
41 #include <aims/data/data_g.h>
42 #include <aims/math/bspline3.h>
43 #include <aims/math/bspline2.h>
44 
45 
47 {
48  public:
49  TabulSpline( std::string name, int order = 3, int length = 65537, int factor = 2);
50  virtual ~TabulSpline();
51 
52  int index( double u ) const;
53  bool isvalid( int index ) const;
54  int getFactor() const;
55  int getTabLength() const;
56  float spline3( double ) const;
57  float spline3derivative( double ) const;
58  float dump( int i ) const {return _splineCoef[i];}
59 
60  private:
61  std::string _name;
62 
63  int _factor;
64  int _splineTabLength;
65  float *_splineCoef;
66  float *_derivatedSplineCoef ;
67 };
68 
69 inline int
71 {
72  return _splineTabLength;
73 }
74 
75 inline int
77 {
78  return _factor;
79 }
80 
81 inline int
82 TabulSpline::index( double u ) const
83 {
84  return (int)( fabs(u) * (_splineTabLength - 1) / _factor );
85 }
86 
87 inline bool
89 {
90  return ( index >= 0 && index < _splineTabLength );
91 }
92 
93 inline float
94 TabulSpline::spline3( double u ) const
95 {
96  int i = index(u);
97 
98  if ( !isvalid( i ) ){
99  cartoDbgMsg( 1, "Spline3 : Index " + carto::toString(i)
100  + " corresponding to parameter " + carto::toString(u)
101  + " out of tabulspline : " + carto::toString(_splineTabLength));
102  return 0. ;
103  }
104  return _splineCoef[ i ] ;
105 }
106 
107 
108 inline float
110 {
111  int i = index(u);
112  if ( !isvalid( i ) ) {
113  cartoDbgMsg( 1, "Spline3 derivatives : Index " + carto::toString(i)
114  + " corresponding to parameter " + carto::toString(u)
115  + " out of tabulspline : " + carto::toString(_splineTabLength));
116  return 0. ;
117  }
118 
119  if (u > 0.0)
120  return _derivatedSplineCoef[ i ];
121  else
122  return(- _derivatedSplineCoef[ i ]);
123 }
124 
125 #endif
int index(double u) const
Definition: tabulSpline.h:82
bool isvalid(int index) const
Definition: tabulSpline.h:88
float dump(int i) const
Definition: tabulSpline.h:58
float spline3(double) const
Definition: tabulSpline.h:94
int getFactor() const
Definition: tabulSpline.h:76
TabulSpline(std::string name, int order=3, int length=65537, int factor=2)
std::string toString(const T &object)
virtual ~TabulSpline()
int getTabLength() const
Definition: tabulSpline.h:70
float spline3derivative(double) const
Definition: tabulSpline.h:109
#define cartoDbgMsg(level, message)