40 #ifndef GEOGRAM_BASIC_MATRIX
41 #define GEOGRAM_BASIC_MATRIX
45 #include <initializer_list>
65 template <index_t DIM,
class FT>
93 for(
index_t i = 0; i < DIM; i++) {
94 for(
index_t j = 0; j < DIM; j++) {
105 Matrix(
const std::initializer_list< std::initializer_list<FT> >& Mi) {
133 for(
index_t i = 0; i < DIM; i++) {
134 for(
index_t j = 0; j < DIM; j++) {
135 coeff_[i][j] = FT(0);
146 for(
index_t i = 0; i < DIM; i++) {
147 for(
index_t j = 0; j < DIM; j++) {
148 coeff_[i][j] = (i == j) ? FT(1) : FT(0);
159 for(
index_t i = 0; i < DIM; i++) {
160 for(
index_t j = 0; j < DIM; j++) {
161 FT rhs = ((i == j) ? FT(1) : FT(0));
162 if(coeff_[i][j] != rhs) {
205 for(
index_t i = 0; i < DIM; i++) {
206 for(
index_t j = 0; j < DIM; j++) {
207 coeff_[i][j] += m.coeff_[i][j];
220 for(
index_t i = 0; i < DIM; i++) {
221 for(
index_t j = 0; j < DIM; j++) {
222 coeff_[i][j] -= m.coeff_[i][j];
236 for(
index_t i = 0; i < DIM; i++) {
237 for(
index_t j = 0; j < DIM; j++) {
252 for(
index_t i = 0; i < DIM; i++) {
253 for(
index_t j = 0; j < DIM; j++) {
319 for(
index_t i = 0; i < DIM; i++) {
320 for(
index_t j = 0; j < DIM; j++) {
321 result.coeff_[i][j] = FT(0);
322 for(
index_t k = 0; k < DIM; k++) {
323 result.coeff_[i][j] += coeff_[i][k] * m.coeff_[k][j];
351 FT val=FT(0.0), val2=FT(0.0);
356 for(
index_t i = 0; i != DIM; i++) {
359 for(
index_t j = i + 1; j != DIM; j++) {
360 if(fabs(tmp(j, i)) > fabs(val)) {
367 for(
index_t j = 0; j != DIM; j++) {
369 result(i, j) = result(ind, j);
370 result(ind, j) = val2;
372 tmp(i, j) = tmp(ind, j);
381 for(
index_t j = 0; j != DIM; j++) {
386 for(
index_t j = 0; j != DIM; j++) {
391 for(
index_t k = 0; k != DIM; k++) {
392 tmp(j, k) -= tmp(i, k) * val;
393 result(j, k) -= result(i, k) * val;
407 for(
index_t i = 0; i < DIM; i++) {
408 for(
index_t j = 0; j < DIM; j++) {
409 result(i, j) = (* this)(j, i);
421 inline const FT*
data()
const {
422 return &(coeff_[0][0]);
432 return &(coeff_[0][0]);
443 for(
index_t i = 0; i < DIM; i++) {
444 for(
index_t j = 0; j <= i; j++) {
445 *store++ = coeff_[i][j];
465 template <index_t DIM,
class FT>
469 const char* sep =
"";
470 for(
index_t i = 0; i < DIM; i++) {
471 for(
index_t j = 0; j < DIM; j++) {
472 output << sep << m(i, j);
488 template <index_t DIM,
class FT>
492 for(
index_t i = 0; i < DIM; i++) {
493 for(
index_t j = 0; j < DIM; j++) {
515 template <index_t DIM,
class FT>
inline
517 for(
index_t i = 0; i < DIM; i++) {
519 for(
index_t j = 0; j < DIM; j++) {
520 y[i] += M(i, j) * x[j];
535 template <index_t DIM,
class FT>
inline
540 for(
index_t i = 0; i < DIM; i++) {
542 for(
index_t j = 0; j < DIM; j++) {
543 y[i] += M(i, j) * x[j];
557 template <index_t DIM,
class FT>
inline
562 for(
index_t i = 0; i < DIM; i++) {
564 for(
index_t j = 0; j < DIM; j++) {
565 y[i] += M(i, j) * x[j];
#define geo_assert(x)
Verifies that a condition is met.
#define geo_debug_assert(x)
Verifies that a condition is met.
matrix_type transpose() const
Computes the transposed matrix.
void get_lower_triangle(FT *store) const
Gets the lower triangle of the matrix.
Matrix(const FT *vals)
Constructs a matrix from an array of values.
matrix_type & operator-=(const matrix_type &m)
Subtracts a matrix in place.
index_t dimension() const
Gets the matrix dimension.
Matrix< DIM, FT > matrix_type
matrix_type operator+(const matrix_type &m) const
Adds 2 matrices.
matrix_type operator*(FT val) const
Multiplies a matrix by a scalar.
void load_zero()
Clears the matrix.
Matrix(const std::initializer_list< std::initializer_list< FT > > &Mi)
Constructs a matrix from 2d array of initializers.
bool is_identity() const
Tests whether a matrix is the identity matrix.
FT * data()
Gets modifiable matrix data.
matrix_type & operator*=(FT val)
Multiplies by a scalar in place.
matrix_type operator-(const matrix_type &m) const
Subtracts 2 matrices.
void mult(const Matrix< DIM, FT > &M, const FT *x, FT *y)
Multiplies a matrix by a vector.
matrix_type inverse() const
Computes the inverse matrix.
FT & operator()(index_t i, index_t j)
Gets a modifiable element.
void load_identity()
Sets the matrix to identity.
Matrix()
Default constructor.
bool compute_inverse(matrix_type &result) const
Computes the inverse matrix.
matrix_type & operator/=(FT val)
Divides by a scalar in place.
const FT * data() const
Gets non-modifiable matrix data.
matrix_type & operator+=(const matrix_type &m)
Adds a matrix in place.
matrix_type operator/(FT val) const
Divides a matrix by a scalar.
Common include file, providing basic definitions. Should be included before anything else by all head...
Global Vorpaline namespace.
geo_index_t index_t
The type for storing and manipulating indices.
std::ostream & operator<<(std::ostream &out, const Quaternion &q)
Writes a Quaternion to a stream.
vecng< DIM, FT > operator*(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
std::istream & operator>>(std::istream &in, Quaternion &q)
Reads a Quaternion from a stream.
vecng< DIM, FT > mult(const Matrix< DIM, FT > &M, const vecng< DIM, FT > &x)
Computes a matrix vector product.
Generic implementation of geometric vectors.