aimsdata  4.7.0
Neuroimaging data handling
sparsevolume.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 #ifndef AIMS_data_SPARSEVOLUME_H
35 #define AIMS_data_SPARSEVOLUME_H
36 
37 #include <aims/bucket/bucket.h>
39 
40 namespace aims
41 {
42 
43  template <typename T>
45  {
46  public:
47  };
48 
49 
50  template <typename T>
51  class SparseVolume<carto::Volume<T> >
52  {
53  public:
54  class LowLevelStorage
55  {
56  public:
57  typedef T* iterator;
58  typedef const T* const_iterator;
59 
60  LowLevelStorage() : _begin(0), _end(0) {}
61  LowLevelStorage( carto::VolumeRef<T> vol, int y, int z, int t )
62  : _volume( vol ), _begin( &vol->at( 0, y, z, t ) ),
63  _end( &vol->at( vol->getSizeX(), y, z, t ) )
64  {}
65  iterator begin() { return _begin; }
66  const_iterator begin() const { return _begin; }
67  iterator end() { return _end; }
68  const_iterator end() const { return _end; }
69  carto::VolumeRef<T> volume() const { return _volume; }
70 
71  private:
72  carto::VolumeRef<T> _volume;
73  T* _begin;
74  T* _end;
75  };
76 
77 
78  class const_LowLevelStorage
79  {
80  public:
81  typedef const T* const_iterator;
82 
83  const_LowLevelStorage() : _begin(0), _end(0) {}
84  const_LowLevelStorage( const carto::VolumeRef<T> vol, int y, int z,
85  int t )
86  : _volume( vol ), _begin( &vol->at( 0, y, z, t ) ),
87  _end( &vol->at( vol->getSizeX(), y, z, t ) )
88  {}
89  const_LowLevelStorage( const LowLevelStorage & other )
90  : _volume( other.volume() ), _begin( other.begin() ),
91  _end( other.end() )
92  {}
93  const_iterator begin() const { return _begin; }
94  const_iterator end() const { return _end; }
95  carto::VolumeRef<T> volume() const { return _volume; }
96 
97  private:
98  carto::VolumeRef<T> _volume;
99  const T* _begin;
100  const T* _end;
101  };
102 
103 
104  class iterator
105  {
106  public:
107  iterator() : _pos( Point4d( 0, 0, 0 ), LowLevelStorage() ) {}
108  iterator( carto::VolumeRef<T> vol, int y, int z, int t )
109  : _pos( Point4d( 0, y, z, t ), LowLevelStorage( vol, y, z, t ) ) {}
110  std::pair<Point4d, LowLevelStorage> & operator * ()
111  { return _pos; }
112  std::pair<Point4d, LowLevelStorage> *operator -> ()
113  { return &_pos; }
114  LowLevelStorage & storage() { return _pos.second; }
115  bool operator == ( const iterator & x ) const
116  {
117  return &_pos.second.volume()->at( 0, _pos.first[1], _pos.first[2],
118  _pos.first[3] )
119  == &x._pos.second.volume()->at( 0, x._pos.first[1], x._pos.first[2],
120  x._pos.first[3] );
121  }
122  bool operator != ( const iterator & x ) const
123  { return !( *this == x ); }
124  iterator & operator ++ ()
125  {
126  int16_t & y = _pos.first[1];
127  int16_t & z = _pos.first[2];
128  int16_t & t = _pos.first[3];
129  ++y;
130  if( y >= _pos.second.volume()->getSizeY() )
131  {
132  y = 0;
133  ++z;
134  if( z >= _pos.second.volume()->getSizeZ() )
135  {
136  z = 0;
137  ++t;
138  }
139  }
140  _pos.second = LowLevelStorage( _pos.second.volume(), y, z, t );
141  return *this;
142  }
143 
144  private:
145  std::pair<Point4d, LowLevelStorage> _pos;
146  };
147 
148  class const_iterator
149  {
150  public:
151  const_iterator() : _pos( Point4d( 0, 0, 0 ), const_LowLevelStorage() ) {}
152  const_iterator( carto::VolumeRef<T> vol, int y, int z, int t )
153  : _pos( Point4d( 0, y, z, t ), const_LowLevelStorage( vol, y, z, t ) )
154  {}
155  const_iterator( iterator other )
156  : _pos( other->first, other->second )
157  {}
158  const std::pair<Point4d, const_LowLevelStorage> & operator * () const
159  { return _pos; }
160  const std::pair<Point4d, const_LowLevelStorage> *operator -> () const
161  { return &_pos; }
162  const const_LowLevelStorage & storage() const { return _pos.second; }
163  bool operator == ( const const_iterator & x ) const
164  {
165  return &_pos.second.volume()->at( 0, _pos.first[1], _pos.first[2],
166  _pos.first[3] )
167  == &x._pos.second.volume()->at( 0, x._pos.first[1],
168  x._pos.first[2], x._pos.first[3] );
169  }
170  bool operator != ( const const_iterator & x ) const
171  { return !( *this == x ); }
172  const_iterator & operator ++ ()
173  {
174  int16_t & y = _pos.first[1];
175  int16_t & z = _pos.first[2];
176  int16_t & t = _pos.first[3];
177  ++y;
178  if( y >= _pos.second.volume()->getSizeY() )
179  {
180  y = 0;
181  ++z;
182  if( z >= _pos.second.volume()->getSizeZ() )
183  {
184  z = 0;
185  ++t;
186  }
187  }
188  _pos.second = const_LowLevelStorage( _pos.second.volume(), y, z, t );
189  return *this;
190  }
191 
192  private:
193  std::pair<Point4d, const_LowLevelStorage> _pos;
194  };
195 
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 );
200  SparseVolume( const carto::VolumeRef< T >& other );
201  SparseVolume( const carto::Volume< T >& other );
203  virtual ~SparseVolume();
204  carto::VolumeRef<T> data() const { return _data; }
205  void reset( carto::Volume<T> *x );
206  template <typename U>
207  static SparseVolume<carto::Volume<T> > alloc(
208  const SparseVolume<carto::Volume<U> > & other );
209  const T & background() const { return _background; }
210  void setBackground( const T & value ) { _background = value; }
211  std::vector<int> getSize() const;
212  const carto::PropertySet& header() const
213  { return _data->header(); }
214  carto::PropertySet& header() { return _data->header(); }
215  std::vector<float> voxelSize() const;
216 
217  void fill( const T & value )
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; }
228  const T & at( const Point3d & p ) const
229  { return _data->at( p[0], p[1], p[2], 0 ); }
230  void setValue( const T & value, const Point3d & p )
231  { _data->at( p[0], p[1], p[2], 0 ) = value; }
233  const T & checkedAt( const Point3d & p ) const
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;
236  static Point4d position
237  ( const const_iterator & i,
238  const typename const_LowLevelStorage::const_iterator & iv )
239  { Point4d x( i->first ); x[0] = iv - i->storage().begin(); return x; }
240  static Point3d position3d
241  ( const const_iterator & i,
242  const typename const_LowLevelStorage::const_iterator & iv )
243  { return Point3d( iv - i->second.begin(), i->first[1], i->first[2] ); }
244  static const T & at
246  { return *iv; }
247 
248  private:
249  carto::VolumeRef<T> _data;
250  T _background;
251  };
252 
253 
254  template <typename T>
256  {
257  public:
258  typedef T VoxelType;
263 
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 );
267  SparseVolume( const carto::rc_ptr<BucketMap<T> >& other );
268  SparseVolume( const BucketMap< T >& other );
269  virtual ~SparseVolume();
270  carto::rc_ptr<BucketMap<T> > data() const { return _data; }
271  void reset( BucketMap<T> *x );
272  template <typename U>
273  static SparseVolume<BucketMap<T> > alloc(
274  const SparseVolume<BucketMap<U> > & other );
275  const T & background() const { return _background; }
276  void setBackground( const T & x ) { _background = x; }
277  std::vector<int> getSize() const;
278  const carto::PropertySet& header() const
279  { return _data->header().getValue(); }
281  { return _data->header().getValue(); }
282  std::vector<float> voxelSize() const;
283 
284  void fill( const T& value )
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 );
292  const T & checkedAt( const Point3d & p ) const
293  { return at( p ); }
294  const T & checkedAt( int x, int y = 0, int z = 0 ) const
295  { return at( x, y, z ); }
296  const T & checkedAt( int x, int y, int z, int t ) const
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; }
306  static const T & at
307  ( const typename const_LowLevelStorage::const_iterator & iv )
308  { return iv->second; }
309 
310  private:
312  mutable typename BucketMap<T>::Bucket *_firstbck;
313  T _background;
314  };
315 
316 
317  template <>
319  {
320  public:
321  typedef int VoxelType;
326 
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 );
330  SparseVolume( const carto::rc_ptr<BucketMap<Void> > & other );
331  SparseVolume( const BucketMap<Void> & other );
332  virtual ~SparseVolume();
333  carto::rc_ptr<BucketMap<Void> > data() const { return _data; }
334  void reset( BucketMap<Void> *x );
335  template <typename U>
336  static SparseVolume<BucketMap<Void> > alloc(
337  const SparseVolume<BucketMap<U> > & other );
338  const VoxelType & background() const { return _background; }
339  void setBackground( const VoxelType & x ) { _background = x; }
340  std::vector<int> getSize() const;
341  const carto::PropertySet& header() const
342  { return _data->header().getValue(); }
344  { return _data->header().getValue(); }
345  std::vector<float> voxelSize() const;
346 
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,
351  int t = 0 );
352  const VoxelType & at( const Point3d & p ) const;
353  void setValue( const VoxelType & value, const Point3d & p );
354  const VoxelType & checkedAt( const Point3d & p ) const
355  { return at( 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
369  & iv )
370  { return iv->second; }
371 
372  private:
374  VoxelType _background;
375  };
376 
377 
378  // ---
379 
380  template <typename T>
381  inline
383  int sizeZ, int sizeT,
384  const carto::AllocatorContext&
385  allocatorContext,
386  bool allocated )
387  : _data( sizeX, sizeY, sizeZ, sizeT, allocatorContext, allocated ),
388  _background( 0 )
389  {
390  if( allocated )
391  _data->fill( _background );
392  }
393 
394 
395  template <typename T>
396  inline
398  int sizeZ, int sizeT,
399  T* buffer )
400  : _data( new carto::Volume<T>( sizeX, sizeY, sizeZ, sizeT, buffer ) ),
401  _background( 0 )
402  {
403  }
404 
405 
406  template <typename T>
407  inline
409  other )
410  : _data( other ),
411  _background( 0 )
412  {
413  }
414 
415 
416  template <typename T>
417  inline
419  other )
420  : _data( new carto::Volume<T>( other ) ),
421  _background( 0 )
422  {
423  }
424 
425 
426  template <typename T>
427  inline
430  : _data( x ),
431  _background( 0 )
432  {
433  }
434 
435 
436  template <typename T>
437  inline
438  SparseVolume<carto::Volume<T> >::~SparseVolume()
439  {
440  }
441 
442 
443  template <typename T>
444  inline
445  std::vector<int> SparseVolume<carto::Volume<T> >::getSize() const
446  {
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();
452 
453  return sz;
454  }
455 
456 
457  template <typename T>
458  inline
459  std::vector<float> SparseVolume<carto::Volume<T> >::voxelSize() const
460  {
461  std::vector<float> vs( 4 );
462  int i = 0;
463  try
464  {
465  carto::Object j, v = header().getProperty( "voxel_size" );
466  for( j=v->objectIterator(); j->isValid(); j->next(), ++i )
467  vs[i] = j->currentValue()->getScalar();
468  }
469  catch( ... )
470  {
471  }
472  for( ; i<4; ++i )
473  vs[i] = 1.;
474  return vs;
475  }
476 
477 
478  template <typename T>
479  inline const T &
480  SparseVolume<carto::Volume<T> >::checkedAt( int x, int y, int z,
481  int t ) const
482  {
483  if( x < 0 || y < 0 || z < 0 || t < 0 || x >= _data->getSizeX()
484  || y >= _data->getSizeY() || z >= _data->getSizeZ()
485  || t >= _data->getSizeT() )
486  return _background;
487  return _data->at( x, y, z, t );
488  }
489 
490 
491  template <typename T>
492  inline void
494  {
495  _data.reset( d );
496  }
497 
498 
499  template <typename T> template <typename U>
502  ( const SparseVolume<carto::Volume<U> > & other )
503  {
504  carto::Volume<U> & src = *other.data();
505  carto::Volume<T> *data = new carto::Volume<T>( src.getSizeX(),
506  src.getSizeY(), src.getSizeZ(), src.getSizeT(),
507  src.allocatorContext() );
508  data->header() = src.header();
509  data->fill( other.background() );
510  SparseVolume<carto::Volume<T> > svol( data );
511  svol.setBackground( other.background() );
512  return svol;
513  }
514 
515 
516  // ------
517 
518  template <typename T>
519  inline
521  const carto::AllocatorContext&,
522  bool )
523  : _data( new BucketMap<T> ),
524  _background( 0 )
525  {
526  typename BucketMap<T>::iterator i = _data->find( 0 );
527  if( i != _data->end() )
528  _firstbck = &i->second;
529  else
530  _firstbck = 0;
531  }
532 
533 
534  template <typename T>
535  inline
537  & other )
538  : _data( other ),
539  _background( 0 )
540  {
541  typename BucketMap<T>::iterator i = _data->find( 0 );
542  if( i != _data->end() )
543  _firstbck = &i->second;
544  else
545  _firstbck = 0;
546  }
547 
548 
549  template <typename T>
550  inline
552  : _data( new BucketMap<T>( other ) ),
553  _background( 0 )
554  {
555  typename BucketMap<T>::iterator i = _data->find( 0 );
556  if( i != _data->end() )
557  _firstbck = &i->second;
558  else
559  _firstbck = 0;
560  }
561 
562 
563  template <typename T>
564  inline
565  SparseVolume<BucketMap<T> >::~SparseVolume()
566  {
567  }
568 
569 
570  template <typename T>
571  inline std::vector<int>
572  SparseVolume<BucketMap<T> >::getSize() const
573  {
574  std::vector<int> sz(4);
575  if( _data->empty() )
576  {
577  sz[0] = 0;
578  sz[1] = 0;
579  sz[2] = 0;
580  sz[3] = 0;
581  return sz;
582  }
583  sz[3] = _data->rbegin()->first + 1;
584  int & x = sz[0];
585  int & y = sz[1];
586  int & z = sz[2];
587  typename BucketMap<T>::const_iterator ib, eb = _data->end();
589  for( ib=_data->begin(); ib!=eb; ++ib )
590  for( i=ib->second.begin(), e=ib->second.end(); i!=e; ++i )
591  {
592  const Point3d & p = i->first;
593  if( p[0] > x )
594  x = p[0];
595  if( p[1] > y )
596  y = p[1];
597  if( p[2] > z )
598  z = p[2];
599  }
600  ++x;
601  ++y;
602  ++z;
603 
604  return sz;
605  }
606 
607 
608  template <typename T>
609  inline
610  std::vector<float> SparseVolume<BucketMap<T> >::voxelSize() const
611  {
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();
617  return vs;
618  }
619 
620 
621  template <typename T>
622  inline const T &
623  SparseVolume<BucketMap<T> >::at( int x, int y, int z, int t ) const
624  {
625  typename BucketMap<T>::const_iterator ib = _data->find( t );
626  if( ib == _data->end() )
627  return _background;
629  = ib->second.find( Point3d( x, y, z ) );
630  if( i != ib->second.end() )
631  return i->second;
632  return _background;
633  }
634 
635 
636  template <typename T>
637  inline const T &
638  SparseVolume<BucketMap<T> >::at( const Point3d & p ) const
639  {
640  if( !_firstbck )
641  return _background;
643  = _firstbck->find( p );
644  if( i != _firstbck->end() )
645  return i->second;
646  return _background;
647  }
648 
649 
650  template <typename T>
651  inline const T &
652  SparseVolume<BucketMap<T> >::at( int x, int y, int z ) const
653  {
654  return at( Point3d( x, y, z ) );
655  }
656 
657 
658  template <typename T>
659  inline void
660  SparseVolume<BucketMap<T> >::setValue( const T & value, int x, int y, int z,
661  int t )
662  {
663  (*_data)[t][ Point3d( x, y, z ) ] = value;
664  }
665 
666 
667  template <typename T>
668  inline void
669  SparseVolume<BucketMap<T> >::setValue( const T & value, const Point3d & p )
670  {
671  if( !_firstbck )
672  _firstbck = &(*_data)[0];
673  (*_firstbck)[ p ] = value;
674  }
675 
676 
677  template <typename T>
678  inline void
679  SparseVolume<BucketMap<T> >::setValue( const T & value, int x, int y, int z )
680  {
681  setValue( value, Point3d( x, y, z ) );
682  }
683 
684 
685  template <typename T>
686  inline void
688  {
689  _data.reset( d );
690  typename BucketMap<T>::iterator i = _data->find( 0 );
691  if( i != _data->end() )
692  _firstbck = &i->second;
693  else
694  _firstbck = 0;
695  }
696 
697 
698  template <typename T> template <typename U>
701  ( const SparseVolume<BucketMap<U> > & other )
702  {
703  BucketMap<U> & src = *other.data();
704  BucketMap<T> *data = new BucketMap<T>;
705  data->setSizeXYZT( src.sizeX(), src.sizeY(), src.sizeZ(), src.sizeT() );
706  data->header().getValue() = src.header().getValue();
708  }
709 
710  // --------
711 
712 
713  inline
715  ( int, int, int, int, const carto::AllocatorContext&, bool )
716  : _data( new BucketMap<Void> ),
717  _background( 0 )
718  {
719  }
720 
721 
722  inline
724  carto::rc_ptr<BucketMap<Void> > & other )
725  : _data( other ),
726  _background( 0 )
727  {
728  }
729 
730 
731  inline
733  : _data( new BucketMap<Void>( other ) ),
734  _background( 0 )
735  {
736  }
737 
738 
739  inline
740  SparseVolume<BucketMap<Void> >::~SparseVolume()
741  {
742  }
743 
744 
745  inline std::vector<int>
746  SparseVolume<BucketMap<Void> >::getSize() const
747  {
748  std::vector<int> sz(4);
749  sz[3] = _data->rbegin()->first + 1;
750  int & x = sz[0];
751  int & y = sz[1];
752  int & z = sz[2];
753  BucketMap<Void>::const_iterator ib, eb = _data->end();
755  for( ib=_data->begin(); ib!=eb; ++ib )
756  for( i=ib->second.begin(), e=ib->second.end(); i!=e; ++i )
757  {
758  const Point3d & p = i->first;
759  if( p[0] > x )
760  x = p[0];
761  if( p[1] > y )
762  y = p[1];
763  if( p[2] > z )
764  z = p[2];
765  }
766  ++x;
767  ++y;
768  ++z;
769 
770  return sz;
771  }
772 
773 
774  inline
775  std::vector<float> SparseVolume<BucketMap<Void> >::voxelSize() const
776  {
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();
782  return vs;
783  }
784 
785 
786  inline const int &
787  SparseVolume<BucketMap<Void> >::at( int x, int y, int z, int ) const
788  {
789  return at( Point3d( x, y, z ) );
790  }
791 
792 
793  inline const int &
794  SparseVolume<BucketMap<Void> >::at( const Point3d & p ) const
795  {
796  BucketMap<Void>::const_iterator ib, eb = _data->end();
797  for( ib=_data->begin(); ib!=eb; ++ib )
798  {
800  = ib->second.find( p );
801  if( i != ib->second.end() )
802  return ib->first;
803  }
804  return _background;
805  }
806 
807 
808  inline void
809  SparseVolume<BucketMap<Void> >::setValue( const int & value, int x, int y,
810  int z, int )
811  {
812  setValue( value, Point3d( x, y, z ) );
813  }
814 
815 
816  inline void
817  SparseVolume<BucketMap<Void> >::setValue( const int & value,
818  const Point3d & p )
819  {
820  // erase first
821  BucketMap<Void>::iterator ib, eb = _data->end();
822  for( ib=_data->begin(); ib!=eb; ++ib )
823  ib->second.erase( p );
824  if( value != background() )
825  (*_data)[value][p] = Void();
826  }
827 
828 
829  inline void
831  {
832  _data.reset( d );
833  }
834 
835 
836  template <typename U>
839  ( const SparseVolume<BucketMap<U> > & other )
840  {
841  BucketMap<U> & src = *other.data();
842  BucketMap<Void> *data = new BucketMap<Void>;
843  data->setSizeXYZT( src.sizeX(), src.sizeY(), src.sizeZ(), src.sizeT() );
844  data->header().getValue() = src.header().getValue();
846  ( carto::rc_ptr<BucketMap<Void> >( data ) );
847  }
848 
849 }
850 
851 #endif
852 
853 
854 
carto::rc_ptr< BucketMap< T > > data() const
Definition: sparsevolume.h:270
const const_LowLevelStorage & storage() const
Definition: sparsevolume.h:162
const T & checkedAt(int x, int y, int z, int t) const
Definition: sparsevolume.h:296
const VoxelType & checkedAt(int x, int y=0, int z=0) const
Definition: sparsevolume.h:356
const T & at(int x, int y=0, int z=0, int t=0) const
Definition: sparsevolume.h:224
const carto::PropertySet & header() const
Definition: sparsevolume.h:212
int getSizeZ() const
const T & checkedAt(int x, int y=0, int z=0) const
Definition: sparsevolume.h:294
BucketMap< Void >::iterator iterator
Definition: sparsevolume.h:324
float sizeY() const
returns the Y resolution in mm
Definition: bucketMap.h:226
const BucketMap< Void >::Bucket const_LowLevelStorage
Definition: sparsevolume.h:323
void erase(const Point3d &pos)
Function redefined to omit time.
Definition: bucketMap.h:201
float sizeZ() const
returns the Z resolution in mm
Definition: bucketMap.h:236
BucketMap< T >::iterator iterator
Definition: sparsevolume.h:261
LowLevelStorage(carto::VolumeRef< T > vol, int y, int z, int t)
Definition: sparsevolume.h:61
float sizeX() const
returns the X resolution in mm
Definition: bucketMap.h:216
The class for EcatSino data write operation.
Definition: border.h:42
const VoxelType & checkedAt(int x, int y, int z, int t) const
Definition: sparsevolume.h:358
carto::VolumeRef< T > data() const
Definition: sparsevolume.h:204
BucketMap< T >::Bucket LowLevelStorage
Definition: sparsevolume.h:259
const AllocatorContext & allocatorContext() const
int getSizeX() const
static const Void & at(const const_LowLevelStorage::const_iterator &iv)
Definition: sparsevolume.h:368
const BucketMap< T >::Bucket const_LowLevelStorage
Definition: sparsevolume.h:260
const T & checkedAt(const Point3d &p) const
checks volume bounds before returning value
Definition: sparsevolume.h:233
An alternate, ordered, representation for buckets (voxels lists).
Definition: bucket.h:57
BucketMap< Void >::Bucket LowLevelStorage
Definition: sparsevolume.h:322
std::map< Point3d, T, BucketMapLess > Bucket
Definition: bucketMap.h:102
void fill(const T &value)
void setSizeXYZT(float sizex, float sizey, float sizez, float sizet)
sets X,Y,Z and T resolutions of the data
Definition: bucketMap.h:309
void setValue(const T &value, int x, int y=0, int z=0, int t=0)
Definition: sparsevolume.h:226
const_iterator(carto::VolumeRef< T > vol, int y, int z, int t)
Definition: sparsevolume.h:152
iterator(carto::VolumeRef< T > vol, int y, int z, int t)
Definition: sparsevolume.h:108
carto::rc_ptr< BucketMap< Void > > data() const
Definition: sparsevolume.h:333
BucketMap< T >::const_iterator const_iterator
Definition: sparsevolume.h:262
void fill(const VoxelType &value)
Definition: sparsevolume.h:347
BucketMap< Void >::const_iterator const_iterator
Definition: sparsevolume.h:325
void setValue(const T &value, const Point3d &p)
Definition: sparsevolume.h:230
const T & at(const Point3d &p) const
Definition: sparsevolume.h:228
virtual T & getValue()
std::map< int, Bucket >::iterator iterator
Definition: bucketMap.h:103
void setBackground(const VoxelType &x)
Definition: sparsevolume.h:339
float sizeT() const
returns the T resolution in s
Definition: bucketMap.h:246
std::map< int, Bucket >::const_iterator const_iterator
Definition: bucketMap.h:104
int getSizeY() const
const VoxelType & checkedAt(const Point3d &p) const
Definition: sparsevolume.h:354
const PropertySet & header() const
const_LowLevelStorage(const carto::VolumeRef< T > vol, int y, int z, int t)
Definition: sparsevolume.h:84
int getSizeT() const
const aims::PythonHeader & header() const
Definition: bucketMap.h:148
const VoxelType & background() const
Definition: sparsevolume.h:338
int operator==(const AimsBucketItem< T > &thing1, const AimsBucketItem< T > &thing2)
Definition: item.h:110
Quaternion operator*(const Quaternion &a, const Quaternion &b)
const carto::PropertySet & header() const
Definition: sparsevolume.h:278
const carto::PropertySet & header() const
Definition: sparsevolume.h:341
const T & checkedAt(const Point3d &p) const
Definition: sparsevolume.h:292