matrix4x1.hpp
Go to the documentation of this file.
1 /*
2 ** TP CPE Lyon
3 ** Copyright (C) 2014 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 #pragma once
20 
21 #ifndef matrix4x1_HPP
22 #define matrix4x1_HPP
23 
24 #include <iostream>
25 #include <vector>
26 
27 #include "../libcommon/exception_cpe.hpp"
28 
29 namespace cpe
30 {
31 
32 class matrix1x4;
33 class matrix4;
34 
36 class matrix4x1
37 {
38 
39 public:
40 
41  // ********************************************* //
42  // ********************************************* //
43  // CONSTRUCTORS
44  // ********************************************* //
45  // ********************************************* //
46 
48  matrix4x1();
50  matrix4x1(float x00,float x01,float x02,float x03);
51 
52 
53 
54  // ********************************************* //
55  // ********************************************* //
56  // Element access
57  // ********************************************* //
58  // ********************************************* //
59 
61  float operator()(const size_t& k1,const size_t& k2) const;
63  float& operator()(const size_t& k1,const size_t& k2);
64 
67  const float* pointer() const;
70  float* pointer_unprotected();
71 
72 
73 
74  // ********************************************* //
75  // ********************************************* //
76  // Math operator
77  // ********************************************* //
78  // ********************************************* //
79 
81  matrix4x1 operator+(const matrix4x1& m2) const;
83  matrix4x1 operator+(float s) const;
84 
86  matrix4x1 operator-(const matrix4x1& m2) const;
88  matrix4x1 operator-(float s) const;
89 
90 
92  matrix4x1 operator*(float s) const;
94  float operator*(const matrix1x4& m2) const;
96  matrix4x1 operator/(float s) const;
97 
98 
100  matrix4x1& operator+=(const matrix4x1& m);
102  matrix4x1& operator+=(float s);
104  matrix4x1& operator-=(const matrix4x1& m);
106  matrix4x1& operator-=(float s);
108  matrix4x1& operator*=(float s);
110  matrix4x1& operator/=(float s);
111 
113  matrix4x1 operator-() const;
114 
119 
121  matrix4x1 transposed() const;
122 
123 
124 
125 
126 
127 
128 
129  // ********************************************* //
130  // ********************************************* //
131  // Projection matrix
132  // ********************************************* //
133  // ********************************************* //
134 
136  std::vector<float> to_vector() const;
137 
138 private:
139 
140  // ********************************************* //
141  // ********************************************* //
142  // Internal parameters
143  // ********************************************* //
144  // ********************************************* //
145 
147  float m[4];
148 
149 
150  // ********************************************* //
151  // ********************************************* //
152  // Helper
153  // ********************************************* //
154  // ********************************************* //
155 
157  void assert_size(const size_t& k1,const size_t& k2) const;
158 
159 };
160 
162 matrix4x1 operator+(float s,const matrix4x1& m);
164 matrix4x1 operator-(float s,const matrix4x1& m);
166 matrix4x1 operator*(float s,const matrix4x1& m);
168 matrix4x1 operator*(const matrix4& m1,const matrix4x1& m2);
169 
170 
171 // ********************************************* //
172 // ********************************************* //
173 // Output
174 // ********************************************* //
175 // ********************************************* //
176 
178 std::ostream& operator<<(std::ostream& stream,const matrix4x1& m);
179 
180 
181 
182 
183 
184 
185 }
186 
187 #endif
std::vector< float > to_vector() const
convert 1x4 matrix into a vector of float of size 4
Definition: matrix4x1.cpp:209
const float * pointer() const
fast pointer access
Definition: matrix4x1.cpp:201
float m[4]
internal storage of the matrix
Definition: matrix4x1.hpp:147
matrix4x1 & operator/=(float s)
internal /
Definition: matrix4x1.cpp:159
matrix4x1()
empty constructor (identity)
Definition: matrix4x1.cpp:35
matrix4x1 transposed() const
transpose matrix
Definition: matrix4x1.cpp:217
Matrix 1x4.
Definition: matrix1x4.hpp:36
float operator()(const size_t &k1, const size_t &k2) const
Access to the k_th entry (k in [0,1])
Definition: matrix4x1.cpp:45
matrix4x1 operator+(const matrix4x1 &m2) const
operator
Definition: matrix4x1.cpp:56
matrix1x4 operator-(float s, const matrix1x4 &m)
operator
Definition: matrix1x4.cpp:82
Matrix 1x4.
Definition: matrix4x1.hpp:36
matrix1x4 operator+(float s, const matrix1x4 &m)
operator
Definition: matrix1x4.cpp:61
matrix4x1 product_compontentwise(const matrix4x1 &m) const
does componentwise multiplication
Definition: matrix4x1.cpp:170
float * pointer_unprotected()
fast pointer access
Definition: matrix4x1.cpp:205
void assert_size(const size_t &k1, const size_t &k2) const
assert that a size_t belongs to 0x[[0,3]]
Definition: matrix4x1.cpp:191
Matrix 4x4.
Definition: matrix4.hpp:37
matrix1x4 operator*(float s, const matrix1x4 &m)
multiply by a scalar operator
Definition: matrix1x4.cpp:93
std::ostream & operator<<(std::ostream &stream, const matrix1x4 &_m)
output the vector in ostream
Definition: matrix1x4.cpp:182
matrix4x1 operator/(float s) const
divide by a scalar operator
Definition: matrix4x1.cpp:117
matrix4x1 & operator-=(const matrix4x1 &m)
internal -
Definition: matrix4x1.cpp:137
matrix4x1 & product_compontentwise_internal(const matrix4x1 &m)
does componentwise multiplication
Definition: matrix4x1.cpp:176
matrix4x1 & operator+=(const matrix4x1 &m)
internal +
Definition: matrix4x1.cpp:122
matrix4x1 & operator*=(float s)
internal *
Definition: matrix4x1.cpp:152
matrix4x1 operator*(float s) const
multiply by a scalar operator
Definition: matrix4x1.cpp:102
matrix4x1 operator-() const
unary negation
Definition: matrix4x1.cpp:166