CTL
0.6.1
Computed Tomography Library
|
The VoxelVolume class provides a simple container for storage of voxelized 3D volume data. More...
#include <voxelvolume.h>
Classes | |
class | VoxelIterator |
Public Types | |
using | Dimensions = VoxelVolumeDimensions |
using | VoxelSize = VoxelVolumeVoxelSize |
using | Offset = VoxelVolumeOffset |
using | iterator = VoxelIterator< typename std::vector< T >::iterator > |
using | const_iterator = VoxelIterator< typename std::vector< T >::const_iterator > |
using | reverse_iterator = std::reverse_iterator< iterator > |
using | const_reverse_iterator = std::reverse_iterator< const_iterator > |
Public Member Functions | |
iterator | begin () |
iterator | end () |
const_iterator | begin () const |
const_iterator | end () const |
const_iterator | cbegin () const |
const_iterator | cend () const |
reverse_iterator | rbegin () |
reverse_iterator | rend () |
const_reverse_iterator | rbegin () const |
const_reverse_iterator | rend () const |
const_reverse_iterator | crbegin () const |
const_reverse_iterator | crend () const |
VoxelVolume (const Dimensions &nbVoxels) | |
VoxelVolume (const Dimensions &nbVoxels, const VoxelSize &voxelSize) | |
VoxelVolume (uint nbVoxelX, uint nbVoxelY, uint nbVoxelZ) | |
VoxelVolume (uint nbVoxelX, uint nbVoxelY, uint nbVoxelZ, float xSize, float ySize, float zSize) | |
VoxelVolume (const Dimensions &nbVoxels, std::vector< T > data) | |
VoxelVolume (const Dimensions &nbVoxels, const VoxelSize &voxelSize, std::vector< T > data) | |
VoxelVolume (uint nbVoxelX, uint nbVoxelY, uint nbVoxelZ, std::vector< T > data) | |
VoxelVolume (uint nbVoxelX, uint nbVoxelY, uint nbVoxelZ, float xSize, float ySize, float zSize, std::vector< T > data) | |
VoxelVolume (const VoxelVolume &)=default | |
VoxelVolume (VoxelVolume &&)=default | |
VoxelVolume & | operator= (const VoxelVolume &)=default |
VoxelVolume & | operator= (VoxelVolume &&)=default |
size_t | allocatedElements () const |
const std::vector< T > & | constData () const |
const std::vector< T > & | data () const |
std::vector< T > & | data () |
const Dimensions & | dimensions () const |
bool | hasData () const |
const Dimensions & | nbVoxels () const |
const Offset & | offset () const |
T * | rawData () |
const T * | rawData () const |
size_t | totalVoxelCount () const |
const VoxelSize & | voxelSize () const |
void | setData (std::vector< T > &&data) |
void | setData (const std::vector< T > &data) |
void | setVolumeOffset (const Offset &offset) |
void | setVolumeOffset (float xOffset, float yOffset, float zOffset) |
void | setVoxelSize (const VoxelSize &size) |
void | setVoxelSize (float xSize, float ySize, float zSize) |
void | setVoxelSize (float isotropicSize) |
void | allocateMemory () |
void | allocateMemory (const T &initValue) |
VoxelCoordinates | coordinates (const VoxelIndex &index) const |
VoxelCoordinates | coordinates (uint x, uint y, uint z) const |
VoxelCoordinates | cornerVoxel () const |
VoxelIndex | index (const VoxelCoordinates &coordinates) const |
VoxelIndex | index (float x_mm, float y_mm, float z_mm) const |
bool | isIsotropic () const |
void | fill (const T &fillValue) |
void | freeMemory () |
T | max () const |
T | min () const |
VoxelVolume< T > | reslicedByX (bool reverse=false) const |
VoxelVolume< T > | reslicedByY (bool reverse=false) const |
VoxelVolume< T > | reslicedByZ (bool reverse=false) const |
Chunk2D< T > | sliceX (uint slice) const |
Chunk2D< T > | sliceY (uint slice) const |
Chunk2D< T > | sliceZ (uint slice) const |
float | smallestVoxelSize () const |
VoxelCoordinates | volumeCorner () const |
std::vector< T >::reference | operator() (uint x, uint y, uint z) |
std::vector< T >::const_reference | operator() (uint x, uint y, uint z) const |
std::vector< T >::reference | operator() (const VoxelIndex &index) |
std::vector< T >::const_reference | operator() (const VoxelIndex &index) const |
VoxelVolume< T > & | operator+= (const VoxelVolume< T > &other) |
VoxelVolume< T > & | operator-= (const VoxelVolume< T > &other) |
VoxelVolume< T > & | operator+= (const T &additiveShift) |
VoxelVolume< T > & | operator-= (const T &subtractiveShift) |
VoxelVolume< T > & | operator *= (const T &factor) |
VoxelVolume< T > & | operator/= (const T &divisor) |
VoxelVolume< T > | operator+ (const VoxelVolume< T > &other) const |
VoxelVolume< T > | operator- (const VoxelVolume< T > &other) const |
VoxelVolume< T > | operator+ (const T &additiveShift) const |
VoxelVolume< T > | operator- (const T &subtractiveShift) const |
VoxelVolume< T > | operator * (const T &factor) const |
VoxelVolume< T > | operator/ (const T &divisor) const |
Static Public Member Functions | |
static VoxelVolume< T > | fromChunk2DStack (const std::vector< Chunk2D< T >> &stack) |
static VoxelVolume< T > | ball (float radius, float voxelSize, const T &fillValue) |
static VoxelVolume< T > | cube (uint nbVoxel, float voxelSize, const T &fillValue) |
static VoxelVolume< T > | cylinderX (float radius, float height, float voxelSize, const T &fillValue) |
static VoxelVolume< T > | cylinderY (float radius, float height, float voxelSize, const T &fillValue) |
static VoxelVolume< T > | cylinderZ (float radius, float height, float voxelSize, const T &fillValue) |
Protected Attributes | |
Dimensions | _dim |
The dimensions of the volume. | |
VoxelSize | _size = { 0.0f, 0.0f, 0.0f } |
The size of individual voxels (in mm). | |
Offset | _offset = { 0.0f, 0.0f, 0.0f } |
The positional offset of the volume (in mm). | |
std::vector< T > | _data |
The internal data of the volume. | |
Private Member Functions | |
bool | hasEqualSizeAs (const std::vector< T > &other) const |
template<class Function > | |
void | parallelExecution (const Function &f) const |
The VoxelVolume class provides a simple container for storage of voxelized 3D volume data.
This class is the main container used for storage of voxelized 3D volume data. The container is templated. Internally, data is stored using an std::vector<T> (one-dimensional). Typical types for T
are:
float
: for absorption coefficients \([\mu]=\text{mm}^{-1}\). unsigned short
: for Hounsfield units (with offset 1000).To specify the volume, the number of voxels in each dimensions must be defined. Physical meaning is assigned to the volume by defining the dimensions of the voxels (in millimeter). The physical center of the volume coincides with the origin of the world coordinate system. Optionally, an offset can be specified to describe the an off-center location of the volume in space. Without any offset, the center of the volume is located exactly in the origin \([0,0,0]\) of the world coordinate system.
The internal storage has row major order, i.e. consecutive values are first all voxel values in x-direction followed by y-direction. At last, z is incremented.
|
explicit |
Constructs a voxelized volume with nbVoxels voxels.
This constuctor does not allocate memory for the data. To enforce memory allocation, use allocateMemory().
CTL::VoxelVolume< T >::VoxelVolume | ( | const Dimensions & | nbVoxels, |
const VoxelSize & | voxelSize | ||
) |
Constructs a voxelized volume with nbVoxels voxels. Each voxel has the (physical) dimensions specified by voxelSize.
This constuctor does not allocate memory for the data. To enforce memory allocation, use allocateMemory().
CTL::VoxelVolume< T >::VoxelVolume | ( | uint | nbVoxelX, |
uint | nbVoxelY, | ||
uint | nbVoxelZ | ||
) |
Constructs a voxelized volume with [nbVoxelX, nbVoxelY, nbVoxelZ] voxels.
This constuctor does not allocate memory for the data. To enforce memory allocation, use allocateMemory().
CTL::VoxelVolume< T >::VoxelVolume | ( | uint | nbVoxelX, |
uint | nbVoxelY, | ||
uint | nbVoxelZ, | ||
float | xSize, | ||
float | ySize, | ||
float | zSize | ||
) |
Constructs a voxelized volume with [nbVoxelX, nbVoxelY, nbVoxelZ] voxels. Each voxel has the (physical) dimensions xSize x ySize x zSize (in millimeters).
This constuctor does not allocate memory for the data. To enforce memory allocation, use allocateMemory().
CTL::VoxelVolume< T >::VoxelVolume | ( | const Dimensions & | nbVoxels, |
std::vector< T > | data | ||
) |
Constructs a voxelized volume with nbVoxels voxels and sets its data to data.
A dimension consistency check is performed to set the data, i.e. the number of elements in data need to match the number of voxels in the volume. Throws std::domain_error in case of mismatching dimensions.
CTL::VoxelVolume< T >::VoxelVolume | ( | const Dimensions & | nbVoxels, |
const VoxelSize & | voxelSize, | ||
std::vector< T > | data | ||
) |
Constructs a voxelized volume with nbVoxels voxels and sets its data to data. Each voxel has the (physical) dimensions specified by voxelSize.
A dimension consistency check is performed to set the data, i.e. the number of elements in data need to match the number of voxels in the volume. Throws std::domain_error in case of mismatching dimensions.
CTL::VoxelVolume< T >::VoxelVolume | ( | uint | nbVoxelX, |
uint | nbVoxelY, | ||
uint | nbVoxelZ, | ||
std::vector< T > | data | ||
) |
Constructs a voxelized volume with [nbVoxelX, nbVoxelY, nbVoxelZ] voxels and sets its data to data.
A dimension consistency check is performed to set the data, i.e. the number of elements in data need to match the number of voxels in the volume. Throws std::domain_error in case of mismatching dimensions.
CTL::VoxelVolume< T >::VoxelVolume | ( | uint | nbVoxelX, |
uint | nbVoxelY, | ||
uint | nbVoxelZ, | ||
float | xSize, | ||
float | ySize, | ||
float | zSize, | ||
std::vector< T > | data | ||
) |
Constructs a voxelized volume with [nbVoxelX, nbVoxelY, nbVoxelZ] voxels and sets its data to data. The voxels have the (physical) dimensions xSize x ySize x zSize (in millimeters).
A dimension consistency check is performed to set the data, i.e. the number of elements in data need to match the number of voxels in the volume. Throws std::domain_error in case of mismatching dimensions.
size_t CTL::VoxelVolume< T >::allocatedElements | ( | ) | const |
Returns the number of elements for which memory has been allocated. This is either zero if no memory has been allocated (after instantiation with a non-allocating constructor) or equal to the number of elements.
Same as: constData().size().
void CTL::VoxelVolume< T >::allocateMemory | ( | ) |
Enforces memory allocation. This resizes the internal std::vector to the required number of elements, given by the dimensions of the chunk, i.e. width x heigth.
As a result, allocatedElements() will return the same as totalVoxelCount().
void CTL::VoxelVolume< T >::allocateMemory | ( | const T & | initValue | ) |
Enforces memory allocation and if the current number of allocated elements is less than the number of elements in the chunk, additional copies of initValue are appended.
|
static |
Constructs a voxelized volume with voxels of isotropic dimensions voxelSize (in mm) and fills all voxels inside a ball of radius radius (in mm) around the center of the volume with fillValue. The voxels surrounding the ball are filled with zeros.
The resulting volume will have \( \left\lceil 2\cdot radius/voxelSize\right\rceil \) voxels in each dimension.
const std::vector< T > & CTL::VoxelVolume< T >::constData | ( | ) | const |
Returns a constant reference to the stored data vector.
VoxelCoordinates CTL::VoxelVolume< T >::coordinates | ( | const VoxelIndex & | index | ) | const |
Returns the (world) coordinates (in mm) of the center of the voxel with index index.
VoxelCoordinates CTL::VoxelVolume< T >::coordinates | ( | uint | x, |
uint | y, | ||
uint | z | ||
) | const |
Returns the (world) coordinates (in mm) of the center of the voxel with index \([x,y,z]\).
VoxelCoordinates CTL::VoxelVolume< T >::cornerVoxel | ( | ) | const |
Returns the (world) coordinates (in mm) of the center of the voxel with index \([0,0,0]\), i.e. located at the corner of the volume.
|
static |
Constructs a cubic voxelized volume with nbVoxel x nbVoxel x nbVoxel voxels (voxel dimension: voxelSize x voxelSize x voxelSize), filled with fillValue.
|
static |
Constructs a voxelized volume with voxels of isotropic dimensions voxelSize (in mm) and fills all voxels inside a cylinder of radius radius (in mm) and height height (in mm) aligned with the x-axis with* fillValue. The voxels surrounding the cylinder are filled with zeros.
The resulting volume will have \( \left\lceil 2\cdot radius/voxelSize\right\rceil \) voxels in y- and z-dimension and \( \left\lceil height/voxelSize\right\rceil \) in x-direction.
|
static |
Constructs a voxelized volume with voxels of isotropic dimensions voxelSize (in mm) and fills all voxels inside a cylinder of radius radius (in mm) and height height (in mm) aligned with the y-axis with* fillValue. The voxels surrounding the cylinder are filled with zeros.
The resulting volume will have \( \left\lceil 2\cdot radius/voxelSize\right\rceil \) voxels in x- and z-dimension and \( \left\lceil height/voxelSize\right\rceil \) in y-direction.
|
static |
Constructs a voxelized volume with voxels of isotropic dimensions voxelSize (in mm) and fills all voxels inside a cylinder of radius radius (in mm) and height height (in mm) aligned with the z-axis with* fillValue. The voxels surrounding the cylinder are filled with zeros.
The resulting volume will have \( \left\lceil 2\cdot radius/voxelSize\right\rceil \) voxels in x- and y-dimension and \( \left\lceil height/voxelSize\right\rceil \) in z-direction.
const std::vector< T > & CTL::VoxelVolume< T >::data | ( | ) | const |
Returns a constant reference to the stored data vector.
std::vector< T > & CTL::VoxelVolume< T >::data | ( | ) |
Returns a reference to the stored data vector.
const VoxelVolume< T >::Dimensions & CTL::VoxelVolume< T >::dimensions | ( | ) | const |
Returns the number of voxels in all three dimensions.
Same as nbVoxels().
void CTL::VoxelVolume< T >::fill | ( | const T & | fillValue | ) |
Fills the volume with fillValue. Note that this will overwrite all data stored in the volume.
This method allocates memory for the data if it has not been allocated before.
void CTL::VoxelVolume< T >::freeMemory | ( | ) |
Deletes the data of the voxel volume.
|
static |
Constructs a voxelized volume from a stack of slices (vector of Chunk2D). All slices in stack will be concatenated in z-direction.
Note that all slices are required to have identical dimensions. Throws an std::domain_error otherwise. Returns an empty VoxelVolume (all dimensions zero) when an empty stack is passed.
bool CTL::VoxelVolume< T >::hasData | ( | ) | const |
Returns true
if the number of allocated elements is equal to the total number of voxels. Otherwise the function returns false
.
|
private |
Checks if the number of elements in other match the voxel count of this instance.
VoxelIndex CTL::VoxelVolume< T >::index | ( | const VoxelCoordinates & | coordinates | ) | const |
Returns the index of the voxel whose center is closest to the world coordinate position coordinates.
Does not perform out of bounds checks.
VoxelIndex CTL::VoxelVolume< T >::index | ( | float | x_mm, |
float | y_mm, | ||
float | z_mm | ||
) | const |
Returns the index of the voxel whose center is closest to the world coordinate position \([x_mm, y_mm, z_mm]\)).
Does not perform out of bounds checks.
bool CTL::VoxelVolume< T >::isIsotropic | ( | ) | const |
Returns true
if the voxel sizes in all three dimensions are considered equal; thus the size is isotropic. Returns false
otherwise.
Same as
.
T CTL::VoxelVolume< T >::max | ( | ) | const |
Returns the highest value in this volume. Returns zero for empty VoxelVolume objects.
T CTL::VoxelVolume< T >::min | ( | ) | const |
Returns the smallest value in this volume. Returns zero for empty VoxelVolume objects.
const VoxelVolume< T >::Dimensions & CTL::VoxelVolume< T >::nbVoxels | ( | ) | const |
Returns the number of voxels in all three dimensions.
For the total number of voxels in the volume, use totalVoxelCount().
const VoxelVolume< T >::Offset & CTL::VoxelVolume< T >::offset | ( | ) | const |
Returns the offset of the volume.
VoxelVolume< T > CTL::VoxelVolume< T >::operator * | ( | const T & | factor | ) | const |
Returns a copy of this volume with all its voxel values multiplied by factor.
VoxelVolume< T > & CTL::VoxelVolume< T >::operator *= | ( | const T & | factor | ) |
Multiplies all voxel values in this volume by factor and returns a reference to this instance.
std::vector< T >::reference CTL::VoxelVolume< T >::operator() | ( | uint | x, |
uint | y, | ||
uint | z | ||
) |
Returns a reference to the data at voxel \([x,y,z]\). Does not perform boundary checks.
std::vector< T >::const_reference CTL::VoxelVolume< T >::operator() | ( | uint | x, |
uint | y, | ||
uint | z | ||
) | const |
Returns a constant reference to the data at voxel \([x,y,z]\). Does not perform boundary checks.
std::vector< T >::reference CTL::VoxelVolume< T >::operator() | ( | const VoxelIndex & | index | ) |
Returns a constant reference to the data at voxel index index. Does not perform boundary checks.
std::vector< T >::const_reference CTL::VoxelVolume< T >::operator() | ( | const VoxelIndex & | index | ) | const |
Returns a constant reference to the data at voxel index index. Does not perform boundary checks.
VoxelVolume< T > CTL::VoxelVolume< T >::operator+ | ( | const VoxelVolume< T > & | other | ) | const |
Returns the (element-wise) sum of this volume and other. Throws an std::domain_error if the dimensions of other and this volume do not match.
Note that the voxel size will be ignored (i.e. there is no consistency check). Hence, the result will always have the voxel size of this instance (i.e. left hand side operand).
VoxelVolume< T > CTL::VoxelVolume< T >::operator+ | ( | const T & | additiveShift | ) | const |
Returns a copy of this volume in which additiveShift has been added to all voxel values.
VoxelVolume< T > & CTL::VoxelVolume< T >::operator+= | ( | const VoxelVolume< T > & | other | ) |
Adds the data from other to this volume and returns a reference to this instance. Throws an std::domain_error if the dimensions of other and this volume do not match.
Note that the voxel size will be ignored (i.e. there is no consistency check). Hence, the result will always have the voxel size of this instance.
VoxelVolume< T > & CTL::VoxelVolume< T >::operator+= | ( | const T & | additiveShift | ) |
Adds additiveShift to all voxel values in this volume and returns a reference to this instance.
VoxelVolume< T > CTL::VoxelVolume< T >::operator- | ( | const VoxelVolume< T > & | other | ) | const |
Returns the (element-wise) difference between this volume and other. Throws an std::domain_error if the dimensions of other and this volume do not match.
Note that the voxel size will be ignored (i.e. there is no consistency check). Hence, the result will always have the voxel size of this instance (i.e. left hand side operand).
VoxelVolume< T > CTL::VoxelVolume< T >::operator- | ( | const T & | subtractiveShift | ) | const |
Returns a copy of this volume in which subtractiveShift has been subtracted from all voxel values.
VoxelVolume< T > & CTL::VoxelVolume< T >::operator-= | ( | const VoxelVolume< T > & | other | ) |
Subtracts the data from other from this volume and returns a reference to this instance. Throws an std::domain_error if the dimensions of other and this volume do not match.
Note that the voxel size will be ignored (i.e. there is no consistency check). Hence, the result will always have the voxel size of this instance.
VoxelVolume< T > & CTL::VoxelVolume< T >::operator-= | ( | const T & | subtractiveShift | ) |
Subtracts subtractiveShift from all voxel values in this volume and returns a reference to this instance.
VoxelVolume< T > CTL::VoxelVolume< T >::operator/ | ( | const T & | divisor | ) | const |
Returns a copy of this volume with all its voxel values divided by divisor.
VoxelVolume< T > & CTL::VoxelVolume< T >::operator/= | ( | const T & | divisor | ) |
Divides all voxel values in this volume by divisor and returns a reference to this instance.
|
private |
Helper function for running tasks in parallel over voxels.
T * CTL::VoxelVolume< T >::rawData | ( | ) |
const T * CTL::VoxelVolume< T >::rawData | ( | ) | const |
Returns the pointer to the constant raw data.
Same as constData().data().
VoxelVolume< T > CTL::VoxelVolume< T >::reslicedByX | ( | bool | reverse = false | ) | const |
Returns a copy of the volume resliced along the x-axis. If reverse is set true
, reslicing will be performed in inverse order (i.e. with descending x value).
The reslicing process switches the orientation of the volume, such that the original axes: [x,y,z] change to [y,z,x].
VoxelVolume< T > CTL::VoxelVolume< T >::reslicedByY | ( | bool | reverse = false | ) | const |
Returns a copy of the volume resliced along the y-axis. If reverse is set true
, reslicing will be performed in inverse order (i.e. with descending y value).
The reslicing process switches the orientation of the volume, such that the original axes: [x,y,z] change to [x,z,y].
VoxelVolume< T > CTL::VoxelVolume< T >::reslicedByZ | ( | bool | reverse = false | ) | const |
Returns a copy of the volume resliced along the z-axis. If reverse is set true
, reslicing will be performed in inverse order (i.e. with descending z value).
Since the volume is sliced in z-direction by default, this method will not change the axes when reverse is false
(default value). It simply returns an exact copy of the volume.
void CTL::VoxelVolume< T >::setData | ( | std::vector< T > && | data | ) |
Move-sets the data vector to data. This method performs a dimensionality check and throws an error if dimensions mismatch.
void CTL::VoxelVolume< T >::setData | ( | const std::vector< T > & | data | ) |
Sets the data vector to data. This method performs a dimensionality check and throws an error if dimensions mismatch.
void CTL::VoxelVolume< T >::setVolumeOffset | ( | const Offset & | offset | ) |
Sets the offset of the volume to offset. This is expected to be specified in millimeter.
void CTL::VoxelVolume< T >::setVolumeOffset | ( | float | xOffset, |
float | yOffset, | ||
float | zOffset | ||
) |
Convenience setter. Sets the offset of the volume using the components xOffset, yOffset and zOffset. Offset values are expected to be specified in millimeter.
void CTL::VoxelVolume< T >::setVoxelSize | ( | const VoxelSize & | size | ) |
Sets the voxel size to size. This is expected to be specified in millimeter.
void CTL::VoxelVolume< T >::setVoxelSize | ( | float | xSize, |
float | ySize, | ||
float | zSize | ||
) |
Convenience setter. Sets the voxel size using the components xSize, ySize and zSize. Dimensions are expected to be specified in millimeter.
void CTL::VoxelVolume< T >::setVoxelSize | ( | float | isotropicSize | ) |
Sets an isotropic voxels size of isotropicSize (in mm).
Chunk2D< T > CTL::VoxelVolume< T >::sliceX | ( | uint | slice | ) | const |
Returns the yz-slice of the volume at position \(x=\) slice as a Chunk2D.
Chunk2D< T > CTL::VoxelVolume< T >::sliceY | ( | uint | slice | ) | const |
Returns the xz-slice of the volume at position \(y=\) slice as a Chunk2D.
Chunk2D< T > CTL::VoxelVolume< T >::sliceZ | ( | uint | slice | ) | const |
Returns the xy-slice of the volume at position \(z=\) slice as a Chunk2D.
float CTL::VoxelVolume< T >::smallestVoxelSize | ( | ) | const |
Returns the smallest edge length of the voxels (in millimeter).
size_t CTL::VoxelVolume< T >::totalVoxelCount | ( | ) | const |
Returns the total number of voxels in the volume. This is the product of the voxel count in all three dimensions.
VoxelCoordinates CTL::VoxelVolume< T >::volumeCorner | ( | ) | const |
Returns the (world) coordinates (in mm) of the corner of the volume (referring to voxel \([0,0,0]\)).
const VoxelVolume< T >::VoxelSize & CTL::VoxelVolume< T >::voxelSize | ( | ) | const |
Returns the size of the voxels (in millimeter).