Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkNumericTraits.h

Go to the documentation of this file.
00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkNumericTraits.h,v $ 00005 Language: C++ 00006 Date: $Date: 2003/09/10 14:29:18 $ 00007 Version: $Revision: 1.33 $ 00008 00009 Copyright (c) Insight Software Consortium. All rights reserved. 00010 See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __itkNumericTraits_h 00018 #define __itkNumericTraits_h 00019 00020 #include "itkMacro.h" 00021 #undef min 00022 #undef max 00023 00024 #if (defined(_MSC_VER)) || (defined(__BORLANDC__)) || (defined(__sgi) && !defined(__GNUC__)) 00025 #include <limits> 00026 #define ITK_NUMERIC_LIMITS std::numeric_limits 00027 #else 00028 #include "vnl/vnl_numeric_limits.h" 00029 #define ITK_NUMERIC_LIMITS vnl_numeric_limits 00030 #endif 00031 00032 namespace itk 00033 { 00034 00045 template <class T> 00046 class NumericTraits : public ITK_NUMERIC_LIMITS<T> { 00047 public: 00049 typedef T ValueType; 00050 00052 typedef T PrintType; 00053 00055 typedef T AbsType; 00056 00058 typedef double AccumulateType; 00059 00061 static const T Zero; 00062 00064 static const T One; 00065 00067 static T NonpositiveMin() { return min(); } 00068 00070 static bool IsPositive(T val) { return val > Zero; } 00071 00073 static bool IsNonpositive(T val) { return val <= Zero; } 00074 00076 static bool IsNegative(T val) { return val < Zero; } 00077 00079 static bool IsNonnegative(T val) { return val >= Zero; } 00080 }; 00081 00088 template <> 00089 class NumericTraits<bool> : public ITK_NUMERIC_LIMITS<bool> { 00090 public: 00091 typedef bool ValueType; 00092 typedef bool PrintType; 00093 typedef unsigned char AbsType; 00094 typedef unsigned char AccumulateType; 00095 static const bool ITKCommon_EXPORT Zero; 00096 static const bool ITKCommon_EXPORT One; 00097 00098 static bool NonpositiveMin() { return false; } 00099 static bool IsPositive(bool val) { return val; } 00100 static bool IsNonpositive(bool val) { return !val; } 00101 static bool IsNegative(bool /* val */) { return false; } 00102 static bool IsNonnegative(bool /*val*/) {return true; } 00103 }; 00104 00109 template <> 00110 class NumericTraits<char> : public ITK_NUMERIC_LIMITS<char> { 00111 public: 00112 typedef char ValueType; 00113 typedef int PrintType; 00114 typedef unsigned char AbsType; 00115 typedef short AccumulateType; 00116 typedef double RealType; 00117 static const char ITKCommon_EXPORT Zero; 00118 static const char ITKCommon_EXPORT One; 00119 00120 static char min() { return char(255) < 0 ? -128 : 0; } 00121 static char max() { return char(255) < 0 ? 127 : 255; } 00122 static char NonpositiveMin() { return min(); } 00123 static bool IsPositive(char val) { return val > Zero; } 00124 static bool IsNonpositive(char val) { return val <= Zero; } 00125 static bool IsNegative(char val) { return val < Zero; } 00126 static bool IsNonnegative(char val) {return val >= Zero; } 00127 }; 00128 00133 template <> 00134 class NumericTraits<signed char> : public ITK_NUMERIC_LIMITS<signed char> { 00135 public: 00136 typedef signed char ValueType; 00137 typedef int PrintType; 00138 typedef unsigned char AbsType; 00139 typedef short AccumulateType; 00140 typedef double RealType; 00141 static const signed char ITKCommon_EXPORT Zero; 00142 static const signed char ITKCommon_EXPORT One; 00143 00144 static signed char min() { return -128; } 00145 static signed char max() { return 127; } 00146 static signed char NonpositiveMin() { return min(); } 00147 static bool IsPositive(signed char val) { return val > Zero; } 00148 static bool IsNonpositive(signed char val) { return val <= Zero; } 00149 static bool IsNegative(signed char val) { return val < Zero; } 00150 static bool IsNonnegative(signed char val) {return val >= Zero; } 00151 }; 00152 00157 template <> 00158 class NumericTraits<unsigned char> : public ITK_NUMERIC_LIMITS<unsigned char> { 00159 public: 00160 typedef unsigned char ValueType; 00161 typedef int PrintType; 00162 typedef unsigned char AbsType; 00163 typedef unsigned short AccumulateType; 00164 typedef double RealType; 00165 static const unsigned char ITKCommon_EXPORT Zero; 00166 static const unsigned char ITKCommon_EXPORT One; 00167 00168 static unsigned char NonpositiveMin() { return min(); } 00169 static bool IsPositive(unsigned char val) { return val != Zero; } 00170 static bool IsNonpositive(unsigned char val) { return val == Zero; } 00171 static bool IsNegative(unsigned char /* val */) { return false; } 00172 static bool IsNonnegative(unsigned char /*val */) {return true; } 00173 }; 00174 00178 template <> 00179 class NumericTraits<short> : public ITK_NUMERIC_LIMITS<short> { 00180 public: 00181 typedef short ValueType; 00182 typedef short PrintType; 00183 typedef unsigned short AbsType; 00184 typedef int AccumulateType; 00185 typedef double RealType; 00186 static const short ITKCommon_EXPORT Zero; 00187 static const short ITKCommon_EXPORT One; 00188 00189 static short NonpositiveMin() { return min(); } 00190 static bool IsPositive(short val) { return val > Zero; } 00191 static bool IsNonpositive(short val) { return val <= Zero; } 00192 static bool IsNegative(short val) { return val < Zero; } 00193 static bool IsNonnegative(short val) {return val >= Zero; } 00194 }; 00195 00200 template <> 00201 class NumericTraits<unsigned short> : public ITK_NUMERIC_LIMITS<unsigned short> { 00202 public: 00203 typedef unsigned short ValueType; 00204 typedef unsigned short PrintType; 00205 typedef unsigned short AbsType; 00206 typedef unsigned int AccumulateType; 00207 typedef double RealType; 00208 static const unsigned short ITKCommon_EXPORT Zero; 00209 static const unsigned short ITKCommon_EXPORT One; 00210 00211 static unsigned short NonpositiveMin() { return min(); } 00212 static unsigned short IsPositive(unsigned short val) { return val != Zero; } 00213 static bool IsNonpositive(unsigned short val) { return val == Zero; } 00214 static bool IsNegative(unsigned short/* val*/) { return false; } 00215 static bool IsNonnegative(unsigned short /*val*/) {return true; } 00216 }; 00217 00221 template <> 00222 class NumericTraits<int> : public ITK_NUMERIC_LIMITS<int> { 00223 public: 00224 typedef int ValueType; 00225 typedef int PrintType; 00226 typedef unsigned int AbsType; 00227 typedef long AccumulateType; 00228 typedef double RealType; 00229 static const int ITKCommon_EXPORT Zero; 00230 static const int ITKCommon_EXPORT One; 00231 00232 static int NonpositiveMin() { return min(); } 00233 static bool IsPositive(int val) { return val > Zero; } 00234 static bool IsNonpositive(int val) { return val <= Zero; } 00235 static bool IsNegative(int val) { return val < Zero; } 00236 static bool IsNonnegative(int val) {return val >= Zero; } 00237 }; 00238 00243 template <> 00244 class NumericTraits<unsigned int> : public ITK_NUMERIC_LIMITS<unsigned int> { 00245 public: 00246 typedef unsigned int ValueType; 00247 typedef unsigned int PrintType; 00248 typedef unsigned int AbsType; 00249 typedef unsigned int AccumulateType; 00250 typedef double RealType; 00251 static const unsigned int ITKCommon_EXPORT Zero; 00252 static const unsigned int ITKCommon_EXPORT One; 00253 00254 static unsigned int min(void) { return 0; } 00255 static unsigned int max(void) { return static_cast<unsigned int>( -1 ); } 00256 static unsigned int NonpositiveMin() { return 0; } 00257 static bool IsPositive(unsigned int val) { return val != Zero; } 00258 static bool IsNonpositive(unsigned int val) { return val == Zero; } 00259 static bool IsNegative(unsigned int /*val*/) { return false; } 00260 static bool IsNonnegative(unsigned int /*val*/) {return true; } 00261 }; 00262 00267 template <> 00268 class NumericTraits<long> : public ITK_NUMERIC_LIMITS<long> { 00269 public: 00270 typedef long ValueType; 00271 typedef long PrintType; 00272 typedef unsigned long AbsType; 00273 typedef long AccumulateType; 00274 typedef double RealType; 00275 static const long ITKCommon_EXPORT Zero; 00276 static const long ITKCommon_EXPORT One; 00277 00278 static long NonpositiveMin() { return min(); } 00279 static bool IsPositive(long val) { return val > Zero; } 00280 static bool IsNonpositive(long val) { return val <= Zero; } 00281 static bool IsNegative(long val) { return val < Zero; } 00282 static bool IsNonnegative(long val) {return val >= Zero; } 00283 }; 00284 00289 template <> 00290 class NumericTraits<unsigned long> : public ITK_NUMERIC_LIMITS<unsigned long> { 00291 public: 00292 typedef unsigned long ValueType; 00293 typedef unsigned long PrintType; 00294 typedef unsigned long AbsType; 00295 typedef unsigned long AccumulateType; 00296 typedef double RealType; 00297 static const unsigned long ITKCommon_EXPORT Zero; 00298 static const unsigned long ITKCommon_EXPORT One; 00299 00300 static unsigned long NonpositiveMin() { return min(); } 00301 static bool IsPositive(unsigned long val) { return val != Zero; } 00302 static bool IsNonpositive(unsigned long val) { return val == Zero; } 00303 static bool IsNegative(unsigned long) { return false; } 00304 static bool IsNonnegative(unsigned long) {return true; } 00305 }; 00306 00311 template <> 00312 class NumericTraits<float> : public ITK_NUMERIC_LIMITS<float> { 00313 public: 00314 typedef float ValueType; 00315 typedef float PrintType; 00316 typedef float AbsType; 00317 typedef double AccumulateType; 00318 typedef double RealType; 00319 static const float ITKCommon_EXPORT Zero; 00320 static const float ITKCommon_EXPORT One; 00321 00322 static float NonpositiveMin() { return -max(); } 00323 static bool IsPositive(float val) { return val > Zero; } 00324 static bool IsNonpositive(float val) { return val <= Zero; } 00325 static bool IsNegative(float val) { return val < Zero; } 00326 static bool IsNonnegative(float val) {return val >= Zero; } 00327 }; 00328 00333 template <> 00334 class NumericTraits<double> : public ITK_NUMERIC_LIMITS<double> { 00335 public: 00336 typedef double ValueType; 00337 typedef double PrintType; 00338 typedef double AbsType; 00339 typedef double AccumulateType; 00340 typedef double RealType; 00341 static const double ITKCommon_EXPORT Zero; 00342 static const double ITKCommon_EXPORT One; 00343 00344 static double NonpositiveMin() { return -max(); } 00345 static bool IsPositive(double val) { return val > Zero; } 00346 static bool IsNonpositive(double val) { return val <= Zero; } 00347 static bool IsNegative(double val) { return val < Zero; } 00348 static bool IsNonnegative(double val) {return val >= Zero; } 00349 }; 00350 00355 template <> 00356 class NumericTraits<long double> : public ITK_NUMERIC_LIMITS<long double> { 00357 public: 00358 typedef long double ValueType; 00359 typedef long double PrintType; 00360 typedef long double AbsType; 00361 typedef long double AccumulateType; 00362 typedef long double RealType; 00363 static const long double ITKCommon_EXPORT Zero; 00364 static const long double ITKCommon_EXPORT One; 00365 00366 static long double NonpositiveMin() { return -max(); } 00367 static bool IsPositive(long double val) { return val > Zero; } 00368 static bool IsNonpositive(long double val) { return val <= Zero; } 00369 static bool IsNegative(long double val) { return val < Zero; } 00370 static bool IsNonnegative(long double val) {return val >= Zero; } 00371 }; 00372 00373 } // end namespace itk 00374 00375 #endif // __itkNumericTraits_h

Generated at Sat Mar 31 02:26:38 2007 for ITK by doxygen 1.3.8 written by Dimitri van Heesch, © 1997-2000