A.I.M.S algorithms


splineresampler.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 #ifndef AIMS_RESAMPLING_SPLINERESAMPLER_H
36 #define AIMS_RESAMPLING_SPLINERESAMPLER_H
37 
39 #include <cstdlib>
40 #include <cmath>
41 
71 template <class T>
72 class SplineResampler : public Resampler< T >
73 {
74 public:
75 
78 
80  virtual int getOrder() const = 0;
81 
101  int t = 0,
102  bool verbose = false );
103 
108  void reset();
109 
110 protected:
111 
119  void doResample( const AimsData< T > &inVolume,
120  const Motion &transform3d,
121  const T &outBackground,
122  const Point3df &outLocation,
123  T &outValue,
124  int t );
125 
127  void updateParameters( const AimsData< T >& inVolume, int t,
128  bool verbose );
129  void iirConvolveMirror( std::vector< double >& data ) const;
130 
131  // This method returns a mirror index when needed
132  //
133  // Only inVolume's size spline coefficient are computed since "outside"
134  // coefficients are equal to their mirror inside the image domain.
135  // This method computes this mirror correspondance.
136  //
137  // - If i is in [0, size-1]: returns i
138  // - If i < 0: returns -1
139  // - If i >= size: returns size - (i - size) - 2
140  int getFold( int i, int size ) const;
141 
145  virtual double getBSplineWeight( int i, double x ) const = 0;
146 
147  std::vector<double> _poles;
148  double _gain;
152 };
153 
154 namespace aims {
155 
156  // This method returns a mirror index when needed
157  //
158  // Only inVolume's size spline coefficient are computed since "outside"
159  // coefficients are equal to their mirror inside the image domain.
160  // This method computes this mirror correspondance.
161  //
162  // - If i is in [0, size-1]: returns i
163  // - If i < 0: returns -1
164  // - If i >= size: returns size - (i - size) - 2
165  inline int mirrorCoeff( int i, int size )
166  {
167  i = std::abs( i );
168  if ( i < size )
169  {
170 
171  return i;
172 
173  }
174  if ( size == 1 )
175  {
176 
177  return 0;
178 
179  }
180  int size2 = ( size << 1 ) - 2;
181  ldiv_t modOp = std::ldiv( i, size2 );
182  return ( modOp.rem < size ) ? modOp.rem : ( size2 - modOp.rem );
183  }
184 
185 } // namespace aims
186 
187 #endif
188 
int getFold(int i, int size) const
void iirConvolveMirror(std::vector< double > &data) const
virtual double getBSplineWeight(int i, double x) const =0
Returns B^n( x - i )
Resampler resamples an input data to build or fill an output data, using an affine transformation...
Definition: resampler.h:52
AimsData< double > getSplineCoef(const AimsData< T > &inVolume, int t=0, bool verbose=false)
Computes spline coefficients corresponding to an input volume.
void updateParameters(const AimsData< T > &inVolume, int t, bool verbose)
B-Spline-based resampling.
virtual int getOrder() const =0
Spline order (1 to 7)
void doResample(const AimsData< T > &inVolume, const Motion &transform3d, const T &outBackground, const Point3df &outLocation, T &outValue, int t)
Resample a point.
const AimsData< T > * _lastvolume
void reset()
Clear the cache.
std::vector< double > _poles
AimsData< double > _splineCoefficients