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: 2002/09/16 16:44:17 $
00007   Version:   $Revision: 1.27 $
00008 
00009   Copyright (c) 2002 Insight 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 
00087 template <>
00088 class NumericTraits<bool> : public ITK_NUMERIC_LIMITS<bool> {
00089 public:
00090   typedef bool ValueType;
00091   typedef bool PrintType;
00092   typedef unsigned char AbsType;
00093   typedef unsigned char AccumulateType;
00094   static const bool Zero;
00095   static const bool One;
00096 
00097   static bool NonpositiveMin() { return false; }
00098   static bool IsPositive(bool val) { return val; }
00099   static bool IsNonpositive(bool val) { return !val; }
00100   static bool IsNegative(bool val) { return false; }
00101   static bool IsNonnegative(bool val) {return true; }
00102 };
00103 
00107 template <>
00108 class NumericTraits<char> : public ITK_NUMERIC_LIMITS<char> {
00109 public:
00110   typedef char ValueType;
00111   typedef int PrintType;
00112   typedef unsigned char AbsType;
00113   typedef short AccumulateType;
00114   typedef double RealType;
00115   static const char Zero;
00116   static const char One;
00117 
00118   static char min() { return 0; }
00119   static char max() { return 127; }
00120   static char NonpositiveMin() { return -128; }
00121   static bool IsPositive(char val) { return val > Zero; }
00122   static bool IsNonpositive(char val) { return val <= Zero; }
00123   static bool IsNegative(char val) { return val < Zero; }
00124   static bool IsNonnegative(char val) {return val >= Zero; }
00125 };
00126 
00131 template <>
00132 class NumericTraits<unsigned char> : public ITK_NUMERIC_LIMITS<unsigned char> {
00133 public:
00134   typedef unsigned char ValueType;
00135   typedef int PrintType;
00136   typedef unsigned char AbsType;
00137   typedef unsigned short AccumulateType;
00138   typedef double RealType;
00139   static const unsigned char Zero;
00140   static const unsigned char One;
00141 
00142   static unsigned char NonpositiveMin() { return min(); }
00143   static bool IsPositive(unsigned char val) { return val != Zero; }
00144   static bool IsNonpositive(unsigned char val) { return val == Zero; }
00145   static bool IsNegative(unsigned char val) { return false; }
00146   static bool IsNonnegative(unsigned char val) {return true; }
00147 };
00148 
00152 template <>
00153 class NumericTraits<short> : public ITK_NUMERIC_LIMITS<short> {
00154 public:
00155   typedef short ValueType;
00156   typedef short PrintType;
00157   typedef unsigned short AbsType;
00158   typedef int AccumulateType;
00159   typedef double RealType;
00160   static const short Zero;
00161   static const short One;
00162 
00163   static short NonpositiveMin() { return min(); }
00164   static bool IsPositive(short val) { return val > Zero; }
00165   static bool IsNonpositive(short val) { return val <= Zero; }
00166   static bool IsNegative(short val) { return val < Zero; }
00167   static bool IsNonnegative(short val) {return val >= Zero; }
00168 };
00169 
00174 template <>
00175 class NumericTraits<unsigned short> : public ITK_NUMERIC_LIMITS<unsigned short> {
00176 public:
00177   typedef unsigned short ValueType;
00178   typedef unsigned short PrintType;
00179   typedef unsigned short AbsType;
00180   typedef unsigned int AccumulateType;
00181   typedef double RealType;
00182   static const unsigned short Zero;
00183   static const unsigned short One;
00184 
00185   static unsigned short NonpositiveMin() { return min(); }
00186   static unsigned short IsPositive(unsigned short val) { return val != Zero; }
00187   static bool IsNonpositive(unsigned short val) { return val == Zero; }
00188   static bool IsNegative(unsigned short val) { return false; }
00189   static bool IsNonnegative(unsigned short val) {return true; }
00190 };
00191 
00195 template <>
00196 class NumericTraits<int> : public ITK_NUMERIC_LIMITS<int> {
00197 public:
00198   typedef int ValueType;
00199   typedef int PrintType;
00200   typedef unsigned int AbsType;
00201   typedef long AccumulateType;
00202   typedef double RealType;
00203   static const int Zero;
00204   static const int One;
00205 
00206   static int NonpositiveMin() { return min(); }
00207   static bool IsPositive(int val) { return val > Zero; }
00208   static bool IsNonpositive(int val) { return val <= Zero; }
00209   static bool IsNegative(int val) { return val < Zero; }
00210   static bool IsNonnegative(int val) {return val >= Zero; }
00211 };
00212 
00217 template <>
00218 class NumericTraits<unsigned int> : public ITK_NUMERIC_LIMITS<unsigned int> {
00219 public:
00220   typedef unsigned int ValueType;
00221   typedef unsigned int PrintType;
00222   typedef unsigned int AbsType;
00223   typedef unsigned int AccumulateType;
00224   typedef double RealType;
00225   static const unsigned int Zero;
00226   static const unsigned int One;
00227 
00228   static unsigned int max(void) { return static_cast<unsigned int>( -1 ); }
00229   static unsigned int NonpositiveMin() { return 0; }
00230   static bool IsPositive(unsigned int val) { return val != Zero; }
00231   static bool IsNonpositive(unsigned int val) { return  val == Zero; }
00232   static bool IsNegative(unsigned int val) { return false; }
00233   static bool IsNonnegative(unsigned int val) {return true; }
00234 };
00235 
00240 template <>
00241 class NumericTraits<long> : public ITK_NUMERIC_LIMITS<long> {
00242 public:
00243   typedef long ValueType;
00244   typedef long PrintType;
00245   typedef unsigned long AbsType;
00246   typedef long AccumulateType;
00247   typedef double RealType;
00248   static const long Zero;
00249   static const long One;
00250 
00251   static long NonpositiveMin() { return min(); }
00252   static bool IsPositive(long val) { return val > Zero; }
00253   static bool IsNonpositive(long val) { return val <= Zero; }
00254   static bool IsNegative(long val) { return val < Zero; }
00255   static bool IsNonnegative(long val) {return val >= Zero; }
00256 };
00257 
00262 template <>
00263 class NumericTraits<unsigned long> : public ITK_NUMERIC_LIMITS<unsigned long> {
00264 public:
00265   typedef unsigned long ValueType;
00266   typedef unsigned long PrintType;
00267   typedef unsigned long AbsType;
00268   typedef unsigned long AccumulateType;
00269   typedef double RealType;
00270   static const unsigned long Zero;
00271   static const unsigned long One;
00272 
00273   static unsigned long NonpositiveMin() { return min(); }
00274   static bool IsPositive(unsigned long val) { return val != Zero; }
00275   static bool IsNonpositive(unsigned long val) { return val == Zero; }
00276   static bool IsNegative(unsigned long val) { return false; }
00277   static bool IsNonnegative(unsigned long val) {return true; }
00278 };
00279 
00284 template <>
00285 class NumericTraits<float> : public ITK_NUMERIC_LIMITS<float> {
00286 public:
00287   typedef float ValueType;
00288   typedef float PrintType;
00289   typedef float AbsType;
00290   typedef double AccumulateType;
00291   typedef double RealType;
00292   static const float Zero;
00293   static const float One;
00294 
00295   static float NonpositiveMin() { return -max(); }
00296   static bool IsPositive(float val) { return val > Zero; }
00297   static bool IsNonpositive(float val) { return val <= Zero; }
00298   static bool IsNegative(float val) { return val < Zero; }
00299   static bool IsNonnegative(float val) {return val >= Zero; }
00300 };
00301 
00306 template <>
00307 class NumericTraits<double> : public ITK_NUMERIC_LIMITS<double> {
00308 public:
00309   typedef double ValueType;
00310   typedef double PrintType;
00311   typedef double AbsType;
00312   typedef double AccumulateType;
00313   typedef double RealType;
00314   static const double Zero;
00315   static const double One;
00316 
00317   static double NonpositiveMin() { return -max(); }
00318   static bool IsPositive(double val) { return val > Zero; }
00319   static bool IsNonpositive(double val) { return val <= Zero; }
00320   static bool IsNegative(double val) { return val < Zero; }
00321   static bool IsNonnegative(double val) {return val >= Zero; }
00322 };
00323 
00328 template <>
00329 class NumericTraits<long double> : public ITK_NUMERIC_LIMITS<long double> {
00330 public:
00331   typedef long double ValueType;
00332   typedef long double PrintType;
00333   typedef long double AbsType;
00334   typedef long double AccumulateType;
00335   typedef long double RealType;
00336   static const long double Zero;
00337   static const long double One;
00338 
00339   static long double NonpositiveMin() { return -max(); }
00340   static bool IsPositive(long double val) { return val > Zero; }
00341   static bool IsNonpositive(long double val) { return val <= Zero; }
00342   static bool IsNegative(long double val) { return val < Zero; }
00343   static bool IsNonnegative(long double val) {return val >= Zero; }
00344 };
00345 
00346 } // end namespace itk
00347 
00348 #endif // __itkNumericTraits_h

Generated at Wed Mar 12 01:13:08 2003 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000