ITK  5.0.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 constexpr ValueType min(ValueType) \
28  { \
29  return std::numeric_limits< ValueType >::min(); \
30  } \
31  static constexpr ValueType max(ValueType) \
32  { \
33  return std::numeric_limits< ValueType >::max(); \
34  } \
35  static constexpr ValueType min() \
36  { \
37  return std::numeric_limits< ValueType >::min(); \
38  } \
39  static constexpr ValueType max() \
40  { \
41  return std::numeric_limits< ValueType >::max(); \
42  }
43 
44 #include <limits> // for std::numeric_limits
45 #include <complex>
46 
47 namespace itk
48 {
49 
50 // forward decare to avoid circular dependencies
51 template< typename TValue, unsigned int VLength> class FixedArray;
52 
68 template< typename T >
69 class NumericTraits:public std::numeric_limits< T >
70 {
71 public:
73  using TraitsType = std::numeric_limits< T >;
74 
76  using ValueType = T;
77 
79  using PrintType = T;
80 
82  using AbsType = T;
83 
85  using AccumulateType = double;
86 
88  using MeasurementVectorType = FixedArray<ValueType, 1>;
89 
92  using FloatType = float;
93 
95  using RealType = double;
96 
98  using ScalarRealType = RealType;
99 
101  static const T ITKCommon_EXPORT Zero;
102 
104  static const T ITKCommon_EXPORT One;
105 
107  static constexpr T NonpositiveMin() { return TraitsType::lowest(); }
108 
110  static bool IsPositive(T val) { return val > Zero; }
111 
113  static bool IsNonpositive(T val) { return val <= Zero; }
114 
116  static bool IsNegative(T val) { return val < Zero; }
117 
119  static bool IsNonnegative(T val) { return val >= Zero; }
120 
124  static constexpr bool IsSigned = false;
125 
129  static constexpr bool IsInteger = false;
130 
134  static constexpr bool IsComplex = false;
135 
138  static T ZeroValue() { return Zero; }
139 
142  static T OneValue() { return One; }
143 
144  /* Provide a default implementation of the max() method with
145  * argument. This API is needed for VariableLengthVector because
146  * its length is only known at run-time. Specializations of the
147  * VariableLengthVector will provide a different implementation
148  * where a vector of the correct size is built. */
149  static constexpr T max(const T &) { return TraitsType::max(); }
150  static constexpr T min(const T &) { return TraitsType::min(); }
151 
159  static void SetLength(T & m, const unsigned int s)
160  {
161  if ( s != 1 )
162  {
163  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
164  }
166  }
167 
174  static unsigned int GetLength(const T &)
175  {
176  return GetLength();
177  }
178 
180  static unsigned int GetLength()
181  {
182  return 1;
183  }
184 
188  static T NonpositiveMin(const T &)
189  {
190  return NonpositiveMin();
191  }
192 
196  static T ZeroValue(const T &)
197  {
198  return ZeroValue();
199  }
200 
204  static T OneValue(const T &)
205  {
206  return OneValue();
207  }
208 
210  template<typename TArray>
211  static void AssignToArray( const T & v, TArray & mv )
212  {
213  mv[0] = v;
214  }
215 
216 };
217 
219 
227 template< >
228 class NumericTraits< bool > :public std::numeric_limits< bool >
229 {
230 public:
231  using ValueType = bool;
232  using PrintType = bool;
233  using AbsType = unsigned char;
234  using AccumulateType = unsigned char;
235  using RealType = double;
236  using ScalarRealType = RealType;
237  using FloatType = float;
238  using MeasurementVectorType = FixedArray<ValueType, 1>;
239 
240  static constexpr bool ITKCommon_EXPORT Zero = false;
241  static constexpr bool ITKCommon_EXPORT One = true;
242 
243  static constexpr bool min() { return false; }
244  static constexpr bool max() { return true; }
245  static constexpr bool min(bool) { return min(); }
246  static constexpr bool max(bool) { return max(); }
247  static constexpr bool NonpositiveMin() { return false; }
248  static constexpr bool IsPositive(bool val) { return val; }
249  static constexpr bool IsNonpositive(bool val) { return !val; }
250  static constexpr bool IsNegative(bool val) { return val ? false : false; }
251  static constexpr bool IsNonnegative(bool val) { return val ? true : true; }
252  static constexpr bool IsSigned = false;
253  static constexpr bool IsInteger = true;
254  static constexpr bool IsComplex = false;
255  static constexpr bool ZeroValue() { return Zero; }
256  static constexpr bool OneValue() { return One; }
257  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
258  static constexpr unsigned int GetLength() { return 1; }
259  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
260  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
261  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
262 
263  template<typename TArray>
264  static void AssignToArray( const ValueType & v, TArray & mv )
265  {
266  mv[0] = v;
267  }
268  static void SetLength(ValueType & m, const unsigned int s)
269  {
270  if ( s != 1 )
271  {
272  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
273  }
275  }
276 
277 };
278 
284 template< >
285 class NumericTraits< char > :public std::numeric_limits< char >
286 {
287 public:
288  using ValueType = char;
289  using PrintType = int;
290  using AbsType = unsigned char;
291  using AccumulateType = short;
292  using RealType = double;
293  using ScalarRealType = RealType;
294  using FloatType = float;
295  using MeasurementVectorType = FixedArray<ValueType, 1>;
296 
297  static constexpr char ITKCommon_EXPORT Zero = 0;
298  static constexpr char ITKCommon_EXPORT One = 1;
299 
301 
302  static constexpr char NonpositiveMin() { return lowest(); }
303  static constexpr bool IsPositive(char val) { return val > Zero; }
304  static constexpr bool IsNonpositive(char val) { return val <= Zero; }
305 
306  static constexpr bool IsNegative(char) { return false; }
307  static constexpr bool IsNonnegative(char) { return true; }
308  static constexpr bool IsSigned = std::numeric_limits<char>::is_signed;
309 
310  static constexpr bool IsInteger = std::numeric_limits<char>::is_integer;
311  static constexpr bool IsComplex = false;
312  static constexpr char ZeroValue() { return Zero; }
313  static constexpr char OneValue() { return One; }
314  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
315  static constexpr unsigned int GetLength() { return 1; }
316  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
317  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
318  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
319 
320  template<typename TArray>
321  static void AssignToArray( const ValueType & v, TArray & mv )
322  {
323  mv[0] = v;
324  }
325  static void SetLength(ValueType & m, const unsigned int s)
326  {
327  if ( s != 1 )
328  {
329  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
330  }
332  }
333 };
334 
340 template< >
341 class NumericTraits< signed char > :public std::numeric_limits< signed char >
342 {
343 public:
344  using ValueType = signed char;
345  using PrintType = int;
346  using AbsType = unsigned char;
347  using AccumulateType = short;
348  using RealType = double;
349  using ScalarRealType = RealType;
350  using FloatType = float;
351  using MeasurementVectorType = FixedArray<ValueType, 1>;
352 
353  static constexpr signed char ITKCommon_EXPORT Zero = 0;
354  static constexpr signed char ITKCommon_EXPORT One = 1;
355 
356  static constexpr signed char min() { return -128; }
357  static constexpr signed char max() { return 127; }
358  static constexpr signed char min(signed char) { return min(); }
359  static constexpr signed char max(signed char) { return max(); }
360  static constexpr signed char NonpositiveMin() { return lowest(); }
361  static constexpr bool IsPositive(signed char val) { return val > Zero; }
362  static constexpr bool IsNonpositive(signed char val) { return val <= Zero; }
363  static constexpr bool IsNegative(signed char val) { return val < Zero; }
364  static constexpr bool IsNonnegative(signed char val) { return val >= Zero; }
365  static constexpr bool IsSigned = true;
366  static constexpr bool IsInteger = true;
367  static constexpr bool IsComplex = false;
368  static constexpr signed char ZeroValue() { return Zero; }
369  static constexpr signed char OneValue() { return One; }
370  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
371  static constexpr unsigned int GetLength() { return 1; }
372  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
373  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
374  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
375 
376  template<typename TArray>
377  static void AssignToArray( const ValueType & v, TArray & mv )
378  {
379  mv[0] = v;
380  }
381  static void SetLength(ValueType & m, const unsigned int s)
382  {
383  if ( s != 1 )
384  {
385  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
386  }
388  }
389 };
390 
396 template< >
397 class NumericTraits< unsigned char > :public std::numeric_limits< unsigned char >
398 {
399 public:
400  using ValueType = unsigned char;
401  using PrintType = int;
402  using AbsType = unsigned char;
403  using AccumulateType = unsigned short;
404  using RealType = double;
405  using ScalarRealType = RealType;
406  using FloatType = float;
407  using MeasurementVectorType = FixedArray<ValueType, 1>;
408 
409  static constexpr unsigned char ITKCommon_EXPORT Zero = 0;
410  static constexpr unsigned char ITKCommon_EXPORT One = 1;
411 
413 
414  static constexpr unsigned char NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
415  static constexpr bool IsPositive(unsigned char val) { return val != Zero; }
416  static constexpr bool IsNonpositive(unsigned char val) { return val == Zero; }
417  static constexpr bool IsNegative(unsigned char val) { return val ? false : false; }
418  static constexpr bool IsNonnegative(unsigned char val) { return val ? true : true; }
419  static constexpr bool IsSigned = false;
420  static constexpr bool IsInteger = true;
421  static constexpr bool IsComplex = false;
422  static constexpr unsigned char ZeroValue() { return Zero; }
423  static constexpr unsigned char OneValue() { return One; }
424  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
425  static constexpr unsigned int GetLength() { return 1; }
426  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
427  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
428  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
429 
430  template<typename TArray>
431  static void AssignToArray( const ValueType & v, TArray & mv )
432  {
433  mv[0] = v;
434  }
435  static void SetLength(ValueType & m, const unsigned int s)
436  {
437  if ( s != 1 )
438  {
439  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
440  }
442  }
443 };
444 
449 template< >
450 class NumericTraits< short > :public std::numeric_limits< short >
451 {
452 public:
453  using ValueType = short;
454  using PrintType = short;
455  using AbsType = unsigned short;
456  using AccumulateType = int;
457  using RealType = double;
458  using ScalarRealType = RealType;
459  using FloatType = float;
460  using MeasurementVectorType = FixedArray<ValueType, 1>;
461 
462  static constexpr short ITKCommon_EXPORT Zero = 0;
463  static constexpr short ITKCommon_EXPORT One = 1;
464 
466  static constexpr short NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
467  static constexpr bool IsPositive(short val) { return val > Zero; }
468  static constexpr bool IsNonpositive(short val) { return val <= Zero; }
469  static constexpr bool IsNegative(short val) { return val < Zero; }
470  static constexpr bool IsNonnegative(short val) { return val >= Zero; }
471  static constexpr bool IsSigned = true;
472  static constexpr bool IsInteger = true;
473  static constexpr bool IsComplex = false;
474  static constexpr short ZeroValue() { return Zero; }
475  static constexpr short OneValue() { return One; }
476  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
477  static constexpr unsigned int GetLength() { return 1; }
478  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
479  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
480  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
481 
482  template<typename TArray>
483  static void AssignToArray( const ValueType & v, TArray & mv )
484  {
485  mv[0] = v;
486  }
487  static void SetLength(ValueType & m, const unsigned int s)
488  {
489  if ( s != 1 )
490  {
491  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
492  }
494  }
495 };
496 
502 template< >
503 class NumericTraits< unsigned short > :public std::numeric_limits< unsigned short >
504 {
505 public:
506  using ValueType = unsigned short;
507  using PrintType = unsigned short;
508  using AbsType = unsigned short;
509  using AccumulateType = unsigned int;
510  using RealType = double;
511  using ScalarRealType = RealType;
512  using FloatType = float;
513  using MeasurementVectorType = FixedArray<ValueType, 1>;
514 
515  static constexpr unsigned short ITKCommon_EXPORT Zero = 0;
516  static constexpr unsigned short ITKCommon_EXPORT One = 1;
517 
519  static constexpr unsigned short NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
520  static constexpr bool IsPositive(unsigned short val) { return val != Zero; }
521  static constexpr bool IsNonpositive(unsigned short val) { return val == Zero; }
522  static constexpr bool IsNegative(unsigned short val) { return val ? false : false; }
523  static constexpr bool IsNonnegative(unsigned short val) { return val ? true : true; }
524  static constexpr bool IsSigned = false;
525  static constexpr bool IsInteger = true;
526  static constexpr bool IsComplex = false;
527  static constexpr unsigned short ZeroValue() { return Zero; }
528  static constexpr unsigned short OneValue() { return One; }
529  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
530  static constexpr unsigned int GetLength() { return 1; }
531  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
532  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
533  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
534 
535  template<typename TArray>
536  static void AssignToArray( const ValueType & v, TArray & mv )
537  {
538  mv[0] = v;
539  }
540  static void SetLength(ValueType & m, const unsigned int s)
541  {
542  if ( s != 1 )
543  {
544  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
545  }
547  }
548 };
549 
554 template< >
555 class NumericTraits< int > :public std::numeric_limits< int >
556 {
557 public:
558  using ValueType = int;
559  using PrintType = int;
560  using AbsType = unsigned int;
561  using AccumulateType = long;
562  using RealType = double;
563  using ScalarRealType = RealType;
564  using FloatType = float;
565  using MeasurementVectorType = FixedArray<ValueType, 1>;
566 
567  static constexpr int ITKCommon_EXPORT Zero = 0;
568  static constexpr int ITKCommon_EXPORT One = 1;
569 
571  static constexpr int NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
572  static constexpr bool IsPositive(int val) { return val > Zero; }
573  static constexpr bool IsNonpositive(int val) { return val <= Zero; }
574  static constexpr bool IsNegative(int val) { return val < Zero; }
575  static constexpr bool IsNonnegative(int val) { return val >= Zero; }
576  static constexpr bool IsSigned = true;
577  static constexpr bool IsInteger = true;
578  static constexpr bool IsComplex = false;
579  static constexpr int ZeroValue() { return Zero; }
580  static constexpr int OneValue() { return One; }
581  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
582  static constexpr unsigned int GetLength() { return 1; }
583  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
584  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
585  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
586 
587  template<typename TArray>
588  static void AssignToArray( const ValueType & v, TArray & mv )
589  {
590  mv[0] = v;
591  }
592  static void SetLength(ValueType & m, const unsigned int s)
593  {
594  if ( s != 1 )
595  {
596  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
597  }
599  }
600 };
601 
607 template< >
608 class NumericTraits< unsigned int > :public std::numeric_limits< unsigned int >
609 {
610 public:
611  using ValueType = unsigned int;
612  using PrintType = unsigned int;
613  using AbsType = unsigned int;
614  using AccumulateType = unsigned int;
615  using RealType = double;
616  using ScalarRealType = RealType;
617  using FloatType = float;
618  using MeasurementVectorType = FixedArray<ValueType, 1>;
619 
620  static constexpr unsigned int ITKCommon_EXPORT Zero = 0;
621  static constexpr unsigned int ITKCommon_EXPORT One = 1;
622 
623  static constexpr unsigned int min() { return 0; }
624  static constexpr unsigned int max() { return static_cast< unsigned int >( -1 ); }
625  static constexpr unsigned int min(unsigned int) { return std::numeric_limits< ValueType >::min(); }
626  static constexpr unsigned int max(unsigned int) { return std::numeric_limits< ValueType >::max(); }
627  static constexpr unsigned int NonpositiveMin() { return 0; }
628  static constexpr bool IsPositive(unsigned int val) { return val != Zero; }
629  static constexpr bool IsNonpositive(unsigned int val) { return val == Zero; }
630  static constexpr bool IsNegative(unsigned int val) { return val ? false : false; }
631  static constexpr bool IsNonnegative(unsigned int val) { return val ? true : true; }
632  static constexpr bool IsSigned = false;
633  static constexpr bool IsInteger = true;
634  static constexpr bool IsComplex = false;
635  static constexpr unsigned int ZeroValue() { return Zero; }
636  static constexpr unsigned int OneValue() { return One; }
637  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
638  static constexpr unsigned int GetLength() { return 1; }
639  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
640  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
641  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
642 
643  template<typename TArray>
644  static void AssignToArray( const ValueType & v, TArray & mv )
645  {
646  mv[0] = v;
647  }
648  static void SetLength(ValueType & m, const unsigned int s)
649  {
650  if ( s != 1 )
651  {
652  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
653  }
655  }
656 };
657 
663 template< >
664 class NumericTraits< long > :public std::numeric_limits< long >
665 {
666 public:
667  using ValueType = long;
668  using PrintType = long;
669  using AbsType = unsigned long;
670  using AccumulateType = long;
671  using RealType = double;
672  using ScalarRealType = RealType;
673  using FloatType = float;
674  using MeasurementVectorType = FixedArray<ValueType, 1>;
675 
676  static constexpr long ITKCommon_EXPORT Zero = 0L;
677  static constexpr long ITKCommon_EXPORT One = 1L;
678 
680  static constexpr long NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
681  static constexpr bool IsPositive(long val) { return val > Zero; }
682  static constexpr bool IsNonpositive(long val) { return val <= Zero; }
683  static constexpr bool IsNegative(long val) { return val < Zero; }
684  static constexpr bool IsNonnegative(long val) { return val >= Zero; }
685  static constexpr bool IsSigned = true;
686  static constexpr bool IsInteger = true;
687  static constexpr bool IsComplex = false;
688  static constexpr long ZeroValue() { return Zero; }
689  static constexpr long OneValue() { return One; }
690  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
691  static constexpr unsigned int GetLength() { return 1; }
692  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
693  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
694  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
695 
696  template<typename TArray>
697  static void AssignToArray( const ValueType & v, TArray & mv )
698  {
699  mv[0] = v;
700  }
701  static void SetLength(ValueType & m, const unsigned int s)
702  {
703  if ( s != 1 )
704  {
705  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
706  }
708  }
709 };
710 
716 template< >
717 class NumericTraits< unsigned long > :public std::numeric_limits< unsigned long >
718 {
719 public:
720  using ValueType = unsigned long;
721  using PrintType = unsigned long;
722  using AbsType = unsigned long;
723  using AccumulateType = unsigned long;
724  using RealType = double;
725  using ScalarRealType = RealType;
726  using FloatType = float;
727  using MeasurementVectorType = FixedArray<ValueType, 1>;
728 
729  static constexpr unsigned long ITKCommon_EXPORT Zero = 0UL;
730  static constexpr unsigned long ITKCommon_EXPORT One = 1UL;
731 
733  static constexpr unsigned long NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
734  static constexpr bool IsPositive(unsigned long val) { return val != Zero; }
735  static constexpr bool IsNonpositive(unsigned long val) { return val == Zero; }
736  static constexpr bool IsNegative(unsigned long) { return false; }
737  static constexpr bool IsNonnegative(unsigned long) { return true; }
738  static constexpr bool IsSigned = false;
739  static constexpr bool IsInteger = true;
740  static constexpr bool IsComplex = false;
741  static constexpr unsigned long ZeroValue() { return Zero; }
742  static constexpr unsigned long OneValue() { return One; }
743  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
744  static constexpr unsigned int GetLength() { return 1; }
745  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
746  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
747  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
748 
749  template<typename TArray>
750  static void AssignToArray( const ValueType & v, TArray & mv )
751  {
752  mv[0] = v;
753  }
754  static void SetLength(ValueType & m, const unsigned int s)
755  {
756  if ( s != 1 )
757  {
758  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
759  }
761  }
762 };
763 
769 template< >
770 class NumericTraits< float > :public std::numeric_limits< float >
771 {
772 public:
773  using ValueType = float;
774  using PrintType = float;
775  using AbsType = float;
776  using AccumulateType = double;
777  using RealType = double;
778  using ScalarRealType = RealType;
779  using FloatType = float;
780  using MeasurementVectorType = FixedArray<ValueType, 1>;
781 
782 
783  static constexpr float ITKCommon_EXPORT Zero =0.0f;
784  static constexpr float ITKCommon_EXPORT One =1.0f;
785 
787  static constexpr float NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
788  static constexpr bool IsPositive(float val) { return val > Zero; }
789  static constexpr bool IsNonpositive(float val) { return val <= Zero; }
790  static constexpr bool IsNegative(float val) { return val < Zero; }
791  static constexpr bool IsNonnegative(float val) { return val >= Zero; }
792  static constexpr bool IsSigned = true;
793  static constexpr bool IsInteger = false;
794  static constexpr bool IsComplex = false;
795  static constexpr float ZeroValue() { return Zero; }
796  static constexpr float OneValue() { return One; }
797  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
798  static constexpr unsigned int GetLength() { return 1; }
799  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
800  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
801  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
802 
803  template<typename TArray>
804  static void AssignToArray( const ValueType & v, TArray & mv )
805  {
806  mv[0] = v;
807  }
808  static void SetLength(ValueType & m, const unsigned int s)
809  {
810  if ( s != 1 )
811  {
812  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
813  }
815  }
816 };
817 
823 template< >
824 class NumericTraits< double > :public std::numeric_limits< double >
825 {
826 public:
827  using ValueType = double;
828  using PrintType = double;
829  using AbsType = double;
830  using AccumulateType = double;
831  using RealType = double;
832  using ScalarRealType = RealType;
833  using FloatType = float;
834  using MeasurementVectorType = FixedArray<ValueType, 1>;
835 
836  static constexpr double ITKCommon_EXPORT Zero = 0.0;
837  static constexpr double ITKCommon_EXPORT One = 1.0;
838 
840  static constexpr double NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
841  static constexpr bool IsPositive(double val) { return val > Zero; }
842  static constexpr bool IsNonpositive(double val) { return val <= Zero; }
843  static constexpr bool IsNegative(double val) { return val < Zero; }
844  static constexpr bool IsNonnegative(double val) { return val >= Zero; }
845  static constexpr bool IsSigned = true;
846  static constexpr bool IsInteger = false;
847  static constexpr bool IsComplex = false;
848  static constexpr double ZeroValue() { return Zero; }
849  static constexpr double OneValue() { return One; }
850  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
851  static constexpr unsigned int GetLength() { return 1; }
852  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
853  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
854  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
855 
856  template<typename TArray>
857  static void AssignToArray( const ValueType & v, TArray & mv )
858  {
859  mv[0] = v;
860  }
861  static void SetLength(ValueType & m, const unsigned int s)
862  {
863  if ( s != 1 )
864  {
865  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
866  }
868  }
869 };
870 
876 template< >
877 class NumericTraits< long double > :public std::numeric_limits< long double >
878 {
879 public:
880  using ValueType = long double;
881 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
882  // sun studio in 32 bit mode is unable to print long double values: it
883  // segfaults.
884  // conversion to double will give usable results if the value is in the double
885  // range - better than nothing.
886  using PrintType = double;
887 #else
888  using PrintType = long double;
889 #endif
890  using AbsType = long double;
891  using AccumulateType = long double;
892  using RealType = long double;
893  using ScalarRealType = RealType;
894  using FloatType = float;
895  using MeasurementVectorType = FixedArray<ValueType, 1>;
896 
897  static constexpr long double ITKCommon_EXPORT Zero = 0.0;
898  static constexpr long double ITKCommon_EXPORT One = 1.0;
899 
901  static constexpr long double NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
902  static constexpr bool IsPositive(long double val) { return val > Zero; }
903  static constexpr bool IsNonpositive(long double val) { return val <= Zero; }
904  static constexpr bool IsNegative(long double val) { return val < Zero; }
905  static constexpr bool IsNonnegative(long double val) { return val >= Zero; }
906  static constexpr bool IsSigned = true;
907  static constexpr bool IsInteger = false;
908  static constexpr bool IsComplex = false;
909  static constexpr long double ZeroValue() { return Zero; }
910  static constexpr long double OneValue() { return One; }
911  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
912  static constexpr unsigned int GetLength() { return 1; }
913  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
914  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
915  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
916 
917  template<typename TArray>
918  static void AssignToArray( const ValueType & v, TArray & mv )
919  {
920  mv[0] = v;
921  }
922  static void SetLength(ValueType & m, const unsigned int s)
923  {
924  if ( s != 1 )
925  {
926  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
927  }
929  }
930 };
931 
932 
938 template< >
939 class NumericTraits< long long > :
940  public std::numeric_limits< long long >
941 {
942 public:
943  using ValueType = long long;
944  using PrintType = long long;
945  using AbsType = long long;
946  using AccumulateType = long long;
947  using RealType = double;
948  using ScalarRealType = RealType;
949  using FloatType = float;
950  using MeasurementVectorType = FixedArray<ValueType, 1>;
951 
952  static constexpr ValueType ITKCommon_EXPORT Zero = 0LL;
953  static constexpr ValueType ITKCommon_EXPORT One = 1LL;
954 
956  static constexpr ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
957  static constexpr bool IsPositive(ValueType val) { return val > Zero; }
958  static constexpr bool IsNonpositive(ValueType val) { return val <= Zero; }
959  static constexpr bool IsNegative(ValueType val) { return val < Zero; }
960  static constexpr bool IsNonnegative(ValueType val) { return val >= Zero; }
961  static constexpr bool IsSigned = true;
962  static constexpr bool IsInteger = true;
963  static constexpr bool IsComplex = false;
964  static constexpr ValueType ZeroValue() { return Zero; }
965  static constexpr ValueType OneValue() { return One; }
966  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
967  static constexpr unsigned int GetLength() { return 1; }
968  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
969  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
970  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
971 
972  template<typename TArray>
973  static void AssignToArray( const ValueType & v, TArray & mv )
974  {
975  mv[0] = v;
976  }
977  static void SetLength(ValueType & m, const unsigned int s)
978  {
979  if ( s != 1 )
980  {
981  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
982  }
984  }
985 };
986 
992 template< >
993 class NumericTraits< unsigned long long > :
994  public std::numeric_limits< unsigned long long >
995 {
996 public:
997  using ValueType = unsigned long long;
998  using PrintType = unsigned long long;
999  using AbsType = unsigned long long;
1000  using AccumulateType = unsigned long long;
1001  using RealType = double;
1002  using ScalarRealType = RealType;
1003  using FloatType = float;
1004  using MeasurementVectorType = FixedArray<ValueType, 1>;
1005 
1006  static constexpr ValueType ITKCommon_EXPORT Zero = 0ULL;
1007  static constexpr ValueType ITKCommon_EXPORT One = 1ULL;
1008 
1010  static constexpr ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::lowest(); }
1011  static constexpr bool IsPositive(ValueType val) { return val != Zero; }
1012  static constexpr bool IsNonpositive(ValueType val) { return val == Zero; }
1013  static constexpr bool IsNegative(ValueType) { return false; }
1014  static constexpr bool IsNonnegative(ValueType) { return true; }
1015  static constexpr bool IsSigned = false;
1016  static constexpr bool IsInteger = true;
1017  static constexpr bool IsComplex = false;
1018  static constexpr ValueType ZeroValue() { return Zero; }
1019  static constexpr ValueType OneValue() { return One; }
1020  static constexpr unsigned int GetLength(const ValueType &) { return 1; }
1021  static constexpr unsigned int GetLength() { return 1; }
1022  static constexpr ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1023  static constexpr ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1024  static constexpr ValueType OneValue(const ValueType &) { return OneValue(); }
1025 
1026  template<typename TArray>
1027  static void AssignToArray( const ValueType & v, TArray & mv )
1028  {
1029  mv[0] = v;
1030  }
1031  static void SetLength(ValueType & m, const unsigned int s)
1032  {
1033  if ( s != 1 )
1034  {
1035  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1036  }
1038  }
1039 };
1040 
1041 
1047 template<typename TComponent>
1048 class NumericTraits< std::complex< TComponent > >
1049 {
1050 public:
1051  using Self = std::complex< TComponent >;
1052  // for backward compatibility
1053  using TheType = Self;
1054  using ValueType = TComponent;
1055  using PrintType = Self;
1056  using AbsType = double;
1057  using AccumulateType = Self;
1058  using RealType = std::complex< double >;
1059  using ScalarRealType = double;
1060  using FloatType = std::complex< float >;
1061  using MeasurementVectorType = FixedArray<ValueType, 2>;
1062 
1063  static const Self ITKCommon_EXPORT Zero;
1064  static const Self ITKCommon_EXPORT One;
1065 
1066  static constexpr Self min() { return std::numeric_limits< ValueType >::min(); }
1067  static constexpr Self max() { return std::numeric_limits< ValueType >::max(); }
1068  static constexpr Self min(Self) { return min(); }
1069  static constexpr Self max(Self) { return max(); }
1070  static constexpr ValueType epsilon() { return std::numeric_limits<ValueType>::epsilon(); }
1071  static constexpr Self NonpositiveMin()
1072  {
1074  }
1075 
1076  static constexpr bool IsPositive(Self val) { return val.real() > 0; }
1077  static constexpr bool IsNonpositive(Self val) { return val.real() <= 0; }
1078  static constexpr bool IsNegative(Self val) { return val.real() < 0; }
1079  static constexpr bool IsNonnegative(Self val) { return val.real() >= 0; }
1080 
1081  static constexpr bool IsSigned = NumericTraits< ValueType >::IsSigned;
1082  static constexpr bool IsInteger = false;
1083  static constexpr bool IsComplex = true;
1084  static Self ZeroValue() { return Zero; }
1085  static Self OneValue() { return One; }
1086  static constexpr unsigned int GetLength(const Self &) { return 2; }
1087  static constexpr unsigned int GetLength() { return 2; }
1088  static constexpr Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1089  static Self ZeroValue(const Self &) { return ZeroValue(); }
1090  static Self OneValue(const Self &) { return OneValue(); }
1091 
1092  template<typename TArray>
1093  static void AssignToArray( const Self & v, TArray & mv )
1094  {
1095  mv[0] = v.real();
1096  mv[1] = v.imag();
1097  }
1098  static void SetLength(Self & m, const unsigned int s)
1099  {
1100  if ( s != 2 )
1101  {
1102  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1103  }
1105  }
1106 };
1107 } // end namespace itk
1108 
1109 #include "itkFixedArray.h"
1110 
1111 #endif // itkNumericTraits_h
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
Define numeric traits for std::vector.