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/03/11 15:20:34 $
00007   Version:   $Revision: 1.28.2.1 $
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 -128; }
00119   static char max() { return 127; }
00120   static char NonpositiveMin() { return min(); }
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 min(void) { return 0; }
00229   static unsigned int max(void) { return static_cast<unsigned int>( -1 ); }
00230   static unsigned int NonpositiveMin() { return 0; }
00231   static bool IsPositive(unsigned int val) { return val != Zero; }
00232   static bool IsNonpositive(unsigned int val) { return  val == Zero; }
00233   static bool IsNegative(unsigned int val) { return false; }
00234   static bool IsNonnegative(unsigned int val) {return true; }
00235 };
00236 
00241 template <>
00242 class NumericTraits<long> : public ITK_NUMERIC_LIMITS<long> {
00243 public:
00244   typedef long ValueType;
00245   typedef long PrintType;
00246   typedef unsigned long AbsType;
00247   typedef long AccumulateType;
00248   typedef double RealType;
00249   static const long Zero;
00250   static const long One;
00251 
00252   static long NonpositiveMin() { return min(); }
00253   static bool IsPositive(long val) { return val > Zero; }
00254   static bool IsNonpositive(long val) { return val <= Zero; }
00255   static bool IsNegative(long val) { return val < Zero; }
00256   static bool IsNonnegative(long val) {return val >= Zero; }
00257 };
00258 
00263 template <>
00264 class NumericTraits<unsigned long> : public ITK_NUMERIC_LIMITS<unsigned long> {
00265 public:
00266   typedef unsigned long ValueType;
00267   typedef unsigned long PrintType;
00268   typedef unsigned long AbsType;
00269   typedef unsigned long AccumulateType;
00270   typedef double RealType;
00271   static const unsigned long Zero;
00272   static const unsigned long One;
00273 
00274   static unsigned long NonpositiveMin() { return min(); }
00275   static bool IsPositive(unsigned long val) { return val != Zero; }
00276   static bool IsNonpositive(unsigned long val) { return val == Zero; }
00277   static bool IsNegative(unsigned long) { return false; }
00278   static bool IsNonnegative(unsigned long) {return true; }
00279 };
00280 
00285 template <>
00286 class NumericTraits<float> : public ITK_NUMERIC_LIMITS<float> {
00287 public:
00288   typedef float ValueType;
00289   typedef float PrintType;
00290   typedef float AbsType;
00291   typedef double AccumulateType;
00292   typedef double RealType;
00293   static const float Zero;
00294   static const float One;
00295 
00296   static float NonpositiveMin() { return -max(); }
00297   static bool IsPositive(float val) { return val > Zero; }
00298   static bool IsNonpositive(float val) { return val <= Zero; }
00299   static bool IsNegative(float val) { return val < Zero; }
00300   static bool IsNonnegative(float val) {return val >= Zero; }
00301 };
00302 
00307 template <>
00308 class NumericTraits<double> : public ITK_NUMERIC_LIMITS<double> {
00309 public:
00310   typedef double ValueType;
00311   typedef double PrintType;
00312   typedef double AbsType;
00313   typedef double AccumulateType;
00314   typedef double RealType;
00315   static const double Zero;
00316   static const double One;
00317 
00318   static double NonpositiveMin() { return -max(); }
00319   static bool IsPositive(double val) { return val > Zero; }
00320   static bool IsNonpositive(double val) { return val <= Zero; }
00321   static bool IsNegative(double val) { return val < Zero; }
00322   static bool IsNonnegative(double val) {return val >= Zero; }
00323 };
00324 
00329 template <>
00330 class NumericTraits<long double> : public ITK_NUMERIC_LIMITS<long double> {
00331 public:
00332   typedef long double ValueType;
00333   typedef long double PrintType;
00334   typedef long double AbsType;
00335   typedef long double AccumulateType;
00336   typedef long double RealType;
00337   static const long double Zero;
00338   static const long double One;
00339 
00340   static long double NonpositiveMin() { return -max(); }
00341   static bool IsPositive(long double val) { return val > Zero; }
00342   static bool IsNonpositive(long double val) { return val <= Zero; }
00343   static bool IsNegative(long double val) { return val < Zero; }
00344   static bool IsNonnegative(long double val) {return val >= Zero; }
00345 };
00346 
00347 } // end namespace itk
00348 
00349 #endif // __itkNumericTraits_h

Generated at Fri May 21 01:15:09 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000