Grid3
Public Member Functions | Protected Attributes | List of all members
Grid3< T > Class Template Reference

Class representing a 3D image grid, each voxel being of type T. More...

#include <Grid3.h>

Public Member Functions

 Grid3 ()
 Default constructor. More...
 
 Grid3 (int width, int height, int depth=1, double x_spacing=1.0, double y_spacing=1.0, double z_spacing=1.0)
 Construct a grid with given dimensions. More...
 
 Grid3 (Vec3i dimensions, Vec3d spacing=Vec3d(1.0, 1.0, 1.0))
 Construct a grid with given dimensions. More...
 
void Init (int width, int height, int depth=1, double x_spacing=1.0, double y_spacing=1.0, double z_spacing=1.0)
 Initialize the grid with given dimensions. Any previous data in the grid will be overwritten. More...
 
int GetWidth ()
 Return the number of grid columns. More...
 
int GetHeight ()
 Return the number of grid rows. More...
 
int GetDepth ()
 Return the number of grid slices. More...
 
Vec3i GetDimensions ()
 Return a vector containing the grid dimensions. More...
 
double GetSpacingX ()
 Return the spacing along X. More...
 
double GetSpacingY ()
 Return the spacing along Y. More...
 
double GetSpacingZ ()
 Return the spacing along Z. More...
 
Vec3d GetSpacing ()
 Return the spacing along all three dimesions. More...
 
void SetSpacing (double x_spacing, double y_spacing, double z_spacing)
 Set spacing. More...
 
void SetSpacing (Vec3d spacing)
 Set spacing. More...
 
Vec3d WorldToGrid (Vec3d p)
 Transform point p from world coordinates to grid coordinates. More...
 
Vec3d GridToWorld (Vec3d p)
 Transform point p from grid coordinates to world coordinates. More...
 
MetaDataContainer GetMetaData ()
 Returns a MetaDataContainer with the current image meta data. More...
 
void SetMetaData (MetaDataContainer md)
 Set image meta data. All current meta data is overwritten. More...
 
int NumberOfElements ()
 Return the total number of grid points. More...
 
T * Data ()
 Returns a pointer to the beginning of the internal data array. The called object owns the pointer. More...
 
std::string GetDataType ()
 Return a string representation of the voxel type. More...
 
int Offset (int x, int y, int z)
 Returns the index of a specified coordinate in the internal data array. More...
 
int Offset (Vec3i p)
 Returns the index of a specified coordinate in the internal data array. More...
 
Vec3i Coordinate (long index)
 Returns the coordinate corresponding to a specified index in the internal data array. More...
 
bool IsInside (int x, int y, int z)
 Test if the given grid point is within the bounds of the grid. More...
 
bool IsInside (Vec3i p)
 Test if the given grid point is within the bounds of the grid. More...
 
T & Background ()
 Access to the the background value of the grid. This is the value that is returned when trying to read a value outside of the grid, with boundary mode set to "CONSTANT". More...
 
T & operator[] (long index)
 Access to the grid value at a specified index. The passed index is assumed to be within the grid bounds. More...
 
T & operator() (int x, int y, int z=0, bool Safe=false, BoundaryMode mode=REPLICATE)
 Access to the grid value at a specified coordinate. If "Safe" is false, the passed coordinate is assumed to be within the grid bounds. If "Safe" is true, the behaviour for out-of-bounds coordinates depends on the "mode" parameter. If "mode" is set to "REPLICATE" a reference to the closest grid point is returned for out-of-bounds coordinates. If "mode" is set to "CONSTANT", a reference to the background value is returned. More...
 
T & operator() (Vec3i p, bool Safe=false, BoundaryMode mode=REPLICATE)
 Access to the grid value at a specified coordinate. If "Safe" is false, the passed coordinate is assumed to be within the grid bounds. If "Safe" is true, the behaviour for out-of-bounds coordinates depends on the "mode" parameter. If "mode" is set to "REPLICATE" a reference to the closest grid point is returned for out-of-bounds coordinates. If "mode" is set to "CONSTANT", a reference to the background value is returned. More...
 
LinearAt (double x, double y, double z, BoundaryMode mode=REPLICATE)
 Get the grid value at a specified coordinate using trilinear interpolation. The "mode" parameter determines the behaviour for coordinates outside the grid bounds, see the documentation of the () operator. More...
 
LinearAt (Vec3d p, BoundaryMode mode=REPLICATE)
 Get the grid value at a specified coordinate using trilinear interpolation. The "mode" parameter determines the behaviour for coordinates outside the grid bounds, see the documentation of the () operator. More...
 
void Get6Neighbors (long index, vector< long > &n)
 Fill the vector n with the indices of the 6-neighbors of the gridpoint at the specified index. More...
 
void Get6Neighbors (Vec3i p, vector< Vec3i > &n)
 Fill the vector n with the coordinates of the 6-neighbors of the gridpoint at the specified coordinate. More...
 
void Fill (T value)
 Set all points in the grid to a specified value. More...
 
GetMaxValue ()
 Return the maximum value in the grid. More...
 
GetMinValue ()
 Return the minimum value in the grid. More...
 
void CopyDataFrom (Grid3< T > &src)
 Replace the current grid data with that of another grid. If the two grids do not have the same NumberOfElements(), nothing happens. More...
 
void SwapContentsWith (Grid3< T > &v)
 Swap the contents of two grids. If the two grids do not have the same NumberOfElements(), nothing happens. More...
 
bool CreateFromFile (std::string filename)
 Construct grid from an image file. More...
 
bool ReadVTK (std::string filename)
 Construct grid from an image file in VTK legacy format. More...
 
bool WriteVTK (std::string filename)
 Save grid in VTK legacy format. More...
 
bool ReadMetaImage (std::string filename)
 Construct grid from an image file in MetaImage format. More...
 
bool WriteMetaImage (std::string filename)
 Save grid in MetaImage format. More...
 
bool ReadNIFTI (std::string filename)
 Construct grid from an image file in NIFTI format. More...
 
bool WriteNIFTI (std::string filename)
 Save grid in NIFTI format. More...
 
bool ReadDICOM (std::string filename)
 Construct grid from an image file in DICOM format. More...
 
template<>
std::string GetDataType ()
 
template<>
std::string GetDataType ()
 
template<>
std::string GetDataType ()
 
template<>
std::string GetDataType ()
 
template<>
std::string GetDataType ()
 
template<>
std::string GetDataType ()
 

Protected Attributes

std::vector< T > data
 
background_value
 
int _width
 
int _height
 
int _depth
 
double _spacingX
 
double _spacingY
 
double _spacingZ
 
MetaDataContainer metadata
 

Detailed Description

template<class T>
class Grid3< T >

Class representing a 3D image grid, each voxel being of type T.

Constructor & Destructor Documentation

template<class T>
Grid3< T >::Grid3 ( )
inline

Default constructor.

template<class T >
Grid3< T >::Grid3 ( int  width,
int  height,
int  depth = 1,
double  x_spacing = 1.0,
double  y_spacing = 1.0,
double  z_spacing = 1.0 
)
inline

Construct a grid with given dimensions.

template<class T >
Grid3< T >::Grid3 ( Vec3i  dimensions,
Vec3d  spacing = Vec3d(1.0,1.0,1.0) 
)
inline

Construct a grid with given dimensions.

Member Function Documentation

template<class T >
T & Grid3< T >::Background ( )
inline

Access to the the background value of the grid. This is the value that is returned when trying to read a value outside of the grid, with boundary mode set to "CONSTANT".

template<class T >
Vec3i Grid3< T >::Coordinate ( long  index)
inline

Returns the coordinate corresponding to a specified index in the internal data array.

template<class T >
void Grid3< T >::CopyDataFrom ( Grid3< T > &  src)
inline

Replace the current grid data with that of another grid. If the two grids do not have the same NumberOfElements(), nothing happens.

template<class T >
bool Grid3< T >::CreateFromFile ( std::string  filename)
inline

Construct grid from an image file.

template<class T >
T * Grid3< T >::Data ( )
inline

Returns a pointer to the beginning of the internal data array. The called object owns the pointer.

template<class T >
void Grid3< T >::Fill ( value)
inline

Set all points in the grid to a specified value.

template<class T >
void Grid3< T >::Get6Neighbors ( long  index,
vector< long > &  n 
)
inline

Fill the vector n with the indices of the 6-neighbors of the gridpoint at the specified index.

template<class T >
void Grid3< T >::Get6Neighbors ( Vec3i  p,
vector< Vec3i > &  n 
)
inline

Fill the vector n with the coordinates of the 6-neighbors of the gridpoint at the specified coordinate.

template<>
std::string Grid3< uint8_t >::GetDataType ( )
inline
template<>
std::string Grid3< int8_t >::GetDataType ( )
inline
template<>
std::string Grid3< uint16_t >::GetDataType ( )
inline
template<>
std::string Grid3< int16_t >::GetDataType ( )
inline
template<>
std::string Grid3< uint32_t >::GetDataType ( )
inline
template<class T >
std::string Grid3< T >::GetDataType ( )
inline

Return a string representation of the voxel type.

template<>
std::string Grid3< int32_t >::GetDataType ( )
inline
template<class T>
int Grid3< T >::GetDepth ( )
inline

Return the number of grid slices.

template<class T>
Vec3i Grid3< T >::GetDimensions ( )
inline

Return a vector containing the grid dimensions.

template<class T>
int Grid3< T >::GetHeight ( )
inline

Return the number of grid rows.

template<class T >
T Grid3< T >::GetMaxValue ( )
inline

Return the maximum value in the grid.

template<class T>
MetaDataContainer Grid3< T >::GetMetaData ( )
inline

Returns a MetaDataContainer with the current image meta data.

template<class T >
T Grid3< T >::GetMinValue ( )
inline

Return the minimum value in the grid.

template<class T>
Vec3d Grid3< T >::GetSpacing ( )
inline

Return the spacing along all three dimesions.

template<class T>
double Grid3< T >::GetSpacingX ( )
inline

Return the spacing along X.

template<class T>
double Grid3< T >::GetSpacingY ( )
inline

Return the spacing along Y.

template<class T>
double Grid3< T >::GetSpacingZ ( )
inline

Return the spacing along Z.

template<class T>
int Grid3< T >::GetWidth ( )
inline

Return the number of grid columns.

template<class T >
Vec3d Grid3< T >::GridToWorld ( Vec3d  p)
inline

Transform point p from grid coordinates to world coordinates.

template<class T >
void Grid3< T >::Init ( int  width,
int  height,
int  depth = 1,
double  x_spacing = 1.0,
double  y_spacing = 1.0,
double  z_spacing = 1.0 
)
inline

Initialize the grid with given dimensions. Any previous data in the grid will be overwritten.

template<class T >
bool Grid3< T >::IsInside ( int  x,
int  y,
int  z 
)
inline

Test if the given grid point is within the bounds of the grid.

template<class T >
bool Grid3< T >::IsInside ( Vec3i  p)
inline

Test if the given grid point is within the bounds of the grid.

template<class T >
T Grid3< T >::LinearAt ( double  x,
double  y,
double  z,
BoundaryMode  mode = REPLICATE 
)
inline

Get the grid value at a specified coordinate using trilinear interpolation. The "mode" parameter determines the behaviour for coordinates outside the grid bounds, see the documentation of the () operator.

template<class T >
T Grid3< T >::LinearAt ( Vec3d  p,
BoundaryMode  mode = REPLICATE 
)
inline

Get the grid value at a specified coordinate using trilinear interpolation. The "mode" parameter determines the behaviour for coordinates outside the grid bounds, see the documentation of the () operator.

template<class T >
int Grid3< T >::NumberOfElements ( )
inline

Return the total number of grid points.

template<class T >
int Grid3< T >::Offset ( int  x,
int  y,
int  z 
)
inline

Returns the index of a specified coordinate in the internal data array.

template<class T>
int Grid3< T >::Offset ( Vec3i  p)
inline

Returns the index of a specified coordinate in the internal data array.

template<class T >
T & Grid3< T >::operator() ( int  x,
int  y,
int  z = 0,
bool  Safe = false,
BoundaryMode  mode = REPLICATE 
)
inline

Access to the grid value at a specified coordinate. If "Safe" is false, the passed coordinate is assumed to be within the grid bounds. If "Safe" is true, the behaviour for out-of-bounds coordinates depends on the "mode" parameter. If "mode" is set to "REPLICATE" a reference to the closest grid point is returned for out-of-bounds coordinates. If "mode" is set to "CONSTANT", a reference to the background value is returned.

template<class T >
T & Grid3< T >::operator() ( Vec3i  p,
bool  Safe = false,
BoundaryMode  mode = REPLICATE 
)
inline

Access to the grid value at a specified coordinate. If "Safe" is false, the passed coordinate is assumed to be within the grid bounds. If "Safe" is true, the behaviour for out-of-bounds coordinates depends on the "mode" parameter. If "mode" is set to "REPLICATE" a reference to the closest grid point is returned for out-of-bounds coordinates. If "mode" is set to "CONSTANT", a reference to the background value is returned.

template<class T >
T & Grid3< T >::operator[] ( long  index)
inline

Access to the grid value at a specified index. The passed index is assumed to be within the grid bounds.

template<class T >
bool Grid3< T >::ReadDICOM ( std::string  filename)
inline

Construct grid from an image file in DICOM format.

template<class T >
bool Grid3< T >::ReadMetaImage ( std::string  filename)
inline

Construct grid from an image file in MetaImage format.

template<class T >
bool Grid3< T >::ReadNIFTI ( std::string  filename)
inline

Construct grid from an image file in NIFTI format.

template<class T >
bool Grid3< T >::ReadVTK ( std::string  filename)
inline

Construct grid from an image file in VTK legacy format.

template<class T>
void Grid3< T >::SetMetaData ( MetaDataContainer  md)
inline

Set image meta data. All current meta data is overwritten.

template<class T >
void Grid3< T >::SetSpacing ( double  x_spacing,
double  y_spacing,
double  z_spacing 
)
inline

Set spacing.

template<class T >
void Grid3< T >::SetSpacing ( Vec3d  spacing)
inline

Set spacing.

template<class T >
void Grid3< T >::SwapContentsWith ( Grid3< T > &  v)
inline

Swap the contents of two grids. If the two grids do not have the same NumberOfElements(), nothing happens.

template<class T >
Vec3d Grid3< T >::WorldToGrid ( Vec3d  p)
inline

Transform point p from world coordinates to grid coordinates.

template<class T >
bool Grid3< T >::WriteMetaImage ( std::string  filename)
inline

Save grid in MetaImage format.

template<class T >
bool Grid3< T >::WriteNIFTI ( std::string  filename)
inline

Save grid in NIFTI format.

template<class T >
bool Grid3< T >::WriteVTK ( std::string  filename)
inline

Save grid in VTK legacy format.

Member Data Documentation

template<class T>
int Grid3< T >::_depth
protected
template<class T>
int Grid3< T >::_height
protected
template<class T>
double Grid3< T >::_spacingX
protected
template<class T>
double Grid3< T >::_spacingY
protected
template<class T>
double Grid3< T >::_spacingZ
protected
template<class T>
int Grid3< T >::_width
protected
template<class T>
T Grid3< T >::background_value
protected
template<class T>
std::vector<T> Grid3< T >::data
protected
template<class T>
MetaDataContainer Grid3< T >::metadata
protected

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