ITK  4.9.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 std::numeric_limits< ValueType >::min(); \
30  } \
31  static ValueType max() \
32  { \
33  return std::numeric_limits< ValueType >::max(); \
34  } \
35  static ValueType min(ValueType) \
36  { \
37  return std::numeric_limits< ValueType >::min(); \
38  } \
39  static ValueType max(ValueType) \
40  { \
41  return std::numeric_limits< ValueType >::max(); \
42  } \
43 
44 
45 #include "vcl_limits.h" // for std::numeric_limits
46 #include <complex>
47 
48 namespace itk
49 {
50 
51 // forward decare to avoid circular dependencies
52 template< typename TValue, unsigned int VLength> class FixedArray;
53 
69 template< typename T >
70 class NumericTraits:public std::numeric_limits< T >
71 {
72 public:
74  typedef std::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 
125  static const bool IsSigned = false;
126 
130  static const bool IsInteger = false;
131 
135  static const bool IsComplex = false;
136 
139  static T ZeroValue() { return Zero; }
140 
143  static T OneValue() { return One; }
144 
145  /* Provide a default implementation of the max() method with
146  * argument. This API is needed for VariableLengthVector because
147  * its length is only known at run-time. Specializations of the
148  * VariableLengthVector will provide a different implementation
149  * where a vector of the correct size is built. */
150  static T max(const T &) { return TraitsType::max(); }
151  static T min(const T &) { return TraitsType::min(); }
152 
160  static void SetLength(T & m, const unsigned int s)
161  {
162  if ( s != 1 )
163  {
164  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
165  }
167  }
168 
175  static unsigned int GetLength(const T &)
176  {
177  return GetLength();
178  }
179 
181  static unsigned int GetLength()
182  {
183  return 1;
184  }
185 
189  static T NonpositiveMin(const T &)
190  {
191  return NonpositiveMin();
192  }
193 
197  static T ZeroValue(const T &)
198  {
199  return ZeroValue();
200  }
201 
205  static T OneValue(const T &)
206  {
207  return OneValue();
208  }
209 
211  template<typename TArray>
212  static void AssignToArray( const T & v, TArray & mv )
213  {
214  mv[0] = v;
215  }
216 
217 };
218 
220 
228 template< >
229 class NumericTraits< bool > :public std::numeric_limits< bool >
230 {
231 public:
232  typedef bool ValueType;
233  typedef bool PrintType;
234  typedef unsigned char AbsType;
235  typedef unsigned char AccumulateType;
236  typedef double RealType;
237  typedef RealType ScalarRealType;
238  typedef float FloatType;
239  typedef FixedArray<ValueType, 1> MeasurementVectorType;
240 
241  static const bool ITKCommon_EXPORT Zero;
242  static const bool ITKCommon_EXPORT One;
243 
244  static bool min() { return false; }
245  static bool max() { return true; }
246  static bool min(bool) { return min(); }
247  static bool max(bool) { return max(); }
248  static bool NonpositiveMin() { return false; }
249  static bool IsPositive(bool val) { return val; }
250  static bool IsNonpositive(bool val) { return !val; }
251  static bool IsNegative(bool val) { return val ? false : false; }
252  static bool IsNonnegative(bool val) { return val ? true : true; }
253  static const bool IsSigned = false;
254  static const bool IsInteger = true;
255  static const bool IsComplex = false;
256  static bool ZeroValue() { return Zero; }
257  static bool OneValue() { return One; }
258  static unsigned int GetLength(const ValueType &) { return 1; }
259  static unsigned int GetLength() { return 1; }
260  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
261  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
262  static ValueType OneValue(const ValueType &) { return OneValue(); }
263 
264  template<typename TArray>
265  static void AssignToArray( const ValueType & v, TArray & mv )
266  {
267  mv[0] = v;
268  }
269  static void SetLength(ValueType & m, const unsigned int s)
270  {
271  if ( s != 1 )
272  {
273  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
274  }
276  }
277 
278 };
279 
285 template< >
286 class NumericTraits< char > :public std::numeric_limits< char >
287 {
288 public:
289  typedef char ValueType;
290  typedef int PrintType;
291  typedef unsigned char AbsType;
292  typedef short AccumulateType;
293  typedef double RealType;
294  typedef RealType ScalarRealType;
295  typedef float FloatType;
296  typedef FixedArray<ValueType, 1> MeasurementVectorType;
297 
298  static const char ITKCommon_EXPORT Zero;
299  static const char ITKCommon_EXPORT One;
300 
301  static char min() { return char(255) < char(0) ? char(-128) : char(0); }
302  static char max() { return char(255) < char(0) ? char(127) : char(255); }
303 
304  static char min(char) { return min(); }
305  static char max(char) { return max(); }
306  static char NonpositiveMin() { return min(); }
307  static bool IsPositive(char val) { return val > Zero; }
308  static bool IsNonpositive(char val) { return val <= Zero; }
309 // char on PowerPC, for example, is not signed
310 #if VCL_CHAR_IS_SIGNED
311  static bool IsNegative(char val) { return val < Zero; }
312  static bool IsNonnegative(char val) { return val >= Zero; }
313  static const bool IsSigned = true;
314 #else
315  static bool IsNegative(char) { return false; }
316  static bool IsNonnegative(char) { return true; }
317  static const bool IsSigned = false;
318 #endif
319  static const bool IsInteger = true;
320  static const bool IsComplex = false;
321  static char ZeroValue() { return Zero; }
322  static char OneValue() { return One; }
323  static unsigned int GetLength(const ValueType &) { return 1; }
324  static unsigned int GetLength() { return 1; }
325  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
326  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
327  static ValueType OneValue(const ValueType &) { return OneValue(); }
328 
329  template<typename TArray>
330  static void AssignToArray( const ValueType & v, TArray & mv )
331  {
332  mv[0] = v;
333  }
334  static void SetLength(ValueType & m, const unsigned int s)
335  {
336  if ( s != 1 )
337  {
338  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
339  }
341  }
342 };
343 
349 template< >
350 class NumericTraits< signed char > :public std::numeric_limits< signed char >
351 {
352 public:
353  typedef signed char ValueType;
354  typedef int PrintType;
355  typedef unsigned char AbsType;
356  typedef short AccumulateType;
357  typedef double RealType;
358  typedef RealType ScalarRealType;
359  typedef float FloatType;
360  typedef FixedArray<ValueType, 1> MeasurementVectorType;
361 
362  static const signed char ITKCommon_EXPORT Zero;
363  static const signed char ITKCommon_EXPORT One;
364 
365  static signed char min() { return -128; }
366  static signed char max() { return 127; }
367  static signed char min(signed char) { return min(); }
368  static signed char max(signed char) { return max(); }
369  static signed char NonpositiveMin() { return min(); }
370  static bool IsPositive(signed char val) { return val > Zero; }
371  static bool IsNonpositive(signed char val) { return val <= Zero; }
372  static bool IsNegative(signed char val) { return val < Zero; }
373  static bool IsNonnegative(signed char val) { return val >= Zero; }
374  static const bool IsSigned = true;
375  static const bool IsInteger = true;
376  static const bool IsComplex = false;
377  static signed char ZeroValue() { return Zero; }
378  static signed char OneValue() { return One; }
379  static unsigned int GetLength(const ValueType &) { return 1; }
380  static unsigned int GetLength() { return 1; }
381  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
382  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
383  static ValueType OneValue(const ValueType &) { return OneValue(); }
384 
385  template<typename TArray>
386  static void AssignToArray( const ValueType & v, TArray & mv )
387  {
388  mv[0] = v;
389  }
390  static void SetLength(ValueType & m, const unsigned int s)
391  {
392  if ( s != 1 )
393  {
394  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
395  }
397  }
398 };
399 
405 template< >
406 class NumericTraits< unsigned char > :public std::numeric_limits< unsigned char >
407 {
408 public:
409  typedef unsigned char ValueType;
410  typedef int PrintType;
411  typedef unsigned char AbsType;
412  typedef unsigned short AccumulateType;
413  typedef double RealType;
414  typedef RealType ScalarRealType;
415  typedef float FloatType;
416  typedef FixedArray<ValueType, 1> MeasurementVectorType;
417 
418  static const unsigned char ITKCommon_EXPORT Zero;
419  static const unsigned char ITKCommon_EXPORT One;
420 
422 
423  static unsigned char NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
424  static bool IsPositive(unsigned char val) { return val != Zero; }
425  static bool IsNonpositive(unsigned char val) { return val == Zero; }
426  static bool IsNegative(unsigned char val) { return val ? false : false; }
427  static bool IsNonnegative(unsigned char val) { return val ? true : true; }
428  static const bool IsSigned = false;
429  static const bool IsInteger = true;
430  static const bool IsComplex = false;
431  static unsigned char ZeroValue() { return Zero; }
432  static unsigned char OneValue() { return One; }
433  static unsigned int GetLength(const ValueType &) { return 1; }
434  static unsigned int GetLength() { return 1; }
435  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
436  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
437  static ValueType OneValue(const ValueType &) { return OneValue(); }
438 
439  template<typename TArray>
440  static void AssignToArray( const ValueType & v, TArray & mv )
441  {
442  mv[0] = v;
443  }
444  static void SetLength(ValueType & m, const unsigned int s)
445  {
446  if ( s != 1 )
447  {
448  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
449  }
451  }
452 };
453 
458 template< >
459 class NumericTraits< short > :public std::numeric_limits< short >
460 {
461 public:
462  typedef short ValueType;
463  typedef short PrintType;
464  typedef unsigned short AbsType;
465  typedef int AccumulateType;
466  typedef double RealType;
467  typedef RealType ScalarRealType;
468  typedef float FloatType;
469  typedef FixedArray<ValueType, 1> MeasurementVectorType;
470 
471  static const short ITKCommon_EXPORT Zero;
472  static const short ITKCommon_EXPORT One;
473 
475  static short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
476  static bool IsPositive(short val) { return val > Zero; }
477  static bool IsNonpositive(short val) { return val <= Zero; }
478  static bool IsNegative(short val) { return val < Zero; }
479  static bool IsNonnegative(short val) { return val >= Zero; }
480  static const bool IsSigned = true;
481  static const bool IsInteger = true;
482  static const bool IsComplex = false;
483  static short ZeroValue() { return Zero; }
484  static short OneValue() { return One; }
485  static unsigned int GetLength(const ValueType &) { return 1; }
486  static unsigned int GetLength() { return 1; }
487  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
488  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
489  static ValueType OneValue(const ValueType &) { return OneValue(); }
490 
491  template<typename TArray>
492  static void AssignToArray( const ValueType & v, TArray & mv )
493  {
494  mv[0] = v;
495  }
496  static void SetLength(ValueType & m, const unsigned int s)
497  {
498  if ( s != 1 )
499  {
500  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
501  }
503  }
504 };
505 
511 template< >
512 class NumericTraits< unsigned short > :public std::numeric_limits< unsigned short >
513 {
514 public:
515  typedef unsigned short ValueType;
516  typedef unsigned short PrintType;
517  typedef unsigned short AbsType;
518  typedef unsigned int AccumulateType;
519  typedef double RealType;
520  typedef RealType ScalarRealType;
521  typedef float FloatType;
522  typedef FixedArray<ValueType, 1> MeasurementVectorType;
523 
524  static const unsigned short ITKCommon_EXPORT Zero;
525  static const unsigned short ITKCommon_EXPORT One;
526 
528  static unsigned short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
529  static bool IsPositive(unsigned short val) { return val != Zero; }
530  static bool IsNonpositive(unsigned short val) { return val == Zero; }
531  static bool IsNegative(unsigned short val) { return val ? false : false; }
532  static bool IsNonnegative(unsigned short val) { return val ? true : true; }
533  static const bool IsSigned = false;
534  static const bool IsInteger = true;
535  static const bool IsComplex = false;
536  static unsigned short ZeroValue() { return Zero; }
537  static unsigned short OneValue() { return One; }
538  static unsigned int GetLength(const ValueType &) { return 1; }
539  static unsigned int GetLength() { return 1; }
540  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
541  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
542  static ValueType OneValue(const ValueType &) { return OneValue(); }
543 
544  template<typename TArray>
545  static void AssignToArray( const ValueType & v, TArray & mv )
546  {
547  mv[0] = v;
548  }
549  static void SetLength(ValueType & m, const unsigned int s)
550  {
551  if ( s != 1 )
552  {
553  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
554  }
556  }
557 };
558 
563 template< >
564 class NumericTraits< int > :public std::numeric_limits< int >
565 {
566 public:
567  typedef int ValueType;
568  typedef int PrintType;
569  typedef unsigned int AbsType;
570  typedef long AccumulateType;
571  typedef double RealType;
572  typedef RealType ScalarRealType;
573  typedef float FloatType;
574  typedef FixedArray<ValueType, 1> MeasurementVectorType;
575 
576  static const int ITKCommon_EXPORT Zero;
577  static const int ITKCommon_EXPORT One;
578 
580  static int NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
581  static bool IsPositive(int val) { return val > Zero; }
582  static bool IsNonpositive(int val) { return val <= Zero; }
583  static bool IsNegative(int val) { return val < Zero; }
584  static bool IsNonnegative(int val) { return val >= Zero; }
585  static const bool IsSigned = true;
586  static const bool IsInteger = true;
587  static const bool IsComplex = false;
588  static int ZeroValue() { return Zero; }
589  static int OneValue() { return One; }
590  static unsigned int GetLength(const ValueType &) { return 1; }
591  static unsigned int GetLength() { return 1; }
592  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
593  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
594  static ValueType OneValue(const ValueType &) { return OneValue(); }
595 
596  template<typename TArray>
597  static void AssignToArray( const ValueType & v, TArray & mv )
598  {
599  mv[0] = v;
600  }
601  static void SetLength(ValueType & m, const unsigned int s)
602  {
603  if ( s != 1 )
604  {
605  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
606  }
608  }
609 };
610 
616 template< >
617 class NumericTraits< unsigned int > :public std::numeric_limits< unsigned int >
618 {
619 public:
620  typedef unsigned int ValueType;
621  typedef unsigned int PrintType;
622  typedef unsigned int AbsType;
623  typedef unsigned int AccumulateType;
624  typedef double RealType;
625  typedef RealType ScalarRealType;
626  typedef float FloatType;
627  typedef FixedArray<ValueType, 1> MeasurementVectorType;
628 
629  static const unsigned int ITKCommon_EXPORT Zero;
630  static const unsigned int ITKCommon_EXPORT One;
631 
632  static unsigned int min(void) { return 0; }
633  static unsigned int max(void) { return static_cast< unsigned int >( -1 ); }
634  static unsigned int min(unsigned int) { return std::numeric_limits< ValueType >::min(); }
635  static unsigned int max(unsigned int) { return std::numeric_limits< ValueType >::max(); }
636  static unsigned int NonpositiveMin() { return 0; }
637  static bool IsPositive(unsigned int val) { return val != Zero; }
638  static bool IsNonpositive(unsigned int val) { return val == Zero; }
639  static bool IsNegative(unsigned int val) { return val ? false : false; }
640  static bool IsNonnegative(unsigned int val) { return val ? true : true; }
641  static const bool IsSigned = false;
642  static const bool IsInteger = true;
643  static const bool IsComplex = false;
644  static unsigned int ZeroValue() { return Zero; }
645  static unsigned int OneValue() { return One; }
646  static unsigned int GetLength(const ValueType &) { return 1; }
647  static unsigned int GetLength() { return 1; }
648  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
649  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
650  static ValueType OneValue(const ValueType &) { return OneValue(); }
651 
652  template<typename TArray>
653  static void AssignToArray( const ValueType & v, TArray & mv )
654  {
655  mv[0] = v;
656  }
657  static void SetLength(ValueType & m, const unsigned int s)
658  {
659  if ( s != 1 )
660  {
661  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
662  }
664  }
665 };
666 
672 template< >
673 class NumericTraits< long > :public std::numeric_limits< long >
674 {
675 public:
676  typedef long ValueType;
677  typedef long PrintType;
678  typedef unsigned long AbsType;
679  typedef long AccumulateType;
680  typedef double RealType;
681  typedef RealType ScalarRealType;
682  typedef float FloatType;
683  typedef FixedArray<ValueType, 1> MeasurementVectorType;
684 
685  static const long ITKCommon_EXPORT Zero;
686  static const long ITKCommon_EXPORT One;
687 
689  static long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
690  static bool IsPositive(long val) { return val > Zero; }
691  static bool IsNonpositive(long val) { return val <= Zero; }
692  static bool IsNegative(long val) { return val < Zero; }
693  static bool IsNonnegative(long val) { return val >= Zero; }
694  static const bool IsSigned = true;
695  static const bool IsInteger = true;
696  static const bool IsComplex = false;
697  static long ZeroValue() { return Zero; }
698  static long OneValue() { return One; }
699  static unsigned int GetLength(const ValueType &) { return 1; }
700  static unsigned int GetLength() { return 1; }
701  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
702  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
703  static ValueType OneValue(const ValueType &) { return OneValue(); }
704 
705  template<typename TArray>
706  static void AssignToArray( const ValueType & v, TArray & mv )
707  {
708  mv[0] = v;
709  }
710  static void SetLength(ValueType & m, const unsigned int s)
711  {
712  if ( s != 1 )
713  {
714  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
715  }
717  }
718 };
719 
725 template< >
726 class NumericTraits< unsigned long > :public std::numeric_limits< unsigned long >
727 {
728 public:
729  typedef unsigned long ValueType;
730  typedef unsigned long PrintType;
731  typedef unsigned long AbsType;
732  typedef unsigned long AccumulateType;
733  typedef double RealType;
734  typedef RealType ScalarRealType;
735  typedef float FloatType;
736  typedef FixedArray<ValueType, 1> MeasurementVectorType;
737 
738  static const unsigned long ITKCommon_EXPORT Zero;
739  static const unsigned long ITKCommon_EXPORT One;
740 
742  static unsigned long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
743  static bool IsPositive(unsigned long val) { return val != Zero; }
744  static bool IsNonpositive(unsigned long val) { return val == Zero; }
745  static bool IsNegative(unsigned long) { return false; }
746  static bool IsNonnegative(unsigned long) { return true; }
747  static const bool IsSigned = false;
748  static const bool IsInteger = true;
749  static const bool IsComplex = false;
750  static unsigned long ZeroValue() { return Zero; }
751  static unsigned long OneValue() { return One; }
752  static unsigned int GetLength(const ValueType &) { return 1; }
753  static unsigned int GetLength() { return 1; }
754  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
755  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
756  static ValueType OneValue(const ValueType &) { return OneValue(); }
757 
758  template<typename TArray>
759  static void AssignToArray( const ValueType & v, TArray & mv )
760  {
761  mv[0] = v;
762  }
763  static void SetLength(ValueType & m, const unsigned int s)
764  {
765  if ( s != 1 )
766  {
767  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
768  }
770  }
771 };
772 
778 template< >
779 class NumericTraits< float > :public std::numeric_limits< float >
780 {
781 public:
782  typedef float ValueType;
783  typedef float PrintType;
784  typedef float AbsType;
785  typedef double AccumulateType;
786  typedef double RealType;
787  typedef RealType ScalarRealType;
788  typedef float FloatType;
789  typedef FixedArray<ValueType, 1> MeasurementVectorType;
790 
791  static const float ITKCommon_EXPORT Zero;
792  static const float ITKCommon_EXPORT One;
793 
795  static float NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
796  static bool IsPositive(float val) { return val > Zero; }
797  static bool IsNonpositive(float val) { return val <= Zero; }
798  static bool IsNegative(float val) { return val < Zero; }
799  static bool IsNonnegative(float val) { return val >= Zero; }
800  static const bool IsSigned = true;
801  static const bool IsInteger = false;
802  static const bool IsComplex = false;
803  static float ZeroValue() { return Zero; }
804  static float OneValue() { return One; }
805  static unsigned int GetLength(const ValueType &) { return 1; }
806  static unsigned int GetLength() { return 1; }
807  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
808  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
809  static ValueType OneValue(const ValueType &) { return OneValue(); }
810 
811  template<typename TArray>
812  static void AssignToArray( const ValueType & v, TArray & mv )
813  {
814  mv[0] = v;
815  }
816  static void SetLength(ValueType & m, const unsigned int s)
817  {
818  if ( s != 1 )
819  {
820  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
821  }
823  }
824 };
825 
831 template< >
832 class NumericTraits< double > :public std::numeric_limits< double >
833 {
834 public:
835  typedef double ValueType;
836  typedef double PrintType;
837  typedef double AbsType;
838  typedef double AccumulateType;
839  typedef double RealType;
840  typedef RealType ScalarRealType;
841  typedef float FloatType;
842  typedef FixedArray<ValueType, 1> MeasurementVectorType;
843 
844  static const double ITKCommon_EXPORT Zero;
845  static const double ITKCommon_EXPORT One;
846 
848  static double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
849  static bool IsPositive(double val) { return val > Zero; }
850  static bool IsNonpositive(double val) { return val <= Zero; }
851  static bool IsNegative(double val) { return val < Zero; }
852  static bool IsNonnegative(double val) { return val >= Zero; }
853  static const bool IsSigned = true;
854  static const bool IsInteger = false;
855  static const bool IsComplex = false;
856  static double ZeroValue() { return Zero; }
857  static double OneValue() { return One; }
858  static unsigned int GetLength(const ValueType &) { return 1; }
859  static unsigned int GetLength() { return 1; }
860  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
861  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
862  static ValueType OneValue(const ValueType &) { return OneValue(); }
863 
864  template<typename TArray>
865  static void AssignToArray( const ValueType & v, TArray & mv )
866  {
867  mv[0] = v;
868  }
869  static void SetLength(ValueType & m, const unsigned int s)
870  {
871  if ( s != 1 )
872  {
873  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
874  }
876  }
877 };
878 
884 template< >
885 class NumericTraits< long double > :public std::numeric_limits< long double >
886 {
887 public:
888  typedef long double ValueType;
889 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
890  // sun studio in 32 bit mode is unable to print long double values: it
891  // segfaults.
892  // conversion to double will give usable results if the value is in the double
893  // range - better than nothing.
894  typedef double PrintType;
895 #else
896  typedef long double PrintType;
897 #endif
898  typedef long double AbsType;
899  typedef long double AccumulateType;
900  typedef long double RealType;
901  typedef RealType ScalarRealType;
902  typedef float FloatType;
903  typedef FixedArray<ValueType, 1> MeasurementVectorType;
904 
905  static const long double ITKCommon_EXPORT Zero;
906  static const long double ITKCommon_EXPORT One;
907 
909  static long double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
910  static bool IsPositive(long double val) { return val > Zero; }
911  static bool IsNonpositive(long double val) { return val <= Zero; }
912  static bool IsNegative(long double val) { return val < Zero; }
913  static bool IsNonnegative(long double val) { return val >= Zero; }
914  static const bool IsSigned = true;
915  static const bool IsInteger = false;
916  static const bool IsComplex = false;
917  static long double ZeroValue() { return Zero; }
918  static long double OneValue() { return One; }
919  static unsigned int GetLength(const ValueType &) { return 1; }
920  static unsigned int GetLength() { return 1; }
921  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
922  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
923  static ValueType OneValue(const ValueType &) { return OneValue(); }
924 
925  template<typename TArray>
926  static void AssignToArray( const ValueType & v, TArray & mv )
927  {
928  mv[0] = v;
929  }
930  static void SetLength(ValueType & m, const unsigned int s)
931  {
932  if ( s != 1 )
933  {
934  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
935  }
937  }
938 };
939 
945 template< >
946 class NumericTraits< std::complex< char > >
947 {
948 public:
949  typedef std::complex< char > Self;
950  // for backward compatibility
951  typedef Self TheType;
952  typedef char ValueType;
953  typedef std::complex< int > PrintType;
954  typedef double AbsType;
955  typedef Self AccumulateType;
956  typedef std::complex< double > RealType;
957  typedef double ScalarRealType;
958  typedef std::complex< float > FloatType;
959  typedef FixedArray<char, 2> MeasurementVectorType;
960 
961  static const Self ITKCommon_EXPORT Zero;
962  static const Self ITKCommon_EXPORT One;
963 
964  static Self min() { return std::numeric_limits< Self >::min(); }
965  static Self max() { return std::numeric_limits< Self >::max(); }
966  static Self min(Self) { return min(); }
967  static Self max(Self) { return max(); }
968  static Self NonpositiveMin()
969  {
970  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
971  }
972 
973  static bool IsPositive(Self val) { return val.real() > 0; }
974  static bool IsNonpositive(Self val) { return val.real() <= 0; }
975 // char on PowerPC, for example, is not signed
976 #if VCL_CHAR_IS_SIGNED
977  static bool IsNegative(Self val) { return val.real() < 0; }
978  static bool IsNonnegative(Self val) { return val.real() >= 0; }
979 #else
980  static bool IsNegative(Self) { return false; }
981  static bool IsNonnegative(Self) { return true; }
982 #endif
983  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
984  static const bool IsInteger = false;
985  static const bool IsComplex = true;
986  static Self ZeroValue() { return Zero; }
987  static Self OneValue() { return One; }
988  static unsigned int GetLength(const Self &) { return 2; }
989  static unsigned int GetLength() { return 2; }
990  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
991  static Self ZeroValue(const Self &) { return ZeroValue(); }
992  static Self OneValue(const Self &) { return OneValue(); }
993  template<typename TArray>
994  static void AssignToArray( const Self & v, TArray & mv )
995  {
996  mv[0] = v.real();
997  mv[1] = v.imag();
998  }
999  static void SetLength(Self & m, const unsigned int s)
1000  {
1001  if ( s != 2 )
1002  {
1003  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1004  }
1006  }
1007 };
1008 
1014 template< >
1015 class NumericTraits< std::complex< unsigned char > >
1016 {
1017 public:
1018  typedef std::complex< unsigned char > Self;
1019  // for backward compatibility
1020  typedef Self TheType;
1021  typedef unsigned char ValueType;
1022  typedef std::complex< unsigned int > PrintType;
1023  typedef double AbsType;
1024  typedef Self AccumulateType;
1025  typedef std::complex< double > RealType;
1026  typedef double ScalarRealType;
1027  typedef std::complex< float > FloatType;
1028  typedef FixedArray<unsigned char, 2> MeasurementVectorType;
1029 
1030  static const Self ITKCommon_EXPORT Zero;
1031  static const Self ITKCommon_EXPORT One;
1032 
1033  static Self min() { return std::numeric_limits< Self >::min(); }
1034  static Self max() { return std::numeric_limits< Self >::max(); }
1035  static Self min(Self) { return min(); }
1036  static Self max(Self) { return max(); }
1037  static Self NonpositiveMin()
1038  {
1039  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1040  }
1041 
1042  static bool IsPositive(Self val) { return val.real() > 0; }
1043  static bool IsNonpositive(Self val) { return val.real() == 0; }
1044  static bool IsNegative(Self) { return false; }
1045  static bool IsNonnegative(Self) { return true; }
1046  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1047  static const bool IsInteger = false;
1048  static const bool IsComplex = true;
1049  static Self ZeroValue() { return Zero; }
1050  static Self OneValue() { return One; }
1051  static unsigned int GetLength(const Self &) { return 2; }
1052  static unsigned int GetLength() { return 2; }
1053  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1054  static Self ZeroValue(const Self &) { return ZeroValue(); }
1055  static Self OneValue(const Self &) { return OneValue(); }
1056  template<typename TArray>
1057  static void AssignToArray( const Self & v, TArray & mv )
1058  {
1059  mv[0] = v.real();
1060  mv[1] = v.imag();
1061  }
1062  static void SetLength(Self & m, const unsigned int s)
1063  {
1064  if ( s != 2 )
1065  {
1066  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1067  }
1069  }
1070 };
1071 
1077 template< >
1078 class NumericTraits< std::complex< short > >
1079 {
1080 public:
1081  typedef std::complex< short > Self;
1082  // for backward compatibility
1083  typedef Self TheType;
1084  typedef short ValueType;
1085  typedef Self PrintType;
1086  typedef double AbsType;
1087  typedef Self AccumulateType;
1088  typedef std::complex< double > RealType;
1089  typedef double ScalarRealType;
1090  typedef std::complex< float > FloatType;
1091  typedef FixedArray<short, 2> MeasurementVectorType;
1092 
1093  static const Self ITKCommon_EXPORT Zero;
1094  static const Self ITKCommon_EXPORT One;
1095 
1096  static Self min() { return std::numeric_limits< Self >::min(); }
1097  static Self max() { return std::numeric_limits< Self >::max(); }
1098  static Self min(Self) { return min(); }
1099  static Self max(Self) { return max(); }
1100  static Self NonpositiveMin()
1101  {
1102  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1103  }
1104 
1105  static bool IsPositive(Self val) { return val.real() > 0; }
1106  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1107  static bool IsNegative(Self val) { return val.real() < 0; }
1108  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1109  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1110  static const bool IsInteger = false;
1111  static const bool IsComplex = true;
1112  static Self ZeroValue() { return Zero; }
1113  static Self OneValue() { return One; }
1114  static unsigned int GetLength(const Self &) { return 2; }
1115  static unsigned int GetLength() { return 2; }
1116  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1117  static Self ZeroValue(const Self &) { return ZeroValue(); }
1118  static Self OneValue(const Self &) { return OneValue(); }
1119  template<typename TArray>
1120  static void AssignToArray( const Self & v, TArray & mv )
1121  {
1122  mv[0] = v.real();
1123  mv[1] = v.imag();
1124  }
1125  static void SetLength(Self & m, const unsigned int s)
1126  {
1127  if ( s != 2 )
1128  {
1129  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1130  }
1132  }
1133 };
1134 
1140 template< >
1141 class NumericTraits< std::complex< unsigned short > >
1142 {
1143 public:
1144  typedef std::complex< unsigned short > Self;
1145  // for backward compatibility
1146  typedef Self TheType;
1147  typedef unsigned short ValueType;
1148  typedef Self PrintType;
1149  typedef double AbsType;
1150  typedef Self AccumulateType;
1151  typedef std::complex< double > RealType;
1152  typedef double ScalarRealType;
1153  typedef std::complex< float > FloatType;
1154  typedef FixedArray<unsigned short, 2> MeasurementVectorType;
1155 
1156  static const Self ITKCommon_EXPORT Zero;
1157  static const Self ITKCommon_EXPORT One;
1158 
1159  static Self min() { return std::numeric_limits< Self >::min(); }
1160  static Self max() { return std::numeric_limits< Self >::max(); }
1161  static Self min(Self) { return min(); }
1162  static Self max(Self) { return max(); }
1163  static Self NonpositiveMin()
1164  {
1165  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1166  }
1167 
1168  static bool IsPositive(Self val) { return val.real() > 0; }
1169  static bool IsNonpositive(Self val) { return val.real() == 0; }
1170  static bool IsNegative(Self) { return false; }
1171  static bool IsNonnegative(Self) { return true; }
1172  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1173  static const bool IsInteger = false;
1174  static const bool IsComplex = true;
1175  static Self ZeroValue() { return Zero; }
1176  static Self OneValue() { return One; }
1177  static unsigned int GetLength(const Self &) { return 2; }
1178  static unsigned int GetLength() { return 2; }
1179  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1180  static Self ZeroValue(const Self &) { return ZeroValue(); }
1181  static Self OneValue(const Self &) { return OneValue(); }
1182  template<typename TArray>
1183  static void AssignToArray( const Self & v, TArray & mv )
1184  {
1185  mv[0] = v.real();
1186  mv[1] = v.imag();
1187  }
1188  static void SetLength(Self & m, const unsigned int s)
1189  {
1190  if ( s != 2 )
1191  {
1192  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1193  }
1195  }
1196 };
1197 
1203 template< >
1204 class NumericTraits< std::complex< int > >
1205 {
1206 public:
1207  typedef std::complex< int > Self;
1208  // for backward compatibility
1209  typedef Self TheType;
1210  typedef int ValueType;
1211  typedef Self PrintType;
1212  typedef double AbsType;
1213  typedef Self AccumulateType;
1214  typedef std::complex< double > RealType;
1215  typedef double ScalarRealType;
1216  typedef std::complex< float > FloatType;
1217  typedef FixedArray<int, 2> MeasurementVectorType;
1218 
1219  static const Self ITKCommon_EXPORT Zero;
1220  static const Self ITKCommon_EXPORT One;
1221 
1222  static Self min() { return std::numeric_limits< Self >::min(); }
1223  static Self max() { return std::numeric_limits< Self >::max(); }
1224  static Self min(Self) { return min(); }
1225  static Self max(Self) { return max(); }
1226  static Self NonpositiveMin()
1227  {
1228  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1229  }
1230 
1231  static bool IsPositive(Self val) { return val.real() > 0; }
1232  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1233  static bool IsNegative(Self val) { return val.real() < 0; }
1234  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1235  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1236  static const bool IsInteger = false;
1237  static const bool IsComplex = true;
1238  static Self ZeroValue() { return Zero; }
1239  static Self OneValue() { return One; }
1240  static unsigned int GetLength(const Self &) { return 2; }
1241  static unsigned int GetLength() { return 2; }
1242  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1243  static Self ZeroValue(const Self &) { return ZeroValue(); }
1244  static Self OneValue(const Self &) { return OneValue(); }
1245  template<typename TArray>
1246  static void AssignToArray( const Self & v, TArray & mv )
1247  {
1248  mv[0] = v.real();
1249  mv[1] = v.imag();
1250  }
1251  static void SetLength(Self & m, const unsigned int s)
1252  {
1253  if ( s != 2 )
1254  {
1255  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1256  }
1258  }
1259 };
1260 
1266 template< >
1267 class NumericTraits< std::complex< unsigned int > >
1268 {
1269 public:
1270  typedef std::complex< unsigned int > Self;
1271  // for backward compatibility
1272  typedef Self TheType;
1273  typedef unsigned int ValueType;
1274  typedef Self PrintType;
1275  typedef double AbsType;
1276  typedef Self AccumulateType;
1277  typedef std::complex< double > RealType;
1278  typedef double ScalarRealType;
1279  typedef std::complex< float > FloatType;
1280  typedef FixedArray<unsigned int, 2> MeasurementVectorType;
1281 
1282  static const Self ITKCommon_EXPORT Zero;
1283  static const Self ITKCommon_EXPORT One;
1284 
1285  static Self min() { return std::numeric_limits< Self >::min(); }
1286  static Self max() { return std::numeric_limits< Self >::max(); }
1287  static Self min(Self) { return min(); }
1288  static Self max(Self) { return max(); }
1289  static Self NonpositiveMin()
1290  {
1291  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1292  }
1293 
1294  static bool IsPositive(Self val) { return val.real() > 0; }
1295  static bool IsNonpositive(Self val) { return val.real() == 0; }
1296  static bool IsNegative(Self) { return false; }
1297  static bool IsNonnegative(Self) { return true; }
1298  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1299  static const bool IsInteger = false;
1300  static const bool IsComplex = true;
1301  static Self ZeroValue() { return Zero; }
1302  static Self OneValue() { return One; }
1303  static unsigned int GetLength(const Self &) { return 2; }
1304  static unsigned int GetLength() { return 2; }
1305  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1306  static Self ZeroValue(const Self &) { return ZeroValue(); }
1307  static Self OneValue(const Self &) { return OneValue(); }
1308  template<typename TArray>
1309  static void AssignToArray( const Self & v, TArray & mv )
1310  {
1311  mv[0] = v.real();
1312  mv[1] = v.imag();
1313  }
1314  static void SetLength(Self & m, const unsigned int s)
1315  {
1316  if ( s != 2 )
1317  {
1318  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1319  }
1321  }
1322 };
1323 
1329 template< >
1330 class NumericTraits< std::complex< long > >
1331 {
1332 public:
1333  typedef std::complex< long > Self;
1334  // for backward compatibility
1335  typedef Self TheType;
1336  typedef long ValueType;
1337  typedef Self PrintType;
1338  typedef double AbsType;
1339  typedef Self AccumulateType;
1340  typedef std::complex< double > RealType;
1341  typedef double ScalarRealType;
1342  typedef std::complex< float > FloatType;
1343  typedef FixedArray<long, 2> MeasurementVectorType;
1344 
1345  static const Self ITKCommon_EXPORT Zero;
1346  static const Self ITKCommon_EXPORT One;
1347 
1348  static Self min() { return std::numeric_limits< Self >::min(); }
1349  static Self max() { return std::numeric_limits< Self >::max(); }
1350  static Self min(Self) { return min(); }
1351  static Self max(Self) { return max(); }
1352  static Self NonpositiveMin()
1353  {
1354  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1355  }
1356 
1357  static bool IsPositive(Self val) { return val.real() > 0; }
1358  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1359  static bool IsNegative(Self val) { return val.real() < 0; }
1360  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1361  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1362  static const bool IsInteger = false;
1363  static const bool IsComplex = true;
1364  static Self ZeroValue() { return Zero; }
1365  static Self OneValue() { return One; }
1366  static unsigned int GetLength(const Self &) { return 2; }
1367  static unsigned int GetLength() { return 2; }
1368  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1369  static Self ZeroValue(const Self &) { return ZeroValue(); }
1370  static Self OneValue(const Self &) { return OneValue(); }
1371  template<typename TArray>
1372  static void AssignToArray( const Self & v, TArray & mv )
1373  {
1374  mv[0] = v.real();
1375  mv[1] = v.imag();
1376  }
1377  static void SetLength(Self & m, const unsigned int s)
1378  {
1379  if ( s != 2 )
1380  {
1381  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1382  }
1384  }
1385 };
1386 
1392 template< >
1393 class NumericTraits< std::complex< unsigned long > >
1394 {
1395 public:
1396  typedef std::complex< unsigned long > Self;
1397  // for backward compatibility
1398  typedef Self TheType;
1399  typedef unsigned long ValueType;
1400  typedef Self PrintType;
1401  typedef double AbsType;
1402  typedef Self AccumulateType;
1403  typedef std::complex< double > RealType;
1404  typedef double ScalarRealType;
1405  typedef std::complex< float > FloatType;
1406  typedef FixedArray<unsigned long, 2> MeasurementVectorType;
1407 
1408  static const Self ITKCommon_EXPORT Zero;
1409  static const Self ITKCommon_EXPORT One;
1410 
1411  static Self min() { return std::numeric_limits< Self >::min(); }
1412  static Self max() { return std::numeric_limits< Self >::max(); }
1413  static Self min(Self) { return min(); }
1414  static Self max(Self) { return max(); }
1415  static Self NonpositiveMin()
1416  {
1417  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1418  }
1419 
1420  static bool IsPositive(Self val) { return val.real() > 0; }
1421  static bool IsNonpositive(Self val) { return val.real() == 0; }
1422  static bool IsNegative(Self) { return false; }
1423  static bool IsNonnegative(Self) { return true; }
1424  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1425  static const bool IsInteger = false;
1426  static const bool IsComplex = true;
1427  static Self ZeroValue() { return Zero; }
1428  static Self OneValue() { return One; }
1429  static unsigned int GetLength(const Self &) { return 2; }
1430  static unsigned int GetLength() { return 2; }
1431  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1432  static Self ZeroValue(const Self &) { return ZeroValue(); }
1433  static Self OneValue(const Self &) { return OneValue(); }
1434  template<typename TArray>
1435  static void AssignToArray( const Self & v, TArray & mv )
1436  {
1437  mv[0] = v.real();
1438  mv[1] = v.imag();
1439  }
1440  static void SetLength(Self & m, const unsigned int s)
1441  {
1442  if ( s != 2 )
1443  {
1444  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1445  }
1447  }
1448 };
1449 
1455 template< >
1456 class NumericTraits< std::complex< float > >
1457 {
1458 public:
1459  typedef std::complex< float > Self;
1460  // for backward compatibility
1461  typedef Self TheType;
1462  typedef float ValueType;
1463  typedef Self PrintType;
1464  typedef double AbsType;
1465  typedef Self AccumulateType;
1466  typedef std::complex< double > RealType;
1467  typedef double ScalarRealType;
1468  typedef std::complex< float > FloatType;
1469  typedef FixedArray<float, 2> MeasurementVectorType;
1470 
1471  static const Self ITKCommon_EXPORT Zero;
1472  static const Self ITKCommon_EXPORT One;
1473 
1474  static Self min() { return std::numeric_limits< Self >::min(); }
1475  static Self max() { return std::numeric_limits< Self >::max(); }
1476  static Self min(Self) { return min(); }
1477  static Self max(Self) { return max(); }
1478  static Self NonpositiveMin()
1479  {
1480  return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
1481  }
1482 
1483  static bool IsPositive(Self val) { return val.real() > 0.0; }
1484  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1485  static bool IsNegative(Self val) { return val.real() < 0.0; }
1486  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1487  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1488  static const bool IsInteger = false;
1489  static const bool IsComplex = true;
1490  static Self ZeroValue() { return Zero; }
1491  static Self OneValue() { return One; }
1492  static unsigned int GetLength(const Self &) { return 2; }
1493  static unsigned int GetLength() { return 2; }
1494  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1495  static Self ZeroValue(const Self &) { return ZeroValue(); }
1496  static Self OneValue(const Self &) { return OneValue(); }
1497  template<typename TArray>
1498  static void AssignToArray( const Self & v, TArray & mv )
1499  {
1500  mv[0] = v.real();
1501  mv[1] = v.imag();
1502  }
1503  static void SetLength(Self & m, const unsigned int s)
1504  {
1505  if ( s != 2 )
1506  {
1507  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1508  }
1510  }
1511 };
1512 
1518 template< >
1519 class NumericTraits< std::complex< double > >
1520 {
1521 public:
1522  typedef std::complex< double > Self;
1523  // for backward compatibility
1524  typedef Self TheType;
1525  typedef double ValueType;
1526  typedef Self PrintType;
1527  typedef double AbsType;
1528  typedef Self AccumulateType;
1529  typedef std::complex< double > RealType;
1530  typedef double ScalarRealType;
1531  typedef std::complex< float > FloatType;
1532  typedef FixedArray<double, 2> MeasurementVectorType;
1533 
1534  static const Self ITKCommon_EXPORT Zero;
1535  static const Self ITKCommon_EXPORT One;
1536 
1537  static Self min() { return std::numeric_limits< ValueType >::min(); }
1538  static Self max() { return std::numeric_limits< ValueType >::max(); }
1539  static Self min(Self) { return min(); }
1540  static Self max(Self) { return max(); }
1541  static Self NonpositiveMin()
1542  {
1543  return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
1544  }
1545 
1546  static bool IsPositive(Self val) { return val.real() > 0.0; }
1547  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1548  static bool IsNegative(Self val) { return val.real() < 0.0; }
1549  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1550  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1551  static const bool IsInteger = false;
1552  static const bool IsComplex = true;
1553  static Self ZeroValue() { return Zero; }
1554  static Self OneValue() { return One; }
1555  static unsigned int GetLength(const Self &) { return 2; }
1556  static unsigned int GetLength() { return 2; }
1557  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1558  static Self ZeroValue(const Self &) { return ZeroValue(); }
1559  static Self OneValue(const Self &) { return OneValue(); }
1560  template<typename TArray>
1561  static void AssignToArray( const Self & v, TArray & mv )
1562  {
1563  mv[0] = v.real();
1564  mv[1] = v.imag();
1565  }
1566  static void SetLength(Self & m, const unsigned int s)
1567  {
1568  if ( s != 2 )
1569  {
1570  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1571  }
1573  }
1574 };
1575 
1581 template< >
1582 class NumericTraits< std::complex< long double > >
1583 {
1584 public:
1585  typedef std::complex< long double > Self;
1586  // for backward compatibility
1587  typedef Self TheType;
1588  typedef long double ValueType;
1589  typedef Self PrintType;
1590  typedef long double AbsType;
1591  typedef Self AccumulateType;
1592  typedef std::complex< long double > RealType;
1593  typedef long double ScalarRealType;
1594  typedef std::complex< float > FloatType;
1595  typedef FixedArray<long double, 2> MeasurementVectorType;
1596 
1597  static const Self ITKCommon_EXPORT Zero;
1598  static const Self ITKCommon_EXPORT One;
1599 
1600  static Self min() { return std::numeric_limits< ValueType >::min(); }
1601  static Self max() { return std::numeric_limits< ValueType >::max(); }
1602  static Self min(Self) { return min(); }
1603  static Self max(Self) { return max(); }
1604  static Self NonpositiveMin()
1605  {
1606  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
1607  }
1608 
1609  static bool IsPositive(Self val) { return val.real() > 0.0; }
1610  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1611  static bool IsNegative(Self val) { return val.real() < 0.0; }
1612  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1613  static const bool IsSigned = NumericTraits< ValueType >::IsSigned;
1614  static const bool IsInteger = false;
1615  static const bool IsComplex = true;
1616  static Self ZeroValue() { return Zero; }
1617  static Self OneValue() { return One; }
1618  static unsigned int GetLength(const Self &) { return 2; }
1619  static unsigned int GetLength() { return 2; }
1620  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1621  static Self ZeroValue(const Self &) { return ZeroValue(); }
1622  static Self OneValue(const Self &) { return OneValue(); }
1623  template<typename TArray>
1624  static void AssignToArray( const Self & v, TArray & mv )
1625  {
1626  mv[0] = v.real();
1627  mv[1] = v.imag();
1628  }
1629  static void SetLength(Self & m, const unsigned int s)
1630  {
1631  if ( s != 2 )
1632  {
1633  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1634  }
1636  }
1637 };
1638 
1644 template< >
1645 class NumericTraits< long long > :
1646  public std::numeric_limits< long long >
1647 {
1648 public:
1649  typedef long long ValueType;
1650  typedef long long PrintType;
1651  typedef long long AbsType;
1652  typedef long long AccumulateType;
1653  typedef double RealType;
1654  typedef RealType ScalarRealType;
1655  typedef float FloatType;
1656  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1657 
1658  static const ValueType ITKCommon_EXPORT Zero;
1659  static const ValueType ITKCommon_EXPORT One;
1660 
1662  static ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
1663  static bool IsPositive(ValueType val) { return val > Zero; }
1664  static bool IsNonpositive(ValueType val) { return val <= Zero; }
1665  static bool IsNegative(ValueType val) { return val < Zero; }
1666  static bool IsNonnegative(ValueType val) { return val >= Zero; }
1667  static const bool IsSigned = true;
1668  static const bool IsInteger = true;
1669  static const bool IsComplex = false;
1670  static ValueType ZeroValue() { return Zero; }
1671  static ValueType OneValue() { return One; }
1672  static unsigned int GetLength(const ValueType &) { return 1; }
1673  static unsigned int GetLength() { return 1; }
1674  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1675  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1676  static ValueType OneValue(const ValueType &) { return OneValue(); }
1677 
1678  template<typename TArray>
1679  static void AssignToArray( const ValueType & v, TArray & mv )
1680  {
1681  mv[0] = v;
1682  }
1683  static void SetLength(ValueType & m, const unsigned int s)
1684  {
1685  if ( s != 1 )
1686  {
1687  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1688  }
1690  }
1691 };
1692 
1698 template< >
1699 class NumericTraits< unsigned long long > :
1700  public std::numeric_limits< unsigned long long >
1701 {
1702 public:
1703  typedef unsigned long long ValueType;
1704  typedef unsigned long long PrintType;
1705  typedef unsigned long long AbsType;
1706  typedef unsigned long long AccumulateType;
1707  typedef double RealType;
1708  typedef RealType ScalarRealType;
1709  typedef float FloatType;
1710  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1711 
1712  static const ValueType ITKCommon_EXPORT Zero;
1713  static const ValueType ITKCommon_EXPORT One;
1714 
1716  static ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
1717  static bool IsPositive(ValueType val) { return val != Zero; }
1718  static bool IsNonpositive(ValueType val) { return val == Zero; }
1719  static bool IsNegative(ValueType) { return false; }
1720  static bool IsNonnegative(ValueType) { return true; }
1721  static const bool IsSigned = false;
1722  static const bool IsInteger = true;
1723  static const bool IsComplex = false;
1724  static ValueType ZeroValue() { return Zero; }
1725  static ValueType OneValue() { return One; }
1726  static unsigned int GetLength(const ValueType &) { return 1; }
1727  static unsigned int GetLength() { return 1; }
1728  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1729  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1730  static ValueType OneValue(const ValueType &) { return OneValue(); }
1731 
1732  template<typename TArray>
1733  static void AssignToArray( const ValueType & v, TArray & mv )
1734  {
1735  mv[0] = v;
1736  }
1737  static void SetLength(ValueType & m, const unsigned int s)
1738  {
1739  if ( s != 1 )
1740  {
1741  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1742  }
1744  }
1745 };
1746 
1748 
1749 } // end namespace itk
1750 
1751 #include "itkFixedArray.h"
1752 
1753 #endif // itkNumericTraits_h
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
static T OneValue(const T &)
static void AssignToArray(const T &v, TArray &mv)
static const bool IsSigned
static bool IsPositive(T val)
static T min(const T &)
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
static const T Zero
static bool IsNonnegative(T val)
static T NonpositiveMin(const T &)
std::numeric_limits< T > TraitsType
static unsigned int GetLength()
static T max(const T &)
static void SetLength(T &m, const unsigned int s)
static bool IsNegative(T val)
static T ZeroValue(const T &)
static bool IsNonpositive(T val)
static const T One
FixedArray< ValueType, 1 > MeasurementVectorType
static const bool IsInteger
static const bool IsComplex
Define additional traits for native types such as int or float.
static unsigned int GetLength(const T &)