latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 00004 * 00005 * This file is part of the LTI-Computer Vision Library (LTI-Lib) 00006 * 00007 * The LTI-Lib is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Lesser General Public License (LGPL) 00009 * as published by the Free Software Foundation; either version 2.1 of 00010 * the License, or (at your option) any later version. 00011 * 00012 * The LTI-Lib is distributed in the hope that it will be 00013 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty 00014 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Lesser General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Lesser General Public 00018 * License along with the LTI-Lib; see the file LICENSE. If 00019 * not, write to the Free Software Foundation, Inc., 59 Temple Place - 00020 * Suite 330, Boston, MA 02111-1307, USA. 00021 */ 00022 00023 00024 /*---------------------------------------------------------------- 00025 * project ....: LTI Digital Image/Signal Processing Library 00026 * file .......: ltiDynamicMatrix.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 09.04.99 00030 * revisions ..: $Id: ltiDynamicMatrix.h,v 1.3 2006/02/08 12:18:00 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_DYNAMIC_MATRIX_H_ 00034 #define _LTI_DYNAMIC_MATRIX_H_ 00035 00036 #include <assert.h> 00037 #include <iostream> 00038 #include <map> 00039 #include <list> 00040 00041 #include "ltiMathObject.h" 00042 #include "ltiMath.h" 00043 #include "ltiPoint.h" 00044 00045 namespace lti { 00046 /** 00047 * This template class allows the use of matrices which change its 00048 * dimensions without losing any data. They are base on the 00049 * STL-maps. The intention of this class is to provide a base 00050 * data-structure for the generation of classification statistics 00051 * (confusion-matrices). This is a VERY SLOW class, but highly 00052 * confortable for dynamically growing matrices. 00053 * 00054 * @ingroup gAggregate 00055 */ 00056 template <class T> 00057 class dynamicMatrix : public mathObject { 00058 public: 00059 /** 00060 * default constructor (create an empty matrix) 00061 */ 00062 dynamicMatrix(); 00063 00064 /** 00065 * copy constructor 00066 */ 00067 dynamicMatrix(const dynamicMatrix<T>& other); 00068 00069 /** 00070 * destructor 00071 */ 00072 ~dynamicMatrix(); 00073 00074 /** 00075 * get number of rows actually being stored 00076 */ 00077 inline unsigned int rows() const { return theRowIdx.size();}; 00078 00079 /** 00080 * get the number of columns actually being stored 00081 */ 00082 inline unsigned int columns() const { return theColIdx.size();}; 00083 00084 /** 00085 * Return type of the size() member 00086 */ 00087 typedef point size_type; 00088 00089 /** 00090 * return the size of the matrix (number of used rows and columns) as 00091 * a point. The "x" member contains the used columns and "y" the used 00092 * rows. 00093 */ 00094 inline size_type size() const {return point();} 00095 00096 /** 00097 * check if the given row exist on the matrix 00098 */ 00099 bool isRowValid(const int theRow) const; 00100 00101 /** 00102 * check if the given matrix exist on the matrix 00103 */ 00104 bool isColumnValid(const int theColumn) const; 00105 00106 /** 00107 * insert a row with index "theRow" on the matrix, and initialize 00108 * its contents with "initialValue" 00109 */ 00110 bool addRow(const int theRow,const T initialValue = T()); 00111 00112 /** 00113 * insert a column with index "theColumn" on the matrix, and initialize 00114 * its contents with "initialValue" 00115 */ 00116 bool addColumn(const int theColumn,const T initialValue = T()); 00117 00118 /** 00119 * delete the given row if it exists 00120 */ 00121 bool deleteRow(const int theRow); 00122 00123 /** 00124 * delete the given column if it exists 00125 */ 00126 bool deleteColumn(const int theColumn); 00127 00128 /** 00129 * read-write access operator 00130 */ 00131 inline T& at(const int& theRow,const int& theColumn); 00132 00133 /** 00134 * read only access operator 00135 */ 00136 inline const T & at(const int& theRow,const int& theColumn) const; 00137 00138 /** 00139 * assignment operator 00140 */ 00141 inline dynamicMatrix& operator=(const dynamicMatrix<T>& theMatrix) { 00142 return copy(theMatrix); 00143 }; 00144 00145 /** 00146 * copy operator 00147 */ 00148 inline dynamicMatrix& copy(const dynamicMatrix<T>& theMatrix); 00149 00150 /** 00151 * clone member 00152 */ 00153 mathObject* clone() const; 00154 00155 /** 00156 * the value given here will be return if the content of a non existent 00157 * cell is requested 00158 */ 00159 void setErrorValue(T error) {errorValue = error;}; 00160 00161 /** 00162 * clear the contents of the matrix 00163 */ 00164 void clear(); 00165 00166 /** 00167 * list of integers, used to indicate the used indices in the matrix 00168 */ 00169 typedef std::list<int> stdIndexList; 00170 00171 /** 00172 * returns a list of integers with the used row indices 00173 */ 00174 const stdIndexList& getUsedRows() const {return theRowIdx;}; 00175 00176 /** 00177 * returns a list of integers with the used column indices 00178 */ 00179 const stdIndexList& getUsedColumns() const {return theColIdx;}; 00180 00181 protected: 00182 /** 00183 * type of a "dynamic"-row 00184 */ 00185 typedef std::map<int,T> stdRowMap; 00186 00187 /** 00188 * the matrix-data type 00189 */ 00190 typedef std::map<int,stdRowMap> stddynamicMatrix; 00191 00192 /** 00193 * the list of row indices 00194 */ 00195 stdIndexList theRowIdx; 00196 00197 /** 00198 * the list of column indices 00199 */ 00200 stdIndexList theColIdx; 00201 00202 /** 00203 * the matrix data 00204 */ 00205 stddynamicMatrix theMatrix; 00206 00207 /** 00208 * value used when unexistent cells are accessed. 00209 */ 00210 T errorValue; 00211 }; 00212 00213 00214 } 00215 00216 #include "ltiDynamicMatrix_template.h" 00217 00218 #endif