34 #ifndef CARTODATA_VOLUME_VOLUMEBASE_D_H 35 #define CARTODATA_VOLUME_VOLUMEBASE_D_H 69 template <
typename T >
71 const AllocatorContext& allocatorContext,
74 _items( 0U, allocatorContext ),
75 #ifndef CARTO_USE_BLITZ
82 allocate( -1, -1, -1, -1, allocated, allocatorContext );
85 template <
typename T >
90 size[1] > 0 ? size[1] : 1,
91 size[2] > 0 ? size[2] : 1,
92 size[3] > 0 ? size[3] : 1 ),
93 _items( 0U, allocatorContext ),
94 #ifndef CARTO_USE_BLITZ
101 allocate( -1, -1, -1, -1, allocated, allocatorContext );
108 template <
typename T >
113 if( !bordersize.empty()
117 size_t bsize =
sizeof(T);
118 std::vector<int> large_size( n );
122 if( i < bordersize.size() )
123 large_size[i] += bordersize[i] * 2;
127 allocatorContext, allocated ) );
130 _refvol->allocatorContext().isAllocated()
131 ? AllocatorContext( AllocatorStrategy::NotOwner,
133 ( (
char *) &(*
_refvol)( bordersize ),
136 if(
_refvol->allocatorContext().isAllocated() )
139 #ifdef CARTO_USE_BLITZ 140 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
144 for( ; i<Volume<T>::DIM_MAX; ++i )
151 blitz::GeneralArrayStorage<8>
152 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
154 _lineoffset = &(*_refvol)( 0, 1, 0 ) - &(*
_refvol)( 0, 0, 0 );
155 _sliceoffset = &(*_refvol)( 0, 0, 1 ) - &(*
_refvol)( 0, 0, 0 );
156 _volumeoffset = &(*_refvol)( 0, 0, 0, 1 ) - &(*
_refvol)( 0, 0, 0 );
162 allocate( -1, -1, -1, -1, allocated, allocatorContext );
166 template <
typename T >
172 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
173 DataSource::
none() ) ),
174 #ifndef CARTO_USE_BLITZ
179 _pos( bordersize.toVector() )
184 template <
typename T >
190 size[1] > 0 ? size[1] : 1,
191 size[2] > 0 ? size[2] : 1,
192 size[3] > 0 ? size[3] : 1 ),
193 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
194 DataSource::
none() ) ),
195 #ifndef CARTO_USE_BLITZ
200 _pos( bordersize.toVector() )
205 template <
typename T >
207 int sizeT,
int bordersize,
211 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
212 DataSource::
none() ) ),
213 #ifndef CARTO_USE_BLITZ
220 _pos[0] = bordersize;
221 _pos[1] = bordersize;
222 _pos[2] = bordersize;
225 Position4Di( bordersize, bordersize, bordersize, 0 ).toVector(),
226 allocatorContext, allocated );
229 template <
typename T >
235 size[1] > 0 ? size[1] : 1,
236 size[2] > 0 ? size[2] : 1,
237 size[3] > 0 ? size[3] : 1 ),
238 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
239 DataSource::
none() ) ),
240 #ifndef CARTO_USE_BLITZ
247 _pos[0] = bordersize;
248 _pos[1] = bordersize;
249 _pos[2] = bordersize;
251 Position4Di( bordersize, bordersize, bordersize, 0 ).toVector(),
252 allocatorContext, allocated );
256 template <
typename T >
261 _items( 0U, allocatorContext ),
262 #ifndef CARTO_USE_BLITZ
269 allocate( std::vector<int>( 1, -1 ), allocated, allocatorContext );
273 template <
typename T >
275 const std::vector<int> & bordersize,
279 _items( 0U, AllocatorContext( AllocatorStrategy::NotOwner,
280 DataSource::
none() ) ),
281 #ifndef CARTO_USE_BLITZ
288 while(
_pos.size() < 4 )
296 template <
typename T >
299 _items( sizeX * sizeY * sizeZ * sizeT, buffer ),
300 #ifndef CARTO_USE_BLITZ
311 template <
typename T >
314 size[1] > 0 ? size[1] : 1,
315 size[2] > 0 ? size[2] : 1,
316 size[3] > 0 ? size[3] : 1 ),
317 _items( (long)(size[0] > 0 ? size[0] : 1) *
318 (long)(size[1] > 0 ? size[1] : 1) *
319 (long)(size[2] > 0 ? size[2] : 1) *
320 (long)(size[3] > 0 ? size[3] : 1), buffer ),
321 #ifndef CARTO_USE_BLITZ
332 template <
typename T >
336 #ifndef CARTO_USE_BLITZ
350 template<
typename T>
inline 353 const AllocatorContext & allocContext )
356 size[1] >= 0 ? size[1] :
358 size[2] >= 0 ? size[2] :
360 size[3] >= 0 ? size[3] :
362 _items( 0U, allocContext ),
364 #ifndef CARTO_USE_BLITZ
369 _pos( pos.toVector() )
371 if( other->allocatorContext().isAllocated() )
373 size_t bsize =
sizeof(T);
374 int i, n = size.
size();
379 AllocatorContext( AllocatorStrategy::NotOwner,
381 ( (
char *) &(*other)( pos.
toVector() ),
384 #ifdef CARTO_USE_BLITZ 385 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
389 for( ; i<Volume<T>::DIM_MAX; ++i )
395 other->_blitz.stride(),
396 blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
397 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
399 _lineoffset = &(*other)( 0, 1, 0 ) - &(*other)( 0, 0, 0 );
400 _sliceoffset = &(*other)( 0, 0, 1 ) - &(*other)( 0, 0, 0 );
401 _volumeoffset = &(*other)( 0, 0, 0, 1 ) - &(*other)( 0, 0, 0 );
405 allocate( -1, -1, -1, -1,
true, allocContext );
418 carto::Object vs = other->header().getProperty(
"voxel_size" );
419 size_t n = this->
getSize().size();
424 std::vector<carto::Object> vs2( n );
426 vs2[i] = vs->getArrayItem( i );
439 template<
typename T>
inline 442 const AllocatorContext & allocContext )
444 _items( 0U, allocContext ),
446 #ifndef CARTO_USE_BLITZ
453 if( other->allocatorContext().isAllocated() )
455 size_t bsize =
sizeof(T);
456 int i, n = size.size();
461 AllocatorContext( AllocatorStrategy::NotOwner,
463 ( (
char *) &(*other)( pos ),
467 #ifdef CARTO_USE_BLITZ 468 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
472 for( ; i<Volume<T>::DIM_MAX; ++i )
478 other->_blitz.stride(),
479 blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
480 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
482 _lineoffset = &(*other)( 0, 1, 0 ) - &(*other)( 0, 0, 0 );
483 _sliceoffset = &(*other)( 0, 0, 1 ) - &(*other)( 0, 0, 0 );
484 _volumeoffset = &(*other)( 0, 0, 0, 1 ) - &(*other)( 0, 0, 0 );
488 allocate( -1, -1, -1, -1,
true, allocContext );
501 carto::Object vs = other->header().getProperty(
"voxel_size" );
502 size_t n = this->
getSize().size();
507 std::vector<carto::Object> vs2( n );
509 vs2[i] = vs->getArrayItem( i );
525 template <
typename T >
530 #ifdef CARTO_USE_BLITZ
535 blitz::GeneralArrayStorage<8>
536 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ),
538 _lineoffset( other._lineoffset ),
539 _sliceoffset( other._sliceoffset ),
540 _volumeoffset( other._volumeoffset ),
549 std::vector<int> oldSize(1, -1);
551 ? AllocatorContext( AllocatorStrategy::NotOwner,
553 ( (
char *) &(*
_refvol)( pos[0], pos[1], pos[2], pos[3] ),
559 if(
_refvol->allocatorContext().isAllocated() )
562 #ifdef CARTO_USE_BLITZ 563 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
567 for( ; i<Volume<T>::DIM_MAX; ++i )
574 blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
575 ( blitz::shape( 0, 1, 2, 3, 5, 6, 7, 8 ), true ) ) );
577 _lineoffset = &other( 0, 1, 0 ) - &other( 0, 0, 0 );
578 _sliceoffset = &other( 0, 0, 1 ) - &other( 0, 0, 0 );
579 _volumeoffset = &other( 0, 0, 0, 1 ) - &other( 0, 0, 0 );
585 template <
typename T >
594 template <
typename T >
inline 597 return _items.allocatorContext();
600 template <
typename T>
inline 606 template <
typename T>
inline 612 template <
typename T>
624 template <
typename T>
633 if ((l < 0) && (l >= c)) {
642 template <
typename T>
649 while ((c < l) && (!v.
isNull())) {
657 template <
typename T>
660 const int level)
const {
662 size_t s = this->
getSize().size();
666 while ((c < l) && (!v.
isNull())) {
667 const Position & pos = v->posInRefVolume();
669 for (
size_t i = 0; i < s; ++i)
679 template <
typename T>
inline 694 if(
_refvol->allocatorContext().isAllocated() )
696 size_t size =
sizeof(T);
702 AllocatorContext( AllocatorStrategy::NotOwner,
710 if (
_refvol->allocatorContext().isAllocated() )
713 #ifdef CARTO_USE_BLITZ 714 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
718 for( ; i<Volume<T>::DIM_MAX; ++i )
725 blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
726 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
728 _lineoffset = &(*_refvol)( 0, 1, 0 ) - &(*
_refvol)( 0, 0, 0 );
729 _sliceoffset = &(*_refvol)( 0, 0, 1 ) - &(*
_refvol)( 0, 0, 0 );
730 _volumeoffset = &(*_refvol)( 0, 0, 0, 1 ) - &(*
_refvol)( 0, 0, 0 );
756 template <
typename T>
inline 767 template <
typename T>
inline 772 while(
_pos.size() < 4 )
778 template <
typename T>
inline 786 template <
typename T>
inline 795 for( i=0, n=
_pos.size(); i<n; ++i )
797 borders[i*2] =
_pos[i];
798 borders[i*2+1] -=
_pos[i];
805 template <
typename T>
inline 809 #ifdef CARTO_USE_BLITZ 810 const blitz::TinyVector<BlitzStridesType, Volume<T>::DIM_MAX>& bstrides =
_blitz.stride();
812 std::vector<size_t> strides( n );
813 for (d = 0; d < n; ++d)
814 strides[d] = bstrides[d];
816 std::vector<size_t> strides(4);
819 strides[1] = _lineoffset;
820 strides[2] = _sliceoffset;
821 strides[3] = _volumeoffset;
827 template <
typename T >
840 #ifdef CARTO_USE_BLITZ 843 blitz::TinyVector<long, Volume<T>::DIM_MAX> dims;
847 for( ; i<Volume<T>::DIM_MAX; ++i )
854 blitz::GeneralArrayStorage<Volume<T>::DIM_MAX>
855 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ), true ) ) );
857 _lineoffset = other._lineoffset;
858 _sliceoffset = other._sliceoffset;
859 _volumeoffset = other._volumeoffset;
873 template <
typename T >
877 #ifdef CARTO_USE_BLITZ 886 template <
typename T >
890 #ifdef CARTO_USE_BLITZ 899 template <
typename T >
903 #ifdef CARTO_USE_BLITZ 912 template <
typename T >
916 #ifdef CARTO_USE_BLITZ 925 template <
typename T >
933 std::set< std::string > sizePropertyNames;
934 sizePropertyNames.insert(
"sizeX" );
935 sizePropertyNames.insert(
"sizeY" );
936 sizePropertyNames.insert(
"sizeZ" );
937 sizePropertyNames.insert(
"sizeT" );
938 sizePropertyNames.insert(
"volume_dimension" );
940 sizeRcPropertyFilter(
new PropertyFilter(
"size", sizePropertyNames ) );
950 template <
typename T >
956 const AllocatorContext& ac )
958 std::vector<int> oldSize(4);
959 oldSize[0] = oldSizeX;
960 oldSize[1] = oldSizeY;
961 oldSize[2] = oldSizeZ;
962 oldSize[3] = oldSizeT;
967 template <
typename T >
970 const AllocatorContext& ac )
976 for( i=0; i<nn; ++i )
981 for( ; i<Volume<T>::DIM_MAX; ++i )
982 strides[i] = strides[i-1];
984 unsigned long long int total_len = strides[nn-1];
986 if ( total_len *
sizeof(T) >
990 throw std::runtime_error
991 ( std::string(
"attempt to allocate a volume which size is greater " 992 "than allowed by the system (" )
999 if( oldSize[i] != -1 )
1006 || !
_items.allocatorContext().isAllocated()
1012 _items.allocate( (
size_t ) total_len, ac );
1015 || &ac != &
_items.allocatorContext() )
1019 AllocatedVector<T> newItems( (
size_t ) total_len, ac );
1023 if( oldSize[i] < minSize[i] )
1024 minSize[i] = oldSize[i];
1028 if( newItems.allocatorContext().allocatorType()
1029 != AllocatorStrategy::ReadOnlyMap )
1030 for ( t = 0; t < minSize[3]; t++ )
1033 for ( z = 0; z < minSize[2]; z++ )
1036 for ( y = 0; y < minSize[1]; y++ )
1039 for ( x = 0; x < minSize[0]; x++ )
1043 z * ( size_t ) strides[1] +
1044 t * (
size_t ) strides[2] ] =
1047 z * ( size_t ) oldSize[0]
1048 * (
size_t ) oldSize[1] +
1049 t * ( size_t ) oldSize[0] *
1050 (
size_t ) oldSize[1]
1051 * ( size_t ) oldSize[2] ];
1068 #ifdef CARTO_USE_BLITZ 1076 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1077 for( i=0; i<nn; ++i )
1079 for( ; i<Volume<T>::DIM_MAX; ++i )
1085 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
1100 _sliceoffset = strides[1];
1101 _volumeoffset = strides[2];
1106 #ifdef CARTO_USE_BLITZ 1107 blitz::TinyVector<int, Volume<T>::DIM_MAX> dims;
1108 for( i=0; i<nn; ++i )
1110 for( ; i<Volume<T>::DIM_MAX; ++i )
1117 ( blitz::shape( 0, 1, 2, 3, 4, 5, 6, 7 ),
true ) ) );
1128 template <
typename T >
1136 template <
typename T >
1141 <<
" >::slotSizeChanged" 1150 propertyFilter.
getOldValue(
"sizeX" )->GenericObject::value<
int >();
1157 propertyFilter.
getOldValue(
"sizeY" )->GenericObject::value<
int >();
1164 propertyFilter.
getOldValue(
"sizeZ" )->GenericObject::value<
int >();
1171 propertyFilter.
getOldValue(
"sizeT" )->GenericObject::value<
int >();
1174 std::cout <<
"old size: " << oldSize[0] <<
", " << oldSize[1] <<
", " 1175 << oldSize[2] <<
", " << oldSize[3] << std::endl;
1186 template <
typename T >
1192 const AllocatorContext & ac,
1204 if( keepcontents || ( sizeX == oldx && sizeY == oldy && sizeZ == oldz
1205 && sizeT == oldt ) )
1206 allocate( oldx, oldy, oldz, oldt, alloc, ac );
1208 allocate( std::vector<int>(1, -1), alloc, ac );
1212 template <
typename T >
1215 const AllocatorContext & ac,
1218 return reallocate( size[0] > 0 ? size[0] : 1,
1219 size[1] > 0 ? size[1] : 1,
1220 size[2] > 0 ? size[2] : 1,
1221 size[3] > 0 ? size[3] : 1,
1222 keepcontents, ac, alloc );
1225 template <
typename T >
1228 const AllocatorContext & ac,
1246 if( keepcontents || size == old )
1249 allocate( std::vector<int>(1, -1), alloc, ac );
1257 template <
typename T>
1259 const AllocatorContext & context,
1262 std::vector<int> dims( 4, 1 );
1263 bool unalloc =
false;
1264 if( !header->getProperty(
"volume_dimension", dims ) )
1266 header->getProperty(
"sizeX", dims[0] );
1267 header->getProperty(
"sizeY", dims[1] );
1268 header->getProperty(
"sizeZ", dims[2] );
1269 header->getProperty(
"sizeT", dims[3] );
1271 options->getProperty(
"unallocated", unalloc );
1272 std::vector<int> borders( 3, 0 );
1274 borders[0] = (int) rint( options->getProperty(
"border" )->getScalar() );
1275 borders[1] = (int) rint( options->getProperty(
"border" )->getScalar() );
1276 borders[2] = (int) rint( options->getProperty(
"border" )->getScalar() );
1279 borders[0] = (int) rint( options->getProperty(
"bx" )->getScalar() );
1282 borders[1] = (int) rint( options->getProperty(
"by" )->getScalar() );
1285 borders[2] = (int) rint( options->getProperty(
"bz" )->getScalar() );
1289 if( borders[0] != 0 || borders[1] != 0 || borders[2] != 0 )
1291 std::vector<int> big_dims = dims;
1292 big_dims[0] += borders[0] * 2;
1293 big_dims[1] += borders[1] * 2;
1294 big_dims[2] += borders[2] * 2;
1295 obj =
new Volume<T>( big_dims, context, !unalloc );
1299 obj =
new Volume<T>( dims, context, !unalloc );
1301 obj->
header().copyProperties( header );
1307 template <
typename T>
1309 const AllocatorContext & context,
1312 std::vector<int> dims( 4, 1 );
1313 bool unalloc =
false, partial =
false, keep_allocation =
false;
1314 options->getProperty(
"partial_reading", partial );
1317 if( !header->getProperty(
"volume_dimension", dims ) )
1319 header->getProperty(
"sizeX", dims[0] );
1320 header->getProperty(
"sizeY", dims[1] );
1321 header->getProperty(
"sizeZ", dims[2] );
1322 header->getProperty(
"sizeT", dims[3] );
1324 options->getProperty(
"unallocated", unalloc );
1325 options->getProperty(
"keep_allocation", keep_allocation );
1327 obj.
reallocate( dims,
false, context, !unalloc );
1332 ( context.dataSource() );
1337 obj.
header().copyProperties( header );
1353 #endif // CARTODATA_VOLUME_VOLUMEBASE_D_H Volume(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation.
void setRefVolume(const rc_ptr< Volume< T > > &refvol)
Set parent volume.
const Position & posInRefVolume() const
Get position in parent volume.
int refLevel(const int level) const
Transform a level index to a valid level index in the volume hierarchy.
void allocate()
This function is only useful in the particular context of an unallocated Volume, when the constructor...
rc_ptr< Volume< T > > _refvol
void constructBorders(const Position &bordersize, const AllocatorContext &allocatorContext, bool allocated)
blitz::Array< T, Volume< T >::DIM_MAX > _blitz
iterator begin()
Iterators returned here are the most "basic" (and fastest) iterators: they go from the first voxel li...
rc_ptr< Volume< T > > refVolumeAtLevel(const int level) const
Get parent volume at a specified level in volume hierarchy.
VolumeProxy< T > & operator=(const VolumeProxy< T > &other)
Position posInRefVolumeAtLevel(const int level) const
Get position relatively to parent volume at specified level.
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
void setPosInRefVolume(const Position4Di &pos)
Set position in parent volume.
VolumeProxy is the base class for volumes.
std::vector< size_t > getStrides() const
Get strides for the volume.
std::vector< int > getSize() const
get the 4 dimensions in a vector
bool hasOldValue(const std::string &propertyName) const
const AllocatorContext & allocatorContext() const
returns volume's AllocatorContext
T min(const Volume< T > &vol)
Returns the minimum value of the volume.
std::vector< int > getBorders() const
Get borders for the volume.
void setProperty(const std::string &, const T &)
Object getOldValue(const std::string &propertyName) const
rc_ptr< Volume< T > > refVolume() const
Get parent volume.
int getLevelsCount() const
Get levels count in volume hierarchy from the current volume to the topmost volume.
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)
allows resizing and changing allocator
const std::vector< int > & toVector() const
void changeBuiltinProperty(const std::string &, T &)
blitz::Array< T, Volume< T >::DIM_MAX >::iterator iterator
Volume< T > & operator=(const Volume< T > &other)
std::string toString(const T &object)
void slotSizeChanged(const PropertyFilter &propertyFilter)
std::vector< int > Position
AllocatedVector< T > _items
virtual void initialize()
Initializes header info.