34#ifndef CARTODATA_VOLUME_VOLUMEBASE_D_H
35#define CARTODATA_VOLUME_VOLUMEBASE_D_H
45#include <cartobase/type/limits.h>
46#include <cartobase/type/string_conversion.h>
47#include <cartobase/object/object.h>
48#include <cartobase/object/property.h>
49#include <cartobase/object/propertyfilter.h>
50#include <cartobase/containers/nditerator.h>
51#include <cartobase/uuid/uuid.h>
71 template <
typename T >
84 template <
typename T >
89 size[1] > 0 ? size[1] : 1,
90 size[2] > 0 ? size[2] : 1,
91 size[3] > 0 ? size[3] : 1 ),
104 template <
typename T >
109 bool has_border =
false;
110 if( !bordersize.empty() )
112 size_t i, n = bordersize.size();
113 for( i=0; !has_border && i<n; ++i )
114 if( bordersize[i] != 0 )
121 size_t bsize =
sizeof(T);
122 std::vector<int> large_size( n );
126 if( i < bordersize.size() )
127 large_size[i] += bordersize[i] * 2;
134 _refvol->allocatorContext().isAllocated()
135 ? AllocatorContext( AllocatorStrategy::NotOwner,
137 ( (
char *) &(*
_refvol)( bordersize ),
140 if(
_refvol->allocatorContext().isAllocated() )
143 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
147 for( ; i<Volume<T>::DIM_MAX; ++i )
154 blitz::GeneralArrayStorage<8>
155 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
164 template <
typename T >
170 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
171 DataSource::
none() ) ),
173 _pos( bordersize.toVector() )
179 template <
typename T >
185 size[1] > 0 ? size[1] : 1,
186 size[2] > 0 ? size[2] : 1,
187 size[3] > 0 ? size[3] : 1 ),
188 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
191 _pos( bordersize.toVector() )
197 template <
typename T >
199 int sizeT,
int bordersize,
203 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
209 _pos[0] = bordersize;
210 _pos[1] = bordersize;
211 _pos[2] = bordersize;
218 template <
typename T >
224 size[1] > 0 ? size[1] : 1,
225 size[2] > 0 ? size[2] : 1,
226 size[3] > 0 ? size[3] : 1 ),
227 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
228 DataSource::
none() ) ),
234 _pos[1] = bordersize;
235 _pos[2] = bordersize;
237 Position4Di( bordersize, bordersize, bordersize, 0 ).toVector(),
242 template <
typename T >
256 template <
typename T >
258 const std::vector<int> & bordersize,
262 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
268 while(
_pos.size() < 4 )
276 template <
typename T >
278 const std::vector<long> *strides )
280 _items( sizeX * sizeY * sizeZ * sizeT, buffer ),
289 template <
typename T >
291 const std::vector<long> *strides ):
293 size[1] > 0 ? size[1] : 1,
294 size[2] > 0 ? size[2] : 1,
295 size[3] > 0 ? size[3] : 1 ),
296 _items( (long)(size[0] > 0 ? size[0] : 1) *
297 (long)(size[1] > 0 ? size[1] : 1) *
298 (long)(size[2] > 0 ? size[2] : 1) *
299 (long)(size[3] > 0 ? size[3] : 1), buffer ),
307 template <
typename T >
309 const std::vector<long> *strides ):
321 template <
typename T>
322 void _updateHeaderFromParent(
Volume<T> *vol )
339 carto::Object vs = parent->header().getProperty(
"voxel_size" );
340 size_t n = vol->
getSize().size();
345 std::vector<carto::Object> vs2( n );
347 vs2[i] = vs->getArrayItem( i );
360 while( vs.size() < 3 )
363 std::vector<float> trv( 16, 0.f );
368 trv[3] = pos[0] * vs[0];
369 trv[7] = pos[1] * vs[1];
370 trv[11] = pos[2] * vs[2];
371 AffineTransformationBase tr( trv );
373 std::string
ref = parent->referential().uuid();
374 std::vector<std::string> refs;
375 std::vector<std::vector<float> > trans;
376 refs.push_back(
ref );
377 trans.push_back( trv );
380 carto::Object tl = parent->header().getProperty(
"transformations" );
381 trans.reserve( tl->size() + 1 );
383 for( it = tl->objectIterator(); it->isValid(); it->next() )
385 AffineTransformationBase tn( it->currentValue() );
387 trans.push_back( tn.toVector() );
389 carto::Object rl = parent->header().getProperty(
"referentials" );
390 refs.reserve( rl->size() + 1 );
391 for( it = rl->objectIterator(); it->isValid(); it->next() )
392 refs.push_back( it->currentValue()->getString() );
407 template<
typename T>
inline
410 const AllocatorContext & allocContext )
413 size[1] >= 0 ? size[1] :
415 size[2] >= 0 ? size[2] :
417 size[3] >= 0 ? size[3] :
419 _items( 0U, allocContext ),
430 if( other->allocatorContext().isAllocated() )
432 size_t bsize =
sizeof(T);
433 std::vector<int> osize = other->getSize();
434 int i, n = osize.size();
439 AllocatorContext( AllocatorStrategy::NotOwner,
441 ( (
char *) &other->_items[0],
444 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
448 for( ; i<Volume<T>::DIM_MAX; ++i )
455 other->_blitz.stride(),
457 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
460 allocate( -1, -1, -1, -1,
true, allocContext );
462 _updateHeaderFromParent(
this );
466 template<
typename T>
inline
469 const AllocatorContext & allocContext )
471 _items( 0U, allocContext ),
482 if( other->allocatorContext().isAllocated() )
484 size_t bsize =
sizeof(T);
485 std::vector<int> osize = other->getSize();
486 int i, n = osize.size();
493 AllocatorContext( AllocatorStrategy::NotOwner,
495 ( (
char *) &other->_items[0],
499 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
503 for( ; i<Volume<T>::DIM_MAX; ++i )
505 _start = &(*other)( pos );
510 other->_blitz.stride(),
512 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
515 allocate( -1, -1, -1, -1,
true, allocContext );
517 _updateHeaderFromParent(
this );
523 template <
typename T >
526 const std::vector<long> & strides )
546 template <
typename T >
558 blitz::GeneralArrayStorage<8>
559 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ),
569 std::vector<int> oldSize(1, -1);
571 ? AllocatorContext( AllocatorStrategy::NotOwner,
573 ( (
char *) &(*
_refvol)( pos[0], pos[1], pos[2], pos[3] ),
579 if(
_refvol->allocatorContext().isAllocated() )
582 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
586 for( ; i<Volume<T>::DIM_MAX; ++i )
594 ( blitz::shape( 0, 1, 2, 3, 5, 6, 7, 8 ),
true ) ) );
599 template <
typename T >
608 template <
typename T >
inline
611 return _items.allocatorContext();
614 template <
typename T>
inline
620 template <
typename T>
inline
626 template <
typename T>
638 template <
typename T>
647 if ((l < 0) && (l >= c)) {
656 template <
typename T>
663 while ((c < l) && (!v.
isNull())) {
671 template <
typename T>
674 const int level)
const {
676 size_t s = this->
getSize().size();
680 while ((c < l) && (!v.
isNull())) {
681 const Position & pos = v->posInRefVolume();
683 for (
size_t i = 0; i < s; ++i)
693 template <
typename T>
inline
708 if(
_refvol->allocatorContext().isAllocated() )
710 size_t size =
sizeof(T);
716 AllocatorContext( AllocatorStrategy::NotOwner,
725 if (
_refvol->allocatorContext().isAllocated() )
728 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
732 for( ; i<Volume<T>::DIM_MAX; ++i )
740 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
755 this->
header().setProperty(
"voxel_size", vs );
765 template <
typename T>
inline
776 template <
typename T>
inline
781 while(
_pos.size() < 4 )
787 template <
typename T>
inline
789 if (refvol.get() !=
_refvol.get()) {
795 template <
typename T>
inline
804 for( i=0, n=
_pos.size(); i<n; ++i )
806 borders[i*2] =
_pos[i];
807 borders[i*2+1] -=
_pos[i];
814 template <
typename T>
inline
818 const blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>& bstrides =
_blitz.stride();
820 std::vector<long> strides( n );
821 for (d = 0; d < n; ++d)
822 strides[d] = bstrides[d];
827 template <
typename T >
843 blitz::TinyVector<long, Volume<T>::DIM_MAX> dims;
847 for( ; i<Volume<T>::DIM_MAX; ++i )
855 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
869 template <
typename T>
871 const std::vector<int> & pos )
873 std::vector<int> size = this->
getSize();
874 std::vector<int> osize = source.
getSize();
877 for( i=0; i<size.size() && i<osize.size(); ++i )
882 size[i] = std::min( size[i] - ip, osize[i] );
884 for( ; i<size.size(); ++i )
892 for( ; !it.
ended(); ++it, ++oit )
902 template <
typename T>
904 const std::vector<int> & pos )
909 template <
typename T >
918 template <
typename T >
927 template <
typename T >
936 template <
typename T >
945 template <
typename T >
953 std::set< std::string > sizePropertyNames;
954 sizePropertyNames.insert(
"sizeX" );
955 sizePropertyNames.insert(
"sizeY" );
956 sizePropertyNames.insert(
"sizeZ" );
957 sizePropertyNames.insert(
"sizeT" );
958 sizePropertyNames.insert(
"volume_dimension" );
960 sizeRcPropertyFilter(
new PropertyFilter(
"size", sizePropertyNames ) );
970 template <
typename T >
976 const AllocatorContext& ac,
977 const std::vector<long> *strides )
979 std::vector<int> oldSize(4);
980 oldSize[0] = oldSizeX;
981 oldSize[1] = oldSizeY;
982 oldSize[2] = oldSizeZ;
983 oldSize[3] = oldSizeT;
988 template <
typename T >
991 const AllocatorContext& ac,
992 const std::vector<long> *nstrides )
997 unsigned long long int stride_max = 0;
998 unsigned long long int total_len = 0;
999 unsigned long long absstride = 0;
1000 unsigned long long int offset = 0;
1004 for( ; i<std::min(nstrides->size(),
size_t(nn)); ++i )
1006 strides[i] = (*nstrides)[i];
1007 absstride = std::abs( strides[i] );
1008 if( absstride > stride_max )
1009 stride_max = absstride;
1012 if( strides[i] < 0 )
1020 if( strides[i] > stride_max )
1021 stride_max = strides[i];
1025 for( ; i<Volume<T>::DIM_MAX; ++i )
1029 if ( total_len *
sizeof(T) >
1033 throw std::runtime_error
1034 ( std::string(
"attempt to allocate a volume which size is greater "
1035 "than allowed by the system (" )
1041 for( i=0; i<n; ++i )
1042 if( oldSize[i] != -1 )
1049 || !
_items.allocatorContext().isAllocated()
1056 _items.allocate( (
size_t ) total_len, ac );
1060 || &ac != &
_items.allocatorContext() )
1064 AllocatedVector<T> newItems( (
size_t ) total_len, ac );
1067 for( i=0; i<std::min(n, nn); ++i )
1068 if( oldSize[i] < minSize[i] )
1069 minSize[i] = oldSize[i];
1073 if( newItems.allocatorContext().allocatorType()
1074 != AllocatorStrategy::ReadOnlyMap )
1075 for ( t = 0; t < minSize[3]; t++ )
1078 for ( z = 0; z < minSize[2]; z++ )
1081 for ( y = 0; y < minSize[1]; y++ )
1084 for ( x = 0; x < minSize[0]; x++ )
1087 newItems[ x * strides[0] +
1089 z * ( size_t ) strides[2] +
1090 t * (
size_t ) strides[3] ] =
1093 z * ( size_t ) oldSize[0]
1094 * (
size_t ) oldSize[1] +
1095 t * ( size_t ) oldSize[0] *
1096 (
size_t ) oldSize[1]
1097 * ( size_t ) oldSize[2] ];
1112 blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX> bstrides;
1115 for( i=0; i<nn; ++i )
1116 bstrides[i] = strides[i];
1118 for( ; i<Volume<T>::DIM_MAX; ++i )
1124 bstrides[i] = ( i == 0 ? n : n * stride_max );
1125 if( strides[i] > stride_max )
1126 stride_max = bstrides[i];
1141 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1142 for( i=0; i<nn; ++i )
1144 for( ; i<Volume<T>::DIM_MAX; ++i )
1152 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
1159 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
1175 _start = (T*)( 0 ) + offset;
1176 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1177 for( i=0; i<nn; ++i )
1179 for( ; i<Volume<T>::DIM_MAX; ++i )
1188 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
1195 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
1202 template <
typename T >
1214 template <
typename T >
1228 propertyFilter.
getOldValue(
"sizeX" )->GenericObject::value<
int >();
1235 propertyFilter.
getOldValue(
"sizeY" )->GenericObject::value<
int >();
1242 propertyFilter.
getOldValue(
"sizeZ" )->GenericObject::value<
int >();
1249 propertyFilter.
getOldValue(
"sizeT" )->GenericObject::value<
int >();
1266 template <
typename T >
1272 const AllocatorContext & ac,
1274 const std::vector<long> *strides )
1285 if( keepcontents || ( sizeX == oldx && sizeY == oldy && sizeZ == oldz
1286 && sizeT == oldt ) )
1287 allocate( oldx, oldy, oldz, oldt, alloc, ac, strides );
1289 allocate( std::vector<int>(1, -1), alloc, ac, strides );
1293 template <
typename T >
1296 const AllocatorContext & ac,
1298 const std::vector<long> *strides )
1300 return reallocate( size[0] > 0 ? size[0] : 1,
1301 size[1] > 0 ? size[1] : 1,
1302 size[2] > 0 ? size[2] : 1,
1303 size[3] > 0 ? size[3] : 1,
1304 keepcontents, ac, alloc, strides );
1307 template <
typename T >
1310 const AllocatorContext & ac,
1312 const std::vector<long> *strides )
1329 if( keepcontents || size == old )
1330 allocate( old, alloc, ac, strides );
1332 allocate( std::vector<int>(1, -1), alloc, ac, strides );
1337 template <
typename T >
1340 std::vector<int> border( 3 );
1342 border[1] = ( bsy < 0 ? bsx : bsy );
1343 border[2] = ( bsz < 0 ? bsx : bsz );
1349 template <
typename T >
1354 bool has_border =
false;
1355 if( !border.empty() )
1357 size_t i, n = border.size();
1358 for( i=0; !has_border && i<n; ++i )
1359 if( border[i] != 0 )
1369 if(
_pos.size() < 4 )
1370 _pos.resize( 4, 0 );
1376 template <
typename T >
1384 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims =
_blitz.shape();
1385 blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>
1386 strides =
_blitz.stride();
1388 int i, n = this->
getSize().size();
1389 std::vector<float>transl( n, 0.f );
1391 for( i=0; i<n; ++i )
1392 transl[i] = dims[i] - 1;
1397 std::unique_ptr<AffineTransformationBase> iflip = flip.
inverse();
1398 blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>
1399 new_strides = strides;
1400 long long offset = 0, old_offset =
_start - &
_items[0];
1402 for( i=0; i<n; ++i )
1404 std::vector<int> p( n, 0 );
1406 std::vector<int> p1 = iflip->transformVector( p );
1407 new_strides[i] = &
at( p1 ) - &
at( 0 );
1409 std::vector<int> vdims( dims.begin(), dims.end() );
1411 for( i=0; i<n; ++i )
1412 new_dims[i] = std::abs( new_dims[i] );
1413 blitz::TinyVector<int, Volume<T>::DIM_MAX> new_bdims = dims;
1414 for( i=0; i<n; ++i )
1415 new_bdims[i] = new_dims[i];
1416 for( i=0; i<n; ++i )
1418 if( new_strides[i] < 0 )
1419 offset += -new_strides[i] * ( new_dims[i] - 1 );
1420 if( strides[i] < 0 )
1421 old_offset += strides[i] * ( dims[i] - 1 );
1428 this->
header().copyProperties( reor_hdr );
1437 ( blitz::shape( 0, 1, 2, 3, 5, 6, 7, 8 ),
true ) ) );
1453 template <
typename T >
1455 const std::string & orient,
const std::string & force_memory_layout )
1458 std::vector<int> dims = this->
getSize();
1459 int i, n = dims.size();
1460 std::vector<float>transl( n, 0.f );
1461 for( i=0; i<n; ++i )
1462 transl[i] = dims[i] - 1;
1465 =
referential().toOrientation( force_memory_layout, transl );
1469 bool change_layout =
false;
1471 for( i=0; i<n; ++i )
1472 new_dims[i] = std::abs( new_dims[i] );
1476 std::unique_ptr<AffineTransformationBase> iflip = flip.
inverse();
1477 for( i=0; i<n; ++i )
1479 std::vector<int> p0( n, 0 );
1481 p0 = iflip->transformVector( p0 );
1482 long st = &this->
at( p0 ) - &this->
at( 0 );
1485 change_layout =
true;
1488 cstride *= new_dims[i];
1497 copy->referential().setOrientation( force_memory_layout );
1498 copy->referential().setLpiReferential(
1506 std::vector<int> pos;
1507 std::vector<int> p0;
1509 dp = &
copy->at( pos );
1510 p0 = std::vector<int>( n, 0 );
1513 dstride = &
copy->at( pos ) - dp;
1515 for( ; !it.
ended(); ++it )
1519 dp = &
copy->at( pos );
1535 template <
typename T>
1543 std::vector<int> dims = this->
getSize();
1544 size_t i, n = dims.size();
1545 std::vector<float>transl( n, 0.f );
1547 for( i=0; i<n; ++i )
1548 transl[i] = dims[i] - 1;
1553 std::unique_ptr<AffineTransformationBase> iflip = flip.
inverse();
1556 for( i=0, n=dims.size(); i<n; ++i )
1557 dims[i] = std::abs( dims[i] );
1558 rhdr->setProperty(
"volume_dimension", dims );
1559 if( rhdr->hasProperty(
"sizeX" ) )
1560 rhdr->removeProperty(
"sizeX" );
1561 if( rhdr->hasProperty(
"sizeY" ) )
1562 rhdr->removeProperty(
"sizeY" );
1563 if( rhdr->hasProperty(
"sizeZ" ) )
1564 rhdr->removeProperty(
"sizeZ" );
1565 if( rhdr->hasProperty(
"sizeT" ) )
1566 rhdr->removeProperty(
"sizeT" );
1570 for( i=0, n=rvs.size(); i<n; ++i )
1571 rvs[i] = std::abs( rvs[i] );
1572 rhdr->setProperty(
"voxel_size", rvs );
1574 bool is3d = this->
referential().is3DOriented( orient );
1578 AffineTransformationBase mvs( dims.size() );
1579 AffineTransformationBase rmvs( dims.size() );
1580 for( i=0, n=vs.size(); i<n; ++i )
1582 mvs.matrix()(i, i) = vs[i];
1583 rmvs.matrix()(i, i) = 1.f / rvs[i];
1586 AffineTransformationBase iflipmm = mvs * *iflip * rmvs;
1588 std::vector<std::vector<float> > rtrans;
1590 rtrans.reserve( transs->size() );
1591 Object tit = transs->objectIterator();
1592 for(; tit->isValid(); tit->next() )
1594 AffineTransformationBase trans( tit->currentValue() );
1595 trans.extendOrder( flip.
order() );
1598 trans = trans * iflipmm;
1600 trans.squeezeOrder( 3,
true,
false );
1601 rtrans.push_back( trans.toVector() );
1603 rhdr->setProperty(
"transformations", rtrans );
1608 AffineTransformationBase
1610 s2m.extendOrder( flip.
order() );
1614 rhdr->setProperty(
"storage_to_memory", s2m.toVector() );
1617 if( rhdr->hasProperty(
"referential" ) )
1619 if( orient ==
"LPI" )
1620 rhdr->setProperty(
"referential",
_referential.lpiReferentialUuid() );
1622 rhdr->removeProperty(
"referential" );
1629 template <
typename T>
1632 std::vector<long> strides = this->
getStrides();
1633 size_t i, j, n = strides.size();
1634 std::multimap<std::pair<long, bool>,
size_t> ordered_strides;
1635 std::vector<int> orient( n, 0 );
1636 std::vector<int> dims = this->
getSize();
1638 for( i=0; i<n; ++i )
1640 bool several = ( dims[i] > 1 );
1641 ordered_strides.insert(
1642 std::make_pair( std::make_pair( std::abs( strides[i] ), several),
1646 std::vector<int> aorient = this->
referential().axesOrientation();
1648 im, em = ordered_strides.end();
1650 for( im=ordered_strides.begin(), i=0; im!=em; ++im, ++i )
1652 j = ( ( aorient[ im->second ] - 1 ) / 2 ) * 2 + 1;
1653 bool neg = ( aorient[ im->second ] - 1 ) % 2;
1654 if( strides[ im->second] < 0 )
1665 template <
typename T>
1670 Object s2mo = this->
header().getProperty(
"storage_to_memory" );
1672 std::unique_ptr<AffineTransformationBase> m2s = s2m.
inverse();
1673 return this->
referential().orientationFromTransform( *m2s );
1679 std::vector<int> orient( this->
getSize().size(), 0 );
1688 template <
typename T>
1690 const AllocatorContext & context,
1693 std::vector<int> dims( 4, 1 );
1694 bool unalloc =
false;
1695 if( !header->getProperty(
"volume_dimension", dims ) )
1697 header->getProperty(
"sizeX", dims[0] );
1698 header->getProperty(
"sizeY", dims[1] );
1699 header->getProperty(
"sizeZ", dims[2] );
1700 header->getProperty(
"sizeT", dims[3] );
1703 unsigned n = dims.size();
1707 Object uao = options->getProperty(
"unallocated" );
1708 unalloc = bool( uao->getScalar() );
1717 Object oo = options->getProperty(
"orientation" );
1718 orient = oo->getString();
1726 std::vector<int> tdims = dims;
1728 if( !orient.empty() )
1733 if( orient ==
"storage" )
1738 Object s2mo = header->getProperty(
"storage_to_memory" );
1746 orient =
ref.orientationStr(
ref.orientationFromTransform( *ortr ) );
1761 tdims = ortr->transformVector( dims );
1762 for(
unsigned i=0; i<n; ++i )
1763 tdims[i] = std::abs( tdims[i] );
1765 orient =
ref.orientationStr( orient );
1766 if( orient ==
ref.orientationStr(
"LPI" ) )
1773 std::vector<int> borders( 3, 0 );
1775 borders[0] = (int) rint( options->getProperty(
"border" )->getScalar() );
1776 borders[1] = borders[0];
1777 borders[2] = borders[0];
1780 borders[0] = (int) rint( options->getProperty(
"bx" )->getScalar() );
1783 borders[1] = (int) rint( options->getProperty(
"by" )->getScalar() );
1786 borders[2] = (int) rint( options->getProperty(
"bz" )->getScalar() );
1790 if( borders[0] != 0 || borders[1] != 0 || borders[2] != 0 )
1792 std::vector<int> big_dims = dims;
1793 big_dims[0] += borders[0] * 2;
1794 big_dims[1] += borders[1] * 2;
1795 big_dims[2] += borders[2] * 2;
1797 big_dims = ortr->transformVector( big_dims );
1798 for(
unsigned i=0; i<big_dims.size(); ++i )
1799 big_dims[i] = std::abs( big_dims[i] );
1800 borders = ortr->transformVector( borders );
1801 for(
unsigned i=0; i<borders.size(); ++i )
1802 borders[i] = std::abs( borders[i] );
1804 obj =
new Volume<T>( big_dims, context, !unalloc );
1805 if( !orient.empty() )
1810 obj =
new Volume<T>( tdims, context, !unalloc );
1812 if( !orient.empty() )
1831 catch( std::exception & )
1841 template <
typename T>
1843 const AllocatorContext & context,
1846 std::vector<int> dims( 4, 1 );
1847 bool unalloc =
false, partial =
false, keep_allocation =
false;
1850 carto::Object p = options->getProperty(
"partial_reading" );
1851 partial = bool( p->getScalar() );
1856 if( !header->getProperty(
"volume_dimension", dims ) )
1858 header->getProperty(
"sizeX", dims[0] );
1859 header->getProperty(
"sizeY", dims[1] );
1860 header->getProperty(
"sizeZ", dims[2] );
1861 header->getProperty(
"sizeT", dims[3] );
1866 unalloc = bool( p->getScalar() );
1871 carto::Object p = options->getProperty(
"keep_allocation" );
1872 keep_allocation = bool( p->getScalar() );
1877 != AllocatorStrategy::Unallocated )
1878 obj.
reallocate( dims,
false, context, !unalloc );
1883 ( context.dataSource() );
static void setup(Volume< T > &, Object, const AllocatorContext &, Object)
static Volume< T > * create(Object, const AllocatorContext &, Object)
virtual void copyProperties(Object source)
const std::vector< int > & position() const
Object reference(Object &value)
Object getOldValue(const std::string &propertyName) const
bool hasOldValue(const std::string &propertyName) const
void setProperty(const std::string &, const T &)
virtual bool hasProperty(const std::string &) const
void addBuiltinProperty(const std::string &, T &)
bool getProperty(const std::string &, T &) const
void changeBuiltinProperty(const std::string &, T &)
Referential holds information about coordinates system and axes.
void setOrientation(const std::string &orient, bool allow_resize=false)
set a new orientation for the referential.
VolumeProxy(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1)
VolumeProxy< T > & operator=(const VolumeProxy< T > &other)
std::vector< float > getVoxelSize() const
get the voxel size from the header, with 4 values defaulting to 1.mm if not present
virtual void copyHeaderFrom(const PropertySet &other, bool stopOnError=true)
copy properties from other to this, avoiding forbidden properties like size.
std::vector< int > getSize() const
get the 4 dimensions in a vector
Convenient handle for a Volume - this is normally the entry point for all volumes handling.
Position4Di(int x=0, int y=0, int z=0, int t=0)
const std::vector< int > & toVector() const
iterator begin()
Iterators returned here are the most "basic" (and fastest) iterators: they go from the first voxel li...
std::vector< int > Position
const Referential & referential() const
const AllocatorContext & allocatorContext() const
returns volume's AllocatorContext
rc_ptr< Volume< T > > _refvol
void setPosInRefVolume(const Position4Di &pos)
Set position in parent volume.
Volume< T > & operator=(const Volume< T > &other)
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
virtual void initialize()
Initializes header info.
Object reorientedHeader(const std::string &orient) const
used by flipToOrientation(), reorient header information
Volume(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation.
const Position & posInRefVolume() const
Get position in parent volume.
void constructBorders(const Position &bordersize, const AllocatorContext &allocatorContext, bool allocated)
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.
Volume< T > copy() const
Create a volume of same dimension and copy the data.
blitz::Array< T, Volume< T >::DIM_MAX >::iterator iterator
Position posInRefVolumeAtLevel(const int level) const
Get position relatively to parent volume at specified level.
rc_ptr< Volume< T > > refVolume() const
Get parent volume.
void copySubVolume(const Volume< T > &source, const std::vector< int > &pos=std::vector< int >())
Copy voxels values from another volume.
std::vector< int > getBorders() const
Get borders for the volume.
int refLevel(const int level) const
Transform a level index to a valid level index in the volume hierarchy.
std::vector< int > storageLayoutOrientation() const
determine the storage (disk) layout orientation.
std::vector< long > getStrides() const
Get strides for the volume.
rc_ptr< Volume< T > > refVolumeAtLevel(const int level) const
Get parent volume at a specified level in volume hierarchy.
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.
void slotSizeChanged(const PropertyFilter &propertyFilter)
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< long > *strides=0)
allows resizing and changing allocator
void allocateBorders(int bsx, int bsy=-1, int bsz=-1)
reallocate the volume with given borders, keep (copy) the contents.
blitz::Array< T, Volume< T >::DIM_MAX > _blitz
void allocate(const std::vector< int > &oldSize, bool allocate, const AllocatorContext &allocatorContext, const std::vector< long > *strides=0)
void flipToOrientation(const std::string &orient)
Flip the volume to a given orientation.
std::vector< int > memoryLayoutOrientation() const
determine the memory layout orientation from strides and current indices orientation.
AllocatedVector< T > _items
void inc_line_ptr(const T *&p) const
int line_direction() const
std::ptrdiff_t line_length() const
void inc_line_ptr(T *&p) const
std::string toString(const T &object)
Volume< T > copy(const Volume< T > &src)
Performs a copy of the data (not only a reference copy) Only the data inside the view is copied.