21 template <
typename T, cgv::type::u
int32_type N, cgv::type::u
int32_type M>
37 (*
this)(i, j) = a[column_major ? j * n + i : i * m + j];
44 (*
this)(i, j) = (T)a[column_major ? j * n + i : i * m + j];
50 template <
typename T1,
typename T2>
52 for(
unsigned i = 0; i < N; i++)
53 for(
unsigned j = 0; j < M; j++)
54 (*
this)(i,j) = (T)(v(i)*
w(j));
57 static unsigned nrows() {
return N; }
59 static unsigned ncols() {
return M; }
75 assert(i < N && j < M);
76 return base_type::v[j*N+i];
80 assert(i < N && j < M);
81 return base_type::v[j*N+i];
102 template <
typename S>
105 template <
typename S>
108 template <
typename S>
111 template <
typename S>
114 template <
typename S>
119 for(
unsigned i = 0; i < N; i++)
120 for(
unsigned j = 0; j < N;j++)
121 for(
unsigned k = 0; k < N; k++)
127 template <
typename S, cgv::type::u
int32_type L>
131 for(
unsigned i = 0; i < N; i++)
132 for(
unsigned j = 0; j < L;j++)
133 for(
unsigned k = 0; k < M; k++)
139 template <
typename S>
142 for(
unsigned i = 0; i < N; i++)
149 for(
unsigned j = 0; j < M; j++)
155 for(
unsigned j = 0; j < M;j++)
156 operator()(i,j)=v(j);
160 return *(
const fvec<T,N>*)(&
operator()(0,j));
164 for(
unsigned i = 0; i < N;i++)
165 operator()(i,j)=v(i);
171 for(
unsigned i = 0; i < N;i++)
179 for(
unsigned i = 1; i < N; i++)
180 for(
unsigned j = 0; j < i; j++)
181 std::swap(
operator()(i,j),
operator()(j,i));
189 for(
unsigned i = 0; i < M && i < N; ++i)
195 template <
typename T, cgv::type::u
int32_type N>
204 template <
typename T, cgv::type::u
int32_type N, cgv::type::u
int32_type M>
211 template <
typename T, cgv::type::u
int32_type N, cgv::type::u
int32_type M>
215 for (
unsigned i = 0; i < M; i++)
216 r_row(i) =
dot(m.col(i), v_row);
221 template <
typename T, cgv::type::u
int32_type N, cgv::type::u
int32_type M>
224 for (
unsigned i=0;i<N;++i) {
225 for(
unsigned j =0;j < M-1;++j)
226 out << m(i,j) <<
" ";
235 template <
typename T, cgv::type::u
int32_type N, cgv::type::u
int32_type M>
238 for (
unsigned i=0;i<m.nrows();++i)
239 for(
unsigned j =0;j < m.ncols();++j)
247 template <
typename T, cgv::type::u
int32_type N,
typename S, cgv::type::u
int32_type M>
251 for (
unsigned i = 0; i < N; i++)
252 for (
unsigned j = 0; j < M; j++)
253 m(i, j) = v(i)*(T)w(j);
258 template <
typename T, cgv::type::u
int32_type N, cgv::type::u
int32_type M>
262 for(
unsigned i = 0; i < N; i++)
263 for(
unsigned j = 0; j < M; j++)
264 m(i, j) = ((T)1 - t)*m1(i, j) + t * m2(i, j);
269 template <
typename T, cgv::type::u
int32_type N, cgv::type::u
int32_type M>
270 const fmat<T, N, M> lerp(
const fmat<T, N, M>& m1,
const fmat<T, N, M>& m2,
fmat<T, N, M> t)
273 for(
unsigned i = 0; i < N; i++)
274 for(
unsigned j = 0; j < M; j++)
275 m(i, j) = ((T)1 - t(i, j))*m1(i, j) + t(i, j)*m2(i, j);
fvec< T, N > & operator-=(const T &s)
in place subtraction by scalar s
Definition: fvec.h:161
fmat< T, N, M > this_type
base type is a vector with sufficent number of elements
Definition: fmat.h:28
matrix of fixed size dimensions
Definition: fmat.h:23
T length() const
length of the vector L2-Norm
Definition: fvec.h:219
fvec< T, N > & operator+=(const T &s)
in place addition of a scalar s
Definition: fvec.h:159
void zeros()
fill the vector with zeros
Definition: fvec.h:115
const fmat< T, N, L > operator*(const fmat< S, M, L > &m2) const
multiplication with a ncols x M matrix m2
Definition: fmat.h:128
const fmat< T, N, M > operator*=(const fmat< S, N, N > &m2)
in place matrix multiplication with a ncols x ncols matrix m2
Definition: fmat.h:115
void set_col(unsigned j, const fvec< T, N > &v)
set column j of the matrix to vector v
Definition: fmat.h:163
T & operator()(unsigned i, unsigned j)
access to the element in the ith row in column j
Definition: fmat.h:74
fmat< T, N, M > & operator+=(const T &s)
in place addition by a scalar
Definition: fmat.h:92
const fmat< T, N, M > operator+(const T &s)
componentwise addition of a scalar
Definition: fmat.h:94
T & w()
fourth element
Definition: fvec.h:141
void set_row(unsigned i, const fvec< T, M > &v)
set row i of the matrix to vector v
Definition: fmat.h:154
fvec< T, N > & operator*=(const T &s)
in place multiplication with s
Definition: fvec.h:163
const fmat< T, N, M > operator+(const fmat< S, N, M > m2) const
matrix addition
Definition: fmat.h:109
const fmat< T, N, M > operator/(const T &s) const
division by a scalar
Definition: fmat.h:90
void transpose()
transpose matrix
Definition: fmat.h:177
fmat(const fvec< T1, N > &v, const fvec< T2, M > &w)
construct from outer product of vector v and w
Definition: fmat.h:51
T frobenius_norm() const
returns the frobenius norm of matrix m
Definition: fmat.h:184
fmat< T, N, N > transpose(const fmat< T, N, N > &m)
return the transposed of a square matrix
Definition: fmat.h:196
std::ostream & operator<<(std::ostream &out, const diag_mat< T > &m)
output of a diagonal matrix onto an ostream
Definition: diag_mat.h:442
fvec< T, N *M > base_type
base type is a vector with sufficent number of elements
Definition: fmat.h:26
bool is_square() const
returns true if matrix is a square matrix
Definition: fmat.h:72
fmat< T, N, M > & operator=(const fmat< S, N, M > &m)
assignment of a matrix with a different element type
Definition: fmat.h:62
fmat< T, N, M > dyad(const fvec< T, N > &v, const fvec< S, M > &w)
returns the outer product of vector v and w
Definition: fmat.h:248
const fmat< T, N, M > lerp(const fmat< T, N, M > &m1, const fmat< T, N, M > &m2, T t)
linear interpolation returns (1-t)*m1 + t*m2
Definition: fmat.h:259
static unsigned nrows()
number of rows
Definition: fmat.h:57
void fill(const T &a)
fill elements of vector with scalar v
Definition: fvec.h:113
std::istream & operator>>(std::istream &in, diag_mat< T > &m)
input of a diagonal matrix from an istream
Definition: diag_mat.h:453
const fvec< T, M > row(unsigned i) const
extract a row from the matrix as a vector, this is done by a type cast
Definition: fmat.h:147
fmat()
standard constructor
Definition: fmat.h:30
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
Definition: standard_types.h:20
fmat(const fmat< S, N, M > &m)
copy constructor for matrix with different element type
Definition: fmat.h:48
fvec & operator=(const fvec< T, N > &rhs)
assign vector rhs, if vector and rhs have different sizes, vector has been resized to match the size ...
Definition: fvec.h:103
T dot(const fvec< T, N > &v, const fvec< T, N > &w)
returns the dot product of vector v and w
Definition: fvec.h:300
fmat< T, N, M > & operator-=(const T &s)
in place substraction of a scalar
Definition: fmat.h:96
void identity()
set identity matrix
Definition: fmat.h:186
fmat< T, N, M > & operator/=(const T &s)
in place division by a scalar
Definition: fmat.h:88
const fmat< T, N, M > operator-() const
negation operator
Definition: fmat.h:100
fmat(cgv::type::uint32_type n, cgv::type::uint32_type m, const T *a, bool column_major=true)
creates a matrix from an array a of given dimensions - by default in column major format
Definition: fmat.h:34
fmat(cgv::type::uint32_type n, cgv::type::uint32_type m, const S *a, bool column_major=true)
creates a matrix from an array a of given dimensions but different type - by default in column major ...
Definition: fmat.h:41
fmat(const T &c)
construct a matrix with all elements set to c
Definition: fmat.h:32
const fmat< T, N, M > operator-(const fmat< S, N, M > m2) const
matrix subtraction
Definition: fmat.h:112
const fvec< T, N > & col(unsigned j) const
extract a column of the matrix as a vector
Definition: fmat.h:159
the cgv namespace
Definition: vr_calib.cxx:9
this_type operator*(const T &s) const
scalar multiplication
Definition: fmat.h:86
static unsigned ncols()
number of columns
Definition: fmat.h:59
T trace() const
returns the trace
Definition: fmat.h:168
fvec< T, N > & operator/=(const T &s)
in place division by scalar s
Definition: fvec.h:165