latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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-Lib: Image Processing and Computer Vision Library 00026 * file .......: ltiUciDataWriter.h 00027 * authors ....: Jens Paustenbach 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 21.5.2002 00030 * revisions ..: $Id: ltiUciDataWriter.h,v 1.8 2006/02/08 12:08:53 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_UCI_DATA_WRITER_H_ 00034 #define _LTI_UCI_DATA_WRITER_H_ 00035 00036 #include <fstream> 00037 #include <list> 00038 00039 #include "ltiMatrix.h" 00040 #include "ltiVector.h" 00041 #include "ltiIOFunctor.h" 00042 00043 00044 namespace lti { 00045 /** 00046 * Writes data in the form as it is often found in standard data sets: 00047 * Raw data either just a matrix of doubles with each row a feature 00048 * vector, or rows containing feature vectors and an id as last element 00049 * of the row, or raw data with or without ids and a header with the number 00050 * of points and the dimensionality. With %parameter append it can be choosen 00051 * if the data if appended to an existing file or if the file should be new 00052 * created. 00053 * <p> If the filename exists and append is false, your data will be lost. 00054 * 00055 * This %functor needs the filename and the existence of a header as 00056 * %parameters. With the third parameter you can choose if the data 00057 * should be appended of if a new file will be created. 00058 */ 00059 class uciDataWriter : public ioFunctor { 00060 public: 00061 /** 00062 * the parameters for the class uciDataWriter 00063 */ 00064 class parameters : public ioFunctor::parameters { 00065 public: 00066 /** 00067 * default constructor 00068 */ 00069 parameters(); 00070 00071 /** 00072 * copy constructor 00073 * @param other the parameters object to be copied 00074 */ 00075 parameters(const parameters& other); 00076 00077 /** 00078 * destructor 00079 */ 00080 ~parameters(); 00081 00082 /** 00083 * returns name of this type 00084 */ 00085 const char* getTypeName() const; 00086 00087 /** 00088 * copy the contents of a parameters object 00089 * @param other the parameters object to be copied 00090 * @return a reference to this parameters object 00091 */ 00092 parameters& copy(const parameters& other); 00093 00094 /** 00095 * copy the contents of a parameters object 00096 * @param other the parameters object to be copied 00097 * @return a reference to this parameters object 00098 */ 00099 parameters& operator=(const parameters& other); 00100 00101 00102 /** 00103 * returns a pointer to a clone of the parameters 00104 */ 00105 virtual functor::parameters* clone() const; 00106 00107 /** 00108 * write the parameters in the given ioHandler 00109 * @param handler the ioHandler to be used 00110 * @param complete if true (the default) the enclosing begin/end will 00111 * be also written, otherwise only the data block will be written. 00112 * @return true if write was successful 00113 */ 00114 virtual bool write(ioHandler& handler,const bool complete=true) const; 00115 00116 /** 00117 * read the parameters from the given ioHandler 00118 * @param handler the ioHandler to be used 00119 * @param complete if true (the default) the enclosing begin/end will 00120 * be also written, otherwise only the data block will be written. 00121 * @return true if write was successful 00122 */ 00123 virtual bool read(ioHandler& handler,const bool complete=true); 00124 00125 # ifdef _LTI_MSC_6 00126 /** 00127 * this function is required by MSVC only, as a workaround for a 00128 * very awful bug, which exists since MSVC V.4.0, and still by 00129 * V.6.0 with all bugfixes (so called "service packs") remains 00130 * there... This method is also public due to another bug, so please 00131 * NEVER EVER call this method directly: use read() instead 00132 */ 00133 bool readMS(ioHandler& handler,const bool complete=true); 00134 00135 /** 00136 * this function is required by MSVC only, as a workaround for a 00137 * very awful bug, which exists since MSVC V.4.0, and still by 00138 * V.6.0 with all bugfixes (so called "service packs") remains 00139 * there... This method is also public due to another bug, so please 00140 * NEVER EVER call this method directly: use write() instead 00141 */ 00142 bool writeMS(ioHandler& handler,const bool complete=true) const; 00143 # endif 00144 00145 // ------------------------------------------------ 00146 // the parameters 00147 // ------------------------------------------------ 00148 00149 /** 00150 * if true there is an id indicating the class of the feature vector 00151 * inserted 00152 */ 00153 bool hasHeader; 00154 00155 /** 00156 * if true the data will be appended to the given file 00157 */ 00158 bool append; 00159 }; 00160 00161 /** 00162 * default constructor 00163 */ 00164 uciDataWriter(); 00165 00166 /** 00167 * sets the filename 00168 */ 00169 uciDataWriter(std::string filename); 00170 00171 /** 00172 * sets the parameters filename and hasHeader 00173 */ 00174 uciDataWriter(std::string filename, bool bHeader); 00175 00176 /** 00177 * copy constructor 00178 * @param other the object to be copied 00179 */ 00180 uciDataWriter(const uciDataWriter& other); 00181 00182 /** 00183 * destructor 00184 */ 00185 virtual ~uciDataWriter(); 00186 00187 /** 00188 * returns the name of this type ("uciDataWriter") 00189 */ 00190 virtual const char* getTypeName() const; 00191 00192 /** 00193 * Writes data to the file given in the parameters. 00194 * @param data the feature vectors 00195 * @return true if apply successful or false otherwise. 00196 */ 00197 bool apply(dmatrix& data) const; 00198 00199 /** 00200 * Writes data and ids to the file given in the parameters. 00201 * @param data the feature vectors 00202 * @param ids ids of the feature vectors 00203 * @return true if apply successful or false otherwise. 00204 */ 00205 bool apply(dmatrix& data, ivector& ids) const; 00206 00207 /** 00208 * Writes data to the file given in the parameters. 00209 * @param data the feature vectors 00210 * @return true if apply successful or false otherwise. 00211 */ 00212 bool apply(fmatrix& data) const; 00213 00214 /** 00215 * Writes data and ids to the file given in the parameters. 00216 * @param data the feature vectors 00217 * @param ids ids of the feature vectors 00218 * @return true if apply successful or false otherwise. 00219 */ 00220 bool apply(fmatrix& data, ivector& ids) const; 00221 00222 /** 00223 * Writes data and ids to the file given in the parameters. 00224 * It is suggested that each element of the list is one Cluster 00225 * @param data the feature vectors 00226 * @return true if apply successful or false otherwise. 00227 */ 00228 bool apply(std::list<dmatrix>& data) const; 00229 00230 /** 00231 * Writes data and ids to the file given in the parameters. 00232 * The i-th element of ids is the number to which the points in the i-th 00233 * matrix in data belong to 00234 * @param data the feature vectors 00235 * @param ids IDs for the elements in data. 00236 * @return true if apply successful or false otherwise. 00237 */ 00238 bool apply(std::list<dmatrix>& data,ivector& ids) const; 00239 00240 /** 00241 * copy data of "other" functor. 00242 * @param other the functor to be copied 00243 * @return a reference to this functor object 00244 */ 00245 uciDataWriter& copy(const uciDataWriter& other); 00246 00247 /** 00248 * alias for copy member 00249 * @param other the functor to be copied 00250 * @return a reference to this functor object 00251 */ 00252 uciDataWriter& operator=(const uciDataWriter& other); 00253 00254 /** 00255 * returns a pointer to a clone of this functor. 00256 */ 00257 virtual functor* clone() const; 00258 00259 /** 00260 * returns used parameters 00261 */ 00262 const parameters& getParameters() const; 00263 }; 00264 } 00265 00266 #endif