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,
263 DataSource::
none() ) ),
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,
bool transToParent )
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 );
358 std::vector<std::string> refs;
359 std::vector<std::vector<float> > trans;
363 while( vs.size() < 3 )
366 std::vector<float> trv( 16, 0.f );
371 trv[3] = pos[0] * vs[0];
372 trv[7] = pos[1] * vs[1];
373 trv[11] = pos[2] * vs[2];
374 AffineTransformationBase tr( trv );
378 std::string
ref = parent->referential().uuid();
379 refs.push_back(
ref );
380 trans.push_back( trv );
385 carto::Object tl = parent->header().getProperty(
"transformations" );
386 trans.reserve( tl->size() + 1 );
388 for( it = tl->objectIterator(); it->isValid(); it->next() )
390 AffineTransformationBase tn( it->currentValue() );
392 trans.push_back( tn.toVector() );
394 carto::Object rl = parent->header().getProperty(
"referentials" );
395 refs.reserve( rl->size() + 1 );
396 for( it = rl->objectIterator(); it->isValid(); it->next() )
397 refs.push_back( it->currentValue()->getString() );
407 "storage_to_memory" );
408 AffineTransformationBase s2m( s2mo );
410 std::vector<int> p = vol->
getSize();
414 std::vector<int> tp = s2m.transform( p );
415 std::vector<int> t0 = s2m.transform( std::vector<int>( 3, 0 ) );
420 s2m.matrix()( 0, 3 ) = -tp[0];
422 s2m.matrix()( 0, 3 ) = -tp[1];
424 s2m.matrix()( 0, 3 ) = -tp[2];
438 template<
typename T>
inline
441 const AllocatorContext & allocContext,
445 size[1] >= 0 ? size[1] :
447 size[2] >= 0 ? size[2] :
449 size[3] >= 0 ? size[3] :
451 _items( 0U, allocContext ),
462 if( other->allocatorContext().isAllocated() )
464 size_t bsize =
sizeof(T);
465 std::vector<int> osize = other->getSize();
466 int i, n = osize.size();
471 AllocatorContext( AllocatorStrategy::NotOwner,
473 ( (
char *) &other->_items[0],
476 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
480 for( ; i<Volume<T>::DIM_MAX; ++i )
487 other->_blitz.stride(),
489 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
492 allocate( -1, -1, -1, -1,
true, allocContext );
494 _updateHeaderFromParent(
this, transToParent );
498 template<
typename T>
inline
501 const AllocatorContext & allocContext,
504 _items( 0U, allocContext ),
515 if( other->allocatorContext().isAllocated() )
517 size_t bsize =
sizeof(T);
518 std::vector<int> osize = other->getSize();
519 int i, n = osize.size();
526 AllocatorContext( AllocatorStrategy::NotOwner,
528 ( (
char *) &other->_items[0],
532 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
536 for( ; i<Volume<T>::DIM_MAX; ++i )
538 _start = &(*other)( pos );
543 other->_blitz.stride(),
545 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
550 _updateHeaderFromParent(
this, transToParent );
556 template <
typename T >
559 const std::vector<long> & strides )
579 template <
typename T >
591 blitz::GeneralArrayStorage<8>
592 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ),
602 std::vector<int> oldSize(1, -1);
604 ? AllocatorContext( AllocatorStrategy::NotOwner,
606 ( (
char *) &(*
_refvol)( pos[0], pos[1], pos[2], pos[3] ),
612 if(
_refvol->allocatorContext().isAllocated() )
615 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
619 for( ; i<Volume<T>::DIM_MAX; ++i )
627 ( blitz::shape( 0, 1, 2, 3, 5, 6, 7, 8 ),
true ) ) );
632 template <
typename T >
641 template <
typename T >
inline
644 return _items.allocatorContext();
647 template <
typename T>
inline
653 template <
typename T>
inline
659 template <
typename T>
671 template <
typename T>
680 if ((l < 0) && (l >= c)) {
689 template <
typename T>
696 while ((c < l) && (!v.
isNull())) {
704 template <
typename T>
707 const int level)
const {
709 size_t s = this->
getSize().size();
713 while ((c < l) && (!v.
isNull())) {
714 const Position & pos = v->posInRefVolume();
716 for (
size_t i = 0; i < s; ++i)
726 template <
typename T>
inline
741 if(
_refvol->allocatorContext().isAllocated() )
743 size_t size =
sizeof(T);
749 AllocatorContext( AllocatorStrategy::NotOwner,
758 if (
_refvol->allocatorContext().isAllocated() )
761 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
765 for( ; i<Volume<T>::DIM_MAX; ++i )
773 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
788 this->
header().setProperty(
"voxel_size", vs );
798 template <
typename T>
inline
809 template <
typename T>
inline
814 while(
_pos.size() < 4 )
820 template <
typename T>
inline
822 if (refvol.get() !=
_refvol.get()) {
828 template <
typename T>
inline
837 for( i=0, n=
_pos.size(); i<n; ++i )
839 borders[i*2] =
_pos[i];
840 borders[i*2+1] -=
_pos[i];
847 template <
typename T>
inline
851 const blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>& bstrides =
_blitz.stride();
853 std::vector<long> strides( n );
854 for (d = 0; d < n; ++d)
855 strides[d] = bstrides[d];
860 template <
typename T >
876 blitz::TinyVector<long, Volume<T>::DIM_MAX> dims;
880 for( ; i<Volume<T>::DIM_MAX; ++i )
888 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
902 template <
typename T>
904 const std::vector<int> & pos )
906 std::vector<int> size = this->
getSize();
907 std::vector<int> osize = source.
getSize();
910 for( i=0; i<size.size() && i<osize.size(); ++i )
915 size[i] = std::min( size[i] - ip, osize[i] );
917 for( ; i<size.size(); ++i )
925 for( ; !it.
ended(); ++it, ++oit )
935 template <
typename T>
937 const std::vector<int> & pos )
942 template <
typename T >
951 template <
typename T >
960 template <
typename T >
969 template <
typename T >
978 template <
typename T >
986 std::set< std::string > sizePropertyNames;
987 sizePropertyNames.insert(
"sizeX" );
988 sizePropertyNames.insert(
"sizeY" );
989 sizePropertyNames.insert(
"sizeZ" );
990 sizePropertyNames.insert(
"sizeT" );
991 sizePropertyNames.insert(
"volume_dimension" );
993 sizeRcPropertyFilter(
new PropertyFilter(
"size", sizePropertyNames ) );
1003 template <
typename T >
1009 const AllocatorContext& ac,
1010 const std::vector<long> *strides )
1012 std::vector<int> oldSize(4);
1013 oldSize[0] = oldSizeX;
1014 oldSize[1] = oldSizeY;
1015 oldSize[2] = oldSizeZ;
1016 oldSize[3] = oldSizeT;
1021 template <
typename T >
1024 const AllocatorContext& ac,
1025 const std::vector<long> *nstrides )
1030 unsigned long long int stride_max = 0;
1031 unsigned long long int total_len = 0;
1032 unsigned long long absstride = 0;
1033 unsigned long long int offset = 0;
1037 for( ; i<std::min(nstrides->size(),
size_t(nn)); ++i )
1039 strides[i] = (*nstrides)[i];
1040 absstride = std::abs( strides[i] );
1041 if( absstride > stride_max )
1042 stride_max = absstride;
1045 if( strides[i] < 0 )
1053 if( strides[i] > stride_max )
1054 stride_max = strides[i];
1058 for( ; i<Volume<T>::DIM_MAX; ++i )
1062 if ( total_len *
sizeof(T) >
1066 throw std::runtime_error
1067 ( std::string(
"attempt to allocate a volume which size is greater "
1068 "than allowed by the system (" )
1074 for( i=0; i<n; ++i )
1075 if( oldSize[i] != -1 )
1082 || !
_items.allocatorContext().isAllocated()
1089 _items.allocate( (
size_t ) total_len, ac );
1093 || &ac != &
_items.allocatorContext() )
1097 AllocatedVector<T> newItems( (
size_t ) total_len, ac );
1100 for( i=0; i<std::min(n, nn); ++i )
1101 if( oldSize[i] < minSize[i] )
1102 minSize[i] = oldSize[i];
1106 if( newItems.allocatorContext().allocatorType()
1107 != AllocatorStrategy::ReadOnlyMap )
1108 for ( t = 0; t < minSize[3]; t++ )
1111 for ( z = 0; z < minSize[2]; z++ )
1114 for ( y = 0; y < minSize[1]; y++ )
1117 for ( x = 0; x < minSize[0]; x++ )
1120 newItems[ x * strides[0] +
1122 z * ( size_t ) strides[2] +
1123 t * (
size_t ) strides[3] ] =
1126 z * ( size_t ) oldSize[0]
1127 * (
size_t ) oldSize[1] +
1128 t * ( size_t ) oldSize[0] *
1129 (
size_t ) oldSize[1]
1130 * ( size_t ) oldSize[2] ];
1145 blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX> bstrides;
1148 for( i=0; i<nn; ++i )
1149 bstrides[i] = strides[i];
1151 for( ; i<Volume<T>::DIM_MAX; ++i )
1157 bstrides[i] = ( i == 0 ? n : n * stride_max );
1158 if( strides[i] > stride_max )
1159 stride_max = bstrides[i];
1174 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1175 for( i=0; i<nn; ++i )
1177 for( ; i<Volume<T>::DIM_MAX; ++i )
1185 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
1192 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
1208 _start = (T*)( 0 ) + offset;
1209 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1210 for( i=0; i<nn; ++i )
1212 for( ; i<Volume<T>::DIM_MAX; ++i )
1221 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
1228 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
1235 template <
typename T >
1247 template <
typename T >
1261 propertyFilter.
getOldValue(
"sizeX" )->GenericObject::value<
int >();
1268 propertyFilter.
getOldValue(
"sizeY" )->GenericObject::value<
int >();
1275 propertyFilter.
getOldValue(
"sizeZ" )->GenericObject::value<
int >();
1282 propertyFilter.
getOldValue(
"sizeT" )->GenericObject::value<
int >();
1299 template <
typename T >
1305 const AllocatorContext & ac,
1307 const std::vector<long> *strides )
1318 if( keepcontents || ( sizeX == oldx && sizeY == oldy && sizeZ == oldz
1319 && sizeT == oldt ) )
1320 allocate( oldx, oldy, oldz, oldt, alloc, ac, strides );
1322 allocate( std::vector<int>(1, -1), alloc, ac, strides );
1326 template <
typename T >
1329 const AllocatorContext & ac,
1331 const std::vector<long> *strides )
1333 return reallocate( size[0] > 0 ? size[0] : 1,
1334 size[1] > 0 ? size[1] : 1,
1335 size[2] > 0 ? size[2] : 1,
1336 size[3] > 0 ? size[3] : 1,
1337 keepcontents, ac, alloc, strides );
1340 template <
typename T >
1343 const AllocatorContext & ac,
1345 const std::vector<long> *strides )
1362 if( keepcontents || size == old )
1363 allocate( old, alloc, ac, strides );
1365 allocate( std::vector<int>(1, -1), alloc, ac, strides );
1370 template <
typename T >
1373 std::vector<int> border( 3 );
1375 border[1] = ( bsy < 0 ? bsx : bsy );
1376 border[2] = ( bsz < 0 ? bsx : bsz );
1382 template <
typename T >
1387 bool has_border =
false;
1388 if( !border.empty() )
1390 size_t i, n = border.size();
1391 for( i=0; !has_border && i<n; ++i )
1392 if( border[i] != 0 )
1402 if(
_pos.size() < 4 )
1403 _pos.resize( 4, 0 );
1409 template <
typename T >
1417 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims =
_blitz.shape();
1418 blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>
1419 strides =
_blitz.stride();
1421 int i, n = this->
getSize().size();
1422 std::vector<float>transl( n, 0.f );
1424 for( i=0; i<n; ++i )
1425 transl[i] = dims[i] - 1;
1430 std::unique_ptr<AffineTransformationBase> iflip = flip.
inverse();
1431 blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>
1432 new_strides = strides;
1433 long long offset = 0, old_offset =
_start - &
_items[0];
1435 for( i=0; i<n; ++i )
1437 std::vector<int> p( n, 0 );
1439 std::vector<int> p1 = iflip->transformVector( p );
1440 new_strides[i] = &
at( p1 ) - &
at( 0 );
1442 std::vector<int> vdims( dims.begin(), dims.end() );
1444 for( i=0; i<n; ++i )
1445 new_dims[i] = std::abs( new_dims[i] );
1446 blitz::TinyVector<int, Volume<T>::DIM_MAX> new_bdims = dims;
1447 for( i=0; i<n; ++i )
1448 new_bdims[i] = new_dims[i];
1449 for( i=0; i<n; ++i )
1451 if( new_strides[i] < 0 )
1452 offset += -new_strides[i] * ( new_dims[i] - 1 );
1453 if( strides[i] < 0 )
1454 old_offset += strides[i] * ( dims[i] - 1 );
1461 this->
header().copyProperties( reor_hdr );
1470 ( blitz::shape( 0, 1, 2, 3, 5, 6, 7, 8 ),
true ) ) );
1486 template <
typename T >
1488 const std::string & orient,
const std::string & force_memory_layout )
1491 std::vector<int> dims = this->
getSize();
1492 int i, n = dims.size();
1493 std::vector<float>transl( n, 0.f );
1494 for( i=0; i<n; ++i )
1495 transl[i] = dims[i] - 1;
1498 =
referential().toOrientation( force_memory_layout, transl );
1502 bool change_layout =
false;
1504 for( i=0; i<n; ++i )
1505 new_dims[i] = std::abs( new_dims[i] );
1509 std::unique_ptr<AffineTransformationBase> iflip = flip.
inverse();
1510 for( i=0; i<n; ++i )
1512 std::vector<int> p0( n, 0 );
1514 p0 = iflip->transformVector( p0 );
1515 long st = &this->
at( p0 ) - &this->
at( 0 );
1518 change_layout =
true;
1521 cstride *= new_dims[i];
1530 copy->referential().setOrientation( force_memory_layout );
1531 copy->referential().setLpiReferential(
1539 std::vector<int> pos;
1540 std::vector<int> p0;
1542 dp = &
copy->at( pos );
1543 p0 = std::vector<int>( n, 0 );
1546 dstride = &
copy->at( pos ) - dp;
1548 for( ; !it.
ended(); ++it )
1552 dp = &
copy->at( pos );
1568 template <
typename T>
1576 std::vector<int> dims = this->
getSize();
1577 size_t i, n = dims.size();
1578 std::vector<float>transl( n, 0.f );
1580 for( i=0; i<n; ++i )
1581 transl[i] = dims[i] - 1;
1586 std::unique_ptr<AffineTransformationBase> iflip = flip.
inverse();
1589 for( i=0, n=dims.size(); i<n; ++i )
1590 dims[i] = std::abs( dims[i] );
1591 rhdr->setProperty(
"volume_dimension", dims );
1592 if( rhdr->hasProperty(
"sizeX" ) )
1593 rhdr->removeProperty(
"sizeX" );
1594 if( rhdr->hasProperty(
"sizeY" ) )
1595 rhdr->removeProperty(
"sizeY" );
1596 if( rhdr->hasProperty(
"sizeZ" ) )
1597 rhdr->removeProperty(
"sizeZ" );
1598 if( rhdr->hasProperty(
"sizeT" ) )
1599 rhdr->removeProperty(
"sizeT" );
1603 for( i=0, n=rvs.size(); i<n; ++i )
1604 rvs[i] = std::abs( rvs[i] );
1605 rhdr->setProperty(
"voxel_size", rvs );
1607 bool is3d = this->
referential().is3DOriented( orient );
1611 AffineTransformationBase mvs( dims.size() );
1612 AffineTransformationBase rmvs( dims.size() );
1613 for( i=0, n=vs.size(); i<n; ++i )
1615 mvs.matrix()(i, i) = vs[i];
1616 rmvs.matrix()(i, i) = 1.f / rvs[i];
1619 AffineTransformationBase iflipmm = mvs * *iflip * rmvs;
1621 std::vector<std::vector<float> > rtrans;
1623 rtrans.reserve( transs->size() );
1624 Object tit = transs->objectIterator();
1625 for(; tit->isValid(); tit->next() )
1627 AffineTransformationBase trans( tit->currentValue() );
1628 trans.extendOrder( flip.
order() );
1631 trans = trans * iflipmm;
1633 trans.squeezeOrder( 3,
true,
false );
1634 rtrans.push_back( trans.toVector() );
1636 rhdr->setProperty(
"transformations", rtrans );
1641 AffineTransformationBase
1643 s2m.extendOrder( flip.
order() );
1647 rhdr->setProperty(
"storage_to_memory", s2m.toVector() );
1650 if( rhdr->hasProperty(
"referential" ) )
1652 if( orient ==
"LPI" )
1653 rhdr->setProperty(
"referential",
_referential.lpiReferentialUuid() );
1655 rhdr->removeProperty(
"referential" );
1662 template <
typename T>
1665 std::vector<long> strides = this->
getStrides();
1666 size_t i, j, n = strides.size();
1667 std::multimap<std::pair<long, bool>,
size_t> ordered_strides;
1668 std::vector<int> orient( n, 0 );
1669 std::vector<int> dims = this->
getSize();
1671 for( i=0; i<n; ++i )
1673 bool several = ( dims[i] > 1 );
1674 ordered_strides.insert(
1675 std::make_pair( std::make_pair( std::abs( strides[i] ), several),
1679 std::vector<int> aorient = this->
referential().axesOrientation();
1681 im, em = ordered_strides.end();
1683 for( im=ordered_strides.begin(), i=0; im!=em; ++im, ++i )
1685 j = ( ( aorient[ im->second ] - 1 ) / 2 ) * 2 + 1;
1686 bool neg = ( aorient[ im->second ] - 1 ) % 2;
1687 if( strides[ im->second] < 0 )
1698 template <
typename T>
1703 Object s2mo = this->
header().getProperty(
"storage_to_memory" );
1705 std::unique_ptr<AffineTransformationBase> m2s = s2m.
inverse();
1706 return this->
referential().orientationFromTransform( *m2s );
1712 std::vector<int> orient( this->
getSize().size(), 0 );
1721 template <
typename T>
1723 const AllocatorContext & context,
1726 std::vector<int> dims( 4, 1 );
1727 bool unalloc =
false;
1728 if( !header->getProperty(
"volume_dimension", dims ) )
1730 header->getProperty(
"sizeX", dims[0] );
1731 header->getProperty(
"sizeY", dims[1] );
1732 header->getProperty(
"sizeZ", dims[2] );
1733 header->getProperty(
"sizeT", dims[3] );
1736 unsigned n = dims.size();
1740 Object uao = options->getProperty(
"unallocated" );
1741 unalloc = bool( uao->getScalar() );
1750 Object oo = options->getProperty(
"orientation" );
1751 orient = oo->getString();
1759 std::vector<int> tdims = dims;
1761 if( !orient.empty() )
1766 if( orient ==
"storage" )
1771 Object s2mo = header->getProperty(
"storage_to_memory" );
1779 orient =
ref.orientationStr(
ref.orientationFromTransform( *ortr ) );
1794 tdims = ortr->transformVector( dims );
1795 for(
unsigned i=0; i<n; ++i )
1796 tdims[i] = std::abs( tdims[i] );
1798 orient =
ref.orientationStr( orient );
1799 if( orient ==
ref.orientationStr(
"LPI" ) )
1806 std::vector<int> borders( 3, 0 );
1808 borders[0] = (int) rint( options->getProperty(
"border" )->getScalar() );
1809 borders[1] = borders[0];
1810 borders[2] = borders[0];
1813 borders[0] = (int) rint( options->getProperty(
"bx" )->getScalar() );
1816 borders[1] = (int) rint( options->getProperty(
"by" )->getScalar() );
1819 borders[2] = (int) rint( options->getProperty(
"bz" )->getScalar() );
1823 if( borders[0] != 0 || borders[1] != 0 || borders[2] != 0 )
1825 std::vector<int> big_dims = dims;
1826 big_dims[0] += borders[0] * 2;
1827 big_dims[1] += borders[1] * 2;
1828 big_dims[2] += borders[2] * 2;
1830 big_dims = ortr->transformVector( big_dims );
1831 for(
unsigned i=0; i<big_dims.size(); ++i )
1832 big_dims[i] = std::abs( big_dims[i] );
1833 borders = ortr->transformVector( borders );
1834 for(
unsigned i=0; i<borders.size(); ++i )
1835 borders[i] = std::abs( borders[i] );
1837 obj =
new Volume<T>( big_dims, context, !unalloc );
1838 if( !orient.empty() )
1843 obj =
new Volume<T>( tdims, context, !unalloc );
1845 if( !orient.empty() )
1864 catch( std::exception & )
1874 template <
typename T>
1876 const AllocatorContext & context,
1879 std::vector<int> dims( 4, 1 );
1880 bool unalloc =
false, partial =
false, keep_allocation =
false;
1883 carto::Object p = options->getProperty(
"partial_reading" );
1884 partial = bool( p->getScalar() );
1889 if( !header->getProperty(
"volume_dimension", dims ) )
1891 header->getProperty(
"sizeX", dims[0] );
1892 header->getProperty(
"sizeY", dims[1] );
1893 header->getProperty(
"sizeZ", dims[2] );
1894 header->getProperty(
"sizeT", dims[3] );
1899 unalloc = bool( p->getScalar() );
1904 carto::Object p = options->getProperty(
"keep_allocation" );
1905 keep_allocation = bool( p->getScalar() );
1910 != AllocatorStrategy::Unallocated )
1911 obj.
reallocate( dims,
false, context, !unalloc );
1916 ( 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 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.