matrix.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #ifndef __GEOMETRY_MATRIX_H_
00027 #define __GEOMETRY_MATRIX_H_
00028
00029 namespace fawkes {
00030
00031 class Vector;
00032
00033 class Matrix
00034 {
00035 public:
00036 Matrix(unsigned int num_rows = 0, unsigned int num_cols = 0,
00037 float *data = 0, bool manage_own_memory = true);
00038 Matrix(const Matrix &tbc);
00039 ~Matrix();
00040
00041 void size(unsigned int &num_rows, unsigned int &num_cols) const;
00042 inline unsigned int num_rows() const { return m_num_rows; }
00043 inline unsigned int num_cols() const { return m_num_cols; }
00044
00045 Matrix &id();
00046 static Matrix get_id(unsigned int size, float *data_buffer = 0);
00047 static Matrix get_diag(unsigned int size, float value, float *data_buffer = 0);
00048
00049 Matrix &transpose();
00050 Matrix get_transpose() const;
00051
00052 Matrix &invert();
00053 Matrix get_inverse() const;
00054
00055 float det() const;
00056
00057 const float* get_data() const { return m_data; }
00058 float* get_data() { return m_data; }
00059
00060 Matrix get_submatrix(unsigned int row, unsigned int col,
00061 unsigned int num_rows, unsigned int num_cols) const;
00062
00063 void overlay(unsigned int row, unsigned int col, const Matrix &m);
00064
00065 float operator()(unsigned int row, unsigned int col) const;
00066 float &operator()(unsigned int row, unsigned int col);
00067
00068 Matrix& operator=(const Matrix &rhs);
00069
00070 Matrix operator*(const Matrix &rhs) const;
00071 Matrix& operator*=(const Matrix &rhs);
00072
00073 Vector operator*(const Vector &cv) const;
00074
00075 Matrix operator*(const float &f) const;
00076 Matrix& operator*=(const float &f);
00077
00078 Matrix operator/(const float &f) const;
00079 Matrix& operator/=(const float &f);
00080
00081 Matrix operator+(const Matrix &rhs) const;
00082 Matrix& operator+=(const Matrix &rhs);
00083
00084 Matrix operator-(const Matrix &rhs) const;
00085 Matrix& operator-=(const Matrix &rhs);
00086
00087 bool operator==(const Matrix &rhs) const;
00088
00089 void print_info(const char *name = 0, const char *col_sep = 0,
00090 const char *row_sep = 0) const;
00091
00092 private:
00093 void mult_row(unsigned int row, float factor);
00094 void sub_row(unsigned int row_a, unsigned int row_b, float factor);
00095 inline float data(unsigned int row, unsigned int col) const
00096 {
00097 return m_data[row * m_num_cols + col];
00098 }
00099 inline float& data(unsigned int row, unsigned int col)
00100 {
00101 return m_data[row * m_num_cols + col];
00102 }
00103
00104 private:
00105 float *m_data;
00106
00107 unsigned int m_num_rows;
00108 unsigned int m_num_cols;
00109 unsigned int m_num_elements;
00110
00111 bool m_own_memory;
00112 };
00113
00114 }
00115
00116 #endif