34 #ifndef CARTODATA_VOLUME_VOLUMEBASE_H 
   35 #define CARTODATA_VOLUME_VOLUMEBASE_H 
   50       #define CARTO_REENTRANT_MEMO 
   53     #include <blitz/blitz.h> 
   54     #ifdef CARTO_REENTRANT_MEMO 
   56       #undef CARTO_REENTRANT_MEMO 
   59   #include <blitz/array.h> 
   70   class AllocatorContext;
 
  117   template < 
typename T >
 
  158     explicit Volume( 
int sizeX = 1, 
int sizeY = 1, 
int sizeZ = 1,
 
  161                       = AllocatorContext(),
 
  162                      bool allocated = 
true );
 
  173                       = AllocatorContext(),
 
  174                      bool allocated = 
true );
 
  179     explicit Volume( 
int sizeX, 
int sizeY, 
int sizeZ,
 
  180                      int sizeT, 
int bordersize,
 
  182                       = AllocatorContext(),
 
  183                      bool allocated = 
true );
 
  190                       = AllocatorContext(),
 
  191                      bool allocated = 
true );
 
  195     explicit Volume( 
int sizeX, 
int sizeY, 
int sizeZ, 
int sizeT,
 
  198                       = AllocatorContext(),
 
  199                      bool allocated = 
true );
 
  206                       = AllocatorContext(),
 
  207                      bool allocated = 
true );
 
  211     explicit Volume( 
const std::vector<int> & size,
 
  213                       = AllocatorContext(),
 
  214                      bool allocated = 
true );
 
  218     explicit Volume( 
const std::vector<int> & size,
 
  219                      const std::vector<int> & border,
 
  221                       = AllocatorContext(),
 
  222                      bool allocated = 
true );
 
  225     Volume( 
int sizeX, 
int sizeY, 
int sizeZ, 
int sizeT, T* buffer,
 
  226             const std::vector<size_t> *strides = 0 );
 
  231             const std::vector<size_t> *strides = 0 );
 
  232     Volume( 
const std::vector<int> & size, T* buffer,
 
  233             const std::vector<size_t> *strides = 0 );
 
  242             const AllocatorContext & allocContext = AllocatorContext() );
 
  251             const AllocatorContext & allocContext = AllocatorContext() );
 
  257             T* buffer, 
const std::vector<size_t> & strides );
 
  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     const T & 
at( 
const blitz::TinyVector<int,1> & ) 
const;
 
  302     T & 
at( 
const blitz::TinyVector<int,1> & );
 
  303     const T & 
at( 
const blitz::TinyVector<int,2> & ) 
const;
 
  304     T & 
at( 
const blitz::TinyVector<int,2> & );
 
  305     const T & 
at( 
const blitz::TinyVector<int,3> & ) 
const;
 
  306     T & 
at( 
const blitz::TinyVector<int,3> & );
 
  307     const T & 
at( 
const blitz::TinyVector<int,4> & ) 
const;
 
  308     T & 
at( 
const blitz::TinyVector<int,4> & );
 
  315     blitz::Array<T,Volume<T>::DIM_MAX> 
at( 
const blitz::Range & r0 ) 
const;
 
  316     blitz::Array<T,Volume<T>::DIM_MAX> 
at( 
const blitz::Range & r0,
 
  317                           const blitz::Range & r1 ) 
const;
 
  318     blitz::Array<T,Volume<T>::DIM_MAX> 
at( 
const blitz::Range & r0,
 
  319                                 const blitz::Range & r1,
 
  320                                 const blitz::Range & r2 ) 
const;
 
  321     blitz::Array<T,Volume<T>::DIM_MAX> 
at( 
const blitz::Range & r0,
 
  322                                 const blitz::Range & r1,
 
  323                                 const blitz::Range & r2,
 
  324                                 const blitz::Range & r3 ) 
const;
 
  326     const T & 
at( 
long x1, 
long x2, 
long x3, 
long x4, 
long x5, 
long x6=0,
 
  327                   long x7=0, 
long x8=0 ) 
const;
 
  328     T & 
at( 
long x1, 
long x2, 
long x3, 
long x4, 
long x5, 
long x6=0,
 
  329             long x7=0, 
long x8=0 );
 
  330     const T& 
operator()( 
long x1, 
long x2, 
long x3, 
long x4, 
long x5,
 
  331                          long x6=0, 
long x7=0, 
long x8=0 ) 
const;
 
  332     T& 
operator() ( 
long x1, 
long x2, 
long x3, 
long x4, 
long x5, 
long x6=0,
 
  333                     long x7=0, 
long x8=0 );
 
  350     virtual void reallocate( 
int sizeX = 1, 
int sizeY = 1, 
int sizeZ = 1,
 
  351                              int sizeT = 1, 
bool keepcontents = 
false,
 
  353                              = AllocatorContext(), 
bool allocate = 
true,
 
  354                              const std::vector<size_t> *strides = 0 );
 
  356                              bool keepcontents = 
false,
 
  358                              = AllocatorContext(), 
bool allocate = 
true,
 
  359                              const std::vector<size_t> *strides = 0 );
 
  360     virtual void reallocate( 
const std::vector<int> & size,
 
  361                              bool keepcontents = 
false,
 
  363                              = AllocatorContext(), 
bool allocate = 
true,
 
  364                              const std::vector<size_t> *strides = 0 );
 
  374     template <
typename OUTP>
 
  379     template <
typename OUTP>
 
  385     template <
typename OUTP>
 
  394                         const std::vector<int> & pos = std::vector<int>() );
 
  401                         const std::vector<int> & pos = std::vector<int>() );
 
  404     template <
typename OUTP>
 
  415     int refLevel(
const int level) 
const;
 
  477     operator bool() 
const;
 
  492     void fill( 
const T & value );
 
  519     void allocate( 
int oldSizeX, 
int oldSizeY, 
int oldSizeZ, 
int oldSizeT,
 
  521                    const std::vector<size_t> *strides = 0 );
 
  522     void allocate( 
const std::vector<int> & oldSize,
 
  524                    const std::vector<size_t> *strides = 0 );
 
  533     blitz::Array<T, Volume<T>::DIM_MAX>  
_blitz;
 
  541   template <
typename T>
 
  545     explicit Position4Di( 
int x = 0, 
int y = 0, 
int z = 0, 
int t = 0 )
 
  558     template <
typename U>
 
  562       for( 
size_t i = 0; i < size_t( other.size() ) && i < 4; ++i )
 
  563         _coords[i] = other[i];
 
  564       for( 
size_t i = 
size_t( other.size() ); i < 4; ++i )
 
  574           int & operator [] ( 
int coord )       { 
return _coords[ coord ]; }
 
  575     const int & operator [] ( 
int coord )
 const { 
return _coords[ coord ]; }
 
  579       return ( _coords == p._coords );
 
  584     unsigned size()
 const { 
return _coords.size(); }
 
  592       if( vec.size() >= 4 )
 
  594       std::vector<int> fixed( vec );
 
  596       for( 
int i=vec.size(); i<4; ++i )
 
  601     static std::vector<int> 
fixed_size( 
const std::vector<int> & vec )
 
  603       if( vec.size() >= 4 )
 
  605       std::vector<int> fixed( vec );
 
  607       for( 
int i=vec.size(); i<4; ++i )
 
  614       int i, n = vec.size();
 
  615       unsigned long long num = 1;
 
  622     std::vector<int>  _coords;
 
  628 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 
  630   template <
typename T>
 
  635     { 
return "CartoVolume"; }
 
  644   template <
typename T>
 
  658 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES 
  686     std::ostream & _ostream;
 
  715   template <
typename T>
 
  742   template <
typename T>
 
  743   std::ostream & 
operator<< ( std::ostream & out,
 
  748   template <
typename T>
 
static std::string name()
static std::string objectType()
static std::string dataType()
const size_t & maxX() const
const size_t & maxZ() const
const size_t & maxY() const
const size_t & maxT() const
VolumeOStream(const VolumeOStream &other)
const size_t & maxT() const
VolumeOStream(std::ostream &ostream)
const size_t & maxY() const
std::ostream & ostream() const
const size_t & maxZ() const
const size_t & maxX() const
VolumeProxy is the base class for volumes.
Position4Di(const Position4Di &pos)
static std::vector< int > fixed_position(const std::vector< int > &vec)
bool operator!=(const Position4Di &p) const
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
static std::vector< int > fixed_size(const std::vector< int > &vec)
bool operator==(const Position4Di &p) const
iterator begin()
Iterators returned here are the most "basic" (and fastest) iterators: they go from the first voxel li...
Volume< T > copyStructure() const
Copy the full data structure without copying the actual data.
std::vector< int > Position
const AllocatorContext & allocatorContext() const
returns volume's AllocatorContext
rc_ptr< Volume< T > > _refvol
bool all() const
True if all values compare to true.
Volume< T > deepcopy() const
Copy the full data structure.
void setPosInRefVolume(const Position4Di &pos)
Set position in parent volume.
Volume< T > copy() const
Create a volume of same dimension and copy the data.
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< size_t > *strides=0)
allows resizing and changing allocator
Volume< T > & operator=(const Volume< T > &other)
Volume< OUTP > copyStructure() const
Copy the full data structure without copying the actual data.
blitz::Array< T, Volume< T >::DIM_MAX >::const_iterator const_iterator
bool any() const
True if at least one value compares to true.
Volume< OUTP > deepcopy() const
virtual void initialize()
Initializes header info.
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)
std::vector< size_t > getStrides() const
Get strides for the volume.
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.
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.
DataTypeTraits< T >::LongType sum() const
To avoid overflow, the biggest possible type (intmax_t, uintmax_t, double...) is used for computation...
Volume< OUTP > copy() const
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)
blitz::Array< T, Volume< T >::DIM_MAX > _blitz
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 ...
AllocatedVector< T > _items
void fillBorder(const T &value)
Fill border with a constant value.
T datatype
Access to T type.
std::ostream & operator<<(std::ostream &out, const VoxelValue< T, C > &aa)
void displayRefVolumes(const Volume< T > &vol)
Display information about volumes hierarchy.
VolumeOStreamSetter setMaxDim(size_t m)
carto::Volume< bool > operator==(const carto::Volume< T > &vol, const U &value)
ptrdiff_t BlitzStridesType