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.

1447  {
1448  p_fillZero();
1449  }
void p_fillZero()
Definition: homog2d.hpp:1555

◆ Matrix_() [2/2]

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

Copy-Constructor.

1454  {
1455  for( int i=0; i<3; i++ )
1456  for( int j=0; j<3; j++ )
1457  _mdata[i][j] = other._mdata[i][j];
1458  _isNormalized = other._isNormalized;
1459  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
bool _isNormalized
Definition: homog2d.hpp:1442

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

1493  {
1494  auto det = _mdata[0][0] * p_det2x2( {1,1, 1,2, 2,1, 2,2} );
1495  det -= _mdata[0][1] * p_det2x2( {1,0, 1,2, 2,0, 2,2} );
1496  det += _mdata[0][2] * p_det2x2( {1,0, 1,1, 2,0, 2,1} );
1497  return det;
1498  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441

◆ getRaw() [1/2]

template<typename FPT>
matrix_t<FPT>& h2d::detail::Matrix_< FPT >::getRaw ( )
inline
1461 { return _mdata; }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
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
1462 { return _mdata; }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441

◆ inverse()

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

Inverse matrix.

1514  {
1515  auto det = determ();
1516  if( homog2d_abs(det) < thr::nullDeter() )
1517  HOMOG2D_THROW_ERROR_1( "matrix is not invertible, det=" << std::scientific << homog2d_abs(det) );
1518 
1519  auto adjugate = p_adjugate();
1520  p_divideAll(adjugate, det);
1521  _mdata = adjugate._mdata;
1522  _isNormalized = false;
1523  return *this;
1524  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
#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:1580
bool _isNormalized
Definition: homog2d.hpp:1442
#define HOMOG2D_THROW_ERROR_1(msg)
Error throw wrapper macro.
Definition: homog2d.hpp:181
static HOMOG2D_INUMTYPE & nullDeter()
Definition: homog2d.hpp:1217
HOMOG2D_INUMTYPE determ() const
Return determinant of matrix.
Definition: homog2d.hpp:1492
Here is the caller graph for this function:

◆ isNormalized()

template<typename FPT>
bool h2d::detail::Matrix_< FPT >::isNormalized ( ) const
inline
1525 { return _isNormalized; }
bool _isNormalized
Definition: homog2d.hpp:1442
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.

1581  {
1582  for( int i=0; i<3; i++ )
1583  for( int j=0; j<3; j++ )
1584  mat._mdata[i][j] /= value;
1585  _isNormalized = false;
1586  }
bool _isNormalized
Definition: homog2d.hpp:1442
const FPT & value(size_t r, size_t c) const
Definition: homog2d.hpp:1473

◆ 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

1548  {
1549 // assert( std::fabs( _mdata[r][c] ) > 1000*std::numeric_limits<FPT>::epsilon() );
1550  for( auto& li: _mdata )
1551  for( auto& e: li )
1552  e /= _mdata[r][c];
1553  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
Line2d li
Definition: homog2d_test.cpp:4035

◆ p_fillEye()

template<typename FPT>
void h2d::detail::Matrix_< FPT >::p_fillEye ( )
inlineprotected
1562  {
1563  p_fillZero();
1564  _mdata[0][0] = 1.;
1565  _mdata[1][1] = 1.; // "eye" matrix => unit transformation
1566  _mdata[2][2] = 1.;
1567  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
void p_fillZero()
Definition: homog2d.hpp:1555
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
1571  {
1572  for( auto i=0; i<3; i++ )
1573  for( auto j=0; j<3; j++ )
1574  _mdata[i][j] = in[i][j];
1575  _isNormalized = false;
1576  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
bool _isNormalized
Definition: homog2d.hpp:1442
Here is the caller graph for this function:

◆ p_fillZero()

template<typename FPT>
void h2d::detail::Matrix_< FPT >::p_fillZero ( )
inlineprotected
1556  {
1557  for( auto& li: _mdata )
1558  for( auto& e: li )
1559  e = 0.;
1560  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
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
1529  {
1530 #ifndef HOMOG2D_NOCHECKS
1531  if( std::fabs(_mdata[r][c]) < thr::nullDenom() )
1533  "Unable to normalize matrix, value at ("
1534  << r << ',' << c << ") less than " << thr::nullDenom()
1535  );
1536 #endif
1537  p_divideBy( r, c );
1538  if( std::signbit( _mdata[r][c] ) )
1539  for( auto& li: _mdata )
1540  for( auto& e: li )
1541  e = -e;
1542  _isNormalized = true;
1543  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
bool _isNormalized
Definition: homog2d.hpp:1442
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:1547
static HOMOG2D_INUMTYPE & nullDenom()
Definition: homog2d.hpp:1211
#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
1466  {
1467  #ifndef HOMOG2D_NOCHECKS
1469  #endif
1470  _mdata[r][c] = v;
1471  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
#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.

1502  {
1503  matrix_t<FPT> out;
1504  for( int i=0; i<3; i++ )
1505  for( int j=0; j<3; j++ )
1506  out[i][j] = _mdata[j][i];
1507  _mdata = out;
1508  _isNormalized = false;
1509  return *this;
1510  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
bool _isNormalized
Definition: homog2d.hpp:1442
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
1474  {
1475  #ifndef HOMOG2D_NOCHECKS
1477  #endif
1478  return _mdata[r][c];
1479  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
#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
1481  {
1482  #ifndef HOMOG2D_NOCHECKS
1484  #endif
1485  return _mdata[r][c];
1486  }
matrix_t< FPT > _mdata
Definition: homog2d.hpp:1441
#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
1640 {
1641 // HOMOG2D_START;
1642  Matrix_<T1> out;
1643  product( out, h1, h2 );
1644  return out;
1645 }
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:9604

◆ operator<<

template<typename FPT>
std::ostream& operator<< ( std::ostream &  f,
const Matrix_< FPT > &  h 
)
friend
1621  {
1622  for( const auto& li: h._mdata )
1623  {
1624  f << "| ";
1625  for( const auto& e: li )
1626  f << std::setw(6) << e << ' ';
1627  f << " |\n";
1628  }
1629  return f;
1630  }
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.

9609 {
9610  for( int i=0; i<3; i++ )
9611  {
9612  auto sum = static_cast<HOMOG2D_INUMTYPE>(h._mdata[i][0]) * in._v[0];
9613  sum += h._mdata[i][1] * in._v[1];
9614  sum += h._mdata[i][2] * in._v[2];
9615  out._v[i] = sum;
9616  }
9617 }
#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.

9589 {
9590  out.p_fillZero();
9591  for( int i=0; i<3; i++ )
9592  for( int j=0; j<3; j++ )
9593  for( int k=0; k<3; k++ )
9594  out.value(i,j) +=
9595  static_cast<HOMOG2D_INUMTYPE>( h1.value(i,k) ) * h2.value(k,j);
9596 }
#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: