ITK  4.4.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) < char(0) ? char(-128) : char(0); }
282  static char max() { return char(255) < char(0) ? char(127) : char(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< char > >
872 {
873 public:
874  typedef std::complex< char > Self;
875  // for backward compatibility
876  typedef Self TheType;
877  typedef char ValueType;
878  typedef std::complex< int > 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<char, 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< ValueType >::NonpositiveMin(), 0);
896  }
897 
898  static bool IsPositive(Self val) { return val.real() > 0; }
899  static bool IsNonpositive(Self val) { return val.real() <= 0; }
900  static bool IsNegative(Self val) { return val.real() < 0; }
901  static bool IsNonnegative(Self val) { return val.real() >= 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< unsigned char > >
931 {
932 public:
933  typedef std::complex< unsigned char > Self;
934  // for backward compatibility
935  typedef Self TheType;
936  typedef unsigned char ValueType;
937  typedef std::complex< unsigned int > 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<unsigned char, 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< Self >::min(); }
949  static Self max() { return vcl_numeric_limits< Self >::max(); }
950  static Self min(Self) { return min(); }
951  static Self max(Self) { return max(); }
952  static Self NonpositiveMin()
953  {
954  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
955  }
956 
957  static bool IsPositive(Self val) { return val.real() > 0; }
958  static bool IsNonpositive(Self val) { return val.real() == 0; }
959  static bool IsNegative(Self) { return false; }
960  static bool IsNonnegative(Self) { return true; }
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< std::complex< short > >
990 {
991 public:
992  typedef std::complex< short > Self;
993  // for backward compatibility
994  typedef Self TheType;
995  typedef short ValueType;
996  typedef Self PrintType;
997  typedef double AbsType;
998  typedef Self AccumulateType;
999  typedef std::complex< double > RealType;
1000  typedef double ScalarRealType;
1001  typedef std::complex< float > FloatType;
1002  typedef FixedArray<short, 2> MeasurementVectorType;
1003 
1004  static const Self ITKCommon_EXPORT Zero;
1005  static const Self ITKCommon_EXPORT One;
1006 
1007  static Self min() { return vcl_numeric_limits< Self >::min(); }
1008  static Self max() { return vcl_numeric_limits< Self >::max(); }
1009  static Self min(Self) { return min(); }
1010  static Self max(Self) { return max(); }
1011  static Self NonpositiveMin()
1012  {
1013  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1014  }
1015 
1016  static bool IsPositive(Self val) { return val.real() > 0; }
1017  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1018  static bool IsNegative(Self val) { return val.real() < 0; }
1019  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1020  static Self ZeroValue() { return Zero; }
1021  static Self OneValue() { return One; }
1022  static unsigned int GetLength(const Self &) { return 2; }
1023  static unsigned int GetLength() { return 2; }
1024  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1025  static Self ZeroValue(const Self &) { return ZeroValue(); }
1026  static Self OneValue(const Self &) { return OneValue(); }
1027  template<class TArray>
1028  static void AssignToArray( const Self & v, TArray & mv )
1029  {
1030  mv[0] = v.real();
1031  mv[1] = v.imag();
1032  }
1033  static void SetLength(Self &, const unsigned int s)
1034  {
1035  if ( s != 2 )
1036  {
1037  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1038  }
1039  }
1040 };
1041 
1047 template< >
1048 class NumericTraits< std::complex< unsigned short > >
1049 {
1050 public:
1051  typedef std::complex< unsigned short > Self;
1052  // for backward compatibility
1053  typedef Self TheType;
1054  typedef unsigned short ValueType;
1055  typedef Self PrintType;
1056  typedef double AbsType;
1057  typedef Self AccumulateType;
1058  typedef std::complex< double > RealType;
1059  typedef double ScalarRealType;
1060  typedef std::complex< float > FloatType;
1061  typedef FixedArray<unsigned short, 2> MeasurementVectorType;
1062 
1063  static const Self ITKCommon_EXPORT Zero;
1064  static const Self ITKCommon_EXPORT One;
1065 
1066  static Self min() { return vcl_numeric_limits< Self >::min(); }
1067  static Self max() { return vcl_numeric_limits< Self >::max(); }
1068  static Self min(Self) { return min(); }
1069  static Self max(Self) { return max(); }
1070  static Self NonpositiveMin()
1071  {
1072  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1073  }
1074 
1075  static bool IsPositive(Self val) { return val.real() > 0; }
1076  static bool IsNonpositive(Self val) { return val.real() == 0; }
1077  static bool IsNegative(Self) { return false; }
1078  static bool IsNonnegative(Self) { return true; }
1079  static Self ZeroValue() { return Zero; }
1080  static Self OneValue() { return One; }
1081  static unsigned int GetLength(const Self &) { return 2; }
1082  static unsigned int GetLength() { return 2; }
1083  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1084  static Self ZeroValue(const Self &) { return ZeroValue(); }
1085  static Self OneValue(const Self &) { return OneValue(); }
1086  template<class TArray>
1087  static void AssignToArray( const Self & v, TArray & mv )
1088  {
1089  mv[0] = v.real();
1090  mv[1] = v.imag();
1091  }
1092  static void SetLength(Self &, const unsigned int s)
1093  {
1094  if ( s != 2 )
1095  {
1096  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1097  }
1098  }
1099 };
1100 
1106 template< >
1107 class NumericTraits< std::complex< int > >
1108 {
1109 public:
1110  typedef std::complex< int > Self;
1111  // for backward compatibility
1112  typedef Self TheType;
1113  typedef int ValueType;
1114  typedef Self PrintType;
1115  typedef double AbsType;
1116  typedef Self AccumulateType;
1117  typedef std::complex< double > RealType;
1118  typedef double ScalarRealType;
1119  typedef std::complex< float > FloatType;
1120  typedef FixedArray<int, 2> MeasurementVectorType;
1121 
1122  static const Self ITKCommon_EXPORT Zero;
1123  static const Self ITKCommon_EXPORT One;
1124 
1125  static Self min() { return vcl_numeric_limits< Self >::min(); }
1126  static Self max() { return vcl_numeric_limits< Self >::max(); }
1127  static Self min(Self) { return min(); }
1128  static Self max(Self) { return max(); }
1129  static Self NonpositiveMin()
1130  {
1131  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1132  }
1133 
1134  static bool IsPositive(Self val) { return val.real() > 0; }
1135  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1136  static bool IsNegative(Self val) { return val.real() < 0; }
1137  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1138  static Self ZeroValue() { return Zero; }
1139  static Self OneValue() { return One; }
1140  static unsigned int GetLength(const Self &) { return 2; }
1141  static unsigned int GetLength() { return 2; }
1142  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1143  static Self ZeroValue(const Self &) { return ZeroValue(); }
1144  static Self OneValue(const Self &) { return OneValue(); }
1145  template<class TArray>
1146  static void AssignToArray( const Self & v, TArray & mv )
1147  {
1148  mv[0] = v.real();
1149  mv[1] = v.imag();
1150  }
1151  static void SetLength(Self &, const unsigned int s)
1152  {
1153  if ( s != 2 )
1154  {
1155  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1156  }
1157  }
1158 };
1159 
1165 template< >
1166 class NumericTraits< std::complex< unsigned int > >
1167 {
1168 public:
1169  typedef std::complex< unsigned int > Self;
1170  // for backward compatibility
1171  typedef Self TheType;
1172  typedef unsigned int ValueType;
1173  typedef Self PrintType;
1174  typedef double AbsType;
1175  typedef Self AccumulateType;
1176  typedef std::complex< double > RealType;
1177  typedef double ScalarRealType;
1178  typedef std::complex< float > FloatType;
1179  typedef FixedArray<unsigned int, 2> MeasurementVectorType;
1180 
1181  static const Self ITKCommon_EXPORT Zero;
1182  static const Self ITKCommon_EXPORT One;
1183 
1184  static Self min() { return vcl_numeric_limits< Self >::min(); }
1185  static Self max() { return vcl_numeric_limits< Self >::max(); }
1186  static Self min(Self) { return min(); }
1187  static Self max(Self) { return max(); }
1188  static Self NonpositiveMin()
1189  {
1190  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1191  }
1192 
1193  static bool IsPositive(Self val) { return val.real() > 0; }
1194  static bool IsNonpositive(Self val) { return val.real() == 0; }
1195  static bool IsNegative(Self) { return false; }
1196  static bool IsNonnegative(Self) { return true; }
1197  static Self ZeroValue() { return Zero; }
1198  static Self OneValue() { return One; }
1199  static unsigned int GetLength(const Self &) { return 2; }
1200  static unsigned int GetLength() { return 2; }
1201  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1202  static Self ZeroValue(const Self &) { return ZeroValue(); }
1203  static Self OneValue(const Self &) { return OneValue(); }
1204  template<class TArray>
1205  static void AssignToArray( const Self & v, TArray & mv )
1206  {
1207  mv[0] = v.real();
1208  mv[1] = v.imag();
1209  }
1210  static void SetLength(Self &, const unsigned int s)
1211  {
1212  if ( s != 2 )
1213  {
1214  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1215  }
1216  }
1217 };
1218 
1224 template< >
1225 class NumericTraits< std::complex< long > >
1226 {
1227 public:
1228  typedef std::complex< long > Self;
1229  // for backward compatibility
1230  typedef Self TheType;
1231  typedef long ValueType;
1232  typedef Self PrintType;
1233  typedef double AbsType;
1234  typedef Self AccumulateType;
1235  typedef std::complex< double > RealType;
1236  typedef double ScalarRealType;
1237  typedef std::complex< float > FloatType;
1238  typedef FixedArray<long, 2> MeasurementVectorType;
1239 
1240  static const Self ITKCommon_EXPORT Zero;
1241  static const Self ITKCommon_EXPORT One;
1242 
1243  static Self min() { return vcl_numeric_limits< Self >::min(); }
1244  static Self max() { return vcl_numeric_limits< Self >::max(); }
1245  static Self min(Self) { return min(); }
1246  static Self max(Self) { return max(); }
1247  static Self NonpositiveMin()
1248  {
1249  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1250  }
1251 
1252  static bool IsPositive(Self val) { return val.real() > 0; }
1253  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1254  static bool IsNegative(Self val) { return val.real() < 0; }
1255  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1256  static Self ZeroValue() { return Zero; }
1257  static Self OneValue() { return One; }
1258  static unsigned int GetLength(const Self &) { return 2; }
1259  static unsigned int GetLength() { return 2; }
1260  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1261  static Self ZeroValue(const Self &) { return ZeroValue(); }
1262  static Self OneValue(const Self &) { return OneValue(); }
1263  template<class TArray>
1264  static void AssignToArray( const Self & v, TArray & mv )
1265  {
1266  mv[0] = v.real();
1267  mv[1] = v.imag();
1268  }
1269  static void SetLength(Self &, const unsigned int s)
1270  {
1271  if ( s != 2 )
1272  {
1273  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1274  }
1275  }
1276 };
1277 
1283 template< >
1284 class NumericTraits< std::complex< unsigned long > >
1285 {
1286 public:
1287  typedef std::complex< unsigned long > Self;
1288  // for backward compatibility
1289  typedef Self TheType;
1290  typedef unsigned long ValueType;
1291  typedef Self PrintType;
1292  typedef double AbsType;
1293  typedef Self AccumulateType;
1294  typedef std::complex< double > RealType;
1295  typedef double ScalarRealType;
1296  typedef std::complex< float > FloatType;
1297  typedef FixedArray<unsigned long, 2> MeasurementVectorType;
1298 
1299  static const Self ITKCommon_EXPORT Zero;
1300  static const Self ITKCommon_EXPORT One;
1301 
1302  static Self min() { return vcl_numeric_limits< Self >::min(); }
1303  static Self max() { return vcl_numeric_limits< Self >::max(); }
1304  static Self min(Self) { return min(); }
1305  static Self max(Self) { return max(); }
1306  static Self NonpositiveMin()
1307  {
1308  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1309  }
1310 
1311  static bool IsPositive(Self val) { return val.real() > 0; }
1312  static bool IsNonpositive(Self val) { return val.real() == 0; }
1313  static bool IsNegative(Self) { return false; }
1314  static bool IsNonnegative(Self) { return true; }
1315  static Self ZeroValue() { return Zero; }
1316  static Self OneValue() { return One; }
1317  static unsigned int GetLength(const Self &) { return 2; }
1318  static unsigned int GetLength() { return 2; }
1319  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1320  static Self ZeroValue(const Self &) { return ZeroValue(); }
1321  static Self OneValue(const Self &) { return OneValue(); }
1322  template<class TArray>
1323  static void AssignToArray( const Self & v, TArray & mv )
1324  {
1325  mv[0] = v.real();
1326  mv[1] = v.imag();
1327  }
1328  static void SetLength(Self &, const unsigned int s)
1329  {
1330  if ( s != 2 )
1331  {
1332  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1333  }
1334  }
1335 };
1336 
1342 template< >
1343 class NumericTraits< std::complex< float > >
1344 {
1345 public:
1346  typedef std::complex< float > Self;
1347  // for backward compatibility
1348  typedef Self TheType;
1349  typedef float ValueType;
1350  typedef Self PrintType;
1351  typedef double AbsType;
1352  typedef Self AccumulateType;
1353  typedef std::complex< double > RealType;
1354  typedef double ScalarRealType;
1355  typedef std::complex< float > FloatType;
1356  typedef FixedArray<float, 2> MeasurementVectorType;
1357 
1358  static const Self ITKCommon_EXPORT Zero;
1359  static const Self ITKCommon_EXPORT One;
1360 
1361  static Self min() { return vcl_numeric_limits< Self >::min(); }
1362  static Self max() { return vcl_numeric_limits< Self >::max(); }
1363  static Self min(Self) { return min(); }
1364  static Self max(Self) { return max(); }
1365  static Self NonpositiveMin()
1366  {
1367  return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
1368  }
1369 
1370  static bool IsPositive(Self val) { return val.real() > 0.0; }
1371  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1372  static bool IsNegative(Self val) { return val.real() < 0.0; }
1373  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1374  static Self ZeroValue() { return Zero; }
1375  static Self OneValue() { return One; }
1376  static unsigned int GetLength(const Self &) { return 2; }
1377  static unsigned int GetLength() { return 2; }
1378  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1379  static Self ZeroValue(const Self &) { return ZeroValue(); }
1380  static Self OneValue(const Self &) { return OneValue(); }
1381  template<class TArray>
1382  static void AssignToArray( const Self & v, TArray & mv )
1383  {
1384  mv[0] = v.real();
1385  mv[1] = v.imag();
1386  }
1387  static void SetLength(Self &, const unsigned int s)
1388  {
1389  if ( s != 2 )
1390  {
1391  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1392  }
1393  }
1394 };
1395 
1401 template< >
1402 class NumericTraits< std::complex< double > >
1403 {
1404 public:
1405  typedef std::complex< double > Self;
1406  // for backward compatibility
1407  typedef Self TheType;
1408  typedef double ValueType;
1409  typedef Self PrintType;
1410  typedef double AbsType;
1411  typedef Self AccumulateType;
1412  typedef std::complex< double > RealType;
1413  typedef double ScalarRealType;
1414  typedef std::complex< float > FloatType;
1415  typedef FixedArray<double, 2> MeasurementVectorType;
1416 
1417  static const Self ITKCommon_EXPORT Zero;
1418  static const Self ITKCommon_EXPORT One;
1419 
1420  static Self min() { return vcl_numeric_limits< ValueType >::min(); }
1421  static Self max() { return vcl_numeric_limits< ValueType >::max(); }
1422  static Self min(Self) { return min(); }
1423  static Self max(Self) { return max(); }
1424  static Self NonpositiveMin()
1425  {
1426  return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
1427  }
1428 
1429  static bool IsPositive(Self val) { return val.real() > 0.0; }
1430  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1431  static bool IsNegative(Self val) { return val.real() < 0.0; }
1432  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1433  static Self ZeroValue() { return Zero; }
1434  static Self OneValue() { return One; }
1435  static unsigned int GetLength(const Self &) { return 2; }
1436  static unsigned int GetLength() { return 2; }
1437  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1438  static Self ZeroValue(const Self &) { return ZeroValue(); }
1439  static Self OneValue(const Self &) { return OneValue(); }
1440  template<class TArray>
1441  static void AssignToArray( const Self & v, TArray & mv )
1442  {
1443  mv[0] = v.real();
1444  mv[1] = v.imag();
1445  }
1446  static void SetLength(Self &, const unsigned int s)
1447  {
1448  if ( s != 2 )
1449  {
1450  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1451  }
1452  }
1453 };
1454 
1460 template< >
1461 class NumericTraits< std::complex< long double > >
1462 {
1463 public:
1464  typedef std::complex< long double > Self;
1465  // for backward compatibility
1466  typedef Self TheType;
1467  typedef long double ValueType;
1468  typedef Self PrintType;
1469  typedef long double AbsType;
1470  typedef Self AccumulateType;
1471  typedef std::complex< long double > RealType;
1472  typedef long double ScalarRealType;
1473  typedef std::complex< float > FloatType;
1474  typedef FixedArray<long double, 2> MeasurementVectorType;
1475 
1476  static const Self ITKCommon_EXPORT Zero;
1477  static const Self ITKCommon_EXPORT One;
1478 
1479  static Self min() { return vcl_numeric_limits< ValueType >::min(); }
1480  static Self max() { return vcl_numeric_limits< ValueType >::max(); }
1481  static Self min(Self) { return min(); }
1482  static Self max(Self) { return max(); }
1483  static Self NonpositiveMin()
1484  {
1485  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
1486  }
1487 
1488  static bool IsPositive(Self val) { return val.real() > 0.0; }
1489  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1490  static bool IsNegative(Self val) { return val.real() < 0.0; }
1491  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1492  static Self ZeroValue() { return Zero; }
1493  static Self OneValue() { return One; }
1494  static unsigned int GetLength(const Self &) { return 2; }
1495  static unsigned int GetLength() { return 2; }
1496  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1497  static Self ZeroValue(const Self &) { return ZeroValue(); }
1498  static Self OneValue(const Self &) { return OneValue(); }
1499  template<class TArray>
1500  static void AssignToArray( const Self & v, TArray & mv )
1501  {
1502  mv[0] = v.real();
1503  mv[1] = v.imag();
1504  }
1505  static void SetLength(Self &, const unsigned int s)
1506  {
1507  if ( s != 2 )
1508  {
1509  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1510  }
1511  }
1512 };
1513 
1519 template< >
1520 class NumericTraits< long long > :
1521  public vcl_numeric_limits< long long >
1522 {
1523 public:
1524  typedef long long ValueType;
1525  typedef long long PrintType;
1526  typedef long long AbsType;
1527  typedef long long AccumulateType;
1528  typedef double RealType;
1529  typedef RealType ScalarRealType;
1530  typedef float FloatType;
1531  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1532 
1533  static const ValueType ITKCommon_EXPORT Zero;
1534  static const ValueType ITKCommon_EXPORT One;
1535 
1537  static ValueType NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
1538  static bool IsPositive(ValueType val) { return val > Zero; }
1539  static bool IsNonpositive(ValueType val) { return val <= Zero; }
1540  static bool IsNegative(ValueType val) { return val < Zero; }
1541  static bool IsNonnegative(ValueType val) { return val >= Zero; }
1542  static ValueType ZeroValue() { return Zero; }
1543  static ValueType OneValue() { return One; }
1544  static unsigned int GetLength(const ValueType &) { return 1; }
1545  static unsigned int GetLength() { return 1; }
1546  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1547  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1548  static ValueType OneValue(const ValueType &) { return OneValue(); }
1549 
1550  template<class TArray>
1551  static void AssignToArray( const ValueType & v, TArray & mv )
1552  {
1553  mv[0] = v;
1554  }
1555  static void SetLength(ValueType &, const unsigned int s)
1556  {
1557  if ( s != 1 )
1558  {
1559  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1560  }
1561  }
1562 };
1563 
1569 template< >
1570 class NumericTraits< unsigned long long > :
1571  public vcl_numeric_limits< unsigned long long >
1572 {
1573 public:
1574  typedef unsigned long long ValueType;
1575  typedef unsigned long long PrintType;
1576  typedef unsigned long long AbsType;
1577  typedef unsigned long long AccumulateType;
1578  typedef double RealType;
1579  typedef RealType ScalarRealType;
1580  typedef float FloatType;
1581  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1582 
1583  static const ValueType ITKCommon_EXPORT Zero;
1584  static const ValueType ITKCommon_EXPORT One;
1585 
1587  static ValueType NonpositiveMin() { return vcl_numeric_limits< ValueType >::min(); }
1588  static bool IsPositive(ValueType val) { return val != Zero; }
1589  static bool IsNonpositive(ValueType val) { return val == Zero; }
1590  static bool IsNegative(ValueType) { return false; }
1591  static bool IsNonnegative(ValueType) { return true; }
1592  static ValueType ZeroValue() { return Zero; }
1593  static ValueType OneValue() { return One; }
1594  static unsigned int GetLength(const ValueType &) { return 1; }
1595  static unsigned int GetLength() { return 1; }
1596  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1597  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1598  static ValueType OneValue(const ValueType &) { return OneValue(); }
1599 
1600  template<class TArray>
1601  static void AssignToArray( const ValueType & v, TArray & mv )
1602  {
1603  mv[0] = v;
1604  }
1605  static void SetLength(ValueType &, const unsigned int s)
1606  {
1607  if ( s != 1 )
1608  {
1609  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1610  }
1611  }
1612 };
1613 
1616 } // end namespace itk
1617 
1618 #include "itkFixedArray.h"
1619 
1620 #endif // __itkNumericTraits_h
1621