Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
matrix.h
1 
2 /***************************************************************************
3  * matrix.h - A matrix class
4  *
5  * Created: Wed Sep 26 14:28:01 2007
6  * Copyright 2007-2009 Daniel Beck <beck@kbsg.rwth-aachen.de>
7  * 2009 Masrur Doostdar <doostdar@kbsg.rwth-aachen.de>
8  * 2009 Christof Rath <c.rath@student.tugraz.at>
9  *
10  ****************************************************************************/
11 
12 /* This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version. A runtime exception applies to
16  * this software (see LICENSE.GPL_WRE file mentioned below for details).
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU Library General Public License for more details.
22  *
23  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
24  */
25 
26 #ifndef __GEOMETRY_MATRIX_H_
27 #define __GEOMETRY_MATRIX_H_
28 
29 namespace fawkes {
30 
31 class Vector;
32 
33 class Matrix
34 {
35 public:
36  Matrix(unsigned int num_rows = 0, unsigned int num_cols = 0,
37  float *data = 0, bool manage_own_memory = true);
38  Matrix(const Matrix &tbc);
39  ~Matrix();
40 
41  void size(unsigned int &num_rows, unsigned int &num_cols) const;
42  inline unsigned int num_rows() const { return m_num_rows; }
43  inline unsigned int num_cols() const { return m_num_cols; }
44 
45  Matrix &id();
46  static Matrix get_id(unsigned int size, float *data_buffer = 0);
47  static Matrix get_diag(unsigned int size, float value, float *data_buffer = 0);
48 
49  Matrix &transpose();
50  Matrix get_transpose() const;
51 
52  Matrix &invert();
53  Matrix get_inverse() const;
54 
55  float det() const;
56 
57  const float* get_data() const { return m_data; }
58  float* get_data() { return m_data; }
59 
60  Matrix get_submatrix(unsigned int row, unsigned int col,
61  unsigned int num_rows, unsigned int num_cols) const;
62 
63  void overlay(unsigned int row, unsigned int col, const Matrix &m);
64 
65  float operator()(unsigned int row, unsigned int col) const;
66  float &operator()(unsigned int row, unsigned int col);
67 
68  Matrix& operator=(const Matrix &rhs);
69 
70  Matrix operator*(const Matrix &rhs) const;
71  Matrix& operator*=(const Matrix &rhs);
72 
73  Vector operator*(const Vector &cv) const;
74 
75  Matrix operator*(const float &f) const;
76  Matrix& operator*=(const float &f);
77 
78  Matrix operator/(const float &f) const;
79  Matrix& operator/=(const float &f);
80 
81  Matrix operator+(const Matrix &rhs) const;
82  Matrix& operator+=(const Matrix &rhs);
83 
84  Matrix operator-(const Matrix &rhs) const;
85  Matrix& operator-=(const Matrix &rhs);
86 
87  bool operator==(const Matrix &rhs) const;
88 
89  void print_info(const char *name = 0, const char *col_sep = 0,
90  const char *row_sep = 0) const;
91 
92 private:
93  void mult_row(unsigned int row, float factor);
94  void sub_row(unsigned int row_a, unsigned int row_b, float factor);
95  inline float data(unsigned int row, unsigned int col) const
96  {
97  return m_data[row * m_num_cols + col];
98  }
99  inline float& data(unsigned int row, unsigned int col)
100  {
101  return m_data[row * m_num_cols + col];
102  }
103 
104 private:
105  float *m_data;
106 
107  unsigned int m_num_rows;
108  unsigned int m_num_cols;
109  unsigned int m_num_elements;
110 
111  bool m_own_memory;
112 };
113 
114 } // end namespace fawkes
115 
116 #endif /* __GEOMETRY_MATRIX_H_ */