CTL  0.6.1
Computed Tomography Library
Classes | Public Types | Public Member Functions | Protected Attributes | Private Member Functions | List of all members
CTL::Chunk2D< T > Class Template Reference

The Chunk2D class provides a simple container for storage of 2D image data. More...

#include <chunk2d.h>

Collaboration diagram for CTL::Chunk2D< T >:
Collaboration graph
[legend]

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 Dimensionsdimensions () const
 
uint height () const
 
max () const
 
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
 
Chunk2Doperator+= (const Chunk2D< T > &other)
 
Chunk2Doperator-= (const Chunk2D< T > &other)
 
Chunk2Doperator *= (const T &factor)
 
Chunk2Doperator/= (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
 

Detailed Description

template<typename T>
class CTL::Chunk2D< T >

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:

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().

Constructor & Destructor Documentation

◆ Chunk2D() [1/8]

template<typename T >
CTL::Chunk2D< T >::Chunk2D ( const Dimensions dimensions)
explicit

Constructs a Chunk2D with dimensions of dimensions.

Note that this does NOT allocate memory for storage. To do so, use allocateMemory().

◆ Chunk2D() [2/8]

template<typename T>
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.

◆ Chunk2D() [3/8]

template<typename T>
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.

◆ Chunk2D() [4/8]

template<typename T>
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.

◆ Chunk2D() [5/8]

template<typename T>
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().

◆ Chunk2D() [6/8]

template<typename T>
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.

◆ Chunk2D() [7/8]

template<typename T>
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.

◆ Chunk2D() [8/8]

template<typename T>
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.

Member Function Documentation

◆ allocatedElements()

template<typename T >
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().

See also
nbElements(), allocateMemory().

◆ allocateMemory() [1/2]

template<typename T >
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().

See also
nbElements().

◆ allocateMemory() [2/2]

template<typename T>
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.

See also
allocatedElements(), allocateMemory(), fill().

◆ constData()

template<typename T >
const std::vector< T > & CTL::Chunk2D< T >::constData ( ) const

Returns a constant reference to the std::vector storing the data.

◆ data()

template<typename T >
const std::vector< T > & CTL::Chunk2D< T >::data ( ) const

Returns a constant reference to the std::vector storing the data.

◆ dimensions()

template<typename T >
const Chunk2D< T >::Dimensions & CTL::Chunk2D< T >::dimensions ( ) const

Returns the dimensions of the chunk.

See also
Dimensions.

◆ fill()

template<typename T>
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.

◆ hasData()

template<typename T >
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.

See also
nbElements(), allocatedElements()

◆ hasEqualSizeAs()

template<typename T>
bool CTL::Chunk2D< T >::hasEqualSizeAs ( const std::vector< T > &  other) const
private

Returns true if the number of elements in other is the same as in this instance.

◆ height()

template<typename T >
uint CTL::Chunk2D< T >::height ( ) const

Returns the height of the chunk. Same as: dimensions().height.

See also
width().

◆ max()

template<typename T >
T CTL::Chunk2D< T >::max ( ) const

Returns the maximum value in this instance.

Returns zero if this data is empty.

◆ min()

template<typename T >
T CTL::Chunk2D< T >::min ( ) const

Returns the minimum value in this instance.

Returns zero if this data is empty.

◆ nbElements()

template<typename T >
size_t CTL::Chunk2D< T >::nbElements ( ) const

Returns the number of elements in the chunk. Note that these are not necessarily allocated already.

See also
allocatedElements().

◆ operator *()

template<typename T>
Chunk2D< T > CTL::Chunk2D< T >::operator * ( const T &  factor) const

Multiplies the data of this chunk element-wise by factor and returns the result.

◆ operator *=()

template<typename T>
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.

◆ operator!=()

template<typename T>
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.

◆ operator()() [1/2]

template<typename T >
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!

◆ operator()() [2/2]

template<typename T >
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!

◆ operator+()

template<typename T>
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.

◆ operator+=()

template<typename T>
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.

◆ operator-()

template<typename T>
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.

◆ operator-=()

template<typename T>
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.

◆ operator/()

template<typename T>
Chunk2D< T > CTL::Chunk2D< T >::operator/ ( const T &  divisor) const

Divides the data of this chunk element-wise by divisor and returns the results.

◆ operator/=()

template<typename T>
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.

◆ operator==()

template<typename T>
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.

◆ rawData() [1/2]

template<typename T >
T * CTL::Chunk2D< T >::rawData ( )

Returns the pointer to the raw data in the std::vector. Same as data().data().

See also
rawData() const.

◆ rawData() [2/2]

template<typename T >
const T * CTL::Chunk2D< T >::rawData ( ) const

Returns the pointer to the constant raw data in the std::vector.

See also
rawData().

◆ setData() [1/2]

template<typename T>
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.

◆ setData() [2/2]

template<typename T>
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.

◆ width()

template<typename T >
uint CTL::Chunk2D< T >::width ( ) const

Returns the width of the chunk. Same as: dimensions().width.

See also
height().

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