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: 2004/12/04 13:20:50 $
00007   Version:   $Revision: 1.40 $
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 #include "vcl_limits.h" // for vcl_numeric_limits
00025 
00026 namespace itk
00027 {
00028 
00039 template <class T>
00040 class NumericTraits : public vcl_numeric_limits<T> {
00041 public:
00043   typedef vcl_numeric_limits<T> TraitsType;
00044 
00046   typedef T ValueType; 
00047 
00049   typedef T PrintType; 
00050 
00052   typedef T AbsType; 
00053 
00055   typedef double AccumulateType; 
00056 
00058   static const T Zero;
00059 
00061   static const T One;
00062 
00064   static T NonpositiveMin() { return TraitsType::min(); }
00065 
00067   static bool IsPositive(T val) { return val > Zero; }
00068 
00070   static bool IsNonpositive(T val) { return val <= Zero; }
00071 
00073   static bool IsNegative(T val) { return val < Zero; }
00074 
00076   static bool IsNonnegative(T val) { return val >= Zero; }
00077 
00080   static T ZeroValue() { return Zero; }
00081 };
00082 
00089 template <>
00090 class NumericTraits<bool> : public vcl_numeric_limits<bool> {
00091 public:
00092   typedef bool ValueType;
00093   typedef bool PrintType;
00094   typedef unsigned char AbsType;
00095   typedef unsigned char AccumulateType;
00096   static const bool ITKCommon_EXPORT Zero;
00097   static const bool ITKCommon_EXPORT One;
00098 
00099   static bool NonpositiveMin() { return false; }
00100   static bool IsPositive(bool val) { return val; }
00101   static bool IsNonpositive(bool val) { return !val; }
00102   static bool IsNegative(bool /* val */) { return false; }
00103   static bool IsNonnegative(bool /*val*/) {return true; }
00104   static bool ZeroValue() { return Zero; }
00105 };
00106 
00111 template <>
00112 class NumericTraits<char> : public vcl_numeric_limits<char> {
00113 public:
00114   typedef char ValueType;
00115   typedef int PrintType;
00116   typedef unsigned char AbsType;
00117   typedef short AccumulateType;
00118   typedef double RealType;
00119   static const char ITKCommon_EXPORT Zero;
00120   static const char ITKCommon_EXPORT One;
00121 
00122   static char min() { return char(255) < 0 ? -128 : 0; }
00123   static char max() { return char(255) < 0 ? 127 : 255; }
00124   static char NonpositiveMin() { return min(); }
00125   static bool IsPositive(char val) { return val > Zero; }
00126   static bool IsNonpositive(char val) { return val <= Zero; }
00127   static bool IsNegative(char val) { return val < Zero; }
00128   static bool IsNonnegative(char val) {return val >= Zero; }
00129   static char ZeroValue() { return Zero; }
00130 };
00131 
00136 template <>
00137 class NumericTraits<signed char> : public vcl_numeric_limits<signed char> {
00138 public:
00139   typedef signed char ValueType;
00140   typedef int PrintType;
00141   typedef unsigned char AbsType;
00142   typedef short AccumulateType;
00143   typedef double RealType;
00144   static const signed char ITKCommon_EXPORT Zero;
00145   static const signed char ITKCommon_EXPORT One;
00146 
00147   static signed char min() { return -128; }
00148   static signed char max() { return  127; }
00149   static signed char NonpositiveMin() { return min(); }
00150   static bool IsPositive(signed char val) { return val > Zero; }
00151   static bool IsNonpositive(signed char val) { return val <= Zero; }
00152   static bool IsNegative(signed char val) { return val < Zero; }
00153   static bool IsNonnegative(signed char val) {return val >= Zero; }
00154   static signed char  ZeroValue() { return Zero; }
00155 };
00156 
00161 template <>
00162 class NumericTraits<unsigned char> : public vcl_numeric_limits<unsigned char> {
00163 public:
00164   typedef unsigned char ValueType;
00165   typedef int PrintType;
00166   typedef unsigned char AbsType;
00167   typedef unsigned short AccumulateType;
00168   typedef double RealType;
00169   static const unsigned char ITKCommon_EXPORT Zero;
00170   static const unsigned char ITKCommon_EXPORT One;
00171 
00172   static unsigned char NonpositiveMin() { return min(); }
00173   static bool IsPositive(unsigned char val) { return val != Zero; }
00174   static bool IsNonpositive(unsigned char val) { return val == Zero; }
00175   static bool IsNegative(unsigned char /* val */) { return false; }
00176   static bool IsNonnegative(unsigned char /*val */) {return true; }
00177   static unsigned char  ZeroValue() { return Zero; }
00178 };
00179 
00183 template <>
00184 class NumericTraits<short> : public vcl_numeric_limits<short> {
00185 public:
00186   typedef short ValueType;
00187   typedef short PrintType;
00188   typedef unsigned short AbsType;
00189   typedef int AccumulateType;
00190   typedef double RealType;
00191   static const short ITKCommon_EXPORT Zero;
00192   static const short ITKCommon_EXPORT One;
00193 
00194   static short NonpositiveMin() { return min(); }
00195   static bool IsPositive(short val) { return val > Zero; }
00196   static bool IsNonpositive(short val) { return val <= Zero; }
00197   static bool IsNegative(short val) { return val < Zero; }
00198   static bool IsNonnegative(short val) {return val >= Zero; }
00199   static short  ZeroValue() { return Zero; }
00200 };
00201 
00206 template <>
00207 class NumericTraits<unsigned short> : public vcl_numeric_limits<unsigned short> {
00208 public:
00209   typedef unsigned short ValueType;
00210   typedef unsigned short PrintType;
00211   typedef unsigned short AbsType;
00212   typedef unsigned int AccumulateType;
00213   typedef double RealType;
00214   static const unsigned short ITKCommon_EXPORT Zero;
00215   static const unsigned short ITKCommon_EXPORT One;
00216 
00217   static unsigned short NonpositiveMin() { return min(); }
00218   static unsigned short IsPositive(unsigned short val) { return val != Zero; }
00219   static bool IsNonpositive(unsigned short val) { return val == Zero; }
00220   static bool IsNegative(unsigned short/* val*/) { return false; }
00221   static bool IsNonnegative(unsigned short /*val*/) {return true; }
00222   static unsigned short  ZeroValue() { return Zero; }
00223 };
00224 
00228 template <>
00229 class NumericTraits<int> : public vcl_numeric_limits<int> {
00230 public:
00231   typedef int ValueType;
00232   typedef int PrintType;
00233   typedef unsigned int AbsType;
00234   typedef long AccumulateType;
00235   typedef double RealType;
00236   static const int ITKCommon_EXPORT Zero;
00237   static const int ITKCommon_EXPORT One;
00238 
00239   static int NonpositiveMin() { return min(); }
00240   static bool IsPositive(int val) { return val > Zero; }
00241   static bool IsNonpositive(int val) { return val <= Zero; }
00242   static bool IsNegative(int val) { return val < Zero; }
00243   static bool IsNonnegative(int val) {return val >= Zero; }
00244   static int  ZeroValue() { return Zero; }
00245 };
00246 
00251 template <>
00252 class NumericTraits<unsigned int> : public vcl_numeric_limits<unsigned int> {
00253 public:
00254   typedef unsigned int ValueType;
00255   typedef unsigned int PrintType;
00256   typedef unsigned int AbsType;
00257   typedef unsigned int AccumulateType;
00258   typedef double RealType;
00259   static const unsigned int ITKCommon_EXPORT Zero;
00260   static const unsigned int ITKCommon_EXPORT One;
00261 
00262   static unsigned int min(void) { return 0; }
00263   static unsigned int max(void) { return static_cast<unsigned int>( -1 ); }
00264   static unsigned int NonpositiveMin() { return 0; }
00265   static bool IsPositive(unsigned int val) { return val != Zero; }
00266   static bool IsNonpositive(unsigned int val) { return  val == Zero; }
00267   static bool IsNegative(unsigned int /*val*/) { return false; }
00268   static bool IsNonnegative(unsigned int /*val*/) {return true; }
00269   static unsigned int  ZeroValue() { return Zero; }
00270 };
00271 
00276 template <>
00277 class NumericTraits<long> : public vcl_numeric_limits<long> {
00278 public:
00279   typedef long ValueType;
00280   typedef long PrintType;
00281   typedef unsigned long AbsType;
00282   typedef long AccumulateType;
00283   typedef double RealType;
00284   static const long ITKCommon_EXPORT Zero;
00285   static const long ITKCommon_EXPORT One;
00286 
00287   static long NonpositiveMin() { return min(); }
00288   static bool IsPositive(long val) { return val > Zero; }
00289   static bool IsNonpositive(long val) { return val <= Zero; }
00290   static bool IsNegative(long val) { return val < Zero; }
00291   static bool IsNonnegative(long val) {return val >= Zero; }
00292   static long  ZeroValue() { return Zero; }
00293 };
00294 
00299 template <>
00300 class NumericTraits<unsigned long> : public vcl_numeric_limits<unsigned long> {
00301 public:
00302   typedef unsigned long ValueType;
00303   typedef unsigned long PrintType;
00304   typedef unsigned long AbsType;
00305   typedef unsigned long AccumulateType;
00306   typedef double RealType;
00307   static const unsigned long ITKCommon_EXPORT Zero;
00308   static const unsigned long ITKCommon_EXPORT One;
00309 
00310   static unsigned long NonpositiveMin() { return min(); }
00311   static bool IsPositive(unsigned long val) { return val != Zero; }
00312   static bool IsNonpositive(unsigned long val) { return val == Zero; }
00313   static bool IsNegative(unsigned long) { return false; }
00314   static bool IsNonnegative(unsigned long) {return true; }
00315   static unsigned long  ZeroValue() { return Zero; }
00316 };
00317 
00322 template <>
00323 class NumericTraits<float> : public vcl_numeric_limits<float> {
00324 public:
00325   typedef float ValueType;
00326   typedef float PrintType;
00327   typedef float AbsType;
00328   typedef double AccumulateType;
00329   typedef double RealType;
00330   static const float ITKCommon_EXPORT Zero;
00331   static const float ITKCommon_EXPORT One;
00332 
00333   static float NonpositiveMin() { return -max(); }
00334   static bool IsPositive(float val) { return val > Zero; }
00335   static bool IsNonpositive(float val) { return val <= Zero; }
00336   static bool IsNegative(float val) { return val < Zero; }
00337   static bool IsNonnegative(float val) {return val >= Zero; }
00338   static float  ZeroValue() { return Zero; }
00339 };
00340 
00345 template <>
00346 class NumericTraits<double> : public vcl_numeric_limits<double> {
00347 public:
00348   typedef double ValueType;
00349   typedef double PrintType;
00350   typedef double AbsType;
00351   typedef double AccumulateType;
00352   typedef double RealType;
00353   static const double ITKCommon_EXPORT Zero;
00354   static const double ITKCommon_EXPORT One;
00355 
00356   static double NonpositiveMin() { return -max(); }
00357   static bool IsPositive(double val) { return val > Zero; }
00358   static bool IsNonpositive(double val) { return val <= Zero; }
00359   static bool IsNegative(double val) { return val < Zero; }
00360   static bool IsNonnegative(double val) {return val >= Zero; }
00361   static double  ZeroValue() { return Zero; }
00362 };
00363 
00368 template <>
00369 class NumericTraits<long double> : public vcl_numeric_limits<long double> {
00370 public:
00371   typedef long double ValueType;
00372   typedef long double PrintType;
00373   typedef long double AbsType;
00374   typedef long double AccumulateType;
00375   typedef long double RealType;
00376   static const long double ITKCommon_EXPORT Zero;
00377   static const long double ITKCommon_EXPORT One;
00378 
00379   static long double NonpositiveMin() { return -max(); }
00380   static bool IsPositive(long double val) { return val > Zero; }
00381   static bool IsNonpositive(long double val) { return val <= Zero; }
00382   static bool IsNegative(long double val) { return val < Zero; }
00383   static bool IsNonnegative(long double val) {return val >= Zero; }
00384   static long double ZeroValue() { return Zero; }
00385 };
00386 
00387 
00388 } // end namespace itk
00389 
00390 #endif // __itkNumericTraits_h

Generated at Wed Mar 30 00:06:21 2005 for ITK by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2000