aimsalgo 6.0.0
Neuroimaging image processing
linearresampler_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_LINEARRESAMPLER_D_H
36#define AIMS_RESAMPLING_LINEARRESAMPLER_D_H
37
39
40#include <cartobase/type/converter.h>
41
42#include <cmath>
43
44namespace aims
45{
46
47template < class T >
52
53
54template < class T >
58
59
60template < class T >
62{
63
64 return 1;
65
66}
67
68
69template < class T >
72 const soma::Transformation3d& invTransform3d,
73 const ChannelType& outBackground,
74 const Point3df& outLocation,
75 ChannelType& outValue, int t ) const
76{
77
78 const ChannelType *i = &inVolume.at( 0, 0, 0, t );
79 const ChannelType *pi, *pj;
80
81 Point3df normalizedInLocation;
82 normalizedInLocation = invTransform3d.transform( outLocation );
83
84 float xf = round(normalizedInLocation[0]);
85 float yf = round(normalizedInLocation[1]);
86 float zf = round(normalizedInLocation[2]);
87
88 std::vector<int> dims = inVolume.getSize();
89 int dimx = dims[0], dimy = dims[1], dimz = dims[2];
90
91 // The test is done using floating-point so that NaN values are excluded (the
92 // background value is returned if the transformation yields NaN)
93 if ( ( xf >= 0 ) && ( xf < dimx ) &&
94 ( yf >= 0 ) && ( yf < dimy ) &&
95 ( zf >= 0 ) && ( zf < dimz ) )
96 {
97
98 double weightX0, weightY0, weightX1, weightY1;
99 long foldX0, foldY0, foldX1, foldY1;
100 double intensity, qi, qj;
101
102 // first y contribution
103 int y = static_cast<long>(floor(normalizedInLocation[1]));
104 weightY0 = getBSplineWeight( y, normalizedInLocation[1] );
105 foldY0 = (long)this->getFold( y, dims[1] ) * dims[0];
106
107 // second y contribution
108 ++ y;
109 weightY1 = getBSplineWeight( y, normalizedInLocation[1] );
110 foldY1 = (long)this->getFold( y, dimy ) * dimx;
111
112 // first x contribution
113 int x = static_cast<long>(floor(normalizedInLocation[0]));
114 weightX0 = getBSplineWeight( x, normalizedInLocation[0] );
115 foldX0 = (long)this->getFold( x, dimx );
116
117 // second x contribution
118 ++ x;
119 weightX1 = getBSplineWeight( x, normalizedInLocation[0] );
120 foldX1 = (long)this->getFold( x, dimx );
121
122 if ( dimz == 1 )
123 {
124
125 //summing contributions
126 pj = i;
127 pi = pj + (size_t)(foldY0);
128 qi = weightX0 * ( double )*( pi + (size_t)(foldX0) );
129 qi += weightX1 * ( double )*( pi + size_t(foldX1) );
130 qj = weightY0 * qi;
131 pi = pj + foldY1;
132 qi = weightX0 * ( double )*( pi + (size_t)(foldX0) );
133 qi += weightX1 * ( double )*( pi + (size_t)(foldX1) );
134 intensity = qj + weightY1 * qi;
135
136 }
137 else
138 {
139
140 // first z contribution
141 int z = static_cast<long>(floor(normalizedInLocation[2]));
142 pj = i + (size_t)(this->getFold( z, dimz )) * dimx *
143 dimy;
144 pi = pj + (size_t)(foldY0);
145 qi = weightX0 * ( double )*( pi + (size_t)(foldX0) );
146 qi += weightX1 * ( double )*( pi + (size_t)(foldX1) );
147 qj = weightY0 * qi;
148 pi = pj + (size_t)foldY1;
149 qi = weightX0 * ( double )*( pi + (size_t)(foldX0) );
150 qi += weightX1 * ( double )*( pi + (size_t)(foldX1) );
151 qj += weightY1 * qi;
152 intensity = getBSplineWeight( z, normalizedInLocation[2] ) * qj;
153
154 // first z contribution
155 ++ z;
156 pj = i + (size_t)(this->getFold( z, dimz )) * dimx *
157 dimy;
158 pi = pj + (size_t)(foldY0);
159 qi = weightX0 * ( double )*( pi + (size_t)(foldX0) );
160 qi += weightX1 * ( double )*( pi + (size_t)(foldX1) );
161 qj = weightY0 * qi;
162 pi = pj + (size_t)(foldY1);
163 qi = weightX0 * ( double )*( pi + (size_t)(foldX0) );
164 qi += weightX1 * ( double )*( pi + (size_t)(foldX1) );
165 qj += weightY1 * qi;
166 intensity += getBSplineWeight( z, normalizedInLocation[2] ) * qj;
167 }
168
170
171 }
172 else
173 {
174
175 outValue = outBackground;
176
177 }
178
179}
180
181template < class T >
182double LinearResampler< T >::getBSplineWeight( int i, double x ) const
183{
184
185 x = fabs( x - ( double )i );
186 return ( x > 1.0 ) ? 0.0 : 1.0 - x;
187
188}
189
190} // namespace aims
191
192#endif
double getBSplineWeight(int i, double x) const CARTO_OVERRIDE
Returns .
int getOrder() const CARTO_OVERRIDE
Spline order (1 to 7)
SplineResampler< T >::ChannelType ChannelType
void doResampleChannel(const carto::Volume< ChannelType > &inVolume, const soma::Transformation3d &transform3d, const ChannelType &outBackground, const Point3df &outLocation, ChannelType &outValue, int t) const CARTO_OVERRIDE
int getFold(int i, int size) const
This method returns a mirror index when needed.
void convert(const INP &in, OUTP &out) const
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
AimsVector< float, 3 > Point3df