aimsalgo  5.1.2
Neuroimaging image processing
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 
40 
41 #include <cmath>
42 #include <vector>
43 
44 namespace aims
45 {
46 
47 // This implementation helper allows to change the implementation of methods
48 // depending if the data type is single-channel or multi-channel.
49 template<bool, typename>
51 
52 
87 template <class T>
88 class SplineResampler : public Resampler< T >
89 {
90 public:
91 
94 
96  virtual int getOrder() const = 0;
97 
118  int t = 0,
119  bool verbose = false );
120 
125  void reset();
126 
127  // Overridden for performance in case of multi-channel data
128  void resample_inv_to_vox( const carto::Volume< T >& input_data,
130  inverse_transform_to_vox,
131  const T& background,
132  carto::Volume< T > & output_data,
133  bool verbose = false ) const CARTO_OVERRIDE;
134  using Resampler<T>::resample_inv_to_vox;
135 
136  // Implements iteration over channels for multi-channel data types
137  template<bool, typename> friend struct MultiChannelResamplerSwitch;
138 
139  typedef typename carto::DataTypeTraits<T>::ChannelType ChannelType;
140 
142  const carto::Volume< ChannelType >& inVolume,
143  const soma::Transformation3d& inverse_transform_to_vox,
144  const ChannelType& outBackground,
145  carto::Volume< ChannelType > & outVolume,
146  bool verbose) const;
147 protected:
148 
149  void doResample( const carto::Volume< T > &inVolume,
150  const soma::Transformation3d &transform3d,
151  const T &outBackground,
152  const Point3df &outLocation,
153  T &outValue,
154  int t ) const CARTO_OVERRIDE;
155 
156  virtual void doResampleChannel( const carto::Volume< ChannelType > &inVolume,
157  const soma::Transformation3d &transform3d,
158  const ChannelType &outBackground,
159  const Point3df &outLocation,
160  ChannelType &outValue,
161  int t ) const;
162 
167  void updateParameters( const carto::Volume< T >& inVolume, int t,
168  bool verbose ) const CARTO_OVERRIDE;
169  virtual void updateParametersChannel( const carto::Volume< ChannelType >& inVolume, int t,
170  bool verbose ) const;
171  void iirConvolveMirror( std::vector< double >& data ) const;
172 
182  int getFold( int i, int size ) const;
183 
187  virtual double getBSplineWeight( int i, double x ) const = 0;
188 
189  std::vector<double> _poles;
190  double _gain;
191 
192  // These three mutable members handle the cache of spline coefficients
193  mutable carto::VolumeRef<double> _splineCoefficients;
194  mutable const carto::Volume<ChannelType> * _lastvolume;
195  mutable int _lasttime;
196 };
197 
198 
209  inline int mirrorCoeff( int i, int size )
210  {
211  i = std::abs( i );
212  if ( i < size )
213  {
214 
215  return i;
216 
217  }
218  if ( size == 1 )
219  {
220 
221  return 0;
222 
223  }
224  int size2 = ( size * 2 ) - 2;
225  int rem = i % size2;
226  return ( rem < size ) ? rem : ( size2 - rem );
227  }
228 
229 } // namespace aims
230 
231 #endif
Resampling of data from a volume, applying a transformation.
Definition: resampler.h:76
B-Spline-based resampling.
std::vector< double > _poles
const carto::Volume< ChannelType > * _lastvolume
void doResample(const carto::Volume< T > &inVolume, const soma::Transformation3d &transform3d, const T &outBackground, const Point3df &outLocation, T &outValue, int t) const CARTO_OVERRIDE
Resample a volume at a single location.
void reset()
Clear the cache.
carto::VolumeRef< double > getSplineCoef(const carto::Volume< T > &inVolume, int t=0, bool verbose=false)
Computes spline coefficients corresponding to an input volume.
void resample_inv_to_vox(const carto::Volume< T > &input_data, const soma::Transformation3d &inverse_transform_to_vox, const T &background, carto::Volume< T > &output_data, bool verbose=false) const CARTO_OVERRIDE
Resample a volume into an existing output volume.
virtual int getOrder() const =0
Spline order (1 to 7)
virtual double getBSplineWeight(int i, double x) const =0
Returns .
int getFold(int i, int size) const
This method returns a mirror index when needed.
virtual void updateParametersChannel(const carto::Volume< ChannelType > &inVolume, int t, bool verbose) const
virtual void doResampleChannel(const carto::Volume< ChannelType > &inVolume, const soma::Transformation3d &transform3d, const ChannelType &outBackground, const Point3df &outLocation, ChannelType &outValue, int t) const
void resample_channel_inv_to_vox(const carto::Volume< ChannelType > &inVolume, const soma::Transformation3d &inverse_transform_to_vox, const ChannelType &outBackground, carto::Volume< ChannelType > &outVolume, bool verbose) const
carto::VolumeRef< double > _splineCoefficients
void iirConvolveMirror(std::vector< double > &data) const
void updateParameters(const carto::Volume< T > &inVolume, int t, bool verbose) const CARTO_OVERRIDE
Update the cache of spline coefficients if needed.
int mirrorCoeff(int i, int size)
This method returns a mirror index when needed.