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 ) )
65 iterator
begin() {
return _begin; }
66 const_iterator
begin()
const {
return _begin; }
67 iterator
end() {
return _end; }
68 const_iterator
end()
const {
return _end; }
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() ),
93 const_iterator
begin()
const {
return _begin; }
94 const_iterator
end()
const {
return _end; }
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 ); }
298 iterator
begin() {
return data()->begin(); }
299 const_iterator
begin()
const {
return data()->begin(); }
300 iterator
end() {
return data()->end(); }
301 const_iterator
end()
const {
return data()->end(); }
302 static const Point3d & position3d
303 (
const const_iterator &,
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;
347 void fill(
const VoxelType & value )
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 );
356 const VoxelType &
checkedAt(
int x,
int y = 0,
int z = 0 )
const 357 {
return at( x, y, z ); }
358 const VoxelType &
checkedAt(
int x,
int y,
int z,
int t )
const 359 {
return at( x, y, z, t ); }
360 iterator
begin() {
return data()->begin(); }
361 const_iterator
begin()
const {
return data()->begin(); }
362 iterator
end() {
return data()->end(); }
363 const_iterator
end()
const {
return data()->end(); }
364 static const Point3d & position3d
365 (
const const_iterator &,
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>
509 data->
fill( other.background() );
511 svol.setBackground( other.background() );
518 template <
typename T>
521 const carto::AllocatorContext&,
527 if( i != _data->end() )
528 _firstbck = &i->second;
534 template <
typename T>
542 if( i != _data->end() )
543 _firstbck = &i->second;
549 template <
typename T>
556 if( i != _data->end() )
557 _firstbck = &i->second;
563 template <
typename T>
570 template <
typename T>
571 inline std::vector<int>
574 std::vector<int> sz(4);
583 sz[3] = _data->rbegin()->first + 1;
589 for( ib=_data->begin(); ib!=eb; ++ib )
590 for( i=ib->second.begin(), e=ib->second.end(); i!=e; ++i )
608 template <
typename T>
612 std::vector<float> vs( 4 );
613 vs[0] = _data->sizeX();
614 vs[1] = _data->sizeY();
615 vs[2] = _data->sizeZ();
616 vs[3] = _data->sizeT();
621 template <
typename T>
626 if( ib == _data->end() )
629 = ib->second.find(
Point3d( x, y, z ) );
630 if( i != ib->second.end() )
636 template <
typename T>
643 = _firstbck->find( p );
644 if( i != _firstbck->end() )
650 template <
typename T>
654 return at(
Point3d( x, y, z ) );
658 template <
typename T>
663 (*_data)[t][
Point3d( x, y, z ) ] = value;
667 template <
typename T>
672 _firstbck = &(*_data)[0];
673 (*_firstbck)[ p ] = value;
677 template <
typename T>
681 setValue( value,
Point3d( x, y, z ) );
685 template <
typename T>
691 if( i != _data->end() )
692 _firstbck = &i->second;
698 template <
typename T>
template <
typename U>
715 (
int,
int,
int,
int,
const carto::AllocatorContext&,
bool )
745 inline std::vector<int>
748 std::vector<int> sz(4);
749 sz[3] = _data->rbegin()->first + 1;
755 for( ib=_data->begin(); ib!=eb; ++ib )
756 for( i=ib->second.begin(), e=ib->second.end(); i!=e; ++i )
777 std::vector<float> vs( 4 );
778 vs[0] = _data->sizeX();
779 vs[1] = _data->sizeY();
780 vs[2] = _data->sizeZ();
781 vs[3] = _data->sizeT();
789 return at(
Point3d( x, y, z ) );
797 for( ib=_data->begin(); ib!=eb; ++ib )
800 = ib->second.find( p );
801 if( i != ib->second.end() )
812 setValue( value,
Point3d( x, y, z ) );
822 for( ib=_data->begin(); ib!=eb; ++ib )
823 ib->second.
erase( p );
824 if( value != background() )
825 (*_data)[value][p] =
Void();
836 template <
typename U>
const_iterator end() const
const_iterator end() const
carto::rc_ptr< BucketMap< T > > data() const
const const_LowLevelStorage & storage() const
const T & checkedAt(int x, int y, int z, int t) const
const VoxelType & checkedAt(int x, int y=0, int z=0) const
const_iterator begin() const
const T & at(int x, int y=0, int z=0, int t=0) const
const carto::PropertySet & header() const
const T & checkedAt(int x, int y=0, int z=0) const
BucketMap< Void >::iterator iterator
float sizeY() const
returns the Y resolution in mm
const BucketMap< Void >::Bucket const_LowLevelStorage
void erase(const Point3d &pos)
Function redefined to omit time.
const_iterator begin() const
carto::VolumeRef< T > volume() const
float sizeZ() const
returns the Z resolution in mm
BucketMap< T >::iterator iterator
const_iterator begin() const
LowLevelStorage(carto::VolumeRef< T > vol, int y, int z, int t)
float sizeX() const
returns the X resolution in mm
const_iterator end() const
The class for EcatSino data write operation.
const VoxelType & checkedAt(int x, int y, int z, int t) const
carto::VolumeRef< T > data() const
BucketMap< T >::Bucket LowLevelStorage
void fill(const T &value)
const T & background() const
carto::PropertySet & header()
const AllocatorContext & allocatorContext() const
static const Void & at(const const_LowLevelStorage::const_iterator &iv)
const BucketMap< T >::Bucket const_LowLevelStorage
const T & checkedAt(const Point3d &p) const
checks volume bounds before returning value
An alternate, ordered, representation for buckets (voxels lists).
BucketMap< Void >::Bucket LowLevelStorage
carto::PropertySet & header()
std::map< Point3d, T, BucketMapLess > Bucket
void fill(const T &value)
const_iterator(iterator other)
carto::PropertySet & header()
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
sets X,Y,Z and T resolutions of the data
void setValue(const T &value, int x, int y=0, int z=0, int t=0)
const_iterator(carto::VolumeRef< T > vol, int y, int z, int t)
const T & background() const
carto::VolumeRef< T > volume() const
iterator(carto::VolumeRef< T > vol, int y, int z, int t)
carto::rc_ptr< BucketMap< Void > > data() const
BucketMap< T >::const_iterator const_iterator
const_iterator begin() const
void fill(const VoxelType &value)
void setBackground(const T &value)
BucketMap< Void >::const_iterator const_iterator
const_iterator end() const
void setValue(const T &value, const Point3d &p)
const T & at(const Point3d &p) const
const_LowLevelStorage(const LowLevelStorage &other)
std::map< int, Bucket >::iterator iterator
void setBackground(const VoxelType &x)
float sizeT() const
returns the T resolution in s
std::map< int, Bucket >::const_iterator const_iterator
const_iterator end() const
const VoxelType & checkedAt(const Point3d &p) const
void setBackground(const T &x)
const_LowLevelStorage(const carto::VolumeRef< T > vol, int y, int z, int t)
const aims::PythonHeader & header() const
const_iterator begin() const
const VoxelType & background() const
int operator==(const AimsBucketItem< T > &thing1, const AimsBucketItem< T > &thing2)
Quaternion operator*(const Quaternion &a, const Quaternion &b)
const carto::PropertySet & header() const
const carto::PropertySet & header() const
void fill(const T &value)
LowLevelStorage & storage()
const T & checkedAt(const Point3d &p) const