RNifti
Fast R and C++ Access to NIfTI Images
|
Thin wrapper around a C-style nifti_image
struct that allows C++-style destruction.
More...
#include <NiftiImage.h>
Classes | |
struct | Block |
Inner class referring to a subset of an image. More... | |
Public Member Functions | |
NiftiImage () | |
Default constructor. | |
NiftiImage (const NiftiImage &source) | |
Copy constructor. More... | |
NiftiImage (nifti_image *const image, const bool copy=false) | |
Initialise using an existing nifti_image pointer. More... | |
NiftiImage (const std::string &path, const bool readData=true) | |
Initialise using a path string. More... | |
NiftiImage (const SEXP object, const bool readData=true) | |
Initialise from an R object. More... | |
~NiftiImage () | |
Destructor which frees the wrapped pointer, unless the object is marked as persistent. | |
operator nifti_image * () const | |
Allows a NiftiImage object to be treated as a pointer to a nifti_image . | |
nifti_image * | operator-> () const |
Allows a NiftiImage object to be treated as a pointer to a nifti_image . | |
NiftiImage & | operator= (const NiftiImage &source) |
Copy assignment operator, which copies from its argument. More... | |
NiftiImage & | operator= (const Block &source) |
Copy assignment operator, which allows a block to be used to replace the contents of a suitably sized image. More... | |
void | setPersistence (const bool persistent) |
Allows the image to be marked as persistent, so that it can be passed back to R. More... | |
bool | isNull () const |
Determines whether or not the internal pointer is NULL . | |
bool | isPersistent () const |
Determines whether or not the image is marked as persistent. | |
int | nDims () const |
Returns the number of dimensions in the image. | |
NiftiImage & | drop () |
Drop unitary dimensions. More... | |
void | rescale (const std::vector< float > &scales) |
Rescales the image, changing its image dimensions and pixel dimensions. More... | |
void | update (const SEXP array) |
Update the image from an R array. More... | |
mat44 | xform (const bool preferQuaternion=true) const |
Obtain an xform matrix, indicating the orientation of the image. More... | |
const Block | slice (const int i) const |
Extract a slice block from a 3D image. More... | |
Block | slice (const int i) |
Extract a slice block from a 3D image. More... | |
const Block | volume (const int i) const |
Extract a volume block from a 4D image. More... | |
Block | volume (const int i) |
Extract a volume block from a 4D image. More... | |
void | toFile (const std::string fileName, const short datatype) const |
Write the image to a NIfTI-1 file. More... | |
void | toFile (const std::string fileName, const std::string &datatype) const |
Write the image to a NIfTI-1 file. More... | |
Rcpp::RObject | toArray () const |
Create an R array from the image. More... | |
Rcpp::RObject | toPointer (const std::string label) const |
Create an internal image to pass back to R. More... | |
Rcpp::RObject | toArrayOrPointer (const bool internal, const std::string label) const |
A conditional method that calls either toArray or toPointer. More... | |
Rcpp::RObject | headerToList () const |
Create an R list containing raw image metadata. More... | |
Static Public Member Functions | |
static short | sexpTypeToNiftiType (const int sexpType) |
Convert between R SEXP object type and nifti_image datatype codes. More... | |
Protected Member Functions | |
void | copy (nifti_image *const source) |
Copy the contents of a nifti_image to create a new image. More... | |
void | copy (const NiftiImage &source) |
Copy the contents of another NiftiImage to create a new image. More... | |
void | copy (const Block &source) |
Copy the contents of a Block to create a new image. More... | |
void | initFromNiftiS4 (const Rcpp::RObject &object, const bool copyData=true) |
Initialise the object from an S4 object of class "nifti" . More... | |
void | initFromMriImage (const Rcpp::RObject &object, const bool copyData=true) |
Initialise the object from a reference object of class "MriImage" . More... | |
void | initFromList (const Rcpp::RObject &object) |
Initialise the object from an R list with named elements, which can only contain metadata. More... | |
void | initFromArray (const Rcpp::RObject &object, const bool copyData=true) |
Initialise the object from an R array. More... | |
void | updatePixdim (const std::vector< float > &pixdim) |
Modify the pixel dimensions, and potentially the xform matrices to match. More... | |
void | setPixunits (const std::vector< std::string > &pixunits) |
Modify the pixel dimension units. More... | |
Protected Attributes | |
nifti_image * | image |
The wrapped nifti_image pointer. | |
bool | persistent |
Marker of persistence, which determines whether the nifti_image should be freed on destruction. | |
Thin wrapper around a C-style nifti_image
struct that allows C++-style destruction.
|
inline |
Copy constructor.
source | Another NiftiImage object |
|
inline |
Initialise using an existing nifti_image
pointer.
image | An existing nifti_image pointer, possibly NULL |
copy | If true , the image data will be copied; otherwise this object just wraps the pointer passed to it |
|
inline |
Initialise using a path string.
path | A string specifying a path to a valid NIfTI-1 file, possibly gzipped |
readData | If true , the data will be read as well as the metadata |
runtime_error | If reading from the file fails |
|
inline |
Initialise from an R object.
object | The source object |
readData | If true , the data will be copied as well as the metadata |
|
inlineprotected |
Copy the contents of a nifti_image
to create a new image.
source | A pointer to a nifti_image |
|
inlineprotected |
Copy the contents of another NiftiImage
to create a new image.
source | A reference to a NiftiImage |
|
inlineprotected |
|
inline |
Drop unitary dimensions.
|
inline |
Create an R list containing raw image metadata.
|
inlineprotected |
Initialise the object from an R array.
object | The source object |
copyData | If true , the data are copied in; otherwise just the metadata is extracted |
|
inlineprotected |
Initialise the object from an R list with named elements, which can only contain metadata.
object | The source object |
|
inlineprotected |
Initialise the object from a reference object of class "MriImage"
.
object | The source object |
copyData | If true , the data are copied in; otherwise just the metadata is extracted |
|
inlineprotected |
Initialise the object from an S4 object of class "nifti"
.
object | The source object |
copyData | If true , the data are copied in; otherwise just the metadata is extracted |
|
inline |
Copy assignment operator, which copies from its argument.
source | Another NiftiImage |
|
inline |
Copy assignment operator, which allows a block to be used to replace the contents of a suitably sized image.
source | A reference to a suitable Block object |
|
inline |
Rescales the image, changing its image dimensions and pixel dimensions.
scales | Vector of scale factors along each dimension |
|
inline |
Allows the image to be marked as persistent, so that it can be passed back to R.
persistent | The new persistence state of the object |
|
inlineprotected |
Modify the pixel dimension units.
pixunits | Vector of new pixel units, specified using their standard abbreviations |
|
inlinestatic |
Convert between R SEXP
object type and nifti_image
datatype codes.
sexpType | A numeric R SEXP type code |
nifti_image
datatype code runtime_error | If a non-numeric type is passed |
|
inline |
|
inline |
|
inline |
Create an R array from the image.
|
inline |
|
inline |
Write the image to a NIfTI-1 file.
fileName | The file name to write to, with appropriate suffix (e.g. ".nii.gz") |
datatype | The datatype to use when writing the file |
|
inline |
Write the image to a NIfTI-1 file.
fileName | The file name to write to, with appropriate suffix (e.g. ".nii.gz") |
datatype | The datatype to use when writing the file, or "auto" |
|
inline |
Create an internal image to pass back to R.
label | A string labelling the image |
|
inline |
Update the image from an R array.
array | An R array object |
|
inlineprotected |
Modify the pixel dimensions, and potentially the xform matrices to match.
pixdim | Vector of new pixel dimensions |
|
inline |
Extract a volume block from a 4D image.
i | The volume number required |
|
inline |
Extract a volume block from a 4D image.
i | The volume number required |
|
inline |
Obtain an xform matrix, indicating the orientation of the image.
preferQuaternion | If true , use the qform matrix in preference to the sform |