latest version v1.9 - last update 10 Apr 2010 |
00001 /* 00002 * Copyright (C) 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 .......: ltiTypeInfo.h 00027 * authors ....: Pablo Alvarado 00028 * organization: LTI, RWTH Aachen 00029 * creation ...: 16.05.01 00030 * revisions ..: $Id: ltiTypeInfo.h,v 1.8 2006/02/07 18:10:51 ltilib Exp $ 00031 */ 00032 00033 #ifndef _LTI_TYPE_INFO_H_ 00034 #define _LTI_TYPE_INFO_H_ 00035 00036 #include "ltiObject.h" 00037 #include "ltiTypes.h" 00038 #include <limits> 00039 00040 // Visual define this as macros 00041 #undef min 00042 #undef max 00043 00044 /** 00045 * \file ltiTypeInfo.h 00046 * Definition of some template functions that give information 00047 * about its template type. 00048 */ 00049 00050 /* 00051 * namespace lti 00052 */ 00053 namespace lti { 00054 00055 /** 00056 * This class allows to ask some information required in the 00057 * LTI-Lib for some types. 00058 * Note that the members are static, and you do not need any 00059 * instance of the class to get the type information. 00060 * 00061 * For more information about a type you can also use the 00062 * std::numeric_limits type of the Standard Template Library. 00063 * 00064 * Example: 00065 * \code 00066 * if (typeInfo<double>::isFloatingPointType()) { 00067 * cout << "double is a floating point type" << endl; 00068 * } else { 00069 * cout << "this is a really weird case!" << endl; 00070 * } 00071 * \endcode 00072 */ 00073 template<class T> 00074 class typeInfo : public object { 00075 public: 00076 /** 00077 * Type suggested for accumulation of current type elements 00078 * (for example int for ubyte). 00079 */ 00080 typedef T accumulation_type; 00081 00082 /** 00083 * Type suggested to accumulate the square of values of the current 00084 * type 00085 */ 00086 typedef T square_accumulation_type; 00087 00088 /** 00089 * suggest a norm for the given type. 00090 * Usually 255 is used for ubyte, 127 for byte, 65535 for all other 00091 * integer types and 1.0 for the floating point types. 00092 */ 00093 static T suggestedNorm() throw() {return 65535;} 00094 00095 /** 00096 * return true if the type T is a floating point type. 00097 */ 00098 static bool isFloatingPointType() throw() {return false;} 00099 00100 /** 00101 * Return a const char* with the name of the type 00102 */ 00103 static const char* name() throw() {return "";} 00104 00105 /** 00106 * The difference of this minimum with the std::numeric_limits<T>::min() is 00107 * that here the minimum value is returned for floating point types and 00108 * fixed point types. The STL method returns for floating point values 00109 * the minimal representable value above zero. For max() you can use 00110 * the standard version 00111 */ 00112 static T min() throw() {return std::numeric_limits<T>::min();} 00113 }; 00114 00115 // ------------------------ 00116 // template specializations 00117 // ------------------------ 00118 00119 template<> 00120 class typeInfo<ubyte> : public object { 00121 public: 00122 typedef int accumulation_type; 00123 typedef int square_accumulation_type; 00124 static ubyte suggestedNorm() throw() {return 255;} 00125 static bool isFloatingPointType() throw() {return false;} 00126 static const char* name() throw() {return "ubyte";}; 00127 static ubyte min() throw() {return std::numeric_limits<ubyte>::min();} 00128 }; 00129 00130 template<> 00131 class typeInfo<byte> : public object { 00132 public: 00133 typedef int accumulation_type; 00134 typedef int square_accumulation_type; 00135 static byte suggestedNorm() throw() {return 127;} 00136 static bool isFloatingPointType() throw() {return false;} 00137 static const char* name() throw() {return "byte";} 00138 static byte min() throw() {return std::numeric_limits<byte>::min();} 00139 }; 00140 00141 template<> 00142 class typeInfo<short int> : public object { 00143 public: 00144 typedef int accumulation_type; 00145 typedef double square_accumulation_type; 00146 static short int suggestedNorm() throw() {return 255;} 00147 static bool isFloatingPointType() throw() {return false;} 00148 static const char* name() throw() {return "short int";} 00149 static short int min() throw() { 00150 return std::numeric_limits<short int>::min(); 00151 } 00152 }; 00153 00154 template<> 00155 class typeInfo<unsigned short int> : public object { 00156 public: 00157 typedef int accumulation_type; 00158 typedef double square_accumulation_type; 00159 static unsigned short int suggestedNorm() throw() {return 255;} 00160 static bool isFloatingPointType() throw() {return false;} 00161 static const char* name() throw() {return "unsigned short int";} 00162 static unsigned short int min() throw() { 00163 return std::numeric_limits<unsigned short int>::min(); 00164 } 00165 }; 00166 00167 template<> 00168 class typeInfo<int> : public object { 00169 public: 00170 typedef int accumulation_type; 00171 typedef double square_accumulation_type; 00172 static int suggestedNorm() throw() {return 65535;} 00173 static bool isFloatingPointType() throw() {return false;} 00174 static const char* name() throw() {return "int";} 00175 static int min() throw() {return std::numeric_limits<int>::min();} 00176 }; 00177 00178 template<> 00179 class typeInfo<unsigned int> : public object { 00180 public: 00181 typedef int accumulation_type; 00182 typedef double square_accumulation_type; 00183 static unsigned int suggestedNorm() throw() {return 65535;} 00184 static bool isFloatingPointType() throw() {return false;} 00185 static const char* name() throw() {return "unsigned int";} 00186 static unsigned int min() throw() { 00187 return std::numeric_limits<unsigned int>::min(); 00188 } 00189 }; 00190 00191 template<> 00192 class typeInfo<float> : public object { 00193 public: 00194 typedef float accumulation_type; 00195 typedef double square_accumulation_type; 00196 static float suggestedNorm() throw() {return 1.0f;} 00197 static bool isFloatingPointType() throw() {return true;} 00198 static const char* name() throw() {return "float";}; 00199 static float min() throw() {return -std::numeric_limits<float>::max();} 00200 }; 00201 00202 template<> 00203 class typeInfo<double> : public object { 00204 public: 00205 typedef double accumulation_type; 00206 typedef double square_accumulation_type; 00207 static double suggestedNorm() throw() {return 1.0;} 00208 static bool isFloatingPointType() throw() {return true;} 00209 static const char* name() throw() {return "double";}; 00210 static double min() throw() {return -std::numeric_limits<double>::max();} 00211 }; 00212 } 00213 00214 00215 #endif