Tulip 5.7.1
Large graphs analysis and drawing
Loading...
Searching...
No Matches
Matrix.h
1/*
2 *
3 * This file is part of Tulip (https://tulip.labri.fr)
4 *
5 * Authors: David Auber and the Tulip development Team
6 * from LaBRI, University of Bordeaux
7 *
8 * Tulip is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation, either version 3
11 * of the License, or (at your option) any later version.
12 *
13 * Tulip is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 * See the GNU General Public License for more details.
17 *
18 */
19///@cond DOXYGEN_HIDDEN
20
21//@TLPGEOLICENCE#
22
23#ifndef _TLP_GEO_MATRIX_H
24#define _TLP_GEO_MATRIX_H
25
26#include <cassert>
27#include <iostream>
28#include <vector>
29#include <tulip/Vector.h>
30
31namespace tlp {
32
33#define MATRIX tlp::Matrix<Obj, SIZE>
34
35/**
36 * @ingroup Structures
37 * \brief class for mathematical square matrix
38 *
39 * Enables to create a Square Matrix of Obj with a
40 * limited size and provides Mathematical operation. Mathematical
41 * operators must be defined for Obj. Out of bound accesses
42 * are only checked in debug mode.
43 *
44 * \author : David Auber auber@labri.fr
45 *
46 * \author Contributor : Maxime Delorme
47 * \version 0.0.2 27/04/2005
48 */
49template <typename Obj, size_t SIZE>
50class Matrix : public Array<Vector<Obj, SIZE>, SIZE> {
51public:
52 Matrix() {}
53 Matrix(const Array<Vector<Obj, SIZE>, SIZE> &a) : Array<Vector<Obj, SIZE>, SIZE>(a) {}
54
55 // Builds a correlation matrix from a covariance matrix !
56 Matrix(const std::vector<std::vector<Obj>> &covarianceMatrix);
57
58 /**
59 * Fill the matrix with the value of obj
60 */
61 inline MATRIX &fill(Obj obj);
62 /**
63 * Compute the determinant of the matrix,
64 */
65 Obj determinant() const;
66 /**
67 * Transpose the matrix and return "&(*this)".
68 */
69 MATRIX &transpose();
70 /**
71 * Inverse the matrix and return "&(*this)"
72 */
73 MATRIX &inverse();
74 /**
75 * add another matrix to the current one and return "&(*this)"
76 */
77 inline MATRIX &operator+=(const MATRIX &mat);
78 /**
79 * subtract another matrix from the current and return "&(*this)"
80 */
81 inline MATRIX &operator-=(const MATRIX &mat);
82 /**
83 * Check equality of two Matrices
84 */
85 inline bool operator==(const MATRIX &) const;
86 /**
87 * Check non equality of two Matrices
88 */
89 inline bool operator!=(const MATRIX &) const;
90 /**
91 * Multiply the matrix by another matrix and return "&(*this)"
92 */
93 inline MATRIX &operator*=(const MATRIX &mat);
94 /**
95 * Multiply all elements of the matrix by obj, return "&(*this)"
96 */
97 inline MATRIX &operator*=(const Obj &obj);
98 /**
99 * Divide the matrix by another one return "&(*this)"
100 */
101 inline MATRIX &operator/=(const MATRIX &mat);
102 /**
103 * Divide all elements of the matrix by obj, return "&(*this)"
104 */
105 inline MATRIX &operator/=(const Obj &obj);
106 /**
107 * Returns the cofactor Matrix of this
108 */
109 MATRIX cofactor() const;
110 /**
111 * Returns a new matrix equal to the division of the matrix by
112 * another matrix"
113 */
114 MATRIX operator/(const MATRIX &mat2) const;
115
116 /**
117 * Returns a new matrix equal to the division of the matrix by
118 * obj"
119 */
120 MATRIX operator/(const Obj &obj) const;
121
122 /**
123 * Returns a new vector equal to the most influent eigenvector of the
124 * matrix
125 */
126 inline Vector<Obj, SIZE> powerIteration(const unsigned int nIterations) const;
127
128 ///@cond DOXYGEN_HIDDEN
129 /**
130 * Simplifies a 3x3 matrix in 2x2 matrix to be used with computeEigenVector
131 */
132 inline bool simplify(Matrix<Obj, 2> &simplifiedMatrix) const;
133
134 /**
135 * Returns the EigenVector of the matrix corresponding to the EigenValue passed, with a base x
136 * /!\ This can only be used with a 2x2 matrix !!! /!\
137 */
138 inline bool computeEigenVector(const float x, Vector<Obj, 3> &eigenVector) const;
139 ///@endcond
140};
141
142typedef Matrix<float, 3> Mat3f;
143typedef Matrix<double, 3> Mat3d;
144typedef Matrix<float, 4> Mat4f;
145typedef Matrix<double, 4> Mat4d;
146
147/**
148 * Returns a new matrix equal to the sum of 2 matrices
149 */
150template <typename Obj, size_t SIZE>
151inline MATRIX operator+(const MATRIX &mat1, const MATRIX &mat2);
152/**
153 * Returns a new matrix equal to the difference of 2 matrices
154 */
155template <typename Obj, size_t SIZE>
156inline MATRIX operator-(const MATRIX &mat1, const MATRIX &mat2);
157/**
158 * Returns a new matrix equal to the multiplication of the matrix by
159 * obj
160 */
161template <typename Obj, size_t SIZE>
162inline MATRIX operator*(const MATRIX &mat, const Obj &obj);
163/**
164 * Returns a new matrix equal to the multiplication of the matrix by
165 * another matrix
166 */
167template <typename Obj, size_t SIZE>
168inline MATRIX operator*(const MATRIX &mat1, const MATRIX &mat2);
169/**
170 * Returns a new vector equal to the multiplication of the vector by
171 * a matrix,(the vector is automatically transposed to do the multiplication)
172 */
173template <typename Obj, size_t SIZE>
174inline Vector<Obj, SIZE> operator*(const Vector<Obj, SIZE> &vec, const tlp::Matrix<Obj, SIZE> &);
175/**
176 * Returns a new vector equal to the multiplication of the matrix by
177 * a vector
178 */
179template <typename Obj, size_t SIZE>
180inline Vector<Obj, SIZE> operator*(const Matrix<Obj, SIZE> &, const Vector<Obj, SIZE> &vec);
181} // namespace tlp
182
183#include "cxx/Matrix.cxx"
184#endif
185///@endcond