Tulip  4.2.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
Matrix.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
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 
31 
32 namespace tlp {
33 
34 #define MATRIX tlp::Matrix<Obj,SIZE>
35 
36 
37 /**
38  * @ingroup Structures
39  * \brief class for mathematical square matrix
40  *
41  * Enables to create a Square Matrix of Obj with a
42  * limited size and provides Mathematical operation. Mathematical
43  * operators must be defined for Obj. Out of bound accesses
44  * are only checked in debug mode.
45  *
46  * \author : David Auber auber@tulip-software.org
47  *
48  * \author Contributor : Maxime Delorme
49  * \version 0.0.2 27/04/2005
50  */
51 template<typename Obj,unsigned int SIZE>
52 class Matrix:public Array< Vector<Obj,SIZE> , SIZE > {
53 public:
54  Matrix() {}
55  Matrix(const Array< Vector<Obj,SIZE> , SIZE > &a) :
56  Array< Vector<Obj,SIZE> , SIZE >(a) {
57  }
58 
59  // Builds a correlation matrix from a covariance matrix !
60  Matrix(const std::vector<std::vector<Obj> > &covarianceMatrix);
61 
62  /**
63  * Fill the matrix with the value of obj
64  */
65  inline MATRIX& fill(Obj obj);
66  /**
67  * Compute the determinant of the matrix,
68  */
69  Obj determinant() const;
70  /**
71  * Transpose the matrix and return "&(*this)".
72  */
73  MATRIX& transpose();
74  /**
75  * Inverse the matrix and return "&(*this)"
76  */
77  MATRIX& inverse();
78  /**
79  * add another matrix to the current one and return "&(*this)"
80  */
81  inline MATRIX & operator+=(const MATRIX &mat);
82  /**
83  * substract another matrix from the current and return "&(*this)"
84  */
85  inline MATRIX & operator-=(const MATRIX &mat);
86  /**
87  * Check equality of two Matrices
88  */
89  inline bool operator==(const MATRIX &) const;
90  /**
91  * Check non equality of two Matrices
92  */
93  inline bool operator!=(const MATRIX &) const;
94  /**
95  * Multiply the matrix by another matrix and return "&(*this)"
96  */
97  inline MATRIX & operator*=(const MATRIX &mat);
98  /**
99  * Multiply all elements of the matrix by obj, return "&(*this)"
100  */
101  inline MATRIX & operator*=(const Obj &obj);
102  /**
103  * Divide the matrix by another one return "&(*this)"
104  */
105  inline MATRIX & operator/=(const MATRIX &mat);
106  /**
107  * Divide all elements of the matrix by obj, return "&(*this)"
108  */
109  inline MATRIX & operator/=(const Obj &obj);
110  /**
111  * Returns the cofactor Matrix of this
112  */
113  MATRIX cofactor() const;
114  /**
115  * Returns a new matrix equal to the division of the matrix by
116  * another matrix"
117  */
118  MATRIX operator/(const MATRIX &mat2) const;
119 
120  /**
121  * Returns a new matrix equal to the division of the matrix by
122  * obj"
123  */
124  MATRIX operator/(const Obj &obj) const;
125 
126 
127  /**
128  * Returns a new vector equal to the most influent eigenvector of the
129  * matrix
130  */
131  inline Vector<Obj,SIZE> powerIteration(const unsigned int nIterations) const;
132 
133 #ifndef DOXYGEN_NOTFOR_DEVEL
134  /**
135  * Simplifies a 3x3 matrix in 2x2 matrix to be used with computeEigenVector
136  */
137  inline bool simplify(Matrix<Obj, 2> &simplifiedMatrix) const;
138 
139  /**
140  * Returns the EigenVector of the matrix corresponding to the EigenValue passed, with a base x
141  * /!\ This can only be used with a 2x2 matrix !!! /!\
142  */
143  inline bool computeEigenVector(const float x, Vector<Obj, 3> &eigenVector) const;
144 #endif // DOXYGEN_NOTFOR_DEVEL
145 
146 };
147 
148 
149 /**
150  * Returns a new matrix equal to the sum of 2 matrices
151  */
152 template<typename Obj, unsigned int SIZE>
153 inline MATRIX operator+(const MATRIX &mat1, const MATRIX &mat2);
154 /**
155  * Returns a new matrix equal to the difference of 2 matrices
156  */
157 template<typename Obj, unsigned int SIZE>
158 inline MATRIX operator-(const MATRIX &mat1, const MATRIX &mat2);
159 /**
160  * Returns a new matrix equal to the multiplication of the matrix by
161  * obj
162  */
163 template<typename Obj, unsigned int SIZE>
164 inline MATRIX operator*(const MATRIX &mat, const Obj &obj);
165 /**
166  * Returns a new matrix equal to the multiplication of the matrix by
167  * another matrix
168  */
169 template<typename Obj, unsigned int SIZE>
170 inline MATRIX operator*(const MATRIX &mat1, const MATRIX &mat2);
171 /**
172  * Returns a new vector equal to the multiplication of the vector by
173  * a matrix,(the vector is automatically transposed to do the multiplication)
174  */
175 template<typename Obj, unsigned int SIZE>
176 inline Vector<Obj,SIZE> operator*(const Vector<Obj,SIZE> &vec, const tlp::Matrix<Obj, SIZE> &);
177 /**
178  * Returns a new vector equal to the multiplication of the matrix by
179  * a vector
180  */
181 template<typename Obj, unsigned int SIZE>
182 inline Vector<Obj,SIZE> operator*( const Matrix<Obj, SIZE> &, const Vector<Obj,SIZE> &vec);
183 
184 
185 
186 }
187 
188 #include "cxx/Matrix.cxx"
189 #endif
190 ///@endcond