34#ifndef CARTODATA_TRANSFORMATION_LIGHTRESAMPLER_H
35#define CARTODATA_TRANSFORMATION_LIGHTRESAMPLER_H
38#include <soma-io/transformation/affinetransformation3d_base.h>
39#include <cartobase/containers/nditerator.h>
57 const Volume<T> & vol,
const AffineTransformationBase & tr );
60 const AffineTransformationBase & tr,
const T & background = 0 );
63 const AffineTransformationBase & tr );
65 const std::vector<int> & dims,
const AffineTransformationBase & tr );
67 const std::vector<float> & vs,
const AffineTransformationBase & tr );
73 const std::vector<int> & dims,
const AffineTransformationBase & tr )
75 int d, n = dims.size(), i;
76 std::vector<int> out_dims( n, 0 );
79 std::vector<int> p( n, 0 );
81 p = tr.transformVector( p );
86 out_dims[d] = fabs( out_dims[d] );
94 const std::vector<float> & vs,
const AffineTransformationBase & tr )
96 unsigned d, n = tr.order(), nv = vs.size(), i;
97 n = std::max( n, nv );
98 std::vector<float> out_vs( n, 0.f );
101 std::vector<float> p( n, 0.f );
106 p = tr.transformVector( p );
111 out_vs[d] = fabs( out_vs[d] );
117 template <
typename T>
119 const Volume<T> & vol,
const AffineTransformationBase & tr )
131 template <
typename T>
133 const Object & header,
const AffineTransformationBase & tr )
140 template <
typename T>
143 const AffineTransformationBase & tr,
const T & background )
146 while( ovs.size() < 3 )
149 while( vs.size() < 3 )
152 std::unique_ptr<AffineTransformationBase> trinv = tr.inverse();
154 AffineTransformationBase ivs( tr.order() );
155 unsigned i, n = vs.size();
157 ivs.matrix()( i, i ) = 1.f / vs[i];
158 *trinv = ivs * *trinv;
164 std::vector<float> ipos( n, 0.f );
166 std::vector<float> xoff = trinv->transformVector( ipos );
167 std::vector<int> vipos;
168 std::vector<int> idims = input.
getSize();
169 int dx = idims[0], dy = idims[1], dz = idims[2];
170 unsigned m = idims.size();
174 for( ; !oit.
ended(); ++oit )
179 ipos.insert( ipos.end(), vipos.begin(), vipos.end() );
183 ipos = trinv->transform( ipos );
189 vipos[i] = int(rint(ipos[i]));
190 if( vipos[i] < 0 || vipos[i] >= idims[i] )
198 *p = input.
at( vipos );
Light, simple resampler used for flipping operations.
static void resampleVolume(const Volume< T > &input, Volume< T > &output, const AffineTransformationBase &tr, const T &background=0)
static std::vector< int > getTransformedDims(const std::vector< int > &dims, const AffineTransformationBase &tr)
static std::vector< float > getTransformedVoxelSize(const std::vector< float > &vs, const AffineTransformationBase &tr)
static VolumeRef< T > allocateResampledVolume(const Volume< T > &vol, const AffineTransformationBase &tr)
static Object transformHeader(const Object &header, const AffineTransformationBase &tr)
adapt info in header (referential, transformations)
const std::vector< int > & position() const
Object reference(Object &value)
std::vector< float > getVoxelSize() const
get the voxel size from the header, with 4 values defaulting to 1.mm if not present
std::vector< int > getSize() const
get the 4 dimensions in a vector
Convenient handle for a Volume - this is normally the entry point for all volumes handling.
void setVoxelSize(float vx, float vy=1., float vz=1., float vt=1.)
virtual void copyHeaderFrom(const PropertySet &other)
std::vector< long > getStrides() const
Get strides for the volume.
const T & at(long x, long y=0, long z=0, long t=0) const
int line_direction() const
std::ptrdiff_t line_length() const
void inc_line_ptr(T *&p) const