50 const T&background, T* out,
59 void MaskLinearResampler<T>::
64 T &output_value,
int t )
const
68 float xf = std::floor(input_location[0]);
69 float yf = std::floor(input_location[1]);
70 float zf = std::floor(input_location[2]);
72 std::vector<int> dims = input_data.
getSize();
76 if ( ( xf >= 0 ) && ( xf < dims[0] ) &&
77 ( yf >= 0 ) && ( yf < dims[1] ) &&
78 ( zf >= 0 ) && ( zf < dims[2] ) )
80 int x =
static_cast<int>(xf);
81 int y =
static_cast<int>(yf);
82 int z =
static_cast<int>(zf);
84 if (input_data.
at(x, y, z, t) == -32768 ||
85 input_data.
at(x + 1, y, z, t) == -32768 ||
86 input_data.
at(x, y + 1, z, t) == -32768 ||
87 input_data.
at(x + 1, y + 1, z, t) == -32768 ||
88 input_data.
at(x, y, z + 1, t) == -32768 ||
89 input_data.
at(x + 1, y, z + 1, t) == -32768 ||
90 input_data.
at(x, y + 1, z + 1, t) == -32768 ||
91 input_data.
at(x + 1, y + 1, z + 1, t) == -32768)
93 output_value = -32768;
96 _linearresampler.resample_inv_to_vox(input_data, inverse_transform,
97 background, output_location,
101 output_value = background;
124 dirMotion.
scale( sizeFrom, sizeTo );
125 invMotion.
scale( sizeTo, sizeFrom );
129 T* it = &thing.
at( 0 );
133 std::cout <<
"Resampling volume [ 1] / slice [ 1]" << std::flush;
136 for (
int t = 1; t <= dimt; t++ )
139 for (
int s = 1; s <= dimz; s++ )
142 std::cout <<
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"
143 << std::setw( 3 ) << t <<
"] / slice ["
144 << std::setw( 3 ) << s <<
"]" << std::flush;
147 _sliceResamp( input_data, thing, background, it, start, t - 1,
149 it = &thing.
at( 0, 0, s, t - 1 );
150 start[ 0 ] += invMotion.
rotation()( 0, 2 );
151 start[ 1 ] += invMotion.
rotation()( 1, 2 );
152 start[ 2 ] += invMotion.
rotation()( 2, 2 );
156 std::cout << std::endl;
168 const T& background, T* out,
173 "the optimizations need at least 32-bit int");
175 const T* pOrig = &input_data.
at( 0, 0, 0, t );
181 const int SIXTEEN = 16;
182 const int TWO_THEN_SIXTEEN = 65536;
184 int maxX = TWO_THEN_SIXTEEN * ( dimX1 - 1 );
185 int maxY = TWO_THEN_SIXTEEN * ( input_data.
getSizeY() - 1 );
186 int maxZ = TWO_THEN_SIXTEEN * ( input_data.
getSizeZ() - 1 );
188 int xLinCurrent = ( int )( 65536.0 * start[ 0 ] );
189 int yLinCurrent = ( int )( 65536.0 * start[ 1 ] );
190 int zLinCurrent = ( int )( 65536.0 * start[ 2 ] );
192 int xu = ( int )( 65536.0 * Rinv( 0, 0 ) );
193 int yu = ( int )( 65536.0 * Rinv( 1, 0 ) );
194 int zu = ( int )( 65536.0 * Rinv( 2, 0 ) );
195 int xv = ( int )( 65536.0 * Rinv( 0, 1 ) );
196 int yv = ( int )( 65536.0 * Rinv( 1, 1 ) );
197 int zv = ( int )( 65536.0 * Rinv( 2, 1 ) );
199 int xCurrent, yCurrent, zCurrent;
202 long incr_vois[8] = {
205 &input_data.
at( 0, 1, 0 ) - &input_data.
at( 0 ),
206 &input_data.
at( 0, 1, 0 ) - &input_data.
at( 0 ),
207 &input_data.
at( 0, 0, 1 ) - &input_data.
at( 0 ),
208 &input_data.
at( 1, 0, 1 ) - &input_data.
at( 0 ),
209 &input_data.
at( 1, 1, 1 ) - &input_data.
at( 0 ),
210 &input_data.
at( 0, 1, 1 ) - &input_data.
at( 0 )
212 float stock1, stock2, stock3;
213 for (
int v = dimY2; v--; )
215 xCurrent = xLinCurrent;
216 yCurrent = yLinCurrent;
217 zCurrent = zLinCurrent;
219 for (
int u = dimX2; u--; )
221 if ( xCurrent >= 0 && xCurrent < maxX &&
222 yCurrent >= 0 && yCurrent < maxY &&
223 zCurrent >= 0 && zCurrent < maxZ )
225 dx = xCurrent & 0xffff;
226 dy = yCurrent & 0xffff;
227 dz = zCurrent & 0xffff;
229 it = pOrig + ( zCurrent >> SIXTEEN ) * incr_vois[4]
230 + ( yCurrent >> SIXTEEN ) * dimX1
231 + ( xCurrent >> SIXTEEN );
233 if (*(it + incr_vois[0]) == -32768 ||
234 *(it + incr_vois[1]) == -32768 ||
235 *(it + incr_vois[2]) == -32768 ||
236 *(it + incr_vois[3]) == -32768 ||
237 *(it + incr_vois[4]) == -32768 ||
238 *(it + incr_vois[5]) == -32768 ||
239 *(it + incr_vois[6]) == -32768 ||
240 *(it + incr_vois[7]) == -32768 )
248 stock1 = *it * ( TWO_THEN_SIXTEEN - dx );
249 stock1 += *(++it) * dx;
250 stock1 /= TWO_THEN_SIXTEEN;
254 stock2 += *(--it) * ( TWO_THEN_SIXTEEN - dx );
255 stock2 /= TWO_THEN_SIXTEEN;
257 stock1 *= ( TWO_THEN_SIXTEEN - dy );
258 stock1 += stock2 * dy;
259 stock1 /= TWO_THEN_SIXTEEN;
261 it += incr_vois[4] - dimX1;
262 stock2 = *it * ( TWO_THEN_SIXTEEN - dx );
263 stock2 += *(++it) * dx;
264 stock2 /= TWO_THEN_SIXTEEN;
268 stock3 += *(--it) * ( TWO_THEN_SIXTEEN - dx );
269 stock3 /= TWO_THEN_SIXTEEN;
271 stock2 *= TWO_THEN_SIXTEEN - dy;
272 stock2 += stock3 * dy;
273 stock2 /= TWO_THEN_SIXTEEN;
275 stock1 *= ( TWO_THEN_SIXTEEN - dz );
276 stock1 += stock2 * dz;
278 *out++ =
static_cast<T
>( stock1 / TWO_THEN_SIXTEEN );
#define static_assert(expr, msg)
std::vector< float > getVoxelSize() const
std::vector< int > getSize() const
rc_ptr< Volume< T > > refVolume() const
const T & at(long x, long y=0, long z=0, long t=0) const