ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkNumericTraits.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkNumericTraits_h
00019 #define __itkNumericTraits_h
00020 
00021 #include "itkMacro.h"
00022 
00023 #undef min
00024 #undef max
00025 
00026 #define itkNUMERIC_TRAITS_MIN_MAX_MACRO()          \
00027   static ValueType min()                           \
00028     {                                              \
00029     return vcl_numeric_limits< ValueType >::min(); \
00030     }                                              \
00031   static ValueType max()                           \
00032     {                                              \
00033     return vcl_numeric_limits< ValueType >::max(); \
00034     }                                              \
00035   static ValueType min(ValueType)                  \
00036     {                                              \
00037     return vcl_numeric_limits< ValueType >::min(); \
00038     }                                              \
00039   static ValueType max(ValueType)                  \
00040     {                                              \
00041     return vcl_numeric_limits< ValueType >::max(); \
00042     }                                              \
00043 
00044 
00045 #include "vcl_limits.h" // for vcl_numeric_limits
00046 #include <complex>
00047 
00048 namespace itk
00049 {
00050 
00051 // forward decare to avoid circular dependencies
00052 template< typename TValueType, unsigned int VLength>  class FixedArray;
00053 
00069 template< class T >
00070 class NumericTraits:public vcl_numeric_limits< T >
00071 {
00072 public:
00074   typedef vcl_numeric_limits< T > TraitsType;
00075 
00077   typedef T ValueType;
00078 
00080   typedef T PrintType;
00081 
00083   typedef T AbsType;
00084 
00086   typedef double AccumulateType;
00087 
00089   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00090 
00093   typedef float FloatType;
00094 
00096   typedef double RealType;
00097 
00099   typedef RealType ScalarRealType;
00100 
00102   static const T Zero;
00103 
00105   static const T One;
00106 
00108   static T NonpositiveMin() { return TraitsType::min(); }
00109 
00111   static bool IsPositive(T val) { return val > Zero; }
00112 
00114   static bool IsNonpositive(T val) { return val <= Zero; }
00115 
00117   static bool IsNegative(T val) { return val < Zero; }
00118 
00120   static bool IsNonnegative(T val) { return val >= Zero; }
00121 
00124   static T ZeroValue() { return Zero; }
00125 
00128   static T OneValue() { return One; }
00129 
00130   /* Provide a default implementation of the max() method with
00131    * argument. This API is needed for VariableLengthVector because
00132    * its length is only known at run-time. Specializations of the
00133    * VariableLengthVector will provide a different implementation
00134    * where a vector of the correct size is built. */
00135   static T max(const T &) { return TraitsType::max(); }
00136   static T min(const T &) { return TraitsType::min(); }
00137 
00145   static void SetLength(T &, const unsigned int s)
00146   {
00147     if ( s != 1 )
00148       {
00149       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00150       }
00151   }
00152 
00159   static unsigned int GetLength(const T &)
00160   {
00161     return GetLength();
00162   }
00163 
00165   static unsigned int GetLength()
00166   {
00167     return 1;
00168   }
00169 
00173   static T NonpositiveMin(const T &)
00174   {
00175     return NonpositiveMin();
00176   }
00177 
00181   static T ZeroValue(const T &)
00182   {
00183     return ZeroValue();
00184   }
00185 
00189   static T OneValue(const T &)
00190   {
00191     return OneValue();
00192   }
00193 
00195   template<class TArray>
00196   static void AssignToArray( const T & v, TArray & mv )
00197   {
00198     mv[0] = v;
00199   }
00200 
00201 };
00202 
00212 template< >
00213 class NumericTraits< bool > :public vcl_numeric_limits< bool >
00214 {
00215 public:
00216   typedef bool                     ValueType;
00217   typedef bool                     PrintType;
00218   typedef unsigned char            AbsType;
00219   typedef unsigned char            AccumulateType;
00220   typedef double                   RealType;
00221   typedef RealType                 ScalarRealType;
00222   typedef float                    FloatType;
00223   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00224 
00225   static const bool ITKCommon_EXPORT Zero;
00226   static const bool ITKCommon_EXPORT One;
00227 
00228   static bool min() { return false; }
00229   static bool max() { return true; }
00230   static bool min(bool) { return min(); }
00231   static bool max(bool) { return max(); }
00232   static bool NonpositiveMin() { return false; }
00233   static bool IsPositive(bool val) { return val; }
00234   static bool IsNonpositive(bool val) { return !val; }
00235   static bool IsNegative(bool val) { return val ? false : false; }
00236   static bool IsNonnegative(bool val) { return val ? true : true; }
00237   static bool ZeroValue() { return Zero; }
00238   static bool OneValue() { return One; }
00239   static unsigned int GetLength(const ValueType &) { return 1; }
00240   static unsigned int GetLength() { return 1; }
00241   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00242   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00243   static ValueType OneValue(const ValueType &) { return OneValue(); }
00244 
00245   template<class TArray>
00246   static void AssignToArray( const ValueType & v, TArray & mv )
00247   {
00248     mv[0] = v;
00249   }
00250   static void SetLength(ValueType &, const unsigned int s)
00251   {
00252     if ( s != 1 )
00253       {
00254       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00255       }
00256   }
00257 
00258 };
00259 
00265 template< >
00266 class NumericTraits< char > :public vcl_numeric_limits< char >
00267 {
00268 public:
00269   typedef char                     ValueType;
00270   typedef int                      PrintType;
00271   typedef unsigned char            AbsType;
00272   typedef short                    AccumulateType;
00273   typedef double                   RealType;
00274   typedef RealType                 ScalarRealType;
00275   typedef float                    FloatType;
00276   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00277 
00278   static const char ITKCommon_EXPORT Zero;
00279   static const char ITKCommon_EXPORT One;
00280 
00281   static char min() { return char(255) < 0 ? -128 : 0; }
00282   static char max() { return char(255) < 0 ? 127 : 255; }
00283 
00284   static char min(char) { return min(); }
00285   static char max(char) { return max(); }
00286   static char NonpositiveMin() { return min(); }
00287   static bool IsPositive(char val) { return val > Zero; }
00288   static bool IsNonpositive(char val) { return val <= Zero; }
00289   static bool IsNegative(char val) { return val < Zero; }
00290   static bool IsNonnegative(char val) { return val >= Zero; }
00291   static char ZeroValue() { return Zero; }
00292   static char OneValue() { return One; }
00293   static unsigned int GetLength(const ValueType &) { return 1; }
00294   static unsigned int GetLength() { return 1; }
00295   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00296   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00297   static ValueType OneValue(const ValueType &) { return OneValue(); }
00298 
00299   template<class TArray>
00300   static void AssignToArray( const ValueType & v, TArray & mv )
00301   {
00302     mv[0] = v;
00303   }
00304   static void SetLength(ValueType &, const unsigned int s)
00305   {
00306     if ( s != 1 )
00307       {
00308       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00309       }
00310   }
00311 };
00312 
00318 template< >
00319 class NumericTraits< signed char > :public vcl_numeric_limits< signed char >
00320 {
00321 public:
00322   typedef signed char              ValueType;
00323   typedef int                      PrintType;
00324   typedef unsigned char            AbsType;
00325   typedef short                    AccumulateType;
00326   typedef double                   RealType;
00327   typedef RealType                 ScalarRealType;
00328   typedef float                    FloatType;
00329   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00330 
00331   static const signed char ITKCommon_EXPORT Zero;
00332   static const signed char ITKCommon_EXPORT One;
00333 
00334   static signed char min() { return -128; }
00335   static signed char max() { return 127; }
00336   static signed char min(signed char) { return min(); }
00337   static signed char max(signed char) { return max(); }
00338   static signed char NonpositiveMin() { return min(); }
00339   static bool IsPositive(signed char val) { return val > Zero; }
00340   static bool IsNonpositive(signed char val) { return val <= Zero; }
00341   static bool IsNegative(signed char val) { return val < Zero; }
00342   static bool IsNonnegative(signed char val) { return val >= Zero; }
00343   static signed char  ZeroValue() { return Zero; }
00344   static signed char OneValue() { return One; }
00345   static unsigned int GetLength(const ValueType &) { return 1; }
00346   static unsigned int GetLength() { return 1; }
00347   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00348   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00349   static ValueType OneValue(const ValueType &) { return OneValue(); }
00350 
00351   template<class TArray>
00352   static void AssignToArray( const ValueType & v, TArray & mv )
00353   {
00354     mv[0] = v;
00355   }
00356   static void SetLength(ValueType &, const unsigned int s)
00357   {
00358     if ( s != 1 )
00359       {
00360       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00361       }
00362   }
00363 };
00364 
00370 template< >
00371 class NumericTraits< unsigned char > :public vcl_numeric_limits< unsigned char >
00372 {
00373 public:
00374   typedef unsigned char            ValueType;
00375   typedef int                      PrintType;
00376   typedef unsigned char            AbsType;
00377   typedef unsigned short           AccumulateType;
00378   typedef double                   RealType;
00379   typedef RealType                 ScalarRealType;
00380   typedef float                    FloatType;
00381   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00382 
00383   static const unsigned char ITKCommon_EXPORT Zero;
00384   static const unsigned char ITKCommon_EXPORT One;
00385 
00386   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00387 
00388   static unsigned char NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
00389   static bool IsPositive(unsigned char val) { return val != Zero; }
00390   static bool IsNonpositive(unsigned char val) { return val == Zero; }
00391   static bool IsNegative(unsigned char val) { return val ? false : false; }
00392   static bool IsNonnegative(unsigned char val) { return val ? true : true; }
00393   static unsigned char  ZeroValue() { return Zero; }
00394   static unsigned char OneValue() { return One; }
00395   static unsigned int GetLength(const ValueType &) { return 1; }
00396   static unsigned int GetLength() { return 1; }
00397   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00398   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00399   static ValueType OneValue(const ValueType &) { return OneValue(); }
00400 
00401   template<class TArray>
00402   static void AssignToArray( const ValueType & v, TArray & mv )
00403   {
00404     mv[0] = v;
00405   }
00406   static void SetLength(ValueType &, const unsigned int s)
00407   {
00408     if ( s != 1 )
00409       {
00410       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00411       }
00412   }
00413 };
00414 
00419 template< >
00420 class NumericTraits< short > :public vcl_numeric_limits< short >
00421 {
00422 public:
00423   typedef short                    ValueType;
00424   typedef short                    PrintType;
00425   typedef unsigned short           AbsType;
00426   typedef int                      AccumulateType;
00427   typedef double                   RealType;
00428   typedef RealType                 ScalarRealType;
00429   typedef float                    FloatType;
00430   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00431 
00432   static const short ITKCommon_EXPORT Zero;
00433   static const short ITKCommon_EXPORT One;
00434 
00435   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00436   static short NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
00437   static bool IsPositive(short val) { return val > Zero; }
00438   static bool IsNonpositive(short val) { return val <= Zero; }
00439   static bool IsNegative(short val) { return val < Zero; }
00440   static bool IsNonnegative(short val) { return val >= Zero; }
00441   static short  ZeroValue() { return Zero; }
00442   static short OneValue() { return One; }
00443   static unsigned int GetLength(const ValueType &) { return 1; }
00444   static unsigned int GetLength() { return 1; }
00445   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00446   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00447   static ValueType OneValue(const ValueType &) { return OneValue(); }
00448 
00449   template<class TArray>
00450   static void AssignToArray( const ValueType & v, TArray & mv )
00451   {
00452     mv[0] = v;
00453   }
00454   static void SetLength(ValueType &, const unsigned int s)
00455   {
00456     if ( s != 1 )
00457       {
00458       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00459       }
00460   }
00461 };
00462 
00468 template< >
00469 class NumericTraits< unsigned short > :public vcl_numeric_limits< unsigned short >
00470 {
00471 public:
00472   typedef unsigned short           ValueType;
00473   typedef unsigned short           PrintType;
00474   typedef unsigned short           AbsType;
00475   typedef unsigned int             AccumulateType;
00476   typedef double                   RealType;
00477   typedef RealType                 ScalarRealType;
00478   typedef float                    FloatType;
00479   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00480 
00481   static const unsigned short ITKCommon_EXPORT Zero;
00482   static const unsigned short ITKCommon_EXPORT One;
00483 
00484   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00485   static unsigned short NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
00486   static bool IsPositive(unsigned short val) { return val != Zero; }
00487   static bool IsNonpositive(unsigned short val) { return val == Zero; }
00488   static bool IsNegative(unsigned short val) { return val ? false : false; }
00489   static bool IsNonnegative(unsigned short val) { return val ? true : true; }
00490   static unsigned short ZeroValue() { return Zero; }
00491   static unsigned short OneValue() { return One; }
00492   static unsigned int GetLength(const ValueType &) { return 1; }
00493   static unsigned int GetLength() { return 1; }
00494   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00495   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00496   static ValueType OneValue(const ValueType &) { return OneValue(); }
00497 
00498   template<class TArray>
00499   static void AssignToArray( const ValueType & v, TArray & mv )
00500   {
00501     mv[0] = v;
00502   }
00503   static void SetLength(ValueType &, const unsigned int s)
00504   {
00505     if ( s != 1 )
00506       {
00507       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00508       }
00509   }
00510 };
00511 
00516 template< >
00517 class NumericTraits< int > :public vcl_numeric_limits< int >
00518 {
00519 public:
00520   typedef int                      ValueType;
00521   typedef int                      PrintType;
00522   typedef unsigned int             AbsType;
00523   typedef long                     AccumulateType;
00524   typedef double                   RealType;
00525   typedef RealType                 ScalarRealType;
00526   typedef float                    FloatType;
00527   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00528 
00529   static const int ITKCommon_EXPORT Zero;
00530   static const int ITKCommon_EXPORT One;
00531 
00532   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00533   static int NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
00534   static bool IsPositive(int val) { return val > Zero; }
00535   static bool IsNonpositive(int val) { return val <= Zero; }
00536   static bool IsNegative(int val) { return val < Zero; }
00537   static bool IsNonnegative(int val) { return val >= Zero; }
00538   static int  ZeroValue() { return Zero; }
00539   static int OneValue() { return One; }
00540   static unsigned int GetLength(const ValueType &) { return 1; }
00541   static unsigned int GetLength() { return 1; }
00542   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00543   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00544   static ValueType OneValue(const ValueType &) { return OneValue(); }
00545 
00546   template<class TArray>
00547   static void AssignToArray( const ValueType & v, TArray & mv )
00548   {
00549     mv[0] = v;
00550   }
00551   static void SetLength(ValueType &, const unsigned int s)
00552   {
00553     if ( s != 1 )
00554       {
00555       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00556       }
00557   }
00558 };
00559 
00565 template< >
00566 class NumericTraits< unsigned int > :public vcl_numeric_limits< unsigned int >
00567 {
00568 public:
00569   typedef unsigned int             ValueType;
00570   typedef unsigned int             PrintType;
00571   typedef unsigned int             AbsType;
00572   typedef unsigned int             AccumulateType;
00573   typedef double                   RealType;
00574   typedef RealType                 ScalarRealType;
00575   typedef float                    FloatType;
00576   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00577 
00578   static const unsigned int ITKCommon_EXPORT Zero;
00579   static const unsigned int ITKCommon_EXPORT One;
00580 
00581   static unsigned int min(void) { return 0; }
00582   static unsigned int max(void) { return static_cast< unsigned int >( -1 ); }
00583   static unsigned int min(unsigned int) { return vcl_numeric_limits< ValueType >::min(); }
00584   static unsigned int max(unsigned int) { return vcl_numeric_limits< ValueType >::max(); }
00585   static unsigned int NonpositiveMin() { return 0; }
00586   static bool IsPositive(unsigned int val) { return val != Zero; }
00587   static bool IsNonpositive(unsigned int val) { return val == Zero; }
00588   static bool IsNegative(unsigned int val) { return val ? false : false; }
00589   static bool IsNonnegative(unsigned int val) { return val ? true : true; }
00590   static unsigned int  ZeroValue() { return Zero; }
00591   static unsigned int OneValue() { return One; }
00592   static unsigned int GetLength(const ValueType &) { return 1; }
00593   static unsigned int GetLength() { return 1; }
00594   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00595   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00596   static ValueType OneValue(const ValueType &) { return OneValue(); }
00597 
00598   template<class TArray>
00599   static void AssignToArray( const ValueType & v, TArray & mv )
00600   {
00601     mv[0] = v;
00602   }
00603   static void SetLength(ValueType &, const unsigned int s)
00604   {
00605     if ( s != 1 )
00606       {
00607       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00608       }
00609   }
00610 };
00611 
00617 template< >
00618 class NumericTraits< long > :public vcl_numeric_limits< long >
00619 {
00620 public:
00621   typedef long                     ValueType;
00622   typedef long                     PrintType;
00623   typedef unsigned long            AbsType;
00624   typedef long                     AccumulateType;
00625   typedef double                   RealType;
00626   typedef RealType                 ScalarRealType;
00627   typedef float                    FloatType;
00628   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00629 
00630   static const long ITKCommon_EXPORT Zero;
00631   static const long ITKCommon_EXPORT One;
00632 
00633   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00634   static long NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
00635   static bool IsPositive(long val) { return val > Zero; }
00636   static bool IsNonpositive(long val) { return val <= Zero; }
00637   static bool IsNegative(long val) { return val < Zero; }
00638   static bool IsNonnegative(long val) { return val >= Zero; }
00639   static long  ZeroValue() { return Zero; }
00640   static long OneValue() { return One; }
00641   static unsigned int GetLength(const ValueType &) { return 1; }
00642   static unsigned int GetLength() { return 1; }
00643   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00644   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00645   static ValueType OneValue(const ValueType &) { return OneValue(); }
00646 
00647   template<class TArray>
00648   static void AssignToArray( const ValueType & v, TArray & mv )
00649   {
00650     mv[0] = v;
00651   }
00652   static void SetLength(ValueType &, const unsigned int s)
00653   {
00654     if ( s != 1 )
00655       {
00656       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00657       }
00658   }
00659 };
00660 
00666 template< >
00667 class NumericTraits< unsigned long > :public vcl_numeric_limits< unsigned long >
00668 {
00669 public:
00670   typedef unsigned long            ValueType;
00671   typedef unsigned long            PrintType;
00672   typedef unsigned long            AbsType;
00673   typedef unsigned long            AccumulateType;
00674   typedef double                   RealType;
00675   typedef RealType                 ScalarRealType;
00676   typedef float                    FloatType;
00677   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00678 
00679   static const unsigned long ITKCommon_EXPORT Zero;
00680   static const unsigned long ITKCommon_EXPORT One;
00681 
00682   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00683   static unsigned long NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
00684   static bool IsPositive(unsigned long val) { return val != Zero; }
00685   static bool IsNonpositive(unsigned long val) { return val == Zero; }
00686   static bool IsNegative(unsigned long) { return false; }
00687   static bool IsNonnegative(unsigned long) { return true; }
00688   static unsigned long  ZeroValue() { return Zero; }
00689   static unsigned long  OneValue() { return One; }
00690   static unsigned int GetLength(const ValueType &) { return 1; }
00691   static unsigned int GetLength() { return 1; }
00692   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00693   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00694   static ValueType OneValue(const ValueType &) { return OneValue(); }
00695 
00696   template<class TArray>
00697   static void AssignToArray( const ValueType & v, TArray & mv )
00698   {
00699     mv[0] = v;
00700   }
00701   static void SetLength(ValueType &, const unsigned int s)
00702   {
00703     if ( s != 1 )
00704       {
00705       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00706       }
00707   }
00708 };
00709 
00715 template< >
00716 class NumericTraits< float > :public vcl_numeric_limits< float >
00717 {
00718 public:
00719   typedef float                    ValueType;
00720   typedef float                    PrintType;
00721   typedef float                    AbsType;
00722   typedef double                   AccumulateType;
00723   typedef double                   RealType;
00724   typedef RealType                 ScalarRealType;
00725   typedef float                    FloatType;
00726   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00727 
00728   static const float ITKCommon_EXPORT Zero;
00729   static const float ITKCommon_EXPORT One;
00730 
00731   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00732   static float NonpositiveMin() { return -vcl_numeric_limits< ValueType >::max(); }
00733   static bool IsPositive(float val) { return val > Zero; }
00734   static bool IsNonpositive(float val) { return val <= Zero; }
00735   static bool IsNegative(float val) { return val < Zero; }
00736   static bool IsNonnegative(float val) { return val >= Zero; }
00737   static float  ZeroValue() { return Zero; }
00738   static float  OneValue() { return One; }
00739   static unsigned int GetLength(const ValueType &) { return 1; }
00740   static unsigned int GetLength() { return 1; }
00741   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00742   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00743   static ValueType OneValue(const ValueType &) { return OneValue(); }
00744 
00745   template<class TArray>
00746   static void AssignToArray( const ValueType & v, TArray & mv )
00747   {
00748     mv[0] = v;
00749   }
00750   static void SetLength(ValueType &, const unsigned int s)
00751   {
00752     if ( s != 1 )
00753       {
00754       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00755       }
00756   }
00757 };
00758 
00764 template< >
00765 class NumericTraits< double > :public vcl_numeric_limits< double >
00766 {
00767 public:
00768   typedef double                   ValueType;
00769   typedef double                   PrintType;
00770   typedef double                   AbsType;
00771   typedef double                   AccumulateType;
00772   typedef double                   RealType;
00773   typedef RealType                 ScalarRealType;
00774   typedef float                    FloatType;
00775   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00776 
00777   static const double ITKCommon_EXPORT Zero;
00778   static const double ITKCommon_EXPORT One;
00779 
00780   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00781   static double NonpositiveMin() { return -vcl_numeric_limits< ValueType >::max(); }
00782   static bool IsPositive(double val) { return val > Zero; }
00783   static bool IsNonpositive(double val) { return val <= Zero; }
00784   static bool IsNegative(double val) { return val < Zero; }
00785   static bool IsNonnegative(double val) { return val >= Zero; }
00786   static double  ZeroValue() { return Zero; }
00787   static double  OneValue() { return One; }
00788   static unsigned int GetLength(const ValueType &) { return 1; }
00789   static unsigned int GetLength() { return 1; }
00790   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00791   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00792   static ValueType OneValue(const ValueType &) { return OneValue(); }
00793 
00794   template<class TArray>
00795   static void AssignToArray( const ValueType & v, TArray & mv )
00796   {
00797     mv[0] = v;
00798   }
00799   static void SetLength(ValueType &, const unsigned int s)
00800   {
00801     if ( s != 1 )
00802       {
00803       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00804       }
00805   }
00806 };
00807 
00813 template< >
00814 class NumericTraits< long double > :public vcl_numeric_limits< long double >
00815 {
00816 public:
00817   typedef long double ValueType;
00818 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
00819   // sun studio in 32 bit mode is unable to print long double values: it
00820   // segfaults.
00821   // conversion to double will give usable results if the value is in the double
00822   // range - better than nothing.
00823   typedef double                   PrintType;
00824 #else
00825   typedef long double              PrintType;
00826 #endif
00827   typedef long double              AbsType;
00828   typedef long double              AccumulateType;
00829   typedef long double              RealType;
00830   typedef RealType                 ScalarRealType;
00831   typedef float                    FloatType;
00832   typedef FixedArray<ValueType, 1> MeasurementVectorType;
00833 
00834   static const long double ITKCommon_EXPORT Zero;
00835   static const long double ITKCommon_EXPORT One;
00836 
00837   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
00838   static long double NonpositiveMin() { return -vcl_numeric_limits< ValueType >::max(); }
00839   static bool IsPositive(long double val) { return val > Zero; }
00840   static bool IsNonpositive(long double val) { return val <= Zero; }
00841   static bool IsNegative(long double val) { return val < Zero; }
00842   static bool IsNonnegative(long double val) { return val >= Zero; }
00843   static long double ZeroValue() { return Zero; }
00844   static long double OneValue() { return One; }
00845   static unsigned int GetLength(const ValueType &) { return 1; }
00846   static unsigned int GetLength() { return 1; }
00847   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
00848   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
00849   static ValueType OneValue(const ValueType &) { return OneValue(); }
00850 
00851   template<class TArray>
00852   static void AssignToArray( const ValueType & v, TArray & mv )
00853   {
00854     mv[0] = v;
00855   }
00856   static void SetLength(ValueType &, const unsigned int s)
00857   {
00858     if ( s != 1 )
00859       {
00860       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
00861       }
00862   }
00863 };
00864 
00870 template< >
00871 class NumericTraits< std::complex< float > >
00872 {
00873 public:
00874   typedef std::complex< float >  Self;
00875   // for backward compatibility
00876   typedef Self                   TheType;
00877   typedef float                  ValueType;
00878   typedef Self                   PrintType;
00879   typedef double                 AbsType;
00880   typedef Self                   AccumulateType;
00881   typedef std::complex< double > RealType;
00882   typedef double                 ScalarRealType;
00883   typedef std::complex< float >  FloatType;
00884   typedef FixedArray<float, 2>   MeasurementVectorType;
00885 
00886   static const Self ITKCommon_EXPORT Zero;
00887   static const Self ITKCommon_EXPORT One;
00888 
00889   static Self min() { return vcl_numeric_limits< Self >::min(); }
00890   static Self max() { return vcl_numeric_limits< Self >::max(); }
00891   static Self min(Self) { return min(); }
00892   static Self max(Self) { return max(); }
00893   static Self NonpositiveMin()
00894   {
00895     return Self(-NumericTraits< float >::NonpositiveMin(), 0.0f);
00896   }
00897 
00898   static bool IsPositive(Self val) { return val.real() > 0.0; }
00899   static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
00900   static bool IsNegative(Self val) { return val.real() < 0.0; }
00901   static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
00902   static Self ZeroValue() { return Zero; }
00903   static Self OneValue() { return One; }
00904   static unsigned int GetLength(const Self &) { return 2; }
00905   static unsigned int GetLength() { return 2; }
00906   static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
00907   static Self ZeroValue(const Self &) { return ZeroValue(); }
00908   static Self OneValue(const Self &) { return OneValue(); }
00909   template<class TArray>
00910   static void AssignToArray( const Self & v, TArray & mv )
00911   {
00912     mv[0] = v.real();
00913     mv[1] = v.imag();
00914   }
00915   static void SetLength(Self &, const unsigned int s)
00916   {
00917     if ( s != 2 )
00918       {
00919       itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
00920       }
00921   }
00922 };
00923 
00929 template< >
00930 class NumericTraits< std::complex< double > >
00931 {
00932 public:
00933   typedef std::complex< double > Self;
00934   // for backward compatibility
00935   typedef Self                   TheType;
00936   typedef double                 ValueType;
00937   typedef Self                   PrintType;
00938   typedef double                 AbsType;
00939   typedef Self                   AccumulateType;
00940   typedef std::complex< double > RealType;
00941   typedef double                 ScalarRealType;
00942   typedef std::complex< float >  FloatType;
00943   typedef FixedArray<double, 2>  MeasurementVectorType;
00944 
00945   static const Self ITKCommon_EXPORT Zero;
00946   static const Self ITKCommon_EXPORT One;
00947 
00948   static Self min() { return vcl_numeric_limits< ValueType >::min(); }
00949   static Self max() { return vcl_numeric_limits< ValueType >::max(); }
00950   static Self min(Self) { return min(); }
00951   static Self max(Self) { return max(); }
00952   static Self NonpositiveMin()
00953   {
00954     return Self(-NumericTraits< double >::NonpositiveMin(), 0.0);
00955   }
00956 
00957   static bool IsPositive(Self val) { return val.real() > 0.0; }
00958   static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
00959   static bool IsNegative(Self val) { return val.real() < 0.0; }
00960   static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
00961   static Self ZeroValue() { return Zero; }
00962   static Self OneValue() { return One; }
00963   static unsigned int GetLength(const Self &) { return 2; }
00964   static unsigned int GetLength() { return 2; }
00965   static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
00966   static Self ZeroValue(const Self &) { return ZeroValue(); }
00967   static Self OneValue(const Self &) { return OneValue(); }
00968   template<class TArray>
00969   static void AssignToArray( const Self & v, TArray & mv )
00970   {
00971     mv[0] = v.real();
00972     mv[1] = v.imag();
00973   }
00974   static void SetLength(Self &, const unsigned int s)
00975   {
00976     if ( s != 2 )
00977       {
00978       itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
00979       }
00980   }
00981 };
00982 
00988 template< >
00989 class NumericTraits< long long > :
00990   public vcl_numeric_limits< long long >
00991 {
00992 public:
00993   typedef long long                ValueType;
00994   typedef long long                PrintType;
00995   typedef long long                AbsType;
00996   typedef long long                AccumulateType;
00997   typedef double                   RealType;
00998   typedef RealType                 ScalarRealType;
00999   typedef float                    FloatType;
01000   typedef FixedArray<ValueType, 1> MeasurementVectorType;
01001 
01002   static const ValueType ITKCommon_EXPORT Zero;
01003   static const ValueType ITKCommon_EXPORT One;
01004 
01005   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
01006   static ValueType NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
01007   static bool IsPositive(ValueType val) { return val > Zero; }
01008   static bool IsNonpositive(ValueType val) { return val <= Zero; }
01009   static bool IsNegative(ValueType val) { return val < Zero; }
01010   static bool IsNonnegative(ValueType val) { return val >= Zero; }
01011   static ValueType  ZeroValue() { return Zero; }
01012   static ValueType  OneValue() { return One; }
01013   static unsigned int GetLength(const ValueType &) { return 1; }
01014   static unsigned int GetLength() { return 1; }
01015   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
01016   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
01017   static ValueType OneValue(const ValueType &) { return OneValue(); }
01018 
01019   template<class TArray>
01020   static void AssignToArray( const ValueType & v, TArray & mv )
01021   {
01022     mv[0] = v;
01023   }
01024   static void SetLength(ValueType &, const unsigned int s)
01025   {
01026     if ( s != 1 )
01027       {
01028       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
01029       }
01030   }
01031 };
01032 
01038 template< >
01039 class NumericTraits< unsigned long long > :
01040   public vcl_numeric_limits< unsigned long long >
01041 {
01042 public:
01043   typedef unsigned long long       ValueType;
01044   typedef unsigned long long       PrintType;
01045   typedef unsigned long long       AbsType;
01046   typedef unsigned long long       AccumulateType;
01047   typedef double                   RealType;
01048   typedef RealType                 ScalarRealType;
01049   typedef float                    FloatType;
01050   typedef FixedArray<ValueType, 1> MeasurementVectorType;
01051 
01052   static const ValueType ITKCommon_EXPORT Zero;
01053   static const ValueType ITKCommon_EXPORT One;
01054 
01055   itkNUMERIC_TRAITS_MIN_MAX_MACRO();
01056   static ValueType NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
01057   static bool IsPositive(ValueType val) { return val != Zero; }
01058   static bool IsNonpositive(ValueType val) { return val == Zero; }
01059   static bool IsNegative(ValueType) { return false; }
01060   static bool IsNonnegative(ValueType) { return true; }
01061   static ValueType ZeroValue() { return Zero; }
01062   static ValueType OneValue() { return One; }
01063   static unsigned int GetLength(const ValueType &) { return 1; }
01064   static unsigned int GetLength() { return 1; }
01065   static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
01066   static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
01067   static ValueType OneValue(const ValueType &) { return OneValue(); }
01068 
01069   template<class TArray>
01070   static void AssignToArray( const ValueType & v, TArray & mv )
01071   {
01072     mv[0] = v;
01073   }
01074   static void SetLength(ValueType &, const unsigned int s)
01075   {
01076     if ( s != 1 )
01077       {
01078       itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
01079       }
01080   }
01081 };
01082 
01085 } // end namespace itk
01086 
01087 #include "itkFixedArray.h"
01088 
01089 #endif // __itkNumericTraits_h
01090