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