86 void*
ptr, std::function<
void(
void*)> deleter);
101 void* ptr, std::function<
void(
void*)> deleter);
111 std::ostream&
operator<<(std::ostream &out,
const MRImage& img);
160 void setOrient(
const VectorXd& neworig,
const VectorXd& newspace,
161 const MatrixXd& newdir,
bool reinit =
true,
174 const double&
direction(int64_t row, int64_t col)
const;
186 const double&
invdirection(int64_t row, int64_t col)
const;
221 double&
origin(int64_t row);
231 const double&
origin(int64_t row)
const;
252 void setOrigin(
const VectorXd& neworigin,
bool reinit);
272 const double&
spacing(int64_t row)
const;
292 void setSpacing(
const VectorXd& newspacing,
bool reinit);
309 virtual int indexToPoint(
size_t len,
const int64_t* xyz,
double* ras)
const=0;
323 virtual int indexToPoint(
size_t len,
const double* xyz,
double* ras)
const=0;
337 virtual int pointToIndex(
size_t len,
const double* ras,
double* xyz)
const=0;
351 virtual int pointToIndex(
size_t len,
const double* ras, int64_t* index)
const=0;
366 virtual int orientVector(
size_t len,
const double* xyz,
double* ras)
const=0;
382 virtual int disOrientVector(
size_t len,
const double* ras,
double* xyz)
const=0;
395 virtual bool pointInsideFOV(
size_t len,
const double* ras)
const=0;
409 virtual bool indexInsideFOV(
size_t len,
const double* xyz)
const=0;
422 virtual bool indexInsideFOV(
size_t len,
const int64_t* xyz)
const=0;
442 bool checksize,
double tol = 0.01)
const;
456 virtual bool isIsotropic(
bool only3d =
true,
double tol = 0.01)
const;
470 virtual int write(std::string filename,
double version = 1)
const = 0;
482 return dPtrCast<MRImage>(shared_from_this());
491 return dPtrCast<const MRImage>(shared_from_this());
530 PixelT newtype)
const = 0;
556 const size_t* newsize)
const = 0;
571 PixelT newtype)
const = 0;
596 const size_t* newsize)
const = 0;
610 const size_t* size)
const = 0;
637 const int64_t* index,
const size_t* size,
PixelT newtype)
const = 0;
651 PixelT newtype)
const = 0;
747 template <
size_t D,
typename T>
802 const std::function<
void(
void*)>& deleter);
826 virtual int indexToPoint(
size_t len,
const int64_t* xyz,
double* ras)
const;
840 virtual int indexToPoint(
size_t len,
const double* xyz,
double* ras)
const;
854 virtual int pointToIndex(
size_t len,
const double* ras,
double* xyz)
const;
868 virtual int pointToIndex(
size_t len,
const double* ras, int64_t* index)
const;
883 virtual int orientVector(
size_t len,
const double* xyz,
double* ras)
const;
899 virtual int disOrientVector(
size_t len,
const double* ras,
double* xyz)
const;
939 virtual bool indexInsideFOV(
size_t len,
const int64_t* xyz)
const;
964 int write(std::string filename,
double version)
const;
1027 const size_t* newsize)
const;
1081 const size_t* size)
const;
1114 const int64_t* index,
const size_t* size,
PixelT newtype)
const;
int writeJSON(gzFile file) const
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...
ptr< const MRImage > getConstPtr() const
Returns a constant pointer to self.
const VectorXd & getSpacing() const
Returns const reference to the spacing vector. This is the physical distance between adjacent indexes...
ptr< MRImage > createMRImage(size_t ndim, const size_t *size, PixelT type)
Creates a new MRImage with dimensions set by ndim, and size set by size. Output pixel type is decided...
virtual int disOrientVector(size_t len, const double *ras, double *xyz) const =0
Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by ...
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.
MRImageStore is a version of NDArray that has an orientation matrix. Right now it also has additional...
virtual bool pointInsideFOV(size_t len, const double *ras) const =0
Returns true if the point is within the field of view of the image. Note, like all coordinates pass t...
void updateSliceTiming(double duration, int start, int end, SliceOrderT order)
virtual bool indexInsideFOV(size_t len, const double *xyz) const =0
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.
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 t...
MatrixXd m_inv_direction
Inverse of Direction Matrix.
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...
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 che...
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 ...
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.
SliceOrderT m_slice_order
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 ...
double & spacing(int64_t row)
Returns reference to a value in the spacing vector. This is the physical distance between adjacent in...
ptr< MRImage > cloneImage() const
Create an exact copy of the current image object, and return a pointer to it.
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.
VectorXd m_spacing
Spacing vector. Indicates distance between adjacent pixels in each dimension. Note that you should no...
Pure virtual interface to interact with an ND array.
virtual int orientVector(size_t len, const double *xyz, double *ras) const =0
Convert a vector in index coordinates to a vector in ras coordinates. Vector is simply multiplied by ...
int writeNifti1Header(gzFile file) const
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,.
virtual ptr< NDArray > copy() const =0
Performs a deep copy of the entire image and all metadata.
virtual int writeNifti2Image(gzFile file) const =0
int write(std::string filename, double version) const
Write out nifti image with the current images data.
std::ostream & operator<<(std::ostream &os, const Matrix< D1, D2 > &b)
bool isOriented()
Returns true if the image has a valid orientation.
VectorXd m_origin
Origin vector. Indicates the RAS coordinates of index [0,0,0,..] Note that you should not set this di...
const MatrixXd & getDirection() const
Returns reference to the direction matrix. Each row indicates the direction of the grid in RAS coordi...
int writeNifti2Header(gzFile file) const
virtual int indexToPoint(size_t len, const int64_t *xyz, double *ras) const =0
const VectorXd & getOrigin() const
Returns const reference to the origin vector. This is the physical point that corresponds to index 0...
virtual ptr< NDArray > copyCast(size_t newdims, const size_t *newsize, PixelT newtype) const =0
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.
virtual ptr< NDArray > copyCast(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.
std::string m_units[D]
Vector of units for each dimension.
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 as...
virtual ptr< MRImage > cloneImage() const =0
Create a copy of this image. This is identical to copy() but will return a pointer to an image rather...
MRImage can basically be used like an NDArray, with the addition of orientation related additions...
virtual int write(std::string filename, double version=1) const =0
Write the image to a nifti file.
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...
MRImageStore()
Default constructor, uses identity for direction matrix, 1 for spacing and 0 for origin. Image size is 0.
void setSpacing(const VectorXd &newspacing, bool reinit)
Sets the spacing vector. This is the physical point that corresponds to index 0. Note that min(curren...
virtual int writeNifti1Image(gzFile file) const =0
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.
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.
std::shared_ptr< T > ptr
Make the shared_ptr name shorter...
virtual int pointToIndex(size_t len, const double *ras, double *xyz) const =0
Converts a point in RAS coordinate system to index. If len < dimensions, additional dimensions are as...
void orientDefault()
Default orientation (dir=ident, space=1 and origin=0), also resizes them. So this could be called wit...
virtual ptr< NDArray > copy() const
Performs a deep copy of the entire image and all metadata.
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...
virtual ptr< NDArray > createAnother() const =0
Creates an identical array, but does not initialize pixel values.
friend ptr< MRImage > readNiftiImage(gzFile file, bool verbose)
double & origin(int64_t row)
Returns reference to a value in the origin vector. This is the physical point that corresponds to ind...
int writeNifti2Image(gzFile file) const
int writeNifti1Image(gzFile file) const
virtual ptr< NDArray > createAnother() const
Creates an identical array, but does not initialize pixel values.
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...
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.
void printSelf()
Print information about the image.
virtual void copyMetadata(ptr< const MRImage > src)
Copies metadata from another image. This includes slice timing, anything read from nifti files...
std::map< int64_t, double > m_slice_timing
Basic storage unity for ND array. Creates a big chunk of memory.
ptr< MRImage > getPtr()
Returns a pointer to self.