pbpt
Loading...
Searching...
No Matches
pbpt::math::MatrixView< T, R, C, ViewR, ViewC > Class Template Reference

A non-owning, mutable view/proxy into a sub-region of another Matrix. More...

#include <matrix.hpp>

Public Types

using RowView = VectorView<T, ViewC>
using ColView = VectorView<T, ViewR>

Public Member Functions

constexpr MatrixView (const Matrix< T, R, C > &original, int row_start, int col_start)
 Constructs a view from a Matrix instance.
constexpr const T & at (int r, int c) const
 Provides read-only access to an element of the view.
constexpr const RowView operator[] (int r) const
 Returns a non-owning, read-only view of a row.
constexpr RowView operator[] (int r)
 Returns a non-owning, read-only view of a row.
constexpr const RowView row (int r) const
 Returns a non-owning, read-only view of a row.
constexpr ColView col (int c)
 Returns a non-owning, mutable view of a column.
constexpr Matrix< T, ViewR, ViewC > to_matrix () const
 Converts the view into a new, owning Matrix instance.
constexpr T & at (int r, int c)
 Provides mutable access to an element of the view.
constexpr MatrixViewoperator= (const Matrix< T, ViewR, ViewC > &other)
 Assigns another matrix's content to the region represented by this view.
void apply (const std::function< void(T &, int, int)> &func)
 Applies a function to each element of the matrix.

Protected Attributes

const Matrix< T, R, C > & m_original
 A const reference to the original matrix.
int m_row_start {}
 The starting row of the view in the original matrix's coordinate system.
int m_col_start {}
 The starting column of the view in the original matrix's coordinate system.

Detailed Description

template<typename T, int R, int C, int ViewR, int ViewC>
class pbpt::math::MatrixView< T, R, C, ViewR, ViewC >

A non-owning, mutable view/proxy into a sub-region of another Matrix.

Constructor & Destructor Documentation

◆ MatrixView()

template<typename T, int R, int C, int ViewR, int ViewC>
pbpt::math::MatrixView< T, R, C, ViewR, ViewC >::MatrixView ( const Matrix< T, R, C > & original,
int row_start,
int col_start )
inlineconstexpr

Constructs a view from a Matrix instance.

Parameters
originalThe matrix to view.
row_startThe starting row index of the view.
col_startThe starting column index of the view.

Member Function Documentation

◆ apply()

template<typename T, int R, int C, int ViewR, int ViewC>
void pbpt::math::MatrixView< T, R, C, ViewR, ViewC >::apply ( const std::function< void(T &, int, int)> & func)
inline

Applies a function to each element of the matrix.

Parameters
funcThe function to apply.

◆ at() [1/2]

template<typename T, int R, int C, int ViewR, int ViewC>
T & pbpt::math::MatrixView< T, R, C, ViewR, ViewC >::at ( int r,
int c )
inlineconstexpr

Provides mutable access to an element of the view.

Parameters
rThe row index relative to the view.
cThe column index relative to the view.
Returns
A mutable reference to the element in the original matrix.

◆ at() [2/2]

template<typename T, int R, int C, int ViewR, int ViewC>
const T & pbpt::math::MatrixView< T, R, C, ViewR, ViewC >::at ( int r,
int c ) const
inlineconstexpr

Provides read-only access to an element of the view.

Parameters
rThe row index relative to the view.
cThe column index relative to the view.
Returns
A const reference to the element in the original matrix.

◆ operator=()

template<typename T, int R, int C, int ViewR, int ViewC>
MatrixView & pbpt::math::MatrixView< T, R, C, ViewR, ViewC >::operator= ( const Matrix< T, ViewR, ViewC > & other)
inlineconstexpr

Assigns another matrix's content to the region represented by this view.

Parameters
otherThe matrix to copy from.
Returns
A reference to this view.

◆ to_matrix()

template<typename T, int R, int C, int ViewR, int ViewC>
Matrix< T, ViewR, ViewC > pbpt::math::MatrixView< T, R, C, ViewR, ViewC >::to_matrix ( ) const
inlineconstexpr

Converts the view into a new, owning Matrix instance.

This performs a copy of the elements from the viewed region.


The documentation for this class was generated from the following file:
  • /Users/jinceyang/Desktop/codebase/pbpt/engine/math/matrix.hpp