/home/damien/work/2012_2013_teaching/2012_5eti_synthese/lib3d/matrix3.hpp
Go to the documentation of this file.
1 /*
2 ** TP 5ETI CPE Lyon
3 ** Copyright (C) 2012 Damien Rohmer
4 **
5 ** This program is free software: you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation, either version 3 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 
20 
21 #ifndef MATRIX3_HPP
22 #define MATRIX3_HPP
23 
24 #include <iostream>
25 #include <vector>
26 
27 #include <exception_cpe.hpp>
28 
29 namespace cpe
30 {
31 class v3;
32 
33 
35 class matrix3
36 {
37 
38 public:
39 
40  // ********************************************* //
41  // ********************************************* //
42  // CONSTRUCTORS
43  // ********************************************* //
44  // ********************************************* //
45 
47  matrix3();
49  matrix3(const double& x00,const double& x01,const double& x02,
50  const double& x10,const double& x11,const double& x12,
51  const double& x20,const double& x21,const double& x22);
52 
53  // ********************************************* //
54  // ********************************************* //
55  // Special initialization
56  // ********************************************* //
57  // ********************************************* //
58 
60  static matrix3 identity();
62  static matrix3 zeros();
64  static matrix3 rotation(const v3& axis,const double& angle);
66  static matrix3 scale(const double& s);
68  static matrix3 scale(const double& s_x,const double& s_y,const double& s_z);
69 
70 
71  // ********************************************* //
72  // ********************************************* //
73  // Element access
74  // ********************************************* //
75  // ********************************************* //
76 
78  const double& operator()(const size_t& k1,const size_t& k2) const;
80  double& operator()(const size_t& k1,const size_t& k2);
81 
84  const double* pointer() const;
87  double* pointer_unprotected();
88 
89 
90 
91  // ********************************************* //
92  // ********************************************* //
93  // Math operator
94  // ********************************************* //
95  // ********************************************* //
96 
98  matrix3 operator+(const matrix3& m2) const;
100  matrix3 operator+(const double& s) const;
101 
103  matrix3 operator-(const matrix3& m2) const;
105  matrix3 operator-(const double& s) const;
106 
107 
109  matrix3 operator*(const double& s) const;
111  v3 operator*(const v3& v) const;
113  matrix3 operator*(const matrix3& m2) const;
115  matrix3 operator/(const double& s) const;
116 
117 
119  matrix3& operator+=(const matrix3& m);
121  matrix3& operator+=(const double& s);
123  matrix3& operator-=(const matrix3& m);
125  matrix3& operator-=(const double& s);
127  matrix3& operator*=(const double& s);
129  matrix3& operator/=(const double& s);
130 
132  matrix3 operator-() const;
133 
135  matrix3 product_compontentwise(const matrix3& m) const;
138 
140  matrix3 transposed() const;
141 
142 
143 
144  // ********************************************* //
145  // ********************************************* //
146  // Projection matrix
147  // ********************************************* //
148  // ********************************************* //
149 
151  std::vector<double> to_vector() const;
152 
153 private:
154 
155  // ********************************************* //
156  // ********************************************* //
157  // Internal parameters
158  // ********************************************* //
159  // ********************************************* //
160 
162  double m[9];
163 
164 
165  // ********************************************* //
166  // ********************************************* //
167  // Helper
168  // ********************************************* //
169  // ********************************************* //
170 
172  void assert_size(const size_t& k1,const size_t& k2) const;
173 
174 };
175 
177 matrix3 operator+(const double& s,const matrix3& m);
179 matrix3 operator-(const double& s,const matrix3& m);
181 matrix3 operator*(const double& s,const matrix3& m);
182 
183 // ********************************************* //
184 // ********************************************* //
185 // Output
186 // ********************************************* //
187 // ********************************************* //
188 
190 std::ostream& operator<<(std::ostream& stream,const matrix3& m);
191 
194 {
195 public:
196 
200  exception_matrix3(const std::string& msg,const std::string& file,const std::string& caller,const int& line):exception_cpe(msg,file,caller,line){}
201 };
202 
203 
204 
205 }
206 
207 #endif