cartodata  5.1.2
volumebase_d.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 CARTODATA_VOLUME_VOLUMEBASE_D_H
35 #define CARTODATA_VOLUME_VOLUMEBASE_D_H
36 
37 //--- cartodata --------------------------------------------------------------
44 //--- cartobase --------------------------------------------------------------
45 #include <cartobase/type/limits.h>
51 //--- soma-io ----------------------------------------------------------------
53 //--- std --------------------------------------------------------------------
54 #include <cstdlib>
55 #include <algorithm>
56 #include <stdexcept>
57 #include <string>
58 #include <stdio.h>
59 //----------------------------------------------------------------------------
60 
61 namespace carto
62 {
63 //============================================================================
64 // CONSTRUCTORS
65 //============================================================================
66 
67  /***************************************************************************
68  * Default Constructor
69  **************************************************************************/
70  template < typename T >
71  Volume< T >::Volume( int sizeX, int sizeY, int sizeZ, int sizeT,
72  const AllocatorContext& allocatorContext,
73  bool allocated )
74  : VolumeProxy< T >( sizeX, sizeY, sizeZ, sizeT ),
75  _items( 0U, allocatorContext ),
76  _pos( 4, 0 )
77  {
78  allocate( -1, -1, -1, -1, allocated, allocatorContext );
79  }
80 
81  template < typename T >
83  const AllocatorContext& allocatorContext,
84  bool allocated ):
85  VolumeProxy< T >( size[0] > 0 ? size[0] : 1,
86  size[1] > 0 ? size[1] : 1,
87  size[2] > 0 ? size[2] : 1,
88  size[3] > 0 ? size[3] : 1 ),
89  _items( 0U, allocatorContext ),
90  _pos( 4, 0 )
91  {
92  allocate( -1, -1, -1, -1, allocated, allocatorContext );
93  }
94 
95  /***************************************************************************
96  * Constructor with border
97  **************************************************************************/
98 
99  template < typename T >
100  void Volume< T >::constructBorders( const Position & bordersize,
101  const AllocatorContext& allocatorContext,
102  bool allocated )
103  {
104  if( !bordersize.empty()
105  && bordersize != Position4Di().toVector() )
106  {
107  size_t i, n = VolumeProxy<T>::_size.size();
108  size_t bsize = sizeof(T);
109  std::vector<int> large_size( n );
110  for( i=0; i<n; ++i )
111  {
112  large_size[i] = VolumeProxy<T>::_size[i];
113  if( i < bordersize.size() )
114  large_size[i] += bordersize[i] * 2;
115  bsize *= VolumeProxy<T>::_size[i];
116  }
117  _refvol.reset( new Volume<T>( large_size,
118  allocatorContext, allocated ) );
119 
120  allocate( -1, -1, -1, -1, true,
121  _refvol->allocatorContext().isAllocated()
122  ? AllocatorContext( AllocatorStrategy::NotOwner,
123  rc_ptr<DataSource>( new BufferDataSource
124  ( (char *) &(*_refvol)( bordersize ),
125  bsize ) ) )
126  : allocatorContext );
127  if( _refvol->allocatorContext().isAllocated() )
128  {
129  // fix offsets
130  blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
131  int i, n=VolumeProxy<T>::_size.size();
132  for(i=0; i<n; ++i )
133  dims[i] = VolumeProxy<T>::_size[i];
134  for( ; i<Volume<T>::DIM_MAX; ++i )
135  dims[i] = 1;
136  _blitz.reference
137  ( blitz::Array<T,8>
138  ( &_items[0],
139  dims,
140  _refvol->_blitz.stride(),
141  blitz::GeneralArrayStorage<8>
142  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
143  }
144  }
145  else // no border
146  {
147  allocate( -1, -1, -1, -1, allocated, allocatorContext );
148  }
149  }
150 
151  template < typename T >
152  Volume< T >::Volume( int sizeX, int sizeY, int sizeZ, int sizeT,
153  const Position4Di & bordersize,
154  const AllocatorContext& allocatorContext,
155  bool allocated )
156  : VolumeProxy< T >( sizeX, sizeY, sizeZ, sizeT ),
157  _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
158  DataSource::none() ) ),
159  _pos( bordersize.toVector() )
160  {
161  constructBorders( bordersize.toVector(), allocatorContext, allocated );
162  }
163 
164  template < typename T >
166  const Position4Di & bordersize,
167  const AllocatorContext& allocatorContext,
168  bool allocated ):
169  VolumeProxy< T >( size[0] > 0 ? size[0] : 1,
170  size[1] > 0 ? size[1] : 1,
171  size[2] > 0 ? size[2] : 1,
172  size[3] > 0 ? size[3] : 1 ),
173  _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
174  DataSource::none() ) ),
175  _pos( bordersize.toVector() )
176  {
177  constructBorders( bordersize.toVector(), allocatorContext, allocated );
178  }
179 
180  template < typename T >
181  Volume< T >::Volume( int sizeX, int sizeY, int sizeZ,
182  int sizeT, int bordersize,
183  const AllocatorContext& allocatorContext,
184  bool allocated )
185  : VolumeProxy< T >( sizeX, sizeY, sizeZ, sizeT ),
186  _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
187  DataSource::none() ) ),
188  _pos( 4, 0 )
189  {
190  _pos[0] = bordersize;
191  _pos[1] = bordersize;
192  _pos[2] = bordersize;
193 
195  Position4Di( bordersize, bordersize, bordersize, 0 ).toVector(),
196  allocatorContext, allocated );
197  }
198 
199  template < typename T >
201  int bordersize,
202  const AllocatorContext& allocatorContext,
203  bool allocated ):
204  VolumeProxy< T >( size[0] > 0 ? size[0] : 1,
205  size[1] > 0 ? size[1] : 1,
206  size[2] > 0 ? size[2] : 1,
207  size[3] > 0 ? size[3] : 1 ),
208  _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
209  DataSource::none() ) ),
210  _pos( 4, 0 )
211  {
212  _pos[0] = bordersize;
213  _pos[1] = bordersize;
214  _pos[2] = bordersize;
216  Position4Di( bordersize, bordersize, bordersize, 0 ).toVector(),
217  allocatorContext, allocated );
218  }
219 
220 
221  template < typename T >
222  Volume< T >::Volume( const std::vector<int> & size,
223  const AllocatorContext& allocatorContext,
224  bool allocated ):
225  VolumeProxy< T >( size ),
226  _items( 0U, allocatorContext ),
227  _pos( 4, 0 )
228  {
229  allocate( std::vector<int>( 1, -1 ), allocated, allocatorContext );
230  }
231 
232 
233  template < typename T >
234  Volume< T >::Volume( const std::vector<int> & size,
235  const std::vector<int> & bordersize,
236  const AllocatorContext& allocatorContext,
237  bool allocated ):
238  VolumeProxy< T >( size ),
239  _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
240  DataSource::none() ) ),
241  _pos( bordersize )
242  {
243  while( _pos.size() < 4 )
244  _pos.push_back( 0 );
245  constructBorders( bordersize, allocatorContext, allocated );
246  }
247 
248  /***************************************************************************
249  * Buffer Constructor
250  **************************************************************************/
251  template < typename T >
252  Volume< T >::Volume( int sizeX, int sizeY, int sizeZ, int sizeT, T* buffer,
253  const std::vector<size_t> *strides )
254  : VolumeProxy< T >( sizeX, sizeY, sizeZ, sizeT ),
255  _items( sizeX * sizeY * sizeZ * sizeT, buffer ),
256  _pos( 4, 0 )
257  {
258  allocate( -1, -1, -1, -1, true, allocatorContext(), strides );
259  }
260 
261 
262  template < typename T >
263  Volume< T >::Volume( const Position4Di & size, T* buffer,
264  const std::vector<size_t> *strides ):
265  VolumeProxy< T >( size[0] > 0 ? size[0] : 1,
266  size[1] > 0 ? size[1] : 1,
267  size[2] > 0 ? size[2] : 1,
268  size[3] > 0 ? size[3] : 1 ),
269  _items( (long)(size[0] > 0 ? size[0] : 1) *
270  (long)(size[1] > 0 ? size[1] : 1) *
271  (long)(size[2] > 0 ? size[2] : 1) *
272  (long)(size[3] > 0 ? size[3] : 1), buffer ),
273  _pos( 4, 0 )
274  {
275  allocate( -1, -1, -1, -1, true, allocatorContext(), strides );
276  }
277 
278 
279  template < typename T >
280  Volume< T >::Volume( const std::vector<int> & size, T* buffer,
281  const std::vector<size_t> *strides ):
282  VolumeProxy< T >( size ),
283  _items( (long) Position4Di::size_num_elements( size ), buffer ),
284  _pos( 4, 0 )
285  {
286  allocate( std::vector<int>( 1, -1 ), true, allocatorContext(), strides );
287  }
288 
289 
290  /***************************************************************************
291  * View Constructor
292  **************************************************************************/
293  template<typename T> inline
295  const Position4Di & pos, const Position4Di & size,
296  const AllocatorContext & allocContext )
297  : VolumeProxy<T>( size[0] >= 0 ? size[0] :
298  other->allocatorContext().isAllocated() ? other->getSizeX() : 1,
299  size[1] >= 0 ? size[1] :
300  other->allocatorContext().isAllocated() ? other->getSizeY() : 1,
301  size[2] >= 0 ? size[2] :
302  other->allocatorContext().isAllocated() ? other->getSizeZ() : 1,
303  size[3] >= 0 ? size[3] :
304  other->allocatorContext().isAllocated() ? other->getSizeT() : 1 ),
305  _items( 0U, allocContext ),
306  _refvol( other ),
307  _pos( pos.toVector() )
308  {
309  if( other->allocatorContext().isAllocated() )
310  {
311  size_t bsize = sizeof(T);
312  int i, n = size.size();
313  for( i=0; i<n; ++i )
314  bsize *= size[i];
315 
316  allocate( -1, -1, -1, -1, true,
317  AllocatorContext( AllocatorStrategy::NotOwner,
318  rc_ptr<DataSource>( new BufferDataSource
319  ( (char *) &(*other)( pos.toVector() ),
320  bsize ) ) ) );
321  // fix offsets
322  blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
323  n = VolumeProxy<T>::_size.size();
324  for( i=0; i<n; ++i )
325  dims[i] = VolumeProxy<T>::_size[i];
326  for( ; i<Volume<T>::DIM_MAX; ++i )
327  dims[i] = 1;
328  _blitz.reference
329  ( blitz::Array<T,Volume<T>::DIM_MAX>
330  ( &_items[0],
331  dims,
332  other->_blitz.stride(),
333  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
334  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
335  }
336  else
337  allocate( -1, -1, -1, -1, true, allocContext );
338 
339  /* copy voxel_size from underlying volume, if any.
340  This should probably be more general, but cannot be applied to all
341  header properties (size, transformations...).
342  WARNING: Moreover here we do not guarantee to keep both voxel_size
343  unique: we point to the same vector of values for now, but it can be
344  replaced (thus, duplicated) by a setProperty().
345  We could use a addBuiltinProperty(), but then the voxel size has to be
346  stored in a fixed location somewhere.
347  */
348  try
349  {
350  carto::Object vs = other->header().getProperty( "voxel_size" );
351  size_t n = this->getSize().size();
352  if( vs->size() > n )
353  {
354  // drop additional sizes
355  size_t i;
356  std::vector<carto::Object> vs2( n );
357  for( i=0; i<n; ++i )
358  vs2[i] = vs->getArrayItem( i );
359  this->header().setProperty( "voxel_size", vs2 );
360  }
361  else
362  this->header().setProperty( "voxel_size", vs );
363  }
364  catch( ... )
365  {
366  // never mind.
367  }
368  }
369 
370 
371  template<typename T> inline
373  const Position & pos, const Position & size,
374  const AllocatorContext & allocContext )
375  : VolumeProxy<T>( Position4Di::fixed_size( size ) ),
376  _items( 0U, allocContext ),
377  _refvol( other ),
378  _pos( Position4Di::fixed_position( pos ) )
379  {
380  if( other->allocatorContext().isAllocated() )
381  {
382  size_t bsize = sizeof(T);
383  int i, n = size.size();
384  for( i=0; i<n; ++i )
385  bsize *= size[i];
386 
387  allocate( -1, -1, -1, -1, true,
388  AllocatorContext( AllocatorStrategy::NotOwner,
389  rc_ptr<DataSource>( new BufferDataSource
390  ( (char *) &(*other)( pos ),
391  bsize ) ) ) );
392 
393  // fix offsets
394  blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
395  n = VolumeProxy<T>::_size.size();
396  for(i=0; i<n; ++i )
397  dims[i] = VolumeProxy<T>::_size[i];
398  for( ; i<Volume<T>::DIM_MAX; ++i )
399  dims[i] = 1;
400  _blitz.reference
401  ( blitz::Array<T,Volume<T>::DIM_MAX>
402  ( &_items[0],
403  dims,
404  other->_blitz.stride(),
405  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
406  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
407  }
408  else
409  allocate( -1, -1, -1, -1, true, allocContext );
410 
411  /* copy voxel_size from underlying volume, if any.
412  This should probably be more general, but cannot be applied to all
413  header properties (size, transformations...).
414  WARNING: Moreover here we do not guarantee to keep both voxel_size
415  unique: we point to the same vector of values for now, but it can be
416  replaced (thus, duplicated) by a setProperty().
417  We could use a addBuiltinProperty(), but then the voxel size has to be
418  stored in a fixed location somewhere.
419  */
420  try
421  {
422  carto::Object vs = other->header().getProperty( "voxel_size" );
423  size_t n = this->getSize().size();
424  if( vs->size() > n )
425  {
426  // drop additional sizes
427  size_t i;
428  std::vector<carto::Object> vs2( n );
429  for( i=0; i<n; ++i )
430  vs2[i] = vs->getArrayItem( i );
431  this->header().setProperty( "voxel_size", vs2 );
432  }
433  else
434  this->header().setProperty( "voxel_size", vs );
435  }
436  catch( ... )
437  {
438  // never mind.
439  }
440  }
441 
442 
443  // view + buffer (only for IO)
444 
445  template < typename T >
447  const Position & size, T* buffer,
448  const std::vector<size_t> & strides )
449  : VolumeProxy<T>( size ),
450  _items( (long) Position4Di::size_num_elements( size ), buffer ),
451  _refvol( other ),
452  _pos( pos )
453  {
454  allocate( -1, -1, -1, -1, true, allocatorContext(), &strides );
455  }
456 
457 
458  /***************************************************************************
459  * Copy Constructor
460  **************************************************************************/
461  template < typename T >
463  : RCObject(),
464  VolumeProxy< T >( other ),
465  _items( other._items ),
466 
467  // TODO: test blitz ownership / strides
468  // _blitz = other.blitz;
469  _blitz( &_items[0],
470  other._blitz.shape(),
471  other._blitz.stride(),
472  blitz::GeneralArrayStorage<8>
473  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ),
474  _refvol( other.refVolume().get() ?
475  new Volume<T>( *other.refVolume() ) : 0 ),
476  _pos( other.posInRefVolume() )
477  {
478  if( _refvol.get() ) // view case: the underlying volume is copied.
479  {
480  Position4Di pos = other.posInRefVolume();
481  std::vector<int> oldSize(1, -1);
482  allocate( oldSize, true, _refvol->allocatorContext().isAllocated()
483  ? AllocatorContext( AllocatorStrategy::NotOwner,
484  rc_ptr<DataSource>( new BufferDataSource
485  ( (char *) &(*_refvol)( pos[0], pos[1], pos[2], pos[3] ),
489  * sizeof(T) ) ) )
490  : AllocatorContext( other.allocatorContext() ) );
491  if( _refvol->allocatorContext().isAllocated() )
492  {
493  // fix offsets
494  blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
495  int i, n=VolumeProxy<T>::_size.size();
496  for( i=0; i<n; ++i )
497  dims[i] = VolumeProxy<T>::_size[i];
498  for( ; i<Volume<T>::DIM_MAX; ++i )
499  dims[i] = 1;
500  _blitz.reference
501  ( blitz::Array<T,Volume<T>::DIM_MAX>
502  ( &_items[0],
503  dims,
504  other._blitz.stride(),
505  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
506  ( blitz::shape( 0, 1, 2, 3, 5, 6, 7, 8 ), true ) ) );
507  }
508  }
509  }
510 
511  template < typename T >
513  {
514  }
515 
516 //============================================================================
517 // M E T H O D S
518 //============================================================================
519 
520  template < typename T > inline
521  const AllocatorContext& Volume<T>::allocatorContext() const
522  {
523  return _items.allocatorContext();
524  }
525 
526  template <typename T> inline
528  {
529  return _refvol;
530  }
531 
532  template <typename T> inline
534  {
535  return _pos;
536  }
537 
538  template <typename T>
539  inline
541  int l = 0;
542  rc_ptr<Volume<T> > v(const_cast<Volume<T> *>(this));
543  while (!v.isNull()) {
544  l++;
545  v = v->refVolume();
546  }
547  return l;
548  }
549 
550  template <typename T>
551  inline
552  int Volume<T>::refLevel(const int level) const {
553  int c = getLevelsCount();
554  int l = level;
555  if (l < 0) {
556  l = c + l;
557  }
558 
559  if ((l < 0) && (l >= c)) {
560  throw std::out_of_range("level " + carto::toString(level)
561  + " is out range (" + carto::toString(-c)
562  + ", " + carto::toString(c-1) + ")");
563  }
564 
565  return l;
566  }
567 
568  template <typename T>
569  inline
571  int l = refLevel(level);
572  int c = 0;
573  rc_ptr<Volume<T> > v(const_cast<Volume<T> *>(this));
574 
575  while ((c < l) && (!v.isNull())) {
576  v = v->refVolume();
577  c++;
578  }
579 
580  return v;
581  }
582 
583  template <typename T>
584  inline
586  const int level) const {
587  int l = refLevel(level);
588  size_t s = this->getSize().size();
589  typename Volume<T>::Position offset(s, 0);
590  int c = 0;
591  rc_ptr<Volume<T> > v(const_cast<Volume<T> *>(this));
592  while ((c < l) && (!v.isNull())) {
593  const Position & pos = v->posInRefVolume();
594 
595  for (size_t i = 0; i < s; ++i)
596  offset[i] += pos[i];
597 
598  v = v->refVolume();
599  c++;
600  }
601 
602  return offset;
603  }
604 
605  template <typename T> inline
607  {
608 
609  if ( !allocatorContext().isAllocated()
610  || (allocatorContext().accessMode() == AllocatorStrategy::NotOwner) )
611  {
612 
613  // Free old buffer
614  _items.free();
615 
616  if (_refvol.get())
617  {
618  // Recreate items buffer that reference volume
619  // using correct sizes and position
620  if( _refvol->allocatorContext().isAllocated() )
621  {
622  size_t size = sizeof(T);
623  int i, n = VolumeProxy<T>::_size.size();
624  for( i=0; i<n; ++i )
625  size *= VolumeProxy<T>::_size[i];
626  _items.allocate(
627  0U,
628  AllocatorContext( AllocatorStrategy::NotOwner,
629  rc_ptr<DataSource>( new BufferDataSource
630  ( (char *) &(*(_refvol))( _pos ),
631  size ) ) ) );
632  }
633  else
634  _items.allocate( 0U, allocatorContext() );
635 
636  if ( _refvol->allocatorContext().isAllocated() )
637  {
638  // fix offsets
639  blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
640  int i, n=VolumeProxy<T>::_size.size();
641  for( i=0; i<n; ++i )
642  dims[i] = VolumeProxy<T>::_size[i];
643  for( ; i<Volume<T>::DIM_MAX; ++i )
644  dims[i] = 1;
645  _blitz.reference
646  ( blitz::Array<T,Volume<T>::DIM_MAX>
647  ( &_items[0],
648  dims,
649  _refvol->_blitz.stride(),
650  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
651  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
652  }
653 
654  /* copy voxel_size from underlying volume, if any.
655  This should probably be more general, but cannot be applied to all
656  header properties (size, transformations...).
657  WARNING: Moreover here we do not guarantee to keep both voxel_size
658  unique: we point to the same vector of values for now, but it can be
659  replaced (thus, duplicated) by a setProperty().
660  We could use a addBuiltinProperty(), but then the voxel size has to be
661  stored in a fixed location somewhere.
662  */
663  try
664  {
665  carto::Object vs = _refvol->header().getProperty( "voxel_size" );
666  this->header().setProperty( "voxel_size", vs );
667  }
668  catch( ... )
669  {
670  // never mind.
671  }
672  }
673  }
674  }
675 
676  template <typename T> inline
678  {
679  if ( pos != _pos )
680  {
681  _pos = pos.toVector();
682  updateItemsBuffer();
683  }
684  }
685 
686 
687  template <typename T> inline
689  if (pos != _pos)
690  {
691  _pos = pos;
692  while( _pos.size() < 4 )
693  _pos.push_back( 0 );
694  updateItemsBuffer();
695  }
696  }
697 
698  template <typename T> inline
699  void Volume<T>::setRefVolume( const rc_ptr<Volume<T> > & refvol) {
700  if (refvol.get() != _refvol.get()) {
701  _refvol = refvol;
702  updateItemsBuffer();
703  }
704  }
705 
706  template <typename T> inline
707  std::vector<int> Volume<T>::getBorders() const
708  {
709  std::vector<int> borders( VolumeProxy<T>::_size.size() * 2, 0 );
710  if( _refvol.get() && _refvol->allocatorContext().isAllocated() )
711  {
712  int i, n = VolumeProxy<T>::_size.size();
713  for( i=0; i<n; ++i )
714  borders[i*2 + 1] = _refvol->_size[i] - VolumeProxy<T>::_size[i];
715  for( i=0, n=_pos.size(); i<n; ++i )
716  {
717  borders[i*2] = _pos[i];
718  borders[i*2+1] -= _pos[i];
719  }
720  }
721 
722  return borders;
723  }
724 
725  template <typename T> inline
726  std::vector<size_t> Volume<T>::getStrides() const
727  {
728 
729  const blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>& bstrides = _blitz.stride();
730  int d, n = VolumeProxy<T>::_size.size();
731  std::vector<size_t> strides( n );
732  for (d = 0; d < n; ++d)
733  strides[d] = bstrides[d];
734 
735  return strides;
736  }
737 
738  template < typename T >
740  {
741  if( &other == this )
742  return *this;
743 
744  bool b = Headered::signalsBlocked();
745  if( !b )
746  Headered::blockSignals( true );
747  this->VolumeProxy< T >::operator=( other );
748  // copy buffer, preserving allocator
749  _items.copy( other._items, other.allocatorContext() );
750 
751  // TODO: test blitz ownership / strides
752  // _blitz.reference( other.blitz );
753  blitz::TinyVector<long, Volume<T>::DIM_MAX> dims;
754  int i, n = VolumeProxy<T>::_size.size();
755  for( i=0; i<n; ++i )
756  dims[i] = VolumeProxy<T>::_size[i];
757  for( ; i<Volume<T>::DIM_MAX; ++i )
758  dims[i] = 1;
759  _blitz.reference
760  ( blitz::Array<T,Volume<T>::DIM_MAX>
761  ( &_items[0],
762  dims,
763  other._blitz.stride(),
764  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
765  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
766  _refvol = other._refvol;
767  _pos = other._pos;
768 
769  initialize();
770 
771  if( !b )
772  Headered::blockSignals( false );
773 
774  return *this;
775 
776  }
777 
778  template <typename T>
779  void Volume<T>::copySubVolume( const Volume<T> & source,
780  const std::vector<int> & pos )
781  {
782  std::vector<int> size = this->getSize();
783  std::vector<int> osize = source.getSize();
784  int i;
785 
786  for( i=0; i<size.size() && i<osize.size(); ++i )
787  {
788  int ip = 0;
789  if( pos.size() > i )
790  ip = pos[i];
791  size[i] = std::min( size[i] - ip, osize[i] );
792  }
793  for( ; i<size.size(); ++i )
794  size[i] = 1;
795 
796  line_NDIterator<T> it( &at( pos ), size, this->getStrides() );
797  const_line_NDIterator<T> oit( &source.at( 0 ), size, source.getStrides() );
798  T *p, *pn;
799  const T *op;
800 
801  for( ; !it.ended(); ++it, ++oit )
802  {
803  p = &*it;
804  op = &*oit;
805  for( pn=p + it.line_length(); p!=pn;
806  it.inc_line_ptr( p ), oit.inc_line_ptr( op ) )
807  *p = *op;
808  }
809  }
810 
811  template <typename T>
812  void Volume<T>::copySubVolume( const rc_ptr<Volume<T> > & source,
813  const std::vector<int> & pos )
814  {
815  copySubVolume( *source, pos );
816  }
817 
818  template < typename T >
820  {
821 
822  return _blitz.begin();
823 
824  }
825 
826 
827  template < typename T >
829  {
830 
831  return _blitz.end();
832 
833  }
834 
835 
836  template < typename T >
838  {
839 
840  return _blitz.begin();
841 
842  }
843 
844 
845  template < typename T >
847  {
848 
849  return _blitz.end();
850 
851  }
852 
853 
854  template < typename T >
856  {
857 
858  // initializing headered stuff
859  this->Headered::initialize();
860 
861  // creating size filter
862  std::set< std::string > sizePropertyNames;
863  sizePropertyNames.insert( "sizeX" );
864  sizePropertyNames.insert( "sizeY" );
865  sizePropertyNames.insert( "sizeZ" );
866  sizePropertyNames.insert( "sizeT" );
867  sizePropertyNames.insert( "volume_dimension" );
869  sizeRcPropertyFilter( new PropertyFilter( "size", sizePropertyNames ) );
870 
871  // adding size filter to headered and connecting signal to slot
872  Headered::addPropertyFilter( sizeRcPropertyFilter );
873  Headered::connect( sizeRcPropertyFilter->getName(),
874  ::sigc::mem_fun( *this, &Volume< T >::slotSizeChanged ) );
875 
876  }
877 
878 
879  template < typename T >
880  void Volume< T >::allocate( int oldSizeX,
881  int oldSizeY,
882  int oldSizeZ,
883  int oldSizeT,
884  bool allocate,
885  const AllocatorContext& ac,
886  const std::vector<size_t> *strides )
887  {
888  std::vector<int> oldSize(4);
889  oldSize[0] = oldSizeX;
890  oldSize[1] = oldSizeY;
891  oldSize[2] = oldSizeZ;
892  oldSize[3] = oldSizeT;
893  Volume< T >::allocate( oldSize, allocate, ac, strides );
894  }
895 
896 
897  template < typename T >
898  void Volume< T >::allocate( const std::vector<int> & oldSize,
899  bool allocate,
900  const AllocatorContext& ac,
901  const std::vector<size_t> *nstrides )
902  {
903  std::vector<unsigned long long int> strides(Volume<T>::DIM_MAX, 0);
904  int i = 0, n = oldSize.size(), nn = VolumeProxy<T>::_size.size();
905 
906  unsigned long long int stride_max = 0;
907  unsigned long long int total_len = 0;
908 
909  if( nstrides )
910  {
911  for( ; i<std::min(nstrides->size(), size_t(nn)); ++i )
912  {
913  strides[i] = (*nstrides)[i];
914  if( strides[i] > stride_max )
915  stride_max = strides[i];
916  if( strides[i] * VolumeProxy<T>::_size[i] > total_len )
917  total_len = strides[i] * VolumeProxy<T>::_size[i];
918  }
919  }
920 
921  for( ; i<nn; ++i )
922  {
923  strides[i] = ( i == 0 ? 1 : VolumeProxy<T>::_size[i-1] * stride_max );
924  if( strides[i] > stride_max )
925  stride_max = strides[i];
926  if( strides[i] * VolumeProxy<T>::_size[i] > total_len )
927  total_len = strides[i] * VolumeProxy<T>::_size[i];
928  }
929  for( ; i<Volume<T>::DIM_MAX; ++i )
930  strides[i] = ( i == nn ? VolumeProxy<T>::_size[i-1] * stride_max
931  : strides[i-1] );
932 
933  if ( total_len * sizeof(T) >
934  (unsigned long long int) std::numeric_limits< size_t >::max() )
935  {
936 
937  throw std::runtime_error
938  ( std::string( "attempt to allocate a volume which size is greater "
939  "than allowed by the system (" )
940  + toString( std::numeric_limits< size_t >::max() ) + " bytes)" );
941 
942  }
943 
944  bool no_old = true;
945  for( i=0; i<n; ++i )
946  if( oldSize[i] != -1 )
947  {
948  no_old = false;
949  break;
950  }
951 
952  if ( !allocate // why !allocate ?
953  || !_items.allocatorContext().isAllocated()
954  || no_old )
955  {
956  // allocating memory space
957  _items.free();
958  if( allocate )
959  _items.allocate( ( size_t ) total_len, ac );
960  }
961  else if ( oldSize != VolumeProxy<T>::_size
962  || &ac != &_items.allocatorContext() )
963  {
964 
965  // allocating a new memory space
966  AllocatedVector<T> newItems( ( size_t ) total_len, ac );
967 
968  std::vector<int> minSize = VolumeProxy<T>::_size;
969  for( i=0; i<std::min(n, nn); ++i )
970  if( oldSize[i] < minSize[i] )
971  minSize[i] = oldSize[i];
972 
973  // preserving data
974  int x, y, z, t;
975  if( newItems.allocatorContext().allocatorType()
976  != AllocatorStrategy::ReadOnlyMap )
977  for ( t = 0; t < minSize[3]; t++ )
978  {
979 
980  for ( z = 0; z < minSize[2]; z++ )
981  {
982 
983  for ( y = 0; y < minSize[1]; y++ )
984  {
985 
986  for ( x = 0; x < minSize[0]; x++ )
987  {
988  // TODO: handle former strides with oldSize
989  newItems[ x * strides[0] +
990  y * strides[1] +
991  z * ( size_t ) strides[2] +
992  t * ( size_t ) strides[3] ] =
993  _items[ x +
994  y * oldSize[0] +
995  z * ( size_t ) oldSize[0]
996  * ( size_t ) oldSize[1] +
997  t * ( size_t ) oldSize[0] *
998  ( size_t ) oldSize[1]
999  * ( size_t ) oldSize[2] ];
1000 
1001  }
1002 
1003  }
1004 
1005  }
1006 
1007  }
1008 
1009  // copying new data to old one
1010  _items = newItems;
1011 
1012  }
1013 
1014  blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX> bstrides;
1015  if( nstrides )
1016  {
1017  for( i=0; i<nn; ++i )
1018  bstrides[i] = strides[i];
1019  int n;
1020  for( ; i<Volume<T>::DIM_MAX; ++i )
1021  {
1022  if( i < nn )
1023  n = VolumeProxy<T>::_size[i];
1024  else
1025  n = 1;
1026  bstrides[i] = ( i == 0 ? n : n * stride_max );
1027  if( strides[i] > stride_max )
1028  stride_max = bstrides[i];
1029  }
1030  }
1031 
1032  if( allocate )
1033  {
1034  // TODO: test blitz ownership / strides
1035  /*
1036  std::cout << "alloc blitz: " << VolumeProxy<T>::_size[0] << ", "
1037  << VolumeProxy<T>::_size[1] << ", "
1038  << VolumeProxy<T>::_size[2] << ", "
1039  << VolumeProxy<T>::_size[3] << std::endl;
1040  */
1041  blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1042  for( i=0; i<nn; ++i )
1043  dims[i] = VolumeProxy<T>::_size[i];
1044  for( ; i<Volume<T>::DIM_MAX; ++i )
1045  dims[i] = 1;
1046  if( nstrides)
1047  _blitz.reference( blitz::Array<T,Volume<T>::DIM_MAX>
1048  ( &_items[0],
1049  dims,
1050  bstrides,
1051  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
1052  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
1053  true ) ) );
1054  else
1055  _blitz.reference( blitz::Array<T,Volume<T>::DIM_MAX>
1056  ( &_items[0],
1057  dims,
1058  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
1059  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
1060  true ) ) );
1061  /*
1062  std::cout << &_items[0] << " / " << &_blitz( 0 ) << std::endl;
1063  std::cout << blitz::shape( VolumeProxy<T>::_size[0],
1064  VolumeProxy<T>::_size[1],
1065  VolumeProxy<T>::_size[2],
1066  VolumeProxy<T>::_size[3}] ) << std::endl;
1067  std::cout << "blitz data: " << _blitz.data() << std::endl;
1068  std::cout << "blitz ordering: " << _blitz.ordering() << std::endl;
1069  std::cout << "blitz numEl: " << _blitz.numElements() << std::endl;
1070  std::cout << "blitz strides: " << _blitz.stride() << std::endl;
1071  */
1072  }
1073  else
1074  {
1075  blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1076  for( i=0; i<nn; ++i )
1077  dims[i] = VolumeProxy<T>::_size[i];
1078  for( ; i<Volume<T>::DIM_MAX; ++i )
1079  dims[i] = 1;
1080  if( nstrides )
1081  // TODO: test blitz ownership
1082  _blitz.reference( blitz::Array<T,Volume<T>::DIM_MAX>
1083  ( 0,
1084  dims,
1085  bstrides,
1086  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
1087  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
1088  else
1089  // TODO: test blitz ownership / strides
1090  _blitz.reference( blitz::Array<T,Volume<T>::DIM_MAX>
1091  ( 0,
1092  dims,
1093  blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
1094  ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
1095  }
1096 
1097  }
1098 
1099 
1100  template < typename T >
1102  {
1103  if( !allocatorContext().isAllocated() )
1104  {
1105  std::vector<size_t> strides = getStrides();
1106  allocate( VolumeProxy<T>::getSize(), true, allocatorContext(),
1107  &strides );
1108  }
1109  }
1110 
1111 
1112  template < typename T >
1113  void Volume< T >::slotSizeChanged( const PropertyFilter& propertyFilter )
1114  {
1115 
1116  /* std::cout << "Volume< " << DataTypeCode<T>::name()
1117  << " >::slotSizeChanged"
1118  << std::endl; */
1119 
1120  std::vector<int> oldSize = VolumeProxy<T>::_size;
1121 
1122  if ( propertyFilter.hasOldValue( "sizeX" ) )
1123  {
1124 
1125  oldSize[0] =
1126  propertyFilter.getOldValue( "sizeX" )->GenericObject::value< int >();
1127 
1128  }
1129  if ( propertyFilter.hasOldValue( "sizeY" ) )
1130  {
1131 
1132  oldSize[1] =
1133  propertyFilter.getOldValue( "sizeY" )->GenericObject::value< int >();
1134 
1135  }
1136  if ( propertyFilter.hasOldValue( "sizeZ" ) )
1137  {
1138 
1139  oldSize[2] =
1140  propertyFilter.getOldValue( "sizeZ" )->GenericObject::value< int >();
1141 
1142  }
1143  if ( propertyFilter.hasOldValue( "sizeT" ) )
1144  {
1145 
1146  oldSize[3] =
1147  propertyFilter.getOldValue( "sizeT" )->GenericObject::value< int >();
1148 
1149  }
1150  /*
1151  std::cout << "old size: " << oldSize[0] << ", " << oldSize[1] << ", "
1152  << oldSize[2] << ", " << oldSize[3] << std::endl;
1153  std::cout << "new size: " << VolumeProxy<T>::_size[0] << ", "
1154  << VolumeProxy<T>::_size[1] << ", "
1155  << VolumeProxy<T>::_size[2] << ", " << VolumeProxy<T>::_size[3]
1156  << std::endl;
1157  */
1158  allocate( oldSize,
1159  _items.allocatorContext().isAllocated(), allocatorContext() );
1160 
1161  }
1162 
1163 
1164  template < typename T >
1165  void Volume< T >::reallocate( int sizeX,
1166  int sizeY,
1167  int sizeZ,
1168  int sizeT,
1169  bool keepcontents,
1170  const AllocatorContext & ac,
1171  bool alloc,
1172  const std::vector<size_t> *strides )
1173  {
1174  int oldx = VolumeProxy<T>::_size[0];
1175  int oldy = VolumeProxy<T>::_size[1];
1176  int oldz = VolumeProxy<T>::_size[2];
1177  int oldt = VolumeProxy<T>::_size[3];
1178  VolumeProxy<T>::_size.resize( 4 );
1179  VolumeProxy<T>::_size[0] = sizeX;
1180  VolumeProxy<T>::_size[1] = sizeY;
1181  VolumeProxy<T>::_size[2] = sizeZ;
1182  VolumeProxy<T>::_size[3] = sizeT;
1183  if( keepcontents || ( sizeX == oldx && sizeY == oldy && sizeZ == oldz
1184  && sizeT == oldt ) )
1185  allocate( oldx, oldy, oldz, oldt, alloc, ac, strides );
1186  else
1187  allocate( std::vector<int>(1, -1), alloc, ac, strides );
1188  // emit a signal ?
1189  }
1190 
1191  template < typename T >
1193  bool keepcontents,
1194  const AllocatorContext & ac,
1195  bool alloc,
1196  const std::vector<size_t> *strides )
1197  {
1198  return reallocate( size[0] > 0 ? size[0] : 1,
1199  size[1] > 0 ? size[1] : 1,
1200  size[2] > 0 ? size[2] : 1,
1201  size[3] > 0 ? size[3] : 1,
1202  keepcontents, ac, alloc, strides );
1203  }
1204 
1205  template < typename T >
1206  void Volume< T >::reallocate( const std::vector<int> & size,
1207  bool keepcontents,
1208  const AllocatorContext & ac,
1209  bool alloc,
1210  const std::vector<size_t> *strides )
1211  {
1212  std::vector<int> old = VolumeProxy<T>::_size;
1213 
1214  VolumeProxy<T>::_size = size;
1215  while( VolumeProxy<T>::_size.size() < 4 )
1216  VolumeProxy<T>::_size.push_back( 1 );
1217 
1219  VolumeProxy<T>::_size[0] );
1221  VolumeProxy<T>::_size[1] );
1223  VolumeProxy<T>::_size[2] );
1225  VolumeProxy<T>::_size[3] );
1226 
1227  if( keepcontents || size == old )
1228  allocate( old, alloc, ac, strides );
1229  else
1230  allocate( std::vector<int>(1, -1), alloc, ac, strides );
1231  // emit a signal ?
1232  }
1233 
1234 //============================================================================
1235 // U T I L I T I E S
1236 //============================================================================
1237 
1238  template <typename T>
1239  Volume<T>* Creator<Volume<T> >::create( Object header,
1240  const AllocatorContext & context,
1241  Object options )
1242  {
1243  std::vector<int> dims( 4, 1 );
1244  bool unalloc = false;
1245  if( !header->getProperty( "volume_dimension", dims ) )
1246  {
1247  header->getProperty( "sizeX", dims[0] );
1248  header->getProperty( "sizeY", dims[1] );
1249  header->getProperty( "sizeZ", dims[2] );
1250  header->getProperty( "sizeT", dims[3] );
1251  }
1252  options->getProperty( "unallocated", unalloc );
1253  std::vector<int> borders( 3, 0 );
1254  try {
1255  borders[0] = (int) rint( options->getProperty( "border" )->getScalar() );
1256  borders[1] = (int) rint( options->getProperty( "border" )->getScalar() );
1257  borders[2] = (int) rint( options->getProperty( "border" )->getScalar() );
1258  } catch( ... ) {}
1259  try {
1260  borders[0] = (int) rint( options->getProperty( "bx" )->getScalar() );
1261  } catch( ... ) {}
1262  try {
1263  borders[1] = (int) rint( options->getProperty( "by" )->getScalar() );
1264  } catch( ... ) {}
1265  try {
1266  borders[2] = (int) rint( options->getProperty( "bz" )->getScalar() );
1267  } catch( ... ) {}
1268 
1269  Volume<T> *obj;
1270  if( borders[0] != 0 || borders[1] != 0 || borders[2] != 0 )
1271  {
1272  std::vector<int> big_dims = dims;
1273  big_dims[0] += borders[0] * 2;
1274  big_dims[1] += borders[1] * 2;
1275  big_dims[2] += borders[2] * 2;
1276  obj = new Volume<T>( big_dims, context, !unalloc );
1277  obj = new Volume<T>( rc_ptr<Volume<T> >( obj ), borders, dims, context );
1278  }
1279  else
1280  obj = new Volume<T>( dims, context, !unalloc );
1281  obj->blockSignals( true );
1282  obj->header().copyProperties( header );
1283  // restore original sizes : temporary too...
1284  obj->blockSignals( false );
1285  return obj;
1286  }
1287 
1288  template <typename T>
1289  void Creator<Volume<T> >::setup( Volume<T> & obj, Object header,
1290  const AllocatorContext & context,
1291  Object options )
1292  {
1293  std::vector<int> dims( 4, 1 );
1294  bool unalloc = false, partial = false, keep_allocation = false;
1295  try
1296  {
1297  carto::Object p = options->getProperty( "partial_reading" );
1298  partial = bool( p->getScalar() );
1299  }
1300  catch( ... ) {}
1301  if( !partial )
1302  {
1303  if( !header->getProperty( "volume_dimension", dims ) )
1304  {
1305  header->getProperty( "sizeX", dims[0] );
1306  header->getProperty( "sizeY", dims[1] );
1307  header->getProperty( "sizeZ", dims[2] );
1308  header->getProperty( "sizeT", dims[3] );
1309  }
1310  try
1311  {
1312  carto::Object p = options->getProperty( "unallocated" );
1313  unalloc = bool( p->getScalar() );
1314  }
1315  catch( ... ) {}
1316  try
1317  {
1318  carto::Object p = options->getProperty( "keep_allocation" );
1319  keep_allocation = bool( p->getScalar() );
1320  }
1321  catch( ... ) {}
1322  if( !keep_allocation || !obj.allocatorContext().isAllocated()
1323  || obj.allocatorContext().allocatorType()
1324  != AllocatorStrategy::Unallocated )
1325  obj.reallocate( dims, false, context, !unalloc );
1326  }
1327  else
1328  {
1329  const_cast<AllocatorContext &>( obj.allocatorContext() ).setDataSource
1330  ( context.dataSource() );
1331  // preserve dimensions
1332  dims = obj.getSize();
1333  }
1334  obj.blockSignals( true );
1335  obj.header().copyProperties( header );
1336  if( partial )
1337  {
1338  // restore dimensions
1339  PropertySet & ps = obj.header();
1340  ps.setProperty( "volume_dimension", dims );
1341  ps.setProperty( "sizeX", dims[0] );
1342  ps.setProperty( "sizeY", dims[1] );
1343  ps.setProperty( "sizeZ", dims[2] );
1344  ps.setProperty( "sizeT", dims[3] );
1345  }
1346  obj.blockSignals( false );
1347  }
1348 
1349 } // namespace carto
1350 
1351 #endif // CARTODATA_VOLUME_VOLUMEBASE_D_H
virtual void copyProperties(Object source)
void blockSignals(bool)
bool signalsBlocked() const
const PropertySet & header() const
bool connect(const std::string &propertyFilterName, const PropertyFilter::Slot &slot)
void addPropertyFilter(const rc_ptr< PropertyFilter > &propertyFilter)
virtual void initialize()
Object getOldValue(const std::string &propertyName) const
bool hasOldValue(const std::string &propertyName) const
void setProperty(const std::string &, const T &)
void changeBuiltinProperty(const std::string &, T &)
VolumeProxy is the base class for volumes.
Definition: volumeproxy.h:50
VolumeProxy< T > & operator=(const VolumeProxy< T > &other)
std::vector< int > getSize() const
get the 4 dimensions in a vector
Definition: volumeproxy.h:129
std::vector< int > _size
Definition: volumeproxy.h:82
const std::vector< int > & toVector() const
Definition: volumebase.h:585
unsigned size() const
Definition: volumebase.h:584
N-D Volume main class.
Definition: volumebase.h:119
iterator begin()
Iterators returned here are the most "basic" (and fastest) iterators: they go from the first voxel li...
Definition: volumebase_d.h:819
std::vector< int > _pos
Definition: volumebase.h:535
std::vector< int > Position
Definition: volumebase.h:128
const AllocatorContext & allocatorContext() const
returns volume's AllocatorContext
Definition: volumebase_d.h:521
rc_ptr< Volume< T > > _refvol
Definition: volumebase.h:534
void setPosInRefVolume(const Position4Di &pos)
Set position in parent volume.
Definition: volumebase_d.h:677
virtual void reallocate(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, bool keepcontents=false, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocate=true, const std::vector< size_t > *strides=0)
allows resizing and changing allocator
Volume< T > & operator=(const Volume< T > &other)
Definition: volumebase_d.h:739
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
Definition: volumebase.h:142
virtual void initialize()
Initializes header info.
Definition: volumebase_d.h:855
Volume(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation.
Definition: volumebase_d.h:71
const Position & posInRefVolume() const
Get position in parent volume.
Definition: volumebase_d.h:533
void constructBorders(const Position &bordersize, const AllocatorContext &allocatorContext, bool allocated)
Definition: volumebase_d.h:100
std::vector< size_t > getStrides() const
Get strides for the volume.
Definition: volumebase_d.h:726
void allocate()
This function is only useful in the particular context of an unallocated Volume, when the constructor...
void setRefVolume(const rc_ptr< Volume< T > > &refvol)
Set parent volume.
Definition: volumebase_d.h:699
iterator end()
Definition: volumebase_d.h:828
virtual ~Volume()
Definition: volumebase_d.h:512
blitz::Array< T, Volume< T >::DIM_MAX >::iterator iterator
Definition: volumebase.h:141
Position posInRefVolumeAtLevel(const int level) const
Get position relatively to parent volume at specified level.
Definition: volumebase_d.h:585
rc_ptr< Volume< T > > refVolume() const
Get parent volume.
Definition: volumebase_d.h:527
void copySubVolume(const Volume< T > &source, const std::vector< int > &pos=std::vector< int >())
Copy voxels values from another volume.
Definition: volumebase_d.h:779
std::vector< int > getBorders() const
Get borders for the volume.
Definition: volumebase_d.h:707
int refLevel(const int level) const
Transform a level index to a valid level index in the volume hierarchy.
Definition: volumebase_d.h:552
rc_ptr< Volume< T > > refVolumeAtLevel(const int level) const
Get parent volume at a specified level in volume hierarchy.
Definition: volumebase_d.h:570
const T & at(long x, long y=0, long z=0, long t=0) const
int getLevelsCount() const
Get levels count in volume hierarchy from the current volume to the topmost volume.
Definition: volumebase_d.h:540
void slotSizeChanged(const PropertyFilter &propertyFilter)
blitz::Array< T, Volume< T >::DIM_MAX > _blitz
Definition: volumebase.h:533
void updateItemsBuffer()
Definition: volumebase_d.h:606
AllocatedVector< T > _items
Definition: volumebase.h:532
void inc_line_ptr(const T *&p) const
bool isNull() const
long line_length() const
void inc_line_ptr(T *&p) const
T * get() const
std::vector< int > minSize(const std::vector< int > &s1, const std::vector< int > &s2)
return the smallest dimensions between s1 and s2
Definition: volumeutil.h:497
std::string toString(const T &object)
T min(const Volume< T > &vol)
Returns the minimum value of the volume.
Definition: volumeutil.h:1133
Object none()