NPL
Neurological Programs and Libraries
npl::NDArray Class Referenceabstract

Pure virtual interface to interact with an ND array. More...

#include <ndarray.h>

Inherits enable_shared_from_this< NDArray >.

Inherited by npl::NDArrayStore< 1, double > [virtual], npl::NDArrayStore< 2, double > [virtual], npl::NDArrayStore< 3, double > [virtual], npl::NDArrayStore< D, double > [virtual], npl::MRImage [virtual], and npl::NDArrayStore< D, T > [virtual].

Public Member Functions

virtual size_t ndim () const =0
 
virtual size_t bytes () const =0
 
virtual size_t bytesper () const =0
 
virtual size_t elements () const =0
 
virtual size_t dim (size_t dir) const =0
 
virtual const size_t * dim () const =0
 
virtual PixelT type () const =0
 Return enum PixelT type of pixels. More...
 
bool floatType () const
 Returns true if the stored type is FLOAT32, FLOAT64, or FLOAT128, ie is a pure float type. More...
 
bool complexType () const
 Returns true if the stored type is COMPLEX256, COMPLEX128, or COMPLEX64, ie is a complex floating point type. More...
 
bool signedType () const
 Returns true if the stored type is a variant of signed integer . More...
 
bool unsignedType () const
 Returns true if the stored type is a variant of unsigned signed integer. More...
 
ptr< NDArraygetPtr ()
 
ptr< const NDArraygetConstPtr () const
 
virtual void * data ()=0
 
virtual const void * data () const =0
 
virtual ptr< NDArraycopy () const =0
 Performs a deep copy of the entire array. More...
 
virtual ptr< NDArraycreateAnother () const =0
 Creates an identical array, but does not initialize pixel values. More...
 
virtual ptr< NDArraycreateAnother (size_t newdims, const size_t *newsize, PixelT newtype) const =0
 Create a new array that is the same underlying type as this. If this is an image then it will also copy the metdata, but NOT the pixels. More...
 
virtual ptr< NDArraycreateAnother (PixelT newtype) const =0
 Create a new array that is the same underlying type as this, but with a different pixel type. More...
 
virtual ptr< NDArraycreateAnother (size_t newdims, const size_t *newsize) const =0
 Create a new array that is the same underlying type as this, and same pixel type and orientation as this, but with a different size. More...
 
virtual ptr< NDArraycopyCast (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. More...
 
virtual ptr< NDArraycopyCast (PixelT newtype) const =0
 Create a new array that is a copy of the input, with same dimensions but pxiels cast to newtype. The new array will have all overlapping pixels copied from the old array. More...
 
virtual ptr< NDArraycopyCast (size_t newdims, const size_t *newsize) const =0
 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. More...
 
virtual ptr< NDArrayextractCast (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. More...
 
virtual ptr< NDArrayextractCast (size_t len, const size_t *size) const =0
 extracts a region of this image. Zeros in the size variable indicate dimension to be removed. More...
 
virtual ptr< NDArrayextractCast (size_t len, const int64_t *index, const size_t *size, PixelT newtype) const =0
 extracts a region of this image. Zeros in the size variable indicate dimension to be removed. More...
 
virtual ptr< NDArrayextractCast (size_t len, const size_t *size, PixelT newtype) const =0
 extracts a region of this image. Zeros in the size variable indicate dimension to be removed. More...
 
virtual int write (std::string filename, double version=1) const =0
 Write the image to a nifti file. More...
 
virtual void zero ()=0
 Sets all elements to zero. More...
 
virtual void * __getAddr (std::initializer_list< int64_t > index) const =0
 
virtual void * __getAddr (size_t len, const int64_t *index) const =0
 
virtual void * __getAddr (const std::vector< int64_t > &index) const =0
 
virtual void * __getAddr (int64_t i) const =0
 
virtual void * __getAddr (int64_t x, int64_t y, int64_t z, int64_t t) const =0
 
virtual int64_t getLinIndex (std::initializer_list< int64_t > index) const =0
 
virtual int64_t getLinIndex (size_t len, const int64_t *index) const =0
 
virtual int64_t getLinIndex (const std::vector< int64_t > &index) const =0
 
virtual int64_t getLinIndex (int64_t x, int64_t y, int64_t z, int64_t t) const =0
 
virtual int64_t tlen () const =0
 This function just returns the number of elements in a theoretical fourth dimension (ignoring orgnaization of higher dimensions) More...
 

Protected Member Functions

 NDArray ()
 

Protected Attributes

std::function< void(void *)> m_freefunc
 The function which should be called when deleting data. By default this will just be delete[], but if data is grafted or if. More...
 

Detailed Description

Pure virtual interface to interact with an ND array.

Definition at line 165 of file ndarray.h.

Constructor & Destructor Documentation

npl::NDArray::NDArray ( )
inlineprotected

Definition at line 435 of file ndarray.h.

Member Function Documentation

virtual void* npl::NDArray::__getAddr ( std::initializer_list< int64_t >  index) const
pure virtual
virtual void* npl::NDArray::__getAddr ( size_t  len,
const int64_t *  index 
) const
pure virtual
virtual void* npl::NDArray::__getAddr ( const std::vector< int64_t > &  index) const
pure virtual
virtual void* npl::NDArray::__getAddr ( int64_t  i) const
pure virtual
virtual void* npl::NDArray::__getAddr ( int64_t  x,
int64_t  y,
int64_t  z,
int64_t  t 
) const
pure virtual
bool npl::NDArray::complexType ( ) const
inline

Returns true if the stored type is COMPLEX256, COMPLEX128, or COMPLEX64, ie is a complex floating point type.

Returns
True if the number can be represented by a complex<long double>

Definition at line 203 of file ndarray.h.

virtual ptr<NDArray> npl::NDArray::copyCast ( size_t  newdims,
const size_t *  newsize,
PixelT  newtype 
) const
pure virtual

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.

Parameters
newdimsNumber of dimensions in copied output
newsizeSize of output, this array should be of size newdims
newtypeType of pixels in output array
Returns
Image with overlapping sections cast and copied from 'in'

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::copyCast ( PixelT  newtype) const
pure virtual

Create a new array that is a copy of the input, with same dimensions but pxiels cast to newtype. The new array will have all overlapping pixels copied from the old array.

Parameters
newtypeType of pixels in output array
Returns
Image with overlapping sections cast and copied from 'in'

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::copyCast ( size_t  newdims,
const size_t *  newsize 
) const
pure virtual

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.

Parameters
newdimsNumber of dimensions in output array
newsizeInput array of length newdims that gives the size of output array,
Returns
Image with overlapping sections cast and copied from 'in'

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::createAnother ( size_t  newdims,
const size_t *  newsize,
PixelT  newtype 
) const
pure virtual

Create a new array that is the same underlying type as this. If this is an image then it will also copy the metdata, but NOT the pixels.

Parameters
newdimsNumber of dimensions in copied output
newsizeSize of output, this array should be of size newdims
newtypeType of pixels in output array
Returns
Image with identical orientation but different size and pixeltype

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::createAnother ( PixelT  newtype) const
pure virtual

Create a new array that is the same underlying type as this, but with a different pixel type.

Parameters
newtypeType of pixels in output array
Returns
Image with identical orientation and size but different pixel type

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::createAnother ( size_t  newdims,
const size_t *  newsize 
) const
pure virtual

Create a new array that is the same underlying type as this, and same pixel type and orientation as this, but with a different size.

Parameters
newdimsNumber of dimensions in output array
newsizeInput array of length newdims that gives the size of output array,
Returns
Image with identical orientation and pixel type but different size from this

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual size_t npl::NDArray::dim ( size_t  dir) const
pure virtual
virtual ptr<NDArray> npl::NDArray::extractCast ( size_t  len,
const int64_t *  index,
const size_t *  size 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/newsize arrays
indexIndex to start copying from.
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
Returns
Image with overlapping sections cast and copied from 'in'

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::extractCast ( size_t  len,
const size_t *  size 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/size arrays
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
Returns
Image with overlapping sections cast and copied from 'in'

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::extractCast ( size_t  len,
const int64_t *  index,
const size_t *  size,
PixelT  newtype 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/size arrays
indexIndex to start copying from.
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
newtypePixel type of output image.
Returns
Image with overlapping sections cast and copied from 'in'

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

virtual ptr<NDArray> npl::NDArray::extractCast ( size_t  len,
const size_t *  size,
PixelT  newtype 
) const
pure virtual

extracts a region of this image. Zeros in the size variable indicate dimension to be removed.

Parameters
lenLength of index/size arrays
sizeSize of output image. Note length 0 dimensions will be removed, while length 1 dimensions will be left.
newtypePixel type of output image.
Returns
Image with overlapping sections cast and copied from 'in'

Implemented in npl::MRImageStore< D, T >, npl::MRImageStore< 3, double >, npl::MRImageStore< 4, double >, npl::MRImageStore< 5, double >, npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, npl::NDArrayStore< 3, double >, and npl::MRImage.

bool npl::NDArray::floatType ( ) const
inline

Returns true if the stored type is FLOAT32, FLOAT64, or FLOAT128, ie is a pure float type.

Returns
True if the number can be represented by a long double

Definition at line 193 of file ndarray.h.

ptr<const NDArray> npl::NDArray::getConstPtr ( ) const
inline

Definition at line 231 of file ndarray.h.

virtual int64_t npl::NDArray::getLinIndex ( std::initializer_list< int64_t >  index) const
pure virtual
virtual int64_t npl::NDArray::getLinIndex ( size_t  len,
const int64_t *  index 
) const
pure virtual
virtual int64_t npl::NDArray::getLinIndex ( const std::vector< int64_t > &  index) const
pure virtual
virtual int64_t npl::NDArray::getLinIndex ( int64_t  x,
int64_t  y,
int64_t  z,
int64_t  t 
) const
pure virtual
ptr<NDArray> npl::NDArray::getPtr ( )
inline

Definition at line 227 of file ndarray.h.

bool npl::NDArray::signedType ( ) const
inline

Returns true if the stored type is a variant of signed integer .

Returns
True if the number can be represented by an int64_t

Definition at line 212 of file ndarray.h.

virtual int64_t npl::NDArray::tlen ( ) const
pure virtual

This function just returns the number of elements in a theoretical fourth dimension (ignoring orgnaization of higher dimensions)

Returns
number of elements in the 4th or greater dimensions

Implemented in npl::NDArrayStore< D, T >, npl::NDArrayStore< D, double >, npl::NDArrayStore< 1, double >, npl::NDArrayStore< 2, double >, and npl::NDArrayStore< 3, double >.

virtual PixelT npl::NDArray::type ( ) const
pure virtual
bool npl::NDArray::unsignedType ( ) const
inline

Returns true if the stored type is a variant of unsigned signed integer.

Returns
True if the number can be represented by an size_t

Definition at line 222 of file ndarray.h.

virtual int npl::NDArray::write ( std::string  filename,
double  version = 1 
) const
pure virtual
virtual void npl::NDArray::zero ( )
pure virtual

Member Data Documentation

std::function<void(void*)> npl::NDArray::m_freefunc
protected

The function which should be called when deleting data. By default this will just be delete[], but if data is grafted or if.

Definition at line 435 of file ndarray.h.


The documentation for this class was generated from the following file: