34#ifndef CARTODATA_VOLUME_VOLUMEBASE_H
35#define CARTODATA_VOLUME_VOLUMEBASE_H
45#include <cartobase/smart/rcptr.h>
46#include <cartobase/type/datatypetraits.h>
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>
71 class AllocatorContext;
118 template <
typename T >
159 explicit Volume(
int sizeX = 1,
int sizeY = 1,
int sizeZ = 1,
162 = AllocatorContext(),
163 bool allocated =
true );
172 explicit Volume(
const Position4Di & size,
174 = AllocatorContext(),
175 bool allocated =
true );
180 explicit Volume(
int sizeX,
int sizeY,
int sizeZ,
181 int sizeT,
int bordersize,
183 = AllocatorContext(),
184 bool allocated =
true );
189 explicit Volume(
const Position4Di & size,
int bordersize,
191 = AllocatorContext(),
192 bool allocated =
true );
196 explicit Volume(
int sizeX,
int sizeY,
int sizeZ,
int sizeT,
197 const Position4Di & border,
199 = AllocatorContext(),
200 bool allocated =
true );
204 explicit Volume(
const Position4Di & size,
205 const Position4Di & border,
207 = AllocatorContext(),
208 bool allocated =
true );
212 explicit Volume(
const std::vector<int> & size,
214 = AllocatorContext(),
215 bool allocated =
true );
219 explicit Volume(
const std::vector<int> & size,
220 const std::vector<int> & border,
222 = AllocatorContext(),
223 bool allocated =
true );
226 Volume(
int sizeX,
int sizeY,
int sizeZ,
int sizeT, T* buffer,
227 const std::vector<long> *strides = 0 );
231 Volume(
const Position4Di & size, T* buffer,
232 const std::vector<long> *strides = 0 );
233 Volume(
const std::vector<int> & size, T* buffer,
234 const std::vector<long> *strides = 0 );
241 const Position4Di & pos = Position4Di( 0, 0, 0, 0 ),
242 const Position4Di & size = Position4Di( -1, -1, -1, -1 ),
243 const AllocatorContext & allocContext = AllocatorContext() );
252 const AllocatorContext & allocContext = AllocatorContext() );
258 T* buffer,
const std::vector<long> & strides );
288 const T&
operator()(
long x,
long y = 0,
long z = 0,
long t = 0 )
const;
290 T&
operator() (
long x,
long y = 0,
long z = 0,
long t = 0 );
291 const T&
at(
long x,
long y = 0,
long z = 0,
long t = 0 )
const;
292 T&
at(
long x,
long y = 0,
long z = 0,
long t = 0 );
295 const T&
at(
const Position4Di & position )
const;
296 T&
at(
const Position4Di & position );
297 const T &
at(
const std::vector<int> & )
const;
298 T &
at(
const std::vector<int> & );
299 const T&
operator() (
const std::vector<int> & position )
const;
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 );
351 virtual void reallocate(
int sizeX = 1,
int sizeY = 1,
int sizeZ = 1,
352 int sizeT = 1,
bool keepcontents =
false,
354 = AllocatorContext(),
bool allocate =
true,
355 const std::vector<long> *strides = 0 );
357 bool keepcontents =
false,
359 = AllocatorContext(),
bool allocate =
true,
360 const std::vector<long> *strides = 0 );
362 bool keepcontents =
false,
364 = AllocatorContext(),
bool allocate =
true,
365 const std::vector<long> *strides = 0 );
380 template <
typename OUTP>
385 template <
typename OUTP>
391 template <
typename OUTP>
400 const std::vector<int> & pos = std::vector<int>() );
407 const std::vector<int> & pos = std::vector<int>() );
410 template <
typename OUTP>
473 operator bool()
const;
540 const std::string & force_memory_layout );
567 void allocate(
int oldSizeX,
int oldSizeY,
int oldSizeZ,
int oldSizeT,
569 const std::vector<long> *strides = 0 );
572 const std::vector<long> *strides = 0 );
583 blitz::Array<T, Volume<T>::DIM_MAX>
_blitz;
592 template <
typename T>
596 explicit Position4Di(
int x = 0,
int y = 0,
int z = 0,
int t = 0 )
609 template <
typename U>
613 for(
size_t i = 0; i < size_t( other.size() ) && i < 4; ++i )
614 _coords[i] = other[i];
615 for(
size_t i =
size_t( other.size() ); i < 4; ++i )
625 int & operator [] (
int coord ) {
return _coords[ coord ]; }
626 const int & operator [] (
int coord )
const {
return _coords[ coord ]; }
630 return ( _coords == p._coords );
635 unsigned size()
const {
return _coords.size(); }
643 if( vec.size() >= 4 )
645 std::vector<int> fixed( vec );
647 for(
int i=vec.size(); i<4; ++i )
652 static std::vector<int>
fixed_size(
const std::vector<int> & vec )
654 if( vec.size() >= 4 )
656 std::vector<int> fixed( vec );
658 for(
int i=vec.size(); i<4; ++i )
665 int i, n = vec.size();
666 unsigned long long num = 1;
673 std::vector<int> _coords;
679#ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
681 template <
typename T>
686 {
return "CartoVolume"; }
695 template <
typename T>
709#ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
737 std::ostream & _ostream;
766 template <
typename T>
793 template <
typename T>
794 std::ostream &
operator<< ( std::ostream & out,
799 template <
typename T>
static void setup(Volume< T > &, Object, const AllocatorContext &, Object)
static Volume< T > * create(Object, const AllocatorContext &, Object)
static std::string name()
static std::string objectType()
static std::string dataType()
Referential holds information about coordinates system and axes.
const size_t & maxX() const
const size_t & maxT() const
const size_t & maxZ() const
const size_t & maxY() const
VolumeOStream(const VolumeOStream &other)
VolumeOStream(std::ostream &ostream)
const size_t & maxZ() const
const size_t & maxY() const
std::ostream & ostream() const
const size_t & maxT() const
const size_t & maxX() const
VolumeProxy(int sizeX=1, int sizeY=1, int sizeZ=1, int sizeT=1)
Position4Di(const Position4Di &pos)
static std::vector< int > fixed_position(const std::vector< int > &vec)
bool operator!=(const Position4Di &p) const
static std::vector< int > fixed_size(const std::vector< int > &vec)
Position4Di(int x=0, int y=0, int z=0, int t=0)
static unsigned long long size_num_elements(const std::vector< int > &vec)
Position4Di(const U &other)
Generic constructor from any "vector-like" object, i.e.
const std::vector< int > & toVector() const
bool operator==(const Position4Di &p) const
T & at(long x1, long x2, long x3, long x4, long x5, long x6=0, long x7=0, long x8=0)
iterator begin()
Iterators returned here are the most "basic" (and fastest) iterators: they go from the first voxel li...
const T & operator()(long x1, long x2, long x3, long x4, long x5, long x6=0, long x7=0, long x8=0) const
T & at(const blitz::TinyVector< int, 2 > &)
Volume(int sizeX, int sizeY, int sizeZ, int sizeT, T *buffer, const std::vector< long > *strides=0)
This constructor builds a Volume on an already allocated buffer.
void flipToOrientation(const std::string &orient, const std::string &force_memory_layout)
Flip the volume to a given orientation.
const T & at(long x1, long x2, long x3, long x4, long x5, long x6=0, long x7=0, long x8=0) const
std::vector< int > Position
const T & at(const std::vector< int > &) const
T & at(const Position4Di &position)
Volume(const Position4Di &size, T *buffer, const std::vector< long > *strides=0)
Position4Di version This constructor builds a Volume on an already allocated buffer.
blitz::Array< T, Volume< T >::DIM_MAX > at(const blitz::StridedDomain< Volume< T >::DIM_MAX > &subdomain) const
const T & at(const blitz::TinyVector< int, 2 > &) const
const Referential & referential() const
Referential and orientation information.
const AllocatorContext & allocatorContext() const
rc_ptr< Volume< T > > _refvol
T & at(const std::vector< int > &)
bool all() const
True if all values compare to true.
Volume< T > copyStructure() const
Copy the full data structure without copying the actual data.
Volume(rc_ptr< Volume< T > > other, const Position &pos, const Position &size, T *buffer, const std::vector< long > &strides)
This "very special" constructor should not be used in regular programs.
void allocate(int oldSizeX, int oldSizeY, int oldSizeZ, int oldSizeT, bool allocate, const AllocatorContext &allocatorContext, const std::vector< long > *strides=0)
virtual void reallocate(const std::vector< int > &size, bool keepcontents=false, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocate=true, const std::vector< long > *strides=0)
Volume(const Position4Di &size, const Position4Di &border, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation: Position4Di version Same as the above constructor,...
Volume(const std::vector< int > &size, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation: std::vector version Same as the above constructor,...
void setPosInRefVolume(const Position4Di &pos)
Set position in parent volume.
T & at(const blitz::TinyVector< int, 3 > &)
blitz::Array< T, Volume< T >::DIM_MAX > at(const blitz::Range &r0, const blitz::Range &r1, const blitz::Range &r2) const
const T & at(const blitz::TinyVector< int, 3 > &) const
const_iterator begin() const
Volume< T > & operator=(const Volume< T > &other)
Volume< T > deepcopy() const
Copy the full data structure.
Volume< OUTP > copy() const
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
void copySubVolume(const rc_ptr< Volume< T > > &source, const std::vector< int > &pos=std::vector< int >())
Copy voxels values from another volume pos is the position into the destination (this) volume,...
blitz::Array< T, Volume< T >::DIM_MAX > at(const blitz::Range &r0) const
bool any() const
True if at least one value compares to true.
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.
Referential & referential()
Referential and orientation information.
const Position & posInRefVolume() const
Get position in parent volume.
void allocateBorders(const std::vector< int > &border)
reallocate the volume with given borders, keep (copy) the contents.
void constructBorders(const Position &bordersize, const AllocatorContext &allocatorContext, bool allocated)
blitz::Array< T, Volume< T >::DIM_MAX > at(const blitz::RectDomain< Volume< T >::DIM_MAX > &subdomain) const
void allocate()
This function is only useful in the particular context of an unallocated Volume, when the constructor...
const T & at(const Position4Di &position) const
Volume(rc_ptr< Volume< T > > other, const Position &pos, const Position &size=Position(), const AllocatorContext &allocContext=AllocatorContext())
This is the volume view constructor.
Volume(const Volume< T > &other)
Copy constructor The copy constructors actually duplicates data buffers.
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.
T & at(const blitz::TinyVector< int, Volume< T >::DIM_MAX > &)
void setPosInRefVolume(const Position &pos)
Volume(const Position4Di &size, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation: Position4Di version.
const_iterator end() const
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.
const T & at(const blitz::TinyVector< int, 4 > &) const
Volume(const std::vector< int > &size, T *buffer, const std::vector< long > *strides=0)
void copySubVolume(const Volume< T > &source, const std::vector< int > &pos=std::vector< int >())
Copy voxels values from another volume.
blitz::Array< T, Volume< T >::DIM_MAX > at(const blitz::Range &r0, const blitz::Range &r1, const blitz::Range &r2, const blitz::Range &r3) const
std::vector< int > getBorders() const
Get borders for the volume.
Volume< OUTP > deepcopy() const
blitz::Array< T, Volume< T >::DIM_MAX > at(const blitz::Range &r0, const blitz::Range &r1) const
T & at(long x, long y=0, long z=0, long t=0)
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.
Volume(int sizeX, int sizeY, int sizeZ, int sizeT, const Position4Di &border, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation Same as the above constructor, but allows to specify a border size...
DataTypeTraits< T >::LongType sum() const
To avoid overflow, the biggest possible type (intmax_t, uintmax_t, double...) is used for computation...
std::vector< long > getStrides() const
Get strides for the volume.
Volume(const Position4Di &size, int bordersize, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation: Position4Di version Same as the above constructor,...
const T & at(const blitz::TinyVector< int, 1 > &) const
Volume(rc_ptr< Volume< T > > other, const Position4Di &pos=Position4Di(0, 0, 0, 0), const Position4Di &size=Position4Di(-1, -1, -1, -1), const AllocatorContext &allocContext=AllocatorContext())
This is the volume view constructor.
rc_ptr< Volume< T > > refVolumeAtLevel(const int level) const
Get parent volume at a specified level in volume hierarchy.
void fill(const T &value)
Fills the volume with a given value.
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
T & at(const blitz::TinyVector< int, 1 > &)
Volume(int sizeX, int sizeY, int sizeZ, int sizeT, int bordersize, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation Same as the above constructor, but allows to specify a border size...
void allocateBorders(int bsx, int bsy=-1, int bsz=-1)
reallocate the volume with given borders, keep (copy) the contents.
T & at(const blitz::TinyVector< int, 4 > &)
blitz::Array< T, Volume< T >::DIM_MAX > _blitz
Volume< OUTP > copyStructure() const
Copy the full data structure without copying the actual data.
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.
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 ...
const T & at(const blitz::TinyVector< int, Volume< T >::DIM_MAX > &) const
std::vector< int > memoryLayoutOrientation() const
determine the memory layout orientation from strides and current indices orientation.
Volume(const std::vector< int > &size, const std::vector< int > &border, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocated=true)
Volume construction and allocation: std::vector version Same as the above constructor,...
AllocatedVector< T > _items
virtual void reallocate(const Position4Di &size, bool keepcontents=false, const AllocatorContext &allocatorContext=AllocatorContext(), bool allocate=true, const std::vector< long > *strides=0)
void fillBorder(const T &value)
Fill border with a constant value.
T datatype
Access to T type.
void displayRefVolumes(const Volume< T > &vol)
Display information about volumes hierarchy.
carto::Volume< bool > operator==(const carto::Volume< T > &vol, const U &value)
std::ostream & operator<<(std::ostream &out, const VoxelValue< T, C > &aa)
VolumeOStreamSetter setMaxDim(size_t m)
ptrdiff_t BlitzStridesType