51#include "vtkCommonCoreModule.h"
52#include "vtkMathPrivate.hxx"
58#include "vtkMathConfigure.h"
64#define VTK_DBL_MIN 2.2250738585072014e-308
66#define VTK_DBL_MIN DBL_MIN
70#define VTK_DBL_EPSILON 2.2204460492503131e-16
72#define VTK_DBL_EPSILON DBL_EPSILON
75#ifndef VTK_DBL_EPSILON
77#define VTK_DBL_EPSILON 2.2204460492503131e-16
79#define VTK_DBL_EPSILON DBL_EPSILON
92template <
typename OutT>
106 static constexpr double Pi() {
return 3.141592653589793; }
112 static float RadiansFromDegrees(
float degrees);
113 static double RadiansFromDegrees(
double degrees);
120 static float DegreesFromRadians(
float radians);
121 static double DegreesFromRadians(
double radians);
128 static int Round(
float f) {
return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
129 static int Round(
double f) {
return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
136 template <
typename OutT>
149 static int Floor(
double x);
156 static int Ceil(
double x);
170 static T Min(
const T& a,
const T& b);
177 static T Max(
const T& a,
const T& b);
182 static bool IsPowerOfTwo(vtkTypeUInt64 x);
189 static int NearestPowerOfTwo(
int x);
325 template <
class VectorT1,
class VectorT2>
326 static void Assign(
const VectorT1& a, VectorT2&& b)
336 static void Assign(
const double a[3],
double b[3]) { vtkMath::Assign<>(a, b); }
341 static void Add(
const float a[3],
const float b[3],
float c[3])
343 for (
int i = 0; i < 3; ++i)
352 static void Add(
const double a[3],
const double b[3],
double c[3])
354 for (
int i = 0; i < 3; ++i)
363 static void Subtract(
const float a[3],
const float b[3],
float c[3])
365 for (
int i = 0; i < 3; ++i)
374 static void Subtract(
const double a[3],
const double b[3],
double c[3])
376 for (
int i = 0; i < 3; ++i)
387 template <
class VectorT1,
class VectorT2,
class VectorT3>
388 static void Subtract(
const VectorT1& a,
const VectorT2& b, VectorT3&& c)
401 for (
int i = 0; i < 3; ++i)
413 for (
int i = 0; i < 2; ++i)
425 for (
int i = 0; i < 3; ++i)
437 for (
int i = 0; i < 2; ++i)
446 static float Dot(
const float a[3],
const float b[3])
448 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
454 static double Dot(
const double a[3],
const double b[3])
456 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
474 template <
typename ReturnTypeT = double,
typename TupleRangeT1,
typename TupleRangeT2,
477 TupleRangeT1, TupleRangeT2>::type::value_type>
478 static ReturnTypeT
Dot(
const TupleRangeT1& a,
const TupleRangeT2& b)
480 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
486 static void Outer(
const float a[3],
const float b[3],
float c[3][3])
488 for (
int i = 0; i < 3; ++i)
490 for (
int j = 0; j < 3; ++j)
492 c[i][j] = a[i] * b[j];
500 static void Outer(
const double a[3],
const double b[3],
double c[3][3])
502 for (
int i = 0; i < 3; ++i)
504 for (
int j = 0; j < 3; ++j)
506 c[i][j] = a[i] * b[j];
515 static void Cross(
const float a[3],
const float b[3],
float c[3]);
521 static void Cross(
const double a[3],
const double b[3],
double c[3]);
527 static float Norm(
const float* x,
int n);
528 static double Norm(
const double* x,
int n);
534 static float Norm(
const float v[3]) {
return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); }
539 static double Norm(
const double v[3])
541 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
553 template <
typename ReturnTypeT =
double,
typename TupleRangeT>
556 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
563 static float Normalize(
float v[3]);
569 static double Normalize(
double v[3]);
579 static void Perpendiculars(
const double v1[3],
double v2[3],
double v3[3],
double theta);
580 static void Perpendiculars(
const float v1[3],
float v2[3],
float v3[3],
double theta);
589 static bool ProjectVector(
const float a[3],
const float b[3],
float projection[3]);
590 static bool ProjectVector(
const double a[3],
const double b[3],
double projection[3]);
601 static bool ProjectVector2D(
const double a[2],
const double b[2],
double projection[2]);
619 template <
typename ReturnTypeT = double,
typename TupleRangeT1,
typename TupleRangeT2,
622 TupleRangeT1, TupleRangeT2>::type::value_type>
623 static ReturnTypeT Distance2BetweenPoints(
const TupleRangeT1& p1,
const TupleRangeT2& p2);
629 static float Distance2BetweenPoints(
const float p1[3],
const float p2[3]);
635 static double Distance2BetweenPoints(
const double p1[3],
const double p2[3]);
646 const double v1[3],
const double v2[3],
const double vn[3]);
665 static double GaussianWeight(
const double variance,
const double distanceFromMean);
677 static float Dot2D(
const float x[2],
const float y[2]) {
return x[0] * y[0] + x[1] * y[1]; }
682 static double Dot2D(
const double x[2],
const double y[2]) {
return x[0] * y[0] + x[1] * y[1]; }
687 static void Outer2D(
const float x[2],
const float y[2],
float A[2][2])
689 for (
int i = 0; i < 2; ++i)
691 for (
int j = 0; j < 2; ++j)
693 A[i][j] = x[i] * y[j];
701 static void Outer2D(
const double x[2],
const double y[2],
double A[2][2])
703 for (
int i = 0; i < 2; ++i)
705 for (
int j = 0; j < 2; ++j)
707 A[i][j] = x[i] * y[j];
716 static float Norm2D(
const float x[2]) {
return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
722 static double Norm2D(
const double x[2]) {
return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
728 static float Normalize2D(
float v[2]);
734 static double Normalize2D(
double v[2]);
741 return c1[0] * c2[1] - c2[0] * c1[1];
748 static double Determinant2x2(
double a,
double b,
double c,
double d) {
return a * d - b * c; }
751 return c1[0] * c2[1] - c2[0] * c1[1];
777 static void LinearSolve3x3(
const double A[3][3],
const double x[3],
double y[3]);
784 static void Multiply3x3(
const float A[3][3],
const float v[3],
float u[3]);
785 static void Multiply3x3(
const double A[3][3],
const double v[3],
double u[3]);
792 static void Multiply3x3(
const float A[3][3],
const float B[3][3],
float C[3][3]);
793 static void Multiply3x3(
const double A[3][3],
const double B[3][3],
double C[3][3]);
819 template <
int RowsT,
int MidDimT,
int ColsT,
820 class LayoutT1 = vtkMatrixUtilities::Layout::Identity,
821 class LayoutT2 = vtkMatrixUtilities::Layout::Identity,
class MatrixT1,
class MatrixT2,
823 static void MultiplyMatrix(
const MatrixT1& M1,
const MatrixT2& M2, MatrixT3&& M3)
825 vtkMathPrivate::MultiplyMatrix<RowsT, MidDimT, ColsT, LayoutT1, LayoutT2>::Compute(M1, M2, M3);
848 template <
int RowsT,
int ColsT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
849 class MatrixT,
class VectorT1,
class VectorT2>
852 vtkMathPrivate::MultiplyMatrix<RowsT, ColsT, 1, LayoutT>::Compute(M, X, Y);
860 template <
class ScalarT,
int SizeT,
class VectorT1,
class VectorT2>
861 static ScalarT
Dot(
const VectorT1& x,
const VectorT2& y)
863 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
864 vtkMatrixUtilities::Layout::Identity, vtkMatrixUtilities::Layout::Transpose>::Compute(x, y);
883 template <
int SizeT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
class MatrixT>
887 return vtkMathPrivate::Determinant<SizeT, LayoutT>::Compute(M);
905 template <
int SizeT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
class MatrixT1,
909 vtkMathPrivate::InvertMatrix<SizeT, LayoutT>::Compute(M1, M2);
925 template <
int RowsT,
int ColsT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
926 class MatrixT,
class VectorT1,
class VectorT2>
927 static void LinearSolve(
const MatrixT& M,
const VectorT1& x, VectorT2& y)
929 vtkMathPrivate::LinearSolve<RowsT, ColsT, LayoutT>::Compute(M, x, y);
946 template <
class ScalarT,
int SizeT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
947 class VectorT1,
class MatrixT,
class VectorT2>
948 static ScalarT
Dot(
const VectorT1& x,
const MatrixT& M,
const VectorT2& y)
951 vtkMathPrivate::MultiplyMatrix<SizeT, SizeT, 1, LayoutT>::Compute(M, y, tmp);
952 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
953 vtkMatrixUtilities::Layout::Identity, vtkMatrixUtilities::Layout::Transpose>::Compute(x, tmp);
961 static void MultiplyMatrix(
const double*
const* A,
const double*
const* B,
unsigned int rowA,
962 unsigned int colA,
unsigned int rowB,
unsigned int colB,
double** C);
978 static void Invert3x3(
const float A[3][3],
float AI[3][3]);
979 static void Invert3x3(
const double A[3][3],
double AI[3][3]);
994 static double Determinant3x3(
const float A[3][3]);
995 static double Determinant3x3(
const double A[3][3]);
1001 static float Determinant3x3(
const float c1[3],
const float c2[3],
const float c3[3]);
1006 static double Determinant3x3(
const double c1[3],
const double c2[3],
const double c3[3]);
1014 static double Determinant3x3(
double a1,
double a2,
double a3,
double b1,
double b2,
double b3,
1015 double c1,
double c2,
double c3);
1025 static void QuaternionToMatrix3x3(
const float quat[4],
float A[3][3]);
1026 static void QuaternionToMatrix3x3(
const double quat[4],
double A[3][3]);
1027 template <
class QuaternionT,
class MatrixT,
1028 class EnableT =
typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>
::type>
1029 static void QuaternionToMatrix3x3(
const QuaternionT& q, MatrixT&& A);
1042 static void Matrix3x3ToQuaternion(
const float A[3][3],
float quat[4]);
1043 static void Matrix3x3ToQuaternion(
const double A[3][3],
double quat[4]);
1044 template <
class MatrixT,
class QuaternionT,
1045 class EnableT =
typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>
::type>
1046 static void Matrix3x3ToQuaternion(
const MatrixT& A, QuaternionT&& q);
1110 const float A[3][3],
float U[3][3],
float w[3],
float VT[3][3]);
1112 const double A[3][3],
double U[3][3],
double w[3],
double VT[3][3]);
1123 double a00,
double a01,
double a10,
double a11,
double b0,
double b1,
double& x0,
double& x1);
1149 double** A,
double** AI,
int size,
int* tmp1Size,
double* tmp2Size);
1243 int numberOfSamples,
double** xt,
int xOrder,
double** mt);
1260 int yOrder,
double** mt,
int checkHomogeneous = 1);
1272 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1274 static void RGBToHSV(
float r,
float g,
float b,
float*
h,
float* s,
float* v);
1275 static void RGBToHSV(
const double rgb[3],
double hsv[3])
1277 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1279 static void RGBToHSV(
double r,
double g,
double b,
double*
h,
double* s,
double* v);
1292 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1294 static void HSVToRGB(
float h,
float s,
float v,
float* r,
float* g,
float* b);
1295 static void HSVToRGB(
const double hsv[3],
double rgb[3])
1297 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1299 static void HSVToRGB(
double h,
double s,
double v,
double* r,
double* g,
double* b);
1306 static void LabToXYZ(
const double lab[3],
double xyz[3])
1308 LabToXYZ(lab[0], lab[1], lab[2], xyz + 0, xyz + 1, xyz + 2);
1310 static void LabToXYZ(
double L,
double a,
double b,
double* x,
double* y,
double* z);
1317 static void XYZToLab(
const double xyz[3],
double lab[3])
1319 XYZToLab(xyz[0], xyz[1], xyz[2], lab + 0, lab + 1, lab + 2);
1321 static void XYZToLab(
double x,
double y,
double z,
double* L,
double* a,
double* b);
1328 static void XYZToRGB(
const double xyz[3],
double rgb[3])
1330 XYZToRGB(xyz[0], xyz[1], xyz[2], rgb + 0, rgb + 1, rgb + 2);
1332 static void XYZToRGB(
double x,
double y,
double z,
double* r,
double* g,
double* b);
1339 static void RGBToXYZ(
const double rgb[3],
double xyz[3])
1341 RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz + 0, xyz + 1, xyz + 2);
1343 static void RGBToXYZ(
double r,
double g,
double b,
double* x,
double* y,
double* z);
1353 static void RGBToLab(
const double rgb[3],
double lab[3])
1355 RGBToLab(rgb[0], rgb[1], rgb[2], lab + 0, lab + 1, lab + 2);
1357 static void RGBToLab(
double red,
double green,
double blue,
double* L,
double* a,
double* b);
1364 static void LabToRGB(
const double lab[3],
double rgb[3])
1366 LabToRGB(lab[0], lab[1], lab[2], rgb + 0, rgb + 1, rgb + 2);
1368 static void LabToRGB(
double L,
double a,
double b,
double* red,
double* green,
double* blue);
1392 if (bounds[1] - bounds[0] < 0.0)
1405 static T ClampValue(
const T&
value,
const T& min,
const T&
max);
1412 static void ClampValue(
double*
value,
const double range[2]);
1413 static void ClampValue(
double value,
const double range[2],
double* clamped_value);
1416 const double* values,
int nb_values,
const double range[2],
double* clamped_values);
1425 static double ClampAndNormalizeValue(
double value,
const double range[2]);
1431 template <
class T1,
class T2>
1440 static void TensorFromSymmetricTensor(T tensor[9]);
1451 double range_min,
double range_max,
double scale = 1.0,
double shift = 0.0);
1475 const double bounds1[6],
const double bounds2[6],
const double delta[3]);
1483 const double point[3],
const double bounds[6],
const double delta[3]);
1495 const double bounds[6],
const double normal[3],
const double point[3]);
1507 const double p1[3],
const double p2[3],
const double p3[3],
double center[3]);
1554 void operator=(
const vtkMath&) =
delete;
1560 return x * 0.017453292f;
1566 return x * 0.017453292519943295;
1572 return x * 57.2957795131f;
1578 return x * 57.29577951308232;
1584 return ((x != 0) & ((x & (x - 1)) == 0));
1591 unsigned int z =
static_cast<unsigned int>(((x > 0) ? x - 1 : 0));
1597 return static_cast<int>(z + 1);
1605 int i =
static_cast<int>(x);
1614 int i =
static_cast<int>(x);
1622 return (b <= a ? b : a);
1629 return (b > a ? b : a);
1638 for (
int i = 0; i < 3; ++i)
1652 for (
int i = 0; i < 3; ++i)
1666 for (
int i = 0; i < 2; ++i)
1680 for (
int i = 0; i < 2; ++i)
1691 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1692 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1698 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1699 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1704 double a1,
double a2,
double a3,
double b1,
double b2,
double b3,
double c1,
double c2,
double c3)
1713 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1714 (p1[2] - p2[2]) * (p1[2] - p2[2]));
1720 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1721 (p1[2] - p2[2]) * (p1[2] - p2[2]));
1725template <
typename ReturnTypeT,
typename TupleRangeT1,
typename TupleRangeT2,
typename EnableT>
1728 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1729 (p1[2] - p2[2]) * (p1[2] - p2[2]));
1736 float Cx = a[1] * b[2] - a[2] * b[1];
1737 float Cy = a[2] * b[0] - a[0] * b[2];
1738 float Cz = a[0] * b[1] - a[1] * b[0];
1748 double Cx = a[1] * b[2] - a[2] * b[1];
1749 double Cy = a[2] * b[0] - a[0] * b[2];
1750 double Cz = a[0] * b[1] - a[1] * b[0];
1760 return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] + A[2][0] * A[0][1] * A[1][2] -
1761 A[0][0] * A[2][1] * A[1][2] - A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1780 assert(
"pre: valid_range" && min <=
max);
1782#if __cplusplus >= 201703L
1783 return std::clamp(
value, min,
max);
1788 return (v <
max ? v :
max);
1797 assert(
"pre: valid_range" &&
range[0] <=
range[1]);
1806 if (
range && clamped_value)
1808 assert(
"pre: valid_range" &&
range[0] <=
range[1]);
1817 assert(
"pre: valid_range" &&
range[0] <=
range[1]);
1833 assert(
"post: valid_result" && result >= 0.0 && result <= 1.0);
1839template <
class T1,
class T2>
1842 for (
int i = 0; i < 3; ++i)
1844 tensor[4 * i] = symmTensor[i];
1846 tensor[1] = tensor[3] = symmTensor[3];
1847 tensor[2] = tensor[6] = symmTensor[5];
1848 tensor[5] = tensor[7] = symmTensor[4];
1855 tensor[6] = tensor[5];
1856 tensor[7] = tensor[4];
1857 tensor[8] = tensor[2];
1858 tensor[4] = tensor[1];
1859 tensor[5] = tensor[7];
1860 tensor[2] = tensor[6];
1861 tensor[1] = tensor[3];
1866template <
class QuaternionT,
class MatrixT>
1867inline void vtkQuaternionToMatrix3x3(
const QuaternionT& quat, MatrixT& A)
1871 Scalar ww = quat[0] * quat[0];
1872 Scalar wx = quat[0] * quat[1];
1873 Scalar wy = quat[0] * quat[2];
1874 Scalar wz = quat[0] * quat[3];
1876 Scalar xx = quat[1] * quat[1];
1877 Scalar yy = quat[2] * quat[2];
1878 Scalar zz = quat[3] * quat[3];
1880 Scalar xy = quat[1] * quat[2];
1881 Scalar xz = quat[1] * quat[3];
1882 Scalar yz = quat[2] * quat[3];
1884 Scalar rr = xx + yy + zz;
1886 Scalar f = 1 / (ww + rr);
1887 Scalar s = (ww - rr) * f;
1892 Wrapper::template Get<0, 0>(A) = xx * f + s;
1893 Wrapper::template Get<1, 0>(A) = (xy + wz) * f;
1894 Wrapper::template Get<2, 0>(A) = (xz - wy) * f;
1896 Wrapper::template Get<0, 1>(A) = (xy - wz) * f;
1897 Wrapper::template Get<1, 1>(A) = yy * f + s;
1898 Wrapper::template Get<2, 1>(A) = (yz + wx) * f;
1900 Wrapper::template Get<0, 2>(A) = (xz + wy) * f;
1901 Wrapper::template Get<1, 2>(A) = (yz - wx) * f;
1902 Wrapper::template Get<2, 2>(A) = zz * f + s;
1909 vtkQuaternionToMatrix3x3(quat, A);
1915 vtkQuaternionToMatrix3x3(quat, A);
1919template <
class QuaternionT,
class MatrixT,
class EnableT>
1922 vtkQuaternionToMatrix3x3(q, A);
1932template <
class MatrixT,
class QuaternionT>
1933inline void vtkMatrix3x3ToQuaternion(
const MatrixT& A, QuaternionT& quat)
1942 N[0][0] = Wrapper::template Get<0, 0>(A) + Wrapper::template Get<1, 1>(A) +
1943 Wrapper::template Get<2, 2>(A);
1944 N[1][1] = Wrapper::template Get<0, 0>(A) - Wrapper::template Get<1, 1>(A) -
1945 Wrapper::template Get<2, 2>(A);
1946 N[2][2] = -Wrapper::template Get<0, 0>(A) + Wrapper::template Get<1, 1>(A) -
1947 Wrapper::template Get<2, 2>(A);
1948 N[3][3] = -Wrapper::template Get<0, 0>(A) - Wrapper::template Get<1, 1>(A) +
1949 Wrapper::template Get<2, 2>(A);
1952 N[0][1] = N[1][0] = Wrapper::template Get<2, 1>(A) - Wrapper::template Get<1, 2>(A);
1953 N[0][2] = N[2][0] = Wrapper::template Get<0, 2>(A) - Wrapper::template Get<2, 0>(A);
1954 N[0][3] = N[3][0] = Wrapper::template Get<1, 0>(A) - Wrapper::template Get<0, 1>(A);
1956 N[1][2] = N[2][1] = Wrapper::template Get<1, 0>(A) + Wrapper::template Get<0, 1>(A);
1957 N[1][3] = N[3][1] = Wrapper::template Get<0, 2>(A) + Wrapper::template Get<2, 0>(A);
1958 N[2][3] = N[3][2] = Wrapper::template Get<2, 1>(A) + Wrapper::template Get<1, 2>(A);
1960 Scalar eigenvectors[4][4], eigenvalues[4];
1964 Scalar *NTemp[4], *eigenvectorsTemp[4];
1965 for (
int i = 0; i < 4; ++i)
1968 eigenvectorsTemp[i] = eigenvectors[i];
1973 quat[0] = eigenvectors[0][0];
1974 quat[1] = eigenvectors[1][0];
1975 quat[2] = eigenvectors[2][0];
1976 quat[3] = eigenvectors[3][0];
1983 vtkMatrix3x3ToQuaternion(A, quat);
1989 vtkMatrix3x3ToQuaternion(A, quat);
1993template <
class MatrixT,
class QuaternionT,
class EnableT>
1996 vtkMatrix3x3ToQuaternion(A, q);
2002template <
typename OutT>
2010 *ret =
static_cast<OutT
>((val >= 0.0) ? (val + 0.5) : (val - 0.5));
2030 *retVal =
static_cast<float>(val);
2035#if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
2036#define VTK_MATH_ISINF_IS_INLINE
2039#if defined(VTK_HAS_STD_ISINF)
2040 return std::isinf(x);
2042 return (isinf(x) != 0);
2048#if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
2049#define VTK_MATH_ISNAN_IS_INLINE
2052#if defined(VTK_HAS_STD_ISNAN)
2055 return (
isnan(x) != 0);
2061#if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
2062#define VTK_MATH_ISFINITE_IS_INLINE
2065#if defined(VTK_HAS_STD_ISFINITE)
2066 return std::isfinite(x);
2067#elif defined(VTK_HAS_ISFINITE)
2068 return (isfinite(x) != 0);
2070 return (finite(x) != 0);
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
abstract superclass for arrays of numeric data
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
a simple class to control print indentation
performs common math operations
static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1 &p1, const TupleRangeT2 &p2)
Compute distance squared between two points p1 and p2.
static void Multiply3x3(const float A[3][3], const float B[3][3], float C[3][3])
Multiply one 3x3 matrix by another according to C = AB.
static double Dot(const double a[3], const double b[3])
Dot product of two 3-vectors (double version).
static int GetScalarTypeFittingRange(double range_min, double range_max, double scale=1.0, double shift=0.0)
Return the scalar type that is most likely to have enough precision to store a given range of data on...
static void RGBToXYZ(double r, double g, double b, double *x, double *y, double *z)
Convert color from the RGB system to CIE XYZ.
static void Multiply3x3(const double A[3][3], const double B[3][3], double C[3][3])
Multiply one 3x3 matrix by another according to C = AB.
static double Norm(const double *x, int n)
Compute the norm of n-vector.
static int Round(float f)
Rounds a float to the nearest integer.
static void MultiplyMatrixWithVector(const MatrixT &M, const VectorT1 &X, VectorT2 &&Y)
Multiply matrix M with vector Y such that Y = M x X.
static double Norm2D(const double x[2])
Compute the norm of a 2-vector.
static void XYZToRGB(double x, double y, double z, double *r, double *g, double *b)
Convert color from the CIE XYZ system to RGB.
static void Subtract(const float a[3], const float b[3], float c[3])
Subtraction of two 3-vectors (float version).
static void LUSolve3x3(const double A[3][3], const int index[3], double x[3])
LU back substitution for a 3x3 matrix.
static vtkTypeBool SolveHomogeneousLeastSquares(int numberOfSamples, double **xt, int xOrder, double **mt)
Solves for the least squares best fit matrix for the homogeneous equation X'M' = 0'.
static void Outer2D(const float x[2], const float y[2], float A[2][2])
Outer product of two 2-vectors (float version).
static bool ProjectVector(const double a[3], const double b[3], double projection[3])
Compute the projection of vector a on vector b and return it in projection[3].
static vtkSmartPointer< vtkMathInternal > Internal
static float Norm(const float *x, int n)
Compute the norm of n-vector.
static vtkTypeBool ExtentIsWithinOtherExtent(const int extent1[6], const int extent2[6])
Return true if first 3D extent is within second 3D extent Extent is x-min, x-max, y-min,...
static void Add(const double a[3], const double b[3], double c[3])
Addition of two 3-vectors (double version).
static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v)
Convert color in RGB format (Red, Green, Blue) to HSV format (Hue, Saturation, Value).
static float Norm(const float v[3])
Compute the norm of 3-vector (float version).
static ReturnTypeT Dot(const TupleRangeT1 &a, const TupleRangeT2 &b)
Compute dot product between two points p1 and p2.
static vtkTypeBool Jacobi(double **a, double *w, double **v)
Jacobi iteration for the solution of eigenvectors/eigenvalues of a 3x3 real symmetric matrix.
static void XYZToLab(const double xyz[3], double lab[3])
Convert Color from the CIE XYZ system to CIE-L*ab.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkTypeInt64 Factorial(int N)
Compute N factorial, N! = N*(N-1) * (N-2)...*3*2*1.
static vtkTypeInt64 Binomial(int m, int n)
The number of combinations of n objects from a pool of m objects (m>n).
static double Random()
Generate pseudo-random numbers distributed according to the uniform distribution between 0....
static void LinearSolve(const MatrixT &M, const VectorT1 &x, VectorT2 &y)
This method solves linear systems M * x = y.
static void Identity3x3(float A[3][3])
Set A to the identity matrix.
static double GaussianAmplitude(const double variance, const double distanceFromMean)
Compute the amplitude of a Gaussian function with mean=0 and specified variance.
static void SingularValueDecomposition3x3(const float A[3][3], float U[3][3], float w[3], float VT[3][3])
Perform singular value decomposition on a 3x3 matrix.
static double Nan()
Special IEEE-754 number used to represent Not-A-Number (Nan).
static void Perpendiculars(const float v1[3], float v2[3], float v3[3], double theta)
Given a unit vector v1, find two unit vectors v2 and v3 such that v1 cross v2 = v3 (i....
static double Gaussian(double mean, double std)
Generate pseudo-random numbers distributed according to the Gaussian distribution with mean mean and ...
static bool IsFinite(double x)
Test if a number has finite value i.e.
static void LUSolveLinearSystem(double **A, int *index, double *x, int size)
Solve linear equations Ax = b using LU decomposition A = LU where L is lower triangular matrix and U ...
static double EstimateMatrixCondition(const double *const *A, int size)
Estimate the condition number of a LU factored matrix.
static void LUFactor3x3(float A[3][3], int index[3])
LU Factorization of a 3x3 matrix.
static void FreeCombination(int *combination)
Free the "iterator" array created by vtkMath::BeginCombination.
static double Random(double min, double max)
Generate pseudo-random numbers distributed according to the uniform distribution between min and max.
static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9])
Convert a 6-Component symmetric tensor into a 9-Component tensor, no allocation performed.
static void LabToXYZ(const double lab[3], double xyz[3])
Convert color from the CIE-L*ab system to CIE XYZ.
static double Solve3PointCircle(const double p1[3], const double p2[3], const double p3[3], double center[3])
In Euclidean space, there is a unique circle passing through any given three non-collinear points P1,...
static vtkTypeBool PointIsWithinBounds(const double point[3], const double bounds[6], const double delta[3])
Return true if point is within the given 3D bounds Bounds is x-min, x-max, y-min, y-max,...
static float Dot(const float a[3], const float b[3])
Dot product of two 3-vectors (float version).
static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3])
Diagonalize a symmetric 3x3 matrix and return the eigenvalues in w and the eigenvectors in the column...
static void LabToXYZ(double L, double a, double b, double *x, double *y, double *z)
Convert color from the CIE-L*ab system to CIE XYZ.
static vtkTypeBool GetAdjustedScalarRange(vtkDataArray *array, int comp, double range[2])
Get a vtkDataArray's scalar range for a given component.
static bool ProjectVector(const float a[3], const float b[3], float projection[3])
Compute the projection of vector a on vector b and return it in projection[3].
static void Cross(const float a[3], const float b[3], float c[3])
Cross product of two 3-vectors.
static void MultiplyScalar2D(float a[2], float s)
Multiplies a 2-vector by a scalar (float version).
static void HSVToRGB(const float hsv[3], float rgb[3])
Convert color in HSV format (Hue, Saturation, Value) to RGB format (Red, Green, Blue).
static void Assign(const double a[3], double b[3])
Assign values to a 3-vector (double version).
static double Determinant2x2(const double c1[2], const double c2[2])
Calculate the determinant of a 2x2 matrix: | a b | | c d |.
static T Max(const T &a, const T &b)
Returns the maximum of the two arguments provided.
static void Outer2D(const double x[2], const double y[2], double A[2][2])
Outer product of two 2-vectors (double version).
static void RandomSeed(int s)
Initialize seed value.
static double NegInf()
Special IEEE-754 number used to represent negative infinity.
static void MultiplyScalar2D(double a[2], double s)
Multiplies a 2-vector by a scalar (double version).
static void LabToRGB(double L, double a, double b, double *red, double *green, double *blue)
Convert color from the CIE-L*ab system to RGB.
static double Gaussian()
Generate pseudo-random numbers distributed according to the standard normal distribution.
static int Ceil(double x)
Rounds a double to the nearest integer not less than itself.
static void HSVToRGB(const double hsv[3], double rgb[3])
Convert color in HSV format (Hue, Saturation, Value) to RGB format (Red, Green, Blue).
~vtkMath() override=default
static ScalarT Dot(const VectorT1 &x, const VectorT2 &y)
Computes the dot product between 2 vectors x and y.
static double Inf()
Special IEEE-754 number used to represent positive infinity.
static double GaussianAmplitude(const double mean, const double variance, const double position)
Compute the amplitude of a Gaussian function with specified mean and variance.
static vtkTypeBool Jacobi(float **a, float *w, float **v)
Jacobi iteration for the solution of eigenvectors/eigenvalues of a 3x3 real symmetric matrix.
static int PlaneIntersectsAABB(const double bounds[6], const double normal[3], const double point[3])
Implements Plane / Axis-Aligned Bounding-Box intersection as described in Graphics Gems IV,...
static void RGBToXYZ(const double rgb[3], double xyz[3])
Convert color from the RGB system to CIE XYZ.
static void QuaternionToMatrix3x3(const float quat[4], float A[3][3])
Convert a quaternion to a 3x3 rotation matrix.
static int NearestPowerOfTwo(int x)
Compute the nearest power of two that is not less than x.
static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b)
Convert color in HSV format (Hue, Saturation, Value) to RGB format (Red, Green, Blue).
static void SingularValueDecomposition3x3(const double A[3][3], double U[3][3], double w[3], double VT[3][3])
Perform singular value decomposition on a 3x3 matrix.
static double SignedAngleBetweenVectors(const double v1[3], const double v2[3], const double vn[3])
Compute signed angle in radians between two vectors with regard to a third orthogonal vector.
static float Normalize2D(float v[2])
Normalize (in place) a 2-vector.
static void Invert3x3(const double A[3][3], double AI[3][3])
Invert a 3x3 matrix.
static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b)
Convert color in HSV format (Hue, Saturation, Value) to RGB format (Red, Green, Blue).
static void MultiplyQuaternion(const double q1[4], const double q2[4], double q[4])
Multiply two quaternions.
static void Multiply3x3(const double A[3][3], const double v[3], double u[3])
Multiply a vector by a 3x3 matrix.
static void Outer(const double a[3], const double b[3], double c[3][3])
Outer product of two 3-vectors (double version).
static vtkTypeBool InvertMatrix(double **A, double **AI, int size, int *tmp1Size, double *tmp2Size)
Thread safe version of InvertMatrix method.
static vtkTypeBool InvertMatrix(double **A, double **AI, int size)
Invert input square matrix A into matrix AI.
static void LUSolve3x3(const float A[3][3], const int index[3], float x[3])
LU back substitution for a 3x3 matrix.
static int GetSeed()
Return the current seed used by the random number generator.
static void Assign(const VectorT1 &a, VectorT2 &&b)
Assign values to a 3-vector (templated version).
static float RadiansFromDegrees(float degrees)
Convert degrees into radians.
static void RotateVectorByWXYZ(const double v[3], const double q[4], double r[3])
rotate a vector by WXYZ using // https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
static void Add(const float a[3], const float b[3], float c[3])
Addition of two 3-vectors (float version).
static int CeilLog2(vtkTypeUInt64 x)
Gives the exponent of the lowest power of two not less than x.
static vtkTypeBool AreBoundsInitialized(const double bounds[6])
Are the bounds initialized?
static bool ProjectVector2D(const double a[2], const double b[2], double projection[2])
Compute the projection of 2D vector a on 2D vector b and returns the result in projection[2].
static vtkTypeBool JacobiN(float **a, int n, float *w, float **v)
JacobiN iteration for the solution of eigenvectors/eigenvalues of a nxn real symmetric matrix.
static vtkMatrixUtilities::ScalarTypeExtractor< MatrixT >::value_type Determinant(const MatrixT &M)
Computes the determinant of input square SizeT x SizeT matrix M.
static int NextCombination(int m, int n, int *combination)
Given m, n, and a valid combination of n integers in the range [0,m[, this function alters the intege...
static constexpr double Pi()
A mathematical constant.
static double GaussianWeight(const double variance, const double distanceFromMean)
Compute the amplitude of an unnormalized Gaussian function with mean=0 and specified variance.
static void Multiply3x3(const float A[3][3], const float v[3], float u[3])
Multiply a vector by a 3x3 matrix.
static void Subtract(const double a[3], const double b[3], double c[3])
Subtraction of two 3-vectors (double version).
static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
Convert a 3x3 matrix into a quaternion.
static void Orthogonalize3x3(const double A[3][3], double B[3][3])
Orthogonalize a 3x3 matrix and put the result in B.
static void XYZToRGB(const double xyz[3], double rgb[3])
Convert color from the CIE XYZ system to RGB.
static double ClampAndNormalizeValue(double value, const double range[2])
Clamp a value against a range and then normalize it between 0 and 1.
static void MultiplyScalar(double a[3], double s)
Multiplies a 3-vector by a scalar (double version).
static double Dot2D(const double x[2], const double y[2])
Dot product of two 2-vectors.
static void LinearSolve3x3(const float A[3][3], const float x[3], float y[3])
Solve Ay = x for y and place the result in y.
static void MultiplyMatrix(const MatrixT1 &M1, const MatrixT2 &M2, MatrixT3 &&M3)
Multiply matrices such that M3 = M1 x M2.
static vtkTypeBool IsNan(double x)
Test if a number is equal to the special floating point value Not-A-Number (Nan).
static void Diagonalize3x3(const double A[3][3], double w[3], double V[3][3])
Diagonalize a symmetric 3x3 matrix and return the eigenvalues in w and the eigenvectors in the column...
static void RGBToLab(const double rgb[3], double lab[3])
Convert color from the RGB system to CIE-L*ab.
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
static void RotateVectorByNormalizedQuaternion(const double v[3], const double q[4], double r[3])
rotate a vector by a normalized quaternion using // https://en.wikipedia.org/wiki/Rodrigues%27_rotati...
static void Subtract(const VectorT1 &a, const VectorT2 &b, VectorT3 &&c)
Subtraction of two 3-vectors (templated version).
static vtkTypeBool BoundsIsWithinOtherBounds(const double bounds1[6], const double bounds2[6], const double delta[3])
Return true if first 3D bounds is within the second 3D bounds Bounds is x-min, x-max,...
static double Determinant2x2(double a, double b, double c, double d)
Calculate the determinant of a 2x2 matrix: | a b | | c d |.
static void RGBToHSV(const double rgb[3], double hsv[3])
Convert color in RGB format (Red, Green, Blue) to HSV format (Hue, Saturation, Value).
static vtkTypeBool JacobiN(double **a, int n, double *w, double **v)
JacobiN iteration for the solution of eigenvectors/eigenvalues of a nxn real symmetric matrix.
static double AngleBetweenVectors(const double v1[3], const double v2[3])
Compute angle in radians between two vectors.
static void MultiplyMatrix(const double *const *A, const double *const *B, unsigned int rowA, unsigned int colA, unsigned int rowB, unsigned int colB, double **C)
General matrix multiplication.
static float DegreesFromRadians(float radians)
Convert radians into degrees.
static float Determinant2x2(const float c1[2], const float c2[2])
Compute determinant of 2x2 matrix.
static int Round(double f)
static vtkTypeBool IsInf(double x)
Test if a number is equal to the special floating point value infinity.
static void UninitializeBounds(double bounds[6])
Set the bounds to an uninitialized state.
static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v)
Convert color in RGB format (Red, Green, Blue) to HSV format (Hue, Saturation, Value).
static void Outer(const float a[3], const float b[3], float c[3][3])
Outer product of two 3-vectors (float version).
static int * BeginCombination(int m, int n)
Start iterating over "m choose n" objects.
static double Norm(const double v[3])
Compute the norm of 3-vector (double version).
static void RoundDoubleToIntegralIfNecessary(double val, OutT *ret)
Round a double to type OutT if OutT is integral, otherwise simply clamp the value to the output range...
static void RotateVectorByWXYZ(const float v[3], const float q[4], float r[3])
rotate a vector by WXYZ using // https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Returns true if integer is a power of two.
static void Invert3x3(const float A[3][3], float AI[3][3])
Invert a 3x3 matrix.
static float Normalize(float v[3])
Normalize (in place) a 3-vector.
static void Transpose3x3(const double A[3][3], double AT[3][3])
Transpose a 3x3 matrix.
static ReturnTypeT SquaredNorm(const TupleRangeT &v)
Compute the squared norm of a 3-vector.
static double Determinant3x3(const float A[3][3])
Return the determinant of a 3x3 matrix.
static float Dot2D(const float x[2], const float y[2])
Dot product of two 2-vectors.
static void RotateVectorByNormalizedQuaternion(const float v[3], const float q[4], float r[3])
rotate a vector by a normalized quaternion using // https://en.wikipedia.org/wiki/Rodrigues%27_rotati...
static ScalarT Dot(const VectorT1 &x, const MatrixT &M, const VectorT2 &y)
Computes the dot product x^T M y, where x and y are vectors and M is a metric matrix.
static void RGBToHSV(const float rgb[3], float hsv[3])
Convert color in RGB format (Red, Green, Blue) to HSV format (Hue, Saturation, Value).
static void Orthogonalize3x3(const float A[3][3], float B[3][3])
Orthogonalize a 3x3 matrix and put the result in B.
static bool ProjectVector2D(const float a[2], const float b[2], float projection[2])
Compute the projection of 2D vector a on 2D vector b and returns the result in projection[2].
static vtkTypeBool SolveLinearSystemGEPP2x2(double a00, double a01, double a10, double a11, double b0, double b1, double &x0, double &x1)
Solve linear equation Ax = b using Gaussian Elimination with Partial Pivoting for a 2x2 system.
static vtkTypeBool SolveLinearSystem(double **A, double *x, int size)
Solve linear equations Ax = b using Crout's method.
static void LabToRGB(const double lab[3], double rgb[3])
Convert color from the CIE-L*ab system to RGB.
static float Norm2D(const float x[2])
Compute the norm of a 2-vector.
static double GaussianWeight(const double mean, const double variance, const double position)
Compute the amplitude of an unnormalized Gaussian function with specified mean and variance.
static vtkTypeBool LUFactorLinearSystem(double **A, int *index, int size, double *tmpSize)
Thread safe version of LUFactorLinearSystem method.
static void LinearSolve3x3(const double A[3][3], const double x[3], double y[3])
Solve Ay = x for y and place the result in y.
static void XYZToLab(double x, double y, double z, double *L, double *a, double *b)
Convert Color from the CIE XYZ system to CIE-L*ab.
static void InvertMatrix(const MatrixT1 &M1, MatrixT2 &&M2)
Computes the inverse of input matrix M1 into M2.
static void MultiplyScalar(float a[3], float s)
Multiplies a 3-vector by a scalar (float version).
static T Min(const T &a, const T &b)
Returns the minimum of the two arguments provided.
static void Perpendiculars(const double v1[3], double v2[3], double v3[3], double theta)
Given a unit vector v1, find two unit vectors v2 and v3 such that v1 cross v2 = v3 (i....
static T ClampValue(const T &value, const T &min, const T &max)
Clamp some value against a range, return the result.
static vtkTypeBool SolveLeastSquares(int numberOfSamples, double **xt, int xOrder, double **yt, int yOrder, double **mt, int checkHomogeneous=1)
Solves for the least squares best fit matrix for the equation X'M' = Y'.
static void Identity3x3(double A[3][3])
Set A to the identity matrix.
static void LUFactor3x3(double A[3][3], int index[3])
LU Factorization of a 3x3 matrix.
static vtkTypeBool LUFactorLinearSystem(double **A, int *index, int size)
Factor linear equations Ax = b using LU decomposition into the form A = LU where L is a unit lower tr...
static void RGBToLab(double red, double green, double blue, double *L, double *a, double *b)
Convert color from the RGB system to CIE-L*ab.
static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4])
Multiply two quaternions.
static void ClampValues(const double *values, int nb_values, const double range[2], double *clamped_values)
Clamp some values against a range The method without 'clamped_values' will perform in-place clamping.
static void Transpose3x3(const float A[3][3], float AT[3][3])
Transpose a 3x3 matrix.
static void ClampValues(double *values, int nb_values, const double range[2])
Clamp some values against a range The method without 'clamped_values' will perform in-place clamping.
static int QuadraticRoot(double a, double b, double c, double min, double max, double *u)
find roots of ax^2+bx+c=0 in the interval min,max.
Park and Miller Sequence of pseudo random numbers.
abstract base class for most VTK objects
represent and manipulate 3D points
void RoundDoubleToIntegralIfNecessary(double val, OutT *ret)
Template defining traits of native types used by VTK.
double vtkDeterminant3x3(const T A[3][3])