ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkNumericTraits.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkNumericTraits_h
19 #define __itkNumericTraits_h
20 
21 #include "itkMacro.h"
22 
23 #undef min
24 #undef max
25 
26 #define itkNUMERIC_TRAITS_MIN_MAX_MACRO() \
27  static ValueType min() \
28  { \
29  return vcl_numeric_limits< ValueType >::min(); \
30  } \
31  static ValueType max() \
32  { \
33  return vcl_numeric_limits< ValueType >::max(); \
34  } \
35  static ValueType min(ValueType) \
36  { \
37  return vcl_numeric_limits< ValueType >::min(); \
38  } \
39  static ValueType max(ValueType) \
40  { \
41  return vcl_numeric_limits< ValueType >::max(); \
42  } \
43 
44 
45 #include "vcl_limits.h" // for vcl_numeric_limits
46 #include <complex>
47 
48 namespace itk
49 {
50 
51 // forward decare to avoid circular dependencies
52 template< typename TValueType, unsigned int VLength> class FixedArray;
53 
69 template< class T >
70 class NumericTraits:public vcl_numeric_limits< T >
71 {
72 public:
74  typedef vcl_numeric_limits< T > TraitsType;
75 
77  typedef T ValueType;
78 
80  typedef T PrintType;
81 
83  typedef T AbsType;
84 
86  typedef double AccumulateType;
87 
90 
93  typedef float FloatType;
94 
96  typedef double RealType;
97 
100 
102  static const T Zero;
103 
105  static const T One;
106 
108  static T NonpositiveMin() { return TraitsType::min(); }
109 
111  static bool IsPositive(T val) { return val > Zero; }
112 
114  static bool IsNonpositive(T val) { return val <= Zero; }
115 
117  static bool IsNegative(T val) { return val < Zero; }
118 
120  static bool IsNonnegative(T val) { return val >= Zero; }
121 
124  static T ZeroValue() { return Zero; }
125 
128  static T OneValue() { return One; }
129 
130  /* Provide a default implementation of the max() method with
131  * argument. This API is needed for VariableLengthVector because
132  * its length is only known at run-time. Specializations of the
133  * VariableLengthVector will provide a different implementation
134  * where a vector of the correct size is built. */
135  static T max(const T &) { return TraitsType::max(); }
136  static T min(const T &) { return TraitsType::min(); }
137 
145  static void SetLength(T &, const unsigned int s)
146  {
147  if ( s != 1 )
148  {
149  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
150  }
151  }
152 
159  static unsigned int GetLength(const T &)
160  {
161  return GetLength();
162  }
163 
165  static unsigned int GetLength()
166  {
167  return 1;
168  }
169 
173  static T NonpositiveMin(const T &)
174  {
175  return NonpositiveMin();
176  }
177 
181  static T ZeroValue(const T &)
182  {
183  return ZeroValue();
184  }
185 
189  static T OneValue(const T &)
190  {
191  return OneValue();
192  }
193 
195  template<class TArray>
196  static void AssignToArray( const T & v, TArray & mv )
197  {
198  mv[0] = v;
199  }
200 
201 };
202 
212 template< >
213 class NumericTraits< bool > :public vcl_numeric_limits< bool >
214 {
215 public:
216  typedef bool ValueType;
217  typedef bool PrintType;
218  typedef unsigned char AbsType;
219  typedef unsigned char AccumulateType;
220  typedef double RealType;
221  typedef RealType ScalarRealType;
222  typedef float FloatType;
223  typedef FixedArray<ValueType, 1> MeasurementVectorType;
224 
225  static const bool ITKCommon_EXPORT Zero;
226  static const bool ITKCommon_EXPORT One;
227 
228  static bool min() { return false; }
229  static bool max() { return true; }
230  static bool min(bool) { return min(); }
231  static bool max(bool) { return max(); }
232  static bool NonpositiveMin() { return false; }
233  static bool IsPositive(bool val) { return val; }
234  static bool IsNonpositive(bool val) { return !val; }
235  static bool IsNegative(bool val) { return val ? false : false; }
236  static bool IsNonnegative(bool val) { return val ? true : true; }
237  static bool ZeroValue() { return Zero; }
238  static bool OneValue() { return One; }
239  static unsigned int GetLength(const ValueType &) { return 1; }
240  static unsigned int GetLength() { return 1; }
241  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
242  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
243  static ValueType OneValue(const ValueType &) { return OneValue(); }
244 
245  template<class TArray>
246  static void AssignToArray( const ValueType & v, TArray & mv )
247  {
248  mv[0] = v;
249  }
250  static void SetLength(ValueType &, const unsigned int s)
251  {
252  if ( s != 1 )
253  {
254  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
255  }
256  }
257 
258 };
259 
265 template< >
266 class NumericTraits< char > :public vcl_numeric_limits< char >
267 {
268 public:
269  typedef char ValueType;
270  typedef int PrintType;
271  typedef unsigned char AbsType;
272  typedef short AccumulateType;
273  typedef double RealType;
274  typedef RealType ScalarRealType;
275  typedef float FloatType;
276  typedef FixedArray<ValueType, 1> MeasurementVectorType;
277 
278  static const char ITKCommon_EXPORT Zero;
279  static const char ITKCommon_EXPORT One;
280 
281  static char min() { return char(255) < 0 ? -128 : 0; }
282  static char max() { return char(255) < 0 ? 127 : 255; }
283 
284  static char min(char) { return min(); }
285  static char max(char) { return max(); }
286  static char NonpositiveMin() { return min(); }
287  static bool IsPositive(char val) { return val > Zero; }
288  static bool IsNonpositive(char val) { return val <= Zero; }
289  static bool IsNegative(char val) { return val < Zero; }
290  static bool IsNonnegative(char val) { return val >= Zero; }
291  static char ZeroValue() { return Zero; }
292  static char OneValue() { return One; }
293  static unsigned int GetLength(const ValueType &) { return 1; }
294  static unsigned int GetLength() { return 1; }
295  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
296  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
297  static ValueType OneValue(const ValueType &) { return OneValue(); }
298 
299  template<class TArray>
300  static void AssignToArray( const ValueType & v, TArray & mv )
301  {
302  mv[0] = v;
303  }
304  static void SetLength(ValueType &, const unsigned int s)
305  {
306  if ( s != 1 )
307  {
308  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
309  }
310  }
311 };
312 
318 template< >
319 class NumericTraits< signed char > :public vcl_numeric_limits< signed char >
320 {
321 public:
322  typedef signed char ValueType;
323  typedef int PrintType;
324  typedef unsigned char AbsType;
325  typedef short AccumulateType;
326  typedef double RealType;
327  typedef RealType ScalarRealType;
328  typedef float FloatType;
329  typedef FixedArray<ValueType, 1> MeasurementVectorType;
330 
331  static const signed char ITKCommon_EXPORT Zero;
332  static const signed char ITKCommon_EXPORT One;
333 
334  static signed char min() { return -128; }
335  static signed char max() { return 127; }
336  static signed char min(signed char) { return min(); }
337  static signed char max(signed char) { return max(); }
338  static signed char NonpositiveMin() { return min(); }
339  static bool IsPositive(signed char val) { return val > Zero; }
340  static bool IsNonpositive(signed char val) { return val <= Zero; }
341  static bool IsNegative(signed char val) { return val < Zero; }
342  static bool IsNonnegative(signed char val) { return val >= Zero; }
343  static signed char ZeroValue() { return Zero; }
344  static signed char OneValue() { return One; }
345  static unsigned int GetLength(const ValueType &) { return 1; }
346  static unsigned int GetLength() { return 1; }
347  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
348  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
349  static ValueType OneValue(const ValueType &) { return OneValue(); }
350 
351  template<class TArray>
352  static void AssignToArray( const ValueType & v, TArray & mv )
353  {
354  mv[0] = v;
355  }
356  static void SetLength(ValueType &, const unsigned int s)
357  {
358  if ( s != 1 )
359  {
360  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
361  }
362  }
363 };
364 
370 template< >
371 class NumericTraits< unsigned char > :public vcl_numeric_limits< unsigned char >
372 {
373 public:
374  typedef unsigned char ValueType;
375  typedef int PrintType;
376  typedef unsigned char AbsType;
377  typedef unsigned short AccumulateType;
378  typedef double RealType;
379  typedef RealType ScalarRealType;
380  typedef float FloatType;
381  typedef FixedArray<ValueType, 1> MeasurementVectorType;
382 
383  static const unsigned char ITKCommon_EXPORT Zero;
384  static const unsigned char ITKCommon_EXPORT One;
385 
387 
388  static unsigned char NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
389  static bool IsPositive(unsigned char val) { return val != Zero; }
390  static bool IsNonpositive(unsigned char val) { return val == Zero; }
391  static bool IsNegative(unsigned char val) { return val ? false : false; }
392  static bool IsNonnegative(unsigned char val) { return val ? true : true; }
393  static unsigned char ZeroValue() { return Zero; }
394  static unsigned char OneValue() { return One; }
395  static unsigned int GetLength(const ValueType &) { return 1; }
396  static unsigned int GetLength() { return 1; }
397  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
398  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
399  static ValueType OneValue(const ValueType &) { return OneValue(); }
400 
401  template<class TArray>
402  static void AssignToArray( const ValueType & v, TArray & mv )
403  {
404  mv[0] = v;
405  }
406  static void SetLength(ValueType &, const unsigned int s)
407  {
408  if ( s != 1 )
409  {
410  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
411  }
412  }
413 };
414 
419 template< >
420 class NumericTraits< short > :public vcl_numeric_limits< short >
421 {
422 public:
423  typedef short ValueType;
424  typedef short PrintType;
425  typedef unsigned short AbsType;
426  typedef int AccumulateType;
427  typedef double RealType;
428  typedef RealType ScalarRealType;
429  typedef float FloatType;
430  typedef FixedArray<ValueType, 1> MeasurementVectorType;
431 
432  static const short ITKCommon_EXPORT Zero;
433  static const short ITKCommon_EXPORT One;
434 
436  static short NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
437  static bool IsPositive(short val) { return val > Zero; }
438  static bool IsNonpositive(short val) { return val <= Zero; }
439  static bool IsNegative(short val) { return val < Zero; }
440  static bool IsNonnegative(short val) { return val >= Zero; }
441  static short ZeroValue() { return Zero; }
442  static short OneValue() { return One; }
443  static unsigned int GetLength(const ValueType &) { return 1; }
444  static unsigned int GetLength() { return 1; }
445  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
446  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
447  static ValueType OneValue(const ValueType &) { return OneValue(); }
448 
449  template<class TArray>
450  static void AssignToArray( const ValueType & v, TArray & mv )
451  {
452  mv[0] = v;
453  }
454  static void SetLength(ValueType &, const unsigned int s)
455  {
456  if ( s != 1 )
457  {
458  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
459  }
460  }
461 };
462 
468 template< >
469 class NumericTraits< unsigned short > :public vcl_numeric_limits< unsigned short >
470 {
471 public:
472  typedef unsigned short ValueType;
473  typedef unsigned short PrintType;
474  typedef unsigned short AbsType;
475  typedef unsigned int AccumulateType;
476  typedef double RealType;
477  typedef RealType ScalarRealType;
478  typedef float FloatType;
479  typedef FixedArray<ValueType, 1> MeasurementVectorType;
480 
481  static const unsigned short ITKCommon_EXPORT Zero;
482  static const unsigned short ITKCommon_EXPORT One;
483 
485  static unsigned short NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
486  static bool IsPositive(unsigned short val) { return val != Zero; }
487  static bool IsNonpositive(unsigned short val) { return val == Zero; }
488  static bool IsNegative(unsigned short val) { return val ? false : false; }
489  static bool IsNonnegative(unsigned short val) { return val ? true : true; }
490  static unsigned short ZeroValue() { return Zero; }
491  static unsigned short OneValue() { return One; }
492  static unsigned int GetLength(const ValueType &) { return 1; }
493  static unsigned int GetLength() { return 1; }
494  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
495  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
496  static ValueType OneValue(const ValueType &) { return OneValue(); }
497 
498  template<class TArray>
499  static void AssignToArray( const ValueType & v, TArray & mv )
500  {
501  mv[0] = v;
502  }
503  static void SetLength(ValueType &, const unsigned int s)
504  {
505  if ( s != 1 )
506  {
507  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
508  }
509  }
510 };
511 
516 template< >
517 class NumericTraits< int > :public vcl_numeric_limits< int >
518 {
519 public:
520  typedef int ValueType;
521  typedef int PrintType;
522  typedef unsigned int AbsType;
523  typedef long AccumulateType;
524  typedef double RealType;
525  typedef RealType ScalarRealType;
526  typedef float FloatType;
527  typedef FixedArray<ValueType, 1> MeasurementVectorType;
528 
529  static const int ITKCommon_EXPORT Zero;
530  static const int ITKCommon_EXPORT One;
531 
533  static int NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
534  static bool IsPositive(int val) { return val > Zero; }
535  static bool IsNonpositive(int val) { return val <= Zero; }
536  static bool IsNegative(int val) { return val < Zero; }
537  static bool IsNonnegative(int val) { return val >= Zero; }
538  static int ZeroValue() { return Zero; }
539  static int OneValue() { return One; }
540  static unsigned int GetLength(const ValueType &) { return 1; }
541  static unsigned int GetLength() { return 1; }
542  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
543  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
544  static ValueType OneValue(const ValueType &) { return OneValue(); }
545 
546  template<class TArray>
547  static void AssignToArray( const ValueType & v, TArray & mv )
548  {
549  mv[0] = v;
550  }
551  static void SetLength(ValueType &, const unsigned int s)
552  {
553  if ( s != 1 )
554  {
555  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
556  }
557  }
558 };
559 
565 template< >
566 class NumericTraits< unsigned int > :public vcl_numeric_limits< unsigned int >
567 {
568 public:
569  typedef unsigned int ValueType;
570  typedef unsigned int PrintType;
571  typedef unsigned int AbsType;
572  typedef unsigned int AccumulateType;
573  typedef double RealType;
574  typedef RealType ScalarRealType;
575  typedef float FloatType;
576  typedef FixedArray<ValueType, 1> MeasurementVectorType;
577 
578  static const unsigned int ITKCommon_EXPORT Zero;
579  static const unsigned int ITKCommon_EXPORT One;
580 
581  static unsigned int min(void) { return 0; }
582  static unsigned int max(void) { return static_cast< unsigned int >( -1 ); }
583  static unsigned int min(unsigned int) { return vcl_numeric_limits< ValueType >::min(); }
584  static unsigned int max(unsigned int) { return vcl_numeric_limits< ValueType >::max(); }
585  static unsigned int NonpositiveMin() { return 0; }
586  static bool IsPositive(unsigned int val) { return val != Zero; }
587  static bool IsNonpositive(unsigned int val) { return val == Zero; }
588  static bool IsNegative(unsigned int val) { return val ? false : false; }
589  static bool IsNonnegative(unsigned int val) { return val ? true : true; }
590  static unsigned int ZeroValue() { return Zero; }
591  static unsigned int OneValue() { return One; }
592  static unsigned int GetLength(const ValueType &) { return 1; }
593  static unsigned int GetLength() { return 1; }
594  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
595  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
596  static ValueType OneValue(const ValueType &) { return OneValue(); }
597 
598  template<class TArray>
599  static void AssignToArray( const ValueType & v, TArray & mv )
600  {
601  mv[0] = v;
602  }
603  static void SetLength(ValueType &, const unsigned int s)
604  {
605  if ( s != 1 )
606  {
607  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
608  }
609  }
610 };
611 
617 template< >
618 class NumericTraits< long > :public vcl_numeric_limits< long >
619 {
620 public:
621  typedef long ValueType;
622  typedef long PrintType;
623  typedef unsigned long AbsType;
624  typedef long AccumulateType;
625  typedef double RealType;
626  typedef RealType ScalarRealType;
627  typedef float FloatType;
628  typedef FixedArray<ValueType, 1> MeasurementVectorType;
629 
630  static const long ITKCommon_EXPORT Zero;
631  static const long ITKCommon_EXPORT One;
632 
634  static long NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
635  static bool IsPositive(long val) { return val > Zero; }
636  static bool IsNonpositive(long val) { return val <= Zero; }
637  static bool IsNegative(long val) { return val < Zero; }
638  static bool IsNonnegative(long val) { return val >= Zero; }
639  static long ZeroValue() { return Zero; }
640  static long OneValue() { return One; }
641  static unsigned int GetLength(const ValueType &) { return 1; }
642  static unsigned int GetLength() { return 1; }
643  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
644  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
645  static ValueType OneValue(const ValueType &) { return OneValue(); }
646 
647  template<class TArray>
648  static void AssignToArray( const ValueType & v, TArray & mv )
649  {
650  mv[0] = v;
651  }
652  static void SetLength(ValueType &, const unsigned int s)
653  {
654  if ( s != 1 )
655  {
656  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
657  }
658  }
659 };
660 
666 template< >
667 class NumericTraits< unsigned long > :public vcl_numeric_limits< unsigned long >
668 {
669 public:
670  typedef unsigned long ValueType;
671  typedef unsigned long PrintType;
672  typedef unsigned long AbsType;
673  typedef unsigned long AccumulateType;
674  typedef double RealType;
675  typedef RealType ScalarRealType;
676  typedef float FloatType;
677  typedef FixedArray<ValueType, 1> MeasurementVectorType;
678 
679  static const unsigned long ITKCommon_EXPORT Zero;
680  static const unsigned long ITKCommon_EXPORT One;
681 
683  static unsigned long NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
684  static bool IsPositive(unsigned long val) { return val != Zero; }
685  static bool IsNonpositive(unsigned long val) { return val == Zero; }
686  static bool IsNegative(unsigned long) { return false; }
687  static bool IsNonnegative(unsigned long) { return true; }
688  static unsigned long ZeroValue() { return Zero; }
689  static unsigned long OneValue() { return One; }
690  static unsigned int GetLength(const ValueType &) { return 1; }
691  static unsigned int GetLength() { return 1; }
692  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
693  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
694  static ValueType OneValue(const ValueType &) { return OneValue(); }
695 
696  template<class TArray>
697  static void AssignToArray( const ValueType & v, TArray & mv )
698  {
699  mv[0] = v;
700  }
701  static void SetLength(ValueType &, const unsigned int s)
702  {
703  if ( s != 1 )
704  {
705  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
706  }
707  }
708 };
709 
715 template< >
716 class NumericTraits< float > :public vcl_numeric_limits< float >
717 {
718 public:
719  typedef float ValueType;
720  typedef float PrintType;
721  typedef float AbsType;
722  typedef double AccumulateType;
723  typedef double RealType;
724  typedef RealType ScalarRealType;
725  typedef float FloatType;
726  typedef FixedArray<ValueType, 1> MeasurementVectorType;
727 
728  static const float ITKCommon_EXPORT Zero;
729  static const float ITKCommon_EXPORT One;
730 
732  static float NonpositiveMin() { return -vcl_numeric_limits< ValueType >::max(); }
733  static bool IsPositive(float val) { return val > Zero; }
734  static bool IsNonpositive(float val) { return val <= Zero; }
735  static bool IsNegative(float val) { return val < Zero; }
736  static bool IsNonnegative(float val) { return val >= Zero; }
737  static float ZeroValue() { return Zero; }
738  static float OneValue() { return One; }
739  static unsigned int GetLength(const ValueType &) { return 1; }
740  static unsigned int GetLength() { return 1; }
741  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
742  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
743  static ValueType OneValue(const ValueType &) { return OneValue(); }
744 
745  template<class TArray>
746  static void AssignToArray( const ValueType & v, TArray & mv )
747  {
748  mv[0] = v;
749  }
750  static void SetLength(ValueType &, const unsigned int s)
751  {
752  if ( s != 1 )
753  {
754  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
755  }
756  }
757 };
758 
764 template< >
765 class NumericTraits< double > :public vcl_numeric_limits< double >
766 {
767 public:
768  typedef double ValueType;
769  typedef double PrintType;
770  typedef double AbsType;
771  typedef double AccumulateType;
772  typedef double RealType;
773  typedef RealType ScalarRealType;
774  typedef float FloatType;
775  typedef FixedArray<ValueType, 1> MeasurementVectorType;
776 
777  static const double ITKCommon_EXPORT Zero;
778  static const double ITKCommon_EXPORT One;
779 
781  static double NonpositiveMin() { return -vcl_numeric_limits< ValueType >::max(); }
782  static bool IsPositive(double val) { return val > Zero; }
783  static bool IsNonpositive(double val) { return val <= Zero; }
784  static bool IsNegative(double val) { return val < Zero; }
785  static bool IsNonnegative(double val) { return val >= Zero; }
786  static double ZeroValue() { return Zero; }
787  static double OneValue() { return One; }
788  static unsigned int GetLength(const ValueType &) { return 1; }
789  static unsigned int GetLength() { return 1; }
790  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
791  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
792  static ValueType OneValue(const ValueType &) { return OneValue(); }
793 
794  template<class TArray>
795  static void AssignToArray( const ValueType & v, TArray & mv )
796  {
797  mv[0] = v;
798  }
799  static void SetLength(ValueType &, const unsigned int s)
800  {
801  if ( s != 1 )
802  {
803  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
804  }
805  }
806 };
807 
813 template< >
814 class NumericTraits< long double > :public vcl_numeric_limits< long double >
815 {
816 public:
817  typedef long double ValueType;
818 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
819  // sun studio in 32 bit mode is unable to print long double values: it
820  // segfaults.
821  // conversion to double will give usable results if the value is in the double
822  // range - better than nothing.
823  typedef double PrintType;
824 #else
825  typedef long double PrintType;
826 #endif
827  typedef long double AbsType;
828  typedef long double AccumulateType;
829  typedef long double RealType;
830  typedef RealType ScalarRealType;
831  typedef float FloatType;
832  typedef FixedArray<ValueType, 1> MeasurementVectorType;
833 
834  static const long double ITKCommon_EXPORT Zero;
835  static const long double ITKCommon_EXPORT One;
836 
838  static long double NonpositiveMin() { return -vcl_numeric_limits< ValueType >::max(); }
839  static bool IsPositive(long double val) { return val > Zero; }
840  static bool IsNonpositive(long double val) { return val <= Zero; }
841  static bool IsNegative(long double val) { return val < Zero; }
842  static bool IsNonnegative(long double val) { return val >= Zero; }
843  static long double ZeroValue() { return Zero; }
844  static long double OneValue() { return One; }
845  static unsigned int GetLength(const ValueType &) { return 1; }
846  static unsigned int GetLength() { return 1; }
847  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
848  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
849  static ValueType OneValue(const ValueType &) { return OneValue(); }
850 
851  template<class TArray>
852  static void AssignToArray( const ValueType & v, TArray & mv )
853  {
854  mv[0] = v;
855  }
856  static void SetLength(ValueType &, const unsigned int s)
857  {
858  if ( s != 1 )
859  {
860  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
861  }
862  }
863 };
864 
870 template< >
871 class NumericTraits< std::complex< float > >
872 {
873 public:
874  typedef std::complex< float > Self;
875  // for backward compatibility
876  typedef Self TheType;
877  typedef float ValueType;
878  typedef Self PrintType;
879  typedef double AbsType;
880  typedef Self AccumulateType;
881  typedef std::complex< double > RealType;
882  typedef double ScalarRealType;
883  typedef std::complex< float > FloatType;
884  typedef FixedArray<float, 2> MeasurementVectorType;
885 
886  static const Self ITKCommon_EXPORT Zero;
887  static const Self ITKCommon_EXPORT One;
888 
889  static Self min() { return vcl_numeric_limits< Self >::min(); }
890  static Self max() { return vcl_numeric_limits< Self >::max(); }
891  static Self min(Self) { return min(); }
892  static Self max(Self) { return max(); }
893  static Self NonpositiveMin()
894  {
895  return Self(-NumericTraits< float >::NonpositiveMin(), 0.0f);
896  }
897 
898  static bool IsPositive(Self val) { return val.real() > 0.0; }
899  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
900  static bool IsNegative(Self val) { return val.real() < 0.0; }
901  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
902  static Self ZeroValue() { return Zero; }
903  static Self OneValue() { return One; }
904  static unsigned int GetLength(const Self &) { return 2; }
905  static unsigned int GetLength() { return 2; }
906  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
907  static Self ZeroValue(const Self &) { return ZeroValue(); }
908  static Self OneValue(const Self &) { return OneValue(); }
909  template<class TArray>
910  static void AssignToArray( const Self & v, TArray & mv )
911  {
912  mv[0] = v.real();
913  mv[1] = v.imag();
914  }
915  static void SetLength(Self &, const unsigned int s)
916  {
917  if ( s != 2 )
918  {
919  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
920  }
921  }
922 };
923 
929 template< >
930 class NumericTraits< std::complex< double > >
931 {
932 public:
933  typedef std::complex< double > Self;
934  // for backward compatibility
935  typedef Self TheType;
936  typedef double ValueType;
937  typedef Self PrintType;
938  typedef double AbsType;
939  typedef Self AccumulateType;
940  typedef std::complex< double > RealType;
941  typedef double ScalarRealType;
942  typedef std::complex< float > FloatType;
943  typedef FixedArray<double, 2> MeasurementVectorType;
944 
945  static const Self ITKCommon_EXPORT Zero;
946  static const Self ITKCommon_EXPORT One;
947 
948  static Self min() { return vcl_numeric_limits< ValueType >::min(); }
949  static Self max() { return vcl_numeric_limits< ValueType >::max(); }
950  static Self min(Self) { return min(); }
951  static Self max(Self) { return max(); }
952  static Self NonpositiveMin()
953  {
954  return Self(-NumericTraits< double >::NonpositiveMin(), 0.0);
955  }
956 
957  static bool IsPositive(Self val) { return val.real() > 0.0; }
958  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
959  static bool IsNegative(Self val) { return val.real() < 0.0; }
960  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
961  static Self ZeroValue() { return Zero; }
962  static Self OneValue() { return One; }
963  static unsigned int GetLength(const Self &) { return 2; }
964  static unsigned int GetLength() { return 2; }
965  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
966  static Self ZeroValue(const Self &) { return ZeroValue(); }
967  static Self OneValue(const Self &) { return OneValue(); }
968  template<class TArray>
969  static void AssignToArray( const Self & v, TArray & mv )
970  {
971  mv[0] = v.real();
972  mv[1] = v.imag();
973  }
974  static void SetLength(Self &, const unsigned int s)
975  {
976  if ( s != 2 )
977  {
978  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
979  }
980  }
981 };
982 
988 template< >
989 class NumericTraits< long long > :
990  public vcl_numeric_limits< long long >
991 {
992 public:
993  typedef long long ValueType;
994  typedef long long PrintType;
995  typedef long long AbsType;
996  typedef long long AccumulateType;
997  typedef double RealType;
998  typedef RealType ScalarRealType;
999  typedef float FloatType;
1000  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1001 
1002  static const ValueType ITKCommon_EXPORT Zero;
1003  static const ValueType ITKCommon_EXPORT One;
1004 
1006  static ValueType NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
1007  static bool IsPositive(ValueType val) { return val > Zero; }
1008  static bool IsNonpositive(ValueType val) { return val <= Zero; }
1009  static bool IsNegative(ValueType val) { return val < Zero; }
1010  static bool IsNonnegative(ValueType val) { return val >= Zero; }
1011  static ValueType ZeroValue() { return Zero; }
1012  static ValueType OneValue() { return One; }
1013  static unsigned int GetLength(const ValueType &) { return 1; }
1014  static unsigned int GetLength() { return 1; }
1015  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1016  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1017  static ValueType OneValue(const ValueType &) { return OneValue(); }
1018 
1019  template<class TArray>
1020  static void AssignToArray( const ValueType & v, TArray & mv )
1021  {
1022  mv[0] = v;
1023  }
1024  static void SetLength(ValueType &, const unsigned int s)
1025  {
1026  if ( s != 1 )
1027  {
1028  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1029  }
1030  }
1031 };
1032 
1038 template< >
1039 class NumericTraits< unsigned long long > :
1040  public vcl_numeric_limits< unsigned long long >
1041 {
1042 public:
1043  typedef unsigned long long ValueType;
1044  typedef unsigned long long PrintType;
1045  typedef unsigned long long AbsType;
1046  typedef unsigned long long AccumulateType;
1047  typedef double RealType;
1048  typedef RealType ScalarRealType;
1049  typedef float FloatType;
1050  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1051 
1052  static const ValueType ITKCommon_EXPORT Zero;
1053  static const ValueType ITKCommon_EXPORT One;
1054 
1056  static ValueType NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
1057  static bool IsPositive(ValueType val) { return val != Zero; }
1058  static bool IsNonpositive(ValueType val) { return val == Zero; }
1059  static bool IsNegative(ValueType) { return false; }
1060  static bool IsNonnegative(ValueType) { return true; }
1061  static ValueType ZeroValue() { return Zero; }
1062  static ValueType OneValue() { return One; }
1063  static unsigned int GetLength(const ValueType &) { return 1; }
1064  static unsigned int GetLength() { return 1; }
1065  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1066  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1067  static ValueType OneValue(const ValueType &) { return OneValue(); }
1068 
1069  template<class TArray>
1070  static void AssignToArray( const ValueType & v, TArray & mv )
1071  {
1072  mv[0] = v;
1073  }
1074  static void SetLength(ValueType &, const unsigned int s)
1075  {
1076  if ( s != 1 )
1077  {
1078  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1079  }
1080  }
1081 };
1082 
1085 } // end namespace itk
1086 
1087 #include "itkFixedArray.h"
1088 
1089 #endif // __itkNumericTraits_h
1090