35 #ifndef AIMS_RESAMPLING_RESAMPLER_D_H
36 #define AIMS_RESAMPLING_RESAMPLER_D_H
62 : _ref( 0 ), _defval( T() ), _verbose_stream( &std::cout )
71 const T& outBackground,
78 outResolution[0] = vs[0];
79 outResolution[1] = vs[1];
80 outResolution[2] = vs[2];
82 std::vector<int> sz = outVolume.
getSize();
92 std::ostream *stream = _verbose_stream;
96 * outSizeY * outSizeZ * outSizeT, 0, 100,
"%", 3,
99 for ( t = 0; t < outSizeT; t++ )
101 updateParameters( inVolume, t, verbose );
103 for ( z = 0; z < outSizeZ; z++ )
106 for ( y = 0; y < outSizeY; y++ )
108 o = &outVolume.
at( 0, y, z, t );
110 for ( x = 0; x < outSizeX; x++ )
112 const Point3df outLoc ( x * outResolution[0],
113 y * outResolution[1],
114 z * outResolution[2] );
116 doResample( inVolume, inverse_transform_to_vox, outBackground,
122 if(verbose || _verbose_stream) {
131 template <
typename T>
146 transform_chain.
push_back(external_ref(inverse_transform_to_mm));
147 transform_chain.
push_back(external_ref(mm_to_voxel_transform));
149 resample_inv_to_vox(input_data, transform_chain, background,
150 output_volume, verbose);
153 template <
typename T>
166 mm_to_voxel_transform.
scale(
Point3df( 1, 1, 1 ), in_voxel_size );
169 transform_chain.
push_back(external_ref(inverse_transform_to_mm));
170 transform_chain.
push_back(external_ref(mm_to_voxel_transform));
172 resample_inv_to_vox(input_data, transform_chain, background,
173 output_location, output_value, timestep);
177 template <
typename T >
181 const T& outBackground,
191 normTransform3d = transform3d * normTransform3d;
192 normTransform3d = normTransform3d.
inverse();
194 resample_inv_to_vox(inVolume, normTransform3d, outBackground, outVolume,
200 template <
typename T >
204 const T& outBackground,
206 T& outValue,
int t )
const
214 normTransform3d = transform3d * normTransform3d;
215 normTransform3d = normTransform3d.
inverse();
219 doResample( inVolume, normTransform3d, outBackground, outLocation,
225 template <
typename T>
230 throw std::runtime_error(
"Resampler used without a ref volume to resample"
236 template <
typename T>
239 int dimX,
int dimY,
int dimZ,
243 throw std::runtime_error(
"Resampler used without a ref volume to resample"
246 std::vector<float> vs( 4, 1. );
247 vs[0] = resolution[0];
248 vs[1] = resolution[1];
249 vs[2] = resolution[2];
250 vs[3] = _ref->getVoxelSize()[3];
272 std::vector<std::vector<float> > trout;
273 trout.reserve( trs->size() );
274 for( ; tit->isValid(); tit->next() )
278 trout.push_back( m.toVector() );
285 std::vector<std::vector<float> > trout;
286 std::vector<std::string> refsout;
291 std::string refid = iref->getString();
292 refsout.push_back( refid );
297 if( refsout.empty() )
298 refsout.push_back(
"Coordinates aligned to another file or to "
299 "anatomical truth" );
310 template <
typename T>
void resample_inv(const carto::Volume< T > &input_data, const soma::Transformation3d &inverse_transform_to_mm, const T &background, const Point3df &output_location, T &output_value, int timestep) const
Resample a volume at a single location.
void setRef(const carto::rc_ptr< carto::Volume< T > > &ref)
Set the input data to be resampled by the doit() methods.
virtual void resample(const carto::Volume< T > &input_data, const aims::AffineTransformation3d &transform, const T &background, carto::Volume< T > &output_data, bool verbose=false) const
Resample a volume into an existing output volume.
void doit(const aims::AffineTransformation3d &transform, carto::Volume< T > &output_data) const
Resample the input volume set with setRef() into an existing volume.
void resample_inv_to_vox(const carto::Volume< T > &input_data, const soma::Transformation3d &inverse_transform_to_vox, const T &background, const Point3df &output_location, T &output_value, int timestep) const
Resample a volume at a single location.
void setProperty(const std::string &, const T &)
virtual bool removeProperty(const std::string &key)
bool getProperty(const std::string &, T &) const
std::vector< float > getVoxelSize() const
std::vector< int > getSize() const
virtual void copyHeaderFrom(const PropertySet &other)
const PropertySet & header() const
const T & at(long x, long y=0, long z=0, long t=0) const
reference_wrapper< T > ref(T &ref)