34#ifndef AIMS_data_SPARSEVOLUME_H
35#define AIMS_data_SPARSEVOLUME_H
38#include <cartodata/volume/volume.h>
62 : _volume( vol ), _begin( &vol->
at( 0, y, z, t ) ),
63 _end( &vol->
at( vol->getSizeX(), y, z, t ) )
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() ),
110 std::pair<Point4d, LowLevelStorage> & operator * ()
112 std::pair<Point4d, LowLevelStorage> *operator -> ()
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],
123 {
return !( *
this == x ); }
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() )
145 std::pair<Point4d, LowLevelStorage> _pos;
156 : _pos( other->first, other->second )
158 const std::pair<Point4d, const_LowLevelStorage> & operator * ()
const
160 const std::pair<Point4d, const_LowLevelStorage> *operator -> ()
const
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] );
171 {
return !( *
this == x ); }
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() )
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;
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;
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;
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;
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;
610 typename BucketMap<T>::Bucket::const_iterator i, e;
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() )
650 typename BucketMap<T>::Bucket::const_iterator i
651 = ib->second.find(
Point3d( x, y, z ) );
652 if( i != ib->second.end() )
658 template <
typename T>
664 typename BucketMap<T>::Bucket::const_iterator i
665 = _firstbck->find( p );
666 if( i != _firstbck->end() )
672 template <
typename T>
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>
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;
776 BucketMap<Void>::Bucket::const_iterator i, e;
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();
819 for( ib=_data->begin(); ib!=eb; ++ib )
821 BucketMap<Void>::Bucket::const_iterator i
822 = ib->second.find( p );
823 if( i != ib->second.end() )
844 for( ib=_data->begin(); ib!=eb; ++ib )
845 ib->second.erase( p );
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
std::map< int, Bucket >::const_iterator const_iterator
const aims::PythonHeader & header() const
std::map< Point3d, T, BucketMapLess > Bucket
float sizeT() const
returns the T resolution in s
float sizeY() const
returns the Y resolution in mm
std::map< int, Bucket >::iterator iterator
float sizeX() const
returns the X resolution in mm
void fill(const T &value)
const_iterator begin() const
static SparseVolume< BucketMap< T > > alloc(const SparseVolume< BucketMap< U > > &other)
void setBackground(const T &x)
std::vector< int > getSize() const
static const T & at(const typename const_LowLevelStorage::const_iterator &iv)
static const Point3d & position3d(const const_iterator &, const typename const_LowLevelStorage::const_iterator &iv)
const T & checkedAt(const Point3d &p) const
const T & at(int x, int y, int z, int t) const
void reset(BucketMap< T > *x)
BucketMap< T >::iterator iterator
BucketMap< T >::const_iterator const_iterator
void setValue(const T &value, int x, int y, int z, int t)
const carto::PropertySet & header() const
carto::PropertySet & header()
const T & background() const
std::vector< float > voxelSize() const
carto::rc_ptr< BucketMap< T > > data() const
const_iterator end() const
BucketMap< T >::Bucket LowLevelStorage
const BucketMap< T >::Bucket const_LowLevelStorage
SparseVolume(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, const carto::AllocatorContext &allocatorContext=carto::AllocatorContext(), bool allocated=true)
const T & checkedAt(int x, int y=0, int z=0) const
const T & checkedAt(int x, int y, int z, int t) const
const_iterator begin() const
const carto::PropertySet & header() const
carto::rc_ptr< BucketMap< Void > > data() const
void setBackground(const VoxelType &x)
const VoxelType & checkedAt(const Point3d &p) const
const VoxelType & checkedAt(int x, int y, int z, int t) const
const_iterator end() const
std::vector< int > getSize() const
BucketMap< Void >::iterator iterator
static const Void & at(const const_LowLevelStorage::const_iterator &iv)
void reset(BucketMap< Void > *x)
BucketMap< Void >::const_iterator const_iterator
const VoxelType & checkedAt(int x, int y=0, int z=0) const
static const Point3d & position3d(const const_iterator &, const const_LowLevelStorage::const_iterator &iv)
std::vector< float > voxelSize() const
void fill(const VoxelType &value)
static SparseVolume< BucketMap< Void > > alloc(const SparseVolume< BucketMap< U > > &other)
const VoxelType & background() const
SparseVolume(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, const carto::AllocatorContext &allocatorContext=carto::AllocatorContext(), bool allocated=true)
carto::PropertySet & header()
void setValue(const VoxelType &value, int x, int y=0, int z=0, int t=0)
BucketMap< Void >::Bucket LowLevelStorage
const BucketMap< Void >::Bucket const_LowLevelStorage
const VoxelType & at(int x, int y=0, int z=0, int t=0) const
carto::VolumeRef< T > volume() const
const_iterator begin() const
const_iterator end() const
LowLevelStorage(carto::VolumeRef< T > vol, int y, int z, int t)
const_iterator begin() const
const_LowLevelStorage(const LowLevelStorage &other)
const_iterator end() const
carto::VolumeRef< T > volume() 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)
SparseVolume(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, const carto::AllocatorContext &allocatorContext=carto::AllocatorContext(), bool allocated=true)
static const T & at(const typename const_LowLevelStorage::const_iterator &iv)
void reset(carto::Volume< T > *x)
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(const Point3d &p) const
const carto::PropertySet & header() 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 SparseVolume< carto::Volume< T > > alloc(const SparseVolume< carto::Volume< U > > &other)
const T & at(int x, int y=0, int z=0, int t=0) const
const_iterator end() const
std::vector< float > voxelSize() const
const T & background() const
std::vector< int > getSize() const
void setBackground(const T &value)
carto::VolumeRef< T > data() const
const T & checkedAt(const Point3d &p) const
checks volume bounds before returning value
const_iterator begin() const
carto::PropertySet & header()
void fill(const T &value)
const T & at(long x, long y=0, long z=0, long t=0) const
const AllocatorContext & allocatorContext() const
rc_ptr< Volume< T > > refVolume() const
The class for EcatSino data write operation.
AimsVector< int16_t, 3 > Point3d
AimsVector< int16_t, 4 > Point4d