18 #ifndef __itkNumericTraits_h
19 #define __itkNumericTraits_h
26 #define itkNUMERIC_TRAITS_MIN_MAX_MACRO() \
27 static ValueType min() \
29 return std::numeric_limits< ValueType >::min(); \
31 static ValueType max() \
33 return std::numeric_limits< ValueType >::max(); \
35 static ValueType min(ValueType) \
37 return std::numeric_limits< ValueType >::min(); \
39 static ValueType max(ValueType) \
41 return std::numeric_limits< ValueType >::max(); \
45 #include "vcl_limits.h"
52 template<
typename TValue,
unsigned int VLength>
class FixedArray;
69 template<
typename T >
135 static T
max(
const T &) {
return TraitsType::max(); }
136 static T
min(
const T &) {
return TraitsType::min(); }
149 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
196 template<
typename TArray>
214 class NumericTraits< bool > :
public std::numeric_limits< bool >
226 static const bool ITKCommon_EXPORT
Zero;
227 static const bool ITKCommon_EXPORT
One;
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(); }
234 static bool IsPositive(
bool val) {
return val; }
236 static bool IsNegative(
bool val) {
return val ?
false :
false; }
237 static bool IsNonnegative(
bool val) {
return val ?
true :
true; }
241 static unsigned int GetLength() {
return 1; }
246 template<
typename TArray>
255 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
257 m = NumericTraits< ValueType >::Zero;
268 class NumericTraits< char > :
public std::numeric_limits< char >
280 static const char ITKCommon_EXPORT
Zero;
281 static const char ITKCommon_EXPORT
One;
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); }
286 static char min(
char) {
return min(); }
287 static char max(
char) {
return max(); }
296 static unsigned int GetLength() {
return 1; }
301 template<
typename TArray>
310 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
312 m = NumericTraits< ValueType >::Zero;
322 class NumericTraits< signed char > :
public std::numeric_limits< signed char >
334 static const signed char ITKCommon_EXPORT
Zero;
335 static const signed char ITKCommon_EXPORT
One;
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(); }
349 static unsigned int GetLength() {
return 1; }
354 template<
typename TArray>
363 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
365 m = NumericTraits< ValueType >::Zero;
375 class NumericTraits< unsigned char > :
public std::numeric_limits< unsigned char >
387 static const unsigned char ITKCommon_EXPORT
Zero;
388 static const unsigned char ITKCommon_EXPORT
One;
392 static unsigned char NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
395 static bool IsNegative(
unsigned char val) {
return val ?
false :
false; }
396 static bool IsNonnegative(
unsigned char val) {
return val ?
true :
true; }
400 static unsigned int GetLength() {
return 1; }
405 template<
typename TArray>
414 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
416 m = NumericTraits< ValueType >::Zero;
425 class NumericTraits< short > :
public std::numeric_limits< short >
430 typedef unsigned short AbsType;
437 static const short ITKCommon_EXPORT
Zero;
438 static const short ITKCommon_EXPORT
One;
441 static short NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
449 static unsigned int GetLength() {
return 1; }
454 template<
typename TArray>
463 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
465 m = NumericTraits< ValueType >::Zero;
475 class NumericTraits< unsigned short > :
public std::numeric_limits< unsigned short >
480 typedef unsigned short AbsType;
487 static const unsigned short ITKCommon_EXPORT
Zero;
488 static const unsigned short ITKCommon_EXPORT
One;
491 static unsigned short NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
492 static bool IsPositive(
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; }
499 static unsigned int GetLength() {
return 1; }
504 template<
typename TArray>
513 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
515 m = NumericTraits< ValueType >::Zero;
524 class NumericTraits< int > :
public std::numeric_limits< int >
536 static const int ITKCommon_EXPORT
Zero;
537 static const int ITKCommon_EXPORT
One;
540 static int NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
548 static unsigned int GetLength() {
return 1; }
553 template<
typename TArray>
562 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
564 m = NumericTraits< ValueType >::Zero;
574 class NumericTraits< unsigned int > :
public std::numeric_limits< unsigned int >
586 static const unsigned int ITKCommon_EXPORT
Zero;
587 static const unsigned int ITKCommon_EXPORT
One;
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(); }
596 static bool IsNegative(
unsigned int val) {
return val ?
false :
false; }
597 static bool IsNonnegative(
unsigned int val) {
return val ?
true :
true; }
601 static unsigned int GetLength() {
return 1; }
606 template<
typename TArray>
615 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
617 m = NumericTraits< ValueType >::Zero;
627 class NumericTraits< long > :
public std::numeric_limits< long >
639 static const long ITKCommon_EXPORT
Zero;
640 static const long ITKCommon_EXPORT
One;
643 static long NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
651 static unsigned int GetLength() {
return 1; }
656 template<
typename TArray>
665 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
667 m = NumericTraits< ValueType >::Zero;
677 class NumericTraits< unsigned long > :
public std::numeric_limits< unsigned long >
689 static const unsigned long ITKCommon_EXPORT
Zero;
690 static const unsigned long ITKCommon_EXPORT
One;
693 static unsigned long NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
696 static bool IsNegative(
unsigned long) {
return false; }
701 static unsigned int GetLength() {
return 1; }
706 template<
typename TArray>
715 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
717 m = NumericTraits< ValueType >::Zero;
727 class NumericTraits< float > :
public std::numeric_limits< float >
739 static const float ITKCommon_EXPORT
Zero;
740 static const float ITKCommon_EXPORT
One;
743 static float NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
751 static unsigned int GetLength() {
return 1; }
756 template<
typename TArray>
765 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
767 m = NumericTraits< ValueType >::Zero;
777 class NumericTraits< double > :
public std::numeric_limits< double >
789 static const double ITKCommon_EXPORT
Zero;
790 static const double ITKCommon_EXPORT
One;
793 static double NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
801 static unsigned int GetLength() {
return 1; }
806 template<
typename TArray>
815 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
817 m = NumericTraits< ValueType >::Zero;
827 class NumericTraits< long double > :
public std::numeric_limits< long double >
831 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
847 static const long double ITKCommon_EXPORT
Zero;
848 static const long double ITKCommon_EXPORT
One;
851 static long double NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
859 static unsigned int GetLength() {
return 1; }
864 template<
typename TArray>
873 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
875 m = NumericTraits< ValueType >::Zero;
885 class NumericTraits< std::complex< char > >
888 typedef std::complex< char > Self;
890 typedef Self TheType;
895 typedef std::complex< double >
RealType;
900 static const Self ITKCommon_EXPORT
Zero;
901 static const Self ITKCommon_EXPORT
One;
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(); }
909 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
918 static unsigned int GetLength(
const Self &) {
return 2; }
919 static unsigned int GetLength() {
return 2; }
923 template<
typename TArray>
929 static void SetLength(Self & m,
const unsigned int s)
933 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
935 m = NumericTraits< ValueType >::Zero;
945 class NumericTraits< std::complex< unsigned char > >
948 typedef std::complex< unsigned char > Self;
950 typedef Self TheType;
952 typedef std::complex< unsigned int >
PrintType;
955 typedef std::complex< double >
RealType;
960 static const Self ITKCommon_EXPORT
Zero;
961 static const Self ITKCommon_EXPORT
One;
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(); }
969 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
978 static unsigned int GetLength(
const Self &) {
return 2; }
979 static unsigned int GetLength() {
return 2; }
983 template<
typename TArray>
989 static void SetLength(Self & m,
const unsigned int s)
993 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
995 m = NumericTraits< ValueType >::Zero;
1005 class NumericTraits< std::complex< short > >
1008 typedef std::complex< short > Self;
1010 typedef Self TheType;
1015 typedef std::complex< double >
RealType;
1017 typedef std::complex< float >
FloatType;
1020 static const Self ITKCommon_EXPORT
Zero;
1021 static const Self ITKCommon_EXPORT
One;
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(); }
1029 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1038 static unsigned int GetLength(
const Self &) {
return 2; }
1039 static unsigned int GetLength() {
return 2; }
1043 template<
typename TArray>
1049 static void SetLength(Self & m,
const unsigned int s)
1053 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1055 m = NumericTraits< ValueType >::Zero;
1065 class NumericTraits< std::complex< unsigned short > >
1068 typedef std::complex< unsigned short > Self;
1070 typedef Self TheType;
1075 typedef std::complex< double >
RealType;
1077 typedef std::complex< float >
FloatType;
1080 static const Self ITKCommon_EXPORT
Zero;
1081 static const Self ITKCommon_EXPORT
One;
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(); }
1089 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1098 static unsigned int GetLength(
const Self &) {
return 2; }
1099 static unsigned int GetLength() {
return 2; }
1103 template<
typename TArray>
1109 static void SetLength(Self & m,
const unsigned int s)
1113 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1115 m = NumericTraits< ValueType >::Zero;
1125 class NumericTraits< std::complex< int > >
1128 typedef std::complex< int > Self;
1130 typedef Self TheType;
1135 typedef std::complex< double >
RealType;
1137 typedef std::complex< float >
FloatType;
1140 static const Self ITKCommon_EXPORT
Zero;
1141 static const Self ITKCommon_EXPORT
One;
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(); }
1149 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1158 static unsigned int GetLength(
const Self &) {
return 2; }
1159 static unsigned int GetLength() {
return 2; }
1163 template<
typename TArray>
1169 static void SetLength(Self & m,
const unsigned int s)
1173 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1175 m = NumericTraits< ValueType >::Zero;
1185 class NumericTraits< std::complex< unsigned int > >
1188 typedef std::complex< unsigned int > Self;
1190 typedef Self TheType;
1195 typedef std::complex< double >
RealType;
1197 typedef std::complex< float >
FloatType;
1200 static const Self ITKCommon_EXPORT
Zero;
1201 static const Self ITKCommon_EXPORT
One;
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(); }
1209 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1218 static unsigned int GetLength(
const Self &) {
return 2; }
1219 static unsigned int GetLength() {
return 2; }
1223 template<
typename TArray>
1229 static void SetLength(Self & m,
const unsigned int s)
1233 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1235 m = NumericTraits< ValueType >::Zero;
1245 class NumericTraits< std::complex< long > >
1248 typedef std::complex< long > Self;
1250 typedef Self TheType;
1255 typedef std::complex< double >
RealType;
1257 typedef std::complex< float >
FloatType;
1260 static const Self ITKCommon_EXPORT
Zero;
1261 static const Self ITKCommon_EXPORT
One;
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(); }
1269 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1278 static unsigned int GetLength(
const Self &) {
return 2; }
1279 static unsigned int GetLength() {
return 2; }
1283 template<
typename TArray>
1289 static void SetLength(Self & m,
const unsigned int s)
1293 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1295 m = NumericTraits< ValueType >::Zero;
1305 class NumericTraits< std::complex< unsigned long > >
1308 typedef std::complex< unsigned long > Self;
1310 typedef Self TheType;
1315 typedef std::complex< double >
RealType;
1317 typedef std::complex< float >
FloatType;
1320 static const Self ITKCommon_EXPORT
Zero;
1321 static const Self ITKCommon_EXPORT
One;
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(); }
1329 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1338 static unsigned int GetLength(
const Self &) {
return 2; }
1339 static unsigned int GetLength() {
return 2; }
1343 template<
typename TArray>
1349 static void SetLength(Self & m,
const unsigned int s)
1353 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1355 m = NumericTraits< ValueType >::Zero;
1365 class NumericTraits< std::complex< float > >
1368 typedef std::complex< float > Self;
1370 typedef Self TheType;
1375 typedef std::complex< double >
RealType;
1377 typedef std::complex< float >
FloatType;
1380 static const Self ITKCommon_EXPORT
Zero;
1381 static const Self ITKCommon_EXPORT
One;
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(); }
1389 return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
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; }
1398 static unsigned int GetLength(
const Self &) {
return 2; }
1399 static unsigned int GetLength() {
return 2; }
1403 template<
typename TArray>
1409 static void SetLength(Self & m,
const unsigned int s)
1413 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1415 m = NumericTraits< ValueType >::Zero;
1425 class NumericTraits< std::complex< double > >
1428 typedef std::complex< double > Self;
1430 typedef Self TheType;
1435 typedef std::complex< double >
RealType;
1437 typedef std::complex< float >
FloatType;
1440 static const Self ITKCommon_EXPORT
Zero;
1441 static const Self ITKCommon_EXPORT
One;
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(); }
1449 return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
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; }
1458 static unsigned int GetLength(
const Self &) {
return 2; }
1459 static unsigned int GetLength() {
return 2; }
1463 template<
typename TArray>
1469 static void SetLength(Self & m,
const unsigned int s)
1473 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1475 m = NumericTraits< ValueType >::Zero;
1485 class NumericTraits< std::complex< long double > >
1488 typedef std::complex< long double > Self;
1490 typedef Self TheType;
1495 typedef std::complex< long double >
RealType;
1497 typedef std::complex< float >
FloatType;
1500 static const Self ITKCommon_EXPORT
Zero;
1501 static const Self ITKCommon_EXPORT
One;
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(); }
1509 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
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; }
1518 static unsigned int GetLength(
const Self &) {
return 2; }
1519 static unsigned int GetLength() {
return 2; }
1523 template<
typename TArray>
1529 static void SetLength(Self & m,
const unsigned int s)
1533 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1535 m = NumericTraits< ValueType >::Zero;
1545 class NumericTraits< long long > :
1546 public std::numeric_limits< long long >
1570 static unsigned int GetLength() {
return 1; }
1575 template<
typename TArray>
1584 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1586 m = NumericTraits< ValueType >::Zero;
1596 class NumericTraits< unsigned long long > :
1597 public std::numeric_limits< unsigned long long >
1602 typedef unsigned long long AbsType;
1621 static unsigned int GetLength() {
return 1; }
1626 template<
typename TArray>
1635 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1637 m = NumericTraits< ValueType >::Zero;
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)
Simulate a standard C array with copy semnatics.
static bool IsNonnegative(T val)
static T NonpositiveMin(const T &)
std::numeric_limits< T > TraitsType
static unsigned int GetLength()
static void SetLength(T &m, const unsigned int s)
static bool IsNegative(T val)
static T ZeroValue(const T &)
static bool IsNonpositive(T val)
FixedArray< ValueType, 1 > MeasurementVectorType
static T NonpositiveMin()
Define additional traits for native types such as int or float.
static unsigned int GetLength(const T &)