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 .......: ltiDataTransformer.h 00027 * authors ....: Jochen Wickel 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 5.11.2002 00030 * revisions ..: $Id: ltiDataTransformer.h,v 1.5 2006/02/08 12:02:57 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_DATA_TRANSFORMER_H_ 00034 #define _LTI_DATA_TRANSFORMER_H_ 00035 00036 #include "ltiFunctor.h" 00037 #include "ltiTypes.h" 00038 #include "ltiVector.h" 00039 00040 namespace lti { 00041 /** 00042 * This is the low-level base class for data transformers. Most notable 00043 * examples for such transformers are coding or encryption functors. 00044 * This an abstract class. 00045 */ 00046 class dataTransformer : public functor { 00047 public: 00048 00049 enum { 00050 notEnoughSpace=-1 00051 }; 00052 00053 /** 00054 * Type for the elements in a buffer must be restricted to 00055 * unsigned bytes. 00056 */ 00057 typedef ubyte bufferElement; 00058 00059 /** 00060 * The buffers with the data to be transformed (or the transformed data) 00061 * are manipulated in container instances of the buffer type. 00062 */ 00063 class buffer : public vector<bufferElement> { 00064 public: 00065 buffer(const int& n) : vector<bufferElement>(n) {}; 00066 buffer(const int& n, bufferElement data[], bool constRef) 00067 : vector<bufferElement>(n,data,constRef) {}; 00068 00069 /** 00070 * Save this buffer as a raw data block to the given file. 00071 */ 00072 bool saveRaw(const std::string& name) const; 00073 00074 /** 00075 * Load this buffer as a raw data block from the given file. 00076 * The buffer is resized to fit the size of the file. 00077 */ 00078 bool loadRaw(const std::string& name); 00079 }; 00080 00081 /** 00082 * default constructor 00083 */ 00084 dataTransformer(); 00085 00086 /** 00087 * Construct a functor using the given parameters 00088 */ 00089 dataTransformer(const parameters& par); 00090 00091 /** 00092 * copy constructor 00093 * @param other the object to be copied 00094 */ 00095 dataTransformer(const dataTransformer& other); 00096 00097 /** 00098 * destructor 00099 */ 00100 virtual ~dataTransformer(); 00101 00102 /** 00103 * returns the name of this type ("dataTransformer") 00104 */ 00105 virtual const char* getTypeName() const; 00106 00107 /** 00108 * Operates on the given arguments. 00109 * @param srcdest pointer to an array of bufferElement. The input 00110 * array must be allocated and have enough space for 00111 * input as well as output data. 00112 * @param nsrc the number of input bytes that should be transformed. 00113 * @param ndest The caller must set this to the number of bytes 00114 * of the buffer that can be used for the result. 00115 * After returning, it will contain the number of bytes 00116 * that are actually used. 00117 * If buffer was too small, it will contain notEnoughSpace. 00118 * @return true if apply successful or false otherwise. 00119 */ 00120 virtual bool apply(bufferElement* srcdest, int nsrc, int& ndest) const=0; 00121 00122 /** 00123 * Operates on the given argument. 00124 * @param srcdest vector with the input data which will 00125 * also receive the transformed data. The 00126 * vector will be resized to fit the transformed data. 00127 * @return true if apply successful or false otherwise. 00128 */ 00129 virtual bool apply(buffer& srcdest) const=0; 00130 00131 /** 00132 * Operates on a copy of the given arguments. 00133 * @param src pointer to an array of bufferElement which contains the 00134 * source data 00135 * @param nsrc the number of input bytes that should be transformed. 00136 * @param dest pointer to an array of bufferElement which will receive 00137 * the transformed data. The array must be allocated 00138 * by the caller. 00139 * @param ndest When called, must contain the size of the output 00140 * buffer. When the function returns, it contains the 00141 * number of bytes actually used, or -1 if the buffer 00142 * was too small. 00143 * 00144 * @return true if apply successful or false otherwise. 00145 */ 00146 virtual bool apply(const bufferElement* src, int nsrc, bufferElement* dest, int& ndest) const=0; 00147 00148 /** 00149 * Operates on the given argument. 00150 * @param src vector with the input data. All elements of the vector 00151 * are transformed. 00152 * @param dest vector which will receive the transformed data. The 00153 * vector is resized so that it fits the data. 00154 * @return true if apply successful or false otherwise. 00155 */ 00156 virtual bool apply(const buffer& src, buffer& dest) const=0; 00157 00158 /** 00159 * copy data of "other" functor. 00160 * @param other the functor to be copied 00161 * @return a reference to this functor object 00162 */ 00163 dataTransformer& copy(const dataTransformer& other); 00164 00165 /** 00166 * alias for copy member 00167 * @param other the functor to be copied 00168 * @return a reference to this functor object 00169 */ 00170 dataTransformer& operator=(const dataTransformer& other); 00171 00172 /** 00173 * returns used parameters 00174 */ 00175 const parameters& getParameters() const; 00176 00177 //TODO: comment the attributes of your functor 00178 // If you add more attributes manually, do not forget to do following: 00179 // 1. indicate in the default constructor the default values 00180 // 2. make sure that the copy member also copy your new attributes, or 00181 // to ensure there, that these attributes are properly initialized. 00182 00183 protected: 00184 static const char* notEnoughSpaceMsg; 00185 00186 }; 00187 } 00188 00189 #endif