homog2d library
Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
h2d::detail::Matrix_< FPT > Class Template Reference

A simple wrapper over a 3x3 matrix, provides root functionalities. More...

#include <homog2d.hpp>

Inheritance diagram for h2d::detail::Matrix_< FPT >:
Inheritance graph
[legend]
Collaboration diagram for h2d::detail::Matrix_< FPT >:
Collaboration graph
[legend]

Public Member Functions

HOMOG2D_INUMTYPE determ () const
 Return determinant of matrix. More...
 
matrix_t< FPT > & getRaw ()
 
const matrix_t< FPT > & getRaw () const
 
Matrix_inverse ()
 Inverse matrix. More...
 
bool isNormalized () const
 
 Matrix_ ()
 Constructor. More...
 
template<typename FPT2 >
 Matrix_ (const Matrix_< FPT2 > &other)
 Copy-Constructor. More...
 
template<typename T >
void set (size_t r, size_t c, T v)
 
Matrix_transpose ()
 Transpose and return matrix. More...
 
const FPT & value (size_t r, size_t c) const
 
FPT & value (size_t r, size_t c)
 
- Public Member Functions inherited from h2d::detail::Common< FPT >
std::pair< int, int > dsize () const
 Get data size expressed as number of bits for, respectively, mantissa and exponent. More...
 
Dtype dtype () const
 Get numerical data type as a Dtype value, can be stringified with h2d::getString(Dtype) More...
 
template<typename T >
constexpr bool isInside (const Common< T > &) const
 This function is a fallback for all sub-classes that do not provide such a method. More...
 
size_t size () const
 

Protected Member Functions

template<typename FPT2 >
void p_divideAll (detail::Matrix_< FPT > &mat, FPT2 value) const
 Divide all elements of mat by value. More...
 
void p_divideBy (size_t r, size_t c) const
 Divide all elements by the value at (r,c), used for normalization. More...
 
void p_fillEye ()
 
template<typename T >
void p_fillWith (const T &in)
 
void p_fillZero ()
 
void p_normalizeMat (int r, int c) const
 

Protected Attributes

bool _isNormalized = false
 
matrix_t< FPT > _mdata
 

Friends

template<typename T >
class Matrix_
 
template<typename T1 , typename T2 >
Matrix_< T1 > operator* (const Matrix_< T1 > &, const Matrix_< T2 > &)
 
std::ostream & operator<< (std::ostream &f, const Matrix_ &h)
 
template<typename T1 , typename T2 , typename FPT1 , typename FPT2 >
void product (base::LPBase< T1, FPT1 > &, const detail::Matrix_< FPT2 > &, const base::LPBase< T2, FPT1 > &)
 Implementation of product 3x3 by 3x1. More...
 
template<typename FPT1 , typename FPT2 , typename FPT3 >
void product (Matrix_< FPT1 > &, const Matrix_< FPT2 > &, const Matrix_< FPT3 > &)
 Implementation of product 3x3 by 3x3. More...
 

Detailed Description

template<typename FPT>
class h2d::detail::Matrix_< FPT >

A simple wrapper over a 3x3 matrix, provides root functionalities.

Homogeneous (thus the 'mutable' attribute).

Todo:
20240326: we might need to add another level of inheritance. This class inherits Common, which is designed to be inherited geometric primitives and as such holds member function that cannot be used on a matrix ! (example: isInside() )
So either we remove the latter function and find a way to put it somewhere else, either we create another intermediate class.

Constructor & Destructor Documentation

◆ Matrix_() [1/2]

template<typename FPT>
h2d::detail::Matrix_< FPT >::Matrix_ ( )
inline

Constructor.

1481  {
1482  p_fillZero();
1483  }
void p_fillZero()
Definition: homog2d.hpp:1589

◆ Matrix_() [2/2]

template<typename FPT>
template<typename FPT2 >
h2d::detail::Matrix_< FPT >::Matrix_ ( const Matrix_< FPT2 > &  other)
inline

Copy-Constructor.

1488  {
1489  for( int i=0; i<3; i++ )
1490  for( int j=0; j<3; j++ )
1491  _mdata[i][j] = other._mdata[i][j];
1492  _isNormalized = other._isNormalized;
1493  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
bool _isNormalized
Definition: homog2d.hpp:1476

Member Function Documentation

◆ determ()

template<typename FPT>
HOMOG2D_INUMTYPE h2d::detail::Matrix_< FPT >::determ ( ) const
inline

Return determinant of matrix.

See https://en.wikipedia.org/wiki/Determinant

1527  {
1528  auto det = _mdata[0][0] * p_det2x2( {1,1, 1,2, 2,1, 2,2} );
1529  det -= _mdata[0][1] * p_det2x2( {1,0, 1,2, 2,0, 2,2} );
1530  det += _mdata[0][2] * p_det2x2( {1,0, 1,1, 2,0, 2,1} );
1531  return det;
1532  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475

◆ getRaw() [1/2]

template<typename FPT>
matrix_t<FPT>& h2d::detail::Matrix_< FPT >::getRaw ( )
inline
1495 { return _mdata; }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
Here is the caller graph for this function:

◆ getRaw() [2/2]

template<typename FPT>
const matrix_t<FPT>& h2d::detail::Matrix_< FPT >::getRaw ( ) const
inline
1496 { return _mdata; }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475

◆ inverse()

template<typename FPT>
Matrix_& h2d::detail::Matrix_< FPT >::inverse ( )
inline

Inverse matrix.

1548  {
1549  auto det = determ();
1550  if( homog2d_abs(det) < thr::nullDeter() )
1551  HOMOG2D_THROW_ERROR_1( "matrix is not invertible, det=" << std::scientific << homog2d_abs(det) );
1552 
1553  auto adjugate = p_adjugate();
1554  p_divideAll(adjugate, det);
1555  _mdata = adjugate._mdata;
1556  _isNormalized = false;
1557  return *this;
1558  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
#define homog2d_abs
Definition: homog2d.hpp:69
void p_divideAll(detail::Matrix_< FPT > &mat, FPT2 value) const
Divide all elements of mat by value.
Definition: homog2d.hpp:1614
bool _isNormalized
Definition: homog2d.hpp:1476
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
static HOMOG2D_INUMTYPE & nullDeter()
Definition: homog2d.hpp:1251
HOMOG2D_INUMTYPE determ() const
Return determinant of matrix.
Definition: homog2d.hpp:1526
Here is the caller graph for this function:

◆ isNormalized()

template<typename FPT>
bool h2d::detail::Matrix_< FPT >::isNormalized ( ) const
inline
1559 { return _isNormalized; }
bool _isNormalized
Definition: homog2d.hpp:1476
Here is the caller graph for this function:

◆ p_divideAll()

template<typename FPT>
template<typename FPT2 >
void h2d::detail::Matrix_< FPT >::p_divideAll ( detail::Matrix_< FPT > &  mat,
FPT2  value 
) const
inlineprotected

Divide all elements of mat by value.

1615  {
1616  for( int i=0; i<3; i++ )
1617  for( int j=0; j<3; j++ )
1618  mat._mdata[i][j] /= value;
1619  _isNormalized = false;
1620  }
bool _isNormalized
Definition: homog2d.hpp:1476
const FPT & value(size_t r, size_t c) const
Definition: homog2d.hpp:1507

◆ p_divideBy()

template<typename FPT>
void h2d::detail::Matrix_< FPT >::p_divideBy ( size_t  r,
size_t  c 
) const
inlineprotected

Divide all elements by the value at (r,c), used for normalization.

No need to check value, done by caller

1582  {
1583 // assert( std::fabs( _mdata[r][c] ) > 1000*std::numeric_limits<FPT>::epsilon() );
1584  for( auto& li: _mdata )
1585  for( auto& e: li )
1586  e /= _mdata[r][c];
1587  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
Line2d li
Definition: homog2d_test.cpp:4035

◆ p_fillEye()

template<typename FPT>
void h2d::detail::Matrix_< FPT >::p_fillEye ( )
inlineprotected
1596  {
1597  p_fillZero();
1598  _mdata[0][0] = 1.;
1599  _mdata[1][1] = 1.; // "eye" matrix => unit transformation
1600  _mdata[2][2] = 1.;
1601  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
void p_fillZero()
Definition: homog2d.hpp:1589
Here is the caller graph for this function:

◆ p_fillWith()

template<typename FPT>
template<typename T >
void h2d::detail::Matrix_< FPT >::p_fillWith ( const T &  in)
inlineprotected
1605  {
1606  for( auto i=0; i<3; i++ )
1607  for( auto j=0; j<3; j++ )
1608  _mdata[i][j] = in[i][j];
1609  _isNormalized = false;
1610  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
bool _isNormalized
Definition: homog2d.hpp:1476
Here is the caller graph for this function:

◆ p_fillZero()

template<typename FPT>
void h2d::detail::Matrix_< FPT >::p_fillZero ( )
inlineprotected
1590  {
1591  for( auto& li: _mdata )
1592  for( auto& e: li )
1593  e = 0.;
1594  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
Line2d li
Definition: homog2d_test.cpp:4035

◆ p_normalizeMat()

template<typename FPT>
void h2d::detail::Matrix_< FPT >::p_normalizeMat ( int  r,
int  c 
) const
inlineprotected
1563  {
1564 #ifndef HOMOG2D_NOCHECKS
1565  if( std::fabs(_mdata[r][c]) < thr::nullDenom() )
1567  "Unable to normalize matrix, value at ("
1568  << r << ',' << c << ") less than " << thr::nullDenom()
1569  );
1570 #endif
1571  p_divideBy( r, c );
1572  if( std::signbit( _mdata[r][c] ) )
1573  for( auto& li: _mdata )
1574  for( auto& e: li )
1575  e = -e;
1576  _isNormalized = true;
1577  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
bool _isNormalized
Definition: homog2d.hpp:1476
Line2d li
Definition: homog2d_test.cpp:4035
void p_divideBy(size_t r, size_t c) const
Divide all elements by the value at (r,c), used for normalization.
Definition: homog2d.hpp:1581
static HOMOG2D_INUMTYPE & nullDenom()
Definition: homog2d.hpp:1245
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
Here is the caller graph for this function:

◆ set()

template<typename FPT>
template<typename T >
void h2d::detail::Matrix_< FPT >::set ( size_t  r,
size_t  c,
v 
)
inline
1500  {
1501  #ifndef HOMOG2D_NOCHECKS
1503  #endif
1504  _mdata[r][c] = v;
1505  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
#define HOMOG2D_CHECK_ROW_COL
Definition: homog2d.hpp:137
Here is the caller graph for this function:

◆ transpose()

template<typename FPT>
Matrix_& h2d::detail::Matrix_< FPT >::transpose ( )
inline

Transpose and return matrix.

1536  {
1537  matrix_t<FPT> out;
1538  for( int i=0; i<3; i++ )
1539  for( int j=0; j<3; j++ )
1540  out[i][j] = _mdata[j][i];
1541  _mdata = out;
1542  _isNormalized = false;
1543  return *this;
1544  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
bool _isNormalized
Definition: homog2d.hpp:1476
Here is the caller graph for this function:

◆ value() [1/2]

template<typename FPT>
const FPT& h2d::detail::Matrix_< FPT >::value ( size_t  r,
size_t  c 
) const
inline
1508  {
1509  #ifndef HOMOG2D_NOCHECKS
1511  #endif
1512  return _mdata[r][c];
1513  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
#define HOMOG2D_CHECK_ROW_COL
Definition: homog2d.hpp:137
Here is the caller graph for this function:

◆ value() [2/2]

template<typename FPT>
FPT& h2d::detail::Matrix_< FPT >::value ( size_t  r,
size_t  c 
)
inline
1515  {
1516  #ifndef HOMOG2D_NOCHECKS
1518  #endif
1519  return _mdata[r][c];
1520  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1475
#define HOMOG2D_CHECK_ROW_COL
Definition: homog2d.hpp:137

Friends And Related Function Documentation

◆ Matrix_

template<typename FPT>
template<typename T >
friend class Matrix_
friend

◆ operator*

template<typename FPT>
template<typename T1 , typename T2 >
Matrix_<T1> operator* ( const Matrix_< T1 > &  h1,
const Matrix_< T2 > &  h2 
)
friend
1674 {
1675 // HOMOG2D_START;
1676  Matrix_<T1> out;
1677  product( out, h1, h2 );
1678  return out;
1679 }
friend void product(base::LPBase< T1, FPT1 > &, const detail::Matrix_< FPT2 > &, const base::LPBase< T2, FPT1 > &)
Implementation of product 3x3 by 3x1.
Definition: homog2d.hpp:9605

◆ operator<<

template<typename FPT>
std::ostream& operator<< ( std::ostream &  f,
const Matrix_< FPT > &  h 
)
friend
1655  {
1656  for( const auto& li: h._mdata )
1657  {
1658  f << "| ";
1659  for( const auto& e: li )
1660  f << std::setw(6) << e << ' ';
1661  f << " |\n";
1662  }
1663  return f;
1664  }
Line2d li
Definition: homog2d_test.cpp:4035

◆ product [1/2]

template<typename FPT>
template<typename T1 , typename T2 , typename FPT1 , typename FPT2 >
void product ( base::LPBase< T1, FPT1 > &  out,
const detail::Matrix_< FPT2 > &  h,
const base::LPBase< T2, FPT1 > &  in 
)
friend

Implementation of product 3x3 by 3x1.

9610 {
9611  for( int i=0; i<3; i++ )
9612  {
9613  auto sum = static_cast<HOMOG2D_INUMTYPE>(h._mdata[i][0]) * in._v[0];
9614  sum += h._mdata[i][1] * in._v[1];
9615  sum += h._mdata[i][2] * in._v[2];
9616  out._v[i] = sum;
9617  }
9618 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66

◆ product [2/2]

template<typename FPT>
template<typename FPT1 , typename FPT2 , typename FPT3 >
void product ( Matrix_< FPT1 > &  out,
const Matrix_< FPT2 > &  h1,
const Matrix_< FPT3 > &  h2 
)
friend

Implementation of product 3x3 by 3x3.

9590 {
9591  out.p_fillZero();
9592  for( int i=0; i<3; i++ )
9593  for( int j=0; j<3; j++ )
9594  for( int k=0; k<3; k++ )
9595  out.value(i,j) +=
9596  static_cast<HOMOG2D_INUMTYPE>( h1.value(i,k) ) * h2.value(k,j);
9597 }
#define HOMOG2D_INUMTYPE
Definition: homog2d.hpp:66

Member Data Documentation

◆ _isNormalized

template<typename FPT>
bool h2d::detail::Matrix_< FPT >::_isNormalized = false
mutableprotected

◆ _mdata

template<typename FPT>
matrix_t<FPT> h2d::detail::Matrix_< FPT >::_mdata
mutableprotected

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