37#ifndef AIMS_UTILITY_CONVERTER_BUCKET_H
38#define AIMS_UTILITY_CONVERTER_BUCKET_H
40#include <cartobase/type/converter.h>
42#include <cartodata/volume/volume.h>
49 template <
class INP,
class OUTP>
60 template <
class INP,
class OUTP>
75 template <
class INP,
class OUTP>
77 :
public RawConverter<aims::BucketMap<INP>, rc_ptr<Volume<OUTP> > >
103 RawConverter(
bool timeislabel =
false,
bool withConstantValue =
false,
105 : _timeIsLabel( timeislabel ), _hasValue( withConstantValue ),
128 template <
class OUTP>
130 :
public RawConverter<aims::BucketMap<Void>, rc_ptr<Volume<OUTP> > >
151 template <
class INP,
class OUTP>
162 template <
class INP,
class OUTP>
164 :
public RawConverter<rc_ptr<Volume<INP> >, aims::BucketMap<OUTP> >
179 : _timeIsLabel( timeislabel ) {}
196 :
public RawConverter<rc_ptr<Volume<INP> >, aims::BucketMap<Void> >
206 template <
typename INP,
typename OUTP>
214 template <
typename INP,
typename OUTP>
222 template <
typename INP,
typename OUTP>
238 template <
class INP,
class OUTP>
inline
244 typename aims::BucketMap<INP>::Bucket::const_iterator ib, eb;
250 for( i=in.begin(); i!=e; ++i )
253 for( ib=i->second.begin(), eb=i->second.end(); ib!=eb; ++ib )
255 itemconv.
convert( ib->second, outval );
256 b[ ib->first ] = outval;
262 template <
class INP,
class OUTP>
inline
269 typename aims::BucketMap<INP>::Bucket::const_iterator ib, eb;
271 int dx = out->getSizeX(), dy = out->getSizeY(), dz = out->getSizeZ(),
272 dt = out->getSizeT();
276 for( it=in.begin(); it!=et; ++it, ++i )
280 for( ib=it->second.begin(), eb=it->second.end(); ib!=eb; ++ib )
282 const Point3d pos = ib->first + offset;
283 if( pos[0] >= 0 && pos[1] >= 0 && pos[2] >= 0
284 && pos[0] < dx && pos[1] < dy && pos[2] < dz )
286 out->at( pos[0], pos[1], pos[2], i ) );
294 template <
typename OUTP,
bool MODE>
300 const Point3d & offset,
bool timelabel );
303 template <
typename OUTP>
306 template <
typename INP>
319 aims::BucketMap<Void>::Bucket::const_iterator ib, eb;
321 int dx = out->getSizeX(), dy = out->getSizeY(), dz = out->getSizeZ();
323 for( it=in.begin(); it!=et; ++it, ++i )
325 for( ib=it->second.begin(), eb=it->second.end(); ib!=eb; ++ib )
327 const Point3d pos = ib->first + offset;
328 if( pos[0] >= 0 && pos[1] >= 0 && pos[2] >= 0
329 && pos[0] < dx && pos[1] < dy && pos[2] < dz )
330 out->at( pos ) = (OUTP) it->first;
337 template <
typename OUTP>
340 template <
typename INP>
347 typename aims::BucketMap<INP>::Bucket::const_iterator ib, eb;
349 int dx = out->getSizeX(), dy = out->getSizeY(), dz = out->getSizeZ(),
350 dt = out->getSizeT();
354 for( it=in.begin(); it!=et; ++it, ++i )
358 for( ib=it->second.begin(), eb=it->second.end(); ib!=eb; ++ib )
360 const Point3d pos = ib->first + offset;
361 if( pos[0] >= 0 && pos[1] >= 0 && pos[2] >= 0
362 && pos[0] < dx && pos[1] < dy && pos[2] < dz )
364 out->at( pos[0], pos[1], pos[2], i ) );
370 template <
typename OUTP>
inline
373 const Point3d & offset,
bool timelabel )
376 ( in, out, offset, timelabel );
382 template <
typename OUTP>
inline
383 void RawConverter<aims::BucketMap<Void>,
391 typename aims::BucketMap<Void>::Bucket::const_iterator ib, eb;
393 int dx = out->getSizeX(), dy = out->getSizeY(), dz = out->getSizeZ();
394 for( it=in.begin(); it!=et; ++it, ++i )
396 for( ib=it->second.begin(), eb=it->second.end(); ib!=eb; ++ib )
398 const Point3d & pos = ib->first + offset;
399 if( pos[0] >= 0 && pos[1] >= 0 && pos[2] >= 0
400 && pos[0] < dx && pos[1] < dy && pos[2] < dz )
401 out->at( pos[0], pos[1], pos[2], i ) = _value;
410 template <
class INP,
class OUTP>
inline
412 aims::BucketMap<OUTP> >::convert
413 (
const carto::rc_ptr<
Volume<INP> > &in, aims::BucketMap<OUTP> &out )
const
415 unsigned t, nt = in->getSizeT();
416 int x, y, z, nx = in->getSizeX(), ny = in->getSizeY(), nz = in->getSizeZ();
423 for( t=0; t<nt; ++t )
427 for( z=0; z<nz; ++z )
428 for( y=0; y<ny; ++y )
429 for( x=0; x<nx; ++x )
433 val = in->at( x, y, z, t );
436 itemconv.convert( val, outval );
437 bck.insert( std::pair<Point3d, OUTP>
438 (
Point3d( x, y, z ), outval ) );
447 template <
class INP>
inline
449 aims::BucketMap<Void> >::convert
450 (
const carto::rc_ptr<
Volume<INP> > &in, aims::BucketMap<Void> &out )
const
452 unsigned t, nt = in->getSizeT();
453 int x, y, z, nx = in->getSizeX(), ny = in->getSizeY(), nz = in->getSizeZ();
458 if( nt == 1 && timeIsLabel() )
462 for( z=0; z<nz; ++z )
463 for( y=0; y<ny; ++y )
464 for( x=0; x<nx; ++x )
466 val = in->at( x, y, z );
469 rc.convert( val, t );
470 out[ t ].
insert( std::pair<Point3d, Void>
471 (
Point3d( x, y, z ), Void() ) );
476 for( t=0; t<nt; ++t )
480 for( z=0; z<nz; ++z )
481 for( y=0; y<ny; ++y )
482 for( x=0; x<nx; ++x )
484 val = in->at( x, y, z, t );
486 bck.insert( std::pair<Point3d, Void>(
Point3d( x, y, z ),
495 template <
class INP,
class OUTP>
496 inline aims::BucketMap<OUTP>*
509 template <
class INP,
class OUTP>
515 typename aims::BucketMap<INP>::Bucket::const_iterator ib, eb;
516 Point3d bmin( 0, 0, 0 ), bmax( 0, 0, 0 );
520 for( it=in.begin(); it!=et; ++it )
521 for( ib=it->second.begin(), eb=it->second.end(); ib!=eb; ++ib )
523 const Point3d & pos = ib->first;
536 if( pos[0] < bmin[0] )
538 if( pos[1] < bmin[1] )
540 if( pos[2] < bmin[2] )
542 if( pos[0] > bmax[0] )
544 if( pos[1] > bmax[1] )
546 if( pos[2] > bmax[2] )
551 if( bmin[0] >= 0 && bmin[1] >= 0 && bmin[2] >= 0 )
555 *out(
new VolumeRef<OUTP>( bmax[0] - bmin[0] + 1, bmax[1] - bmin[1] + 1,
556 bmax[2] - bmin[2] + 1, in.size() ) );
557 std::vector<float> vs( 4 );
562 (*out)->header().setProperty(
"voxel_size", vs );
569 template <
class INP,
class OUTP>
inline
573 std::vector<float> vs(4);
583 template <
class OUTP>
inline
587 std::vector<float> vs(4);
An alternate, ordered, representation for buckets (voxels lists).
float sizeZ() const
returns the Z resolution in mm
std::map< int, Bucket >::const_iterator const_iterator
void insert(const Point3d &pos, const T &item)
Function redefined to omit time.
const aims::PythonHeader & header() const
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
sets X,Y,Z and T resolutions of the data
void erase(const Point3d &pos)
Function redefined to omit time.
std::map< Point3d, T, BucketMapLess > Bucket
float sizeT() const
returns the T resolution in s
float sizeY() const
returns the Y resolution in mm
void setHeader(const aims::PythonHeader &hdr)
float sizeX() const
returns the X resolution in mm
std::vector< float > getVoxelSize() const
static VolumeRef< OUTP > * alloc(const aims::BucketMap< INP > &in)
static aims::BucketMap< OUTP > * alloc(const aims::BucketMap< INP > &in)
static rc_ptr< Volume< OUTP > > * alloc(const aims::BucketMap< INP > &in)
static OUTP * alloc(const INP &in)
RawConverter(bool timeislabel=false)
void convert(const aims::BucketMap< INP > &in, VolumeRef< OUTP > &out) const
void printToVolume(const aims::BucketMap< INP > &in, VolumeRef< OUTP > &out, const Point3d &offset=Point3d(0, 0, 0)) const
writes bucket in an already allocated data
void convert(const aims::BucketMap< INP > &in, aims::BucketMap< OUTP > &out) const
void printToVolume(const aims::BucketMap< INP > &in, rc_ptr< Volume< OUTP > > &out, const Point3d &offset=Point3d(0, 0, 0)) const
writes bucket in an already allocated data
void convert(const aims::BucketMap< INP > &in, rc_ptr< Volume< OUTP > > &out) const
void convert(const aims::BucketMap< Void > &in, VolumeRef< OUTP > &out) const
void printToVolume(const aims::BucketMap< Void > &in, VolumeRef< OUTP > &out, const Point3d &offset=Point3d(0, 0, 0)) const
void convert(const aims::BucketMap< Void > &in, rc_ptr< Volume< OUTP > > &out) const
void printToVolume(const aims::BucketMap< Void > &in, rc_ptr< Volume< OUTP > > &out, const Point3d &offset=Point3d(0, 0, 0)) const
void setConstValue(OUTP x)
void setTimeIsLabel(bool x)
RawConverter(bool timeislabel=false, bool withConstantValue=false, OUTP value=0)
bool hasConstantValue() const
void setHasConstValue(bool x)
void convert(const rc_ptr< Volume< INP > > &in, aims::BucketMap< OUTP > &out) const
void setTimeIsLabel(bool x)
RawConverter(bool timeislabel=false)
void convert(const rc_ptr< Volume< INP > > &in, aims::BucketMap< Void > &out) const
void convert(const INP &in, OUTP &out) const
virtual void setProperty(const std::string &, Object)
The class for EcatSino data write operation.
void printToVolume_smart(const aims::BucketMap< Void > &in, carto::rc_ptr< Volume< OUTP > > &out, const Point3d &offset, bool timelabel)
static void printToVolume(const aims::BucketMap< INP > &in, carto::rc_ptr< Volume< OUTP > > &out, const Point3d &offset, bool)
static void printToVolume(const aims::BucketMap< INP > &in, carto::rc_ptr< Volume< OUTP > > &out, const Point3d &offset, bool timelabel)
static void printToVolume(const aims::BucketMap< Void > &in, carto::rc_ptr< Volume< OUTP > > &out, const Point3d &offset, bool timelabel)
AimsVector< int16_t, 3 > Point3d