ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkNumericTraits.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkNumericTraits_h
19 #define itkNumericTraits_h
20 
21 #include "itkMacro.h"
22 
23 #undef min
24 #undef max
25 
26 #define itkNUMERIC_TRAITS_MIN_MAX_MACRO() \
27  static ValueType min() \
28  { \
29  return std::numeric_limits< ValueType >::min(); \
30  } \
31  static ValueType max() \
32  { \
33  return std::numeric_limits< ValueType >::max(); \
34  } \
35  static ValueType min(ValueType) \
36  { \
37  return std::numeric_limits< ValueType >::min(); \
38  } \
39  static ValueType max(ValueType) \
40  { \
41  return std::numeric_limits< ValueType >::max(); \
42  } \
43 
44 
45 #include "vcl_limits.h" // for std::numeric_limits
46 #include <complex>
47 
48 namespace itk
49 {
50 
51 // forward decare to avoid circular dependencies
52 template< typename TValue, unsigned int VLength> class FixedArray;
53 
69 template< typename T >
70 class NumericTraits:public std::numeric_limits< T >
71 {
72 public:
74  typedef std::numeric_limits< T > TraitsType;
75 
77  typedef T ValueType;
78 
80  typedef T PrintType;
81 
83  typedef T AbsType;
84 
86  typedef double AccumulateType;
87 
90 
93  typedef float FloatType;
94 
96  typedef double RealType;
97 
100 
102  static const T Zero;
103 
105  static const T One;
106 
108  static T NonpositiveMin() { return TraitsType::min(); }
109 
111  static bool IsPositive(T val) { return val > Zero; }
112 
114  static bool IsNonpositive(T val) { return val <= Zero; }
115 
117  static bool IsNegative(T val) { return val < Zero; }
118 
120  static bool IsNonnegative(T val) { return val >= Zero; }
121 
124  static T ZeroValue() { return Zero; }
125 
128  static T OneValue() { return One; }
129 
130  /* Provide a default implementation of the max() method with
131  * argument. This API is needed for VariableLengthVector because
132  * its length is only known at run-time. Specializations of the
133  * VariableLengthVector will provide a different implementation
134  * where a vector of the correct size is built. */
135  static T max(const T &) { return TraitsType::max(); }
136  static T min(const T &) { return TraitsType::min(); }
137 
145  static void SetLength(T & m, const unsigned int s)
146  {
147  if ( s != 1 )
148  {
149  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
150  }
152  }
153 
160  static unsigned int GetLength(const T &)
161  {
162  return GetLength();
163  }
164 
166  static unsigned int GetLength()
167  {
168  return 1;
169  }
170 
174  static T NonpositiveMin(const T &)
175  {
176  return NonpositiveMin();
177  }
178 
182  static T ZeroValue(const T &)
183  {
184  return ZeroValue();
185  }
186 
190  static T OneValue(const T &)
191  {
192  return OneValue();
193  }
194 
196  template<typename TArray>
197  static void AssignToArray( const T & v, TArray & mv )
198  {
199  mv[0] = v;
200  }
201 
202 };
203 
213 template< >
214 class NumericTraits< bool > :public std::numeric_limits< bool >
215 {
216 public:
217  typedef bool ValueType;
218  typedef bool PrintType;
219  typedef unsigned char AbsType;
220  typedef unsigned char AccumulateType;
221  typedef double RealType;
222  typedef RealType ScalarRealType;
223  typedef float FloatType;
224  typedef FixedArray<ValueType, 1> MeasurementVectorType;
225 
226  static const bool ITKCommon_EXPORT Zero;
227  static const bool ITKCommon_EXPORT One;
228 
229  static bool min() { return false; }
230  static bool max() { return true; }
231  static bool min(bool) { return min(); }
232  static bool max(bool) { return max(); }
233  static bool NonpositiveMin() { return false; }
234  static bool IsPositive(bool val) { return val; }
235  static bool IsNonpositive(bool val) { return !val; }
236  static bool IsNegative(bool val) { return val ? false : false; }
237  static bool IsNonnegative(bool val) { return val ? true : true; }
238  static bool ZeroValue() { return Zero; }
239  static bool OneValue() { return One; }
240  static unsigned int GetLength(const ValueType &) { return 1; }
241  static unsigned int GetLength() { return 1; }
242  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
243  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
244  static ValueType OneValue(const ValueType &) { return OneValue(); }
245 
246  template<typename TArray>
247  static void AssignToArray( const ValueType & v, TArray & mv )
248  {
249  mv[0] = v;
250  }
251  static void SetLength(ValueType & m, const unsigned int s)
252  {
253  if ( s != 1 )
254  {
255  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
256  }
258  }
259 
260 };
261 
267 template< >
268 class NumericTraits< char > :public std::numeric_limits< char >
269 {
270 public:
271  typedef char ValueType;
272  typedef int PrintType;
273  typedef unsigned char AbsType;
274  typedef short AccumulateType;
275  typedef double RealType;
276  typedef RealType ScalarRealType;
277  typedef float FloatType;
278  typedef FixedArray<ValueType, 1> MeasurementVectorType;
279 
280  static const char ITKCommon_EXPORT Zero;
281  static const char ITKCommon_EXPORT One;
282 
283  static char min() { return char(255) < char(0) ? char(-128) : char(0); }
284  static char max() { return char(255) < char(0) ? char(127) : char(255); }
285 
286  static char min(char) { return min(); }
287  static char max(char) { return max(); }
288  static char NonpositiveMin() { return min(); }
289  static bool IsPositive(char val) { return val > Zero; }
290  static bool IsNonpositive(char val) { return val <= Zero; }
291 // char on PowerPC, for example, is not signed
292 #if VCL_CHAR_IS_SIGNED
293  static bool IsNegative(char val) { return val < Zero; }
294  static bool IsNonnegative(char val) { return val >= Zero; }
295 #else
296  static bool IsNegative(char) { return false; }
297  static bool IsNonnegative(char) { return true; }
298 #endif
299  static char ZeroValue() { return Zero; }
300  static char OneValue() { return One; }
301  static unsigned int GetLength(const ValueType &) { return 1; }
302  static unsigned int GetLength() { return 1; }
303  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
304  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
305  static ValueType OneValue(const ValueType &) { return OneValue(); }
306 
307  template<typename TArray>
308  static void AssignToArray( const ValueType & v, TArray & mv )
309  {
310  mv[0] = v;
311  }
312  static void SetLength(ValueType & m, const unsigned int s)
313  {
314  if ( s != 1 )
315  {
316  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
317  }
319  }
320 };
321 
327 template< >
328 class NumericTraits< signed char > :public std::numeric_limits< signed char >
329 {
330 public:
331  typedef signed char ValueType;
332  typedef int PrintType;
333  typedef unsigned char AbsType;
334  typedef short AccumulateType;
335  typedef double RealType;
336  typedef RealType ScalarRealType;
337  typedef float FloatType;
338  typedef FixedArray<ValueType, 1> MeasurementVectorType;
339 
340  static const signed char ITKCommon_EXPORT Zero;
341  static const signed char ITKCommon_EXPORT One;
342 
343  static signed char min() { return -128; }
344  static signed char max() { return 127; }
345  static signed char min(signed char) { return min(); }
346  static signed char max(signed char) { return max(); }
347  static signed char NonpositiveMin() { return min(); }
348  static bool IsPositive(signed char val) { return val > Zero; }
349  static bool IsNonpositive(signed char val) { return val <= Zero; }
350  static bool IsNegative(signed char val) { return val < Zero; }
351  static bool IsNonnegative(signed char val) { return val >= Zero; }
352  static signed char ZeroValue() { return Zero; }
353  static signed char OneValue() { return One; }
354  static unsigned int GetLength(const ValueType &) { return 1; }
355  static unsigned int GetLength() { return 1; }
356  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
357  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
358  static ValueType OneValue(const ValueType &) { return OneValue(); }
359 
360  template<typename TArray>
361  static void AssignToArray( const ValueType & v, TArray & mv )
362  {
363  mv[0] = v;
364  }
365  static void SetLength(ValueType & m, const unsigned int s)
366  {
367  if ( s != 1 )
368  {
369  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
370  }
372  }
373 };
374 
380 template< >
381 class NumericTraits< unsigned char > :public std::numeric_limits< unsigned char >
382 {
383 public:
384  typedef unsigned char ValueType;
385  typedef int PrintType;
386  typedef unsigned char AbsType;
387  typedef unsigned short AccumulateType;
388  typedef double RealType;
389  typedef RealType ScalarRealType;
390  typedef float FloatType;
391  typedef FixedArray<ValueType, 1> MeasurementVectorType;
392 
393  static const unsigned char ITKCommon_EXPORT Zero;
394  static const unsigned char ITKCommon_EXPORT One;
395 
397 
398  static unsigned char NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
399  static bool IsPositive(unsigned char val) { return val != Zero; }
400  static bool IsNonpositive(unsigned char val) { return val == Zero; }
401  static bool IsNegative(unsigned char val) { return val ? false : false; }
402  static bool IsNonnegative(unsigned char val) { return val ? true : true; }
403  static unsigned char ZeroValue() { return Zero; }
404  static unsigned char OneValue() { return One; }
405  static unsigned int GetLength(const ValueType &) { return 1; }
406  static unsigned int GetLength() { return 1; }
407  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
408  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
409  static ValueType OneValue(const ValueType &) { return OneValue(); }
410 
411  template<typename TArray>
412  static void AssignToArray( const ValueType & v, TArray & mv )
413  {
414  mv[0] = v;
415  }
416  static void SetLength(ValueType & m, const unsigned int s)
417  {
418  if ( s != 1 )
419  {
420  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
421  }
423  }
424 };
425 
430 template< >
431 class NumericTraits< short > :public std::numeric_limits< short >
432 {
433 public:
434  typedef short ValueType;
435  typedef short PrintType;
436  typedef unsigned short AbsType;
437  typedef int AccumulateType;
438  typedef double RealType;
439  typedef RealType ScalarRealType;
440  typedef float FloatType;
441  typedef FixedArray<ValueType, 1> MeasurementVectorType;
442 
443  static const short ITKCommon_EXPORT Zero;
444  static const short ITKCommon_EXPORT One;
445 
447  static short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
448  static bool IsPositive(short val) { return val > Zero; }
449  static bool IsNonpositive(short val) { return val <= Zero; }
450  static bool IsNegative(short val) { return val < Zero; }
451  static bool IsNonnegative(short val) { return val >= Zero; }
452  static short ZeroValue() { return Zero; }
453  static short OneValue() { return One; }
454  static unsigned int GetLength(const ValueType &) { return 1; }
455  static unsigned int GetLength() { return 1; }
456  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
457  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
458  static ValueType OneValue(const ValueType &) { return OneValue(); }
459 
460  template<typename TArray>
461  static void AssignToArray( const ValueType & v, TArray & mv )
462  {
463  mv[0] = v;
464  }
465  static void SetLength(ValueType & m, const unsigned int s)
466  {
467  if ( s != 1 )
468  {
469  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
470  }
472  }
473 };
474 
480 template< >
481 class NumericTraits< unsigned short > :public std::numeric_limits< unsigned short >
482 {
483 public:
484  typedef unsigned short ValueType;
485  typedef unsigned short PrintType;
486  typedef unsigned short AbsType;
487  typedef unsigned int AccumulateType;
488  typedef double RealType;
489  typedef RealType ScalarRealType;
490  typedef float FloatType;
491  typedef FixedArray<ValueType, 1> MeasurementVectorType;
492 
493  static const unsigned short ITKCommon_EXPORT Zero;
494  static const unsigned short ITKCommon_EXPORT One;
495 
497  static unsigned short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
498  static bool IsPositive(unsigned short val) { return val != Zero; }
499  static bool IsNonpositive(unsigned short val) { return val == Zero; }
500  static bool IsNegative(unsigned short val) { return val ? false : false; }
501  static bool IsNonnegative(unsigned short val) { return val ? true : true; }
502  static unsigned short ZeroValue() { return Zero; }
503  static unsigned short OneValue() { return One; }
504  static unsigned int GetLength(const ValueType &) { return 1; }
505  static unsigned int GetLength() { return 1; }
506  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
507  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
508  static ValueType OneValue(const ValueType &) { return OneValue(); }
509 
510  template<typename TArray>
511  static void AssignToArray( const ValueType & v, TArray & mv )
512  {
513  mv[0] = v;
514  }
515  static void SetLength(ValueType & m, const unsigned int s)
516  {
517  if ( s != 1 )
518  {
519  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
520  }
522  }
523 };
524 
529 template< >
530 class NumericTraits< int > :public std::numeric_limits< int >
531 {
532 public:
533  typedef int ValueType;
534  typedef int PrintType;
535  typedef unsigned int AbsType;
536  typedef long AccumulateType;
537  typedef double RealType;
538  typedef RealType ScalarRealType;
539  typedef float FloatType;
540  typedef FixedArray<ValueType, 1> MeasurementVectorType;
541 
542  static const int ITKCommon_EXPORT Zero;
543  static const int ITKCommon_EXPORT One;
544 
546  static int NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
547  static bool IsPositive(int val) { return val > Zero; }
548  static bool IsNonpositive(int val) { return val <= Zero; }
549  static bool IsNegative(int val) { return val < Zero; }
550  static bool IsNonnegative(int val) { return val >= Zero; }
551  static int ZeroValue() { return Zero; }
552  static int OneValue() { return One; }
553  static unsigned int GetLength(const ValueType &) { return 1; }
554  static unsigned int GetLength() { return 1; }
555  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
556  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
557  static ValueType OneValue(const ValueType &) { return OneValue(); }
558 
559  template<typename TArray>
560  static void AssignToArray( const ValueType & v, TArray & mv )
561  {
562  mv[0] = v;
563  }
564  static void SetLength(ValueType & m, const unsigned int s)
565  {
566  if ( s != 1 )
567  {
568  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
569  }
571  }
572 };
573 
579 template< >
580 class NumericTraits< unsigned int > :public std::numeric_limits< unsigned int >
581 {
582 public:
583  typedef unsigned int ValueType;
584  typedef unsigned int PrintType;
585  typedef unsigned int AbsType;
586  typedef unsigned int AccumulateType;
587  typedef double RealType;
588  typedef RealType ScalarRealType;
589  typedef float FloatType;
590  typedef FixedArray<ValueType, 1> MeasurementVectorType;
591 
592  static const unsigned int ITKCommon_EXPORT Zero;
593  static const unsigned int ITKCommon_EXPORT One;
594 
595  static unsigned int min(void) { return 0; }
596  static unsigned int max(void) { return static_cast< unsigned int >( -1 ); }
597  static unsigned int min(unsigned int) { return std::numeric_limits< ValueType >::min(); }
598  static unsigned int max(unsigned int) { return std::numeric_limits< ValueType >::max(); }
599  static unsigned int NonpositiveMin() { return 0; }
600  static bool IsPositive(unsigned int val) { return val != Zero; }
601  static bool IsNonpositive(unsigned int val) { return val == Zero; }
602  static bool IsNegative(unsigned int val) { return val ? false : false; }
603  static bool IsNonnegative(unsigned int val) { return val ? true : true; }
604  static unsigned int ZeroValue() { return Zero; }
605  static unsigned int OneValue() { return One; }
606  static unsigned int GetLength(const ValueType &) { return 1; }
607  static unsigned int GetLength() { return 1; }
608  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
609  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
610  static ValueType OneValue(const ValueType &) { return OneValue(); }
611 
612  template<typename TArray>
613  static void AssignToArray( const ValueType & v, TArray & mv )
614  {
615  mv[0] = v;
616  }
617  static void SetLength(ValueType & m, const unsigned int s)
618  {
619  if ( s != 1 )
620  {
621  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
622  }
624  }
625 };
626 
632 template< >
633 class NumericTraits< long > :public std::numeric_limits< long >
634 {
635 public:
636  typedef long ValueType;
637  typedef long PrintType;
638  typedef unsigned long AbsType;
639  typedef long AccumulateType;
640  typedef double RealType;
641  typedef RealType ScalarRealType;
642  typedef float FloatType;
643  typedef FixedArray<ValueType, 1> MeasurementVectorType;
644 
645  static const long ITKCommon_EXPORT Zero;
646  static const long ITKCommon_EXPORT One;
647 
649  static long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
650  static bool IsPositive(long val) { return val > Zero; }
651  static bool IsNonpositive(long val) { return val <= Zero; }
652  static bool IsNegative(long val) { return val < Zero; }
653  static bool IsNonnegative(long val) { return val >= Zero; }
654  static long ZeroValue() { return Zero; }
655  static long OneValue() { return One; }
656  static unsigned int GetLength(const ValueType &) { return 1; }
657  static unsigned int GetLength() { return 1; }
658  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
659  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
660  static ValueType OneValue(const ValueType &) { return OneValue(); }
661 
662  template<typename TArray>
663  static void AssignToArray( const ValueType & v, TArray & mv )
664  {
665  mv[0] = v;
666  }
667  static void SetLength(ValueType & m, const unsigned int s)
668  {
669  if ( s != 1 )
670  {
671  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
672  }
674  }
675 };
676 
682 template< >
683 class NumericTraits< unsigned long > :public std::numeric_limits< unsigned long >
684 {
685 public:
686  typedef unsigned long ValueType;
687  typedef unsigned long PrintType;
688  typedef unsigned long AbsType;
689  typedef unsigned long AccumulateType;
690  typedef double RealType;
691  typedef RealType ScalarRealType;
692  typedef float FloatType;
693  typedef FixedArray<ValueType, 1> MeasurementVectorType;
694 
695  static const unsigned long ITKCommon_EXPORT Zero;
696  static const unsigned long ITKCommon_EXPORT One;
697 
699  static unsigned long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
700  static bool IsPositive(unsigned long val) { return val != Zero; }
701  static bool IsNonpositive(unsigned long val) { return val == Zero; }
702  static bool IsNegative(unsigned long) { return false; }
703  static bool IsNonnegative(unsigned long) { return true; }
704  static unsigned long ZeroValue() { return Zero; }
705  static unsigned long OneValue() { return One; }
706  static unsigned int GetLength(const ValueType &) { return 1; }
707  static unsigned int GetLength() { return 1; }
708  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
709  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
710  static ValueType OneValue(const ValueType &) { return OneValue(); }
711 
712  template<typename TArray>
713  static void AssignToArray( const ValueType & v, TArray & mv )
714  {
715  mv[0] = v;
716  }
717  static void SetLength(ValueType & m, const unsigned int s)
718  {
719  if ( s != 1 )
720  {
721  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
722  }
724  }
725 };
726 
732 template< >
733 class NumericTraits< float > :public std::numeric_limits< float >
734 {
735 public:
736  typedef float ValueType;
737  typedef float PrintType;
738  typedef float AbsType;
739  typedef double AccumulateType;
740  typedef double RealType;
741  typedef RealType ScalarRealType;
742  typedef float FloatType;
743  typedef FixedArray<ValueType, 1> MeasurementVectorType;
744 
745  static const float ITKCommon_EXPORT Zero;
746  static const float ITKCommon_EXPORT One;
747 
749  static float NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
750  static bool IsPositive(float val) { return val > Zero; }
751  static bool IsNonpositive(float val) { return val <= Zero; }
752  static bool IsNegative(float val) { return val < Zero; }
753  static bool IsNonnegative(float val) { return val >= Zero; }
754  static float ZeroValue() { return Zero; }
755  static float OneValue() { return One; }
756  static unsigned int GetLength(const ValueType &) { return 1; }
757  static unsigned int GetLength() { return 1; }
758  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
759  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
760  static ValueType OneValue(const ValueType &) { return OneValue(); }
761 
762  template<typename TArray>
763  static void AssignToArray( const ValueType & v, TArray & mv )
764  {
765  mv[0] = v;
766  }
767  static void SetLength(ValueType & m, const unsigned int s)
768  {
769  if ( s != 1 )
770  {
771  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
772  }
774  }
775 };
776 
782 template< >
783 class NumericTraits< double > :public std::numeric_limits< double >
784 {
785 public:
786  typedef double ValueType;
787  typedef double PrintType;
788  typedef double AbsType;
789  typedef double AccumulateType;
790  typedef double RealType;
791  typedef RealType ScalarRealType;
792  typedef float FloatType;
793  typedef FixedArray<ValueType, 1> MeasurementVectorType;
794 
795  static const double ITKCommon_EXPORT Zero;
796  static const double ITKCommon_EXPORT One;
797 
799  static double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
800  static bool IsPositive(double val) { return val > Zero; }
801  static bool IsNonpositive(double val) { return val <= Zero; }
802  static bool IsNegative(double val) { return val < Zero; }
803  static bool IsNonnegative(double val) { return val >= Zero; }
804  static double ZeroValue() { return Zero; }
805  static double OneValue() { return One; }
806  static unsigned int GetLength(const ValueType &) { return 1; }
807  static unsigned int GetLength() { return 1; }
808  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
809  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
810  static ValueType OneValue(const ValueType &) { return OneValue(); }
811 
812  template<typename TArray>
813  static void AssignToArray( const ValueType & v, TArray & mv )
814  {
815  mv[0] = v;
816  }
817  static void SetLength(ValueType & m, const unsigned int s)
818  {
819  if ( s != 1 )
820  {
821  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
822  }
824  }
825 };
826 
832 template< >
833 class NumericTraits< long double > :public std::numeric_limits< long double >
834 {
835 public:
836  typedef long double ValueType;
837 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
838  // sun studio in 32 bit mode is unable to print long double values: it
839  // segfaults.
840  // conversion to double will give usable results if the value is in the double
841  // range - better than nothing.
842  typedef double PrintType;
843 #else
844  typedef long double PrintType;
845 #endif
846  typedef long double AbsType;
847  typedef long double AccumulateType;
848  typedef long double RealType;
849  typedef RealType ScalarRealType;
850  typedef float FloatType;
851  typedef FixedArray<ValueType, 1> MeasurementVectorType;
852 
853  static const long double ITKCommon_EXPORT Zero;
854  static const long double ITKCommon_EXPORT One;
855 
857  static long double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
858  static bool IsPositive(long double val) { return val > Zero; }
859  static bool IsNonpositive(long double val) { return val <= Zero; }
860  static bool IsNegative(long double val) { return val < Zero; }
861  static bool IsNonnegative(long double val) { return val >= Zero; }
862  static long double ZeroValue() { return Zero; }
863  static long double OneValue() { return One; }
864  static unsigned int GetLength(const ValueType &) { return 1; }
865  static unsigned int GetLength() { return 1; }
866  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
867  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
868  static ValueType OneValue(const ValueType &) { return OneValue(); }
869 
870  template<typename TArray>
871  static void AssignToArray( const ValueType & v, TArray & mv )
872  {
873  mv[0] = v;
874  }
875  static void SetLength(ValueType & m, const unsigned int s)
876  {
877  if ( s != 1 )
878  {
879  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
880  }
882  }
883 };
884 
890 template< >
891 class NumericTraits< std::complex< char > >
892 {
893 public:
894  typedef std::complex< char > Self;
895  // for backward compatibility
896  typedef Self TheType;
897  typedef char ValueType;
898  typedef std::complex< int > PrintType;
899  typedef double AbsType;
900  typedef Self AccumulateType;
901  typedef std::complex< double > RealType;
902  typedef double ScalarRealType;
903  typedef std::complex< float > FloatType;
904  typedef FixedArray<char, 2> MeasurementVectorType;
905 
906  static const Self ITKCommon_EXPORT Zero;
907  static const Self ITKCommon_EXPORT One;
908 
909  static Self min() { return std::numeric_limits< Self >::min(); }
910  static Self max() { return std::numeric_limits< Self >::max(); }
911  static Self min(Self) { return min(); }
912  static Self max(Self) { return max(); }
913  static Self NonpositiveMin()
914  {
915  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
916  }
917 
918  static bool IsPositive(Self val) { return val.real() > 0; }
919  static bool IsNonpositive(Self val) { return val.real() <= 0; }
920 // char on PowerPC, for example, is not signed
921 #if VCL_CHAR_IS_SIGNED
922  static bool IsNegative(Self val) { return val.real() < 0; }
923  static bool IsNonnegative(Self val) { return val.real() >= 0; }
924 #else
925  static bool IsNegative(Self) { return false; }
926  static bool IsNonnegative(Self) { return true; }
927 #endif
928  static Self ZeroValue() { return Zero; }
929  static Self OneValue() { return One; }
930  static unsigned int GetLength(const Self &) { return 2; }
931  static unsigned int GetLength() { return 2; }
932  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
933  static Self ZeroValue(const Self &) { return ZeroValue(); }
934  static Self OneValue(const Self &) { return OneValue(); }
935  template<typename TArray>
936  static void AssignToArray( const Self & v, TArray & mv )
937  {
938  mv[0] = v.real();
939  mv[1] = v.imag();
940  }
941  static void SetLength(Self & m, const unsigned int s)
942  {
943  if ( s != 2 )
944  {
945  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
946  }
948  }
949 };
950 
956 template< >
957 class NumericTraits< std::complex< unsigned char > >
958 {
959 public:
960  typedef std::complex< unsigned char > Self;
961  // for backward compatibility
962  typedef Self TheType;
963  typedef unsigned char ValueType;
964  typedef std::complex< unsigned int > PrintType;
965  typedef double AbsType;
966  typedef Self AccumulateType;
967  typedef std::complex< double > RealType;
968  typedef double ScalarRealType;
969  typedef std::complex< float > FloatType;
970  typedef FixedArray<unsigned char, 2> MeasurementVectorType;
971 
972  static const Self ITKCommon_EXPORT Zero;
973  static const Self ITKCommon_EXPORT One;
974 
975  static Self min() { return std::numeric_limits< Self >::min(); }
976  static Self max() { return std::numeric_limits< Self >::max(); }
977  static Self min(Self) { return min(); }
978  static Self max(Self) { return max(); }
979  static Self NonpositiveMin()
980  {
981  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
982  }
983 
984  static bool IsPositive(Self val) { return val.real() > 0; }
985  static bool IsNonpositive(Self val) { return val.real() == 0; }
986  static bool IsNegative(Self) { return false; }
987  static bool IsNonnegative(Self) { return true; }
988  static Self ZeroValue() { return Zero; }
989  static Self OneValue() { return One; }
990  static unsigned int GetLength(const Self &) { return 2; }
991  static unsigned int GetLength() { return 2; }
992  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
993  static Self ZeroValue(const Self &) { return ZeroValue(); }
994  static Self OneValue(const Self &) { return OneValue(); }
995  template<typename TArray>
996  static void AssignToArray( const Self & v, TArray & mv )
997  {
998  mv[0] = v.real();
999  mv[1] = v.imag();
1000  }
1001  static void SetLength(Self & m, const unsigned int s)
1002  {
1003  if ( s != 2 )
1004  {
1005  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1006  }
1008  }
1009 };
1010 
1016 template< >
1017 class NumericTraits< std::complex< short > >
1018 {
1019 public:
1020  typedef std::complex< short > Self;
1021  // for backward compatibility
1022  typedef Self TheType;
1023  typedef short ValueType;
1024  typedef Self PrintType;
1025  typedef double AbsType;
1026  typedef Self AccumulateType;
1027  typedef std::complex< double > RealType;
1028  typedef double ScalarRealType;
1029  typedef std::complex< float > FloatType;
1030  typedef FixedArray<short, 2> MeasurementVectorType;
1031 
1032  static const Self ITKCommon_EXPORT Zero;
1033  static const Self ITKCommon_EXPORT One;
1034 
1035  static Self min() { return std::numeric_limits< Self >::min(); }
1036  static Self max() { return std::numeric_limits< Self >::max(); }
1037  static Self min(Self) { return min(); }
1038  static Self max(Self) { return max(); }
1039  static Self NonpositiveMin()
1040  {
1041  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1042  }
1043 
1044  static bool IsPositive(Self val) { return val.real() > 0; }
1045  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1046  static bool IsNegative(Self val) { return val.real() < 0; }
1047  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1048  static Self ZeroValue() { return Zero; }
1049  static Self OneValue() { return One; }
1050  static unsigned int GetLength(const Self &) { return 2; }
1051  static unsigned int GetLength() { return 2; }
1052  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1053  static Self ZeroValue(const Self &) { return ZeroValue(); }
1054  static Self OneValue(const Self &) { return OneValue(); }
1055  template<typename TArray>
1056  static void AssignToArray( const Self & v, TArray & mv )
1057  {
1058  mv[0] = v.real();
1059  mv[1] = v.imag();
1060  }
1061  static void SetLength(Self & m, const unsigned int s)
1062  {
1063  if ( s != 2 )
1064  {
1065  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1066  }
1068  }
1069 };
1070 
1076 template< >
1077 class NumericTraits< std::complex< unsigned short > >
1078 {
1079 public:
1080  typedef std::complex< unsigned short > Self;
1081  // for backward compatibility
1082  typedef Self TheType;
1083  typedef unsigned short ValueType;
1084  typedef Self PrintType;
1085  typedef double AbsType;
1086  typedef Self AccumulateType;
1087  typedef std::complex< double > RealType;
1088  typedef double ScalarRealType;
1089  typedef std::complex< float > FloatType;
1090  typedef FixedArray<unsigned short, 2> MeasurementVectorType;
1091 
1092  static const Self ITKCommon_EXPORT Zero;
1093  static const Self ITKCommon_EXPORT One;
1094 
1095  static Self min() { return std::numeric_limits< Self >::min(); }
1096  static Self max() { return std::numeric_limits< Self >::max(); }
1097  static Self min(Self) { return min(); }
1098  static Self max(Self) { return max(); }
1099  static Self NonpositiveMin()
1100  {
1101  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1102  }
1103 
1104  static bool IsPositive(Self val) { return val.real() > 0; }
1105  static bool IsNonpositive(Self val) { return val.real() == 0; }
1106  static bool IsNegative(Self) { return false; }
1107  static bool IsNonnegative(Self) { return true; }
1108  static Self ZeroValue() { return Zero; }
1109  static Self OneValue() { return One; }
1110  static unsigned int GetLength(const Self &) { return 2; }
1111  static unsigned int GetLength() { return 2; }
1112  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1113  static Self ZeroValue(const Self &) { return ZeroValue(); }
1114  static Self OneValue(const Self &) { return OneValue(); }
1115  template<typename TArray>
1116  static void AssignToArray( const Self & v, TArray & mv )
1117  {
1118  mv[0] = v.real();
1119  mv[1] = v.imag();
1120  }
1121  static void SetLength(Self & m, const unsigned int s)
1122  {
1123  if ( s != 2 )
1124  {
1125  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1126  }
1128  }
1129 };
1130 
1136 template< >
1137 class NumericTraits< std::complex< int > >
1138 {
1139 public:
1140  typedef std::complex< int > Self;
1141  // for backward compatibility
1142  typedef Self TheType;
1143  typedef int ValueType;
1144  typedef Self PrintType;
1145  typedef double AbsType;
1146  typedef Self AccumulateType;
1147  typedef std::complex< double > RealType;
1148  typedef double ScalarRealType;
1149  typedef std::complex< float > FloatType;
1150  typedef FixedArray<int, 2> MeasurementVectorType;
1151 
1152  static const Self ITKCommon_EXPORT Zero;
1153  static const Self ITKCommon_EXPORT One;
1154 
1155  static Self min() { return std::numeric_limits< Self >::min(); }
1156  static Self max() { return std::numeric_limits< Self >::max(); }
1157  static Self min(Self) { return min(); }
1158  static Self max(Self) { return max(); }
1159  static Self NonpositiveMin()
1160  {
1161  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1162  }
1163 
1164  static bool IsPositive(Self val) { return val.real() > 0; }
1165  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1166  static bool IsNegative(Self val) { return val.real() < 0; }
1167  static bool IsNonnegative(Self val) { return val.real() >= 0; }
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< unsigned int > >
1198 {
1199 public:
1200  typedef std::complex< unsigned int > Self;
1201  // for backward compatibility
1202  typedef Self TheType;
1203  typedef unsigned int 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<unsigned int, 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) { return false; }
1227  static bool IsNonnegative(Self) { return true; }
1228  static Self ZeroValue() { return Zero; }
1229  static Self OneValue() { return One; }
1230  static unsigned int GetLength(const Self &) { return 2; }
1231  static unsigned int GetLength() { return 2; }
1232  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1233  static Self ZeroValue(const Self &) { return ZeroValue(); }
1234  static Self OneValue(const Self &) { return OneValue(); }
1235  template<typename TArray>
1236  static void AssignToArray( const Self & v, TArray & mv )
1237  {
1238  mv[0] = v.real();
1239  mv[1] = v.imag();
1240  }
1241  static void SetLength(Self & m, const unsigned int s)
1242  {
1243  if ( s != 2 )
1244  {
1245  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1246  }
1248  }
1249 };
1250 
1256 template< >
1257 class NumericTraits< std::complex< long > >
1258 {
1259 public:
1260  typedef std::complex< long > Self;
1261  // for backward compatibility
1262  typedef Self TheType;
1263  typedef long ValueType;
1264  typedef Self PrintType;
1265  typedef double AbsType;
1266  typedef Self AccumulateType;
1267  typedef std::complex< double > RealType;
1268  typedef double ScalarRealType;
1269  typedef std::complex< float > FloatType;
1270  typedef FixedArray<long, 2> MeasurementVectorType;
1271 
1272  static const Self ITKCommon_EXPORT Zero;
1273  static const Self ITKCommon_EXPORT One;
1274 
1275  static Self min() { return std::numeric_limits< Self >::min(); }
1276  static Self max() { return std::numeric_limits< Self >::max(); }
1277  static Self min(Self) { return min(); }
1278  static Self max(Self) { return max(); }
1279  static Self NonpositiveMin()
1280  {
1281  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1282  }
1283 
1284  static bool IsPositive(Self val) { return val.real() > 0; }
1285  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1286  static bool IsNegative(Self val) { return val.real() < 0; }
1287  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1288  static Self ZeroValue() { return Zero; }
1289  static Self OneValue() { return One; }
1290  static unsigned int GetLength(const Self &) { return 2; }
1291  static unsigned int GetLength() { return 2; }
1292  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1293  static Self ZeroValue(const Self &) { return ZeroValue(); }
1294  static Self OneValue(const Self &) { return OneValue(); }
1295  template<typename TArray>
1296  static void AssignToArray( const Self & v, TArray & mv )
1297  {
1298  mv[0] = v.real();
1299  mv[1] = v.imag();
1300  }
1301  static void SetLength(Self & m, const unsigned int s)
1302  {
1303  if ( s != 2 )
1304  {
1305  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1306  }
1308  }
1309 };
1310 
1316 template< >
1317 class NumericTraits< std::complex< unsigned long > >
1318 {
1319 public:
1320  typedef std::complex< unsigned long > Self;
1321  // for backward compatibility
1322  typedef Self TheType;
1323  typedef unsigned long ValueType;
1324  typedef Self PrintType;
1325  typedef double AbsType;
1326  typedef Self AccumulateType;
1327  typedef std::complex< double > RealType;
1328  typedef double ScalarRealType;
1329  typedef std::complex< float > FloatType;
1330  typedef FixedArray<unsigned long, 2> MeasurementVectorType;
1331 
1332  static const Self ITKCommon_EXPORT Zero;
1333  static const Self ITKCommon_EXPORT One;
1334 
1335  static Self min() { return std::numeric_limits< Self >::min(); }
1336  static Self max() { return std::numeric_limits< Self >::max(); }
1337  static Self min(Self) { return min(); }
1338  static Self max(Self) { return max(); }
1339  static Self NonpositiveMin()
1340  {
1341  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1342  }
1343 
1344  static bool IsPositive(Self val) { return val.real() > 0; }
1345  static bool IsNonpositive(Self val) { return val.real() == 0; }
1346  static bool IsNegative(Self) { return false; }
1347  static bool IsNonnegative(Self) { return true; }
1348  static Self ZeroValue() { return Zero; }
1349  static Self OneValue() { return One; }
1350  static unsigned int GetLength(const Self &) { return 2; }
1351  static unsigned int GetLength() { return 2; }
1352  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1353  static Self ZeroValue(const Self &) { return ZeroValue(); }
1354  static Self OneValue(const Self &) { return OneValue(); }
1355  template<typename TArray>
1356  static void AssignToArray( const Self & v, TArray & mv )
1357  {
1358  mv[0] = v.real();
1359  mv[1] = v.imag();
1360  }
1361  static void SetLength(Self & m, const unsigned int s)
1362  {
1363  if ( s != 2 )
1364  {
1365  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1366  }
1368  }
1369 };
1370 
1376 template< >
1377 class NumericTraits< std::complex< float > >
1378 {
1379 public:
1380  typedef std::complex< float > Self;
1381  // for backward compatibility
1382  typedef Self TheType;
1383  typedef float ValueType;
1384  typedef Self PrintType;
1385  typedef double AbsType;
1386  typedef Self AccumulateType;
1387  typedef std::complex< double > RealType;
1388  typedef double ScalarRealType;
1389  typedef std::complex< float > FloatType;
1390  typedef FixedArray<float, 2> MeasurementVectorType;
1391 
1392  static const Self ITKCommon_EXPORT Zero;
1393  static const Self ITKCommon_EXPORT One;
1394 
1395  static Self min() { return std::numeric_limits< Self >::min(); }
1396  static Self max() { return std::numeric_limits< Self >::max(); }
1397  static Self min(Self) { return min(); }
1398  static Self max(Self) { return max(); }
1399  static Self NonpositiveMin()
1400  {
1401  return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
1402  }
1403 
1404  static bool IsPositive(Self val) { return val.real() > 0.0; }
1405  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1406  static bool IsNegative(Self val) { return val.real() < 0.0; }
1407  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1408  static Self ZeroValue() { return Zero; }
1409  static Self OneValue() { return One; }
1410  static unsigned int GetLength(const Self &) { return 2; }
1411  static unsigned int GetLength() { return 2; }
1412  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1413  static Self ZeroValue(const Self &) { return ZeroValue(); }
1414  static Self OneValue(const Self &) { return OneValue(); }
1415  template<typename TArray>
1416  static void AssignToArray( const Self & v, TArray & mv )
1417  {
1418  mv[0] = v.real();
1419  mv[1] = v.imag();
1420  }
1421  static void SetLength(Self & m, const unsigned int s)
1422  {
1423  if ( s != 2 )
1424  {
1425  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1426  }
1428  }
1429 };
1430 
1436 template< >
1437 class NumericTraits< std::complex< double > >
1438 {
1439 public:
1440  typedef std::complex< double > Self;
1441  // for backward compatibility
1442  typedef Self TheType;
1443  typedef double ValueType;
1444  typedef Self PrintType;
1445  typedef double AbsType;
1446  typedef Self AccumulateType;
1447  typedef std::complex< double > RealType;
1448  typedef double ScalarRealType;
1449  typedef std::complex< float > FloatType;
1450  typedef FixedArray<double, 2> MeasurementVectorType;
1451 
1452  static const Self ITKCommon_EXPORT Zero;
1453  static const Self ITKCommon_EXPORT One;
1454 
1455  static Self min() { return std::numeric_limits< ValueType >::min(); }
1456  static Self max() { return std::numeric_limits< ValueType >::max(); }
1457  static Self min(Self) { return min(); }
1458  static Self max(Self) { return max(); }
1459  static Self NonpositiveMin()
1460  {
1461  return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
1462  }
1463 
1464  static bool IsPositive(Self val) { return val.real() > 0.0; }
1465  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1466  static bool IsNegative(Self val) { return val.real() < 0.0; }
1467  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1468  static Self ZeroValue() { return Zero; }
1469  static Self OneValue() { return One; }
1470  static unsigned int GetLength(const Self &) { return 2; }
1471  static unsigned int GetLength() { return 2; }
1472  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1473  static Self ZeroValue(const Self &) { return ZeroValue(); }
1474  static Self OneValue(const Self &) { return OneValue(); }
1475  template<typename TArray>
1476  static void AssignToArray( const Self & v, TArray & mv )
1477  {
1478  mv[0] = v.real();
1479  mv[1] = v.imag();
1480  }
1481  static void SetLength(Self & m, const unsigned int s)
1482  {
1483  if ( s != 2 )
1484  {
1485  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1486  }
1488  }
1489 };
1490 
1496 template< >
1497 class NumericTraits< std::complex< long double > >
1498 {
1499 public:
1500  typedef std::complex< long double > Self;
1501  // for backward compatibility
1502  typedef Self TheType;
1503  typedef long double ValueType;
1504  typedef Self PrintType;
1505  typedef long double AbsType;
1506  typedef Self AccumulateType;
1507  typedef std::complex< long double > RealType;
1508  typedef long double ScalarRealType;
1509  typedef std::complex< float > FloatType;
1510  typedef FixedArray<long double, 2> MeasurementVectorType;
1511 
1512  static const Self ITKCommon_EXPORT Zero;
1513  static const Self ITKCommon_EXPORT One;
1514 
1515  static Self min() { return std::numeric_limits< ValueType >::min(); }
1516  static Self max() { return std::numeric_limits< ValueType >::max(); }
1517  static Self min(Self) { return min(); }
1518  static Self max(Self) { return max(); }
1519  static Self NonpositiveMin()
1520  {
1521  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
1522  }
1523 
1524  static bool IsPositive(Self val) { return val.real() > 0.0; }
1525  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1526  static bool IsNegative(Self val) { return val.real() < 0.0; }
1527  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1528  static Self ZeroValue() { return Zero; }
1529  static Self OneValue() { return One; }
1530  static unsigned int GetLength(const Self &) { return 2; }
1531  static unsigned int GetLength() { return 2; }
1532  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1533  static Self ZeroValue(const Self &) { return ZeroValue(); }
1534  static Self OneValue(const Self &) { return OneValue(); }
1535  template<typename TArray>
1536  static void AssignToArray( const Self & v, TArray & mv )
1537  {
1538  mv[0] = v.real();
1539  mv[1] = v.imag();
1540  }
1541  static void SetLength(Self & m, const unsigned int s)
1542  {
1543  if ( s != 2 )
1544  {
1545  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1546  }
1548  }
1549 };
1550 
1556 template< >
1557 class NumericTraits< long long > :
1558  public std::numeric_limits< long long >
1559 {
1560 public:
1561  typedef long long ValueType;
1562  typedef long long PrintType;
1563  typedef long long AbsType;
1564  typedef long long AccumulateType;
1565  typedef double RealType;
1566  typedef RealType ScalarRealType;
1567  typedef float FloatType;
1568  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1569 
1570  static const ValueType ITKCommon_EXPORT Zero;
1571  static const ValueType ITKCommon_EXPORT One;
1572 
1574  static ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
1575  static bool IsPositive(ValueType val) { return val > Zero; }
1576  static bool IsNonpositive(ValueType val) { return val <= Zero; }
1577  static bool IsNegative(ValueType val) { return val < Zero; }
1578  static bool IsNonnegative(ValueType val) { return val >= Zero; }
1579  static ValueType ZeroValue() { return Zero; }
1580  static ValueType OneValue() { return One; }
1581  static unsigned int GetLength(const ValueType &) { return 1; }
1582  static unsigned int GetLength() { return 1; }
1583  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1584  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1585  static ValueType OneValue(const ValueType &) { return OneValue(); }
1586 
1587  template<typename TArray>
1588  static void AssignToArray( const ValueType & v, TArray & mv )
1589  {
1590  mv[0] = v;
1591  }
1592  static void SetLength(ValueType & m, const unsigned int s)
1593  {
1594  if ( s != 1 )
1595  {
1596  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1597  }
1599  }
1600 };
1601 
1607 template< >
1608 class NumericTraits< unsigned long long > :
1609  public std::numeric_limits< unsigned long long >
1610 {
1611 public:
1612  typedef unsigned long long ValueType;
1613  typedef unsigned long long PrintType;
1614  typedef unsigned long long AbsType;
1615  typedef unsigned long long AccumulateType;
1616  typedef double RealType;
1617  typedef RealType ScalarRealType;
1618  typedef float FloatType;
1619  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1620 
1621  static const ValueType ITKCommon_EXPORT Zero;
1622  static const ValueType ITKCommon_EXPORT One;
1623 
1625  static ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
1626  static bool IsPositive(ValueType val) { return val != Zero; }
1627  static bool IsNonpositive(ValueType val) { return val == Zero; }
1628  static bool IsNegative(ValueType) { return false; }
1629  static bool IsNonnegative(ValueType) { return true; }
1630  static ValueType ZeroValue() { return Zero; }
1631  static ValueType OneValue() { return One; }
1632  static unsigned int GetLength(const ValueType &) { return 1; }
1633  static unsigned int GetLength() { return 1; }
1634  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1635  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1636  static ValueType OneValue(const ValueType &) { return OneValue(); }
1637 
1638  template<typename TArray>
1639  static void AssignToArray( const ValueType & v, TArray & mv )
1640  {
1641  mv[0] = v;
1642  }
1643  static void SetLength(ValueType & m, const unsigned int s)
1644  {
1645  if ( s != 1 )
1646  {
1647  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1648  }
1650  }
1651 };
1652 
1655 } // end namespace itk
1656 
1657 #include "itkFixedArray.h"
1658 
1659 #endif // itkNumericTraits_h
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
static T OneValue(const T &)
static void AssignToArray(const T &v, TArray &mv)
static bool IsPositive(T val)
static T min(const T &)
Simulate a standard C array with copy semnatics.
Definition: itkFixedArray.h:50
static const T Zero
static bool IsNonnegative(T val)
static T NonpositiveMin(const T &)
std::numeric_limits< T > TraitsType
static unsigned int GetLength()
static T max(const T &)
static void SetLength(T &m, const unsigned int s)
static bool IsNegative(T val)
static T ZeroValue(const T &)
static bool IsNonpositive(T val)
static const T One
FixedArray< ValueType, 1 > MeasurementVectorType
Define additional traits for native types such as int or float.
static unsigned int GetLength(const T &)