51 const T&background, T* out,
60 void MaskLinearResampler<T>::
65 T &output_value,
int t )
const 69 float xf = std::floor(input_location[0]);
70 float yf = std::floor(input_location[1]);
71 float zf = std::floor(input_location[2]);
73 std::vector<int> dims = input_data.
getSize();
77 if ( ( xf >= 0 ) && ( xf < dims[0] ) &&
78 ( yf >= 0 ) && ( yf < dims[1] ) &&
79 ( zf >= 0 ) && ( zf < dims[2] ) )
81 int x =
static_cast<int>(xf);
82 int y =
static_cast<int>(yf);
83 int z =
static_cast<int>(zf);
85 if (input_data.
at(x, y, z, t) == -32768 ||
86 input_data.
at(x + 1, y, z, t) == -32768 ||
87 input_data.
at(x, y + 1, z, t) == -32768 ||
88 input_data.
at(x + 1, y + 1, z, t) == -32768 ||
89 input_data.
at(x, y, z + 1, t) == -32768 ||
90 input_data.
at(x + 1, y, z + 1, t) == -32768 ||
91 input_data.
at(x, y + 1, z + 1, t) == -32768 ||
92 input_data.
at(x + 1, y + 1, z + 1, t) == -32768)
94 output_value = -32768;
97 _linearresampler.resample_inv_to_vox(input_data, inverse_transform,
98 background, output_location,
102 output_value = background;
125 dirMotion.scale( sizeFrom, sizeTo );
126 invMotion.
scale( sizeTo, sizeFrom );
130 T* it = &thing.
at( 0 );
134 std::cout <<
"Resampling volume [ 1] / slice [ 1]" << std::flush;
137 for (
int t = 1; t <= dimt; t++ )
140 for (
int s = 1; s <= dimz; s++ )
143 std::cout <<
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" 144 << std::setw( 3 ) << t <<
"] / slice [" 145 << std::setw( 3 ) << s <<
"]" << std::flush;
148 _sliceResamp( input_data, thing, background, it, start, t - 1,
150 it = &thing.
at( 0, 0, s, t - 1 );
151 start[ 0 ] += invMotion.
rotation()( 0, 2 );
152 start[ 1 ] += invMotion.
rotation()( 1, 2 );
153 start[ 2 ] += invMotion.
rotation()( 2, 2 );
157 std::cout << std::endl;
169 const T& background, T* out,
174 "the optimizations need at least 32-bit int");
176 const T* pOrig = &input_data.
at( 0, 0, 0, t );
182 const int SIXTEEN = 16;
183 const int TWO_THEN_SIXTEEN = 65536;
185 int maxX = TWO_THEN_SIXTEEN * ( dimX1 - 1 );
186 int maxY = TWO_THEN_SIXTEEN * ( input_data.
getSizeY() - 1 );
187 int maxZ = TWO_THEN_SIXTEEN * ( input_data.
getSizeZ() - 1 );
189 int xLinCurrent = ( int )( 65536.0 * start[ 0 ] );
190 int yLinCurrent = ( int )( 65536.0 * start[ 1 ] );
191 int zLinCurrent = ( int )( 65536.0 * start[ 2 ] );
193 int xu = ( int )( 65536.0 * Rinv( 0, 0 ) );
194 int yu = ( int )( 65536.0 * Rinv( 1, 0 ) );
195 int zu = ( int )( 65536.0 * Rinv( 2, 0 ) );
196 int xv = ( int )( 65536.0 * Rinv( 0, 1 ) );
197 int yv = ( int )( 65536.0 * Rinv( 1, 1 ) );
198 int zv = ( int )( 65536.0 * Rinv( 2, 1 ) );
200 int xCurrent, yCurrent, zCurrent;
203 long incr_vois[8] = {
206 &input_data.
at( 0, 1, 0 ) - &input_data.
at( 0 ),
207 &input_data.
at( 0, 1, 0 ) - &input_data.
at( 0 ),
208 &input_data.
at( 0, 0, 1 ) - &input_data.
at( 0 ),
209 &input_data.
at( 1, 0, 1 ) - &input_data.
at( 0 ),
210 &input_data.
at( 1, 1, 1 ) - &input_data.
at( 0 ),
211 &input_data.
at( 0, 1, 1 ) - &input_data.
at( 0 )
213 float stock1, stock2, stock3;
214 for (
int v = dimY2; v--; )
216 xCurrent = xLinCurrent;
217 yCurrent = yLinCurrent;
218 zCurrent = zLinCurrent;
220 for (
int u = dimX2; u--; )
222 if ( xCurrent >= 0 && xCurrent < maxX &&
223 yCurrent >= 0 && yCurrent < maxY &&
224 zCurrent >= 0 && zCurrent < maxZ )
226 dx = xCurrent & 0xffff;
227 dy = yCurrent & 0xffff;
228 dz = zCurrent & 0xffff;
230 it = pOrig + ( zCurrent >> SIXTEEN ) * incr_vois[4]
231 + ( yCurrent >> SIXTEEN ) * dimX1
232 + ( xCurrent >> SIXTEEN );
234 if (*(it + incr_vois[0]) == -32768 ||
235 *(it + incr_vois[1]) == -32768 ||
236 *(it + incr_vois[2]) == -32768 ||
237 *(it + incr_vois[3]) == -32768 ||
238 *(it + incr_vois[4]) == -32768 ||
239 *(it + incr_vois[5]) == -32768 ||
240 *(it + incr_vois[6]) == -32768 ||
241 *(it + incr_vois[7]) == -32768 )
249 stock1 = *it * ( TWO_THEN_SIXTEEN - dx );
250 stock1 += *(++it) * dx;
251 stock1 /= TWO_THEN_SIXTEEN;
255 stock2 += *(--it) * ( TWO_THEN_SIXTEEN - dx );
256 stock2 /= TWO_THEN_SIXTEEN;
258 stock1 *= ( TWO_THEN_SIXTEEN - dy );
259 stock1 += stock2 * dy;
260 stock1 /= TWO_THEN_SIXTEEN;
262 it += incr_vois[4] - dimX1;
263 stock2 = *it * ( TWO_THEN_SIXTEEN - dx );
264 stock2 += *(++it) * dx;
265 stock2 /= TWO_THEN_SIXTEEN;
269 stock3 += *(--it) * ( TWO_THEN_SIXTEEN - dx );
270 stock3 /= TWO_THEN_SIXTEEN;
272 stock2 *= TWO_THEN_SIXTEEN - dy;
273 stock2 += stock3 * dy;
274 stock2 /= TWO_THEN_SIXTEEN;
276 stock1 *= ( TWO_THEN_SIXTEEN - dz );
277 stock1 += stock2 * dz;
279 *out++ =
static_cast<T
>( stock1 / TWO_THEN_SIXTEEN );
const T & at(long x, long y=0, long z=0, long t=0) const
std::vector< int > getSize() const
rc_ptr< Volume< T > > refVolume() const
carto::rc_ptr< carto::Volume< float > > volume()
std::vector< float > getVoxelSize() const
#define static_assert(expr, msg)