ITK  4.6.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  }
257  m = NumericTraits< ValueType >::Zero;
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  static bool IsNegative(char val) { return val < Zero; }
292  static bool IsNonnegative(char val) { return val >= Zero; }
293  static char ZeroValue() { return Zero; }
294  static char OneValue() { return One; }
295  static unsigned int GetLength(const ValueType &) { return 1; }
296  static unsigned int GetLength() { return 1; }
297  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
298  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
299  static ValueType OneValue(const ValueType &) { return OneValue(); }
300 
301  template<typename TArray>
302  static void AssignToArray( const ValueType & v, TArray & mv )
303  {
304  mv[0] = v;
305  }
306  static void SetLength(ValueType & m, const unsigned int s)
307  {
308  if ( s != 1 )
309  {
310  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
311  }
312  m = NumericTraits< ValueType >::Zero;
313  }
314 };
315 
321 template< >
322 class NumericTraits< signed char > :public std::numeric_limits< signed char >
323 {
324 public:
325  typedef signed char ValueType;
326  typedef int PrintType;
327  typedef unsigned char AbsType;
328  typedef short AccumulateType;
329  typedef double RealType;
330  typedef RealType ScalarRealType;
331  typedef float FloatType;
332  typedef FixedArray<ValueType, 1> MeasurementVectorType;
333 
334  static const signed char ITKCommon_EXPORT Zero;
335  static const signed char ITKCommon_EXPORT One;
336 
337  static signed char min() { return -128; }
338  static signed char max() { return 127; }
339  static signed char min(signed char) { return min(); }
340  static signed char max(signed char) { return max(); }
341  static signed char NonpositiveMin() { return min(); }
342  static bool IsPositive(signed char val) { return val > Zero; }
343  static bool IsNonpositive(signed char val) { return val <= Zero; }
344  static bool IsNegative(signed char val) { return val < Zero; }
345  static bool IsNonnegative(signed char val) { return val >= Zero; }
346  static signed char ZeroValue() { return Zero; }
347  static signed char OneValue() { return One; }
348  static unsigned int GetLength(const ValueType &) { return 1; }
349  static unsigned int GetLength() { return 1; }
350  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
351  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
352  static ValueType OneValue(const ValueType &) { return OneValue(); }
353 
354  template<typename TArray>
355  static void AssignToArray( const ValueType & v, TArray & mv )
356  {
357  mv[0] = v;
358  }
359  static void SetLength(ValueType & m, const unsigned int s)
360  {
361  if ( s != 1 )
362  {
363  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
364  }
365  m = NumericTraits< ValueType >::Zero;
366  }
367 };
368 
374 template< >
375 class NumericTraits< unsigned char > :public std::numeric_limits< unsigned char >
376 {
377 public:
378  typedef unsigned char ValueType;
379  typedef int PrintType;
380  typedef unsigned char AbsType;
381  typedef unsigned short AccumulateType;
382  typedef double RealType;
383  typedef RealType ScalarRealType;
384  typedef float FloatType;
385  typedef FixedArray<ValueType, 1> MeasurementVectorType;
386 
387  static const unsigned char ITKCommon_EXPORT Zero;
388  static const unsigned char ITKCommon_EXPORT One;
389 
391 
392  static unsigned char NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
393  static bool IsPositive(unsigned char val) { return val != Zero; }
394  static bool IsNonpositive(unsigned char val) { return val == Zero; }
395  static bool IsNegative(unsigned char val) { return val ? false : false; }
396  static bool IsNonnegative(unsigned char val) { return val ? true : true; }
397  static unsigned char ZeroValue() { return Zero; }
398  static unsigned char OneValue() { return One; }
399  static unsigned int GetLength(const ValueType &) { return 1; }
400  static unsigned int GetLength() { return 1; }
401  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
402  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
403  static ValueType OneValue(const ValueType &) { return OneValue(); }
404 
405  template<typename TArray>
406  static void AssignToArray( const ValueType & v, TArray & mv )
407  {
408  mv[0] = v;
409  }
410  static void SetLength(ValueType & m, const unsigned int s)
411  {
412  if ( s != 1 )
413  {
414  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
415  }
416  m = NumericTraits< ValueType >::Zero;
417  }
418 };
419 
424 template< >
425 class NumericTraits< short > :public std::numeric_limits< short >
426 {
427 public:
428  typedef short ValueType;
429  typedef short PrintType;
430  typedef unsigned short AbsType;
431  typedef int AccumulateType;
432  typedef double RealType;
433  typedef RealType ScalarRealType;
434  typedef float FloatType;
435  typedef FixedArray<ValueType, 1> MeasurementVectorType;
436 
437  static const short ITKCommon_EXPORT Zero;
438  static const short ITKCommon_EXPORT One;
439 
441  static short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
442  static bool IsPositive(short val) { return val > Zero; }
443  static bool IsNonpositive(short val) { return val <= Zero; }
444  static bool IsNegative(short val) { return val < Zero; }
445  static bool IsNonnegative(short val) { return val >= Zero; }
446  static short ZeroValue() { return Zero; }
447  static short OneValue() { return One; }
448  static unsigned int GetLength(const ValueType &) { return 1; }
449  static unsigned int GetLength() { return 1; }
450  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
451  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
452  static ValueType OneValue(const ValueType &) { return OneValue(); }
453 
454  template<typename TArray>
455  static void AssignToArray( const ValueType & v, TArray & mv )
456  {
457  mv[0] = v;
458  }
459  static void SetLength(ValueType & m, const unsigned int s)
460  {
461  if ( s != 1 )
462  {
463  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
464  }
465  m = NumericTraits< ValueType >::Zero;
466  }
467 };
468 
474 template< >
475 class NumericTraits< unsigned short > :public std::numeric_limits< unsigned short >
476 {
477 public:
478  typedef unsigned short ValueType;
479  typedef unsigned short PrintType;
480  typedef unsigned short AbsType;
481  typedef unsigned int AccumulateType;
482  typedef double RealType;
483  typedef RealType ScalarRealType;
484  typedef float FloatType;
485  typedef FixedArray<ValueType, 1> MeasurementVectorType;
486 
487  static const unsigned short ITKCommon_EXPORT Zero;
488  static const unsigned short ITKCommon_EXPORT One;
489 
491  static unsigned short NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
492  static bool IsPositive(unsigned short val) { return val != Zero; }
493  static bool IsNonpositive(unsigned short val) { return val == Zero; }
494  static bool IsNegative(unsigned short val) { return val ? false : false; }
495  static bool IsNonnegative(unsigned short val) { return val ? true : true; }
496  static unsigned short ZeroValue() { return Zero; }
497  static unsigned short OneValue() { return One; }
498  static unsigned int GetLength(const ValueType &) { return 1; }
499  static unsigned int GetLength() { return 1; }
500  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
501  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
502  static ValueType OneValue(const ValueType &) { return OneValue(); }
503 
504  template<typename TArray>
505  static void AssignToArray( const ValueType & v, TArray & mv )
506  {
507  mv[0] = v;
508  }
509  static void SetLength(ValueType & m, const unsigned int s)
510  {
511  if ( s != 1 )
512  {
513  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
514  }
515  m = NumericTraits< ValueType >::Zero;
516  }
517 };
518 
523 template< >
524 class NumericTraits< int > :public std::numeric_limits< int >
525 {
526 public:
527  typedef int ValueType;
528  typedef int PrintType;
529  typedef unsigned int AbsType;
530  typedef long AccumulateType;
531  typedef double RealType;
532  typedef RealType ScalarRealType;
533  typedef float FloatType;
534  typedef FixedArray<ValueType, 1> MeasurementVectorType;
535 
536  static const int ITKCommon_EXPORT Zero;
537  static const int ITKCommon_EXPORT One;
538 
540  static int NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
541  static bool IsPositive(int val) { return val > Zero; }
542  static bool IsNonpositive(int val) { return val <= Zero; }
543  static bool IsNegative(int val) { return val < Zero; }
544  static bool IsNonnegative(int val) { return val >= Zero; }
545  static int ZeroValue() { return Zero; }
546  static int OneValue() { return One; }
547  static unsigned int GetLength(const ValueType &) { return 1; }
548  static unsigned int GetLength() { return 1; }
549  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
550  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
551  static ValueType OneValue(const ValueType &) { return OneValue(); }
552 
553  template<typename TArray>
554  static void AssignToArray( const ValueType & v, TArray & mv )
555  {
556  mv[0] = v;
557  }
558  static void SetLength(ValueType & m, const unsigned int s)
559  {
560  if ( s != 1 )
561  {
562  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
563  }
564  m = NumericTraits< ValueType >::Zero;
565  }
566 };
567 
573 template< >
574 class NumericTraits< unsigned int > :public std::numeric_limits< unsigned int >
575 {
576 public:
577  typedef unsigned int ValueType;
578  typedef unsigned int PrintType;
579  typedef unsigned int AbsType;
580  typedef unsigned int AccumulateType;
581  typedef double RealType;
582  typedef RealType ScalarRealType;
583  typedef float FloatType;
584  typedef FixedArray<ValueType, 1> MeasurementVectorType;
585 
586  static const unsigned int ITKCommon_EXPORT Zero;
587  static const unsigned int ITKCommon_EXPORT One;
588 
589  static unsigned int min(void) { return 0; }
590  static unsigned int max(void) { return static_cast< unsigned int >( -1 ); }
591  static unsigned int min(unsigned int) { return std::numeric_limits< ValueType >::min(); }
592  static unsigned int max(unsigned int) { return std::numeric_limits< ValueType >::max(); }
593  static unsigned int NonpositiveMin() { return 0; }
594  static bool IsPositive(unsigned int val) { return val != Zero; }
595  static bool IsNonpositive(unsigned int val) { return val == Zero; }
596  static bool IsNegative(unsigned int val) { return val ? false : false; }
597  static bool IsNonnegative(unsigned int val) { return val ? true : true; }
598  static unsigned int ZeroValue() { return Zero; }
599  static unsigned int OneValue() { return One; }
600  static unsigned int GetLength(const ValueType &) { return 1; }
601  static unsigned int GetLength() { return 1; }
602  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
603  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
604  static ValueType OneValue(const ValueType &) { return OneValue(); }
605 
606  template<typename TArray>
607  static void AssignToArray( const ValueType & v, TArray & mv )
608  {
609  mv[0] = v;
610  }
611  static void SetLength(ValueType & m, const unsigned int s)
612  {
613  if ( s != 1 )
614  {
615  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
616  }
617  m = NumericTraits< ValueType >::Zero;
618  }
619 };
620 
626 template< >
627 class NumericTraits< long > :public std::numeric_limits< long >
628 {
629 public:
630  typedef long ValueType;
631  typedef long PrintType;
632  typedef unsigned long AbsType;
633  typedef long AccumulateType;
634  typedef double RealType;
635  typedef RealType ScalarRealType;
636  typedef float FloatType;
637  typedef FixedArray<ValueType, 1> MeasurementVectorType;
638 
639  static const long ITKCommon_EXPORT Zero;
640  static const long ITKCommon_EXPORT One;
641 
643  static long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
644  static bool IsPositive(long val) { return val > Zero; }
645  static bool IsNonpositive(long val) { return val <= Zero; }
646  static bool IsNegative(long val) { return val < Zero; }
647  static bool IsNonnegative(long val) { return val >= Zero; }
648  static long ZeroValue() { return Zero; }
649  static long OneValue() { return One; }
650  static unsigned int GetLength(const ValueType &) { return 1; }
651  static unsigned int GetLength() { return 1; }
652  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
653  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
654  static ValueType OneValue(const ValueType &) { return OneValue(); }
655 
656  template<typename TArray>
657  static void AssignToArray( const ValueType & v, TArray & mv )
658  {
659  mv[0] = v;
660  }
661  static void SetLength(ValueType & m, const unsigned int s)
662  {
663  if ( s != 1 )
664  {
665  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
666  }
667  m = NumericTraits< ValueType >::Zero;
668  }
669 };
670 
676 template< >
677 class NumericTraits< unsigned long > :public std::numeric_limits< unsigned long >
678 {
679 public:
680  typedef unsigned long ValueType;
681  typedef unsigned long PrintType;
682  typedef unsigned long AbsType;
683  typedef unsigned long AccumulateType;
684  typedef double RealType;
685  typedef RealType ScalarRealType;
686  typedef float FloatType;
687  typedef FixedArray<ValueType, 1> MeasurementVectorType;
688 
689  static const unsigned long ITKCommon_EXPORT Zero;
690  static const unsigned long ITKCommon_EXPORT One;
691 
693  static unsigned long NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
694  static bool IsPositive(unsigned long val) { return val != Zero; }
695  static bool IsNonpositive(unsigned long val) { return val == Zero; }
696  static bool IsNegative(unsigned long) { return false; }
697  static bool IsNonnegative(unsigned long) { return true; }
698  static unsigned long ZeroValue() { return Zero; }
699  static unsigned long OneValue() { return One; }
700  static unsigned int GetLength(const ValueType &) { return 1; }
701  static unsigned int GetLength() { return 1; }
702  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
703  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
704  static ValueType OneValue(const ValueType &) { return OneValue(); }
705 
706  template<typename TArray>
707  static void AssignToArray( const ValueType & v, TArray & mv )
708  {
709  mv[0] = v;
710  }
711  static void SetLength(ValueType & m, const unsigned int s)
712  {
713  if ( s != 1 )
714  {
715  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
716  }
717  m = NumericTraits< ValueType >::Zero;
718  }
719 };
720 
726 template< >
727 class NumericTraits< float > :public std::numeric_limits< float >
728 {
729 public:
730  typedef float ValueType;
731  typedef float PrintType;
732  typedef float AbsType;
733  typedef double AccumulateType;
734  typedef double RealType;
735  typedef RealType ScalarRealType;
736  typedef float FloatType;
737  typedef FixedArray<ValueType, 1> MeasurementVectorType;
738 
739  static const float ITKCommon_EXPORT Zero;
740  static const float ITKCommon_EXPORT One;
741 
743  static float NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
744  static bool IsPositive(float val) { return val > Zero; }
745  static bool IsNonpositive(float val) { return val <= Zero; }
746  static bool IsNegative(float val) { return val < Zero; }
747  static bool IsNonnegative(float val) { return val >= Zero; }
748  static float ZeroValue() { return Zero; }
749  static float OneValue() { return One; }
750  static unsigned int GetLength(const ValueType &) { return 1; }
751  static unsigned int GetLength() { return 1; }
752  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
753  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
754  static ValueType OneValue(const ValueType &) { return OneValue(); }
755 
756  template<typename TArray>
757  static void AssignToArray( const ValueType & v, TArray & mv )
758  {
759  mv[0] = v;
760  }
761  static void SetLength(ValueType & m, const unsigned int s)
762  {
763  if ( s != 1 )
764  {
765  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
766  }
767  m = NumericTraits< ValueType >::Zero;
768  }
769 };
770 
776 template< >
777 class NumericTraits< double > :public std::numeric_limits< double >
778 {
779 public:
780  typedef double ValueType;
781  typedef double PrintType;
782  typedef double AbsType;
783  typedef double AccumulateType;
784  typedef double RealType;
785  typedef RealType ScalarRealType;
786  typedef float FloatType;
787  typedef FixedArray<ValueType, 1> MeasurementVectorType;
788 
789  static const double ITKCommon_EXPORT Zero;
790  static const double ITKCommon_EXPORT One;
791 
793  static double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
794  static bool IsPositive(double val) { return val > Zero; }
795  static bool IsNonpositive(double val) { return val <= Zero; }
796  static bool IsNegative(double val) { return val < Zero; }
797  static bool IsNonnegative(double val) { return val >= Zero; }
798  static double ZeroValue() { return Zero; }
799  static double OneValue() { return One; }
800  static unsigned int GetLength(const ValueType &) { return 1; }
801  static unsigned int GetLength() { return 1; }
802  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
803  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
804  static ValueType OneValue(const ValueType &) { return OneValue(); }
805 
806  template<typename TArray>
807  static void AssignToArray( const ValueType & v, TArray & mv )
808  {
809  mv[0] = v;
810  }
811  static void SetLength(ValueType & m, const unsigned int s)
812  {
813  if ( s != 1 )
814  {
815  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
816  }
817  m = NumericTraits< ValueType >::Zero;
818  }
819 };
820 
826 template< >
827 class NumericTraits< long double > :public std::numeric_limits< long double >
828 {
829 public:
830  typedef long double ValueType;
831 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
832  // sun studio in 32 bit mode is unable to print long double values: it
833  // segfaults.
834  // conversion to double will give usable results if the value is in the double
835  // range - better than nothing.
836  typedef double PrintType;
837 #else
838  typedef long double PrintType;
839 #endif
840  typedef long double AbsType;
841  typedef long double AccumulateType;
842  typedef long double RealType;
843  typedef RealType ScalarRealType;
844  typedef float FloatType;
845  typedef FixedArray<ValueType, 1> MeasurementVectorType;
846 
847  static const long double ITKCommon_EXPORT Zero;
848  static const long double ITKCommon_EXPORT One;
849 
851  static long double NonpositiveMin() { return -std::numeric_limits< ValueType >::max(); }
852  static bool IsPositive(long double val) { return val > Zero; }
853  static bool IsNonpositive(long double val) { return val <= Zero; }
854  static bool IsNegative(long double val) { return val < Zero; }
855  static bool IsNonnegative(long double val) { return val >= Zero; }
856  static long double ZeroValue() { return Zero; }
857  static long double OneValue() { return One; }
858  static unsigned int GetLength(const ValueType &) { return 1; }
859  static unsigned int GetLength() { return 1; }
860  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
861  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
862  static ValueType OneValue(const ValueType &) { return OneValue(); }
863 
864  template<typename TArray>
865  static void AssignToArray( const ValueType & v, TArray & mv )
866  {
867  mv[0] = v;
868  }
869  static void SetLength(ValueType & m, const unsigned int s)
870  {
871  if ( s != 1 )
872  {
873  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
874  }
875  m = NumericTraits< ValueType >::Zero;
876  }
877 };
878 
884 template< >
885 class NumericTraits< std::complex< char > >
886 {
887 public:
888  typedef std::complex< char > Self;
889  // for backward compatibility
890  typedef Self TheType;
891  typedef char ValueType;
892  typedef std::complex< int > PrintType;
893  typedef double AbsType;
894  typedef Self AccumulateType;
895  typedef std::complex< double > RealType;
896  typedef double ScalarRealType;
897  typedef std::complex< float > FloatType;
898  typedef FixedArray<char, 2> MeasurementVectorType;
899 
900  static const Self ITKCommon_EXPORT Zero;
901  static const Self ITKCommon_EXPORT One;
902 
903  static Self min() { return std::numeric_limits< Self >::min(); }
904  static Self max() { return std::numeric_limits< Self >::max(); }
905  static Self min(Self) { return min(); }
906  static Self max(Self) { return max(); }
907  static Self NonpositiveMin()
908  {
909  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
910  }
911 
912  static bool IsPositive(Self val) { return val.real() > 0; }
913  static bool IsNonpositive(Self val) { return val.real() <= 0; }
914  static bool IsNegative(Self val) { return val.real() < 0; }
915  static bool IsNonnegative(Self val) { return val.real() >= 0; }
916  static Self ZeroValue() { return Zero; }
917  static Self OneValue() { return One; }
918  static unsigned int GetLength(const Self &) { return 2; }
919  static unsigned int GetLength() { return 2; }
920  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
921  static Self ZeroValue(const Self &) { return ZeroValue(); }
922  static Self OneValue(const Self &) { return OneValue(); }
923  template<typename TArray>
924  static void AssignToArray( const Self & v, TArray & mv )
925  {
926  mv[0] = v.real();
927  mv[1] = v.imag();
928  }
929  static void SetLength(Self & m, const unsigned int s)
930  {
931  if ( s != 2 )
932  {
933  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
934  }
935  m = NumericTraits< ValueType >::Zero;
936  }
937 };
938 
944 template< >
945 class NumericTraits< std::complex< unsigned char > >
946 {
947 public:
948  typedef std::complex< unsigned char > Self;
949  // for backward compatibility
950  typedef Self TheType;
951  typedef unsigned char ValueType;
952  typedef std::complex< unsigned int > PrintType;
953  typedef double AbsType;
954  typedef Self AccumulateType;
955  typedef std::complex< double > RealType;
956  typedef double ScalarRealType;
957  typedef std::complex< float > FloatType;
958  typedef FixedArray<unsigned char, 2> MeasurementVectorType;
959 
960  static const Self ITKCommon_EXPORT Zero;
961  static const Self ITKCommon_EXPORT One;
962 
963  static Self min() { return std::numeric_limits< Self >::min(); }
964  static Self max() { return std::numeric_limits< Self >::max(); }
965  static Self min(Self) { return min(); }
966  static Self max(Self) { return max(); }
967  static Self NonpositiveMin()
968  {
969  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
970  }
971 
972  static bool IsPositive(Self val) { return val.real() > 0; }
973  static bool IsNonpositive(Self val) { return val.real() == 0; }
974  static bool IsNegative(Self) { return false; }
975  static bool IsNonnegative(Self) { return true; }
976  static Self ZeroValue() { return Zero; }
977  static Self OneValue() { return One; }
978  static unsigned int GetLength(const Self &) { return 2; }
979  static unsigned int GetLength() { return 2; }
980  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
981  static Self ZeroValue(const Self &) { return ZeroValue(); }
982  static Self OneValue(const Self &) { return OneValue(); }
983  template<typename TArray>
984  static void AssignToArray( const Self & v, TArray & mv )
985  {
986  mv[0] = v.real();
987  mv[1] = v.imag();
988  }
989  static void SetLength(Self & m, const unsigned int s)
990  {
991  if ( s != 2 )
992  {
993  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
994  }
995  m = NumericTraits< ValueType >::Zero;
996  }
997 };
998 
1004 template< >
1005 class NumericTraits< std::complex< short > >
1006 {
1007 public:
1008  typedef std::complex< short > Self;
1009  // for backward compatibility
1010  typedef Self TheType;
1011  typedef short ValueType;
1012  typedef Self PrintType;
1013  typedef double AbsType;
1014  typedef Self AccumulateType;
1015  typedef std::complex< double > RealType;
1016  typedef double ScalarRealType;
1017  typedef std::complex< float > FloatType;
1018  typedef FixedArray<short, 2> MeasurementVectorType;
1019 
1020  static const Self ITKCommon_EXPORT Zero;
1021  static const Self ITKCommon_EXPORT One;
1022 
1023  static Self min() { return std::numeric_limits< Self >::min(); }
1024  static Self max() { return std::numeric_limits< Self >::max(); }
1025  static Self min(Self) { return min(); }
1026  static Self max(Self) { return max(); }
1027  static Self NonpositiveMin()
1028  {
1029  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1030  }
1031 
1032  static bool IsPositive(Self val) { return val.real() > 0; }
1033  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1034  static bool IsNegative(Self val) { return val.real() < 0; }
1035  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1036  static Self ZeroValue() { return Zero; }
1037  static Self OneValue() { return One; }
1038  static unsigned int GetLength(const Self &) { return 2; }
1039  static unsigned int GetLength() { return 2; }
1040  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1041  static Self ZeroValue(const Self &) { return ZeroValue(); }
1042  static Self OneValue(const Self &) { return OneValue(); }
1043  template<typename TArray>
1044  static void AssignToArray( const Self & v, TArray & mv )
1045  {
1046  mv[0] = v.real();
1047  mv[1] = v.imag();
1048  }
1049  static void SetLength(Self & m, const unsigned int s)
1050  {
1051  if ( s != 2 )
1052  {
1053  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1054  }
1055  m = NumericTraits< ValueType >::Zero;
1056  }
1057 };
1058 
1064 template< >
1065 class NumericTraits< std::complex< unsigned short > >
1066 {
1067 public:
1068  typedef std::complex< unsigned short > Self;
1069  // for backward compatibility
1070  typedef Self TheType;
1071  typedef unsigned short ValueType;
1072  typedef Self 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<unsigned short, 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  static bool IsNegative(Self) { return false; }
1095  static bool IsNonnegative(Self) { return true; }
1096  static Self ZeroValue() { return Zero; }
1097  static Self OneValue() { return One; }
1098  static unsigned int GetLength(const Self &) { return 2; }
1099  static unsigned int GetLength() { return 2; }
1100  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1101  static Self ZeroValue(const Self &) { return ZeroValue(); }
1102  static Self OneValue(const Self &) { return OneValue(); }
1103  template<typename TArray>
1104  static void AssignToArray( const Self & v, TArray & mv )
1105  {
1106  mv[0] = v.real();
1107  mv[1] = v.imag();
1108  }
1109  static void SetLength(Self & m, const unsigned int s)
1110  {
1111  if ( s != 2 )
1112  {
1113  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1114  }
1115  m = NumericTraits< ValueType >::Zero;
1116  }
1117 };
1118 
1124 template< >
1125 class NumericTraits< std::complex< int > >
1126 {
1127 public:
1128  typedef std::complex< int > Self;
1129  // for backward compatibility
1130  typedef Self TheType;
1131  typedef int ValueType;
1132  typedef Self PrintType;
1133  typedef double AbsType;
1134  typedef Self AccumulateType;
1135  typedef std::complex< double > RealType;
1136  typedef double ScalarRealType;
1137  typedef std::complex< float > FloatType;
1138  typedef FixedArray<int, 2> MeasurementVectorType;
1139 
1140  static const Self ITKCommon_EXPORT Zero;
1141  static const Self ITKCommon_EXPORT One;
1142 
1143  static Self min() { return std::numeric_limits< Self >::min(); }
1144  static Self max() { return std::numeric_limits< Self >::max(); }
1145  static Self min(Self) { return min(); }
1146  static Self max(Self) { return max(); }
1147  static Self NonpositiveMin()
1148  {
1149  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1150  }
1151 
1152  static bool IsPositive(Self val) { return val.real() > 0; }
1153  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1154  static bool IsNegative(Self val) { return val.real() < 0; }
1155  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1156  static Self ZeroValue() { return Zero; }
1157  static Self OneValue() { return One; }
1158  static unsigned int GetLength(const Self &) { return 2; }
1159  static unsigned int GetLength() { return 2; }
1160  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1161  static Self ZeroValue(const Self &) { return ZeroValue(); }
1162  static Self OneValue(const Self &) { return OneValue(); }
1163  template<typename TArray>
1164  static void AssignToArray( const Self & v, TArray & mv )
1165  {
1166  mv[0] = v.real();
1167  mv[1] = v.imag();
1168  }
1169  static void SetLength(Self & m, const unsigned int s)
1170  {
1171  if ( s != 2 )
1172  {
1173  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1174  }
1175  m = NumericTraits< ValueType >::Zero;
1176  }
1177 };
1178 
1184 template< >
1185 class NumericTraits< std::complex< unsigned int > >
1186 {
1187 public:
1188  typedef std::complex< unsigned int > Self;
1189  // for backward compatibility
1190  typedef Self TheType;
1191  typedef unsigned int ValueType;
1192  typedef Self PrintType;
1193  typedef double AbsType;
1194  typedef Self AccumulateType;
1195  typedef std::complex< double > RealType;
1196  typedef double ScalarRealType;
1197  typedef std::complex< float > FloatType;
1198  typedef FixedArray<unsigned int, 2> MeasurementVectorType;
1199 
1200  static const Self ITKCommon_EXPORT Zero;
1201  static const Self ITKCommon_EXPORT One;
1202 
1203  static Self min() { return std::numeric_limits< Self >::min(); }
1204  static Self max() { return std::numeric_limits< Self >::max(); }
1205  static Self min(Self) { return min(); }
1206  static Self max(Self) { return max(); }
1207  static Self NonpositiveMin()
1208  {
1209  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1210  }
1211 
1212  static bool IsPositive(Self val) { return val.real() > 0; }
1213  static bool IsNonpositive(Self val) { return val.real() == 0; }
1214  static bool IsNegative(Self) { return false; }
1215  static bool IsNonnegative(Self) { return true; }
1216  static Self ZeroValue() { return Zero; }
1217  static Self OneValue() { return One; }
1218  static unsigned int GetLength(const Self &) { return 2; }
1219  static unsigned int GetLength() { return 2; }
1220  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1221  static Self ZeroValue(const Self &) { return ZeroValue(); }
1222  static Self OneValue(const Self &) { return OneValue(); }
1223  template<typename TArray>
1224  static void AssignToArray( const Self & v, TArray & mv )
1225  {
1226  mv[0] = v.real();
1227  mv[1] = v.imag();
1228  }
1229  static void SetLength(Self & m, const unsigned int s)
1230  {
1231  if ( s != 2 )
1232  {
1233  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1234  }
1235  m = NumericTraits< ValueType >::Zero;
1236  }
1237 };
1238 
1244 template< >
1245 class NumericTraits< std::complex< long > >
1246 {
1247 public:
1248  typedef std::complex< long > Self;
1249  // for backward compatibility
1250  typedef Self TheType;
1251  typedef long ValueType;
1252  typedef Self PrintType;
1253  typedef double AbsType;
1254  typedef Self AccumulateType;
1255  typedef std::complex< double > RealType;
1256  typedef double ScalarRealType;
1257  typedef std::complex< float > FloatType;
1258  typedef FixedArray<long, 2> MeasurementVectorType;
1259 
1260  static const Self ITKCommon_EXPORT Zero;
1261  static const Self ITKCommon_EXPORT One;
1262 
1263  static Self min() { return std::numeric_limits< Self >::min(); }
1264  static Self max() { return std::numeric_limits< Self >::max(); }
1265  static Self min(Self) { return min(); }
1266  static Self max(Self) { return max(); }
1267  static Self NonpositiveMin()
1268  {
1269  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1270  }
1271 
1272  static bool IsPositive(Self val) { return val.real() > 0; }
1273  static bool IsNonpositive(Self val) { return val.real() <= 0; }
1274  static bool IsNegative(Self val) { return val.real() < 0; }
1275  static bool IsNonnegative(Self val) { return val.real() >= 0; }
1276  static Self ZeroValue() { return Zero; }
1277  static Self OneValue() { return One; }
1278  static unsigned int GetLength(const Self &) { return 2; }
1279  static unsigned int GetLength() { return 2; }
1280  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1281  static Self ZeroValue(const Self &) { return ZeroValue(); }
1282  static Self OneValue(const Self &) { return OneValue(); }
1283  template<typename TArray>
1284  static void AssignToArray( const Self & v, TArray & mv )
1285  {
1286  mv[0] = v.real();
1287  mv[1] = v.imag();
1288  }
1289  static void SetLength(Self & m, const unsigned int s)
1290  {
1291  if ( s != 2 )
1292  {
1293  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1294  }
1295  m = NumericTraits< ValueType >::Zero;
1296  }
1297 };
1298 
1304 template< >
1305 class NumericTraits< std::complex< unsigned long > >
1306 {
1307 public:
1308  typedef std::complex< unsigned long > Self;
1309  // for backward compatibility
1310  typedef Self TheType;
1311  typedef unsigned long ValueType;
1312  typedef Self PrintType;
1313  typedef double AbsType;
1314  typedef Self AccumulateType;
1315  typedef std::complex< double > RealType;
1316  typedef double ScalarRealType;
1317  typedef std::complex< float > FloatType;
1318  typedef FixedArray<unsigned long, 2> MeasurementVectorType;
1319 
1320  static const Self ITKCommon_EXPORT Zero;
1321  static const Self ITKCommon_EXPORT One;
1322 
1323  static Self min() { return std::numeric_limits< Self >::min(); }
1324  static Self max() { return std::numeric_limits< Self >::max(); }
1325  static Self min(Self) { return min(); }
1326  static Self max(Self) { return max(); }
1327  static Self NonpositiveMin()
1328  {
1329  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
1330  }
1331 
1332  static bool IsPositive(Self val) { return val.real() > 0; }
1333  static bool IsNonpositive(Self val) { return val.real() == 0; }
1334  static bool IsNegative(Self) { return false; }
1335  static bool IsNonnegative(Self) { return true; }
1336  static Self ZeroValue() { return Zero; }
1337  static Self OneValue() { return One; }
1338  static unsigned int GetLength(const Self &) { return 2; }
1339  static unsigned int GetLength() { return 2; }
1340  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1341  static Self ZeroValue(const Self &) { return ZeroValue(); }
1342  static Self OneValue(const Self &) { return OneValue(); }
1343  template<typename TArray>
1344  static void AssignToArray( const Self & v, TArray & mv )
1345  {
1346  mv[0] = v.real();
1347  mv[1] = v.imag();
1348  }
1349  static void SetLength(Self & m, const unsigned int s)
1350  {
1351  if ( s != 2 )
1352  {
1353  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1354  }
1355  m = NumericTraits< ValueType >::Zero;
1356  }
1357 };
1358 
1364 template< >
1365 class NumericTraits< std::complex< float > >
1366 {
1367 public:
1368  typedef std::complex< float > Self;
1369  // for backward compatibility
1370  typedef Self TheType;
1371  typedef float ValueType;
1372  typedef Self PrintType;
1373  typedef double AbsType;
1374  typedef Self AccumulateType;
1375  typedef std::complex< double > RealType;
1376  typedef double ScalarRealType;
1377  typedef std::complex< float > FloatType;
1378  typedef FixedArray<float, 2> MeasurementVectorType;
1379 
1380  static const Self ITKCommon_EXPORT Zero;
1381  static const Self ITKCommon_EXPORT One;
1382 
1383  static Self min() { return std::numeric_limits< Self >::min(); }
1384  static Self max() { return std::numeric_limits< Self >::max(); }
1385  static Self min(Self) { return min(); }
1386  static Self max(Self) { return max(); }
1387  static Self NonpositiveMin()
1388  {
1389  return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
1390  }
1391 
1392  static bool IsPositive(Self val) { return val.real() > 0.0; }
1393  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1394  static bool IsNegative(Self val) { return val.real() < 0.0; }
1395  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1396  static Self ZeroValue() { return Zero; }
1397  static Self OneValue() { return One; }
1398  static unsigned int GetLength(const Self &) { return 2; }
1399  static unsigned int GetLength() { return 2; }
1400  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1401  static Self ZeroValue(const Self &) { return ZeroValue(); }
1402  static Self OneValue(const Self &) { return OneValue(); }
1403  template<typename TArray>
1404  static void AssignToArray( const Self & v, TArray & mv )
1405  {
1406  mv[0] = v.real();
1407  mv[1] = v.imag();
1408  }
1409  static void SetLength(Self & m, const unsigned int s)
1410  {
1411  if ( s != 2 )
1412  {
1413  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1414  }
1415  m = NumericTraits< ValueType >::Zero;
1416  }
1417 };
1418 
1424 template< >
1425 class NumericTraits< std::complex< double > >
1426 {
1427 public:
1428  typedef std::complex< double > Self;
1429  // for backward compatibility
1430  typedef Self TheType;
1431  typedef double ValueType;
1432  typedef Self PrintType;
1433  typedef double AbsType;
1434  typedef Self AccumulateType;
1435  typedef std::complex< double > RealType;
1436  typedef double ScalarRealType;
1437  typedef std::complex< float > FloatType;
1438  typedef FixedArray<double, 2> MeasurementVectorType;
1439 
1440  static const Self ITKCommon_EXPORT Zero;
1441  static const Self ITKCommon_EXPORT One;
1442 
1443  static Self min() { return std::numeric_limits< ValueType >::min(); }
1444  static Self max() { return std::numeric_limits< ValueType >::max(); }
1445  static Self min(Self) { return min(); }
1446  static Self max(Self) { return max(); }
1447  static Self NonpositiveMin()
1448  {
1449  return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
1450  }
1451 
1452  static bool IsPositive(Self val) { return val.real() > 0.0; }
1453  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1454  static bool IsNegative(Self val) { return val.real() < 0.0; }
1455  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1456  static Self ZeroValue() { return Zero; }
1457  static Self OneValue() { return One; }
1458  static unsigned int GetLength(const Self &) { return 2; }
1459  static unsigned int GetLength() { return 2; }
1460  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1461  static Self ZeroValue(const Self &) { return ZeroValue(); }
1462  static Self OneValue(const Self &) { return OneValue(); }
1463  template<typename TArray>
1464  static void AssignToArray( const Self & v, TArray & mv )
1465  {
1466  mv[0] = v.real();
1467  mv[1] = v.imag();
1468  }
1469  static void SetLength(Self & m, const unsigned int s)
1470  {
1471  if ( s != 2 )
1472  {
1473  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1474  }
1475  m = NumericTraits< ValueType >::Zero;
1476  }
1477 };
1478 
1484 template< >
1485 class NumericTraits< std::complex< long double > >
1486 {
1487 public:
1488  typedef std::complex< long double > Self;
1489  // for backward compatibility
1490  typedef Self TheType;
1491  typedef long double ValueType;
1492  typedef Self PrintType;
1493  typedef long double AbsType;
1494  typedef Self AccumulateType;
1495  typedef std::complex< long double > RealType;
1496  typedef long double ScalarRealType;
1497  typedef std::complex< float > FloatType;
1498  typedef FixedArray<long double, 2> MeasurementVectorType;
1499 
1500  static const Self ITKCommon_EXPORT Zero;
1501  static const Self ITKCommon_EXPORT One;
1502 
1503  static Self min() { return std::numeric_limits< ValueType >::min(); }
1504  static Self max() { return std::numeric_limits< ValueType >::max(); }
1505  static Self min(Self) { return min(); }
1506  static Self max(Self) { return max(); }
1507  static Self NonpositiveMin()
1508  {
1509  return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
1510  }
1511 
1512  static bool IsPositive(Self val) { return val.real() > 0.0; }
1513  static bool IsNonpositive(Self val) { return val.real() <= 0.0; }
1514  static bool IsNegative(Self val) { return val.real() < 0.0; }
1515  static bool IsNonnegative(Self val) { return val.real() >= 0.0; }
1516  static Self ZeroValue() { return Zero; }
1517  static Self OneValue() { return One; }
1518  static unsigned int GetLength(const Self &) { return 2; }
1519  static unsigned int GetLength() { return 2; }
1520  static Self NonpositiveMin(const Self &) { return NonpositiveMin(); }
1521  static Self ZeroValue(const Self &) { return ZeroValue(); }
1522  static Self OneValue(const Self &) { return OneValue(); }
1523  template<typename TArray>
1524  static void AssignToArray( const Self & v, TArray & mv )
1525  {
1526  mv[0] = v.real();
1527  mv[1] = v.imag();
1528  }
1529  static void SetLength(Self & m, const unsigned int s)
1530  {
1531  if ( s != 2 )
1532  {
1533  itkGenericExceptionMacro(<< "Cannot set the size of a complex to " << s);
1534  }
1535  m = NumericTraits< ValueType >::Zero;
1536  }
1537 };
1538 
1544 template< >
1545 class NumericTraits< long long > :
1546  public std::numeric_limits< long long >
1547 {
1548 public:
1549  typedef long long ValueType;
1550  typedef long long PrintType;
1551  typedef long long AbsType;
1552  typedef long long AccumulateType;
1553  typedef double RealType;
1554  typedef RealType ScalarRealType;
1555  typedef float FloatType;
1556  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1557 
1558  static const ValueType ITKCommon_EXPORT Zero;
1559  static const ValueType ITKCommon_EXPORT One;
1560 
1562  static ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
1563  static bool IsPositive(ValueType val) { return val > Zero; }
1564  static bool IsNonpositive(ValueType val) { return val <= Zero; }
1565  static bool IsNegative(ValueType val) { return val < Zero; }
1566  static bool IsNonnegative(ValueType val) { return val >= Zero; }
1567  static ValueType ZeroValue() { return Zero; }
1568  static ValueType OneValue() { return One; }
1569  static unsigned int GetLength(const ValueType &) { return 1; }
1570  static unsigned int GetLength() { return 1; }
1571  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1572  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1573  static ValueType OneValue(const ValueType &) { return OneValue(); }
1574 
1575  template<typename TArray>
1576  static void AssignToArray( const ValueType & v, TArray & mv )
1577  {
1578  mv[0] = v;
1579  }
1580  static void SetLength(ValueType & m, const unsigned int s)
1581  {
1582  if ( s != 1 )
1583  {
1584  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1585  }
1586  m = NumericTraits< ValueType >::Zero;
1587  }
1588 };
1589 
1595 template< >
1596 class NumericTraits< unsigned long long > :
1597  public std::numeric_limits< unsigned long long >
1598 {
1599 public:
1600  typedef unsigned long long ValueType;
1601  typedef unsigned long long PrintType;
1602  typedef unsigned long long AbsType;
1603  typedef unsigned long long AccumulateType;
1604  typedef double RealType;
1605  typedef RealType ScalarRealType;
1606  typedef float FloatType;
1607  typedef FixedArray<ValueType, 1> MeasurementVectorType;
1608 
1609  static const ValueType ITKCommon_EXPORT Zero;
1610  static const ValueType ITKCommon_EXPORT One;
1611 
1613  static ValueType NonpositiveMin() { return std::numeric_limits< ValueType >::min(); }
1614  static bool IsPositive(ValueType val) { return val != Zero; }
1615  static bool IsNonpositive(ValueType val) { return val == Zero; }
1616  static bool IsNegative(ValueType) { return false; }
1617  static bool IsNonnegative(ValueType) { return true; }
1618  static ValueType ZeroValue() { return Zero; }
1619  static ValueType OneValue() { return One; }
1620  static unsigned int GetLength(const ValueType &) { return 1; }
1621  static unsigned int GetLength() { return 1; }
1622  static ValueType NonpositiveMin(const ValueType &) { return NonpositiveMin(); }
1623  static ValueType ZeroValue(const ValueType &) { return ZeroValue(); }
1624  static ValueType OneValue(const ValueType &) { return OneValue(); }
1625 
1626  template<typename TArray>
1627  static void AssignToArray( const ValueType & v, TArray & mv )
1628  {
1629  mv[0] = v;
1630  }
1631  static void SetLength(ValueType & m, const unsigned int s)
1632  {
1633  if ( s != 1 )
1634  {
1635  itkGenericExceptionMacro(<< "Cannot set the size of a scalar to " << s);
1636  }
1637  m = NumericTraits< ValueType >::Zero;
1638  }
1639 };
1640 
1643 } // end namespace itk
1644 
1645 #include "itkFixedArray.h"
1646 
1647 #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 &)