00001 00003 // This software is distributed as part of the Improla library. 00004 // Improla is a GUI framework for image processing. 00005 // 00006 // Copyright (c) 2004, B. R. Siva Chandra, India 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation; either version 2 00011 // of the License, or (at your option) any later version. 00012 // 00013 // This program is distributed in the hope that it will be useful, 00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 // GNU General Public License for more details. 00017 // 00018 // You should have received a copy of the GNU General Public License 00019 // along with this program; if not, write to the Free Software 00020 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00021 // 00022 // In case you would like to contact the author, use the following e-mail 00023 // address: sivachandra_br@yahoo.com 00025 00026 #ifndef __TNT_MATRIX_H__ 00027 #define __TNT_MATRIX_H__ 00028 00029 #include <tnt/tnt_array2d.h> 00030 #include <tntVector.h> 00031 #include <cstdio> 00032 #include <cmath> 00033 00034 namespace mutk 00035 { // Start brace of namespace 00036 00040 class Matrix : public TNT::Array2D< double > 00041 { 00042 public: 00043 // Constructors... 00044 Matrix(void); // Default constructor. 00045 Matrix(int, int, double); // Memory initialiser. 00046 Matrix(const Matrix&); // Copy constructor. 00047 virtual ~Matrix(); // Do nothing destructor. 00048 00049 // Data Retrievers.. 00050 Matrix transpose(void); // Deprecated. Use global function instead. 00051 virtual void fPrintf(FILE *fp); // Formatted output to a file. 00052 00053 // public Operators... 00054 00055 private: 00056 00057 }; 00058 00059 } // End brace of namespace. 00060 00061 // Operators... 00062 mutk::Matrix operator*(const mutk::Matrix&, const mutk::Matrix&); 00063 mutk::Matrix operator+(const mutk::Matrix&, const mutk::Matrix&); 00064 mutk::Matrix operator-(const mutk::Matrix&, const mutk::Matrix&); 00065 mutk::Vector operator*(const mutk::Matrix&, const mutk::Vector&); 00066 mutk::Matrix operator/(const mutk::Matrix&, double); 00067 00068 // Utils... 00069 /* 00070 Utility functions having a post-fix Small are implemented using the naive algorithms. 00071 The post-fix of Small indicates that they should be used only on small sized matrices. 00072 Determinant has been implemented using partial Gauss-Jordan elimination. Wherever 00073 required, in other utilities, this determinant has been used. Other utilities having a 00074 post-fix (say for example GaussJordan) would mean that they have been implemented using 00075 that algorithm. The loadMatrix utility should be used carefully with the FILE pointer 00076 correctly placed. Matrix::fPrintf and loadMatrix use a common format. 00077 */ 00078 mutk::Matrix loadMatrix(FILE *fp); // To be used very carefully. Formatted input from a file. 00079 mutk::Matrix Identity(int n); 00080 double determinant(const mutk::Matrix &M); 00081 mutk::Matrix transpose(const mutk::Matrix &M); // Use only for small matrices even though it is not Small. 00082 mutk::Matrix adjoint(const mutk::Matrix &M); 00083 mutk::Matrix inverseSmall(const mutk::Matrix &M); // Check for the determinant before using!! 00084 mutk::Matrix pseudoInverseSmall(const mutk::Matrix &M); // Use your own way of dealing with singular matrices!! 00085 00086 #ifndef IDENT 00087 #define IDENT(n) mutk::Identity(n) 00088 #endif 00089 00090 #endif // __TNT_MATRIX_H__ 00091