Fawkes API  Fawkes Development Version
matrix.h
00001 
00002 /***************************************************************************
00003  *  matrix.h - A matrix class
00004  *
00005  *  Created: Wed Sep 26 14:28:01 2007
00006  *  Copyright  2007-2009  Daniel Beck <beck@kbsg.rwth-aachen.de>
00007  *             2009       Masrur Doostdar <doostdar@kbsg.rwth-aachen.de>
00008  *             2009       Christof Rath <c.rath@student.tugraz.at>
00009  *
00010  ****************************************************************************/
00011 
00012 /*  This program is free software; you can redistribute it and/or modify
00013  *  it under the terms of the GNU General Public License as published by
00014  *  the Free Software Foundation; either version 2 of the License, or
00015  *  (at your option) any later version. A runtime exception applies to
00016  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00017  *
00018  *  This program is distributed in the hope that it will be useful,
00019  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00020  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00021  *  GNU Library General Public License for more details.
00022  *
00023  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
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 } // end namespace fawkes
00115 
00116 #endif /* __GEOMETRY_MATRIX_H_ */