Thea
Public Types | Public Member Functions | List of all members
ImageMatrix< T > Class Template Reference

A wrapper class that allows a single-channel (luminance) image to be treated as an addressable matrix. More...

#include <ImageMatrix.hpp>

Inheritance diagram for ImageMatrix< T >:
IAddressableMatrix< T > IMatrix< T >

Public Types

typedef T Value
 Type of values stored in the matrix. More...
 
typedef T value_type
 Type of values stored in the matrix (STL convention). More...
 

Public Member Functions

IAddressableMatrix< Value > const * asAddressable () const
 If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More...
 
IAddressableMatrix< Value > * asAddressable ()
 If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More...
 
IDenseMatrix< Value > const * asDense () const
 If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access. More...
 
IDenseMatrix< Value > * asDense ()
 If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access. More...
 
ISparseMatrix< Value > const * asSparse () const
 If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access. More...
 
ISparseMatrix< Value > * asSparse ()
 If the matrix is sparse, get a pointer to a derived interface giving sparse-specific access. More...
 
Value const & at (int64 row, int64 col) const
 Get a read-only element. More...
 
int64 cols () const
 Get the number of columns. More...
 
void getColumn (int64 col, Value *values) const
 Get a column of the matrix. More...
 
void getRow (int64 row, Value *values) const
 Get a row of the matrix. More...
 
 ImageMatrix (Image *image_)
 Constructor. More...
 
int8 isResizable () const
 Check if the matrix can be freely resized. More...
 
ValuemutableAt (int64 row, int64 col)
 Get an element that can be directly modified. More...
 
int8 resize (int64 num_rows, int64 num_cols)
 Resize the matrix to new dimensions, if isResizable() returns true. More...
 
int64 rows () const
 Get the number of rows. More...
 
void setColumn (int64 col, Value const *values)
 Set a column of the matrix. More...
 
void setRow (int64 row, Value const *values)
 Set a row of the matrix. More...
 
void setZero ()
 Set all elements to zero. More...
 
 ~ImageMatrix ()
 Destructor. More...
 

Detailed Description

template<typename T>
class Thea::ImageMatrix< T >

A wrapper class that allows a single-channel (luminance) image to be treated as an addressable matrix.

Please ensure the type T matches the type of pixels in the image! The constructor will do a series of checks for this, but checks can be defeated when custom types are involved.

Definition at line 32 of file ImageMatrix.hpp.

Member Typedef Documentation

typedef T Value
inherited

Type of values stored in the matrix.

Definition at line 33 of file IMatrix.hpp.

typedef T value_type
inherited

Type of values stored in the matrix (STL convention).

Definition at line 34 of file IMatrix.hpp.

Constructor & Destructor Documentation

ImageMatrix ( Image image_)

Constructor.

The image pointer must remain valid until the matrix is destroyed.

Definition at line 41 of file ImageMatrix.hpp.

Destructor.

Definition at line 51 of file ImageMatrix.hpp.

Member Function Documentation

IAddressableMatrix<Value> const* asAddressable ( ) const
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< T >.

Definition at line 93 of file ImageMatrix.hpp.

IAddressableMatrix<Value>* asAddressable ( )
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< T >.

Definition at line 94 of file ImageMatrix.hpp.

IDenseMatrix<Value> const* asDense ( ) const
virtual

If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IAddressableMatrix< T >.

Definition at line 97 of file ImageMatrix.hpp.

IDenseMatrix<Value>* asDense ( )
virtual

If the matrix is stored as a dense array, get a pointer to a derived interface supporting dense-specific access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IAddressableMatrix< T >.

Definition at line 98 of file ImageMatrix.hpp.

ISparseMatrix<Value> const* asSparse ( ) const
virtual

If the matrix elements are addressable by (row, col) pairs, get a pointer to a derived interface supporting such access.

Else, return null.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< T >.

Definition at line 95 of file ImageMatrix.hpp.

ISparseMatrix<Value>* asSparse ( )
virtual

If the matrix is sparse, get a pointer to a derived interface giving sparse-specific access.

Else, return null. Note that a sparse matrix can still be addressable, e.g. if it is stored as a map of (row, col) –> value pairs.

Note
dynamic_cast does not work reliably across shared library boundaries, and relying on users to avoid it and only use static_cast is dangerous.

Implements IMatrix< T >.

Definition at line 96 of file ImageMatrix.hpp.

Value const& at ( int64  row,
int64  col 
) const
virtual

Get a read-only element.

Most derived/underlying classes define operator() to access an element quicker, without the virtual function overhead. Use this function only in generic algorithms that need polymorphic access to matrices without using templates, or when accessing matrices across shared library boundaries.

Implements IAddressableMatrix< T >.

Definition at line 64 of file ImageMatrix.hpp.

int64 cols ( ) const
virtual

Get the number of columns.

Implements IMatrix< T >.

Definition at line 54 of file ImageMatrix.hpp.

void getColumn ( int64  col,
Value values 
) const
virtual

Get a column of the matrix.

values must be preallocated with rows() elements.

Implements IAddressableMatrix< T >.

Definition at line 80 of file ImageMatrix.hpp.

void getRow ( int64  row,
Value values 
) const
virtual

Get a row of the matrix.

values must be preallocated with cols() elements.

Implements IAddressableMatrix< T >.

Definition at line 68 of file ImageMatrix.hpp.

int8 isResizable ( ) const
virtual

Check if the matrix can be freely resized.

Implements IMatrix< T >.

Definition at line 55 of file ImageMatrix.hpp.

Value& mutableAt ( int64  row,
int64  col 
)
virtual

Get an element that can be directly modified.

Most derived/underlying classes define operator() to access an element quicker, without the virtual function overhead. Use this function only in generic algorithms that need polymorphic access to matrices without using templates, or when accessing matrices across shared library boundaries.

Implements IAddressableMatrix< T >.

Definition at line 65 of file ImageMatrix.hpp.

int8 resize ( int64  nrows,
int64  ncols 
)
virtual

Resize the matrix to new dimensions, if isResizable() returns true.

Else, if the new dimensions are identical to the old dimensions, do nothing and return true, else return false. If the dimensions are changed, existing entries will in general not be preserved in the resized matrix.

Returns
True if the final dimensions of the matrix are identical to the desired dimensions, else false.

Implements IMatrix< T >.

Definition at line 56 of file ImageMatrix.hpp.

int64 rows ( ) const
virtual

Get the number of rows.

Implements IMatrix< T >.

Definition at line 53 of file ImageMatrix.hpp.

void setColumn ( int64  col,
Value const *  values 
)
virtual

Set a column of the matrix.

values must contain rows() elements.

Implements IAddressableMatrix< T >.

Definition at line 86 of file ImageMatrix.hpp.

void setRow ( int64  row,
Value const *  values 
)
virtual

Set a row of the matrix.

values must contain cols() elements.

Implements IAddressableMatrix< T >.

Definition at line 74 of file ImageMatrix.hpp.

void setZero ( )
virtual

Set all elements to zero.

Implements IMatrix< T >.

Definition at line 58 of file ImageMatrix.hpp.


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