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);
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(); }
292 #if VCL_CHAR_IS_SIGNED
296 static bool IsNegative(
char) {
return false; }
302 static unsigned int GetLength() {
return 1; }
307 template<
typename TArray>
316 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
328 class NumericTraits< signed char > :
public std::numeric_limits< signed char >
340 static const signed char ITKCommon_EXPORT
Zero;
341 static const signed char ITKCommon_EXPORT
One;
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(); }
355 static unsigned int GetLength() {
return 1; }
360 template<
typename TArray>
369 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
381 class NumericTraits< unsigned char > :
public std::numeric_limits< unsigned char >
393 static const unsigned char ITKCommon_EXPORT
Zero;
394 static const unsigned char ITKCommon_EXPORT
One;
398 static unsigned char NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
401 static bool IsNegative(
unsigned char val) {
return val ?
false :
false; }
402 static bool IsNonnegative(
unsigned char val) {
return val ?
true :
true; }
406 static unsigned int GetLength() {
return 1; }
411 template<
typename TArray>
420 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
431 class NumericTraits< short > :
public std::numeric_limits< short >
436 typedef unsigned short AbsType;
443 static const short ITKCommon_EXPORT
Zero;
444 static const short ITKCommon_EXPORT
One;
447 static short NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
455 static unsigned int GetLength() {
return 1; }
460 template<
typename TArray>
469 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
481 class NumericTraits< unsigned short > :
public std::numeric_limits< unsigned short >
486 typedef unsigned short AbsType;
493 static const unsigned short ITKCommon_EXPORT
Zero;
494 static const unsigned short ITKCommon_EXPORT
One;
497 static unsigned short NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
498 static bool IsPositive(
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; }
505 static unsigned int GetLength() {
return 1; }
510 template<
typename TArray>
519 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
530 class NumericTraits< int > :
public std::numeric_limits< int >
542 static const int ITKCommon_EXPORT
Zero;
543 static const int ITKCommon_EXPORT
One;
546 static int NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
554 static unsigned int GetLength() {
return 1; }
559 template<
typename TArray>
568 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
580 class NumericTraits< unsigned int > :
public std::numeric_limits< unsigned int >
592 static const unsigned int ITKCommon_EXPORT
Zero;
593 static const unsigned int ITKCommon_EXPORT
One;
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(); }
602 static bool IsNegative(
unsigned int val) {
return val ?
false :
false; }
603 static bool IsNonnegative(
unsigned int val) {
return val ?
true :
true; }
607 static unsigned int GetLength() {
return 1; }
612 template<
typename TArray>
621 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
633 class NumericTraits< long > :
public std::numeric_limits< long >
645 static const long ITKCommon_EXPORT
Zero;
646 static const long ITKCommon_EXPORT
One;
649 static long NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
657 static unsigned int GetLength() {
return 1; }
662 template<
typename TArray>
671 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
683 class NumericTraits< unsigned long > :
public std::numeric_limits< unsigned long >
695 static const unsigned long ITKCommon_EXPORT
Zero;
696 static const unsigned long ITKCommon_EXPORT
One;
699 static unsigned long NonpositiveMin() {
return std::numeric_limits< ValueType >::min(); }
702 static bool IsNegative(
unsigned long) {
return false; }
707 static unsigned int GetLength() {
return 1; }
712 template<
typename TArray>
721 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
733 class NumericTraits< float > :
public std::numeric_limits< float >
745 static const float ITKCommon_EXPORT
Zero;
746 static const float ITKCommon_EXPORT
One;
749 static float NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
757 static unsigned int GetLength() {
return 1; }
762 template<
typename TArray>
771 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
783 class NumericTraits< double > :
public std::numeric_limits< double >
795 static const double ITKCommon_EXPORT
Zero;
796 static const double ITKCommon_EXPORT
One;
799 static double NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
807 static unsigned int GetLength() {
return 1; }
812 template<
typename TArray>
821 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
833 class NumericTraits< long double > :
public std::numeric_limits< long double >
837 #if defined( __SUNPRO_CC ) && defined( _ILP32 )
853 static const long double ITKCommon_EXPORT
Zero;
854 static const long double ITKCommon_EXPORT
One;
857 static long double NonpositiveMin() {
return -std::numeric_limits< ValueType >::max(); }
865 static unsigned int GetLength() {
return 1; }
870 template<
typename TArray>
879 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
891 class NumericTraits< std::complex< char > >
894 typedef std::complex< char > Self;
896 typedef Self TheType;
901 typedef std::complex< double >
RealType;
906 static const Self ITKCommon_EXPORT
Zero;
907 static const Self ITKCommon_EXPORT
One;
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(); }
915 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
918 static bool IsPositive(Self val) {
return val.real() > 0; }
919 static bool IsNonpositive(Self val) {
return val.real() <= 0; }
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; }
925 static bool IsNegative(Self) {
return false; }
930 static unsigned int GetLength(
const Self &) {
return 2; }
931 static unsigned int GetLength() {
return 2; }
935 template<
typename TArray>
941 static void SetLength(Self & m,
const unsigned int s)
945 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
957 class NumericTraits< std::complex< unsigned char > >
960 typedef std::complex< unsigned char > Self;
962 typedef Self TheType;
964 typedef std::complex< unsigned int >
PrintType;
967 typedef std::complex< double >
RealType;
972 static const Self ITKCommon_EXPORT
Zero;
973 static const Self ITKCommon_EXPORT
One;
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(); }
981 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
990 static unsigned int GetLength(
const Self &) {
return 2; }
991 static unsigned int GetLength() {
return 2; }
995 template<
typename TArray>
1001 static void SetLength(Self & m,
const unsigned int s)
1005 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1017 class NumericTraits< std::complex< short > >
1020 typedef std::complex< short > Self;
1022 typedef Self TheType;
1027 typedef std::complex< double >
RealType;
1029 typedef std::complex< float >
FloatType;
1032 static const Self ITKCommon_EXPORT
Zero;
1033 static const Self ITKCommon_EXPORT
One;
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(); }
1041 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1050 static unsigned int GetLength(
const Self &) {
return 2; }
1051 static unsigned int GetLength() {
return 2; }
1055 template<
typename TArray>
1061 static void SetLength(Self & m,
const unsigned int s)
1065 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1077 class NumericTraits< std::complex< unsigned short > >
1080 typedef std::complex< unsigned short > Self;
1082 typedef Self TheType;
1087 typedef std::complex< double >
RealType;
1089 typedef std::complex< float >
FloatType;
1092 static const Self ITKCommon_EXPORT
Zero;
1093 static const Self ITKCommon_EXPORT
One;
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(); }
1101 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1110 static unsigned int GetLength(
const Self &) {
return 2; }
1111 static unsigned int GetLength() {
return 2; }
1115 template<
typename TArray>
1121 static void SetLength(Self & m,
const unsigned int s)
1125 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1137 class NumericTraits< std::complex< int > >
1140 typedef std::complex< int > Self;
1142 typedef Self TheType;
1147 typedef std::complex< double >
RealType;
1149 typedef std::complex< float >
FloatType;
1152 static const Self ITKCommon_EXPORT
Zero;
1153 static const Self ITKCommon_EXPORT
One;
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(); }
1161 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1170 static unsigned int GetLength(
const Self &) {
return 2; }
1171 static unsigned int GetLength() {
return 2; }
1175 template<
typename TArray>
1181 static void SetLength(Self & m,
const unsigned int s)
1185 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1197 class NumericTraits< std::complex< unsigned int > >
1200 typedef std::complex< unsigned int > Self;
1202 typedef Self TheType;
1207 typedef std::complex< double >
RealType;
1209 typedef std::complex< float >
FloatType;
1212 static const Self ITKCommon_EXPORT
Zero;
1213 static const Self ITKCommon_EXPORT
One;
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(); }
1221 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1230 static unsigned int GetLength(
const Self &) {
return 2; }
1231 static unsigned int GetLength() {
return 2; }
1235 template<
typename TArray>
1241 static void SetLength(Self & m,
const unsigned int s)
1245 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1257 class NumericTraits< std::complex< long > >
1260 typedef std::complex< long > Self;
1262 typedef Self TheType;
1267 typedef std::complex< double >
RealType;
1269 typedef std::complex< float >
FloatType;
1272 static const Self ITKCommon_EXPORT
Zero;
1273 static const Self ITKCommon_EXPORT
One;
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(); }
1281 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1290 static unsigned int GetLength(
const Self &) {
return 2; }
1291 static unsigned int GetLength() {
return 2; }
1295 template<
typename TArray>
1301 static void SetLength(Self & m,
const unsigned int s)
1305 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1317 class NumericTraits< std::complex< unsigned long > >
1320 typedef std::complex< unsigned long > Self;
1322 typedef Self TheType;
1327 typedef std::complex< double >
RealType;
1329 typedef std::complex< float >
FloatType;
1332 static const Self ITKCommon_EXPORT
Zero;
1333 static const Self ITKCommon_EXPORT
One;
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(); }
1341 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0);
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; }
1350 static unsigned int GetLength(
const Self &) {
return 2; }
1351 static unsigned int GetLength() {
return 2; }
1355 template<
typename TArray>
1361 static void SetLength(Self & m,
const unsigned int s)
1365 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1377 class NumericTraits< std::complex< float > >
1380 typedef std::complex< float > Self;
1382 typedef Self TheType;
1387 typedef std::complex< double >
RealType;
1389 typedef std::complex< float >
FloatType;
1392 static const Self ITKCommon_EXPORT
Zero;
1393 static const Self ITKCommon_EXPORT
One;
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(); }
1401 return Self(NumericTraits< float >::NonpositiveMin(), 0.0f);
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; }
1410 static unsigned int GetLength(
const Self &) {
return 2; }
1411 static unsigned int GetLength() {
return 2; }
1415 template<
typename TArray>
1421 static void SetLength(Self & m,
const unsigned int s)
1425 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1437 class NumericTraits< std::complex< double > >
1440 typedef std::complex< double > Self;
1442 typedef Self TheType;
1447 typedef std::complex< double >
RealType;
1449 typedef std::complex< float >
FloatType;
1452 static const Self ITKCommon_EXPORT
Zero;
1453 static const Self ITKCommon_EXPORT
One;
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(); }
1461 return Self(NumericTraits< double >::NonpositiveMin(), 0.0);
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; }
1470 static unsigned int GetLength(
const Self &) {
return 2; }
1471 static unsigned int GetLength() {
return 2; }
1475 template<
typename TArray>
1481 static void SetLength(Self & m,
const unsigned int s)
1485 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1497 class NumericTraits< std::complex< long double > >
1500 typedef std::complex< long double > Self;
1502 typedef Self TheType;
1507 typedef std::complex< long double >
RealType;
1509 typedef std::complex< float >
FloatType;
1512 static const Self ITKCommon_EXPORT
Zero;
1513 static const Self ITKCommon_EXPORT
One;
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(); }
1521 return Self(NumericTraits< ValueType >::NonpositiveMin(), 0.0);
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; }
1530 static unsigned int GetLength(
const Self &) {
return 2; }
1531 static unsigned int GetLength() {
return 2; }
1535 template<
typename TArray>
1541 static void SetLength(Self & m,
const unsigned int s)
1545 itkGenericExceptionMacro(<<
"Cannot set the size of a complex to " << s);
1557 class NumericTraits< long long > :
1558 public std::numeric_limits< long long >
1582 static unsigned int GetLength() {
return 1; }
1587 template<
typename TArray>
1596 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
1608 class NumericTraits< unsigned long long > :
1609 public std::numeric_limits< unsigned long long >
1614 typedef unsigned long long AbsType;
1633 static unsigned int GetLength() {
return 1; }
1638 template<
typename TArray>
1647 itkGenericExceptionMacro(<<
"Cannot set the size of a scalar to " << s);
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)
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 &)