CTL
0.6.1
Computed Tomography Library
|
The Chunk2D class provides a simple container for storage of 2D image data. More...
#include <chunk2d.h>
Classes | |
class | PixelIterator |
Public Types | |
using | Dimensions = Chunk2DDimensions |
using | iterator = PixelIterator< typename std::vector< T >::iterator > |
using | const_iterator = PixelIterator< 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 |
Chunk2D (const Dimensions &dimensions) | |
Chunk2D (const Dimensions &dimensions, const T &initValue) | |
Chunk2D (const Dimensions &dimensions, std::vector< T > &&data) | |
Chunk2D (const Dimensions &dimensions, const std::vector< T > &data) | |
Chunk2D (uint width, uint height) | |
Chunk2D (uint width, uint height, const T &initValue) | |
Chunk2D (uint width, uint height, std::vector< T > &&data) | |
Chunk2D (uint width, uint height, const std::vector< T > &data) | |
size_t | allocatedElements () const |
const std::vector< T > & | constData () const |
const std::vector< T > & | data () const |
bool | hasData () const |
const Dimensions & | dimensions () const |
uint | height () const |
T | max () const |
T | min () const |
size_t | nbElements () const |
T * | rawData () |
const T * | rawData () const |
uint | width () const |
std::vector< T >::reference | operator() (uint x, uint y) |
std::vector< T >::const_reference | operator() (uint x, uint y) const |
bool | operator== (const Chunk2D< T > &other) const |
bool | operator!= (const Chunk2D< T > &other) const |
Chunk2D & | operator+= (const Chunk2D< T > &other) |
Chunk2D & | operator-= (const Chunk2D< T > &other) |
Chunk2D & | operator *= (const T &factor) |
Chunk2D & | operator/= (const T &divisor) |
Chunk2D | operator+ (const Chunk2D< T > &other) const |
Chunk2D | operator- (const Chunk2D< T > &other) const |
Chunk2D | operator * (const T &factor) const |
Chunk2D | operator/ (const T &divisor) const |
void | setData (std::vector< T > &&data) |
void | setData (const std::vector< T > &data) |
void | allocateMemory () |
void | allocateMemory (const T &initValue) |
void | fill (const T &fillValue) |
void | freeMemory () |
Protected Attributes | |
std::vector< T > | _data |
The internal data of the chunk. | |
Dimensions | _dim |
The dimensions (width x height) of the chunk. | |
Private Member Functions | |
bool | hasEqualSizeAs (const std::vector< T > &other) const |
The Chunk2D class provides a simple container for storage of 2D image data.
This class is the main container used for storage of 2D image data. Typical use cases are projection images and individual slices from 3D volumes.
Internally, data is stored using an std::vector. Chunk2D is a template class that allows for the storage of different data types. Most common types are:
float
for projection data and volume slices of absorption coefficients unsigned short
for volume slices in Hounsfield units (HU) unsigned char
for segmented images (segment labels).By default (i.e. for most of the constructor types), memory is not allocated on creation of a Chunk2D object. However, memory allocation can be enforced using allocateMemory().
|
explicit |
Constructs a Chunk2D with dimensions of dimensions.
Note that this does NOT allocate memory for storage. To do so, use allocateMemory().
CTL::Chunk2D< T >::Chunk2D | ( | const Dimensions & | dimensions, |
const T & | initValue | ||
) |
Constructs a Chunk2D with dimensions of dimensions and fills it with initValue.
This constructor allocates memory for all elements.
CTL::Chunk2D< T >::Chunk2D | ( | const Dimensions & | dimensions, |
std::vector< T > && | data | ||
) |
Constructs a Chunk2D with dimensions of dimensions and sets its internal data to data. This uses the move-semantics such that the Chunk2D internal data points to the original location of data.
This constructor fails if the number of elements in data does not match the specified dimensions. In this case, an std::domain_error is thrown.
CTL::Chunk2D< T >::Chunk2D | ( | const Dimensions & | dimensions, |
const std::vector< T > & | data | ||
) |
Constructs a Chunk2D with dimensions of dimensions and sets its internal data to data. This creates a copy of data. If this is not required, consider using the move-semantic alternative Chunk2D(const Dimensions&, std::vector<T>&&) instead.
This constructor fails if the number of elements in data does not match the specified dimensions. In this case, an std::domain_error is thrown.
CTL::Chunk2D< T >::Chunk2D | ( | uint | width, |
uint | height | ||
) |
Constructs a Chunk2D with dimensions of (width x height).
Note that this does NOT allocate memory for storage. To do so, use allocateMemory().
CTL::Chunk2D< T >::Chunk2D | ( | uint | width, |
uint | height, | ||
const T & | initValue | ||
) |
Constructs a Chunk2D with dimensions of (width x height) and fills it with initValue.
This constructor allocates memory for all elements.
CTL::Chunk2D< T >::Chunk2D | ( | uint | width, |
uint | height, | ||
std::vector< T > && | data | ||
) |
Constructs a Chunk2D with dimensions of (width x height) and sets its internal data to data. This uses the move-semantics such that the Chunk2D internal data points to the original location of data.
This constructor fails if the number of elements in data does not match the specified dimensions. In this case, an std::domain_error is thrown.
CTL::Chunk2D< T >::Chunk2D | ( | uint | width, |
uint | height, | ||
const std::vector< T > & | data | ||
) |
Constructs a Chunk2D with dimensions of (width x height) and sets its internal data to data. This creates a copy of data. If this is not required, consider using the move-semantic alternative Chunk2D(const Dimensions&, std::vector<T>&&) instead.
This constructor fails if the number of elements in data does not match the specified dimensions. In this case, an std::domain_error is thrown.
size_t CTL::Chunk2D< 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::Chunk2D< 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 nbElements().
void CTL::Chunk2D< 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.
const std::vector< T > & CTL::Chunk2D< T >::constData | ( | ) | const |
Returns a constant reference to the std::vector storing the data.
const std::vector< T > & CTL::Chunk2D< T >::data | ( | ) | const |
Returns a constant reference to the std::vector storing the data.
const Chunk2D< T >::Dimensions & CTL::Chunk2D< T >::dimensions | ( | ) | const |
Returns the dimensions of the chunk.
void CTL::Chunk2D< T >::fill | ( | const T & | fillValue | ) |
Fills the chunk with fillValue. Note that this will overwrite all data stored in the chunk.
This method allocates memory for the data if it has not been allocated before.
bool CTL::Chunk2D< T >::hasData | ( | ) | const |
Returns true
if the number of allocated elements is equal to the total number of pixels. Otherwise the function returns false
.
|
private |
Returns true
if the number of elements in other is the same as in this instance.
uint CTL::Chunk2D< T >::height | ( | ) | const |
Returns the height of the chunk. Same as: dimensions().height.
T CTL::Chunk2D< T >::max | ( | ) | const |
Returns the maximum value in this instance.
Returns zero if this data is empty.
T CTL::Chunk2D< T >::min | ( | ) | const |
Returns the minimum value in this instance.
Returns zero if this data is empty.
size_t CTL::Chunk2D< T >::nbElements | ( | ) | const |
Returns the number of elements in the chunk. Note that these are not necessarily allocated already.
Chunk2D< T > CTL::Chunk2D< T >::operator * | ( | const T & | factor | ) | const |
Multiplies the data of this chunk element-wise by factor and returns the result.
Chunk2D< T > & CTL::Chunk2D< T >::operator *= | ( | const T & | factor | ) |
Multiplies the data of this chunk element-wise by factor and returns a reference to this instance.
bool CTL::Chunk2D< T >::operator!= | ( | const Chunk2D< T > & | other | ) | const |
Returns a true if either the dimensions or the data of other differ from those of this chunk.
std::vector< T >::reference CTL::Chunk2D< T >::operator() | ( | uint | x, |
uint | y | ||
) |
Returns a reference to the element at position (x, y) or (column, row). Does not perform boundary checks!
std::vector< T >::const_reference CTL::Chunk2D< T >::operator() | ( | uint | x, |
uint | y | ||
) | const |
Returns a constant reference to the element at position (x, y) or (column, row). Does not perform boundary checks!
Chunk2D< T > CTL::Chunk2D< T >::operator+ | ( | const Chunk2D< T > & | other | ) | const |
Adds the data from other to this chunk and returns the result. Throws an std::domain_error if the dimensions of other and this chunk instance do not match.
Chunk2D< T > & CTL::Chunk2D< T >::operator+= | ( | const Chunk2D< T > & | other | ) |
Adds the data from other to this chunk and returns a reference to this instance. Throws an std::domain_error if the dimensions of other and this chunk instance do not match.
Chunk2D< T > CTL::Chunk2D< T >::operator- | ( | const Chunk2D< T > & | other | ) | const |
Subtracts the data of other from this chunk and returns the result. Throws an std::domain_error if the dimensions of other and this chunk instance do not match.
Chunk2D< T > & CTL::Chunk2D< T >::operator-= | ( | const Chunk2D< T > & | other | ) |
Subtracts the data of other from this chunk and returns a reference to this instance. Throws an std::domain_error if the dimensions of other and this chunk instance do not match.
Chunk2D< T > CTL::Chunk2D< T >::operator/ | ( | const T & | divisor | ) | const |
Divides the data of this chunk element-wise by divisor and returns the results.
Chunk2D< T > & CTL::Chunk2D< T >::operator/= | ( | const T & | divisor | ) |
Divides the data of this chunk element-wise by divisor and returns a reference to this instance.
bool CTL::Chunk2D< T >::operator== | ( | const Chunk2D< T > & | other | ) | const |
Returns a true if the dimensions and data of other are equal to those of this chunk.
T * CTL::Chunk2D< T >::rawData | ( | ) |
Returns the pointer to the raw data in the std::vector. Same as data().data().
const T * CTL::Chunk2D< T >::rawData | ( | ) | const |
Returns the pointer to the constant raw data in the std::vector.
void CTL::Chunk2D< T >::setData | ( | std::vector< T > && | data | ) |
Move-sets the internal data to data. This uses the move-semantics such that the Chunk2D internal data points to the original location of data.
Throws an std::domain_error if the number of elements in data does not match the dimensions of this chunk instance.
void CTL::Chunk2D< T >::setData | ( | const std::vector< T > & | data | ) |
Sets the internal data to data. This creates a copy of data. If this is not required, consider using the move-semantic alternative setData(std::vector<T>&&) instead.
Throws an std::domain_error if the number of elements in data does not match the dimensions of this chunk instance.
uint CTL::Chunk2D< T >::width | ( | ) | const |
Returns the width of the chunk. Same as: dimensions().width.