aimsalgo  5.1.2
Neuroimaging image processing
nearestneighborresampler_d.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_NEARESTNEIGHBORRESAMPLER_D_H
36 #define AIMS_RESAMPLING_NEARESTNEIGHBORRESAMPLER_D_H
37 
39 
40 #include <cmath>
41 
42 using namespace std;
43 
44 namespace aims
45 {
46 
47 template <class T>
48 void
50  const soma::Transformation3d &invTransform3d,
51  const T &outBackground,
52  const Point3df &outLocation,
53  T &outValue, int t ) const
54 {
55 
56  Point3df inLocation = invTransform3d.transform( outLocation );
57 
58  doResample(inVolume, inLocation, outBackground, outValue, t);
59 }
60 
61 template <class T>
62 void
64  const Point3df &inLocation,
65  const T &outBackground,
66  T &outValue, int t ) const
67 {
68  float xf = round(inLocation[0]);
69  float yf = round(inLocation[1]);
70  float zf = round(inLocation[2]);
71 
72  std::vector<int> dims = inVolume.getSize();
73 
74  // The test is done using floating-point so that NaN values are excluded (the
75  // background value is returned if the transformation yields NaN)
76  if ( ( xf >= 0 ) && ( xf < dims[0] ) &&
77  ( yf >= 0 ) && ( yf < dims[1] ) &&
78  ( zf >= 0 ) && ( zf < dims[2] ) )
79  {
80  int x = static_cast<int>(xf);
81  int y = static_cast<int>(yf);
82  int z = static_cast<int>(zf);
83  outValue = inVolume.at( x, y, z, t );
84  }
85  else
86  {
87  outValue = outBackground;
88  }
89 
90 }
91 
92 } // namespace aims
93 
94 #endif
Volume resampler using nearest-neighbour interpolation.
std::vector< int > getSize() const
const T & at(long x, long y=0, long z=0, long t=0) const
Point3dd transform(double x, double y, double z) const