18#ifndef itkNumericTraits_h
19#define itkNumericTraits_h
26#define itkNUMERIC_TRAITS_MIN_MAX_MACRO() \
27 static constexpr ValueType min(ValueType) { return std::numeric_limits<ValueType>::min(); } \
28 static constexpr ValueType max(ValueType) { return std::numeric_limits<ValueType>::max(); } \
29 static constexpr ValueType min() { return std::numeric_limits<ValueType>::min(); } \
30 static constexpr ValueType max() { return std::numeric_limits<ValueType>::max(); } \
31 ITK_MACROEND_NOOP_STATEMENT
41template <
typename TValue,
unsigned int VLength>
92 static const T ITKCommon_EXPORT
Zero;
95 static const T ITKCommon_EXPORT
One;
101 return TraitsType::lowest();
171 return TraitsType::max();
176 return TraitsType::min();
191 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
243 template <
typename TArray>
261class NumericTraits<bool> :
public std::numeric_limits<bool>
273 static constexpr bool ITKCommon_EXPORT
Zero =
false;
274 static constexpr bool ITKCommon_EXPORT
One =
true;
276 static constexpr bool
281 static constexpr bool
286 static constexpr bool
291 static constexpr bool
296 static constexpr bool
301 static constexpr bool
306 static constexpr bool
311 static constexpr bool
314 return val ? false :
false;
316 static constexpr bool
319 return val ? true :
true;
321 static constexpr bool IsSigned =
false;
324 static constexpr bool
329 static constexpr bool
334 static constexpr unsigned int
339 static constexpr unsigned int
360 template <
typename TArray>
371 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
383class NumericTraits<char> :
public std::numeric_limits<char>
395 static constexpr char ITKCommon_EXPORT
Zero = 0;
396 static constexpr char ITKCommon_EXPORT
One = 1;
400 static constexpr char
405 static constexpr bool
410 static constexpr bool
416 static constexpr bool
421 static constexpr bool
426 static constexpr bool IsSigned = std::numeric_limits<char>::is_signed;
428 static constexpr bool IsInteger = std::numeric_limits<char>::is_integer;
430 static constexpr char
435 static constexpr char
440 static constexpr unsigned int
445 static constexpr unsigned int
466 template <
typename TArray>
477 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
489class NumericTraits<signed char> :
public std::numeric_limits<signed char>
501 static constexpr signed char ITKCommon_EXPORT
Zero = 0;
502 static constexpr signed char ITKCommon_EXPORT
One = 1;
504 static constexpr signed char
509 static constexpr signed char
514 static constexpr signed char
519 static constexpr signed char
524 static constexpr signed char
529 static constexpr bool
534 static constexpr bool
539 static constexpr bool
544 static constexpr bool
549 static constexpr bool IsSigned =
true;
552 static constexpr signed char
557 static constexpr signed char
562 static constexpr unsigned int
567 static constexpr unsigned int
588 template <
typename TArray>
599 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
611class NumericTraits<unsigned char> :
public std::numeric_limits<unsigned char>
623 static constexpr unsigned char ITKCommon_EXPORT
Zero = 0;
624 static constexpr unsigned char ITKCommon_EXPORT
One = 1;
628 static constexpr unsigned char
631 return std::numeric_limits<ValueType>::lowest();
633 static constexpr bool
638 static constexpr bool
643 static constexpr bool
646 return val ? false :
false;
648 static constexpr bool
651 return val ? true :
true;
653 static constexpr bool IsSigned =
false;
656 static constexpr unsigned char
661 static constexpr unsigned char
666 static constexpr unsigned int
671 static constexpr unsigned int
692 template <
typename TArray>
703 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
714class NumericTraits<short> :
public std::numeric_limits<short>
719 using AbsType =
unsigned short;
726 static constexpr short ITKCommon_EXPORT
Zero = 0;
727 static constexpr short ITKCommon_EXPORT
One = 1;
730 static constexpr short
733 return std::numeric_limits<ValueType>::lowest();
735 static constexpr bool
740 static constexpr bool
745 static constexpr bool
750 static constexpr bool
755 static constexpr bool IsSigned =
true;
758 static constexpr short
763 static constexpr short
768 static constexpr unsigned int
773 static constexpr unsigned int
794 template <
typename TArray>
805 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
817class NumericTraits<unsigned short> :
public std::numeric_limits<unsigned short>
822 using AbsType =
unsigned short;
829 static constexpr unsigned short ITKCommon_EXPORT
Zero = 0;
830 static constexpr unsigned short ITKCommon_EXPORT
One = 1;
833 static constexpr unsigned short
836 return std::numeric_limits<ValueType>::lowest();
838 static constexpr bool
843 static constexpr bool
848 static constexpr bool
851 return val ? false :
false;
853 static constexpr bool
856 return val ? true :
true;
858 static constexpr bool IsSigned =
false;
861 static constexpr unsigned short
866 static constexpr unsigned short
871 static constexpr unsigned int
876 static constexpr unsigned int
897 template <
typename TArray>
908 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
919class NumericTraits<int> :
public std::numeric_limits<int>
931 static constexpr int ITKCommon_EXPORT
Zero = 0;
932 static constexpr int ITKCommon_EXPORT
One = 1;
938 return std::numeric_limits<ValueType>::lowest();
940 static constexpr bool
945 static constexpr bool
950 static constexpr bool
955 static constexpr bool
960 static constexpr bool IsSigned =
true;
973 static constexpr unsigned int
978 static constexpr unsigned int
999 template <
typename TArray>
1010 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1022class NumericTraits<unsigned int> :
public std::numeric_limits<unsigned int>
1034 static constexpr unsigned int ITKCommon_EXPORT
Zero = 0;
1035 static constexpr unsigned int ITKCommon_EXPORT
One = 1;
1037 static constexpr unsigned int
1042 static constexpr unsigned int
1045 return static_cast<unsigned int>(-1);
1047 static constexpr unsigned int
1050 return std::numeric_limits<ValueType>::min();
1052 static constexpr unsigned int
1055 return std::numeric_limits<ValueType>::max();
1057 static constexpr unsigned int
1062 static constexpr bool
1067 static constexpr bool
1072 static constexpr bool
1075 return val ? false :
false;
1077 static constexpr bool
1080 return val ? true :
true;
1082 static constexpr bool IsSigned =
false;
1084 static constexpr bool IsComplex =
false;
1085 static constexpr unsigned int
1090 static constexpr unsigned int
1095 static constexpr unsigned int
1100 static constexpr unsigned int
1121 template <
typename TArray>
1132 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1144class NumericTraits<long> :
public std::numeric_limits<long>
1149 using AbsType =
unsigned long;
1156 static constexpr long ITKCommon_EXPORT
Zero = 0L;
1157 static constexpr long ITKCommon_EXPORT
One = 1L;
1160 static constexpr long
1163 return std::numeric_limits<ValueType>::lowest();
1165 static constexpr bool
1170 static constexpr bool
1175 static constexpr bool
1180 static constexpr bool
1185 static constexpr bool IsSigned =
true;
1187 static constexpr bool IsComplex =
false;
1188 static constexpr long
1193 static constexpr long
1198 static constexpr unsigned int
1203 static constexpr unsigned int
1224 template <
typename TArray>
1235 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1247class NumericTraits<unsigned long> :
public std::numeric_limits<unsigned long>
1252 using AbsType =
unsigned long;
1259 static constexpr unsigned long ITKCommon_EXPORT
Zero = 0UL;
1260 static constexpr unsigned long ITKCommon_EXPORT
One = 1UL;
1263 static constexpr unsigned long
1266 return std::numeric_limits<ValueType>::lowest();
1268 static constexpr bool
1273 static constexpr bool
1278 static constexpr bool
1283 static constexpr bool
1288 static constexpr bool IsSigned =
false;
1290 static constexpr bool IsComplex =
false;
1291 static constexpr unsigned long
1296 static constexpr unsigned long
1301 static constexpr unsigned int
1306 static constexpr unsigned int
1327 template <
typename TArray>
1338 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1350class NumericTraits<float> :
public std::numeric_limits<float>
1363 static constexpr float ITKCommon_EXPORT
Zero = 0.0f;
1364 static constexpr float ITKCommon_EXPORT
One = 1.0f;
1367 static constexpr float
1370 return std::numeric_limits<ValueType>::lowest();
1372 static constexpr bool
1377 static constexpr bool
1382 static constexpr bool
1387 static constexpr bool
1392 static constexpr bool IsSigned =
true;
1393 static constexpr bool IsInteger =
false;
1394 static constexpr bool IsComplex =
false;
1395 static constexpr float
1400 static constexpr float
1405 static constexpr unsigned int
1410 static constexpr unsigned int
1431 template <
typename TArray>
1442 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1454class NumericTraits<double> :
public std::numeric_limits<double>
1466 static constexpr double ITKCommon_EXPORT
Zero = 0.0;
1467 static constexpr double ITKCommon_EXPORT
One = 1.0;
1470 static constexpr double
1473 return std::numeric_limits<ValueType>::lowest();
1475 static constexpr bool
1480 static constexpr bool
1485 static constexpr bool
1490 static constexpr bool
1495 static constexpr bool IsSigned =
true;
1496 static constexpr bool IsInteger =
false;
1497 static constexpr bool IsComplex =
false;
1498 static constexpr double
1503 static constexpr double
1508 static constexpr unsigned int
1513 static constexpr unsigned int
1534 template <
typename TArray>
1545 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1557class NumericTraits<long double> :
public std::numeric_limits<long double>
1561#if defined(__SUNPRO_CC) && defined(_ILP32)
1577 static constexpr long double ITKCommon_EXPORT
Zero = 0.0;
1578 static constexpr long double ITKCommon_EXPORT
One = 1.0;
1581 static constexpr long double
1584 return std::numeric_limits<ValueType>::lowest();
1586 static constexpr bool
1591 static constexpr bool
1596 static constexpr bool
1601 static constexpr bool
1606 static constexpr bool IsSigned =
true;
1607 static constexpr bool IsInteger =
false;
1608 static constexpr bool IsComplex =
false;
1609 static constexpr long double
1614 static constexpr long double
1619 static constexpr unsigned int
1624 static constexpr unsigned int
1645 template <
typename TArray>
1656 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1669class NumericTraits<long long> :
public std::numeric_limits<long long>
1688 return std::numeric_limits<ValueType>::lowest();
1690 static constexpr bool
1695 static constexpr bool
1700 static constexpr bool
1705 static constexpr bool
1710 static constexpr bool IsSigned =
true;
1712 static constexpr bool IsComplex =
false;
1723 static constexpr unsigned int
1728 static constexpr unsigned int
1749 template <
typename TArray>
1760 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1772class NumericTraits<unsigned long long> :
public std::numeric_limits<unsigned long long>
1777 using AbsType =
unsigned long long;
1785 static constexpr ValueType ITKCommon_EXPORT
One = 1ULL;
1791 return std::numeric_limits<ValueType>::lowest();
1793 static constexpr bool
1798 static constexpr bool
1805 static constexpr bool IsSigned =
false;
1807 static constexpr bool IsComplex =
false;
1818 static constexpr unsigned int
1823 static constexpr unsigned int
1844 template <
typename TArray>
1855 itkGenericExceptionMacro(
"Cannot set the size of a scalar to " << s);
1867template <
typename TComponent>
1868class NumericTraits<
std::complex<TComponent>>
1871 using Self = std::complex<TComponent>;
1873 using TheType =
Self;
1878 using RealType = std::complex<double>;
1883 static const Self ITKCommon_EXPORT
Zero;
1884 static const Self ITKCommon_EXPORT
One;
1886 static constexpr Self
1889 return std::numeric_limits<ValueType>::min();
1891 static constexpr Self
1894 return std::numeric_limits<ValueType>::max();
1901 return std::numeric_limits<ValueType>::epsilon();
1903 static constexpr Self
1909 static constexpr bool
1912 return val.real() > 0;
1914 static constexpr bool
1917 return val.real() <= 0;
1919 static constexpr bool
1922 return val.real() < 0;
1924 static constexpr bool
1927 return val.real() >= 0;
1930 static constexpr bool IsSigned = std::is_signed_v<ValueType>;
1931 static constexpr bool IsInteger =
false;
1943 static constexpr unsigned int
1948 static constexpr unsigned int
1953 static constexpr Self
1969 template <
typename TArray>
1981 itkGenericExceptionMacro(
"Cannot set the size of a complex to " << s);
1986#if defined(ITK_LEGACY_REMOVE)
1987 static_assert(std::is_floating_point_v<TComponent>,
1988 "As per https://en.cppreference.com/w/cpp/numeric/complex the behavior is unspecified and may fail to "
1989 "compile if TComponent is not float, double, or long double and undefined if T is not NumericType.");
Pixel-wise addition of two images.
Simulate a standard C array with copy semantics.
Define additional traits for native types such as int or float.
static constexpr bool IsInteger
static constexpr bool IsSigned
static bool IsNegative(T val)
static T OneValue(const T &)
static constexpr T NonpositiveMin()
static constexpr T max(const T &)
static T ZeroValue(const T &)
std::numeric_limits< T > TraitsType
static bool IsPositive(T val)
static constexpr T min(const T &)
static void AssignToArray(const T &v, TArray &mv)
static unsigned int GetLength()
static const T ITKCommon_EXPORT Zero
static bool IsNonpositive(T val)
static T NonpositiveMin(const T &)
static const T ITKCommon_EXPORT One
static void SetLength(T &m, const unsigned int s)
static bool IsNonnegative(T val)
FixedArray< ValueType, 1 > MeasurementVectorType
static constexpr bool IsComplex
static unsigned int GetLength(const T &)
#define itkNUMERIC_TRAITS_MIN_MAX_MACRO()
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....