ITK  4.13.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 ITK_CONSTEXPR_FUNC ValueType min() \
28  { \
29  return std::numeric_limits< ValueType >::min(); \
30  } \
31  static ITK_CONSTEXPR_FUNC ValueType max() \
32  { \
33  return std::numeric_limits< ValueType >::max(); \
34  } \
35  static ITK_CONSTEXPR_FUNC ValueType min(ValueType) \
36  { \
37  return std::numeric_limits< ValueType >::min(); \
38  } \
39  static ITK_CONSTEXPR_FUNC ValueType max(ValueType) \
40  { \
41  return std::numeric_limits< ValueType >::max(); \
42  } \
43 
44 #if ITK_COMPILER_CXX_CONSTEXPR
45 #define itkNUMERIC_TRAITS_C11_ASSINMENT(x) = x
46 #else
47 #define itkNUMERIC_TRAITS_C11_ASSINMENT(x)
48 #endif
49 
50 #if !defined( ITK_LEGACY_FUTURE_REMOVE )
51 # include "vcl_limits.h"
52 #endif
53 #include <limits> // for std::numeric_limits
54 #include <complex>
55 
56 namespace itk
57 {
58 
59 // forward decare to avoid circular dependencies
60 template< typename TValue, unsigned int VLength> class FixedArray;
61 
77 template< typename T >
78 class NumericTraits:public std::numeric_limits< T >
79 {
80 public:
82  typedef std::numeric_limits< T > TraitsType;
83 
85  typedef T ValueType;
86 
88  typedef T PrintType;
89 
91  typedef T AbsType;
92 
94  typedef double AccumulateType;
95 
98 
101  typedef float FloatType;
102 
104  typedef double RealType;
105 
108 
110  static const T Zero;
111 
113  static const T One;
114 
116  static ITK_CONSTEXPR_FUNC T NonpositiveMin() { return TraitsType::min(); }
117 
119  static bool IsPositive(T val) { return val > Zero; }
120 
122  static bool IsNonpositive(T val) { return val <= Zero; }
123 
125  static bool IsNegative(T val) { return val < Zero; }
126 
128  static bool IsNonnegative(T val) { return val >= Zero; }
129 
133  static ITK_CONSTEXPR_VAR bool IsSigned = false;
134 
138  static ITK_CONSTEXPR_VAR bool IsInteger = false;
139 
143  static ITK_CONSTEXPR_VAR bool IsComplex = false;
144 
147  static T ZeroValue() { return Zero; }
148 
151  static T OneValue() { return One; }
152 
153  /* Provide a default implementation of the max() method with
154  * argument. This API is needed for VariableLengthVector because
155  * its length is only known at run-time. Specializations of the
156  * VariableLengthVector will provide a different implementation
157  * where a vector of the correct size is built. */
158  static ITK_CONSTEXPR_FUNC T max(const T &) { return TraitsType::max(); }
159  static ITK_CONSTEXPR_FUNC T min(const T &) { return TraitsType::min(); }
160 
168  static void SetLength(T & m, const unsigned int s)
169  {
170  if ( s != 1 )
171  {
172  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
173  }
175  }
176 
183  static unsigned int GetLength(const T &)
184  {
185  return GetLength();
186  }
187 
189  static unsigned int GetLength()
190  {
191  return 1;
192  }
193 
197  static T NonpositiveMin(const T &)
198  {
199  return NonpositiveMin();
200  }
201 
205  static T ZeroValue(const T &)
206  {
207  return ZeroValue();
208  }
209 
213  static T OneValue(const T &)
214  {
215  return OneValue();
216  }
217 
219  template<typename TArray>
220  static void AssignToArray( const T & v, TArray & mv )
221  {
222  mv[0] = v;
223  }
224 
225 };
226 
228 
236 template< >
237 class NumericTraits< bool > :public std::numeric_limits< bool >
238 {
239 public:
240  typedef bool ValueType;
241  typedef bool PrintType;
242  typedef unsigned char AbsType;
243  typedef unsigned char AccumulateType;
244  typedef double RealType;
245  typedef RealType ScalarRealType;
246  typedef float FloatType;
247  typedef FixedArray<ValueType, 1> MeasurementVectorType;
248 
249  static ITK_CONSTEXPR_VAR bool Zero = false;
250  static ITK_CONSTEXPR_VAR bool One = true;
251 
252  static ITK_CONSTEXPR_FUNC bool min() { return false; }
253  static ITK_CONSTEXPR_FUNC bool max() { return true; }
254  static ITK_CONSTEXPR_FUNC bool min(bool) { return min(); }
255  static ITK_CONSTEXPR_FUNC bool max(bool) { return max(); }
256  static ITK_CONSTEXPR_FUNC bool NonpositiveMin() { return false; }
257  static ITK_CONSTEXPR_FUNC bool IsPositive(bool val) { return val; }
258  static ITK_CONSTEXPR_FUNC bool IsNonpositive(bool val) { return !val; }
259  static ITK_CONSTEXPR_FUNC bool IsNegative(bool val) { return val ? false : false; }
260  static ITK_CONSTEXPR_FUNC bool IsNonnegative(bool val) { return val ? true : true; }
261  static ITK_CONSTEXPR_VAR bool IsSigned = false;
262  static ITK_CONSTEXPR_VAR bool IsInteger = true;
263  static ITK_CONSTEXPR_VAR bool IsComplex = false;
264  static ITK_CONSTEXPR_FUNC bool ZeroValue() { return Zero; }
265  static ITK_CONSTEXPR_FUNC bool OneValue() { return One; }
266  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
267  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
268  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
269  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
270  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
271 
272  template<typename TArray>
273  static void AssignToArray( const ValueType & v, TArray & mv )
274  {
275  mv[0] = v;
276  }
277  static void SetLength(ValueType & m, const unsigned int s)
278  {
279  if ( s != 1 )
280  {
281  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
282  }
284  }
285 
286 };
287 
293 template< >
294 class NumericTraits< char > :public std::numeric_limits< char >
295 {
296 public:
297  typedef char ValueType;
298  typedef int PrintType;
299  typedef unsigned char AbsType;
300  typedef short AccumulateType;
301  typedef double RealType;
302  typedef RealType ScalarRealType;
303  typedef float FloatType;
304  typedef FixedArray<ValueType, 1> MeasurementVectorType;
305 
306  static ITK_CONSTEXPR_VAR char ITKCommon_EXPORT Zero = 0;
307  static ITK_CONSTEXPR_VAR char ITKCommon_EXPORT One = 1;
308 
309  static ITK_CONSTEXPR_FUNC char min() { return char(255) < char(0) ? char(-128) : char(0); }
310  static ITK_CONSTEXPR_FUNC char max() { return char(255) < char(0) ? char(127) : char(255); }
311 
312  static ITK_CONSTEXPR_FUNC char min(char) { return min(); }
313  static ITK_CONSTEXPR_FUNC char max(char) { return max(); }
314  static ITK_CONSTEXPR_FUNC char NonpositiveMin() { return min(); }
315  static ITK_CONSTEXPR_FUNC bool IsPositive(char val) { return val > Zero; }
316  static ITK_CONSTEXPR_FUNC bool IsNonpositive(char val) { return val <= Zero; }
317 // char on PowerPC, for example, is not signed
318 #if VCL_CHAR_IS_SIGNED
319  static ITK_CONSTEXPR_FUNC bool IsNegative(char val) { return val < Zero; }
320  static ITK_CONSTEXPR_FUNC bool IsNonnegative(char val) { return val >= Zero; }
321  static ITK_CONSTEXPR_VAR bool IsSigned = true;
322 #else
323  static ITK_CONSTEXPR_FUNC bool IsNegative(char) { return false; }
324  static ITK_CONSTEXPR_FUNC bool IsNonnegative(char) { return true; }
325  static ITK_CONSTEXPR_VAR bool IsSigned = false;
326 #endif
327  static ITK_CONSTEXPR_VAR bool IsInteger = true;
328  static ITK_CONSTEXPR_VAR bool IsComplex = false;
329  static ITK_CONSTEXPR_FUNC char ZeroValue() { return Zero; }
330  static ITK_CONSTEXPR_FUNC char OneValue() { return One; }
331  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
332  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
333  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
334  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
335  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
336 
337  template<typename TArray>
338  static void AssignToArray( const ValueType & v, TArray & mv )
339  {
340  mv[0] = v;
341  }
342  static void SetLength(ValueType & m, const unsigned int s)
343  {
344  if ( s != 1 )
345  {
346  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
347  }
349  }
350 };
351 
357 template< >
358 class NumericTraits< signed char > :public std::numeric_limits< signed char >
359 {
360 public:
361  typedef signed char ValueType;
362  typedef int PrintType;
363  typedef unsigned char AbsType;
364  typedef short AccumulateType;
365  typedef double RealType;
366  typedef RealType ScalarRealType;
367  typedef float FloatType;
368  typedef FixedArray<ValueType, 1> MeasurementVectorType;
369 
370  static ITK_CONSTEXPR_VAR signed char ITKCommon_EXPORT Zero = 0;
371  static ITK_CONSTEXPR_VAR signed char ITKCommon_EXPORT One = 1;
372 
373  static ITK_CONSTEXPR_FUNC signed char min() { return -128; }
374  static ITK_CONSTEXPR_FUNC signed char max() { return 127; }
375  static ITK_CONSTEXPR_FUNC signed char min(signed char) { return min(); }
376  static ITK_CONSTEXPR_FUNC signed char max(signed char) { return max(); }
377  static ITK_CONSTEXPR_FUNC signed char NonpositiveMin() { return min(); }
378  static ITK_CONSTEXPR_FUNC bool IsPositive(signed char val) { return val > Zero; }
379  static ITK_CONSTEXPR_FUNC bool IsNonpositive(signed char val) { return val <= Zero; }
380  static ITK_CONSTEXPR_FUNC bool IsNegative(signed char val) { return val < Zero; }
381  static ITK_CONSTEXPR_FUNC bool IsNonnegative(signed char val) { return val >= Zero; }
382  static ITK_CONSTEXPR_VAR bool IsSigned = true;
383  static ITK_CONSTEXPR_VAR bool IsInteger = true;
384  static ITK_CONSTEXPR_VAR bool IsComplex = false;
385  static ITK_CONSTEXPR_FUNC signed char ZeroValue() { return Zero; }
386  static ITK_CONSTEXPR_FUNC signed char OneValue() { return One; }
387  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
388  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
389  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
390  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
391  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
392 
393  template<typename TArray>
394  static void AssignToArray( const ValueType & v, TArray & mv )
395  {
396  mv[0] = v;
397  }
398  static void SetLength(ValueType & m, const unsigned int s)
399  {
400  if ( s != 1 )
401  {
402  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
403  }
405  }
406 };
407 
413 template< >
414 class NumericTraits< unsigned char > :public std::numeric_limits< unsigned char >
415 {
416 public:
417  typedef unsigned char ValueType;
418  typedef int PrintType;
419  typedef unsigned char AbsType;
420  typedef unsigned short AccumulateType;
421  typedef double RealType;
422  typedef RealType ScalarRealType;
423  typedef float FloatType;
424  typedef FixedArray<ValueType, 1> MeasurementVectorType;
425 
426  static ITK_CONSTEXPR_VAR unsigned char ITKCommon_EXPORT Zero = 0;
427  static ITK_CONSTEXPR_VAR unsigned char ITKCommon_EXPORT One = 1;
428 
430 
431  static ITK_CONSTEXPR_FUNC unsigned char NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
432  static ITK_CONSTEXPR_FUNC bool IsPositive(unsigned char val) { return val != Zero; }
433  static ITK_CONSTEXPR_FUNC bool IsNonpositive(unsigned char val) { return val == Zero; }
434  static ITK_CONSTEXPR_FUNC bool IsNegative(unsigned char val) { return val ? false : false; }
435  static ITK_CONSTEXPR_FUNC bool IsNonnegative(unsigned char val) { return val ? true : true; }
436  static ITK_CONSTEXPR_VAR bool IsSigned = false;
437  static ITK_CONSTEXPR_VAR bool IsInteger = true;
438  static ITK_CONSTEXPR_VAR bool IsComplex = false;
439  static ITK_CONSTEXPR_FUNC unsigned char ZeroValue() { return Zero; }
440  static ITK_CONSTEXPR_FUNC unsigned char OneValue() { return One; }
441  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
442  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
443  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
444  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
445  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
446 
447  template<typename TArray>
448  static void AssignToArray( const ValueType & v, TArray & mv )
449  {
450  mv[0] = v;
451  }
452  static void SetLength(ValueType & m, const unsigned int s)
453  {
454  if ( s != 1 )
455  {
456  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
457  }
459  }
460 };
461 
466 template< >
467 class NumericTraits< short > :public std::numeric_limits< short >
468 {
469 public:
470  typedef short ValueType;
471  typedef short PrintType;
472  typedef unsigned short AbsType;
473  typedef int AccumulateType;
474  typedef double RealType;
475  typedef RealType ScalarRealType;
476  typedef float FloatType;
477  typedef FixedArray<ValueType, 1> MeasurementVectorType;
478 
479  static ITK_CONSTEXPR_VAR short ITKCommon_EXPORT Zero = 0;
480  static ITK_CONSTEXPR_VAR short ITKCommon_EXPORT One = 1;
481 
483  static ITK_CONSTEXPR_FUNC short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
484  static ITK_CONSTEXPR_FUNC bool IsPositive(short val) { return val > Zero; }
485  static ITK_CONSTEXPR_FUNC bool IsNonpositive(short val) { return val <= Zero; }
486  static ITK_CONSTEXPR_FUNC bool IsNegative(short val) { return val < Zero; }
487  static ITK_CONSTEXPR_FUNC bool IsNonnegative(short val) { return val >= Zero; }
488  static ITK_CONSTEXPR_VAR bool IsSigned = true;
489  static ITK_CONSTEXPR_VAR bool IsInteger = true;
490  static ITK_CONSTEXPR_VAR bool IsComplex = false;
491  static ITK_CONSTEXPR_FUNC short ZeroValue() { return Zero; }
492  static ITK_CONSTEXPR_FUNC short OneValue() { return One; }
493  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
494  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
495  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
496  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
497  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
498 
499  template<typename TArray>
500  static void AssignToArray( const ValueType & v, TArray & mv )
501  {
502  mv[0] = v;
503  }
504  static void SetLength(ValueType & m, const unsigned int s)
505  {
506  if ( s != 1 )
507  {
508  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
509  }
511  }
512 };
513 
519 template< >
520 class NumericTraits< unsigned short > :public std::numeric_limits< unsigned short >
521 {
522 public:
523  typedef unsigned short ValueType;
524  typedef unsigned short PrintType;
525  typedef unsigned short AbsType;
526  typedef unsigned int AccumulateType;
527  typedef double RealType;
528  typedef RealType ScalarRealType;
529  typedef float FloatType;
530  typedef FixedArray<ValueType, 1> MeasurementVectorType;
531 
532  static ITK_CONSTEXPR_VAR unsigned short ITKCommon_EXPORT Zero = 0;
533  static ITK_CONSTEXPR_VAR unsigned short ITKCommon_EXPORT One = 1;
534 
536  static ITK_CONSTEXPR_FUNC unsigned short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
537  static ITK_CONSTEXPR_FUNC bool IsPositive(unsigned short val) { return val != Zero; }
538  static ITK_CONSTEXPR_FUNC bool IsNonpositive(unsigned short val) { return val == Zero; }
539  static ITK_CONSTEXPR_FUNC bool IsNegative(unsigned short val) { return val ? false : false; }
540  static ITK_CONSTEXPR_FUNC bool IsNonnegative(unsigned short val) { return val ? true : true; }
541  static ITK_CONSTEXPR_VAR bool IsSigned = false;
542  static ITK_CONSTEXPR_VAR bool IsInteger = true;
543  static ITK_CONSTEXPR_VAR bool IsComplex = false;
544  static ITK_CONSTEXPR_FUNC unsigned short ZeroValue() { return Zero; }
545  static ITK_CONSTEXPR_FUNC unsigned short OneValue() { return One; }
546  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
547  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
548  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
549  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
550  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
551 
552  template<typename TArray>
553  static void AssignToArray( const ValueType & v, TArray & mv )
554  {
555  mv[0] = v;
556  }
557  static void SetLength(ValueType & m, const unsigned int s)
558  {
559  if ( s != 1 )
560  {
561  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
562  }
564  }
565 };
566 
571 template< >
572 class NumericTraits< int > :public std::numeric_limits< int >
573 {
574 public:
575  typedef int ValueType;
576  typedef int PrintType;
577  typedef unsigned int AbsType;
578  typedef long AccumulateType;
579  typedef double RealType;
580  typedef RealType ScalarRealType;
581  typedef float FloatType;
582  typedef FixedArray<ValueType, 1> MeasurementVectorType;
583 
584  static ITK_CONSTEXPR_VAR int ITKCommon_EXPORT Zero = 0;
585  static ITK_CONSTEXPR_VAR int ITKCommon_EXPORT One = 1;
586 
588  static ITK_CONSTEXPR_FUNC int NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
589  static ITK_CONSTEXPR_FUNC bool IsPositive(int val) { return val > Zero; }
590  static ITK_CONSTEXPR_FUNC bool IsNonpositive(int val) { return val <= Zero; }
591  static ITK_CONSTEXPR_FUNC bool IsNegative(int val) { return val < Zero; }
592  static ITK_CONSTEXPR_FUNC bool IsNonnegative(int val) { return val >= Zero; }
593  static ITK_CONSTEXPR_VAR bool IsSigned = true;
594  static ITK_CONSTEXPR_VAR bool IsInteger = true;
595  static ITK_CONSTEXPR_VAR bool IsComplex = false;
596  static ITK_CONSTEXPR_FUNC int ZeroValue() { return Zero; }
597  static ITK_CONSTEXPR_FUNC int OneValue() { return One; }
598  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
599  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
600  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
601  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
602  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
603 
604  template<typename TArray>
605  static void AssignToArray( const ValueType & v, TArray & mv )
606  {
607  mv[0] = v;
608  }
609  static void SetLength(ValueType & m, const unsigned int s)
610  {
611  if ( s != 1 )
612  {
613  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
614  }
616  }
617 };
618 
624 template< >
625 class NumericTraits< unsigned int > :public std::numeric_limits< unsigned int >
626 {
627 public:
628  typedef unsigned int ValueType;
629  typedef unsigned int PrintType;
630  typedef unsigned int AbsType;
631  typedef unsigned int AccumulateType;
632  typedef double RealType;
633  typedef RealType ScalarRealType;
634  typedef float FloatType;
635  typedef FixedArray<ValueType, 1> MeasurementVectorType;
636 
637  static ITK_CONSTEXPR_VAR unsigned int ITKCommon_EXPORT Zero = 0;
638  static ITK_CONSTEXPR_VAR unsigned int ITKCommon_EXPORT One = 1;
639 
640  static ITK_CONSTEXPR_FUNC unsigned int min(void) { return 0; }
641  static ITK_CONSTEXPR_FUNC unsigned int max(void) { return static_cast< unsigned int >( -1 ); }
642  static ITK_CONSTEXPR_FUNC unsigned int min(unsigned int) { return std::numeric_limits< ValueType >::min(); }
643  static ITK_CONSTEXPR_FUNC unsigned int max(unsigned int) { return std::numeric_limits< ValueType >::max(); }
644  static ITK_CONSTEXPR_FUNC unsigned int NonpositiveMin() { return 0; }
645  static ITK_CONSTEXPR_FUNC bool IsPositive(unsigned int val) { return val != Zero; }
646  static ITK_CONSTEXPR_FUNC bool IsNonpositive(unsigned int val) { return val == Zero; }
647  static ITK_CONSTEXPR_FUNC bool IsNegative(unsigned int val) { return val ? false : false; }
648  static ITK_CONSTEXPR_FUNC bool IsNonnegative(unsigned int val) { return val ? true : true; }
649  static ITK_CONSTEXPR_VAR bool IsSigned = false;
650  static ITK_CONSTEXPR_VAR bool IsInteger = true;
651  static ITK_CONSTEXPR_VAR bool IsComplex = false;
652  static ITK_CONSTEXPR_FUNC unsigned int ZeroValue() { return Zero; }
653  static ITK_CONSTEXPR_FUNC unsigned int OneValue() { return One; }
654  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
655  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
656  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
657  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
658  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
659 
660  template<typename TArray>
661  static void AssignToArray( const ValueType & v, TArray & mv )
662  {
663  mv[0] = v;
664  }
665  static void SetLength(ValueType & m, const unsigned int s)
666  {
667  if ( s != 1 )
668  {
669  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
670  }
672  }
673 };
674 
680 template< >
681 class NumericTraits< long > :public std::numeric_limits< long >
682 {
683 public:
684  typedef long ValueType;
685  typedef long PrintType;
686  typedef unsigned long AbsType;
687  typedef long AccumulateType;
688  typedef double RealType;
689  typedef RealType ScalarRealType;
690  typedef float FloatType;
691  typedef FixedArray<ValueType, 1> MeasurementVectorType;
692 
693  static ITK_CONSTEXPR_VAR long ITKCommon_EXPORT Zero = 0L;
694  static ITK_CONSTEXPR_VAR long ITKCommon_EXPORT One = 1L;
695 
697  static ITK_CONSTEXPR_FUNC long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
698  static ITK_CONSTEXPR_FUNC bool IsPositive(long val) { return val > Zero; }
699  static ITK_CONSTEXPR_FUNC bool IsNonpositive(long val) { return val <= Zero; }
700  static ITK_CONSTEXPR_FUNC bool IsNegative(long val) { return val < Zero; }
701  static ITK_CONSTEXPR_FUNC bool IsNonnegative(long val) { return val >= Zero; }
702  static ITK_CONSTEXPR_VAR bool IsSigned = true;
703  static ITK_CONSTEXPR_VAR bool IsInteger = true;
704  static ITK_CONSTEXPR_VAR bool IsComplex = false;
705  static ITK_CONSTEXPR_FUNC long ZeroValue() { return Zero; }
706  static ITK_CONSTEXPR_FUNC long OneValue() { return One; }
707  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
708  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
709  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
710  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
711  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
712 
713  template<typename TArray>
714  static void AssignToArray( const ValueType & v, TArray & mv )
715  {
716  mv[0] = v;
717  }
718  static void SetLength(ValueType & m, const unsigned int s)
719  {
720  if ( s != 1 )
721  {
722  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
723  }
725  }
726 };
727 
733 template< >
734 class NumericTraits< unsigned long > :public std::numeric_limits< unsigned long >
735 {
736 public:
737  typedef unsigned long ValueType;
738  typedef unsigned long PrintType;
739  typedef unsigned long AbsType;
740  typedef unsigned long AccumulateType;
741  typedef double RealType;
742  typedef RealType ScalarRealType;
743  typedef float FloatType;
744  typedef FixedArray<ValueType, 1> MeasurementVectorType;
745 
746  static ITK_CONSTEXPR_VAR unsigned long ITKCommon_EXPORT Zero = 0UL;
747  static ITK_CONSTEXPR_VAR unsigned long ITKCommon_EXPORT One = 1UL;
748 
750  static ITK_CONSTEXPR_FUNC unsigned long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
751  static ITK_CONSTEXPR_FUNC bool IsPositive(unsigned long val) { return val != Zero; }
752  static ITK_CONSTEXPR_FUNC bool IsNonpositive(unsigned long val) { return val == Zero; }
753  static ITK_CONSTEXPR_FUNC bool IsNegative(unsigned long) { return false; }
754  static ITK_CONSTEXPR_FUNC bool IsNonnegative(unsigned long) { return true; }
755  static ITK_CONSTEXPR_VAR bool IsSigned = false;
756  static ITK_CONSTEXPR_VAR bool IsInteger = true;
757  static ITK_CONSTEXPR_VAR bool IsComplex = false;
758  static ITK_CONSTEXPR_FUNC unsigned long ZeroValue() { return Zero; }
759  static ITK_CONSTEXPR_FUNC unsigned long OneValue() { return One; }
760  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
761  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
762  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
763  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
764  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
765 
766  template<typename TArray>
767  static void AssignToArray( const ValueType & v, TArray & mv )
768  {
769  mv[0] = v;
770  }
771  static void SetLength(ValueType & m, const unsigned int s)
772  {
773  if ( s != 1 )
774  {
775  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
776  }
778  }
779 };
780 
786 template< >
787 class NumericTraits< float > :public std::numeric_limits< float >
788 {
789 public:
790  typedef float ValueType;
791  typedef float PrintType;
792  typedef float AbsType;
793  typedef double AccumulateType;
794  typedef double RealType;
795  typedef RealType ScalarRealType;
796  typedef float FloatType;
797  typedef FixedArray<ValueType, 1> MeasurementVectorType;
798 
799 
800  static ITK_CONSTEXPR_VAR float ITKCommon_EXPORT Zero itkNUMERIC_TRAITS_C11_ASSINMENT(0.0f);
801  static ITK_CONSTEXPR_VAR float ITKCommon_EXPORT One itkNUMERIC_TRAITS_C11_ASSINMENT(1.0f);
802 
804  static ITK_CONSTEXPR_FUNC float NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
805  static ITK_CONSTEXPR_FUNC bool IsPositive(float val) { return val > Zero; }
806  static ITK_CONSTEXPR_FUNC bool IsNonpositive(float val) { return val <= Zero; }
807  static ITK_CONSTEXPR_FUNC bool IsNegative(float val) { return val < Zero; }
808  static ITK_CONSTEXPR_FUNC bool IsNonnegative(float val) { return val >= Zero; }
809  static ITK_CONSTEXPR_VAR bool IsSigned = true;
810  static ITK_CONSTEXPR_VAR bool IsInteger = false;
811  static ITK_CONSTEXPR_VAR bool IsComplex = false;
812  static ITK_CONSTEXPR_FUNC float ZeroValue() { return Zero; }
813  static ITK_CONSTEXPR_FUNC float OneValue() { return One; }
814  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
815  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
816  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
817  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
818  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
819 
820  template<typename TArray>
821  static void AssignToArray( const ValueType & v, TArray & mv )
822  {
823  mv[0] = v;
824  }
825  static void SetLength(ValueType & m, const unsigned int s)
826  {
827  if ( s != 1 )
828  {
829  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
830  }
832  }
833 };
834 
840 template< >
841 class NumericTraits< double > :public std::numeric_limits< double >
842 {
843 public:
844  typedef double ValueType;
845  typedef double PrintType;
846  typedef double AbsType;
847  typedef double AccumulateType;
848  typedef double RealType;
849  typedef RealType ScalarRealType;
850  typedef float FloatType;
851  typedef FixedArray<ValueType, 1> MeasurementVectorType;
852 
853  static ITK_CONSTEXPR_VAR double ITKCommon_EXPORT Zero itkNUMERIC_TRAITS_C11_ASSINMENT(0.0);
854  static ITK_CONSTEXPR_VAR double ITKCommon_EXPORT One itkNUMERIC_TRAITS_C11_ASSINMENT(1.0);
855 
857  static ITK_CONSTEXPR_FUNC double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
858  static ITK_CONSTEXPR_FUNC bool IsPositive(double val) { return val > Zero; }
859  static ITK_CONSTEXPR_FUNC bool IsNonpositive(double val) { return val <= Zero; }
860  static ITK_CONSTEXPR_FUNC bool IsNegative(double val) { return val < Zero; }
861  static ITK_CONSTEXPR_FUNC bool IsNonnegative(double val) { return val >= Zero; }
862  static ITK_CONSTEXPR_VAR bool IsSigned = true;
863  static ITK_CONSTEXPR_VAR bool IsInteger = false;
864  static ITK_CONSTEXPR_VAR bool IsComplex = false;
865  static ITK_CONSTEXPR_FUNC double ZeroValue() { return Zero; }
866  static ITK_CONSTEXPR_FUNC double OneValue() { return One; }
867  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
868  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
869  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
870  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
871  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
872 
873  template<typename TArray>
874  static void AssignToArray( const ValueType & v, TArray & mv )
875  {
876  mv[0] = v;
877  }
878  static void SetLength(ValueType & m, const unsigned int s)
879  {
880  if ( s != 1 )
881  {
882  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
883  }
885  }
886 };
887 
893 template< >
894 class NumericTraits< long double > :public std::numeric_limits< long double >
895 {
896 public:
897  typedef long double ValueType;
898 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
899  // sun studio in 32 bit mode is unable to print long double values: it
900  // segfaults.
901  // conversion to double will give usable results if the value is in the double
902  // range - better than nothing.
903  typedef double PrintType;
904 #else
905  typedef long double PrintType;
906 #endif
907  typedef long double AbsType;
908  typedef long double AccumulateType;
909  typedef long double RealType;
910  typedef RealType ScalarRealType;
911  typedef float FloatType;
912  typedef FixedArray<ValueType, 1> MeasurementVectorType;
913 
914  static ITK_CONSTEXPR_VAR long double ITKCommon_EXPORT Zero itkNUMERIC_TRAITS_C11_ASSINMENT(0.0);
915  static ITK_CONSTEXPR_VAR long double ITKCommon_EXPORT One itkNUMERIC_TRAITS_C11_ASSINMENT(1.0);
916 
918  static ITK_CONSTEXPR_FUNC long double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
919  static ITK_CONSTEXPR_FUNC bool IsPositive(long double val) { return val > Zero; }
920  static ITK_CONSTEXPR_FUNC bool IsNonpositive(long double val) { return val <= Zero; }
921  static ITK_CONSTEXPR_FUNC bool IsNegative(long double val) { return val < Zero; }
922  static ITK_CONSTEXPR_FUNC bool IsNonnegative(long double val) { return val >= Zero; }
923  static ITK_CONSTEXPR_VAR bool IsSigned = true;
924  static ITK_CONSTEXPR_VAR bool IsInteger = false;
925  static ITK_CONSTEXPR_VAR bool IsComplex = false;
926  static ITK_CONSTEXPR_FUNC long double ZeroValue() { return Zero; }
927  static ITK_CONSTEXPR_FUNC long double OneValue() { return One; }
928  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
929  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
930  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
931  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
932  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
933 
934  template<typename TArray>
935  static void AssignToArray( const ValueType & v, TArray & mv )
936  {
937  mv[0] = v;
938  }
939  static void SetLength(ValueType & m, const unsigned int s)
940  {
941  if ( s != 1 )
942  {
943  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
944  }
946  }
947 };
948 
949 
955 template< >
956 class NumericTraits< long long > :
957  public std::numeric_limits< long long >
958 {
959 public:
960  typedef long long ValueType;
961  typedef long long PrintType;
962  typedef long long AbsType;
963  typedef long long AccumulateType;
964  typedef double RealType;
965  typedef RealType ScalarRealType;
966  typedef float FloatType;
967  typedef FixedArray<ValueType, 1> MeasurementVectorType;
968 
969  static ITK_CONSTEXPR_VAR ValueType ITKCommon_EXPORT Zero = 0LL;
970  static ITK_CONSTEXPR_VAR ValueType ITKCommon_EXPORT One = 1LL;
971 
973  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
974  static ITK_CONSTEXPR_FUNC bool IsPositive(ValueType val) { return val > Zero; }
975  static ITK_CONSTEXPR_FUNC bool IsNonpositive(ValueType val) { return val <= Zero; }
976  static ITK_CONSTEXPR_FUNC bool IsNegative(ValueType val) { return val < Zero; }
977  static ITK_CONSTEXPR_FUNC bool IsNonnegative(ValueType val) { return val >= Zero; }
978  static ITK_CONSTEXPR_VAR bool IsSigned = true;
979  static ITK_CONSTEXPR_VAR bool IsInteger = true;
980  static ITK_CONSTEXPR_VAR bool IsComplex = false;
981  static ITK_CONSTEXPR_FUNC ValueType ZeroValue() { return Zero; }
982  static ITK_CONSTEXPR_FUNC ValueType OneValue() { return One; }
983  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
984  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
985  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
986  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
987  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
988 
989  template<typename TArray>
990  static void AssignToArray( const ValueType & v, TArray & mv )
991  {
992  mv[0] = v;
993  }
994  static void SetLength(ValueType & m, const unsigned int s)
995  {
996  if ( s != 1 )
997  {
998  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
999  }
1001  }
1002 };
1003 
1009 template< >
1010 class NumericTraits< unsigned long long > :
1011  public std::numeric_limits< unsigned long long >
1012 {
1013 public:
1014  typedef unsigned long long ValueType;
1015  typedef unsigned long long PrintType;
1016  typedef unsigned long long AbsType;
1017  typedef unsigned long long AccumulateType;
1018  typedef double RealType;
1019  typedef RealType ScalarRealType;
1020  typedef float FloatType;
1021  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1022 
1023  static ITK_CONSTEXPR_VAR ValueType ITKCommon_EXPORT Zero = 0ULL;
1024  static ITK_CONSTEXPR_VAR ValueType ITKCommon_EXPORT One = 1ULL;
1025 
1027  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
1028  static ITK_CONSTEXPR_FUNC bool IsPositive(ValueType val) { return val != Zero; }
1029  static ITK_CONSTEXPR_FUNC bool IsNonpositive(ValueType val) { return val == Zero; }
1030  static ITK_CONSTEXPR_FUNC bool IsNegative(ValueType) { return false; }
1031  static ITK_CONSTEXPR_FUNC bool IsNonnegative(ValueType) { return true; }
1032  static ITK_CONSTEXPR_VAR bool IsSigned = false;
1033  static ITK_CONSTEXPR_VAR bool IsInteger = true;
1034  static ITK_CONSTEXPR_VAR bool IsComplex = false;
1035  static ITK_CONSTEXPR_FUNC ValueType ZeroValue() { return Zero; }
1036  static ITK_CONSTEXPR_FUNC ValueType OneValue() { return One; }
1037  static ITK_CONSTEXPR_FUNC unsigned int GetLength(const ValueType &) { return 1; }
1038  static ITK_CONSTEXPR_FUNC unsigned int GetLength() { return 1; }
1039  static ITK_CONSTEXPR_FUNC ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1040  static ITK_CONSTEXPR_FUNC ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1041  static ITK_CONSTEXPR_FUNC ValueType OneValue(const ValueType &) { return OneValue(); }
1042 
1043  template<typename TArray>
1044  static void AssignToArray( const ValueType & v, TArray & mv )
1045  {
1046  mv[0] = v;
1047  }
1048  static void SetLength(ValueType & m, const unsigned int s)
1049  {
1050  if ( s != 1 )
1051  {
1052  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1053  }
1055  }
1056 };
1057 
1058 
1064 template< >
1065 class NumericTraits< std::complex< char > >
1066 {
1067 public:
1068  typedef std::complex< char > Self;
1069  // for backward compatibility
1070  typedef Self TheType;
1071  typedef char ValueType;
1072  typedef std::complex< int > PrintType;
1073  typedef double AbsType;
1074  typedef Self AccumulateType;
1075  typedef std::complex< double > RealType;
1076  typedef double ScalarRealType;
1077  typedef std::complex< float > FloatType;
1078  typedef FixedArray<char, 2> MeasurementVectorType;
1079 
1080  static const Self ITKCommon_EXPORT Zero;
1081  static const Self ITKCommon_EXPORT One;
1082 
1083  static Self min() { return std::numeric_limits< Self >::min(); }
1084  static Self max() { return std::numeric_limits< Self >::max(); }
1085  static Self min(Self) { return min(); }
1086  static Self max(Self) { return max(); }
1087  static Self NonpositiveMin()
1088  {
1089  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1090  }
1091 
1092  static bool IsPositive(Self val) { return val.real() > 0; }
1093  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1094 // char on PowerPC, for example, is not signed
1095 #if VCL_CHAR_IS_SIGNED
1096  static bool IsNegative(Self val) { return val.real() < 0; }
1097  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1098 #else
1099  static bool IsNegative(Self) { return false; }
1100  static bool IsNonnegative(Self) { return true; }
1101 #endif
1102  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1103  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1104  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1105  static Self ZeroValue() { return Zero; }
1106  static Self OneValue() { return One; }
1107  static unsigned int GetLength(const Self &) { return 2; }
1108  static unsigned int GetLength() { return 2; }
1109  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1110  static Self ZeroValue(const Self &) { return ZeroValue(); }
1111  static Self OneValue(const Self &) { return OneValue(); }
1112  template<typename TArray>
1113  static void AssignToArray( const Self & v, TArray & mv )
1114  {
1115  mv[0] = v.real();
1116  mv[1] = v.imag();
1117  }
1118  static void SetLength(Self & m, const unsigned int s)
1119  {
1120  if ( s != 2 )
1121  {
1122  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1123  }
1125  }
1126 };
1127 
1133 template< >
1134 class NumericTraits< std::complex< unsigned char > >
1135 {
1136 public:
1137  typedef std::complex< unsigned char > Self;
1138  // for backward compatibility
1139  typedef Self TheType;
1140  typedef unsigned char ValueType;
1141  typedef std::complex< unsigned int > PrintType;
1142  typedef double AbsType;
1143  typedef Self AccumulateType;
1144  typedef std::complex< double > RealType;
1145  typedef double ScalarRealType;
1146  typedef std::complex< float > FloatType;
1147  typedef FixedArray<unsigned char, 2> MeasurementVectorType;
1148 
1149  static const Self ITKCommon_EXPORT Zero;
1150  static const Self ITKCommon_EXPORT One;
1151 
1152  static Self min() { return std::numeric_limits< Self >::min(); }
1153  static Self max() { return std::numeric_limits< Self >::max(); }
1154  static Self min(Self) { return min(); }
1155  static Self max(Self) { return max(); }
1156  static Self NonpositiveMin()
1157  {
1158  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1159  }
1160 
1161  static bool IsPositive(Self val) { return val.real() > 0; }
1162  static bool IsNonpositive(Self val) { return val.real() == 0; }
1163  static bool IsNegative(Self) { return false; }
1164  static bool IsNonnegative(Self) { return true; }
1165  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1166  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1167  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1168  static Self ZeroValue() { return Zero; }
1169  static Self OneValue() { return One; }
1170  static unsigned int GetLength(const Self &) { return 2; }
1171  static unsigned int GetLength() { return 2; }
1172  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1173  static Self ZeroValue(const Self &) { return ZeroValue(); }
1174  static Self OneValue(const Self &) { return OneValue(); }
1175  template<typename TArray>
1176  static void AssignToArray( const Self & v, TArray & mv )
1177  {
1178  mv[0] = v.real();
1179  mv[1] = v.imag();
1180  }
1181  static void SetLength(Self & m, const unsigned int s)
1182  {
1183  if ( s != 2 )
1184  {
1185  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1186  }
1188  }
1189 };
1190 
1196 template< >
1197 class NumericTraits< std::complex< short > >
1198 {
1199 public:
1200  typedef std::complex< short > Self;
1201  // for backward compatibility
1202  typedef Self TheType;
1203  typedef short ValueType;
1204  typedef Self PrintType;
1205  typedef double AbsType;
1206  typedef Self AccumulateType;
1207  typedef std::complex< double > RealType;
1208  typedef double ScalarRealType;
1209  typedef std::complex< float > FloatType;
1210  typedef FixedArray<short, 2> MeasurementVectorType;
1211 
1212  static const Self ITKCommon_EXPORT Zero;
1213  static const Self ITKCommon_EXPORT One;
1214 
1215  static Self min() { return std::numeric_limits< Self >::min(); }
1216  static Self max() { return std::numeric_limits< Self >::max(); }
1217  static Self min(Self) { return min(); }
1218  static Self max(Self) { return max(); }
1219  static Self NonpositiveMin()
1220  {
1221  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1222  }
1223 
1224  static bool IsPositive(Self val) { return val.real() > 0; }
1225  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1226  static bool IsNegative(Self val) { return val.real() < 0; }
1227  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1228  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1229  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1230  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1231  static Self ZeroValue() { return Zero; }
1232  static Self OneValue() { return One; }
1233  static unsigned int GetLength(const Self &) { return 2; }
1234  static unsigned int GetLength() { return 2; }
1235  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1236  static Self ZeroValue(const Self &) { return ZeroValue(); }
1237  static Self OneValue(const Self &) { return OneValue(); }
1238  template<typename TArray>
1239  static void AssignToArray( const Self & v, TArray & mv )
1240  {
1241  mv[0] = v.real();
1242  mv[1] = v.imag();
1243  }
1244  static void SetLength(Self & m, const unsigned int s)
1245  {
1246  if ( s != 2 )
1247  {
1248  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1249  }
1251  }
1252 };
1253 
1259 template< >
1260 class NumericTraits< std::complex< unsigned short > >
1261 {
1262 public:
1263  typedef std::complex< unsigned short > Self;
1264  // for backward compatibility
1265  typedef Self TheType;
1266  typedef unsigned short ValueType;
1267  typedef Self PrintType;
1268  typedef double AbsType;
1269  typedef Self AccumulateType;
1270  typedef std::complex< double > RealType;
1271  typedef double ScalarRealType;
1272  typedef std::complex< float > FloatType;
1273  typedef FixedArray<unsigned short, 2> MeasurementVectorType;
1274 
1275  static const Self ITKCommon_EXPORT Zero;
1276  static const Self ITKCommon_EXPORT One;
1277 
1278  static Self min() { return std::numeric_limits< Self >::min(); }
1279  static Self max() { return std::numeric_limits< Self >::max(); }
1280  static Self min(Self) { return min(); }
1281  static Self max(Self) { return max(); }
1282  static Self NonpositiveMin()
1283  {
1284  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1285  }
1286 
1287  static bool IsPositive(Self val) { return val.real() > 0; }
1288  static bool IsNonpositive(Self val) { return val.real() == 0; }
1289  static bool IsNegative(Self) { return false; }
1290  static bool IsNonnegative(Self) { return true; }
1291  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1292  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1293  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1294  static Self ZeroValue() { return Zero; }
1295  static Self OneValue() { return One; }
1296  static unsigned int GetLength(const Self &) { return 2; }
1297  static unsigned int GetLength() { return 2; }
1298  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1299  static Self ZeroValue(const Self &) { return ZeroValue(); }
1300  static Self OneValue(const Self &) { return OneValue(); }
1301  template<typename TArray>
1302  static void AssignToArray( const Self & v, TArray & mv )
1303  {
1304  mv[0] = v.real();
1305  mv[1] = v.imag();
1306  }
1307  static void SetLength(Self & m, const unsigned int s)
1308  {
1309  if ( s != 2 )
1310  {
1311  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1312  }
1314  }
1315 };
1316 
1322 template< >
1323 class NumericTraits< std::complex< int > >
1324 {
1325 public:
1326  typedef std::complex< int > Self;
1327  // for backward compatibility
1328  typedef Self TheType;
1329  typedef int ValueType;
1330  typedef Self PrintType;
1331  typedef double AbsType;
1332  typedef Self AccumulateType;
1333  typedef std::complex< double > RealType;
1334  typedef double ScalarRealType;
1335  typedef std::complex< float > FloatType;
1336  typedef FixedArray<int, 2> MeasurementVectorType;
1337 
1338  static const Self ITKCommon_EXPORT Zero;
1339  static const Self ITKCommon_EXPORT One;
1340 
1341  static Self min() { return std::numeric_limits< Self >::min(); }
1342  static Self max() { return std::numeric_limits< Self >::max(); }
1343  static Self min(Self) { return min(); }
1344  static Self max(Self) { return max(); }
1345  static Self NonpositiveMin()
1346  {
1347  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1348  }
1349 
1350  static bool IsPositive(Self val) { return val.real() > 0; }
1351  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1352  static bool IsNegative(Self val) { return val.real() < 0; }
1353  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1354  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1355  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1356  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1357  static Self ZeroValue() { return Zero; }
1358  static Self OneValue() { return One; }
1359  static unsigned int GetLength(const Self &) { return 2; }
1360  static unsigned int GetLength() { return 2; }
1361  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1362  static Self ZeroValue(const Self &) { return ZeroValue(); }
1363  static Self OneValue(const Self &) { return OneValue(); }
1364  template<typename TArray>
1365  static void AssignToArray( const Self & v, TArray & mv )
1366  {
1367  mv[0] = v.real();
1368  mv[1] = v.imag();
1369  }
1370  static void SetLength(Self & m, const unsigned int s)
1371  {
1372  if ( s != 2 )
1373  {
1374  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1375  }
1377  }
1378 };
1379 
1385 template< >
1386 class NumericTraits< std::complex< unsigned int > >
1387 {
1388 public:
1389  typedef std::complex< unsigned int > Self;
1390  // for backward compatibility
1391  typedef Self TheType;
1392  typedef unsigned int ValueType;
1393  typedef Self PrintType;
1394  typedef double AbsType;
1395  typedef Self AccumulateType;
1396  typedef std::complex< double > RealType;
1397  typedef double ScalarRealType;
1398  typedef std::complex< float > FloatType;
1399  typedef FixedArray<unsigned int, 2> MeasurementVectorType;
1400 
1401  static const Self ITKCommon_EXPORT Zero;
1402  static const Self ITKCommon_EXPORT One;
1403 
1404  static Self min() { return std::numeric_limits< Self >::min(); }
1405  static Self max() { return std::numeric_limits< Self >::max(); }
1406  static Self min(Self) { return min(); }
1407  static Self max(Self) { return max(); }
1408  static Self NonpositiveMin()
1409  {
1410  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1411  }
1412 
1413  static bool IsPositive(Self val) { return val.real() > 0; }
1414  static bool IsNonpositive(Self val) { return val.real() == 0; }
1415  static bool IsNegative(Self) { return false; }
1416  static bool IsNonnegative(Self) { return true; }
1417  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1418  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1419  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1420  static Self ZeroValue() { return Zero; }
1421  static Self OneValue() { return One; }
1422  static unsigned int GetLength(const Self &) { return 2; }
1423  static unsigned int GetLength() { return 2; }
1424  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1425  static Self ZeroValue(const Self &) { return ZeroValue(); }
1426  static Self OneValue(const Self &) { return OneValue(); }
1427  template<typename TArray>
1428  static void AssignToArray( const Self & v, TArray & mv )
1429  {
1430  mv[0] = v.real();
1431  mv[1] = v.imag();
1432  }
1433  static void SetLength(Self & m, const unsigned int s)
1434  {
1435  if ( s != 2 )
1436  {
1437  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1438  }
1440  }
1441 };
1442 
1448 template< >
1449 class NumericTraits< std::complex< long > >
1450 {
1451 public:
1452  typedef std::complex< long > Self;
1453  // for backward compatibility
1454  typedef Self TheType;
1455  typedef long ValueType;
1456  typedef Self PrintType;
1457  typedef double AbsType;
1458  typedef Self AccumulateType;
1459  typedef std::complex< double > RealType;
1460  typedef double ScalarRealType;
1461  typedef std::complex< float > FloatType;
1462  typedef FixedArray<long, 2> MeasurementVectorType;
1463 
1464  static const Self ITKCommon_EXPORT Zero;
1465  static const Self ITKCommon_EXPORT One;
1466 
1467  static Self min() { return std::numeric_limits< Self >::min(); }
1468  static Self max() { return std::numeric_limits< Self >::max(); }
1469  static Self min(Self) { return min(); }
1470  static Self max(Self) { return max(); }
1471  static Self NonpositiveMin()
1472  {
1473  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1474  }
1475 
1476  static bool IsPositive(Self val) { return val.real() > 0; }
1477  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1478  static bool IsNegative(Self val) { return val.real() < 0; }
1479  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1480  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1481  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1482  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1483  static Self ZeroValue() { return Zero; }
1484  static Self OneValue() { return One; }
1485  static unsigned int GetLength(const Self &) { return 2; }
1486  static unsigned int GetLength() { return 2; }
1487  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1488  static Self ZeroValue(const Self &) { return ZeroValue(); }
1489  static Self OneValue(const Self &) { return OneValue(); }
1490  template<typename TArray>
1491  static void AssignToArray( const Self & v, TArray & mv )
1492  {
1493  mv[0] = v.real();
1494  mv[1] = v.imag();
1495  }
1496  static void SetLength(Self & m, const unsigned int s)
1497  {
1498  if ( s != 2 )
1499  {
1500  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1501  }
1503  }
1504 };
1505 
1511 template< >
1512 class NumericTraits< std::complex< unsigned long > >
1513 {
1514 public:
1515  typedef std::complex< unsigned long > Self;
1516  // for backward compatibility
1517  typedef Self TheType;
1518  typedef unsigned long ValueType;
1519  typedef Self PrintType;
1520  typedef double AbsType;
1521  typedef Self AccumulateType;
1522  typedef std::complex< double > RealType;
1523  typedef double ScalarRealType;
1524  typedef std::complex< float > FloatType;
1525  typedef FixedArray<unsigned long, 2> MeasurementVectorType;
1526 
1527  static const Self ITKCommon_EXPORT Zero;
1528  static const Self ITKCommon_EXPORT One;
1529 
1530  static Self min() { return std::numeric_limits< Self >::min(); }
1531  static Self max() { return std::numeric_limits< Self >::max(); }
1532  static Self min(Self) { return min(); }
1533  static Self max(Self) { return max(); }
1534  static Self NonpositiveMin()
1535  {
1536  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1537  }
1538 
1539  static bool IsPositive(Self val) { return val.real() > 0; }
1540  static bool IsNonpositive(Self val) { return val.real() == 0; }
1541  static bool IsNegative(Self) { return false; }
1542  static bool IsNonnegative(Self) { return true; }
1543  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1544  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1545  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1546  static Self ZeroValue() { return Zero; }
1547  static Self OneValue() { return One; }
1548  static unsigned int GetLength(const Self &) { return 2; }
1549  static unsigned int GetLength() { return 2; }
1550  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1551  static Self ZeroValue(const Self &) { return ZeroValue(); }
1552  static Self OneValue(const Self &) { return OneValue(); }
1553  template<typename TArray>
1554  static void AssignToArray( const Self & v, TArray & mv )
1555  {
1556  mv[0] = v.real();
1557  mv[1] = v.imag();
1558  }
1559  static void SetLength(Self & m, const unsigned int s)
1560  {
1561  if ( s != 2 )
1562  {
1563  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1564  }
1566  }
1567 };
1568 
1574 template< >
1575 class NumericTraits< std::complex< float > >
1576 {
1577 public:
1578  typedef std::complex< float > Self;
1579  // for backward compatibility
1580  typedef Self TheType;
1581  typedef float ValueType;
1582  typedef Self PrintType;
1583  typedef double AbsType;
1584  typedef Self AccumulateType;
1585  typedef std::complex< double > RealType;
1586  typedef double ScalarRealType;
1587  typedef std::complex< float > FloatType;
1588  typedef FixedArray<float, 2> MeasurementVectorType;
1589 
1590  static const Self ITKCommon_EXPORT Zero;
1591  static const Self ITKCommon_EXPORT One;
1592 
1593  static Self min() { return std::numeric_limits< Self >::min(); }
1594  static Self max() { return std::numeric_limits< Self >::max(); }
1595  static Self min(Self) { return min(); }
1596  static Self max(Self) { return max(); }
1597  static Self NonpositiveMin()
1598  {
1599  return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
1600  }
1601 
1602  static bool IsPositive(Self val) { return val.real() > 0.0; }
1603  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1604  static bool IsNegative(Self val) { return val.real() < 0.0; }
1605  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1606  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1607  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1608  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1609  static Self ZeroValue() { return Zero; }
1610  static Self OneValue() { return One; }
1611  static unsigned int GetLength(const Self &) { return 2; }
1612  static unsigned int GetLength() { return 2; }
1613  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1614  static Self ZeroValue(const Self &) { return ZeroValue(); }
1615  static Self OneValue(const Self &) { return OneValue(); }
1616  template<typename TArray>
1617  static void AssignToArray( const Self & v, TArray & mv )
1618  {
1619  mv[0] = v.real();
1620  mv[1] = v.imag();
1621  }
1622  static void SetLength(Self & m, const unsigned int s)
1623  {
1624  if ( s != 2 )
1625  {
1626  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1627  }
1629  }
1630 };
1631 
1637 template< >
1638 class NumericTraits< std::complex< double > >
1639 {
1640 public:
1641  typedef std::complex< double > Self;
1642  // for backward compatibility
1643  typedef Self TheType;
1644  typedef double ValueType;
1645  typedef Self PrintType;
1646  typedef double AbsType;
1647  typedef Self AccumulateType;
1648  typedef std::complex< double > RealType;
1649  typedef double ScalarRealType;
1650  typedef std::complex< float > FloatType;
1651  typedef FixedArray<double, 2> MeasurementVectorType;
1652 
1653  static const Self ITKCommon_EXPORT Zero;
1654  static const Self ITKCommon_EXPORT One;
1655 
1656  static Self min() { return std::numeric_limits< ValueType >::min(); }
1657  static Self max() { return std::numeric_limits< ValueType >::max(); }
1658  static Self min(Self) { return min(); }
1659  static Self max(Self) { return max(); }
1660  static Self NonpositiveMin()
1661  {
1662  return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
1663  }
1664 
1665  static bool IsPositive(Self val) { return val.real() > 0.0; }
1666  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1667  static bool IsNegative(Self val) { return val.real() < 0.0; }
1668  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1669  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1670  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1671  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1672  static Self ZeroValue() { return Zero; }
1673  static Self OneValue() { return One; }
1674  static unsigned int GetLength(const Self &) { return 2; }
1675  static unsigned int GetLength() { return 2; }
1676  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1677  static Self ZeroValue(const Self &) { return ZeroValue(); }
1678  static Self OneValue(const Self &) { return OneValue(); }
1679  template<typename TArray>
1680  static void AssignToArray( const Self & v, TArray & mv )
1681  {
1682  mv[0] = v.real();
1683  mv[1] = v.imag();
1684  }
1685  static void SetLength(Self & m, const unsigned int s)
1686  {
1687  if ( s != 2 )
1688  {
1689  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1690  }
1692  }
1693 };
1694 
1700 template< >
1701 class NumericTraits< std::complex< long double > >
1702 {
1703 public:
1704  typedef std::complex< long double > Self;
1705  // for backward compatibility
1706  typedef Self TheType;
1707  typedef long double ValueType;
1708  typedef Self PrintType;
1709  typedef long double AbsType;
1710  typedef Self AccumulateType;
1711  typedef std::complex< long double > RealType;
1712  typedef long double ScalarRealType;
1713  typedef std::complex< float > FloatType;
1714  typedef FixedArray<long double, 2> MeasurementVectorType;
1715 
1716  static const Self ITKCommon_EXPORT Zero;
1717  static const Self ITKCommon_EXPORT One;
1718 
1719  static Self min() { return std::numeric_limits< ValueType >::min(); }
1720  static Self max() { return std::numeric_limits< ValueType >::max(); }
1721  static Self min(Self) { return min(); }
1722  static Self max(Self) { return max(); }
1723  static Self NonpositiveMin()
1724  {
1725  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
1726  }
1727 
1728  static bool IsPositive(Self val) { return val.real() > 0.0; }
1729  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1730  static bool IsNegative(Self val) { return val.real() < 0.0; }
1731  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1732  static ITK_CONSTEXPR_VAR bool IsSigned = NumericTraits< ValueType >::IsSigned;
1733  static ITK_CONSTEXPR_VAR bool IsInteger = false;
1734  static ITK_CONSTEXPR_VAR bool IsComplex = true;
1735  static Self ZeroValue() { return Zero; }
1736  static Self OneValue() { return One; }
1737  static unsigned int GetLength(const Self &) { return 2; }
1738  static unsigned int GetLength() { return 2; }
1739  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1740  static Self ZeroValue(const Self &) { return ZeroValue(); }
1741  static Self OneValue(const Self &) { return OneValue(); }
1742  template<typename TArray>
1743  static void AssignToArray( const Self & v, TArray & mv )
1744  {
1745  mv[0] = v.real();
1746  mv[1] = v.imag();
1747  }
1748  static void SetLength(Self & m, const unsigned int s)
1749  {
1750  if ( s != 2 )
1751  {
1752  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1753  }
1755  }
1756 };
1757 
1759 
1760 } // end namespace itk
1761 
1762 #undef itkNUMERIC_TRAITS_C11_ASSINMENT
1763 #include "itkFixedArray.h"
1764 
1765 #endif // itkNumericTraits_h
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
static T OneValue(const T &)
static ITK_CONSTEXPR_VAR bool IsComplex
static void AssignToArray(const T &v, TArray &mv)
static bool IsPositive(T val)
static ITK_CONSTEXPR_VAR bool IsInteger
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
static const T Zero
static ITK_CONSTEXPR_FUNC T max(const T &)
static bool IsNonnegative(T val)
static T NonpositiveMin(const T &)
std::numeric_limits< T > TraitsType
static unsigned int GetLength()
static void SetLength(T &m, const unsigned int s)
static bool IsNegative(T val)
static T ZeroValue(const T &)
#define itkNUMERIC_TRAITS_C11_ASSINMENT(x)
static ITK_CONSTEXPR_FUNC T NonpositiveMin()
static ITK_CONSTEXPR_FUNC T min(const T &)
static ITK_CONSTEXPR_VAR bool IsSigned
static bool IsNonpositive(T val)
static const T One
FixedArray< ValueType, 1 > MeasurementVectorType
Define additional traits for native types such as int or float.
static unsigned int GetLength(const T &)