34 #ifndef CARTODATA_VOLUME_VOLUMEBASE_H 35 #define CARTODATA_VOLUME_VOLUMEBASE_H 47 #ifdef CARTO_USE_BLITZ 51 #define CARTO_REENTRANT_MEMO 54 #include <blitz/blitz.h> 55 #ifdef CARTO_REENTRANT_MEMO 57 #undef CARTO_REENTRANT_MEMO 60 #include <blitz/array.h> 73 class AllocatorContext;
120 template <
typename T >
141 #ifdef CARTO_USE_BLITZ 149 typedef typename AllocatedVector<T>::iterator
iterator;
150 typedef typename AllocatedVector<T>::const_iterator
const_iterator;
167 explicit Volume(
int sizeX = 1,
int sizeY = 1,
int sizeZ = 1,
170 = AllocatorContext(),
171 bool allocated =
true );
182 = AllocatorContext(),
183 bool allocated =
true );
188 explicit Volume(
int sizeX,
int sizeY,
int sizeZ,
189 int sizeT,
int bordersize,
191 = AllocatorContext(),
192 bool allocated =
true );
199 = AllocatorContext(),
200 bool allocated =
true );
204 explicit Volume(
int sizeX,
int sizeY,
int sizeZ,
int sizeT,
207 = AllocatorContext(),
208 bool allocated =
true );
215 = AllocatorContext(),
216 bool allocated =
true );
220 explicit Volume(
const std::vector<int> & size,
222 = AllocatorContext(),
223 bool allocated =
true );
227 explicit Volume(
const std::vector<int> & size,
228 const std::vector<int> & border,
230 = AllocatorContext(),
231 bool allocated =
true );
234 Volume(
int sizeX,
int sizeY,
int sizeZ,
int sizeT, T* buffer );
239 Volume(
const std::vector<int> & size, T* buffer );
248 const AllocatorContext & allocContext = AllocatorContext() );
255 const Position & pos,
257 const AllocatorContext & allocContext = AllocatorContext() );
278 const_iterator
begin()
const;
279 const_iterator
end()
const;
287 const T&
operator()(
long x,
long y = 0,
long z = 0,
long t = 0 )
const;
289 T&
operator() (
long x,
long y = 0,
long z = 0,
long t = 0 );
290 const T&
at(
long x,
long y = 0,
long z = 0,
long t = 0 )
const;
291 T&
at(
long x,
long y = 0,
long z = 0,
long t = 0 );
296 const T &
at(
const std::vector<int> & )
const;
297 T &
at(
const std::vector<int> & );
298 const T&
operator() (
const std::vector<int> & position )
const;
299 T&
operator() (
const std::vector<int> & position );
301 #ifdef CARTO_USE_BLITZ 302 const T &
at(
const blitz::TinyVector<int,1> & )
const;
303 T &
at(
const blitz::TinyVector<int,1> & );
304 const T &
at(
const blitz::TinyVector<int,2> & )
const;
305 T &
at(
const blitz::TinyVector<int,2> & );
306 const T &
at(
const blitz::TinyVector<int,3> & )
const;
307 T &
at(
const blitz::TinyVector<int,3> & );
308 const T &
at(
const blitz::TinyVector<int,4> & )
const;
309 T &
at(
const blitz::TinyVector<int,4> & );
316 blitz::Array<T,Volume<T>::DIM_MAX>
at(
const blitz::Range & r0 )
const;
317 blitz::Array<T,Volume<T>::DIM_MAX>
at(
const blitz::Range & r0,
318 const blitz::Range & r1 )
const;
319 blitz::Array<T,Volume<T>::DIM_MAX>
at(
const blitz::Range & r0,
320 const blitz::Range & r1,
321 const blitz::Range & r2 )
const;
322 blitz::Array<T,Volume<T>::DIM_MAX>
at(
const blitz::Range & r0,
323 const blitz::Range & r1,
324 const blitz::Range & r2,
325 const blitz::Range & r3 )
const;
327 const T &
at(
long x1,
long x2,
long x3,
long x4,
long x5,
long x6=0,
328 long x7=0,
long x8=0 )
const;
329 T &
at(
long x1,
long x2,
long x3,
long x4,
long x5,
long x6=0,
330 long x7=0,
long x8=0 );
331 const T&
operator()(
long x1,
long x2,
long x3,
long x4,
long x5,
332 long x6=0,
long x7=0,
long x8=0 )
const;
333 T&
operator() (
long x1,
long x2,
long x3,
long x4,
long x5,
long x6=0,
334 long x7=0,
long x8=0 );
352 virtual void reallocate(
int sizeX = 1,
int sizeY = 1,
int sizeZ = 1,
353 int sizeT = 1,
bool keepcontents =
false,
354 const AllocatorContext& allocatorContext
355 = AllocatorContext(),
bool allocate =
true );
357 bool keepcontents =
false,
358 const AllocatorContext& allocatorContext
359 = AllocatorContext(),
bool allocate =
true );
360 virtual void reallocate(
const std::vector<int> & size,
361 bool keepcontents =
false,
362 const AllocatorContext& allocatorContext
363 = AllocatorContext(),
bool allocate =
true );
373 template <
typename OUTP>
378 template <
typename OUTP>
384 template <
typename OUTP>
388 template <
typename OUTP>
399 int refLevel(
const int level)
const;
461 operator bool()
const;
476 void fill(
const T & value );
503 void allocate(
int oldSizeX,
int oldSizeY,
int oldSizeZ,
int oldSizeT,
504 bool allocate,
const AllocatorContext& allocatorContext );
505 void allocate(
const std::vector<int> & oldSize,
506 bool allocate,
const AllocatorContext& allocatorContext );
511 const AllocatorContext& allocatorContext,
515 #ifdef CARTO_USE_BLITZ 516 blitz::Array<T, Volume<T>::DIM_MAX>
_blitz;
520 size_t _volumeoffset;
529 template <
typename T>
533 explicit Position4Di(
int x = 0,
int y = 0,
int z = 0,
int t = 0 )
546 template <
typename U>
550 for(
size_t i = 0; i < size_t( other.size() ) && i < 4; ++i )
551 _coords[i] = other[i];
552 for(
size_t i =
size_t( other.size() ); i < 4; ++i )
562 int & operator [] (
int coord ) {
return _coords[ coord ]; }
563 const int & operator [] (
int coord )
const {
return _coords[ coord ]; }
567 return ( _coords == p._coords );
572 unsigned size()
const {
return _coords.size(); }
580 if( vec.size() >= 4 )
582 std::vector<int> fixed( vec );
584 for(
int i=vec.size(); i<4; ++i )
589 static std::vector<int>
fixed_size(
const std::vector<int> & vec )
591 if( vec.size() >= 4 )
593 std::vector<int> fixed( vec );
595 for(
int i=vec.size(); i<4; ++i )
602 int i, n = vec.size();
603 unsigned long long num = 1;
610 std::vector<int> _coords;
616 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 618 template <
typename T>
623 {
return "CartoVolume"; }
632 template <
typename T>
646 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 657 std::ostream & ostream()
const;
659 const size_t & maxT()
const;
660 const size_t & maxZ()
const;
661 const size_t & maxY()
const;
662 const size_t & maxX()
const;
674 std::ostream & _ostream;
683 const size_t & maxT()
const;
684 const size_t & maxZ()
const;
685 const size_t & maxY()
const;
686 const size_t & maxX()
const;
703 template <
typename T>
711 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES 730 template <
typename T>
731 std::ostream &
operator<< ( std::ostream & out,
736 template <
typename T>
742 # ifdef CARTO_USE_BLITZ 749 #endif // CARTODATA_VOLUME_VOLUMEBASE_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...
static std::vector< int > fixed_position(const std::vector< int > &vec)
rc_ptr< Volume< T > > _refvol
void constructBorders(const Position &bordersize, const AllocatorContext &allocatorContext, bool allocated)
blitz::Array< T, Volume< T >::DIM_MAX > _blitz
static std::string name()
const T & at(long x, long y=0, long z=0, long t=0) const
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.
T datatype
Access to T type.
Position posInRefVolumeAtLevel(const int level) const
Get position relatively to parent volume at specified level.
VolumeOStreamSetter setMaxDim(size_t m)
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
static std::string dataType()
std::ostream & operator<<(std::ostream &out, const VoxelValue< T, C > &aa)
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.
const AllocatorContext & allocatorContext() const
returns volume's AllocatorContext
carto::Volume< bool > operator==(const carto::Volume< T > &vol, const U &value)
std::vector< int > getBorders() const
Get borders for the volume.
void fill(const T &value)
Fills the volume with a given value.
bool operator==(const Position4Di &p) const
rc_ptr< Volume< T > > refVolume() const
Get parent volume.
void fillBorder(const T &value)
Fill border with a constant value.
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
static unsigned long long size_num_elements(const std::vector< int > &vec)
Volume< T > copyStructure() const
Copy the full data structure without copying the actual data.
void displayRefVolumes(const Volume< T > &vol)
Display information about volumes hierarchy.
ptrdiff_t BlitzStridesType
const std::vector< int > & toVector() const
Volume< T > copy() const
Create a volume of same dimension and copy the data.
const T & operator()(long x, long y=0, long z=0, long t=0) const
Warning: this operator is not virtual, so may not have the expected result on inherited classes (see ...
blitz::Array< T, Volume< T >::DIM_MAX >::iterator iterator
Volume< T > deepcopy() const
Copy the full data structure.
Volume< T > & operator=(const Volume< T > &other)
DataTypeTraits< T >::LongType sum() const
To avoid overflow, the biggest possible type (intmax_t, uintmax_t, double...) is used for computation...
bool any() const
True if at least one value compares to true.
bool operator!=(const Position4Di &p) const
bool all() const
True if all values compare to true.
void slotSizeChanged(const PropertyFilter &propertyFilter)
Position4Di(const U &other)
Generic constructor from any "vector-like" object, i.e.
static std::string objectType()
Position4Di(int x=0, int y=0, int z=0, int t=0)
std::vector< int > Position
Position4Di(const Position4Di &pos)
AllocatedVector< T > _items
virtual void initialize()
Initializes header info.
static std::vector< int > fixed_size(const std::vector< int > &vec)