35 #ifndef AIMS_RESAMPLING_SAMPLER_H 36 #define AIMS_RESAMPLING_SAMPLER_H 47 unsigned short x, y,
z;
54 extern template class Volume<PVItem>;
82 unsigned short x, y,
z ;
94 virtual void doit(
const Motion& motion,
95 std::vector< PVVectorItem >& thing,
107 template <
class T>
inline 116 Motion dirMotion = motion;
120 Point3df sizeFrom( _ref->sizeX(), _ref->sizeY(), _ref->sizeZ() );
122 dirMotion.scale( sizeFrom, sizeTo );
123 invMotion.
scale( sizeTo, sizeFrom );
129 cout <<
"Sampling volume [ 1] / slice [ 1]" << flush;
131 for (
int t = 1; t <= thing.
dimT(); t++ )
134 for (
int s = 1; s <= thing.
dimZ(); s++ )
137 cout <<
"\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" 138 << setw( 3 ) << t <<
"] / slice [" 139 << setw( 3 ) << s <<
"]" << flush;
141 _sliceResamp( thing, it, start, t - 1, invMotion.
rotation() );
143 start[ 0 ] += invMotion.
rotation()( 0, 2 );
144 start[ 1 ] += invMotion.
rotation()( 1, 2 );
145 start[ 2 ] += invMotion.
rotation()( 2, 2 );
154 template <
class T>
inline 161 int dimX1 = _ref->dimX();
162 int dimX2 = resamp.
dimX();
163 int dimY2 = resamp.
dimY();
165 const int SIXTEEN = 16;
166 const int TWO_THEN_SIXTEEN = 65536;
168 int maxX = TWO_THEN_SIXTEEN * ( dimX1 - 1 );
169 int maxY = TWO_THEN_SIXTEEN * ( _ref->dimY() - 1 );
170 int maxZ = TWO_THEN_SIXTEEN * ( _ref->dimZ() - 1 );
172 int xLinCurrent = ( int )( 65536.0 * start[ 0 ] );
173 int yLinCurrent = ( int )( 65536.0 * start[ 1 ] );
174 int zLinCurrent = ( int )( 65536.0 * start[ 2 ] );
176 int xu = ( int )( 65536.0 * Rinv( 0, 0 ) );
177 int yu = ( int )( 65536.0 * Rinv( 1, 0 ) );
178 int zu = ( int )( 65536.0 * Rinv( 2, 0 ) );
179 int xv = ( int )( 65536.0 * Rinv( 0, 1 ) );
180 int yv = ( int )( 65536.0 * Rinv( 1, 1 ) );
181 int zv = ( int )( 65536.0 * Rinv( 2, 1 ) );
183 int xCurrent, yCurrent, zCurrent;
185 int incr_vois[8] = {0, 1,
187 _ref->oSlice(),_ref->oSlice()+1,
188 _ref->oSlice()+ dimX1+1,_ref->oSlice() + dimX1};
189 for (
int v = dimY2; v--; )
191 xCurrent = xLinCurrent;
192 yCurrent = yLinCurrent;
193 zCurrent = zLinCurrent;
195 for (
int u = dimX2; u--; )
197 if ( xCurrent >= 0 && xCurrent < maxX &&
198 yCurrent >= 0 && yCurrent < maxY &&
199 zCurrent >= 0 && zCurrent < maxZ )
201 it = _ref->
begin() + _ref->oFirstPoint() + t * _ref->oVolume()
202 + ( zCurrent >> SIXTEEN ) * _ref->oSlice()
203 + ( yCurrent >> SIXTEEN ) * dimX1
204 + ( xCurrent >> SIXTEEN );
206 if (*(it + incr_vois[0]) == -32768 ||
207 *(it + incr_vois[1]) == -32768 ||
208 *(it + incr_vois[2]) == -32768 ||
209 *(it + incr_vois[3]) == -32768 ||
210 *(it + incr_vois[4]) == -32768 ||
211 *(it + incr_vois[5]) == -32768 ||
212 *(it + incr_vois[6]) == -32768 ||
213 *(it + incr_vois[7]) == -32768 )
219 out->
x = xCurrent & 0xffff;
220 out->
y = yCurrent & 0xffff;
221 out->
z = zCurrent & 0xffff;
222 out->
offset = ( zCurrent >> SIXTEEN ) * _ref->oSlice()
223 + ( yCurrent >> SIXTEEN ) * dimX1
224 + ( xCurrent >> SIXTEEN );
242 template <
class T>
inline 245 std::vector< PVVectorItem >& thing,
248 const int TWO_THEN_SIXTEEN = 65536;
255 Motion dirMotion; dirMotion = motion;
260 Point3df sizeFrom( _ref->sizeX(), _ref->sizeY(), _ref->sizeZ() );
263 dirMotion.
scale( sizeFrom, sizeTo );
264 invMotion.
scale( sizeTo, sizeFrom );
267 it = model.begin()->second.begin() ;
270 int nbOfVoxels = model.begin()->second.size() ;
272 thing.reserve(nbOfVoxels) ;
273 thing.resize(nbOfVoxels) ;
283 x = invMotion.
transform( 1.F, 0.F, 0.F ) ;
284 y = invMotion.
transform( 0.F, 1.F, 0.F ) ;
285 z = invMotion.
transform( 0.F, 0.F, 1.F ) ;
287 int maxX = _ref->dimX() - 1;
288 int maxY = _ref->dimY() - 1;
289 int maxZ = _ref->dimZ() - 1;
290 int oS= _ref->oSlice(), dX = _ref->dimX();
292 for(
int i = 0 ; i < nbOfVoxels ; ++i , ++it )
294 float current0, current1, current2;
295 current0 =
static_cast<float>( (it->first)[0] ) ;
296 current1 =
static_cast<float>( (it->first)[1] ) ;
297 current2 =
static_cast<float>( (it->first)[2] ) ;
299 float tmp0 = current0 * x[0] + current1 * y[0] + current2 * z[0] + transl0 ;
300 float tmp1 = current0 * x[1] + current1 * y[1] + current2 * z[1] + transl1 ;
301 float tmp2 = current0 * x[2] + current1 * y[2] + current2 * z[2] + transl2 ;
304 if ( tmp0 >= 0 && tmp0 < maxX &&
305 tmp1 >= 0 && tmp1 < maxY &&
306 tmp2 >= 0 && tmp2 < maxZ)
308 item.
x = (
unsigned short) (( tmp0 -
int(tmp0) ) * TWO_THEN_SIXTEEN);
309 item.
y = (
unsigned short) (( tmp1 -
int(tmp1) ) * TWO_THEN_SIXTEEN);
310 item.
z = (
unsigned short) (( tmp2 -
int(tmp2) ) * TWO_THEN_SIXTEEN);
311 item.
offset = int(tmp2) * oS +
void setRef(const AimsData< T > &ref)
const AimsData< T > * _ref
void _sliceResamp(AimsData< PVItem > &resamp, PVItem *out, const Point3df &start, int t, const AimsData< float > &Rinv) const
virtual void doit(const Motion &motion, AimsData< PVItem > &thing) const
virtual void doit(const Motion &motion, std::vector< PVVectorItem > &thing, const aims::BucketMap< T > &model) const
void setRef(const AimsData< T > &ref)
const AimsData< T > * _ref