VTK  9.7.20261201
vtkMath.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright 2011 Sandia Corporation
3// SPDX-License-Identifier: LicenseRef-BSD-3-Clause-Sandia-USGov
132
133#ifndef vtkMath_h
134#define vtkMath_h
135
136#include "vtkCommonCoreModule.h" // For export macro
137#include "vtkMathPrivate.hxx" // For Matrix meta-class helpers
138#include "vtkMatrixUtilities.h" // For Matrix wrapping / mapping
139#include "vtkObject.h"
140#include "vtkSmartPointer.h" // For vtkSmartPointer.
141#include "vtkTypeTraits.h" // For type traits
142
143#include "vtkMathConfigure.h" // For <cmath> and VTK_HAS_ISNAN etc.
144
145#include <algorithm> // for std::clamp
146#include <cassert> // assert() in inline implementations.
147#include <type_traits> // for type_traits
148
149#ifndef DBL_MIN
150#define VTK_DBL_MIN 2.2250738585072014e-308
151#else // DBL_MIN
152#define VTK_DBL_MIN DBL_MIN
153#endif // DBL_MIN
154
155#ifndef DBL_EPSILON
156#define VTK_DBL_EPSILON 2.2204460492503131e-16
157#else // DBL_EPSILON
158#define VTK_DBL_EPSILON DBL_EPSILON
159#endif // DBL_EPSILON
160
161#ifndef VTK_DBL_EPSILON
162#ifndef DBL_EPSILON
163#define VTK_DBL_EPSILON 2.2204460492503131e-16
164#else // DBL_EPSILON
165#define VTK_DBL_EPSILON DBL_EPSILON
166#endif // DBL_EPSILON
167#endif // VTK_DBL_EPSILON
168
169VTK_ABI_NAMESPACE_BEGIN
170class vtkDataArray;
171class vtkPoints;
172class vtkMathInternal;
175VTK_ABI_NAMESPACE_END
176
177namespace vtk_detail
178{
179VTK_ABI_NAMESPACE_BEGIN
180// forward declaration
181template <typename OutT>
182void RoundDoubleToIntegralIfNecessary(double val, OutT* ret);
183VTK_ABI_NAMESPACE_END
184} // end namespace vtk_detail
185
186VTK_ABI_NAMESPACE_BEGIN
187class VTKCOMMONCORE_EXPORT vtkMath : public vtkObject
188{
189public:
190 static vtkMath* New();
191 vtkTypeMacro(vtkMath, vtkObject);
192 void PrintSelf(ostream& os, vtkIndent indent) override;
193
194private:
195 template <class VectorT, class = void>
196 struct VectorImplementsSize : std::false_type
197 {
198 };
199
200 template <class VectorT>
201 struct VectorImplementsSize<VectorT, decltype((void)std::declval<VectorT>().size(), void())>
202 : std::true_type
203 {
204 };
205
209 template <class VectorT>
210 using EnableIfVectorImplementsSize =
211 typename std::enable_if<VectorImplementsSize<VectorT>::value>::type;
212
213public:
222 static constexpr int DYNAMIC_VECTOR_SIZE() { return 0; }
223
227 static constexpr double Pi() { return 3.141592653589793; }
228
230
233 static float RadiansFromDegrees(float degrees);
234 static double RadiansFromDegrees(double degrees);
236
238
241 static float DegreesFromRadians(float radians);
242 static double DegreesFromRadians(double radians);
244
248#if 1
249 static int Round(float f) { return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
250 static int Round(double f) { return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
251#endif
252
257 template <typename OutT>
258 static void RoundDoubleToIntegralIfNecessary(double val, OutT* ret)
259 {
260 // Can't specialize template methods in a template class, so we move the
261 // implementations to a external namespace.
263 }
264
270 static int Floor(double x);
271
277 static int Ceil(double x);
278
284 static int CeilLog2(vtkTypeUInt64 x);
285
290 template <class T>
291 static T Min(const T& a, const T& b);
292
297 template <class T>
298 static T Max(const T& a, const T& b);
299
307 static double JacobiPolynomial(int nn, double alpha, double beta, double xx);
308
313 static double JacobiPolynomialDerivative(int nn, double alpha, double beta, double xx);
314
318 static bool IsPowerOfTwo(vtkTypeUInt64 x);
319
325 static int NearestPowerOfTwo(int x);
326
331 static vtkTypeInt64 Factorial(int N);
332
334
347 static vtkTypeInt64 Binomial(int m, int n);
348 static double DoubleBinomial(int m, int n);
350
354 static double RealBinomial(double mm, int nn);
355
367 static int* BeginCombination(int m, int n);
368
379 static int NextCombination(int m, int n, int* combination);
380
384 static void FreeCombination(int* combination);
385
401 static void RandomSeed(int s);
402
414 static int GetSeed();
415
429 static double Random();
430
443 static double Random(double min, double max);
444
457 static double Gaussian();
458
471 static double Gaussian(double mean, double std);
472
477 template <class VectorT1, class VectorT2>
478 static void Assign(const VectorT1& a, VectorT2&& b)
479 {
480 b[0] = a[0];
481 b[1] = a[1];
482 b[2] = a[2];
483 }
484
488 static void Assign(const double a[3], double b[3]) { vtkMath::Assign<>(a, b); }
489
493 static void Add(const float a[3], const float b[3], float c[3])
494 {
495 for (int i = 0; i < 3; ++i)
496 {
497 c[i] = a[i] + b[i];
498 }
499 }
500
504 static void Add(const double a[3], const double b[3], double c[3])
505 {
506 for (int i = 0; i < 3; ++i)
507 {
508 c[i] = a[i] + b[i];
509 }
510 }
511
517 template <class VectorT1, class VectorT2, class VectorT3>
518 static void Add(VectorT1&& a, VectorT2&& b, VectorT3& c)
519 {
520 for (int i = 0; i < 3; ++i)
521 {
522 c[i] = a[i] + b[i];
523 }
524 }
525
529 static void Subtract(const float a[3], const float b[3], float c[3])
530 {
531 for (int i = 0; i < 3; ++i)
532 {
533 c[i] = a[i] - b[i];
534 }
535 }
536
540 static void Subtract(const double a[3], const double b[3], double c[3])
541 {
542 for (int i = 0; i < 3; ++i)
543 {
544 c[i] = a[i] - b[i];
545 }
546 }
547
553 template <class VectorT1, class VectorT2, class VectorT3>
554 static void Subtract(const VectorT1& a, const VectorT2& b, VectorT3&& c)
555 {
556 c[0] = a[0] - b[0];
557 c[1] = a[1] - b[1];
558 c[2] = a[2] - b[2];
559 }
560
565 static void MultiplyScalar(float a[3], float s)
566 {
567 for (int i = 0; i < 3; ++i)
568 {
569 a[i] *= s;
570 }
571 }
572
577 static void MultiplyScalar2D(float a[2], float s)
578 {
579 for (int i = 0; i < 2; ++i)
580 {
581 a[i] *= s;
582 }
583 }
584
589 static void MultiplyScalar(double a[3], double s)
590 {
591 for (int i = 0; i < 3; ++i)
592 {
593 a[i] *= s;
594 }
595 }
596
601 static void MultiplyScalar2D(double a[2], double s)
602 {
603 for (int i = 0; i < 2; ++i)
604 {
605 a[i] *= s;
606 }
607 }
608
612 static float Dot(const float a[3], const float b[3])
613 {
614 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
615 }
616
620 static double Dot(const double a[3], const double b[3])
621 {
622 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
623 }
624
640 template <typename ReturnTypeT = double, typename TupleRangeT1, typename TupleRangeT2,
641 typename EnableT = typename std::conditional<!std::is_pointer<TupleRangeT1>::value &&
642 !std::is_array<TupleRangeT1>::value,
643 TupleRangeT1, TupleRangeT2>::type::value_type>
644 static ReturnTypeT Dot(const TupleRangeT1& a, const TupleRangeT2& b)
645 {
646 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
647 }
648
652 static void Outer(const float a[3], const float b[3], float c[3][3])
653 {
654 for (int i = 0; i < 3; ++i)
655 {
656 for (int j = 0; j < 3; ++j)
657 {
658 c[i][j] = a[i] * b[j];
659 }
660 }
661 }
662
666 static void Outer(const double a[3], const double b[3], double c[3][3])
667 {
668 for (int i = 0; i < 3; ++i)
669 {
670 for (int j = 0; j < 3; ++j)
671 {
672 c[i][j] = a[i] * b[j];
673 }
674 }
675 }
676
682 template <class VectorT1, class VectorT2, class VectorT3>
683 static void Cross(VectorT1&& a, VectorT2&& b, VectorT3& c);
684
689 static void Cross(const float a[3], const float b[3], float c[3]);
690
695 static void Cross(const double a[3], const double b[3], double c[3]);
696
698
701 static float Norm(const float* x, int n);
702 static double Norm(const double* x, int n);
704
708 static float Norm(const float v[3]) { return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); }
709
713 static double Norm(const double v[3])
714 {
715 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
716 }
717
727 template <typename ReturnTypeT = double, typename TupleRangeT>
728 static ReturnTypeT SquaredNorm(const TupleRangeT& v)
729 {
730 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
731 }
732
737 static inline float Normalize(float v[3]);
738
743 static inline double Normalize(double v[3]);
744
746
753 static void Perpendiculars(const double v1[3], double v2[3], double v3[3], double theta);
754 static void Perpendiculars(const float v1[3], float v2[3], float v3[3], double theta);
756
758
763 static bool ProjectVector(const float a[3], const float b[3], float projection[3]);
764 static bool ProjectVector(const double a[3], const double b[3], double projection[3]);
766
768
774 static bool ProjectVector2D(const float a[2], const float b[2], float projection[2]);
775 static bool ProjectVector2D(const double a[2], const double b[2], double projection[2]);
777
793 template <typename ReturnTypeT = double, typename TupleRangeT1, typename TupleRangeT2,
794 typename EnableT = typename std::conditional<!std::is_pointer<TupleRangeT1>::value &&
795 !std::is_array<TupleRangeT1>::value,
796 TupleRangeT1, TupleRangeT2>::type::value_type>
797 static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1& p1, const TupleRangeT2& p2);
798
803 static float Distance2BetweenPoints(const float p1[3], const float p2[3]);
804
809 static double Distance2BetweenPoints(const double p1[3], const double p2[3]);
810
815 static double Distance2BetweenPoints2D(const double p1[2], const double p2[2]);
816
820 static double AngleBetweenVectors(const double v1[3], const double v2[3]);
821
826 const double v1[3], const double v2[3], const double vn[3]);
827
832 static double GaussianAmplitude(double variance, double distanceFromMean);
833
838 static double GaussianAmplitude(double mean, double variance, double position);
839
845 static double GaussianWeight(double variance, double distanceFromMean);
846
852 static double GaussianWeight(double mean, double variance, double position);
853
857 static float Dot2D(const float x[2], const float y[2]) { return x[0] * y[0] + x[1] * y[1]; }
858
862 static double Dot2D(const double x[2], const double y[2]) { return x[0] * y[0] + x[1] * y[1]; }
863
867 static void Outer2D(const float x[2], const float y[2], float A[2][2])
868 {
869 for (int i = 0; i < 2; ++i)
870 {
871 for (int j = 0; j < 2; ++j)
872 {
873 A[i][j] = x[i] * y[j];
874 }
875 }
876 }
877
881 static void Outer2D(const double x[2], const double y[2], double A[2][2])
882 {
883 for (int i = 0; i < 2; ++i)
884 {
885 for (int j = 0; j < 2; ++j)
886 {
887 A[i][j] = x[i] * y[j];
888 }
889 }
890 }
891
896 static float Norm2D(const float x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
897
902 static double Norm2D(const double x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
903
908 static float Normalize2D(float v[2]);
909
914 static double Normalize2D(double v[2]);
915
919 static float Determinant2x2(const float c1[2], const float c2[2])
920 {
921 return c1[0] * c2[1] - c2[0] * c1[1];
922 }
923
925
928 static double Determinant2x2(double a, double b, double c, double d) { return a * d - b * c; }
929 static double Determinant2x2(const double c1[2], const double c2[2])
930 {
931 return c1[0] * c2[1] - c2[0] * c1[1];
932 }
933
934
936
939 static void LUFactor3x3(float A[3][3], int index[3]);
940 static void LUFactor3x3(double A[3][3], int index[3]);
942
944
947 static void LUSolve3x3(const float A[3][3], const int index[3], float x[3]);
948 static void LUSolve3x3(const double A[3][3], const int index[3], double x[3]);
950
952
956 static void LinearSolve3x3(const float A[3][3], const float x[3], float y[3]);
957 static void LinearSolve3x3(const double A[3][3], const double x[3], double y[3]);
959
968 static bool LinearSolveTransposed3x3(const double A[3][3], const double x[3], double y[3]);
969
971
974 static void Multiply3x3(const float A[3][3], const float v[3], float u[3]);
975 static void Multiply3x3(const double A[3][3], const double v[3], double u[3]);
977
979
982 static void Multiply3x3(const float A[3][3], const float B[3][3], float C[3][3]);
983 static void Multiply3x3(const double A[3][3], const double B[3][3], double C[3][3]);
985
1009 template <int RowsT, int MidDimT, int ColsT,
1010 class LayoutT1 = vtkMatrixUtilities::Layout::Identity,
1011 class LayoutT2 = vtkMatrixUtilities::Layout::Identity, class MatrixT1, class MatrixT2,
1012 class MatrixT3>
1013 static void MultiplyMatrix(MatrixT1&& M1, MatrixT2&& M2, MatrixT3&& M3)
1014 {
1015 vtkMathPrivate::MultiplyMatrix<RowsT, MidDimT, ColsT, LayoutT1, LayoutT2>::Compute(
1016 std::forward<MatrixT1>(M1), std::forward<MatrixT2>(M2), std::forward<MatrixT3>(M3));
1017 }
1018
1039 template <int RowsT, int ColsT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
1040 class MatrixT, class VectorT1, class VectorT2>
1041 static void MultiplyMatrixWithVector(MatrixT&& M, VectorT1&& X, VectorT2&& Y)
1042 {
1043 vtkMathPrivate::MultiplyMatrix<RowsT, ColsT, 1, LayoutT>::Compute(
1044 std::forward<MatrixT>(M), std::forward<VectorT1>(X), std::forward<VectorT2>(Y));
1045 }
1046
1052 template <class ScalarT, int SizeT, class VectorT1, class VectorT2,
1053 class = typename std::enable_if<SizeT != DYNAMIC_VECTOR_SIZE()>::type>
1054 static ScalarT Dot(VectorT1&& x, VectorT2&& y)
1055 {
1056 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
1057 vtkMatrixUtilities::Layout::Identity,
1058 vtkMatrixUtilities::Layout::Transpose>::Compute(std::forward<VectorT1>(x),
1059 std::forward<VectorT2>(y));
1060 }
1061
1068 template <class ScalarT, int SizeT, class VectorT1, class VectorT2,
1069 class = typename std::enable_if<SizeT == DYNAMIC_VECTOR_SIZE()>::type,
1070 class = EnableIfVectorImplementsSize<VectorT1>>
1071 static ScalarT Dot(VectorT1&& x, VectorT2&& y)
1072 {
1073 ScalarT dot = 0.0;
1074 using SizeType = decltype(std::declval<VectorT1>().size());
1075 for (SizeType dim = 0; dim < x.size(); ++dim)
1076 {
1077 dot += x[dim] * y[dim];
1078 }
1079 return dot;
1080 }
1081
1089 template <int SizeT, class VectorT>
1091 VectorT&& x)
1092 {
1094 return vtkMath::Dot<Scalar, SizeT>(std::forward<VectorT>(x), std::forward<VectorT>(x));
1095 }
1096
1113 template <int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity, class MatrixT>
1115 MatrixT&& M)
1116 {
1117 return vtkMathPrivate::Determinant<SizeT, LayoutT>::Compute(std::forward<MatrixT>(M));
1118 }
1119
1135 template <int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity, class MatrixT1,
1136 class MatrixT2>
1137 static void InvertMatrix(MatrixT1&& M1, MatrixT2&& M2)
1138 {
1139 vtkMathPrivate::InvertMatrix<SizeT, LayoutT>::Compute(
1140 std::forward<MatrixT1>(M1), std::forward<MatrixT2>(M2));
1141 }
1142
1156 template <int RowsT, int ColsT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
1157 class MatrixT, class VectorT1, class VectorT2>
1158 static void LinearSolve(MatrixT&& M, VectorT1&& x, VectorT2&& y)
1159 {
1160 vtkMathPrivate::LinearSolve<RowsT, ColsT, LayoutT>::Compute(
1161 std::forward<MatrixT>(M), std::forward<VectorT1>(x), std::forward<VectorT2>(y));
1162 }
1163
1178 template <class ScalarT, int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
1179 class VectorT1, class MatrixT, class VectorT2,
1180 class = typename std::enable_if<SizeT != DYNAMIC_VECTOR_SIZE()>::type>
1181 static ScalarT Dot(VectorT1&& x, MatrixT&& M, VectorT2&& y)
1182 {
1183 ScalarT tmp[SizeT];
1184 vtkMathPrivate::MultiplyMatrix<SizeT, SizeT, 1, LayoutT>::Compute(
1185 std::forward<MatrixT>(M), std::forward<VectorT2>(y), tmp);
1186 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
1187 vtkMatrixUtilities::Layout::Identity,
1188 vtkMatrixUtilities::Layout::Transpose>::Compute(std::forward<VectorT1>(x), tmp);
1189 }
1190
1196 static void MultiplyMatrix(const double* const* A, const double* const* B, unsigned int rowA,
1197 unsigned int colA, unsigned int rowB, unsigned int colB, double** C);
1198
1200
1204 static void Transpose3x3(const float A[3][3], float AT[3][3]);
1205 static void Transpose3x3(const double A[3][3], double AT[3][3]);
1207
1209
1213 static void Invert3x3(const float A[3][3], float AI[3][3]);
1214 static void Invert3x3(const double A[3][3], double AI[3][3]);
1216
1218
1221 static void Identity3x3(float A[3][3]);
1222 static void Identity3x3(double A[3][3]);
1224
1226
1229 static double Determinant3x3(const float A[3][3]);
1230 static double Determinant3x3(const double A[3][3]);
1232
1236 static float Determinant3x3(const float c1[3], const float c2[3], const float c3[3]);
1237
1241 static double Determinant3x3(const double c1[3], const double c2[3], const double c3[3]);
1242
1249 static double Determinant3x3(double a1, double a2, double a3, double b1, double b2, double b3,
1250 double c1, double c2, double c3);
1251
1253
1260 static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
1261 static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
1262 template <class QuaternionT, class MatrixT,
1263 class EnableT = typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::type>
1264 static void QuaternionToMatrix3x3(QuaternionT&& q, MatrixT&& A);
1266
1268
1277 static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
1278 static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
1279 template <class MatrixT, class QuaternionT,
1280 class EnableT = typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::type>
1281 static void Matrix3x3ToQuaternion(MatrixT&& A, QuaternionT&& q);
1283
1285
1291 static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4]);
1292 static void MultiplyQuaternion(const double q1[4], const double q2[4], double q[4]);
1294
1296
1300 static void RotateVectorByNormalizedQuaternion(const float v[3], const float q[4], float r[3]);
1301 static void RotateVectorByNormalizedQuaternion(const double v[3], const double q[4], double r[3]);
1303
1305
1309 static void RotateVectorByWXYZ(const float v[3], const float q[4], float r[3]);
1310 static void RotateVectorByWXYZ(const double v[3], const double q[4], double r[3]);
1312
1314
1319 static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
1320 static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
1322
1324
1330 static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
1331 static void Diagonalize3x3(const double A[3][3], double w[3], double V[3][3]);
1333
1335
1345 const float A[3][3], float U[3][3], float w[3], float VT[3][3]);
1347 const double A[3][3], double U[3][3], double w[3], double VT[3][3]);
1349
1358 double a00, double a01, double a10, double a11, double b0, double b1, double& x0, double& x1);
1359
1368 static vtkTypeBool SolveLinearSystem(double** A, double* x, int size);
1369
1376 static vtkTypeBool InvertMatrix(double** A, double** AI, int size);
1377
1384 double** A, double** AI, int size, int* tmp1Size, double* tmp2Size);
1385
1408 static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size);
1409
1415 static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size, double* tmpSize);
1416
1425 static void LUSolveLinearSystem(double** A, int* index, double* x, int size);
1426
1435 static double EstimateMatrixCondition(const double* const* A, int size);
1436
1438
1446 static vtkTypeBool Jacobi(float** a, float* w, float** v);
1447 static vtkTypeBool Jacobi(double** a, double* w, double** v);
1449
1451
1460 static vtkTypeBool JacobiN(float** a, int n, float* w, float** v);
1461 static vtkTypeBool JacobiN(double** a, int n, double* w, double** v);
1463
1478 int numberOfSamples, double** xt, int xOrder, double** mt);
1479
1494 static vtkTypeBool SolveLeastSquares(int numberOfSamples, double** xt, int xOrder, double** yt,
1495 int yOrder, double** mt, int checkHomogeneous = 1);
1496
1498
1505 static void RGBToHSV(const float rgb[3], float hsv[3])
1506 {
1507 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1508 }
1509 static void RGBToHSV(float r, float g, float b, float* h, float* s, float* v);
1510 static void RGBToHSV(const double rgb[3], double hsv[3])
1511 {
1512 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1513 }
1514 static void RGBToHSV(double r, double g, double b, double* h, double* s, double* v);
1516
1518
1525 static void HSVToRGB(const float hsv[3], float rgb[3])
1526 {
1527 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1528 }
1529 static void HSVToRGB(float h, float s, float v, float* r, float* g, float* b);
1530 static void HSVToRGB(const double hsv[3], double rgb[3])
1531 {
1532 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1533 }
1534 static void HSVToRGB(double h, double s, double v, double* r, double* g, double* b);
1536
1538
1542 static void ProLabToXYZ(const double prolab[3], double xyz[3])
1543 {
1544 ProLabToXYZ(prolab[0], prolab[1], prolab[2], xyz + 0, xyz + 1, xyz + 2);
1545 }
1546 static void ProLabToXYZ(double L, double a, double b, double* x, double* y, double* z);
1548
1550
1554 static void XYZToProLab(const double xyz[3], double prolab[3])
1555 {
1556 XYZToProLab(xyz[0], xyz[1], xyz[2], prolab + 0, prolab + 1, prolab + 2);
1557 }
1558 static void XYZToProLab(double x, double y, double z, double* L, double* a, double* b);
1560
1562
1565 static void LabToXYZ(const double lab[3], double xyz[3])
1566 {
1567 LabToXYZ(lab[0], lab[1], lab[2], xyz + 0, xyz + 1, xyz + 2);
1568 }
1569 static void LabToXYZ(double L, double a, double b, double* x, double* y, double* z);
1571
1573
1576 static void XYZToLab(const double xyz[3], double lab[3])
1577 {
1578 XYZToLab(xyz[0], xyz[1], xyz[2], lab + 0, lab + 1, lab + 2);
1579 }
1580 static void XYZToLab(double x, double y, double z, double* L, double* a, double* b);
1582
1584
1587 static void XYZToRGB(const double xyz[3], double rgb[3])
1588 {
1589 XYZToRGB(xyz[0], xyz[1], xyz[2], rgb + 0, rgb + 1, rgb + 2);
1590 }
1591 static void XYZToRGB(double x, double y, double z, double* r, double* g, double* b);
1593
1595
1598 static void RGBToXYZ(const double rgb[3], double xyz[3])
1599 {
1600 RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz + 0, xyz + 1, xyz + 2);
1601 }
1602 static void RGBToXYZ(double r, double g, double b, double* x, double* y, double* z);
1604
1606
1612
1613 static void RGBToLab(const double rgb[3], double lab[3])
1614 {
1615 RGBToLab(rgb[0], rgb[1], rgb[2], lab + 0, lab + 1, lab + 2);
1616 }
1617 static void RGBToLab(double red, double green, double blue, double* L, double* a, double* b);
1619
1621
1624 static void ProLabToRGB(const double prolab[3], double rgb[3])
1625 {
1626 ProLabToRGB(prolab[0], prolab[1], prolab[2], rgb + 0, rgb + 1, rgb + 2);
1627 }
1628 static void ProLabToRGB(double L, double a, double b, double* red, double* green, double* blue);
1630
1632
1639 static void RGBToProLab(const double rgb[3], double prolab[3])
1640 {
1641 RGBToProLab(rgb[0], rgb[1], rgb[2], prolab + 0, prolab + 1, prolab + 2);
1642 }
1643 static void RGBToProLab(double red, double green, double blue, double* L, double* a, double* b);
1645
1647
1650 static void LabToRGB(const double lab[3], double rgb[3])
1651 {
1652 LabToRGB(lab[0], lab[1], lab[2], rgb + 0, rgb + 1, rgb + 2);
1653 }
1654 static void LabToRGB(double L, double a, double b, double* red, double* green, double* blue);
1656
1658
1661 static void UninitializeBounds(double bounds[6])
1662 {
1663 bounds[0] = 1.0;
1664 bounds[1] = -1.0;
1665 bounds[2] = 1.0;
1666 bounds[3] = -1.0;
1667 bounds[4] = 1.0;
1668 bounds[5] = -1.0;
1669 }
1670
1671
1673
1676 static vtkTypeBool AreBoundsInitialized(const double bounds[6])
1677 {
1678 if (bounds[1] - bounds[0] < 0.0)
1679 {
1680 return 0;
1681 }
1682 return 1;
1683 }
1684
1685
1690 template <class T>
1691 static T ClampValue(const T& value, const T& min, const T& max);
1692
1694
1698 static void ClampValue(double* value, const double range[2]);
1699 static void ClampValue(double value, const double range[2], double* clamped_value);
1700 static void ClampValues(double* values, int nb_values, const double range[2]);
1701 static void ClampValues(
1702 const double* values, int nb_values, const double range[2], double* clamped_values);
1704
1711 static double ClampAndNormalizeValue(double value, const double range[2]);
1712
1717 template <class T1, class T2>
1718 static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9]);
1719
1725 template <class T>
1726 static void TensorFromSymmetricTensor(T tensor[9]);
1727
1737 double range_min, double range_max, double scale = 1.0, double shift = 0.0);
1738
1747 static vtkTypeBool GetAdjustedScalarRange(vtkDataArray* array, int comp, double range[2]);
1748
1753 static vtkTypeBool ExtentIsWithinOtherExtent(const int extent1[6], const int extent2[6]);
1754
1761 const double bounds1[6], const double bounds2[6], const double delta[3]);
1762
1769 const double point[3], const double bounds[6], const double delta[3]);
1770
1781 const double bounds[6], const double normal[3], const double point[3]);
1782
1792 static double Solve3PointCircle(
1793 const double p1[3], const double p2[3], const double p3[3], double center[3]);
1794
1798 static double Inf();
1799
1803 static double NegInf();
1804
1808 static double Nan();
1809
1813 static vtkTypeBool IsInf(double x);
1814
1818 static inline vtkTypeBool IsNan(double x);
1819
1824 static bool IsFinite(double x);
1825
1830 static int QuadraticRoot(double a, double b, double c, double min, double max, double* u);
1831
1837 static vtkIdType ComputeGCD(vtkIdType m, vtkIdType n) { return (n ? ComputeGCD(n, m % n) : m); }
1838
1843 {
1844 FULL,
1845 SAME,
1846 VALID
1847 };
1848
1871 template <class Iter1, class Iter2, class Iter3>
1872 static void Convolve1D(Iter1 beginSample, Iter1 endSample, Iter2 beginKernel, Iter2 endKernel,
1873 Iter3 beginOut, Iter3 endOut, ConvolutionMode mode = ConvolutionMode::FULL)
1874 {
1875 int sampleSize = std::distance(beginSample, endSample);
1876 int kernelSize = std::distance(beginKernel, endKernel);
1877 int outSize = std::distance(beginOut, endOut);
1878
1879 if (sampleSize <= 0 || kernelSize <= 0 || outSize <= 0)
1880 {
1881 return;
1882 }
1883
1884 int begin = 0;
1885 int end = outSize;
1886
1887 switch (mode)
1888 {
1890 begin = static_cast<int>(std::ceil((std::min)(sampleSize, kernelSize) / 2.0)) - 1;
1891 end = begin + (std::max)(sampleSize, kernelSize);
1892 break;
1894 begin = (std::min)(sampleSize, kernelSize) - 1;
1895 end = begin + std::abs(sampleSize - kernelSize) + 1;
1896 break;
1898 default:
1899 break;
1900 }
1901
1902 for (int i = begin; i < end; i++)
1903 {
1904 Iter3 out = beginOut + i - begin;
1905 *out = 0;
1906 for (int j = (std::max)(i - sampleSize + 1, 0); j <= (std::min)(i, kernelSize - 1); j++)
1907 {
1908 *out += *(beginSample + (i - j)) * *(beginKernel + j);
1909 }
1910 }
1911 }
1912
1917 static void GetPointAlongLine(double result[3], double p1[3], double p2[3], const double offset)
1918 {
1919 double directionVector[3] = { p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2] };
1920 vtkMath::Normalize(directionVector);
1921 result[0] = p2[0] + (offset * directionVector[0]);
1922 result[1] = p2[1] + (offset * directionVector[1]);
1923 result[2] = p2[2] + (offset * directionVector[2]);
1924 }
1925
1926protected:
1927 vtkMath() = default;
1928 ~vtkMath() override = default;
1929
1931
1932private:
1933 vtkMath(const vtkMath&) = delete;
1934 void operator=(const vtkMath&) = delete;
1935};
1936
1937//----------------------------------------------------------------------------
1938inline float vtkMath::RadiansFromDegrees(float x)
1939{
1940 return x * 0.017453292f;
1941}
1942
1943//----------------------------------------------------------------------------
1944inline double vtkMath::RadiansFromDegrees(double x)
1945{
1946 return x * 0.017453292519943295;
1947}
1948
1949//----------------------------------------------------------------------------
1950inline float vtkMath::DegreesFromRadians(float x)
1951{
1952 return x * 57.2957795131f;
1953}
1954
1955//----------------------------------------------------------------------------
1956inline double vtkMath::DegreesFromRadians(double x)
1957{
1958 return x * 57.29577951308232;
1959}
1960
1961//----------------------------------------------------------------------------
1962inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
1963{
1964 return ((x != 0) & ((x & (x - 1)) == 0));
1965}
1966
1967//----------------------------------------------------------------------------
1968// Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1970{
1971 unsigned int z = static_cast<unsigned int>(((x > 0) ? x - 1 : 0));
1972 z |= z >> 1;
1973 z |= z >> 2;
1974 z |= z >> 4;
1975 z |= z >> 8;
1976 z |= z >> 16;
1977 return static_cast<int>(z + 1);
1978}
1979
1980//----------------------------------------------------------------------------
1981// Modify the trunc() operation provided by static_cast<int>() to get floor(),
1982// Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1983inline int vtkMath::Floor(double x)
1984{
1985 int i = static_cast<int>(x);
1986 return i - (i > x);
1987}
1988
1989//----------------------------------------------------------------------------
1990// Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1991// Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1992inline int vtkMath::Ceil(double x)
1993{
1994 int i = static_cast<int>(x);
1995 return i + (i < x);
1996}
1997
1998//----------------------------------------------------------------------------
1999template <class T>
2000inline T vtkMath::Min(const T& a, const T& b)
2001{
2002 return (b <= a ? b : a);
2003}
2004
2005//----------------------------------------------------------------------------
2006template <class T>
2007inline T vtkMath::Max(const T& a, const T& b)
2008{
2009 return (b > a ? b : a);
2010}
2011
2012//----------------------------------------------------------------------------
2013float vtkMath::Normalize(float v[3])
2014{
2015 float den = vtkMath::Norm(v);
2016 if (den != 0.0)
2017 {
2018 for (int i = 0; i < 3; ++i)
2019 {
2020 v[i] /= den;
2021 }
2022 }
2023 return den;
2024}
2025
2026//----------------------------------------------------------------------------
2027double vtkMath::Normalize(double v[3])
2028{
2029 double den = vtkMath::Norm(v);
2030 if (den != 0.0)
2031 {
2032 for (int i = 0; i < 3; ++i)
2033 {
2034 v[i] /= den;
2035 }
2036 }
2037 return den;
2038}
2039
2040//----------------------------------------------------------------------------
2041inline float vtkMath::Normalize2D(float v[2])
2042{
2043 float den = vtkMath::Norm2D(v);
2044 if (den != 0.0)
2045 {
2046 for (int i = 0; i < 2; ++i)
2047 {
2048 v[i] /= den;
2049 }
2050 }
2051 return den;
2052}
2053
2054//----------------------------------------------------------------------------
2055inline double vtkMath::Normalize2D(double v[2])
2056{
2057 double den = vtkMath::Norm2D(v);
2058 if (den != 0.0)
2059 {
2060 for (int i = 0; i < 2; ++i)
2061 {
2062 v[i] /= den;
2063 }
2064 }
2065 return den;
2066}
2067
2068//----------------------------------------------------------------------------
2069inline float vtkMath::Determinant3x3(const float c1[3], const float c2[3], const float c3[3])
2070{
2071 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
2072 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
2073}
2074
2075//----------------------------------------------------------------------------
2076inline double vtkMath::Determinant3x3(const double c1[3], const double c2[3], const double c3[3])
2077{
2078 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
2079 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
2080}
2081
2082//----------------------------------------------------------------------------
2084 double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3)
2085{
2086 return (a1 * vtkMath::Determinant2x2(b2, b3, c2, c3) -
2087 b1 * vtkMath::Determinant2x2(a2, a3, c2, c3) + c1 * vtkMath::Determinant2x2(a2, a3, b2, b3));
2088}
2089
2090//----------------------------------------------------------------------------
2091inline float vtkMath::Distance2BetweenPoints(const float p1[3], const float p2[3])
2092{
2093 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
2094 (p1[2] - p2[2]) * (p1[2] - p2[2]));
2095}
2096
2097//----------------------------------------------------------------------------
2098inline double vtkMath::Distance2BetweenPoints(const double p1[3], const double p2[3])
2099{
2100 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
2101 (p1[2] - p2[2]) * (p1[2] - p2[2]));
2102}
2103
2104//----------------------------------------------------------------------------
2105template <typename ReturnTypeT, typename TupleRangeT1, typename TupleRangeT2, typename EnableT>
2106inline ReturnTypeT vtkMath::Distance2BetweenPoints(const TupleRangeT1& p1, const TupleRangeT2& p2)
2107{
2108 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
2109 (p1[2] - p2[2]) * (p1[2] - p2[2]));
2110}
2111
2112//------------------------------------------------------------------------------
2113inline double vtkMath::Distance2BetweenPoints2D(const double p1[2], const double p2[2])
2114{
2115 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]));
2116}
2117
2118//----------------------------------------------------------------------------
2119template <class VectorT1, class VectorT2, class VectorT3>
2120void vtkMath::Cross(VectorT1&& a, VectorT2&& b, VectorT3& c)
2121{
2123 ValueType Cx = a[1] * b[2] - a[2] * b[1];
2124 ValueType Cy = a[2] * b[0] - a[0] * b[2];
2125 ValueType Cz = a[0] * b[1] - a[1] * b[0];
2126 c[0] = Cx;
2127 c[1] = Cy;
2128 c[2] = Cz;
2129}
2130
2131//----------------------------------------------------------------------------
2132// Cross product of two 3-vectors. Result (a x b) is stored in c[3].
2133inline void vtkMath::Cross(const float a[3], const float b[3], float c[3])
2134{
2135 float Cx = a[1] * b[2] - a[2] * b[1];
2136 float Cy = a[2] * b[0] - a[0] * b[2];
2137 float Cz = a[0] * b[1] - a[1] * b[0];
2138 c[0] = Cx;
2139 c[1] = Cy;
2140 c[2] = Cz;
2141}
2142
2143//----------------------------------------------------------------------------
2144// Cross product of two 3-vectors. Result (a x b) is stored in c[3].
2145inline void vtkMath::Cross(const double a[3], const double b[3], double c[3])
2146{
2147 double Cx = a[1] * b[2] - a[2] * b[1];
2148 double Cy = a[2] * b[0] - a[0] * b[2];
2149 double Cz = a[0] * b[1] - a[1] * b[0];
2150 c[0] = Cx;
2151 c[1] = Cy;
2152 c[2] = Cz;
2153}
2154
2155//----------------------------------------------------------------------------
2156template <class T>
2157inline double vtkDeterminant3x3(const T A[3][3])
2158{
2159 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] -
2160 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];
2161}
2162
2163//----------------------------------------------------------------------------
2164inline double vtkMath::Determinant3x3(const float A[3][3])
2165{
2166 return vtkDeterminant3x3(A);
2167}
2168
2169//----------------------------------------------------------------------------
2170inline double vtkMath::Determinant3x3(const double A[3][3])
2171{
2172 return vtkDeterminant3x3(A);
2173}
2174
2175//----------------------------------------------------------------------------
2176template <class T>
2177inline T vtkMath::ClampValue(const T& value, const T& min, const T& max)
2178{
2179 assert("pre: valid_range" && min <= max);
2180 return std::clamp(value, min, max);
2181}
2182
2183//----------------------------------------------------------------------------
2184inline void vtkMath::ClampValue(double* value, const double range[2])
2185{
2186 if (value && range)
2187 {
2188 assert("pre: valid_range" && range[0] <= range[1]);
2189
2190 *value = vtkMath::ClampValue(*value, range[0], range[1]);
2191 }
2192}
2193
2194//----------------------------------------------------------------------------
2195inline void vtkMath::ClampValue(double value, const double range[2], double* clamped_value)
2196{
2197 if (range && clamped_value)
2198 {
2199 assert("pre: valid_range" && range[0] <= range[1]);
2200
2201 *clamped_value = vtkMath::ClampValue(value, range[0], range[1]);
2202 }
2203}
2204
2205// ---------------------------------------------------------------------------
2206inline double vtkMath::ClampAndNormalizeValue(double value, const double range[2])
2207{
2208 assert("pre: valid_range" && range[0] <= range[1]);
2209
2210 double result;
2211 if (range[0] == range[1])
2212 {
2213 result = 0.0;
2214 }
2215 else
2216 {
2217 // clamp
2218 result = vtkMath::ClampValue(value, range[0], range[1]);
2219
2220 // normalize
2221 result = (result - range[0]) / (range[1] - range[0]);
2222 }
2223
2224 assert("post: valid_result" && result >= 0.0 && result <= 1.0);
2225
2226 return result;
2227}
2228
2229//-----------------------------------------------------------------------------
2230template <class T1, class T2>
2231inline void vtkMath::TensorFromSymmetricTensor(const T1 symmTensor[9], T2 tensor[9])
2232{
2233 for (int i = 0; i < 3; ++i)
2234 {
2235 tensor[4 * i] = symmTensor[i];
2236 }
2237 tensor[1] = tensor[3] = symmTensor[3];
2238 tensor[2] = tensor[6] = symmTensor[5];
2239 tensor[5] = tensor[7] = symmTensor[4];
2240}
2241
2242//-----------------------------------------------------------------------------
2243template <class T>
2245{
2246 tensor[6] = tensor[5]; // XZ
2247 tensor[7] = tensor[4]; // YZ
2248 tensor[8] = tensor[2]; // ZZ
2249 tensor[4] = tensor[1]; // YY
2250 tensor[5] = tensor[7]; // YZ
2251 tensor[2] = tensor[6]; // XZ
2252 tensor[1] = tensor[3]; // XY
2253}
2254VTK_ABI_NAMESPACE_END
2255
2256namespace
2257{
2258template <class QuaternionT, class MatrixT>
2259inline void vtkQuaternionToMatrix3x3(QuaternionT&& quat, MatrixT&& A)
2260{
2262
2263 Scalar ww = quat[0] * quat[0];
2264 Scalar wx = quat[0] * quat[1];
2265 Scalar wy = quat[0] * quat[2];
2266 Scalar wz = quat[0] * quat[3];
2267
2268 Scalar xx = quat[1] * quat[1];
2269 Scalar yy = quat[2] * quat[2];
2270 Scalar zz = quat[3] * quat[3];
2271
2272 Scalar xy = quat[1] * quat[2];
2273 Scalar xz = quat[1] * quat[3];
2274 Scalar yz = quat[2] * quat[3];
2275
2276 Scalar rr = xx + yy + zz;
2277 // normalization factor, just in case quaternion was not normalized
2278 Scalar f = 1 / (ww + rr);
2279 Scalar s = (ww - rr) * f;
2280 f *= 2;
2281
2283
2284 MatrixT& Ar = A;
2285 Wrapper::template Get<0, 0>(Ar) = xx * f + s;
2286 Wrapper::template Get<1, 0>(Ar) = (xy + wz) * f;
2287 Wrapper::template Get<2, 0>(Ar) = (xz - wy) * f;
2288
2289 Wrapper::template Get<0, 1>(Ar) = (xy - wz) * f;
2290 Wrapper::template Get<1, 1>(Ar) = yy * f + s;
2291 Wrapper::template Get<2, 1>(Ar) = (yz + wx) * f;
2292
2293 Wrapper::template Get<0, 2>(Ar) = (xz + wy) * f;
2294 Wrapper::template Get<1, 2>(Ar) = (yz - wx) * f;
2295 Wrapper::template Get<2, 2>(Ar) = zz * f + s;
2296}
2297} // anonymous namespace
2298
2299VTK_ABI_NAMESPACE_BEGIN
2300//------------------------------------------------------------------------------
2301inline void vtkMath::QuaternionToMatrix3x3(const float quat[4], float A[3][3])
2302{
2303 vtkQuaternionToMatrix3x3(quat, A);
2304}
2305
2306//------------------------------------------------------------------------------
2307inline void vtkMath::QuaternionToMatrix3x3(const double quat[4], double A[3][3])
2308{
2309 vtkQuaternionToMatrix3x3(quat, A);
2310}
2311
2312//-----------------------------------------------------------------------------
2313template <class QuaternionT, class MatrixT, class EnableT>
2314inline void vtkMath::QuaternionToMatrix3x3(QuaternionT&& q, MatrixT&& A)
2315{
2316 vtkQuaternionToMatrix3x3(std::forward<QuaternionT>(q), std::forward<MatrixT>(A));
2317}
2318VTK_ABI_NAMESPACE_END
2319
2320namespace
2321{
2322//------------------------------------------------------------------------------
2323// The solution is based on
2324// Berthold K. P. Horn (1987),
2325// "Closed-form solution of absolute orientation using unit quaternions,"
2326// Journal of the Optical Society of America A, 4:629-642
2327template <class MatrixT, class QuaternionT>
2328inline void vtkMatrix3x3ToQuaternion(MatrixT&& A, QuaternionT&& quat)
2329{
2331
2332 Scalar N[4][4];
2333
2335
2336 MatrixT& Ar = A;
2337
2338 // on-diagonal elements
2339 N[0][0] = Wrapper::template Get<0, 0>(Ar) + Wrapper::template Get<1, 1>(Ar) +
2340 Wrapper::template Get<2, 2>(Ar);
2341 N[1][1] = Wrapper::template Get<0, 0>(Ar) - Wrapper::template Get<1, 1>(Ar) -
2342 Wrapper::template Get<2, 2>(Ar);
2343 N[2][2] = -Wrapper::template Get<0, 0>(Ar) + Wrapper::template Get<1, 1>(Ar) -
2344 Wrapper::template Get<2, 2>(Ar);
2345 N[3][3] = -Wrapper::template Get<0, 0>(Ar) - Wrapper::template Get<1, 1>(Ar) +
2346 Wrapper::template Get<2, 2>(Ar);
2347
2348 // off-diagonal elements
2349 N[0][1] = N[1][0] = Wrapper::template Get<2, 1>(Ar) - Wrapper::template Get<1, 2>(Ar);
2350 N[0][2] = N[2][0] = Wrapper::template Get<0, 2>(Ar) - Wrapper::template Get<2, 0>(Ar);
2351 N[0][3] = N[3][0] = Wrapper::template Get<1, 0>(Ar) - Wrapper::template Get<0, 1>(Ar);
2352
2353 N[1][2] = N[2][1] = Wrapper::template Get<1, 0>(Ar) + Wrapper::template Get<0, 1>(Ar);
2354 N[1][3] = N[3][1] = Wrapper::template Get<0, 2>(Ar) + Wrapper::template Get<2, 0>(Ar);
2355 N[2][3] = N[3][2] = Wrapper::template Get<2, 1>(Ar) + Wrapper::template Get<1, 2>(Ar);
2356
2357 Scalar eigenvectors[4][4], eigenvalues[4];
2358
2359 // convert into format that JacobiN can use,
2360 // then use Jacobi to find eigenvalues and eigenvectors
2361 Scalar *NTemp[4], *eigenvectorsTemp[4];
2362 for (int i = 0; i < 4; ++i)
2363 {
2364 NTemp[i] = N[i];
2365 eigenvectorsTemp[i] = eigenvectors[i];
2366 }
2367 vtkMath::JacobiN(NTemp, 4, eigenvalues, eigenvectorsTemp);
2368
2369 // the first eigenvector is the one we want
2370 quat[0] = eigenvectors[0][0];
2371 quat[1] = eigenvectors[1][0];
2372 quat[2] = eigenvectors[2][0];
2373 quat[3] = eigenvectors[3][0];
2374}
2375} // anonymous namespace
2376
2377VTK_ABI_NAMESPACE_BEGIN
2378//------------------------------------------------------------------------------
2379inline void vtkMath::Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
2380{
2381 vtkMatrix3x3ToQuaternion(A, quat);
2382}
2383
2384//------------------------------------------------------------------------------
2385inline void vtkMath::Matrix3x3ToQuaternion(const double A[3][3], double quat[4])
2386{
2387 vtkMatrix3x3ToQuaternion(A, quat);
2388}
2389
2390//-----------------------------------------------------------------------------
2391template <class MatrixT, class QuaternionT, class EnableT>
2392inline void vtkMath::Matrix3x3ToQuaternion(MatrixT&& A, QuaternionT&& q)
2393{
2394 vtkMatrix3x3ToQuaternion(std::forward<MatrixT>(A), std::forward<QuaternionT>(q));
2395}
2396VTK_ABI_NAMESPACE_END
2397
2398namespace vtk_detail
2399{
2400VTK_ABI_NAMESPACE_BEGIN
2401// Can't specialize templates inside a template class, so we move the impl here.
2402template <typename OutT>
2403void RoundDoubleToIntegralIfNecessary(double val, OutT* ret)
2404{ // OutT is integral -- clamp and round
2405 if (!vtkMath::IsNan(val))
2406 {
2407 double min = static_cast<double>(vtkTypeTraits<OutT>::Min());
2408 double max = static_cast<double>(vtkTypeTraits<OutT>::Max());
2409 val = vtkMath::ClampValue(val, min, max);
2410 *ret = static_cast<OutT>((val >= 0.0) ? (val + 0.5) : (val - 0.5));
2411 }
2412 else
2413 *ret = 0;
2414}
2415template <>
2416inline void RoundDoubleToIntegralIfNecessary(double val, double* retVal)
2417{ // OutT is double: passthrough
2418 *retVal = val;
2419}
2420template <>
2421inline void RoundDoubleToIntegralIfNecessary(double val, float* retVal)
2422{ // OutT is float -- just clamp (as doubles, then the cast to float is well-defined.)
2423 if (!vtkMath::IsNan(val))
2424 {
2425 double min = static_cast<double>(vtkTypeTraits<float>::Min());
2426 double max = static_cast<double>(vtkTypeTraits<float>::Max());
2427 val = vtkMath::ClampValue(val, min, max);
2428 }
2429
2430 *retVal = static_cast<float>(val);
2431}
2432VTK_ABI_NAMESPACE_END
2433} // end namespace vtk_detail
2434
2435VTK_ABI_NAMESPACE_BEGIN
2436//-----------------------------------------------------------------------------
2437#if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
2438#define VTK_MATH_ISINF_IS_INLINE
2439inline vtkTypeBool vtkMath::IsInf(double x)
2440{
2441#if defined(VTK_HAS_STD_ISINF)
2442 return std::isinf(x);
2443#else
2444 return (isinf(x) != 0); // Force conversion to bool
2445#endif
2446}
2447#endif
2448
2449//-----------------------------------------------------------------------------
2450#if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
2451#define VTK_MATH_ISNAN_IS_INLINE
2453{
2454#if defined(VTK_HAS_STD_ISNAN)
2455 return std::isnan(x);
2456#else
2457 return (isnan(x) != 0); // Force conversion to bool
2458#endif
2459}
2460#endif
2461
2462//-----------------------------------------------------------------------------
2463#if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
2464#define VTK_MATH_ISFINITE_IS_INLINE
2465inline bool vtkMath::IsFinite(double x)
2466{
2467#if defined(VTK_HAS_STD_ISFINITE)
2468 return std::isfinite(x);
2469#elif defined(VTK_HAS_ISFINITE)
2470 return (isfinite(x) != 0); // Force conversion to bool
2471#else
2472 return (finite(x) != 0); // Force conversion to bool
2473#endif
2474}
2475#endif
2476
2477VTK_ABI_NAMESPACE_END
2478#endif
RealT xx
Definition EdgeCnBasis.h:16
RealT yy
Definition EdgeCnBasis.h:17
RealT ww
Definition PyrCnBasis.h:44
offset[0]
Definition PyrCnBasis.h:96
RealT nn
Definition TetCnBasis.h:7
RealT mt
Definition PyrC2Basis.h:58
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
a simple class to control print indentation
Definition vtkIndent.h:108
static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1 &p1, const TupleRangeT2 &p2)
Compute distance squared between two points p1 and p2.
Definition vtkMath.h:2106
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).
Definition vtkMath.h:620
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.
Definition vtkMath.h:249
static vtkIdType ComputeGCD(vtkIdType m, vtkIdType n)
Compute the greatest common divisor (GCD) of two positive integers m and n.
Definition vtkMath.h:1837
static void XYZToProLab(const double xyz[3], double prolab[3])
Convert Color from the CIE XYZ system to ProLAB.
Definition vtkMath.h:1554
static double Norm2D(const double x[2])
Compute the norm of a 2-vector.
Definition vtkMath.h:902
static void XYZToProLab(double x, double y, double z, double *L, double *a, double *b)
Convert Color from the CIE XYZ system to ProLAB.
static double GaussianAmplitude(double variance, double distanceFromMean)
Compute the amplitude of a Gaussian function with mean=0 and specified variance.
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 GetPointAlongLine(double result[3], double p1[3], double p2[3], const double offset)
Get the coordinates of a point along a line defined by p1 and p2, at a specified offset relative to p...
Definition vtkMath.h:1917
static void Subtract(const float a[3], const float b[3], float c[3])
Subtraction of two 3-vectors (float version).
Definition vtkMath.h:529
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).
Definition vtkMath.h:867
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
Definition vtkMath.h:1930
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 double GaussianAmplitude(double mean, double variance, double position)
Compute the amplitude of a Gaussian function with specified mean and variance.
static void Add(const double a[3], const double b[3], double c[3])
Addition of two 3-vectors (double version).
Definition vtkMath.h:504
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).
Definition vtkMath.h:708
static ReturnTypeT Dot(const TupleRangeT1 &a, const TupleRangeT2 &b)
Compute dot product between two points p1 and p2.
Definition vtkMath.h:644
static vtkTypeBool Jacobi(double **a, double *w, double **v)
Jacobi iteration for the solution of eigenvectors/eigenvalues of a 3x3 real symmetric matrix.
static ScalarT Dot(VectorT1 &&x, VectorT2 &&y)
Computes the dot product between 2 vectors x and y.
Definition vtkMath.h:1071
static void XYZToLab(const double xyz[3], double lab[3])
Convert Color from the CIE XYZ system to CIE-L*ab.
Definition vtkMath.h:1576
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!
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 Identity3x3(float A[3][3])
Set A to the identity matrix.
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 LinearSolve(MatrixT &&M, VectorT1 &&x, VectorT2 &&y)
This method solves linear systems M * x = y.
Definition vtkMath.h:1158
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.
Definition vtkMath.h:1565
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).
Definition vtkMath.h:612
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 MultiplyScalar2D(float a[2], float s)
Multiplies a 2-vector by a scalar (float version).
Definition vtkMath.h:577
static void HSVToRGB(const float hsv[3], float rgb[3])
Convert color in HSV format (Hue, Saturation, Value) to RGB format (Red, Green, Blue).
Definition vtkMath.h:1525
static void Assign(const double a[3], double b[3])
Assign values to a 3-vector (double version).
Definition vtkMath.h:488
static double Determinant2x2(const double c1[2], const double c2[2])
Calculate the determinant of a 2x2 matrix: | a b | | c d |.
Definition vtkMath.h:929
static T Max(const T &a, const T &b)
Returns the maximum of the two arguments provided.
Definition vtkMath.h:2007
static void Outer2D(const double x[2], const double y[2], double A[2][2])
Outer product of two 2-vectors (double version).
Definition vtkMath.h:881
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).
Definition vtkMath.h:601
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 double RealBinomial(double mm, int nn)
A version of Binomial that allows mm to be real-valued.
static int Ceil(double x)
Rounds a double to the nearest integer not less than itself.
Definition vtkMath.h:1992
static void HSVToRGB(const double hsv[3], double rgb[3])
Convert color in HSV format (Hue, Saturation, Value) to RGB format (Red, Green, Blue).
Definition vtkMath.h:1530
~vtkMath() override=default
static double Inf()
Special IEEE-754 number used to represent positive infinity.
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 ScalarT Dot(VectorT1 &&x, VectorT2 &&y)
Computes the dot product between 2 vectors x and y.
Definition vtkMath.h:1054
static bool LinearSolveTransposed3x3(const double A[3][3], const double x[3], double y[3])
Solve A^T y = x for y, where A^T is the transpose of the 3x3 matrix A, and place the result in y.
static void RGBToXYZ(const double rgb[3], double xyz[3])
Convert color from the RGB system to CIE XYZ.
Definition vtkMath.h:1598
static void QuaternionToMatrix3x3(const float quat[4], float A[3][3])
Convert a quaternion to a 3x3 rotation matrix.
Definition vtkMath.h:2301
static int NearestPowerOfTwo(int x)
Compute the nearest power of two that is not less than x.
Definition vtkMath.h:1969
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 ScalarT Dot(VectorT1 &&x, MatrixT &&M, VectorT2 &&y)
Computes the dot product x^T M y, where x and y are vectors and M is a metric matrix.
Definition vtkMath.h:1181
static float Normalize2D(float v[2])
Normalize (in place) a 2-vector.
Definition vtkMath.h:2041
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 constexpr int DYNAMIC_VECTOR_SIZE()
When this value is passed to a select templated functions in vtkMath, the computation can be performe...
Definition vtkMath.h:222
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).
Definition vtkMath.h:666
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).
Definition vtkMath.h:478
static float RadiansFromDegrees(float degrees)
Convert degrees into radians.
Definition vtkMath.h:1938
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.
Definition vtkMath.h:1872
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).
Definition vtkMath.h:493
static int CeilLog2(vtkTypeUInt64 x)
Gives the exponent of the lowest power of two not less than x.
static void RGBToProLab(double red, double green, double blue, double *L, double *a, double *b)
Convert color from the RGB system to Prolab The input RGB must be values in the range [0,...
static void ProLabToXYZ(const double prolab[3], double xyz[3])
Convert color from the ProLAB system to CIE XYZ.
Definition vtkMath.h:1542
static vtkTypeBool AreBoundsInitialized(const double bounds[6])
Are the bounds initialized?
Definition vtkMath.h:1676
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 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.
Definition vtkMath.h:227
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).
Definition vtkMath.h:540
static void ProLabToXYZ(double L, double a, double b, double *x, double *y, double *z)
Convert color from the ProLAB system to CIE XYZ.
static void RGBToProLab(const double rgb[3], double prolab[3])
Convert color from the RGB system to Prolab The input RGB must be values in the range [0,...
Definition vtkMath.h:1639
static void ProLabToRGB(double L, double a, double b, double *red, double *green, double *blue)
Convert color from the ProLab system to RGB.
static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
Convert a 3x3 matrix into a quaternion.
Definition vtkMath.h:2379
static vtkMath * New()
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.
Definition vtkMath.h:1587
static double ClampAndNormalizeValue(double value, const double range[2])
Clamp a value against a range and then normalize it between 0 and 1.
Definition vtkMath.h:2206
static void MultiplyScalar(double a[3], double s)
Multiplies a 3-vector by a scalar (double version).
Definition vtkMath.h:589
static double Dot2D(const double x[2], const double y[2])
Dot product of two 2-vectors.
Definition vtkMath.h:862
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 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.
Definition vtkMath.h:1613
static void ProLabToRGB(const double prolab[3], double rgb[3])
Convert color from the ProLab system to RGB.
Definition vtkMath.h:1624
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
Definition vtkMath.h:1983
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).
Definition vtkMath.h:554
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 |.
Definition vtkMath.h:928
static void RGBToHSV(const double rgb[3], double hsv[3])
Convert color in RGB format (Red, Green, Blue) to HSV format (Hue, Saturation, Value).
Definition vtkMath.h:1510
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.
Definition vtkMath.h:1950
static float Determinant2x2(const float c1[2], const float c2[2])
Compute determinant of 2x2 matrix.
Definition vtkMath.h:919
static int Round(double f)
Definition vtkMath.h:250
static vtkTypeBool IsInf(double x)
Test if a number is equal to the special floating point value infinity.
static double GaussianWeight(double mean, double variance, double position)
Compute the amplitude of an unnormalized Gaussian function with specified mean and variance.
static void UninitializeBounds(double bounds[6])
Set the bounds to an uninitialized state.
Definition vtkMath.h:1661
vtkMath()=default
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).
Definition vtkMath.h:652
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).
Definition vtkMath.h:713
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...
Definition vtkMath.h:258
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 double JacobiPolynomial(int nn, double alpha, double beta, double xx)
Returns the value of the nn-th Jacobi polynomial for parameters alpha > -1, beta > -1 and (typically)...
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Returns true if integer is a power of two.
Definition vtkMath.h:1962
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.
Definition vtkMath.h:2013
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.
Definition vtkMath.h:728
static double Determinant3x3(const float A[3][3])
Return the determinant of a 3x3 matrix.
Definition vtkMath.h:2164
static float Dot2D(const float x[2], const float y[2])
Dot product of two 2-vectors.
Definition vtkMath.h:857
ConvolutionMode
Support the convolution operations.
Definition vtkMath.h:1843
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 void RGBToHSV(const float rgb[3], float hsv[3])
Convert color in RGB format (Red, Green, Blue) to HSV format (Hue, Saturation, Value).
Definition vtkMath.h:1505
static double DoubleBinomial(int m, int n)
The number of combinations of n objects from a pool of m objects (m>n).
static void Add(VectorT1 &&a, VectorT2 &&b, VectorT3 &c)
Addition of two 3-vectors (double version).
Definition vtkMath.h:518
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 vtkMatrixUtilities::ScalarTypeExtractor< MatrixT >::value_type Determinant(MatrixT &&M)
Computes the determinant of input square SizeT x SizeT matrix M.
Definition vtkMath.h:1114
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.
Definition vtkMath.h:1650
static float Norm2D(const float x[2])
Compute the norm of a 2-vector.
Definition vtkMath.h:896
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 MultiplyScalar(float a[3], float s)
Multiplies a 3-vector by a scalar (float version).
Definition vtkMath.h:565
static T Min(const T &a, const T &b)
Returns the minimum of the two arguments provided.
Definition vtkMath.h:2000
static void InvertMatrix(MatrixT1 &&M1, MatrixT2 &&M2)
Computes the inverse of input matrix M1 into M2.
Definition vtkMath.h:1137
static void Cross(VectorT1 &&a, VectorT2 &&b, VectorT3 &c)
Cross product of two 3-vectors.
Definition vtkMath.h:2120
static void MultiplyMatrix(MatrixT1 &&M1, MatrixT2 &&M2, MatrixT3 &&M3)
Multiply matrices such that M3 = M1 x M2.
Definition vtkMath.h:1013
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.
Definition vtkMath.h:2177
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 double JacobiPolynomialDerivative(int nn, double alpha, double beta, double xx)
Returns the derivative (with respect to xx) of the nn-th Jacobi polynomial.
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 double GaussianWeight(double variance, double distanceFromMean)
Compute the amplitude of an unnormalized Gaussian function with mean=0 and specified variance.
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 double Distance2BetweenPoints2D(const double p1[2], const double p2[2])
Compute distance squared between two 2D points p1 and p2.
Definition vtkMath.h:2113
static vtkMatrixUtilities::ScalarTypeExtractor< VectorT >::value_type SquaredNorm(VectorT &&x)
Computes the dot product between 2 vectors x and y.
Definition vtkMath.h:1090
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.
static void MultiplyMatrixWithVector(MatrixT &&M, VectorT1 &&X, VectorT2 &&Y)
Multiply matrix M with vector Y such that Y = M x X.
Definition vtkMath.h:1041
Park and Miller Sequence of pseudo random numbers.
represent and manipulate 3D points
Definition vtkPoints.h:140
Computes the portion of a dataset which is inside a selection.
Hold a reference to a vtkObjectBase instance.
void RoundDoubleToIntegralIfNecessary(double val, OutT *ret)
Definition vtkMath.h:2403
typename detail::ScalarTypeExtractor< std::is_array< DerefContainer >::value||std::is_pointer< DerefContainer >::value, ContainerT >::value_type value_type
value_type is the underlying arithmetic type held in ContainerT
Template defining traits of native types used by VTK.
int vtkTypeBool
Definition vtkABI.h:64
#define vtkDataArray
double vtkDeterminant3x3(const T A[3][3])
Definition vtkMath.h:2157
#define Distance2BetweenPoints2D(p1, p2)
int vtkIdType
Definition vtkType.h:366
#define max(a, b)