NPL
Neurological Programs and Libraries
npl::MRImageStore< D, T > Class Template Reference

MRImageStore is a version of NDArray that has an orientation matrix. Right now it also has additional data that is unique to nifti. Eventually this class will be forked into a subclass, and this will only have the orientation. More...

#include <mrimage.h>

Inherits npl::NDArrayStore< D, T >, and npl::MRImage.

Public Member Functions

 MRImageStore (std::initializer_list< size_t > a_args)
 Constructor with initializer list. Orientation will be default (direction = identity, spacing = 1, origin = 0). More...
 
 MRImageStore (const std::vector< size_t > &a_args)
 Constructor with vector. Orientation will be default (direction = identity, spacing = 1, origin = 0). More...
 
 MRImageStore (size_t len, const size_t *size)
 Constructor with array of length len, Orientation will be default (direction = identity, spacing = 1, origin = 0). More...
 
 MRImageStore (size_t len, const size_t *size, T *ptr, const std::function< void(void *)> &deleter)
 Constructor which uses a preexsting array, to graft into the image. No new allocation will be performed, however ownership of the array will be taken, meaning it could be deleted anytime after this constructor completes. More...
 
 MRImageStore ()
 Default constructor, uses identity for direction matrix, 1 for spacing and 0 for origin. Image size is 0. More...
 
virtual int indexToPoint (size_t len, const int64_t *xyz, double *ras) const
 Converts an index in pixel space to RAS, physical/time coordinates. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras. More...
 
virtual int indexToPoint (size_t len, const double *xyz, double *ras) const
 Converts an index in pixel space to RAS, physical/time coordinates. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras. More...
 
virtual int pointToIndex (size_t len, const double *ras, double *xyz) const
 Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras. More...
 
virtual int pointToIndex (size_t len, const double *ras, int64_t *index) const
 Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras. More...
 
virtual int orientVector (size_t len, const double *xyz, double *ras) const
 Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix. More...
 
virtual int disOrientVector (size_t len, const double *ras, double *xyz) const
 Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix. More...
 
virtual bool pointInsideFOV (size_t len, const double *ras) const
 Returns true if the point is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array. More...
 
virtual bool indexInsideFOV (size_t len, const double *xyz) const
 Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array. More...
 
virtual bool indexInsideFOV (size_t len, const int64_t *xyz) const
 Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array. More...
 
std::string getUnits (size_t d)
 Returns units of given dimension, note that this is prior to the direction matrix, so if there is oblique orientation you are really looking at a mix of units. More...
 
int write (std::string filename, double version) const
 Write out nifti image with the current images data. More...
 
void printSelf ()
 Print information about the image. More...
 
virtual ptr< NDArraycopy () const
 Performs a deep copy of the entire image and all metadata. More...
 
virtual ptr< NDArraycreateAnother () const
 Creates an identical array, but does not initialize pixel values. More...
 
virtual ptr< NDArraycreateAnother (size_t newdims, const size_t *newsize, PixelT newtype) const
 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
 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
 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
 Create a new image that is a copy of the input, possibly with new dimensions and pixeltype. The new image will have all overlapping pixels copied from the old image. More...
 
virtual ptr< NDArraycopyCast (PixelT newtype) const
 Create a new image that is a copy of the input, with same dimensions but pxiels cast to newtype. The new image will have all overlapping pixels copied from the old image. More...
 
virtual ptr< NDArraycopyCast (size_t newdims, const size_t *newsize) const
 Create a new image that is a copy of the input, possibly with new dimensions or size. The new image will have all overlapping pixels copied from the old image. The new image will have the same pixel type as the input image. More...
 
virtual ptr< NDArrayextractCast (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. More...
 
virtual ptr< NDArrayextractCast (size_t len, 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. Index assumed to be [0,0,...], so the output image will start at the origin of this image. More...
 
virtual ptr< NDArrayextractCast (size_t len, const int64_t *index, const size_t *size, PixelT newtype) 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. More...
 
virtual ptr< NDArrayextractCast (size_t len, const size_t *size, PixelT newtype) 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. Index assumed to be [0,0,...], so the output image will start at the origin of this image. More...
 
ptr< MRImagecloneImage () const
 Create an exact copy of the current image object, and return a pointer to it. More...
 
T & operator[] (const int64_t *index)
 
T & operator[] (const std::vector< int64_t > &index)
 
T & operator[] (std::initializer_list< int64_t > index)
 
T & operator[] (int64_t pixel)
 
const T & operator[] (const int64_t *index) const
 
const T & operator[] (const std::vector< int64_t > &index) const
 
const T & operator[] (std::initializer_list< int64_t > index) const
 
const T & operator[] (int64_t pixel) const
 
size_t ndim () const
 
size_t bytes () const
 
size_t bytesper () const
 
size_t elements () const
 
size_t dim (size_t dir) const
 
const size_t * dim () const
 
void resize (const size_t dim[D])
 Changes the dimensions (size) of the image. This does not affect rank/dimensionality. More...
 
void resize (std::initializer_list< size_t > dim)
 Changes the dimensions (size) of the image. This does not affect rank/dimensionality. More...
 
PixelT type () const
 Return enum PixelT type of pixels. More...
 
void * data ()
 Returns a pointer to the data array. Be careful. More...
 
const void * data () const
 Returns a pointer to the data array. Be careful. More...
 
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. More...
 
void zero ()
 Sets all elements to zero. More...
 
virtual void * __getAddr (std::initializer_list< int64_t > index) const
 
virtual void * __getAddr (size_t len, const int64_t *index) const
 
virtual void * __getAddr (const std::vector< int64_t > &index) const
 
virtual void * __getAddr (int64_t i) const
 
virtual void * __getAddr (int64_t x, int64_t y, int64_t z, int64_t t) const
 
virtual int64_t getLinIndex (std::initializer_list< int64_t > index) const
 
virtual int64_t getLinIndex (size_t len, const int64_t *index) const
 
virtual int64_t getLinIndex (const std::vector< int64_t > &index) const
 
virtual int64_t getLinIndex (int64_t x, int64_t y, int64_t z, int64_t t) const
 
virtual int64_t tlen () const
 This function just returns the number of elements in a theoretical fourth dimension (ignoring orgnaization of higher dimensions) 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
 
void orientDefault ()
 Default orientation (dir=ident, space=1 and origin=0), also resizes them. So this could be called without first initializing size. More...
 
bool isOriented ()
 Returns true if the image has a valid orientation. More...
 
void setOrient (const VectorXd &neworig, const VectorXd &newspace, const MatrixXd &newdir, bool reinit=true, CoordinateT coord=QFORM)
 Update the orientation of the pixels in RAS space. More...
 
const double & direction (int64_t row, int64_t col) const
 Returns reference to a value in the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. More...
 
const double & invdirection (int64_t row, int64_t col) const
 Returns reference to a value in the inverse direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. More...
 
const MatrixXd & getDirection () const
 Returns reference to the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. More...
 
void setDirection (const MatrixXd &newdir, bool reinit, CoordinateT coord=QFORM)
 Updates orientation information. If reinit is given then it will first set direction to the identity. otherwise old values will be left. After this the first min(DIMENSION,dir.rows()) columns and min(DIMENSION,dir.cols()) columns will be copies into the image direction matrix. More...
 
double & origin (int64_t row)
 Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0. More...
 
const double & origin (int64_t row) const
 Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0. More...
 
const VectorXd & getOrigin () const
 Returns const reference to the origin vector. This is the physical point that corresponds to index 0. More...
 
void setOrigin (const VectorXd &neworigin, bool reinit)
 Sets the origin vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied. More...
 
double & spacing (int64_t row)
 Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes. More...
 
const double & spacing (int64_t row) const
 Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes. More...
 
const VectorXd & getSpacing () const
 Returns const reference to the spacing vector. This is the physical distance between adjacent indexes. More...
 
void setSpacing (const VectorXd &newspacing, bool reinit)
 Sets the spacing vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied. More...
 
virtual bool matchingOrient (ptr< const MRImage > other, bool checkdim, bool checksize, double tol=0.01) const
 Returns true of the other image has matching orientation as this. If checksize = true, then it will also check the size of the two images and return true if both orientation and size match, and false if they don't. More...
 
virtual bool isIsotropic (bool only3d=true, double tol=0.01) const
 Returns true if the image is isotropic (same spacing in all dimensions). This can be looseened to checking only the first 3 dims with only3d = true. Tolerence in the absolute maximum difference between the first dim and any other dim. More...
 
ptr< MRImagegetPtr ()
 Returns a pointer to self. More...
 
ptr< const MRImagegetConstPtr () const
 Returns a constant pointer to self. More...
 
virtual void copyMetadata (ptr< const MRImage > src)
 Copies metadata from another image. This includes slice timing, anything read from nifti files, spacing, orientation etc, but NOT pixel data, size, and dimensionality. More...
 
void updateSliceTiming (double duration, int start, int end, SliceOrderT order)
 

Public Attributes

T * _m_data
 
size_t _m_stride [D]
 
size_t _m_dim [D]
 
int m_freqdim
 
int m_phasedim
 
int m_slicedim
 
CoordinateT m_coordinate
 
double m_slice_duration
 
int m_slice_start
 
int m_slice_end
 
SliceOrderT m_slice_order
 
std::map< int64_t, double > m_slice_timing
 

Protected Member Functions

int writeNifti1Image (gzFile file) const
 
int writeNifti2Image (gzFile file) const
 
int writeNifti1Header (gzFile file) const
 
int writeNifti2Header (gzFile file) const
 
int writeJSON (gzFile file) const
 
void updateStrides ()
 
virtual int writePixels (gzFile file) const
 
virtual int writeCSV (gzFile file) const
 

Protected Attributes

std::string m_units [D]
 Vector of units for each dimension. More...
 
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...
 
MatrixXd m_direction
 Direction Matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. Note that you should not set this directly,. More...
 
MatrixXd m_inv_direction
 Inverse of Direction Matrix. More...
 
VectorXd m_spacing
 Spacing vector. Indicates distance between adjacent pixels in each dimension. Note that you should not set this directly, use setSpacing() instead because it will update the affine Matrix. More...
 
VectorXd m_origin
 Origin vector. Indicates the RAS coordinates of index [0,0,0,..] Note that you should not set this directly, use setOrigin() instead because it will update the affine Matrix. More...
 

Detailed Description

template<size_t D, typename T>
class npl::MRImageStore< D, T >

MRImageStore is a version of NDArray that has an orientation matrix. Right now it also has additional data that is unique to nifti. Eventually this class will be forked into a subclass, and this will only have the orientation.

Template Parameters
DNumber of dimensions
TPixel type

Definition at line 748 of file mrimage.h.

Constructor & Destructor Documentation

template<size_t D, typename T>
npl::MRImageStore< D, T >::MRImageStore ( std::initializer_list< size_t >  a_args)

Constructor with initializer list. Orientation will be default (direction = identity, spacing = 1, origin = 0).

Parameters
a_argsdimensions of input, the length of this initializer list may not be fully used if a_args is longer than D. If it is shorter then D then additional dimensions are left as size 1.
template<size_t D, typename T>
npl::MRImageStore< D, T >::MRImageStore ( const std::vector< size_t > &  a_args)

Constructor with vector. Orientation will be default (direction = identity, spacing = 1, origin = 0).

Parameters
a_argsdimensions of input, the length of this initializer list may not be fully used if a_args is longer than D. If it is shorter then D then additional dimensions are left as size 1.
template<size_t D, typename T>
npl::MRImageStore< D, T >::MRImageStore ( size_t  len,
const size_t *  size 
)

Constructor with array of length len, Orientation will be default (direction = identity, spacing = 1, origin = 0).

Parameters
lenLength of array 'size'
sizedimensions of input, the length of this initializer list may not be fully used if a_args is longer than D. If it is shorter then D then additional dimensions are left as size 1.
template<size_t D, typename T>
npl::MRImageStore< D, T >::MRImageStore ( size_t  len,
const size_t *  size,
T *  ptr,
const std::function< void(void *)> &  deleter 
)

Constructor which uses a preexsting array, to graft into the image. No new allocation will be performed, however ownership of the array will be taken, meaning it could be deleted anytime after this constructor completes.

Parameters
lenLength of array 'size'
sizedimensions of input, the length of this initializer list may not be fully used if a_args is longer than D. If it is shorter then D then additional dimensions are left as size 1.
ptrPointer to data array, should be allocated with new, and size should be exactly sizeof(T)*size[0]*size[1]*...*size[len-1]
deleterFunction to use to delete (free) ptr
template<size_t D, typename T>
npl::MRImageStore< D, T >::MRImageStore ( )

Default constructor, uses identity for direction matrix, 1 for spacing and 0 for origin. Image size is 0.

Member Function Documentation

template<size_t D, typename T>
virtual void* npl::NDArrayStore< D, T >::__getAddr ( std::initializer_list< int64_t >  index) const
inlinevirtualinherited

Implements npl::NDArray.

Definition at line 765 of file ndarray.h.

template<size_t D, typename T>
virtual void* npl::NDArrayStore< D, T >::__getAddr ( size_t  len,
const int64_t *  index 
) const
inlinevirtualinherited

Implements npl::NDArray.

Definition at line 770 of file ndarray.h.

template<size_t D, typename T>
virtual void* npl::NDArrayStore< D, T >::__getAddr ( const std::vector< int64_t > &  index) const
inlinevirtualinherited

Implements npl::NDArray.

Definition at line 775 of file ndarray.h.

template<size_t D, typename T>
virtual void* npl::NDArrayStore< D, T >::__getAddr ( int64_t  i) const
inlinevirtualinherited

Implements npl::NDArray.

Definition at line 780 of file ndarray.h.

template<size_t D, typename T>
virtual void* npl::NDArrayStore< D, T >::__getAddr ( int64_t  x,
int64_t  y,
int64_t  z,
int64_t  t 
) const
inlinevirtualinherited

Implements npl::NDArray.

Definition at line 784 of file ndarray.h.

template<size_t D, typename T>
size_t npl::NDArrayStore< D, T >::bytes ( ) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
size_t npl::NDArrayStore< D, T >::bytesper ( ) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
ptr<MRImage> npl::MRImageStore< D, T >::cloneImage ( ) const
virtual

Create an exact copy of the current image object, and return a pointer to it.

Returns
Pointer to exact duplicate of current image.

Implements npl::MRImage.

bool npl::NDArray::complexType ( ) const
inlineinherited

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.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::copy ( ) const
virtual

Performs a deep copy of the entire image and all metadata.

Returns
Copied image.

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::copyCast ( size_t  newdims,
const size_t *  newsize,
PixelT  newtype 
) const
virtual

Create a new image that is a copy of the input, possibly with new dimensions and pixeltype. The new image will have all overlapping pixels copied from the old image.

Parameters
newdimsNumber of dimensions in output image
newsizeSize of output image
newtypeType of pixels in output image
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::copyCast ( PixelT  newtype) const
virtual

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

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

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::copyCast ( size_t  newdims,
const size_t *  newsize 
) const
virtual

Create a new image that is a copy of the input, possibly with new dimensions or size. The new image will have all overlapping pixels copied from the old image. The new image will have the same pixel type as the input image.

Parameters
newdimsNumber of dimensions in output image
newsizeSize of output image
Returns
Image with overlapping sections cast and copied from 'in'

Implements npl::MRImage.

virtual void npl::MRImage::copyMetadata ( ptr< const MRImage src)
virtualinherited

Copies metadata from another image. This includes slice timing, anything read from nifti files, spacing, orientation etc, but NOT pixel data, size, and dimensionality.

Parameters
srcOther image to copy from
template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::createAnother ( ) const
virtual

Creates an identical array, but does not initialize pixel values.

Returns
New array.

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::createAnother ( size_t  newdims,
const size_t *  newsize,
PixelT  newtype 
) const
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

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::createAnother ( PixelT  newtype) const
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

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::createAnother ( size_t  newdims,
const size_t *  newsize 
) const
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

Implements npl::MRImage.

template<size_t D, typename T>
void* npl::NDArrayStore< D, T >::data ( )
inlinevirtualinherited

Returns a pointer to the data array. Be careful.

Returns
Pointer to data

Implements npl::NDArray.

Definition at line 559 of file ndarray.h.

template<size_t D, typename T>
const void* npl::NDArrayStore< D, T >::data ( ) const
inlinevirtualinherited

Returns a pointer to the data array. Be careful.

Returns
Pointer to data

Implements npl::NDArray.

Definition at line 566 of file ndarray.h.

template<size_t D, typename T>
size_t npl::NDArrayStore< D, T >::dim ( size_t  dir) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
const size_t* npl::NDArrayStore< D, T >::dim ( ) const
virtualinherited

Implements npl::NDArray.

const double& npl::MRImage::direction ( int64_t  row,
int64_t  col 
) const
inherited

Returns reference to a value in the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid.

Parameters
rowRow to access
colColumn to access
Returns
Element in direction matrix
template<size_t D, typename T>
virtual int npl::MRImageStore< D, T >::disOrientVector ( size_t  len,
const double *  ras,
double *  xyz 
) const
virtual

Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix.

Parameters
lenLength of input vector (may be different than dimension - extra values will be ignored, missing values will be assumed zero)
rasInput vector in physical space.
xyzOutput vector in index space ijk. This is the product of the input vector and inverse rotation matrix
Returns
Success

Implements npl::MRImage.

template<size_t D, typename T>
size_t npl::NDArrayStore< D, T >::elements ( ) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::extractCast ( size_t  len,
const int64_t *  index,
const size_t *  size 
) const
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
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'

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::extractCast ( size_t  len,
const size_t *  size 
) const
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. Index assumed to be [0,0,...], so the output image will start at the origin of this image.

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'

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::extractCast ( size_t  len,
const int64_t *  index,
const size_t *  size,
PixelT  newtype 
) const
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
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'

Implements npl::MRImage.

template<size_t D, typename T>
virtual ptr<NDArray> npl::MRImageStore< D, T >::extractCast ( size_t  len,
const size_t *  size,
PixelT  newtype 
) const
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. Index assumed to be [0,0,...], so the output image will start at the origin of this image.

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'

Implements npl::MRImage.

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

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
inlineinherited

Definition at line 231 of file ndarray.h.

ptr<const MRImage> npl::MRImage::getConstPtr ( ) const
inlineinherited

Returns a constant pointer to self.

Returns
this

Definition at line 490 of file mrimage.h.

const MatrixXd& npl::MRImage::getDirection ( ) const
inherited

Returns reference to the direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid.

Returns
Direction matrix
template<size_t D, typename T>
virtual int64_t npl::NDArrayStore< D, T >::getLinIndex ( std::initializer_list< int64_t >  index) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
virtual int64_t npl::NDArrayStore< D, T >::getLinIndex ( size_t  len,
const int64_t *  index 
) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
virtual int64_t npl::NDArrayStore< D, T >::getLinIndex ( const std::vector< int64_t > &  index) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
virtual int64_t npl::NDArrayStore< D, T >::getLinIndex ( int64_t  x,
int64_t  y,
int64_t  z,
int64_t  t 
) const
virtualinherited

Implements npl::NDArray.

const VectorXd& npl::MRImage::getOrigin ( ) const
inherited

Returns const reference to the origin vector. This is the physical point that corresponds to index 0.

Returns
Origin vector
ptr<NDArray> npl::NDArray::getPtr ( )
inlineinherited

Definition at line 227 of file ndarray.h.

ptr<MRImage> npl::MRImage::getPtr ( )
inlineinherited

Returns a pointer to self.

Returns
this

Definition at line 481 of file mrimage.h.

const VectorXd& npl::MRImage::getSpacing ( ) const
inherited

Returns const reference to the spacing vector. This is the physical distance between adjacent indexes.

Returns
Spacing vector
template<size_t D, typename T>
std::string npl::MRImageStore< D, T >::getUnits ( size_t  d)
inline

Returns units of given dimension, note that this is prior to the direction matrix, so if there is oblique orientation you are really looking at a mix of units.

Parameters
dDimension
Returns
String describing units.

Definition at line 950 of file mrimage.h.

template<size_t D, typename T>
void npl::NDArrayStore< D, T >::graft ( const size_t  dim[D],
T *  ptr,
const std::function< void(void *)> &  deleter 
)
inherited

Grafts data of the given dimensions into the image, effectively changing the image size.

Parameters
dimDimensions of image
ptrPointer to data which we will take control of
deleterFunction which can be called on ptr to delete it.
template<size_t D, typename T>
virtual bool npl::MRImageStore< D, T >::indexInsideFOV ( size_t  len,
const double *  xyz 
) const
virtual

Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array.

Parameters
lenLength of xyz array
xyzArray of continouos indices
Returns
Whether the index would round to a voxel inside the image.

Implements npl::MRImage.

template<size_t D, typename T>
virtual bool npl::MRImageStore< D, T >::indexInsideFOV ( size_t  len,
const int64_t *  xyz 
) const
virtual

Returns true if the constinuous index is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array.

Parameters
lenLength of xyz array
xyzArray of indices
Returns
Whether the index is inside the image

Implements npl::MRImage.

template<size_t D, typename T>
virtual int npl::MRImageStore< D, T >::indexToPoint ( size_t  len,
const int64_t *  xyz,
double *  ras 
) const
virtual

Converts an index in pixel space to RAS, physical/time coordinates. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras.

Parameters
lenLength of xyz/ras arrays.
xyzArray in xyz... coordinates (maybe as long as you want).
rasCorresponding coordinate
Returns
0

Implements npl::MRImage.

template<size_t D, typename T>
virtual int npl::MRImageStore< D, T >::indexToPoint ( size_t  len,
const double *  xyz,
double *  ras 
) const
virtual

Converts an index in pixel space to RAS, physical/time coordinates. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras.

Parameters
lenLength of xyz/ras arrays.
xyzArray in xyz... coordinates (maybe as long as you want).
rasCorresponding coordinate
Returns
0

Implements npl::MRImage.

const double& npl::MRImage::invdirection ( int64_t  row,
int64_t  col 
) const
inherited

Returns reference to a value in the inverse direction matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid.

Parameters
rowRow to access
colColumn to access
Returns
Element in direction matrix
virtual bool npl::MRImage::isIsotropic ( bool  only3d = true,
double  tol = 0.01 
) const
virtualinherited

Returns true if the image is isotropic (same spacing in all dimensions). This can be looseened to checking only the first 3 dims with only3d = true. Tolerence in the absolute maximum difference between the first dim and any other dim.

Parameters
only3dOnly check spacing in the first 3 dimensions (default)
tolTolerence in the absolute maximum difference between the first dim and any other dim.
Returns
True if the image is roughly isotropic
bool npl::MRImage::isOriented ( )
inlineinherited

Returns true if the image has a valid orientation.

Returns
True if the image has a valid orientation

Definition at line 145 of file mrimage.h.

virtual bool npl::MRImage::matchingOrient ( ptr< const MRImage other,
bool  checkdim,
bool  checksize,
double  tol = 0.01 
) const
virtualinherited

Returns true of the other image has matching orientation as this. If checksize = true, then it will also check the size of the two images and return true if both orientation and size match, and false if they don't.

Parameters
otherMRimage to compare.
checkdimWhether to enforce identical dimensionality. If this is false then the first min(D1,D2) dimensions will be checked, if this is true then mismatched dimensionality will cause this to return a false
checksizeWhether to enforce identical size as well as orientation
toltolerance for differences in orientation. Because the orientation matrix must undergo floating operationt to convert from Quaternions there are likely to be (small) errors.
Returns
True if the two images have matching orientation information.
template<size_t D, typename T>
size_t npl::NDArrayStore< D, T >::ndim ( ) const
virtualinherited

Implements npl::NDArray.

template<size_t D, typename T>
T& npl::NDArrayStore< D, T >::operator[] ( const int64_t *  index)
inherited
template<size_t D, typename T>
T& npl::NDArrayStore< D, T >::operator[] ( const std::vector< int64_t > &  index)
inherited
template<size_t D, typename T>
T& npl::NDArrayStore< D, T >::operator[] ( std::initializer_list< int64_t >  index)
inherited
template<size_t D, typename T>
T& npl::NDArrayStore< D, T >::operator[] ( int64_t  pixel)
inherited
template<size_t D, typename T>
const T& npl::NDArrayStore< D, T >::operator[] ( const int64_t *  index) const
inherited
template<size_t D, typename T>
const T& npl::NDArrayStore< D, T >::operator[] ( const std::vector< int64_t > &  index) const
inherited
template<size_t D, typename T>
const T& npl::NDArrayStore< D, T >::operator[] ( std::initializer_list< int64_t >  index) const
inherited
template<size_t D, typename T>
const T& npl::NDArrayStore< D, T >::operator[] ( int64_t  pixel) const
inherited
void npl::MRImage::orientDefault ( )
inherited

Default orientation (dir=ident, space=1 and origin=0), also resizes them. So this could be called without first initializing size.

template<size_t D, typename T>
virtual int npl::MRImageStore< D, T >::orientVector ( size_t  len,
const double *  xyz,
double *  ras 
) const
virtual

Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by the internal rotation matrix.

Parameters
lenLength of input vector (may be different than dimension - extra values will be ignored, missing values will be assumed zero)
xyzInput vector in index space ijk....
rasOutput vector in physical space. This is the product of the input vector and rotation matrix
Returns
Success

Implements npl::MRImage.

double& npl::MRImage::origin ( int64_t  row)
inherited

Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0.

Parameters
rowRow to access
Returns
Element in origin vector
const double& npl::MRImage::origin ( int64_t  row) const
inherited

Returns reference to a value in the origin vector. This is the physical point that corresponds to index 0.

Parameters
rowRow to access
Returns
Element in origin vector
template<size_t D, typename T>
virtual bool npl::MRImageStore< D, T >::pointInsideFOV ( size_t  len,
const double *  ras 
) const
virtual

Returns true if the point is within the field of view of the image. Note, like all coordinates pass to MRImage, if the array given differs from the dimensions of the image, then the result will either pad out zeros and ignore extra values in the input array.

Parameters
lenLength of RAS array
rasArray of Right-handed coordinates Right+, Anterior+, Superior+
Returns
Whether the point would round to a voxel inside the image.

Implements npl::MRImage.

template<size_t D, typename T>
virtual int npl::MRImageStore< D, T >::pointToIndex ( size_t  len,
const double *  ras,
double *  xyz 
) const
virtual

Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras.

Parameters
lenLength of xyz/ras arrays.
rasArray in RAS... coordinates (may be as long as you want).
xyzCorresponding coordinate
Returns
0

Implements npl::MRImage.

template<size_t D, typename T>
virtual int npl::MRImageStore< D, T >::pointToIndex ( size_t  len,
const double *  ras,
int64_t *  index 
) const
virtual

Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are assumed to be 0. If len > dimensions then additional values are ignored, and only the first DIM values will be transformed and written to ras.

Parameters
lenLength of xyz/ras arrays.
rasArray in RAS... coordinates (may be as long as you want).
indexCorresponding coordinate, rounded to nearest integer
Returns
0

Implements npl::MRImage.

template<size_t D, typename T>
void npl::MRImageStore< D, T >::printSelf ( )

Print information about the image.

template<size_t D, typename T>
void npl::NDArrayStore< D, T >::resize ( const size_t  dim[D])
inherited

Changes the dimensions (size) of the image. This does not affect rank/dimensionality.

Parameters
dimNew size
template<size_t D, typename T>
void npl::NDArrayStore< D, T >::resize ( std::initializer_list< size_t >  dim)
inherited

Changes the dimensions (size) of the image. This does not affect rank/dimensionality.

Parameters
dimNew size
void npl::MRImage::setDirection ( const MatrixXd &  newdir,
bool  reinit,
CoordinateT  coord = QFORM 
)
inherited

Updates orientation information. If reinit is given then it will first set direction to the identity. otherwise old values will be left. After this the first min(DIMENSION,dir.rows()) columns and min(DIMENSION,dir.cols()) columns will be copies into the image direction matrix.

Parameters
newdirInput direction/rotation
reinitWhether to reset everything to Identity/0 before applying. You may want to do this if theinput matrices/vectors differ in dimension from this image.
coordcoordinate system this refers to. Eventually this might include more advanced options (scanner,anat etc). For now it is just QFORM or SFORM
void npl::MRImage::setOrient ( const VectorXd &  neworig,
const VectorXd &  newspace,
const MatrixXd &  newdir,
bool  reinit = true,
CoordinateT  coord = QFORM 
)
inherited

Update the orientation of the pixels in RAS space.

Parameters
neworigNew Origin.
newspaceNew Spacing.
newdirNew Direction
reinitWhether to reset everything to Identity/0 before applying. You may want to do this if theinput matrices/vectors differ in dimension from this image.
coordcoordinate system this refers to. Eventually this might include more advanced options (scanner,anat etc). For now it is just QFORM or SFORM
void npl::MRImage::setOrigin ( const VectorXd &  neworigin,
bool  reinit 
)
inherited

Sets the origin vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied.

Parameters
neworiginthe new origin vector to copy.
reinitWhether to reset everything to Identity/0 before applying. You may want to do this if theinput matrices/vectors differ in dimension from this image.
void npl::MRImage::setSpacing ( const VectorXd &  newspacing,
bool  reinit 
)
inherited

Sets the spacing vector. This is the physical point that corresponds to index 0. Note that min(current, new) elements will be copied.

Parameters
newspacingthe new spacing vector to copy.
reinitSet the whole vector to 1s first. This might be useful if you are setting fewer elements than dimensions
bool npl::NDArray::signedType ( ) const
inlineinherited

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.

double& npl::MRImage::spacing ( int64_t  row)
inherited

Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes.

Parameters
rowRow to access
Returns
Element in spacing vector
const double& npl::MRImage::spacing ( int64_t  row) const
inherited

Returns reference to a value in the spacing vector. This is the physical distance between adjacent indexes.

Parameters
rowRow to access
Returns
Element in spacing vector
template<size_t D, typename T>
virtual int64_t npl::NDArrayStore< D, T >::tlen ( ) const
inlinevirtualinherited

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

Implements npl::NDArray.

Definition at line 800 of file ndarray.h.

template<size_t D, typename T>
PixelT npl::NDArrayStore< D, T >::type ( ) const
virtualinherited

Return enum PixelT type of pixels.

Returns
Type of values stored

Implements npl::NDArray.

bool npl::NDArray::unsignedType ( ) const
inlineinherited

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.

void npl::MRImage::updateSliceTiming ( double  duration,
int  start,
int  end,
SliceOrderT  order 
)
inherited
template<size_t D, typename T>
void npl::NDArrayStore< D, T >::updateStrides ( )
protectedinherited
template<size_t D, typename T>
int npl::MRImageStore< D, T >::write ( std::string  filename,
double  version 
) const
virtual

Write out nifti image with the current images data.

Parameters
filename
version> 2 or < 2 to indicate whether to use nifti version 2 or nifti version 1.
Returns
Success if 0

Implements npl::MRImage.

template<size_t D, typename T>
virtual int npl::NDArrayStore< D, T >::writeCSV ( gzFile  file) const
protectedvirtualinherited
template<size_t D, typename T>
int npl::MRImageStore< D, T >::writeJSON ( gzFile  file) const
protectedvirtual

Reimplemented from npl::NDArrayStore< D, T >.

template<size_t D, typename T>
int npl::MRImageStore< D, T >::writeNifti1Header ( gzFile  file) const
protectedvirtual

Reimplemented from npl::NDArrayStore< D, T >.

template<size_t D, typename T>
int npl::MRImageStore< D, T >::writeNifti1Image ( gzFile  file) const
protectedvirtual

Implements npl::MRImage.

template<size_t D, typename T>
int npl::MRImageStore< D, T >::writeNifti2Header ( gzFile  file) const
protectedvirtual

Reimplemented from npl::NDArrayStore< D, T >.

template<size_t D, typename T>
int npl::MRImageStore< D, T >::writeNifti2Image ( gzFile  file) const
protectedvirtual

Implements npl::MRImage.

template<size_t D, typename T>
virtual int npl::NDArrayStore< D, T >::writePixels ( gzFile  file) const
protectedvirtualinherited
template<size_t D, typename T>
void npl::NDArrayStore< D, T >::zero ( )
virtualinherited

Sets all elements to zero.

Implements npl::NDArray.

Member Data Documentation

template<size_t D, typename T>
T* npl::NDArrayStore< D, T >::_m_data
inherited

Definition at line 805 of file ndarray.h.

template<size_t D, typename T>
size_t npl::NDArrayStore< D, T >::_m_dim[D]
inherited

Definition at line 809 of file ndarray.h.

template<size_t D, typename T>
size_t npl::NDArrayStore< D, T >::_m_stride[D]
inherited

Definition at line 808 of file ndarray.h.

CoordinateT npl::MRImage::m_coordinate
inherited

Definition at line 675 of file mrimage.h.

MatrixXd npl::MRImage::m_direction
protectedinherited

Direction Matrix. Each row indicates the direction of the grid in RAS coordinates. This is the rotation of the Index grid. Note that you should not set this directly,.

Definition at line 714 of file mrimage.h.

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

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.

int npl::MRImage::m_freqdim
inherited

Definition at line 672 of file mrimage.h.

MatrixXd npl::MRImage::m_inv_direction
protectedinherited

Inverse of Direction Matrix.

Definition at line 719 of file mrimage.h.

VectorXd npl::MRImage::m_origin
protectedinherited

Origin vector. Indicates the RAS coordinates of index [0,0,0,..] Note that you should not set this directly, use setOrigin() instead because it will update the affine Matrix.

Definition at line 733 of file mrimage.h.

int npl::MRImage::m_phasedim
inherited

Definition at line 673 of file mrimage.h.

double npl::MRImage::m_slice_duration
inherited

Definition at line 685 of file mrimage.h.

int npl::MRImage::m_slice_end
inherited

Definition at line 687 of file mrimage.h.

SliceOrderT npl::MRImage::m_slice_order
inherited

Definition at line 700 of file mrimage.h.

int npl::MRImage::m_slice_start
inherited

Definition at line 686 of file mrimage.h.

std::map<int64_t,double> npl::MRImage::m_slice_timing
inherited

Definition at line 703 of file mrimage.h.

int npl::MRImage::m_slicedim
inherited

Definition at line 674 of file mrimage.h.

VectorXd npl::MRImage::m_spacing
protectedinherited

Spacing vector. Indicates distance between adjacent pixels in each dimension. Note that you should not set this directly, use setSpacing() instead because it will update the affine Matrix.

Definition at line 726 of file mrimage.h.

template<size_t D, typename T>
std::string npl::MRImageStore< D, T >::m_units[D]
protected

Vector of units for each dimension.

Definition at line 1146 of file mrimage.h.


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