22 #include <initializer_list>
94 PixelT ptype,
void*
ptr, std::function<
void(
void*)> deleter);
109 PixelT ptype,
void* ptr, std::function<
void(
void*)> deleter);
125 const int64_t* inROIL,
const size_t* inROIZ,
ptr<NDArray> out,
126 const int64_t* oROIL,
const size_t* oROIZ,
PixelT newtype);
165 class NDArray :
public std::enable_shared_from_this<NDArray>
173 virtual size_t ndim()
const = 0;
174 virtual size_t bytes()
const = 0;
175 virtual size_t bytesper()
const = 0;
176 virtual size_t elements()
const = 0;
177 virtual size_t dim(
size_t dir)
const = 0;
178 virtual const size_t*
dim()
const = 0;
228 return shared_from_this();
232 return shared_from_this();
235 virtual void*
data() = 0;
236 virtual const void*
data()
const = 0;
264 PixelT newtype)
const = 0;
290 const size_t* newsize)
const = 0;
304 PixelT newtype)
const = 0;
330 const size_t* newsize)
const = 0;
344 const size_t* size)
const = 0;
371 const int64_t* index,
const size_t* size,
PixelT newtype)
const = 0;
385 PixelT newtype)
const = 0;
399 virtual int write(std::string filename,
double version = 1)
const = 0;
408 virtual void zero() = 0;
415 virtual void*
__getAddr(std::initializer_list<int64_t> index)
const = 0;
416 virtual void*
__getAddr(
size_t len,
const int64_t* index)
const = 0;
417 virtual void*
__getAddr(
const std::vector<int64_t>& index)
const = 0;
418 virtual void*
__getAddr(int64_t i)
const = 0;
419 virtual void*
__getAddr(int64_t x, int64_t y, int64_t z, int64_t t)
const = 0;
421 virtual int64_t
getLinIndex(std::initializer_list<int64_t> index)
const = 0;
422 virtual int64_t
getLinIndex(
size_t len,
const int64_t* index)
const = 0;
423 virtual int64_t
getLinIndex(
const std::vector<int64_t>& index)
const = 0;
424 virtual int64_t
getLinIndex(int64_t x, int64_t y, int64_t z, int64_t t)
const = 0;
432 virtual int64_t
tlen()
const = 0;
451 template <
size_t D,
typename T>
508 const std::function<
void(
void*)>& deleter);
516 T&
operator[](
const std::vector<int64_t>& index);
517 T&
operator[](std::initializer_list<int64_t> index);
520 const T&
operator[](
const int64_t* index)
const;
521 const T&
operator[](
const std::vector<int64_t>& index)
const;
522 const T&
operator[](std::initializer_list<int64_t> index)
const;
529 size_t bytes()
const;
532 size_t dim(
size_t dir)
const;
533 const size_t*
dim()
const;
541 void resize(
const size_t dim[D]);
549 void resize(std::initializer_list<size_t> dim);
576 void graft(
const size_t dim[D], T* ptr,
const
577 std::function<
void(
void*)>& deleter);
587 virtual int write(std::string filename,
double version = 1)
const;
645 const size_t* newsize)
const;
700 const size_t* size)
const;
733 const int64_t* index,
const size_t* size,
PixelT newtype)
const;
765 inline virtual void*
__getAddr(std::initializer_list<int64_t> index)
const
770 inline virtual void*
__getAddr(
size_t len,
const int64_t* index)
const
775 inline virtual void*
__getAddr(
const std::vector<int64_t>& index)
const
784 inline virtual void*
__getAddr(int64_t x, int64_t y, int64_t z, int64_t t)
const
789 virtual int64_t
getLinIndex(std::initializer_list<int64_t> index)
const;
790 virtual int64_t
getLinIndex(
size_t len,
const int64_t* index)
const;
791 virtual int64_t
getLinIndex(
const std::vector<int64_t>& index)
const;
792 virtual int64_t
getLinIndex(int64_t x, int64_t y, int64_t z, int64_t t)
const;
820 virtual int writeJSON(gzFile file)
const;
821 virtual int writeCSV(gzFile file)
const;
virtual ptr< NDArray > copy() const =0
Performs a deep copy of the entire array.
virtual const size_t * dim() const =0
virtual int64_t getLinIndex(std::initializer_list< int64_t > index) const
virtual void * __getAddr(int64_t i) const
bool complexType() const
Returns true if the stored type is COMPLEX256, COMPLEX128, or COMPLEX64, ie is a complex floating poi...
T & operator[](const int64_t *index)
virtual int write(std::string filename, double version=1) const
Write the image to a nifti file.
virtual size_t bytesper() const =0
virtual int writePixels(gzFile file) const
void * data()
Returns a pointer to the data array. Be careful.
virtual void zero()=0
Sets all elements to zero.
std::function< void(void *)> m_freefunc
The function which should be called when deleting data. By default this will just be delete[]...
void zero()
Sets all elements to zero.
virtual int writeNifti1Image(gzFile file) const
virtual int writeNifti2Image(gzFile file) const
virtual ptr< NDArray > copyCast(size_t newdims, const size_t *newsize, PixelT newtype) const
Create a new array that is a copy of the input, possibly with new dimensions and pixeltype. The new array will have all overlapping pixels copied from the old array.
Pure virtual interface to interact with an ND array.
virtual int writeNifti2Header(gzFile file) const
ptr< const NDArray > getConstPtr() const
virtual void * __getAddr(size_t len, const int64_t *index) const
const void * data() const
Returns a pointer to the data array. Be careful.
void copyROI(ptr< const NDArray > in, const int64_t *inROIL, const size_t *inROIZ, ptr< NDArray > out, const int64_t *oROIL, const size_t *oROIZ, PixelT newtype)
Copy an roi from one image to another image. ROI's must be the same size.
PixelT type() const
Return enum PixelT type of pixels.
void resize(const size_t dim[D])
Changes the dimensions (size) of the image. This does not affect rank/dimensionality.
std::ostream & operator<<(std::ostream &os, const Matrix< D1, D2 > &b)
PixelT stringToPixelT(std::string type)
Returns a pixeltype as described by the string.
virtual int write(std::string filename, double version=1) const =0
Write the image to a nifti file.
virtual int64_t tlen() const =0
This function just returns the number of elements in a theoretical fourth dimension (ignoring orgnaiz...
bool signedType() const
Returns true if the stored type is a variant of signed integer .
ptr< NDArray > createNDArray(size_t ndim, const size_t *size, PixelT ptype)
Creates a new NDArray with dimensions set by ndim, and size set by size. Output pixel type is decided...
virtual ptr< NDArray > createAnother() const =0
Creates an identical array, but does not initialize pixel values.
virtual void * __getAddr(std::initializer_list< int64_t > index) const
virtual PixelT type() const =0
Return enum PixelT type of pixels.
virtual int64_t getLinIndex(std::initializer_list< int64_t > index) const =0
bool floatType() const
Returns true if the stored type is FLOAT32, FLOAT64, or FLOAT128, ie is a pure float type...
virtual int writeJSON(gzFile file) const
virtual void * __getAddr(int64_t x, int64_t y, int64_t z, int64_t t) const
virtual int writeCSV(gzFile file) const
std::shared_ptr< T > ptr
Make the shared_ptr name shorter...
NDArrayStore()
Constructor with initializer list. Orientation will be default (direction = identity, spacing = 1, origin = 0).
virtual ptr< NDArray > createAnother() const
Creates an identical array, but does not initialize pixel values.
bool unsignedType() const
Returns true if the stored type is a variant of unsigned signed integer.
const size_t MAXDIM
Defines the maximum supported dimension by image, used for stack-allocations.
virtual ptr< NDArray > extractCast(size_t len, const int64_t *index, const size_t *size) const
Create a new array that is a copy of the input, possibly with new dimensions or size. The new array will have all overlapping pixels copied from the old array. The new array will have the same pixel type as the input array.
virtual void * __getAddr(std::initializer_list< int64_t > index) const =0
virtual ptr< NDArray > copyCast(size_t newdims, const size_t *newsize, PixelT newtype) const =0
Create a new array that is a copy of the input, possibly with new dimensions and pixeltype. The new array will have all overlapping pixels copied from the old array.
void graft(const size_t dim[D], T *ptr, const std::function< void(void *)> &deleter)
Grafts data of the given dimensions into the image, effectively changing the image size...
virtual size_t bytes() const =0
std::string pixelTtoString(PixelT type)
Returns a string that is a descrption of the pixel type.
const size_t * dim() const
virtual void * __getAddr(const std::vector< int64_t > &index) const
virtual int writeNifti1Header(gzFile file) const
virtual size_t ndim() const =0
virtual int64_t tlen() const
This function just returns the number of elements in a theoretical fourth dimension (ignoring orgnaiz...
virtual ptr< NDArray > copy() const
Performs a deep copy of the entire array.
Basic storage unity for ND array. Creates a big chunk of memory.
virtual size_t elements() const =0
virtual ptr< NDArray > extractCast(size_t len, const int64_t *index, const size_t *size) const =0
extracts a region of this image. Zeros in the size variable indicate dimension to be removed...