34 #ifndef AIMS_data_SPARSEVOLUME_H 
   35 #define AIMS_data_SPARSEVOLUME_H 
   62         : _volume( vol ), _begin( &vol->at( 0, y, z, t ) ),
 
   63           _end( &vol->at( vol->getSizeX(), y, z, t ) )
 
   78     class const_LowLevelStorage
 
   86         : _volume( vol ), _begin( &vol->at( 0, y, z, t ) ),
 
   87           _end( &vol->at( vol->getSizeX(), y, z, t ) )
 
   90         : _volume( other.volume() ), _begin( other.begin() ),
 
  109         : _pos( 
Point4d( 0, y, z, t ), LowLevelStorage( vol, y, z, t ) ) {}
 
  112       std::pair<Point4d, LowLevelStorage> *operator -> ()
 
  114       LowLevelStorage & 
storage() { 
return _pos.second; }
 
  117         return &_pos.second.volume()->at( 0, _pos.first[1], _pos.first[2],
 
  119           == &x._pos.second.volume()->at( 0, x._pos.first[1], x._pos.first[2],
 
  122       bool operator != ( 
const iterator & x )
 const 
  123       { 
return !( *
this == x ); }
 
  124       iterator & operator ++ ()
 
  126         int16_t & y = _pos.first[1];
 
  127         int16_t & z = _pos.first[2];
 
  128         int16_t & t = _pos.first[3];
 
  130         if( y >= _pos.second.volume()->getSizeY() )
 
  134           if( z >= _pos.second.volume()->getSizeZ() )
 
  140         _pos.second = LowLevelStorage( _pos.second.volume(), y, z, t );
 
  145       std::pair<Point4d, LowLevelStorage> _pos;
 
  153         : _pos( 
Point4d( 0, y, z, t ), const_LowLevelStorage( vol, y, z, t ) )
 
  156       : _pos( other->first, other->second )
 
  158       const std::pair<Point4d, const_LowLevelStorage> & 
operator * ()
 const 
  160       const std::pair<Point4d, const_LowLevelStorage> *operator -> ()
 const 
  162       const const_LowLevelStorage & 
storage()
 const { 
return _pos.second; }
 
  165         return &_pos.second.volume()->at( 0, _pos.first[1], _pos.first[2],
 
  167             == &x._pos.second.volume()->at( 0, x._pos.first[1],
 
  168                                      x._pos.first[2], x._pos.first[3] );
 
  170       bool operator != ( 
const const_iterator & x )
 const 
  171       { 
return !( *
this == x ); }
 
  172       const_iterator & operator ++ ()
 
  174         int16_t & y = _pos.first[1];
 
  175         int16_t & z = _pos.first[2];
 
  176         int16_t & t = _pos.first[3];
 
  178         if( y >= _pos.second.volume()->getSizeY() )
 
  182           if( z >= _pos.second.volume()->getSizeZ() )
 
  188         _pos.second = const_LowLevelStorage( _pos.second.volume(), y, z, t );
 
  193       std::pair<Point4d, const_LowLevelStorage> _pos;
 
  196     SparseVolume( 
int sizeX = 1, 
int sizeY = 1, 
int sizeZ = 1, 
int sizeT = 1,
 
  197                   const carto::AllocatorContext& allocatorContext
 
  198                   = carto::AllocatorContext(), 
bool allocated = 
true );
 
  199     SparseVolume( 
int sizeX, 
int sizeY, 
int sizeZ, 
int sizeT, T* buffer );
 
  206     template <
typename U>
 
  211     std::vector<int> getSize() 
const;
 
  213     { 
return _data->header(); }
 
  215     std::vector<float> voxelSize() 
const;
 
  218     { _data->fill( value ); setBackground( value ); }
 
  219     iterator 
begin() { 
return iterator( data(), 0, 0, 0 ); }
 
  220     iterator 
end() { 
return iterator( data(), 0, 0, data()->getSizeT() ); }
 
  221     const_iterator 
begin()
 const { 
return const_iterator( data(), 0, 0, 0 ); }
 
  222     const_iterator 
end()
 const 
  223     { 
return const_iterator( data(), 0, 0, data()->getSizeT() ); }
 
  224     const T & 
at( 
int x, 
int y = 0, 
int z = 0, 
int t = 0 )
 const 
  225     { 
return _data->at( x, y, z, t ); }
 
  226     void setValue( 
const T & value,  
int x, 
int y = 0, 
int z = 0, 
int t = 0 )
 
  227     { _data->at( x, y, z, t ) = value; }
 
  229     { 
return _data->at( p[0], p[1], p[2], 0 ); }
 
  231     { _data->at( p[0], p[1], p[2], 0 ) = value; }
 
  234     { 
return checkedAt( p[0], p[1], p[2] ); }
 
  235     const T & checkedAt( 
int x, 
int y = 0, 
int z = 0, 
int t = 0 ) 
const;
 
  237         ( 
const const_iterator & i,
 
  239     { 
Point4d x( i->first ); x[0] = iv - i->storage().
begin(); 
return x; }
 
  241         ( 
const const_iterator & i,
 
  243     { 
return Point3d( iv - i->second.begin(), i->first[1], i->first[2] ); }
 
  254   template <
typename T>
 
  264     SparseVolume( 
int sizeX = 1, 
int sizeY = 1, 
int sizeZ = 1, 
int sizeT = 1,
 
  265                   const carto::AllocatorContext& allocatorContext
 
  266                   = carto::AllocatorContext(), 
bool allocated = 
true );
 
  272     template <
typename U>
 
  277     std::vector<int> getSize() 
const;
 
  279     { 
return _data->header().getValue(); }
 
  281     { 
return _data->header().getValue(); }
 
  282     std::vector<float> voxelSize() 
const;
 
  285     { _data->clear(); setBackground( value ); }
 
  286     const T & at( 
int x, 
int y, 
int z, 
int t ) 
const;
 
  287     void setValue( 
const T & value,  
int x, 
int y, 
int z, 
int t );
 
  288     const T & at( 
int x, 
int y = 0, 
int z = 0 ) 
const;
 
  289     void setValue( 
const T & value,  
int x, 
int y = 0, 
int z = 0 );
 
  290     const T & at( 
const Point3d & p ) 
const;
 
  291     void setValue( 
const T & value,  
const Point3d & p );
 
  294     const T & 
checkedAt( 
int x, 
int y = 0, 
int z = 0 )
 const 
  295     { 
return at( x, y, z ); }
 
  297     { 
return at( x, y, z, t ); }
 
  304           const typename const_LowLevelStorage::const_iterator & iv )
 
  305     { 
return iv->first; }
 
  307         ( 
const typename const_LowLevelStorage::const_iterator & iv )
 
  308     { 
return iv->second; }
 
  327     SparseVolume( 
int sizeX = 1, 
int sizeY = 1, 
int sizeZ = 1, 
int sizeT = 1,
 
  328                   const carto::AllocatorContext& allocatorContext
 
  329                   = carto::AllocatorContext(), 
bool allocated = 
true );
 
  335     template <
typename U>
 
  340     std::vector<int> getSize() 
const;
 
  342     { 
return _data->header().getValue(); }
 
  344     { 
return _data->header().getValue(); }
 
  345     std::vector<float> voxelSize() 
const;
 
  348     { _data->clear(); setBackground( value ); }
 
  349     const VoxelType & at( 
int x, 
int y = 0, 
int z = 0, 
int t = 0 ) 
const;
 
  350     void setValue( 
const VoxelType & value,  
int x, 
int y = 0, 
int z = 0,
 
  352     const VoxelType & at( 
const Point3d & p ) 
const;
 
  353     void setValue( 
const VoxelType & value,  
const Point3d & p );
 
  357     { 
return at( x, y, z ); }
 
  359     { 
return at( x, y, z, t ); }
 
  366           const const_LowLevelStorage::const_iterator & iv )
 
  367     { 
return iv->first; }
 
  368     static const Void & 
at( 
const const_LowLevelStorage::const_iterator
 
  370     { 
return iv->second; }
 
  374     VoxelType _background;
 
  380   template <
typename T>
 
  383                                                  int sizeZ, 
int sizeT,
 
  384                                                  const carto::AllocatorContext&
 
  387     : _data( sizeX, sizeY, sizeZ, sizeT, allocatorContext, allocated ),
 
  391       _data->fill( _background );
 
  395   template <
typename T>
 
  398                                                  int sizeZ, 
int sizeT,
 
  400     : _data( new 
carto::Volume<T>( sizeX, sizeY, sizeZ, sizeT, buffer ) ),
 
  406   template <
typename T>
 
  416   template <
typename T>
 
  420     : _data( new 
carto::Volume<T>( other ) ),
 
  426   template <
typename T>
 
  436   template <
typename T>
 
  443   template <
typename T>
 
  447     std::vector<int> sz( 4 );
 
  448     sz[0] = _data->getSizeX();
 
  449     sz[1] = _data->getSizeY();
 
  450     sz[2] = _data->getSizeZ();
 
  451     sz[3] = _data->getSizeT();
 
  457   template <
typename T>
 
  461     std::vector<float> vs( 4 );
 
  466       for( j=v->objectIterator(); j->isValid(); j->next(), ++i )
 
  467         vs[i] = j->currentValue()->getScalar();
 
  478   template <
typename T>
 
  483     if( x < 0 || y < 0 || z < 0 || t < 0 || x >= _data->getSizeX()
 
  484         || y >= _data->getSizeY() || z >= _data->getSizeZ()
 
  485         || t >= _data->getSizeT() )
 
  487     return _data->at( x, y, z, t );
 
  491   template <
typename T>
 
  499   template <
typename T> 
template <
typename U>
 
  520     std::unique_ptr<carto::AllocatorContext> pac;
 
  521     if( ac->allocatorType() == carto::AllocatorStrategy::Unallocated )
 
  525       pac.reset( 
new carto::AllocatorContext );
 
  531     data->
fill( other.background() );
 
  533     svol.setBackground( other.background() );
 
  540   template <
typename T>
 
  543                                              const carto::AllocatorContext&,
 
  549     if( i != _data->end() )
 
  550       _firstbck = &i->second;
 
  556   template <
typename T>
 
  564     if( i != _data->end() )
 
  565       _firstbck = &i->second;
 
  571   template <
typename T>
 
  578     if( i != _data->end() )
 
  579       _firstbck = &i->second;
 
  585   template <
typename T>
 
  592   template <
typename T>
 
  593   inline std::vector<int>
 
  596     std::vector<int> sz(4);
 
  605     sz[3] = _data->rbegin()->first + 1;
 
  611     for( ib=_data->begin(); ib!=eb; ++ib )
 
  612       for( i=ib->second.begin(), e=ib->second.end(); i!=e; ++i )
 
  630   template <
typename T>
 
  634     std::vector<float> vs( 4 );
 
  635     vs[0] = _data->sizeX();
 
  636     vs[1] = _data->sizeY();
 
  637     vs[2] = _data->sizeZ();
 
  638     vs[3] = _data->sizeT();
 
  643   template <
typename T>
 
  648     if( ib == _data->end() )
 
  651       = ib->second.find( 
Point3d( x, y, z ) );
 
  652     if( i != ib->second.end() )
 
  658   template <
typename T>
 
  665       = _firstbck->find( p );
 
  666     if( i != _firstbck->end() )
 
  672   template <
typename T>
 
  676     return at( 
Point3d( x, y, z ) );
 
  680   template <
typename T>
 
  685     (*_data)[t][ 
Point3d( x, y, z ) ] = value;
 
  689   template <
typename T>
 
  694       _firstbck = &(*_data)[0];
 
  695     (*_firstbck)[ p ] = value;
 
  699   template <
typename T>
 
  703     setValue( value, 
Point3d( x, y, z ) );
 
  707   template <
typename T>
 
  713     if( i != _data->end() )
 
  714       _firstbck = &i->second;
 
  720   template <
typename T> 
template <
typename U>
 
  737     ( 
int, 
int, 
int, 
int, 
const carto::AllocatorContext&, 
bool )
 
  767   inline std::vector<int>
 
  770     std::vector<int> sz(4);
 
  771     sz[3] = _data->rbegin()->first + 1;
 
  777     for( ib=_data->begin(); ib!=eb; ++ib )
 
  778       for( i=ib->second.begin(), e=ib->second.end(); i!=e; ++i )
 
  799     std::vector<float> vs( 4 );
 
  800     vs[0] = _data->sizeX();
 
  801     vs[1] = _data->sizeY();
 
  802     vs[2] = _data->sizeZ();
 
  803     vs[3] = _data->sizeT();
 
  811     return at( 
Point3d( x, y, z ) );
 
  819     for( ib=_data->begin(); ib!=eb; ++ib )
 
  822         = ib->second.find( p );
 
  823       if( i != ib->second.end() )
 
  834     setValue( value, 
Point3d( x, y, z ) );
 
  844     for( ib=_data->begin(); ib!=eb; ++ib )
 
  845       ib->second.
erase( p );
 
  846     if( value != background() )
 
  847       (*_data)[value][p] = 
Void();
 
  858   template <
typename U>
 
An alternate, ordered, representation for buckets (voxels lists).
float sizeZ() const
returns the Z resolution in mm
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
sets X,Y,Z and T resolutions of the data
const aims::PythonHeader & header() const
std::map< int, Bucket >::iterator iterator
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
float sizeX() const
returns the X resolution in mm
std::map< int, Bucket >::const_iterator const_iterator
void fill(const T &value)
const_iterator begin() const
const T & background() const
void setBackground(const T &x)
carto::rc_ptr< BucketMap< T > > data() const
static const Point3d & position3d(const const_iterator &, const typename const_LowLevelStorage::const_iterator &iv)
const T & checkedAt(const Point3d &p) const
const T & checkedAt(int x, int y, int z, int t) const
static const T & at(const typename const_LowLevelStorage::const_iterator &iv)
BucketMap< T >::iterator iterator
BucketMap< T >::const_iterator const_iterator
const_iterator end() const
carto::PropertySet & header()
BucketMap< T >::Bucket LowLevelStorage
const carto::PropertySet & header() const
const BucketMap< T >::Bucket const_LowLevelStorage
const T & checkedAt(int x, int y=0, int z=0) const
const VoxelType & background() const
const_iterator begin() const
const VoxelType & checkedAt(int x, int y=0, int z=0) const
void setBackground(const VoxelType &x)
const_iterator end() const
const carto::PropertySet & header() const
BucketMap< Void >::iterator iterator
BucketMap< Void >::const_iterator const_iterator
void fill(const VoxelType &value)
static const Point3d & position3d(const const_iterator &, const const_LowLevelStorage::const_iterator &iv)
carto::PropertySet & header()
static const Void & at(const const_LowLevelStorage::const_iterator &iv)
const VoxelType & checkedAt(const Point3d &p) const
carto::rc_ptr< BucketMap< Void > > data() const
BucketMap< Void >::Bucket LowLevelStorage
const BucketMap< Void >::Bucket const_LowLevelStorage
const VoxelType & checkedAt(int x, int y, int z, int t) const
const_iterator begin() const
const_iterator end() const
LowLevelStorage(carto::VolumeRef< T > vol, int y, int z, int t)
carto::VolumeRef< T > volume() const
const_iterator begin() const
const_LowLevelStorage(const LowLevelStorage &other)
carto::VolumeRef< T > volume() const
const_iterator end() const
const_LowLevelStorage(const carto::VolumeRef< T > vol, int y, int z, int t)
const const_LowLevelStorage & storage() const
const_iterator(iterator other)
const_iterator(carto::VolumeRef< T > vol, int y, int z, int t)
LowLevelStorage & storage()
iterator(carto::VolumeRef< T > vol, int y, int z, int t)
static Point3d position3d(const const_iterator &i, const typename const_LowLevelStorage::const_iterator &iv)
void setValue(const T &value, const Point3d &p)
const T & at(int x, int y=0, int z=0, int t=0) const
carto::PropertySet & header()
carto::VolumeRef< T > data() const
const T & at(const Point3d &p) const
void setValue(const T &value, int x, int y=0, int z=0, int t=0)
static Point4d position(const const_iterator &i, const typename const_LowLevelStorage::const_iterator &iv)
static const T & at(const typename const_LowLevelStorage::const_iterator &iv)
const T & checkedAt(const Point3d &p) const
checks volume bounds before returning value
const_iterator end() const
const T & background() const
void setBackground(const T &value)
const carto::PropertySet & header() const
const_iterator begin() const
void fill(const T &value)
virtual void copyHeaderFrom(const PropertySet &other)
const AllocatorContext & allocatorContext() const
rc_ptr< Volume< T > > refVolume() const
void fill(const T &value)
int operator==(const AimsBucketItem< T > &thing1, const AimsBucketItem< T > &thing2)
The class for EcatSino data write operation.
Quaternion operator*(const Quaternion &a, const Quaternion &b)