48 #include "vtkCommonCoreModule.h"
49 #include "vtkMathPrivate.hxx"
55 #include "vtkMathConfigure.h"
61 #define VTK_DBL_MIN 2.2250738585072014e-308
63 #define VTK_DBL_MIN DBL_MIN
67 #define VTK_DBL_EPSILON 2.2204460492503131e-16
69 #define VTK_DBL_EPSILON DBL_EPSILON
72 #ifndef VTK_DBL_EPSILON
74 #define VTK_DBL_EPSILON 2.2204460492503131e-16
76 #define VTK_DBL_EPSILON DBL_EPSILON
78 #endif // VTK_DBL_EPSILON
82 class vtkMathInternal;
89 template <
typename OutT>
103 static constexpr
double Pi() {
return 3.141592653589793; }
109 static float RadiansFromDegrees(
float degrees);
110 static double RadiansFromDegrees(
double degrees);
117 static float DegreesFromRadians(
float radians);
118 static double DegreesFromRadians(
double radians);
125 static int Round(
float f) {
return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
126 static int Round(
double f) {
return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
133 template <
typename OutT>
146 static int Floor(
double x);
153 static int Ceil(
double x);
160 static int CeilLog2(vtkTypeUInt64 x);
167 static T Min(
const T& a,
const T& b);
174 static T Max(
const T& a,
const T& b);
179 static bool IsPowerOfTwo(vtkTypeUInt64 x);
186 static int NearestPowerOfTwo(
int x);
192 static vtkTypeInt64 Factorial(
int N);
199 static vtkTypeInt64 Binomial(
int m,
int n);
212 static int* BeginCombination(
int m,
int n);
224 static int NextCombination(
int m,
int n,
int* combination);
229 static void FreeCombination(
int* combination);
246 static void RandomSeed(
int s);
259 static int GetSeed();
274 static double Random();
288 static double Random(
double min,
double max);
302 static double Gaussian();
316 static double Gaussian(
double mean,
double std);
322 template <
class VectorT1,
class VectorT2>
323 static void Assign(
const VectorT1& a, VectorT2&& b)
333 static void Assign(
const double a[3],
double b[3]) { vtkMath::Assign<>(a, b); }
338 static void Add(
const float a[3],
const float b[3],
float c[3])
340 for (
int i = 0; i < 3; ++i)
349 static void Add(
const double a[3],
const double b[3],
double c[3])
351 for (
int i = 0; i < 3; ++i)
360 static void Subtract(
const float a[3],
const float b[3],
float c[3])
362 for (
int i = 0; i < 3; ++i)
371 static void Subtract(
const double a[3],
const double b[3],
double c[3])
373 for (
int i = 0; i < 3; ++i)
384 template <
class VectorT1,
class VectorT2,
class VectorT3>
385 static void Subtract(
const VectorT1& a,
const VectorT2& b, VectorT3&& c)
398 for (
int i = 0; i < 3; ++i)
410 for (
int i = 0; i < 2; ++i)
422 for (
int i = 0; i < 3; ++i)
434 for (
int i = 0; i < 2; ++i)
443 static float Dot(
const float a[3],
const float b[3])
445 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
451 static double Dot(
const double a[3],
const double b[3])
453 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
471 template <
typename ReturnTypeT = double,
typename TupleRangeT1,
typename TupleRangeT2,
474 TupleRangeT1, TupleRangeT2>::type::value_type>
475 static ReturnTypeT
Dot(
const TupleRangeT1& a,
const TupleRangeT2& b)
477 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
483 static void Outer(
const float a[3],
const float b[3],
float c[3][3])
485 for (
int i = 0; i < 3; ++i)
487 for (
int j = 0; j < 3; ++j)
489 c[i][j] = a[i] * b[j];
497 static void Outer(
const double a[3],
const double b[3],
double c[3][3])
499 for (
int i = 0; i < 3; ++i)
501 for (
int j = 0; j < 3; ++j)
503 c[i][j] = a[i] * b[j];
512 static void Cross(
const float a[3],
const float b[3],
float c[3]);
518 static void Cross(
const double a[3],
const double b[3],
double c[3]);
524 static float Norm(
const float* x,
int n);
525 static double Norm(
const double* x,
int n);
531 static float Norm(
const float v[3]) {
return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); }
536 static double Norm(
const double v[3])
538 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
550 template <
typename ReturnTypeT =
double,
typename TupleRangeT>
553 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
560 static float Normalize(
float v[3]);
566 static double Normalize(
double v[3]);
576 static void Perpendiculars(
const double v1[3],
double v2[3],
double v3[3],
double theta);
577 static void Perpendiculars(
const float v1[3],
float v2[3],
float v3[3],
double theta);
586 static bool ProjectVector(
const float a[3],
const float b[3],
float projection[3]);
587 static bool ProjectVector(
const double a[3],
const double b[3],
double projection[3]);
597 static bool ProjectVector2D(
const float a[2],
const float b[2],
float projection[2]);
598 static bool ProjectVector2D(
const double a[2],
const double b[2],
double projection[2]);
616 template <
typename ReturnTypeT = double,
typename TupleRangeT1,
typename TupleRangeT2,
619 TupleRangeT1, TupleRangeT2>::type::value_type>
620 static ReturnTypeT Distance2BetweenPoints(
const TupleRangeT1& p1,
const TupleRangeT2& p2);
626 static float Distance2BetweenPoints(
const float p1[3],
const float p2[3]);
632 static double Distance2BetweenPoints(
const double p1[3],
const double p2[3]);
637 static double AngleBetweenVectors(
const double v1[3],
const double v2[3]);
642 static double SignedAngleBetweenVectors(
643 const double v1[3],
const double v2[3],
const double vn[3]);
649 static double GaussianAmplitude(
const double variance,
const double distanceFromMean);
655 static double GaussianAmplitude(
const double mean,
const double variance,
const double position);
662 static double GaussianWeight(
const double variance,
const double distanceFromMean);
669 static double GaussianWeight(
const double mean,
const double variance,
const double position);
674 static float Dot2D(
const float x[2],
const float y[2]) {
return x[0] * y[0] + x[1] * y[1]; }
679 static double Dot2D(
const double x[2],
const double y[2]) {
return x[0] * y[0] + x[1] * y[1]; }
684 static void Outer2D(
const float x[2],
const float y[2],
float A[2][2])
686 for (
int i = 0; i < 2; ++i)
688 for (
int j = 0; j < 2; ++j)
690 A[i][j] = x[i] * y[j];
698 static void Outer2D(
const double x[2],
const double y[2],
double A[2][2])
700 for (
int i = 0; i < 2; ++i)
702 for (
int j = 0; j < 2; ++j)
704 A[i][j] = x[i] * y[j];
713 static float Norm2D(
const float x[2]) {
return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
719 static double Norm2D(
const double x[2]) {
return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
725 static float Normalize2D(
float v[2]);
731 static double Normalize2D(
double v[2]);
738 return c1[0] * c2[1] - c2[0] * c1[1];
745 static double Determinant2x2(
double a,
double b,
double c,
double d) {
return a * d - b * c; }
748 return c1[0] * c2[1] - c2[0] * c1[1];
756 static void LUFactor3x3(
float A[3][3],
int index[3]);
757 static void LUFactor3x3(
double A[3][3],
int index[3]);
764 static void LUSolve3x3(
const float A[3][3],
const int index[3],
float x[3]);
765 static void LUSolve3x3(
const double A[3][3],
const int index[3],
double x[3]);
773 static void LinearSolve3x3(
const float A[3][3],
const float x[3],
float y[3]);
774 static void LinearSolve3x3(
const double A[3][3],
const double x[3],
double y[3]);
781 static void Multiply3x3(
const float A[3][3],
const float v[3],
float u[3]);
782 static void Multiply3x3(
const double A[3][3],
const double v[3],
double u[3]);
789 static void Multiply3x3(
const float A[3][3],
const float B[3][3],
float C[3][3]);
790 static void Multiply3x3(
const double A[3][3],
const double B[3][3],
double C[3][3]);
816 template <
int RowsT,
int MidDimT,
int ColsT,
817 class LayoutT1 = vtkMatrixUtilities::Layout::Identity,
818 class LayoutT2 = vtkMatrixUtilities::Layout::Identity,
class MatrixT1,
class MatrixT2,
820 static void MultiplyMatrix(
const MatrixT1& M1,
const MatrixT2& M2, MatrixT3&& M3)
822 vtkMathPrivate::MultiplyMatrix<RowsT, MidDimT, ColsT, LayoutT1, LayoutT2>::Compute(M1, M2, M3);
845 template <
int RowsT,
int ColsT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
846 class MatrixT,
class VectorT1,
class VectorT2>
849 vtkMathPrivate::MultiplyMatrix<RowsT, ColsT, 1, LayoutT>::Compute(M, X, Y);
857 template <
class ScalarT,
int SizeT,
class VectorT1,
class VectorT2>
858 static ScalarT
Dot(
const VectorT1& x,
const VectorT2& y)
860 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
861 vtkMatrixUtilities::Layout::Identity, vtkMatrixUtilities::Layout::Transpose>::Compute(x, y);
880 template <
int SizeT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
class MatrixT>
884 return vtkMathPrivate::Determinant<SizeT, LayoutT>::Compute(M);
902 template <
int SizeT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
class MatrixT1,
906 vtkMathPrivate::InvertMatrix<SizeT, LayoutT>::Compute(M1, M2);
922 template <
int RowsT,
int ColsT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
923 class MatrixT,
class VectorT1,
class VectorT2>
924 static void LinearSolve(
const MatrixT& M,
const VectorT1& x, VectorT2& y)
926 vtkMathPrivate::LinearSolve<RowsT, ColsT, LayoutT>::Compute(M, x, y);
943 template <
class ScalarT,
int SizeT,
class LayoutT = vtkMatrixUtilities::Layout::Identity,
944 class VectorT1,
class MatrixT,
class VectorT2>
945 static ScalarT
Dot(
const VectorT1& x,
const MatrixT& M,
const VectorT2& y)
948 vtkMathPrivate::MultiplyMatrix<SizeT, SizeT, 1, LayoutT>::Compute(M, y, tmp);
949 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
950 vtkMatrixUtilities::Layout::Identity, vtkMatrixUtilities::Layout::Transpose>::Compute(x, tmp);
958 static void MultiplyMatrix(
const double*
const* A,
const double*
const* B,
unsigned int rowA,
959 unsigned int colA,
unsigned int rowB,
unsigned int colB,
double** C);
966 static void Transpose3x3(
const float A[3][3],
float AT[3][3]);
967 static void Transpose3x3(
const double A[3][3],
double AT[3][3]);
975 static void Invert3x3(
const float A[3][3],
float AI[3][3]);
976 static void Invert3x3(
const double A[3][3],
double AI[3][3]);
983 static void Identity3x3(
float A[3][3]);
984 static void Identity3x3(
double A[3][3]);
991 static double Determinant3x3(
const float A[3][3]);
992 static double Determinant3x3(
const double A[3][3]);
998 static float Determinant3x3(
const float c1[3],
const float c2[3],
const float c3[3]);
1003 static double Determinant3x3(
const double c1[3],
const double c2[3],
const double c3[3]);
1011 static double Determinant3x3(
double a1,
double a2,
double a3,
double b1,
double b2,
double b3,
1012 double c1,
double c2,
double c3);
1022 static void QuaternionToMatrix3x3(
const float quat[4],
float A[3][3]);
1023 static void QuaternionToMatrix3x3(
const double quat[4],
double A[3][3]);
1024 template <
class QuaternionT,
class MatrixT,
1025 class EnableT =
typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::
type>
1026 static void QuaternionToMatrix3x3(
const QuaternionT& q, MatrixT&& A);
1039 static void Matrix3x3ToQuaternion(
const float A[3][3],
float quat[4]);
1040 static void Matrix3x3ToQuaternion(
const double A[3][3],
double quat[4]);
1041 template <
class MatrixT,
class QuaternionT,
1042 class EnableT =
typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::
type>
1043 static void Matrix3x3ToQuaternion(
const MatrixT& A, QuaternionT&& q);
1053 static void MultiplyQuaternion(
const float q1[4],
const float q2[4],
float q[4]);
1054 static void MultiplyQuaternion(
const double q1[4],
const double q2[4],
double q[4]);
1062 static void RotateVectorByNormalizedQuaternion(
const float v[3],
const float q[4],
float r[3]);
1063 static void RotateVectorByNormalizedQuaternion(
const double v[3],
const double q[4],
double r[3]);
1071 static void RotateVectorByWXYZ(
const float v[3],
const float q[4],
float r[3]);
1072 static void RotateVectorByWXYZ(
const double v[3],
const double q[4],
double r[3]);
1081 static void Orthogonalize3x3(
const float A[3][3],
float B[3][3]);
1082 static void Orthogonalize3x3(
const double A[3][3],
double B[3][3]);
1092 static void Diagonalize3x3(
const float A[3][3],
float w[3],
float V[3][3]);
1093 static void Diagonalize3x3(
const double A[3][3],
double w[3],
double V[3][3]);
1106 static void SingularValueDecomposition3x3(
1107 const float A[3][3],
float U[3][3],
float w[3],
float VT[3][3]);
1108 static void SingularValueDecomposition3x3(
1109 const double A[3][3],
double U[3][3],
double w[3],
double VT[3][3]);
1120 double a00,
double a01,
double a10,
double a11,
double b0,
double b1,
double& x0,
double& x1);
1130 static vtkTypeBool SolveLinearSystem(
double** A,
double* x,
int size);
1146 double** A,
double** AI,
int size,
int* tmp1Size,
double* tmp2Size);
1187 static void LUSolveLinearSystem(
double** A,
int*
index,
double* x,
int size);
1197 static double EstimateMatrixCondition(
const double*
const* A,
int size);
1208 static vtkTypeBool Jacobi(
float** a,
float* w,
float** v);
1209 static vtkTypeBool Jacobi(
double** a,
double* w,
double** v);
1222 static vtkTypeBool JacobiN(
float** a,
int n,
float* w,
float** v);
1223 static vtkTypeBool JacobiN(
double** a,
int n,
double* w,
double** v);
1240 int numberOfSamples,
double** xt,
int xOrder,
double** mt);
1256 static vtkTypeBool SolveLeastSquares(
int numberOfSamples,
double** xt,
int xOrder,
double** yt,
1257 int yOrder,
double** mt,
int checkHomogeneous = 1);
1269 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1271 static void RGBToHSV(
float r,
float g,
float b,
float* h,
float* s,
float* v);
1272 static void RGBToHSV(
const double rgb[3],
double hsv[3])
1274 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1276 static void RGBToHSV(
double r,
double g,
double b,
double* h,
double* s,
double* v);
1289 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1291 static void HSVToRGB(
float h,
float s,
float v,
float* r,
float* g,
float* b);
1292 static void HSVToRGB(
const double hsv[3],
double rgb[3])
1294 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1296 static void HSVToRGB(
double h,
double s,
double v,
double* r,
double* g,
double* b);
1303 static void LabToXYZ(
const double lab[3],
double xyz[3])
1305 LabToXYZ(lab[0], lab[1], lab[2], xyz + 0, xyz + 1, xyz + 2);
1307 static void LabToXYZ(
double L,
double a,
double b,
double* x,
double* y,
double* z);
1314 static void XYZToLab(
const double xyz[3],
double lab[3])
1316 XYZToLab(xyz[0], xyz[1], xyz[2], lab + 0, lab + 1, lab + 2);
1318 static void XYZToLab(
double x,
double y,
double z,
double* L,
double* a,
double* b);
1325 static void XYZToRGB(
const double xyz[3],
double rgb[3])
1327 XYZToRGB(xyz[0], xyz[1], xyz[2], rgb + 0, rgb + 1, rgb + 2);
1329 static void XYZToRGB(
double x,
double y,
double z,
double* r,
double* g,
double* b);
1336 static void RGBToXYZ(
const double rgb[3],
double xyz[3])
1338 RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz + 0, xyz + 1, xyz + 2);
1340 static void RGBToXYZ(
double r,
double g,
double b,
double* x,
double* y,
double* z);
1350 static void RGBToLab(
const double rgb[3],
double lab[3])
1352 RGBToLab(rgb[0], rgb[1], rgb[2], lab + 0, lab + 1, lab + 2);
1354 static void RGBToLab(
double red,
double green,
double blue,
double* L,
double* a,
double* b);
1361 static void LabToRGB(
const double lab[3],
double rgb[3])
1363 LabToRGB(lab[0], lab[1], lab[2], rgb + 0, rgb + 1, rgb + 2);
1365 static void LabToRGB(
double L,
double a,
double b,
double* red,
double* green,
double* blue);
1389 if (bounds[1] - bounds[0] < 0.0)
1402 static T ClampValue(
const T&
value,
const T& min,
const T&
max);
1409 static void ClampValue(
double*
value,
const double range[2]);
1410 static void ClampValue(
double value,
const double range[2],
double* clamped_value);
1411 static void ClampValues(
double* values,
int nb_values,
const double range[2]);
1412 static void ClampValues(
1413 const double* values,
int nb_values,
const double range[2],
double* clamped_values);
1422 static double ClampAndNormalizeValue(
double value,
const double range[2]);
1428 template <
class T1,
class T2>
1429 static void TensorFromSymmetricTensor(
const T1 symmTensor[6], T2 tensor[9]);
1437 static void TensorFromSymmetricTensor(T tensor[9]);
1447 static int GetScalarTypeFittingRange(
1448 double range_min,
double range_max,
double scale = 1.0,
double shift = 0.0);
1464 static vtkTypeBool ExtentIsWithinOtherExtent(
const int extent1[6],
const int extent2[6]);
1472 const double bounds1[6],
const double bounds2[6],
const double delta[3]);
1480 const double point[3],
const double bounds[6],
const double delta[3]);
1491 static int PlaneIntersectsAABB(
1492 const double bounds[6],
const double normal[3],
const double point[3]);
1503 static double Solve3PointCircle(
1504 const double p1[3],
const double p2[3],
const double p3[3],
double center[3]);
1509 static double Inf();
1514 static double NegInf();
1519 static double Nan();
1535 static bool IsFinite(
double x);
1541 static int QuadraticRoot(
double a,
double b,
double c,
double min,
double max,
double* u);
1572 template <
class Iter1,
class Iter2,
class Iter3>
1573 static void Convolve1D(Iter1 beginSample, Iter1 endSample, Iter2 beginKernel, Iter2 endKernel,
1576 int sampleSize = std::distance(beginSample, endSample);
1577 int kernelSize = std::distance(beginKernel, endKernel);
1578 int outSize = std::distance(beginOut, endOut);
1580 if (sampleSize <= 0 || kernelSize <= 0 || outSize <= 0)
1590 case ConvolutionMode::SAME:
1591 begin =
static_cast<int>(std::ceil(std::min(sampleSize, kernelSize) / 2.0)) - 1;
1592 end = begin +
std::max(sampleSize, kernelSize);
1594 case ConvolutionMode::VALID:
1595 begin = std::min(sampleSize, kernelSize) - 1;
1596 end = begin + std::abs(sampleSize - kernelSize) + 1;
1598 case ConvolutionMode::FULL:
1603 for (
int i = begin; i < end; i++)
1605 Iter3 out = beginOut + i - begin;
1607 for (
int j =
std::max(i - sampleSize + 1, 0); j <= std::min(i, kernelSize - 1); j++)
1609 *out += *(beginSample + (i - j)) * *(beginKernel + j);
1616 ~
vtkMath()
override =
default;
1622 void operator=(
const vtkMath&) =
delete;
1628 return x * 0.017453292f;
1634 return x * 0.017453292519943295;
1640 return x * 57.2957795131f;
1646 return x * 57.29577951308232;
1652 return ((x != 0) & ((x & (x - 1)) == 0));
1659 unsigned int z =
static_cast<unsigned int>(((x > 0) ? x - 1 : 0));
1665 return static_cast<int>(z + 1);
1673 int i =
static_cast<int>(x);
1682 int i =
static_cast<int>(x);
1690 return (b <= a ? b : a);
1697 return (b > a ? b : a);
1706 for (
int i = 0; i < 3; ++i)
1720 for (
int i = 0; i < 3; ++i)
1734 for (
int i = 0; i < 2; ++i)
1748 for (
int i = 0; i < 2; ++i)
1759 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1760 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1766 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1767 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1772 double a1,
double a2,
double a3,
double b1,
double b2,
double b3,
double c1,
double c2,
double c3)
1781 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1782 (p1[2] - p2[2]) * (p1[2] - p2[2]));
1788 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1789 (p1[2] - p2[2]) * (p1[2] - p2[2]));
1793 template <
typename ReturnTypeT,
typename TupleRangeT1,
typename TupleRangeT2,
typename EnableT>
1796 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1797 (p1[2] - p2[2]) * (p1[2] - p2[2]));
1804 float Cx = a[1] * b[2] - a[2] * b[1];
1805 float Cy = a[2] * b[0] - a[0] * b[2];
1806 float Cz = a[0] * b[1] - a[1] * b[0];
1816 double Cx = a[1] * b[2] - a[2] * b[1];
1817 double Cy = a[2] * b[0] - a[0] * b[2];
1818 double Cz = a[0] * b[1] - a[1] * b[0];
1828 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] -
1829 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];
1848 assert(
"pre: valid_range" && min <= max);
1850 #if __cplusplus >= 201703L
1851 return std::clamp(value, min, max);
1855 T v = (min < value ? value : min);
1856 return (v < max ? v : max);
1865 assert(
"pre: valid_range" && range[0] <= range[1]);
1874 if (range && clamped_value)
1876 assert(
"pre: valid_range" && range[0] <= range[1]);
1885 assert(
"pre: valid_range" && range[0] <= range[1]);
1888 if (range[0] == range[1])
1898 result = (result - range[0]) / (range[1] - range[0]);
1901 assert(
"post: valid_result" && result >= 0.0 && result <= 1.0);
1907 template <
class T1,
class T2>
1910 for (
int i = 0; i < 3; ++i)
1912 tensor[4 * i] = symmTensor[i];
1914 tensor[1] = tensor[3] = symmTensor[3];
1915 tensor[2] = tensor[6] = symmTensor[5];
1916 tensor[5] = tensor[7] = symmTensor[4];
1923 tensor[6] = tensor[5];
1924 tensor[7] = tensor[4];
1925 tensor[8] = tensor[2];
1926 tensor[4] = tensor[1];
1927 tensor[5] = tensor[7];
1928 tensor[2] = tensor[6];
1929 tensor[1] = tensor[3];
1934 template <
class QuaternionT,
class MatrixT>
1935 inline void vtkQuaternionToMatrix3x3(
const QuaternionT& quat, MatrixT& A)
1939 Scalar ww = quat[0] * quat[0];
1940 Scalar wx = quat[0] * quat[1];
1941 Scalar wy = quat[0] * quat[2];
1942 Scalar wz = quat[0] * quat[3];
1944 Scalar xx = quat[1] * quat[1];
1945 Scalar yy = quat[2] * quat[2];
1946 Scalar zz = quat[3] * quat[3];
1948 Scalar xy = quat[1] * quat[2];
1949 Scalar xz = quat[1] * quat[3];
1950 Scalar yz = quat[2] * quat[3];
1952 Scalar rr = xx + yy + zz;
1954 Scalar f = 1 / (ww + rr);
1955 Scalar s = (ww - rr) * f;
1960 Wrapper::template Get<0, 0>(A) = xx * f + s;
1961 Wrapper::template Get<1, 0>(A) = (xy + wz) * f;
1962 Wrapper::template Get<2, 0>(A) = (xz - wy) * f;
1964 Wrapper::template Get<0, 1>(A) = (xy - wz) * f;
1965 Wrapper::template Get<1, 1>(A) = yy * f + s;
1966 Wrapper::template Get<2, 1>(A) = (yz + wx) * f;
1968 Wrapper::template Get<0, 2>(A) = (xz + wy) * f;
1969 Wrapper::template Get<1, 2>(A) = (yz - wx) * f;
1970 Wrapper::template Get<2, 2>(A) = zz * f + s;
1977 vtkQuaternionToMatrix3x3(quat, A);
1983 vtkQuaternionToMatrix3x3(quat, A);
1987 template <
class QuaternionT,
class MatrixT,
class EnableT>
1990 vtkQuaternionToMatrix3x3(q, A);
2000 template <
class MatrixT,
class QuaternionT>
2001 inline void vtkMatrix3x3ToQuaternion(
const MatrixT& A, QuaternionT& quat)
2010 N[0][0] = Wrapper::template Get<0, 0>(A) + Wrapper::template Get<1, 1>(A) +
2011 Wrapper::template Get<2, 2>(A);
2012 N[1][1] = Wrapper::template Get<0, 0>(A) - Wrapper::template Get<1, 1>(A) -
2013 Wrapper::template Get<2, 2>(A);
2014 N[2][2] = -Wrapper::template Get<0, 0>(A) + Wrapper::template Get<1, 1>(A) -
2015 Wrapper::template Get<2, 2>(A);
2016 N[3][3] = -Wrapper::template Get<0, 0>(A) - Wrapper::template Get<1, 1>(A) +
2017 Wrapper::template Get<2, 2>(A);
2020 N[0][1] = N[1][0] = Wrapper::template Get<2, 1>(A) - Wrapper::template Get<1, 2>(A);
2021 N[0][2] = N[2][0] = Wrapper::template Get<0, 2>(A) - Wrapper::template Get<2, 0>(A);
2022 N[0][3] = N[3][0] = Wrapper::template Get<1, 0>(A) - Wrapper::template Get<0, 1>(A);
2024 N[1][2] = N[2][1] = Wrapper::template Get<1, 0>(A) + Wrapper::template Get<0, 1>(A);
2025 N[1][3] = N[3][1] = Wrapper::template Get<0, 2>(A) + Wrapper::template Get<2, 0>(A);
2026 N[2][3] = N[3][2] = Wrapper::template Get<2, 1>(A) + Wrapper::template Get<1, 2>(A);
2028 Scalar eigenvectors[4][4], eigenvalues[4];
2032 Scalar *NTemp[4], *eigenvectorsTemp[4];
2033 for (
int i = 0; i < 4; ++i)
2036 eigenvectorsTemp[i] = eigenvectors[i];
2041 quat[0] = eigenvectors[0][0];
2042 quat[1] = eigenvectors[1][0];
2043 quat[2] = eigenvectors[2][0];
2044 quat[3] = eigenvectors[3][0];
2051 vtkMatrix3x3ToQuaternion(A, quat);
2057 vtkMatrix3x3ToQuaternion(A, quat);
2061 template <
class MatrixT,
class QuaternionT,
class EnableT>
2064 vtkMatrix3x3ToQuaternion(A, q);
2070 template <
typename OutT>
2078 *ret =
static_cast<OutT
>((val >= 0.0) ? (val + 0.5) : (val - 0.5));
2098 *retVal =
static_cast<float>(val);
2103 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
2104 #define VTK_MATH_ISINF_IS_INLINE
2107 #if defined(VTK_HAS_STD_ISINF)
2108 return std::isinf(x);
2110 return (isinf(x) != 0);
2116 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
2117 #define VTK_MATH_ISNAN_IS_INLINE
2120 #if defined(VTK_HAS_STD_ISNAN)
2123 return (
isnan(x) != 0);
2129 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
2130 #define VTK_MATH_ISFINITE_IS_INLINE
2133 #if defined(VTK_HAS_STD_ISFINITE)
2134 return std::isfinite(x);
2135 #elif defined(VTK_HAS_ISFINITE)
2136 return (isfinite(x) != 0);
2138 return (finite(x) != 0);
static void MultiplyScalar2D(float a[2], float s)
Multiplies a 2-vector by a scalar (float version).
static bool IsFinite(double x)
Test if a number has finite value i.e.
static float Dot2D(const float x[2], const float y[2])
Dot product of two 2-vectors.
static float Dot(const float a[3], const float b[3])
Dot product of two 3-vectors (float version).
static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9])
Convert a 6-Component symmetric tensor into a 9-Component tensor, no allocation performed.
abstract base class for most VTK objects
static void LabToXYZ(const double lab[3], double xyz[3])
Convert color from the CIE-L*ab system to CIE XYZ.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Returns true if integer is a power of two.
static void Outer(const double a[3], const double b[3], double c[3][3])
Outer product of two 3-vectors (double version).
void RoundDoubleToIntegralIfNecessary(double val, OutT *ret)
static float Determinant2x2(const float c1[2], const float c2[2])
Compute determinant of 2x2 matrix.
static vtkSmartPointer< vtkMathInternal > Internal
static void QuaternionToMatrix3x3(const float quat[4], float A[3][3])
Convert a quaternion to a 3x3 rotation matrix.
static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
Convert a 3x3 matrix into a quaternion.
static vtkTypeBool IsInf(double x)
Test if a number is equal to the special floating point value infinity.
static ScalarT Dot(const VectorT1 &x, const VectorT2 &y)
Computes the dot product between 2 vectors x and y.
static constexpr double Pi()
A mathematical constant.
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 IsNan(double x)
Test if a number is equal to the special floating point value Not-A-Number (Nan). ...
static int Round(float f)
Rounds a float to the nearest integer.
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 double ClampAndNormalizeValue(double value, const double range[2])
Clamp a value against a range and then normalize it between 0 and 1.
static void Outer(const float a[3], const float b[3], float c[3][3])
Outer product of two 3-vectors (float version).
static void MultiplyMatrixWithVector(const MatrixT &M, const VectorT1 &X, VectorT2 &&Y)
Multiply matrix M with vector Y such that Y = M x X.
static void Add(const double a[3], const double b[3], double c[3])
Addition of two 3-vectors (double version).
static double Dot(const double a[3], const double b[3])
Dot product of two 3-vectors (double version).
static void XYZToRGB(const double xyz[3], double rgb[3])
Convert color from the CIE XYZ system to RGB.
static float Norm2D(const float x[2])
Compute the norm of a 2-vector.
static void UninitializeBounds(double bounds[6])
Set the bounds to an uninitialized state.
double vtkDeterminant3x3(const T A[3][3])
static int NearestPowerOfTwo(int x)
Compute the nearest power of two that is not less than x.
static void RGBToXYZ(const double rgb[3], double xyz[3])
Convert color from the RGB system to CIE XYZ.
static void LinearSolve(const MatrixT &M, const VectorT1 &x, VectorT2 &y)
This method solves linear systems M * x = y.
static T Min(const T &a, const T &b)
Returns the minimum of the two arguments provided.
a simple class to control print indentation
static float Normalize2D(float v[2])
Normalize (in place) a 2-vector.
static void Subtract(const float a[3], const float b[3], float c[3])
Subtraction of two 3-vectors (float version).
static void Subtract(const double a[3], const double b[3], double c[3])
Subtraction of two 3-vectors (double version).
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
static double Determinant3x3(const float A[3][3])
Return the determinant of a 3x3 matrix.
abstract superclass for arrays of numeric data
static ReturnTypeT SquaredNorm(const TupleRangeT &v)
Compute the squared norm of a 3-vector.
static void Convolve1D(Iter1 beginSample, Iter1 endSample, Iter2 beginKernel, Iter2 endKernel, Iter3 beginOut, Iter3 endOut, ConvolutionMode mode=ConvolutionMode::FULL)
Compute the convolution of a sampled 1D signal by a given kernel.
static double Determinant2x2(double a, double b, double c, double d)
Calculate the determinant of a 2x2 matrix: | a b | | c d |.
static float RadiansFromDegrees(float degrees)
Convert degrees into radians.
static void HSVToRGB(const double hsv[3], double rgb[3])
Convert color in HSV format (Hue, Saturation, Value) to RGB format (Red, Green, Blue).
Park and Miller Sequence of pseudo random numbers.
static void MultiplyScalar(double a[3], double s)
Multiplies a 3-vector by a scalar (double version).
static void RGBToLab(const double rgb[3], double lab[3])
Convert color from the RGB system to CIE-L*ab.
static float DegreesFromRadians(float radians)
Convert radians into degrees.
static float Normalize(float v[3])
Normalize (in place) a 3-vector.
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 Outer2D(const float x[2], const float y[2], float A[2][2])
Outer product of two 2-vectors (float version).
static int Ceil(double x)
Rounds a double to the nearest integer not less than itself.
performs common math operations
static double Dot2D(const double x[2], const double y[2])
Dot product of two 2-vectors.
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 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 float Norm(const float v[3])
Compute the norm of 3-vector (float version).
static void MultiplyScalar(float a[3], float s)
Multiplies a 3-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 Subtract(const VectorT1 &a, const VectorT2 &b, VectorT3 &&c)
Subtraction of two 3-vectors (templated version).
static T ClampValue(const T &value, const T &min, const T &max)
Clamp some value against a range, return the result.
static double Norm2D(const double x[2])
Compute the norm of a 2-vector.
static void InvertMatrix(const MatrixT1 &M1, MatrixT2 &&M2)
Computes the inverse of input matrix M1 into M2.
static int Round(double f)
static ReturnTypeT Dot(const TupleRangeT1 &a, const TupleRangeT2 &b)
Compute dot product between two points p1 and p2.
static double Norm(const double v[3])
Compute the norm of 3-vector (double version).
static void MultiplyScalar2D(double a[2], double s)
Multiplies a 2-vector by a scalar (double version).
static void LabToRGB(const double lab[3], double rgb[3])
Convert color from the CIE-L*ab system to RGB.
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
static float Norm(const float *x, int n)
Compute the norm of n-vector.
static void Cross(const float a[3], const float b[3], float c[3])
Cross product of two 3-vectors.
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 ReturnTypeT Distance2BetweenPoints(const TupleRangeT1 &p1, const TupleRangeT2 &p2)
Compute distance squared between two points p1 and p2.
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
static double Determinant2x2(const double c1[2], const double c2[2])
Calculate the determinant of a 2x2 matrix: | a b | | c d |.
static void Add(const float a[3], const float b[3], float c[3])
Addition of two 3-vectors (float version).
static void MultiplyMatrix(const MatrixT1 &M1, const MatrixT2 &M2, MatrixT3 &&M3)
Multiply matrices such that M3 = M1 x M2.
Template defining traits of native types used by VTK.
static vtkTypeBool AreBoundsInitialized(const double bounds[6])
Are the bounds initialized?
represent and manipulate 3D points
static void Assign(const VectorT1 &a, VectorT2 &&b)
Assign values to a 3-vector (templated version).
static T Max(const T &a, const T &b)
Returns the maximum of the two arguments provided.
static vtkMatrixUtilities::ScalarTypeExtractor< MatrixT >::value_type Determinant(const MatrixT &M)
Computes the determinant of input square SizeT x SizeT matrix M.
static void Assign(const double a[3], double b[3])
Assign values to a 3-vector (double version).
static void XYZToLab(const double xyz[3], double lab[3])
Convert Color from the CIE XYZ system to CIE-L*ab.