VTK  9.5.20250807
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
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
303 static bool IsPowerOfTwo(vtkTypeUInt64 x);
304
310 static int NearestPowerOfTwo(int x);
311
316 static vtkTypeInt64 Factorial(int N);
317
323 static vtkTypeInt64 Binomial(int m, int n);
324
336 static int* BeginCombination(int m, int n);
337
348 static int NextCombination(int m, int n, int* combination);
349
353 static void FreeCombination(int* combination);
354
370 static void RandomSeed(int s);
371
383 static int GetSeed();
384
398 static double Random();
399
412 static double Random(double min, double max);
413
426 static double Gaussian();
427
440 static double Gaussian(double mean, double std);
441
446 template <class VectorT1, class VectorT2>
447 static void Assign(const VectorT1& a, VectorT2&& b)
448 {
449 b[0] = a[0];
450 b[1] = a[1];
451 b[2] = a[2];
452 }
453
457 static void Assign(const double a[3], double b[3]) { vtkMath::Assign<>(a, b); }
458
462 static void Add(const float a[3], const float b[3], float c[3])
463 {
464 for (int i = 0; i < 3; ++i)
465 {
466 c[i] = a[i] + b[i];
467 }
468 }
469
473 static void Add(const double a[3], const double b[3], double c[3])
474 {
475 for (int i = 0; i < 3; ++i)
476 {
477 c[i] = a[i] + b[i];
478 }
479 }
480
486 template <class VectorT1, class VectorT2, class VectorT3>
487 static void Add(VectorT1&& a, VectorT2&& b, VectorT3& c)
488 {
489 for (int i = 0; i < 3; ++i)
490 {
491 c[i] = a[i] + b[i];
492 }
493 }
494
498 static void Subtract(const float a[3], const float b[3], float c[3])
499 {
500 for (int i = 0; i < 3; ++i)
501 {
502 c[i] = a[i] - b[i];
503 }
504 }
505
509 static void Subtract(const double a[3], const double b[3], double c[3])
510 {
511 for (int i = 0; i < 3; ++i)
512 {
513 c[i] = a[i] - b[i];
514 }
515 }
516
522 template <class VectorT1, class VectorT2, class VectorT3>
523 static void Subtract(const VectorT1& a, const VectorT2& b, VectorT3&& c)
524 {
525 c[0] = a[0] - b[0];
526 c[1] = a[1] - b[1];
527 c[2] = a[2] - b[2];
528 }
529
534 static void MultiplyScalar(float a[3], float s)
535 {
536 for (int i = 0; i < 3; ++i)
537 {
538 a[i] *= s;
539 }
540 }
541
546 static void MultiplyScalar2D(float a[2], float s)
547 {
548 for (int i = 0; i < 2; ++i)
549 {
550 a[i] *= s;
551 }
552 }
553
558 static void MultiplyScalar(double a[3], double s)
559 {
560 for (int i = 0; i < 3; ++i)
561 {
562 a[i] *= s;
563 }
564 }
565
570 static void MultiplyScalar2D(double a[2], double s)
571 {
572 for (int i = 0; i < 2; ++i)
573 {
574 a[i] *= s;
575 }
576 }
577
581 static float Dot(const float a[3], const float b[3])
582 {
583 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
584 }
585
589 static double Dot(const double a[3], const double b[3])
590 {
591 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
592 }
593
609 template <typename ReturnTypeT = double, typename TupleRangeT1, typename TupleRangeT2,
610 typename EnableT = typename std::conditional<!std::is_pointer<TupleRangeT1>::value &&
611 !std::is_array<TupleRangeT1>::value,
612 TupleRangeT1, TupleRangeT2>::type::value_type>
613 static ReturnTypeT Dot(const TupleRangeT1& a, const TupleRangeT2& b)
614 {
615 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
616 }
617
621 static void Outer(const float a[3], const float b[3], float c[3][3])
622 {
623 for (int i = 0; i < 3; ++i)
624 {
625 for (int j = 0; j < 3; ++j)
626 {
627 c[i][j] = a[i] * b[j];
628 }
629 }
630 }
631
635 static void Outer(const double a[3], const double b[3], double c[3][3])
636 {
637 for (int i = 0; i < 3; ++i)
638 {
639 for (int j = 0; j < 3; ++j)
640 {
641 c[i][j] = a[i] * b[j];
642 }
643 }
644 }
645
651 template <class VectorT1, class VectorT2, class VectorT3>
652 static void Cross(VectorT1&& a, VectorT2&& b, VectorT3& c);
653
658 static void Cross(const float a[3], const float b[3], float c[3]);
659
664 static void Cross(const double a[3], const double b[3], double c[3]);
665
667
670 static float Norm(const float* x, int n);
671 static double Norm(const double* x, int n);
673
677 static float Norm(const float v[3]) { return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); }
678
682 static double Norm(const double v[3])
683 {
684 return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
685 }
686
696 template <typename ReturnTypeT = double, typename TupleRangeT>
697 static ReturnTypeT SquaredNorm(const TupleRangeT& v)
698 {
699 return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
700 }
701
706 static float Normalize(float v[3]);
707
712 static double Normalize(double v[3]);
713
715
722 static void Perpendiculars(const double v1[3], double v2[3], double v3[3], double theta);
723 static void Perpendiculars(const float v1[3], float v2[3], float v3[3], double theta);
725
727
732 static bool ProjectVector(const float a[3], const float b[3], float projection[3]);
733 static bool ProjectVector(const double a[3], const double b[3], double projection[3]);
735
737
743 static bool ProjectVector2D(const float a[2], const float b[2], float projection[2]);
744 static bool ProjectVector2D(const double a[2], const double b[2], double projection[2]);
746
762 template <typename ReturnTypeT = double, typename TupleRangeT1, typename TupleRangeT2,
763 typename EnableT = typename std::conditional<!std::is_pointer<TupleRangeT1>::value &&
764 !std::is_array<TupleRangeT1>::value,
765 TupleRangeT1, TupleRangeT2>::type::value_type>
766 static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1& p1, const TupleRangeT2& p2);
767
772 static float Distance2BetweenPoints(const float p1[3], const float p2[3]);
773
778 static double Distance2BetweenPoints(const double p1[3], const double p2[3]);
779
783 static double AngleBetweenVectors(const double v1[3], const double v2[3]);
784
789 const double v1[3], const double v2[3], const double vn[3]);
790
795 static double GaussianAmplitude(double variance, double distanceFromMean);
796
801 static double GaussianAmplitude(double mean, double variance, double position);
802
808 static double GaussianWeight(double variance, double distanceFromMean);
809
815 static double GaussianWeight(double mean, double variance, double position);
816
820 static float Dot2D(const float x[2], const float y[2]) { return x[0] * y[0] + x[1] * y[1]; }
821
825 static double Dot2D(const double x[2], const double y[2]) { return x[0] * y[0] + x[1] * y[1]; }
826
830 static void Outer2D(const float x[2], const float y[2], float A[2][2])
831 {
832 for (int i = 0; i < 2; ++i)
833 {
834 for (int j = 0; j < 2; ++j)
835 {
836 A[i][j] = x[i] * y[j];
837 }
838 }
839 }
840
844 static void Outer2D(const double x[2], const double y[2], double A[2][2])
845 {
846 for (int i = 0; i < 2; ++i)
847 {
848 for (int j = 0; j < 2; ++j)
849 {
850 A[i][j] = x[i] * y[j];
851 }
852 }
853 }
854
859 static float Norm2D(const float x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
860
865 static double Norm2D(const double x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
866
871 static float Normalize2D(float v[2]);
872
877 static double Normalize2D(double v[2]);
878
882 static float Determinant2x2(const float c1[2], const float c2[2])
883 {
884 return c1[0] * c2[1] - c2[0] * c1[1];
885 }
886
888
891 static double Determinant2x2(double a, double b, double c, double d) { return a * d - b * c; }
892 static double Determinant2x2(const double c1[2], const double c2[2])
893 {
894 return c1[0] * c2[1] - c2[0] * c1[1];
895 }
897
899
902 static void LUFactor3x3(float A[3][3], int index[3]);
903 static void LUFactor3x3(double A[3][3], int index[3]);
905
907
910 static void LUSolve3x3(const float A[3][3], const int index[3], float x[3]);
911 static void LUSolve3x3(const double A[3][3], const int index[3], double x[3]);
913
915
919 static void LinearSolve3x3(const float A[3][3], const float x[3], float y[3]);
920 static void LinearSolve3x3(const double A[3][3], const double x[3], double y[3]);
922
924
927 static void Multiply3x3(const float A[3][3], const float v[3], float u[3]);
928 static void Multiply3x3(const double A[3][3], const double v[3], double u[3]);
930
932
935 static void Multiply3x3(const float A[3][3], const float B[3][3], float C[3][3]);
936 static void Multiply3x3(const double A[3][3], const double B[3][3], double C[3][3]);
938
962 template <int RowsT, int MidDimT, int ColsT,
963 class LayoutT1 = vtkMatrixUtilities::Layout::Identity,
964 class LayoutT2 = vtkMatrixUtilities::Layout::Identity, class MatrixT1, class MatrixT2,
965 class MatrixT3>
966 static void MultiplyMatrix(MatrixT1&& M1, MatrixT2&& M2, MatrixT3&& M3)
967 {
968 vtkMathPrivate::MultiplyMatrix<RowsT, MidDimT, ColsT, LayoutT1, LayoutT2>::Compute(
969 std::forward<MatrixT1>(M1), std::forward<MatrixT2>(M2), std::forward<MatrixT3>(M3));
970 }
971
992 template <int RowsT, int ColsT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
993 class MatrixT, class VectorT1, class VectorT2>
994 static void MultiplyMatrixWithVector(MatrixT&& M, VectorT1&& X, VectorT2&& Y)
995 {
996 vtkMathPrivate::MultiplyMatrix<RowsT, ColsT, 1, LayoutT>::Compute(
997 std::forward<MatrixT>(M), std::forward<VectorT1>(X), std::forward<VectorT2>(Y));
998 }
999
1005 template <class ScalarT, int SizeT, class VectorT1, class VectorT2,
1006 class = typename std::enable_if<SizeT != DYNAMIC_VECTOR_SIZE()>::type>
1007 static ScalarT Dot(VectorT1&& x, VectorT2&& y)
1008 {
1009 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
1010 vtkMatrixUtilities::Layout::Identity,
1011 vtkMatrixUtilities::Layout::Transpose>::Compute(std::forward<VectorT1>(x),
1012 std::forward<VectorT2>(y));
1013 }
1014
1021 template <class ScalarT, int SizeT, class VectorT1, class VectorT2,
1022 class = typename std::enable_if<SizeT == DYNAMIC_VECTOR_SIZE()>::type,
1023 class = EnableIfVectorImplementsSize<VectorT1>>
1024 static ScalarT Dot(VectorT1&& x, VectorT2&& y)
1025 {
1026 ScalarT dot = 0.0;
1027 using SizeType = decltype(std::declval<VectorT1>().size());
1028 for (SizeType dim = 0; dim < x.size(); ++dim)
1029 {
1030 dot += x[dim] * y[dim];
1031 }
1032 return dot;
1033 }
1034
1042 template <int SizeT, class VectorT>
1044 VectorT&& x)
1045 {
1047 return vtkMath::Dot<Scalar, SizeT>(std::forward<VectorT>(x), std::forward<VectorT>(x));
1048 }
1049
1066 template <int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity, class MatrixT>
1068 MatrixT&& M)
1069 {
1070 return vtkMathPrivate::Determinant<SizeT, LayoutT>::Compute(std::forward<MatrixT>(M));
1071 }
1072
1088 template <int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity, class MatrixT1,
1089 class MatrixT2>
1090 static void InvertMatrix(MatrixT1&& M1, MatrixT2&& M2)
1091 {
1092 vtkMathPrivate::InvertMatrix<SizeT, LayoutT>::Compute(
1093 std::forward<MatrixT1>(M1), std::forward<MatrixT2>(M2));
1094 }
1095
1109 template <int RowsT, int ColsT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
1110 class MatrixT, class VectorT1, class VectorT2>
1111 static void LinearSolve(MatrixT&& M, VectorT1&& x, VectorT2&& y)
1112 {
1113 vtkMathPrivate::LinearSolve<RowsT, ColsT, LayoutT>::Compute(
1114 std::forward<MatrixT>(M), std::forward<VectorT1>(x), std::forward<VectorT2>(y));
1115 }
1116
1131 template <class ScalarT, int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
1132 class VectorT1, class MatrixT, class VectorT2,
1133 class = typename std::enable_if<SizeT != DYNAMIC_VECTOR_SIZE()>::type>
1134 static ScalarT Dot(VectorT1&& x, MatrixT&& M, VectorT2&& y)
1135 {
1136 ScalarT tmp[SizeT];
1137 vtkMathPrivate::MultiplyMatrix<SizeT, SizeT, 1, LayoutT>::Compute(
1138 std::forward<MatrixT>(M), std::forward<VectorT2>(y), tmp);
1139 return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
1140 vtkMatrixUtilities::Layout::Identity,
1141 vtkMatrixUtilities::Layout::Transpose>::Compute(std::forward<VectorT1>(x), tmp);
1142 }
1143
1149 static void MultiplyMatrix(const double* const* A, const double* const* B, unsigned int rowA,
1150 unsigned int colA, unsigned int rowB, unsigned int colB, double** C);
1151
1153
1157 static void Transpose3x3(const float A[3][3], float AT[3][3]);
1158 static void Transpose3x3(const double A[3][3], double AT[3][3]);
1160
1162
1166 static void Invert3x3(const float A[3][3], float AI[3][3]);
1167 static void Invert3x3(const double A[3][3], double AI[3][3]);
1169
1171
1174 static void Identity3x3(float A[3][3]);
1175 static void Identity3x3(double A[3][3]);
1177
1179
1182 static double Determinant3x3(const float A[3][3]);
1183 static double Determinant3x3(const double A[3][3]);
1185
1189 static float Determinant3x3(const float c1[3], const float c2[3], const float c3[3]);
1190
1194 static double Determinant3x3(const double c1[3], const double c2[3], const double c3[3]);
1195
1202 static double Determinant3x3(double a1, double a2, double a3, double b1, double b2, double b3,
1203 double c1, double c2, double c3);
1204
1206
1213 static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
1214 static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
1215 template <class QuaternionT, class MatrixT,
1216 class EnableT = typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::type>
1217 static void QuaternionToMatrix3x3(QuaternionT&& q, MatrixT&& A);
1219
1221
1230 static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
1231 static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
1232 template <class MatrixT, class QuaternionT,
1233 class EnableT = typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::type>
1234 static void Matrix3x3ToQuaternion(MatrixT&& A, QuaternionT&& q);
1236
1238
1244 static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4]);
1245 static void MultiplyQuaternion(const double q1[4], const double q2[4], double q[4]);
1247
1249
1253 static void RotateVectorByNormalizedQuaternion(const float v[3], const float q[4], float r[3]);
1254 static void RotateVectorByNormalizedQuaternion(const double v[3], const double q[4], double r[3]);
1256
1258
1262 static void RotateVectorByWXYZ(const float v[3], const float q[4], float r[3]);
1263 static void RotateVectorByWXYZ(const double v[3], const double q[4], double r[3]);
1265
1267
1272 static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
1273 static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
1275
1277
1283 static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
1284 static void Diagonalize3x3(const double A[3][3], double w[3], double V[3][3]);
1286
1288
1298 const float A[3][3], float U[3][3], float w[3], float VT[3][3]);
1300 const double A[3][3], double U[3][3], double w[3], double VT[3][3]);
1302
1311 double a00, double a01, double a10, double a11, double b0, double b1, double& x0, double& x1);
1312
1321 static vtkTypeBool SolveLinearSystem(double** A, double* x, int size);
1322
1329 static vtkTypeBool InvertMatrix(double** A, double** AI, int size);
1330
1337 double** A, double** AI, int size, int* tmp1Size, double* tmp2Size);
1338
1361 static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size);
1362
1368 static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size, double* tmpSize);
1369
1378 static void LUSolveLinearSystem(double** A, int* index, double* x, int size);
1379
1388 static double EstimateMatrixCondition(const double* const* A, int size);
1389
1391
1399 static vtkTypeBool Jacobi(float** a, float* w, float** v);
1400 static vtkTypeBool Jacobi(double** a, double* w, double** v);
1402
1404
1413 static vtkTypeBool JacobiN(float** a, int n, float* w, float** v);
1414 static vtkTypeBool JacobiN(double** a, int n, double* w, double** v);
1416
1431 int numberOfSamples, double** xt, int xOrder, double** mt);
1432
1447 static vtkTypeBool SolveLeastSquares(int numberOfSamples, double** xt, int xOrder, double** yt,
1448 int yOrder, double** mt, int checkHomogeneous = 1);
1449
1451
1458 static void RGBToHSV(const float rgb[3], float hsv[3])
1459 {
1460 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1461 }
1462 static void RGBToHSV(float r, float g, float b, float* h, float* s, float* v);
1463 static void RGBToHSV(const double rgb[3], double hsv[3])
1464 {
1465 RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1466 }
1467 static void RGBToHSV(double r, double g, double b, double* h, double* s, double* v);
1469
1471
1478 static void HSVToRGB(const float hsv[3], float rgb[3])
1479 {
1480 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1481 }
1482 static void HSVToRGB(float h, float s, float v, float* r, float* g, float* b);
1483 static void HSVToRGB(const double hsv[3], double rgb[3])
1484 {
1485 HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1486 }
1487 static void HSVToRGB(double h, double s, double v, double* r, double* g, double* b);
1489
1491
1495 static void ProLabToXYZ(const double prolab[3], double xyz[3])
1496 {
1497 ProLabToXYZ(prolab[0], prolab[1], prolab[2], xyz + 0, xyz + 1, xyz + 2);
1498 }
1499 static void ProLabToXYZ(double L, double a, double b, double* x, double* y, double* z);
1501
1503
1507 static void XYZToProLab(const double xyz[3], double prolab[3])
1508 {
1509 XYZToProLab(xyz[0], xyz[1], xyz[2], prolab + 0, prolab + 1, prolab + 2);
1510 }
1511 static void XYZToProLab(double x, double y, double z, double* L, double* a, double* b);
1513
1515
1518 static void LabToXYZ(const double lab[3], double xyz[3])
1519 {
1520 LabToXYZ(lab[0], lab[1], lab[2], xyz + 0, xyz + 1, xyz + 2);
1521 }
1522 static void LabToXYZ(double L, double a, double b, double* x, double* y, double* z);
1524
1526
1529 static void XYZToLab(const double xyz[3], double lab[3])
1530 {
1531 XYZToLab(xyz[0], xyz[1], xyz[2], lab + 0, lab + 1, lab + 2);
1532 }
1533 static void XYZToLab(double x, double y, double z, double* L, double* a, double* b);
1535
1537
1540 static void XYZToRGB(const double xyz[3], double rgb[3])
1541 {
1542 XYZToRGB(xyz[0], xyz[1], xyz[2], rgb + 0, rgb + 1, rgb + 2);
1543 }
1544 static void XYZToRGB(double x, double y, double z, double* r, double* g, double* b);
1546
1548
1551 static void RGBToXYZ(const double rgb[3], double xyz[3])
1552 {
1553 RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz + 0, xyz + 1, xyz + 2);
1554 }
1555 static void RGBToXYZ(double r, double g, double b, double* x, double* y, double* z);
1557
1559
1566 static void RGBToLab(const double rgb[3], double lab[3])
1567 {
1568 RGBToLab(rgb[0], rgb[1], rgb[2], lab + 0, lab + 1, lab + 2);
1569 }
1570 static void RGBToLab(double red, double green, double blue, double* L, double* a, double* b);
1572
1574
1577 static void ProLabToRGB(const double prolab[3], double rgb[3])
1578 {
1579 ProLabToRGB(prolab[0], prolab[1], prolab[2], rgb + 0, rgb + 1, rgb + 2);
1580 }
1581 static void ProLabToRGB(double L, double a, double b, double* red, double* green, double* blue);
1583
1585
1592 static void RGBToProLab(const double rgb[3], double prolab[3])
1593 {
1594 RGBToProLab(rgb[0], rgb[1], rgb[2], prolab + 0, prolab + 1, prolab + 2);
1595 }
1596 static void RGBToProLab(double red, double green, double blue, double* L, double* a, double* b);
1598
1600
1603 static void LabToRGB(const double lab[3], double rgb[3])
1604 {
1605 LabToRGB(lab[0], lab[1], lab[2], rgb + 0, rgb + 1, rgb + 2);
1606 }
1607 static void LabToRGB(double L, double a, double b, double* red, double* green, double* blue);
1609
1611
1614 static void UninitializeBounds(double bounds[6])
1615 {
1616 bounds[0] = 1.0;
1617 bounds[1] = -1.0;
1618 bounds[2] = 1.0;
1619 bounds[3] = -1.0;
1620 bounds[4] = 1.0;
1621 bounds[5] = -1.0;
1622 }
1624
1626
1629 static vtkTypeBool AreBoundsInitialized(const double bounds[6])
1630 {
1631 if (bounds[1] - bounds[0] < 0.0)
1632 {
1633 return 0;
1634 }
1635 return 1;
1636 }
1638
1643 template <class T>
1644 static T ClampValue(const T& value, const T& min, const T& max);
1645
1647
1651 static void ClampValue(double* value, const double range[2]);
1652 static void ClampValue(double value, const double range[2], double* clamped_value);
1653 static void ClampValues(double* values, int nb_values, const double range[2]);
1654 static void ClampValues(
1655 const double* values, int nb_values, const double range[2], double* clamped_values);
1657
1664 static double ClampAndNormalizeValue(double value, const double range[2]);
1665
1670 template <class T1, class T2>
1671 static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9]);
1672
1678 template <class T>
1679 static void TensorFromSymmetricTensor(T tensor[9]);
1680
1690 double range_min, double range_max, double scale = 1.0, double shift = 0.0);
1691
1700 static vtkTypeBool GetAdjustedScalarRange(vtkDataArray* array, int comp, double range[2]);
1701
1706 static vtkTypeBool ExtentIsWithinOtherExtent(const int extent1[6], const int extent2[6]);
1707
1714 const double bounds1[6], const double bounds2[6], const double delta[3]);
1715
1722 const double point[3], const double bounds[6], const double delta[3]);
1723
1734 const double bounds[6], const double normal[3], const double point[3]);
1735
1745 static double Solve3PointCircle(
1746 const double p1[3], const double p2[3], const double p3[3], double center[3]);
1747
1751 static double Inf();
1752
1756 static double NegInf();
1757
1761 static double Nan();
1762
1766 static vtkTypeBool IsInf(double x);
1767
1771 static vtkTypeBool IsNan(double x);
1772
1777 static bool IsFinite(double x);
1778
1783 static int QuadraticRoot(double a, double b, double c, double min, double max, double* u);
1784
1790 static vtkIdType ComputeGCD(vtkIdType m, vtkIdType n) { return (n ? ComputeGCD(n, m % n) : m); }
1791
1796 {
1797 FULL,
1798 SAME,
1799 VALID
1800 };
1801
1824 template <class Iter1, class Iter2, class Iter3>
1825 static void Convolve1D(Iter1 beginSample, Iter1 endSample, Iter2 beginKernel, Iter2 endKernel,
1826 Iter3 beginOut, Iter3 endOut, ConvolutionMode mode = ConvolutionMode::FULL)
1827 {
1828 int sampleSize = std::distance(beginSample, endSample);
1829 int kernelSize = std::distance(beginKernel, endKernel);
1830 int outSize = std::distance(beginOut, endOut);
1831
1832 if (sampleSize <= 0 || kernelSize <= 0 || outSize <= 0)
1833 {
1834 return;
1835 }
1836
1837 int begin = 0;
1838 int end = outSize;
1839
1840 switch (mode)
1841 {
1842 case ConvolutionMode::SAME:
1843 begin = static_cast<int>(std::ceil((std::min)(sampleSize, kernelSize) / 2.0)) - 1;
1844 end = begin + (std::max)(sampleSize, kernelSize);
1845 break;
1846 case ConvolutionMode::VALID:
1847 begin = (std::min)(sampleSize, kernelSize) - 1;
1848 end = begin + std::abs(sampleSize - kernelSize) + 1;
1849 break;
1850 case ConvolutionMode::FULL:
1851 default:
1852 break;
1853 }
1854
1855 for (int i = begin; i < end; i++)
1856 {
1857 Iter3 out = beginOut + i - begin;
1858 *out = 0;
1859 for (int j = (std::max)(i - sampleSize + 1, 0); j <= (std::min)(i, kernelSize - 1); j++)
1860 {
1861 *out += *(beginSample + (i - j)) * *(beginKernel + j);
1862 }
1863 }
1864 }
1865
1870 static void GetPointAlongLine(double result[3], double p1[3], double p2[3], const double offset)
1871 {
1872 double directionVector[3] = { p2[0] - p1[0], p2[1] - p1[1], p2[2] - p1[2] };
1873 vtkMath::Normalize(directionVector);
1874 result[0] = p2[0] + (offset * directionVector[0]);
1875 result[1] = p2[1] + (offset * directionVector[1]);
1876 result[2] = p2[2] + (offset * directionVector[2]);
1877 }
1878
1879protected:
1880 vtkMath() = default;
1881 ~vtkMath() override = default;
1882
1884
1885private:
1886 vtkMath(const vtkMath&) = delete;
1887 void operator=(const vtkMath&) = delete;
1888};
1889
1890//----------------------------------------------------------------------------
1891inline float vtkMath::RadiansFromDegrees(float x)
1892{
1893 return x * 0.017453292f;
1894}
1895
1896//----------------------------------------------------------------------------
1897inline double vtkMath::RadiansFromDegrees(double x)
1898{
1899 return x * 0.017453292519943295;
1900}
1901
1902//----------------------------------------------------------------------------
1903inline float vtkMath::DegreesFromRadians(float x)
1904{
1905 return x * 57.2957795131f;
1906}
1907
1908//----------------------------------------------------------------------------
1909inline double vtkMath::DegreesFromRadians(double x)
1910{
1911 return x * 57.29577951308232;
1912}
1913
1914//----------------------------------------------------------------------------
1915inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
1916{
1917 return ((x != 0) & ((x & (x - 1)) == 0));
1918}
1919
1920//----------------------------------------------------------------------------
1921// Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1923{
1924 unsigned int z = static_cast<unsigned int>(((x > 0) ? x - 1 : 0));
1925 z |= z >> 1;
1926 z |= z >> 2;
1927 z |= z >> 4;
1928 z |= z >> 8;
1929 z |= z >> 16;
1930 return static_cast<int>(z + 1);
1931}
1932
1933//----------------------------------------------------------------------------
1934// Modify the trunc() operation provided by static_cast<int>() to get floor(),
1935// Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1936inline int vtkMath::Floor(double x)
1937{
1938 int i = static_cast<int>(x);
1939 return i - (i > x);
1940}
1941
1942//----------------------------------------------------------------------------
1943// Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1944// Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1945inline int vtkMath::Ceil(double x)
1946{
1947 int i = static_cast<int>(x);
1948 return i + (i < x);
1949}
1950
1951//----------------------------------------------------------------------------
1952template <class T>
1953inline T vtkMath::Min(const T& a, const T& b)
1954{
1955 return (b <= a ? b : a);
1956}
1957
1958//----------------------------------------------------------------------------
1959template <class T>
1960inline T vtkMath::Max(const T& a, const T& b)
1961{
1962 return (b > a ? b : a);
1963}
1964
1965//----------------------------------------------------------------------------
1966inline float vtkMath::Normalize(float v[3])
1967{
1968 float den = vtkMath::Norm(v);
1969 if (den != 0.0)
1970 {
1971 for (int i = 0; i < 3; ++i)
1972 {
1973 v[i] /= den;
1974 }
1975 }
1976 return den;
1977}
1978
1979//----------------------------------------------------------------------------
1980inline double vtkMath::Normalize(double v[3])
1981{
1982 double den = vtkMath::Norm(v);
1983 if (den != 0.0)
1984 {
1985 for (int i = 0; i < 3; ++i)
1986 {
1987 v[i] /= den;
1988 }
1989 }
1990 return den;
1991}
1992
1993//----------------------------------------------------------------------------
1994inline float vtkMath::Normalize2D(float v[2])
1995{
1996 float den = vtkMath::Norm2D(v);
1997 if (den != 0.0)
1998 {
1999 for (int i = 0; i < 2; ++i)
2000 {
2001 v[i] /= den;
2002 }
2003 }
2004 return den;
2005}
2006
2007//----------------------------------------------------------------------------
2008inline double vtkMath::Normalize2D(double v[2])
2009{
2010 double den = vtkMath::Norm2D(v);
2011 if (den != 0.0)
2012 {
2013 for (int i = 0; i < 2; ++i)
2014 {
2015 v[i] /= den;
2016 }
2017 }
2018 return den;
2019}
2020
2021//----------------------------------------------------------------------------
2022inline float vtkMath::Determinant3x3(const float c1[3], const float c2[3], const float c3[3])
2023{
2024 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
2025 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
2026}
2027
2028//----------------------------------------------------------------------------
2029inline double vtkMath::Determinant3x3(const double c1[3], const double c2[3], const double c3[3])
2030{
2031 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
2032 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
2033}
2034
2035//----------------------------------------------------------------------------
2037 double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3)
2038{
2039 return (a1 * vtkMath::Determinant2x2(b2, b3, c2, c3) -
2040 b1 * vtkMath::Determinant2x2(a2, a3, c2, c3) + c1 * vtkMath::Determinant2x2(a2, a3, b2, b3));
2041}
2042
2043//----------------------------------------------------------------------------
2044inline float vtkMath::Distance2BetweenPoints(const float p1[3], const float p2[3])
2045{
2046 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
2047 (p1[2] - p2[2]) * (p1[2] - p2[2]));
2048}
2049
2050//----------------------------------------------------------------------------
2051inline double vtkMath::Distance2BetweenPoints(const double p1[3], const double p2[3])
2052{
2053 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
2054 (p1[2] - p2[2]) * (p1[2] - p2[2]));
2055}
2056
2057//----------------------------------------------------------------------------
2058template <typename ReturnTypeT, typename TupleRangeT1, typename TupleRangeT2, typename EnableT>
2059inline ReturnTypeT vtkMath::Distance2BetweenPoints(const TupleRangeT1& p1, const TupleRangeT2& p2)
2060{
2061 return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
2062 (p1[2] - p2[2]) * (p1[2] - p2[2]));
2063}
2064
2065//----------------------------------------------------------------------------
2066template <class VectorT1, class VectorT2, class VectorT3>
2067void vtkMath::Cross(VectorT1&& a, VectorT2&& b, VectorT3& c)
2068{
2070 ValueType Cx = a[1] * b[2] - a[2] * b[1];
2071 ValueType Cy = a[2] * b[0] - a[0] * b[2];
2072 ValueType Cz = a[0] * b[1] - a[1] * b[0];
2073 c[0] = Cx;
2074 c[1] = Cy;
2075 c[2] = Cz;
2076}
2077
2078//----------------------------------------------------------------------------
2079// Cross product of two 3-vectors. Result (a x b) is stored in c[3].
2080inline void vtkMath::Cross(const float a[3], const float b[3], float c[3])
2081{
2082 float Cx = a[1] * b[2] - a[2] * b[1];
2083 float Cy = a[2] * b[0] - a[0] * b[2];
2084 float Cz = a[0] * b[1] - a[1] * b[0];
2085 c[0] = Cx;
2086 c[1] = Cy;
2087 c[2] = Cz;
2088}
2089
2090//----------------------------------------------------------------------------
2091// Cross product of two 3-vectors. Result (a x b) is stored in c[3].
2092inline void vtkMath::Cross(const double a[3], const double b[3], double c[3])
2093{
2094 double Cx = a[1] * b[2] - a[2] * b[1];
2095 double Cy = a[2] * b[0] - a[0] * b[2];
2096 double Cz = a[0] * b[1] - a[1] * b[0];
2097 c[0] = Cx;
2098 c[1] = Cy;
2099 c[2] = Cz;
2100}
2101
2102//----------------------------------------------------------------------------
2103template <class T>
2104inline double vtkDeterminant3x3(const T A[3][3])
2105{
2106 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] -
2107 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];
2108}
2109
2110//----------------------------------------------------------------------------
2111inline double vtkMath::Determinant3x3(const float A[3][3])
2112{
2113 return vtkDeterminant3x3(A);
2114}
2115
2116//----------------------------------------------------------------------------
2117inline double vtkMath::Determinant3x3(const double A[3][3])
2118{
2119 return vtkDeterminant3x3(A);
2120}
2121
2122//----------------------------------------------------------------------------
2123template <class T>
2124inline T vtkMath::ClampValue(const T& value, const T& min, const T& max)
2125{
2126 assert("pre: valid_range" && min <= max);
2127 return std::clamp(value, min, max);
2128}
2129
2130//----------------------------------------------------------------------------
2131inline void vtkMath::ClampValue(double* value, const double range[2])
2132{
2133 if (value && range)
2134 {
2135 assert("pre: valid_range" && range[0] <= range[1]);
2136
2137 *value = vtkMath::ClampValue(*value, range[0], range[1]);
2138 }
2139}
2140
2141//----------------------------------------------------------------------------
2142inline void vtkMath::ClampValue(double value, const double range[2], double* clamped_value)
2143{
2144 if (range && clamped_value)
2145 {
2146 assert("pre: valid_range" && range[0] <= range[1]);
2147
2148 *clamped_value = vtkMath::ClampValue(value, range[0], range[1]);
2149 }
2150}
2151
2152// ---------------------------------------------------------------------------
2153inline double vtkMath::ClampAndNormalizeValue(double value, const double range[2])
2154{
2155 assert("pre: valid_range" && range[0] <= range[1]);
2156
2157 double result;
2158 if (range[0] == range[1])
2159 {
2160 result = 0.0;
2161 }
2162 else
2163 {
2164 // clamp
2165 result = vtkMath::ClampValue(value, range[0], range[1]);
2166
2167 // normalize
2168 result = (result - range[0]) / (range[1] - range[0]);
2169 }
2170
2171 assert("post: valid_result" && result >= 0.0 && result <= 1.0);
2172
2173 return result;
2174}
2175
2176//-----------------------------------------------------------------------------
2177template <class T1, class T2>
2178inline void vtkMath::TensorFromSymmetricTensor(const T1 symmTensor[9], T2 tensor[9])
2179{
2180 for (int i = 0; i < 3; ++i)
2181 {
2182 tensor[4 * i] = symmTensor[i];
2183 }
2184 tensor[1] = tensor[3] = symmTensor[3];
2185 tensor[2] = tensor[6] = symmTensor[5];
2186 tensor[5] = tensor[7] = symmTensor[4];
2187}
2188
2189//-----------------------------------------------------------------------------
2190template <class T>
2192{
2193 tensor[6] = tensor[5]; // XZ
2194 tensor[7] = tensor[4]; // YZ
2195 tensor[8] = tensor[2]; // ZZ
2196 tensor[4] = tensor[1]; // YY
2197 tensor[5] = tensor[7]; // YZ
2198 tensor[2] = tensor[6]; // XZ
2199 tensor[1] = tensor[3]; // XY
2200}
2201VTK_ABI_NAMESPACE_END
2202
2203namespace
2204{
2205template <class QuaternionT, class MatrixT>
2206inline void vtkQuaternionToMatrix3x3(QuaternionT&& quat, MatrixT&& A)
2207{
2209
2210 Scalar ww = quat[0] * quat[0];
2211 Scalar wx = quat[0] * quat[1];
2212 Scalar wy = quat[0] * quat[2];
2213 Scalar wz = quat[0] * quat[3];
2214
2215 Scalar xx = quat[1] * quat[1];
2216 Scalar yy = quat[2] * quat[2];
2217 Scalar zz = quat[3] * quat[3];
2218
2219 Scalar xy = quat[1] * quat[2];
2220 Scalar xz = quat[1] * quat[3];
2221 Scalar yz = quat[2] * quat[3];
2222
2223 Scalar rr = xx + yy + zz;
2224 // normalization factor, just in case quaternion was not normalized
2225 Scalar f = 1 / (ww + rr);
2226 Scalar s = (ww - rr) * f;
2227 f *= 2;
2228
2230
2231 Wrapper::template Get<0, 0>(std::forward<MatrixT>(A)) = xx * f + s;
2232 Wrapper::template Get<1, 0>(std::forward<MatrixT>(A)) = (xy + wz) * f;
2233 Wrapper::template Get<2, 0>(std::forward<MatrixT>(A)) = (xz - wy) * f;
2234
2235 Wrapper::template Get<0, 1>(std::forward<MatrixT>(A)) = (xy - wz) * f;
2236 Wrapper::template Get<1, 1>(std::forward<MatrixT>(A)) = yy * f + s;
2237 Wrapper::template Get<2, 1>(std::forward<MatrixT>(A)) = (yz + wx) * f;
2238
2239 Wrapper::template Get<0, 2>(std::forward<MatrixT>(A)) = (xz + wy) * f;
2240 Wrapper::template Get<1, 2>(std::forward<MatrixT>(A)) = (yz - wx) * f;
2241 Wrapper::template Get<2, 2>(std::forward<MatrixT>(A)) = zz * f + s;
2242}
2243} // anonymous namespace
2244
2245VTK_ABI_NAMESPACE_BEGIN
2246//------------------------------------------------------------------------------
2247inline void vtkMath::QuaternionToMatrix3x3(const float quat[4], float A[3][3])
2248{
2249 vtkQuaternionToMatrix3x3(quat, A);
2250}
2251
2252//------------------------------------------------------------------------------
2253inline void vtkMath::QuaternionToMatrix3x3(const double quat[4], double A[3][3])
2254{
2255 vtkQuaternionToMatrix3x3(quat, A);
2256}
2257
2258//-----------------------------------------------------------------------------
2259template <class QuaternionT, class MatrixT, class EnableT>
2260inline void vtkMath::QuaternionToMatrix3x3(QuaternionT&& q, MatrixT&& A)
2261{
2262 vtkQuaternionToMatrix3x3(std::forward<QuaternionT>(q), std::forward<MatrixT>(A));
2263}
2264VTK_ABI_NAMESPACE_END
2265
2266namespace
2267{
2268//------------------------------------------------------------------------------
2269// The solution is based on
2270// Berthold K. P. Horn (1987),
2271// "Closed-form solution of absolute orientation using unit quaternions,"
2272// Journal of the Optical Society of America A, 4:629-642
2273template <class MatrixT, class QuaternionT>
2274inline void vtkMatrix3x3ToQuaternion(MatrixT&& A, QuaternionT&& quat)
2275{
2277
2278 Scalar N[4][4];
2279
2281
2282 // on-diagonal elements
2283 N[0][0] = Wrapper::template Get<0, 0>(std::forward<MatrixT>(A)) +
2284 Wrapper::template Get<1, 1>(std::forward<MatrixT>(A)) +
2285 Wrapper::template Get<2, 2>(std::forward<MatrixT>(A));
2286 N[1][1] = Wrapper::template Get<0, 0>(std::forward<MatrixT>(A)) -
2287 Wrapper::template Get<1, 1>(std::forward<MatrixT>(A)) -
2288 Wrapper::template Get<2, 2>(std::forward<MatrixT>(A));
2289 N[2][2] = -Wrapper::template Get<0, 0>(std::forward<MatrixT>(A)) +
2290 Wrapper::template Get<1, 1>(std::forward<MatrixT>(A)) -
2291 Wrapper::template Get<2, 2>(std::forward<MatrixT>(A));
2292 N[3][3] = -Wrapper::template Get<0, 0>(std::forward<MatrixT>(A)) -
2293 Wrapper::template Get<1, 1>(std::forward<MatrixT>(A)) +
2294 Wrapper::template Get<2, 2>(std::forward<MatrixT>(A));
2295
2296 // off-diagonal elements
2297 N[0][1] = N[1][0] = Wrapper::template Get<2, 1>(std::forward<MatrixT>(A)) -
2298 Wrapper::template Get<1, 2>(std::forward<MatrixT>(A));
2299 N[0][2] = N[2][0] = Wrapper::template Get<0, 2>(std::forward<MatrixT>(A)) -
2300 Wrapper::template Get<2, 0>(std::forward<MatrixT>(A));
2301 N[0][3] = N[3][0] = Wrapper::template Get<1, 0>(std::forward<MatrixT>(A)) -
2302 Wrapper::template Get<0, 1>(std::forward<MatrixT>(A));
2303
2304 N[1][2] = N[2][1] = Wrapper::template Get<1, 0>(std::forward<MatrixT>(A)) +
2305 Wrapper::template Get<0, 1>(std::forward<MatrixT>(A));
2306 N[1][3] = N[3][1] = Wrapper::template Get<0, 2>(std::forward<MatrixT>(A)) +
2307 Wrapper::template Get<2, 0>(std::forward<MatrixT>(A));
2308 N[2][3] = N[3][2] = Wrapper::template Get<2, 1>(std::forward<MatrixT>(A)) +
2309 Wrapper::template Get<1, 2>(std::forward<MatrixT>(A));
2310
2311 Scalar eigenvectors[4][4], eigenvalues[4];
2312
2313 // convert into format that JacobiN can use,
2314 // then use Jacobi to find eigenvalues and eigenvectors
2315 Scalar *NTemp[4], *eigenvectorsTemp[4];
2316 for (int i = 0; i < 4; ++i)
2317 {
2318 NTemp[i] = N[i];
2319 eigenvectorsTemp[i] = eigenvectors[i];
2320 }
2321 vtkMath::JacobiN(NTemp, 4, eigenvalues, eigenvectorsTemp);
2322
2323 // the first eigenvector is the one we want
2324 quat[0] = eigenvectors[0][0];
2325 quat[1] = eigenvectors[1][0];
2326 quat[2] = eigenvectors[2][0];
2327 quat[3] = eigenvectors[3][0];
2328}
2329} // anonymous namespace
2330
2331VTK_ABI_NAMESPACE_BEGIN
2332//------------------------------------------------------------------------------
2333inline void vtkMath::Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
2334{
2335 vtkMatrix3x3ToQuaternion(A, quat);
2336}
2337
2338//------------------------------------------------------------------------------
2339inline void vtkMath::Matrix3x3ToQuaternion(const double A[3][3], double quat[4])
2340{
2341 vtkMatrix3x3ToQuaternion(A, quat);
2342}
2343
2344//-----------------------------------------------------------------------------
2345template <class MatrixT, class QuaternionT, class EnableT>
2346inline void vtkMath::Matrix3x3ToQuaternion(MatrixT&& A, QuaternionT&& q)
2347{
2348 vtkMatrix3x3ToQuaternion(std::forward<MatrixT>(A), std::forward<QuaternionT>(q));
2349}
2350VTK_ABI_NAMESPACE_END
2351
2352namespace vtk_detail
2353{
2354VTK_ABI_NAMESPACE_BEGIN
2355// Can't specialize templates inside a template class, so we move the impl here.
2356template <typename OutT>
2357void RoundDoubleToIntegralIfNecessary(double val, OutT* ret)
2358{ // OutT is integral -- clamp and round
2359 if (!vtkMath::IsNan(val))
2360 {
2361 double min = static_cast<double>(vtkTypeTraits<OutT>::Min());
2362 double max = static_cast<double>(vtkTypeTraits<OutT>::Max());
2363 val = vtkMath::ClampValue(val, min, max);
2364 *ret = static_cast<OutT>((val >= 0.0) ? (val + 0.5) : (val - 0.5));
2365 }
2366 else
2367 *ret = 0;
2368}
2369template <>
2370inline void RoundDoubleToIntegralIfNecessary(double val, double* retVal)
2371{ // OutT is double: passthrough
2372 *retVal = val;
2373}
2374template <>
2375inline void RoundDoubleToIntegralIfNecessary(double val, float* retVal)
2376{ // OutT is float -- just clamp (as doubles, then the cast to float is well-defined.)
2377 if (!vtkMath::IsNan(val))
2378 {
2379 double min = static_cast<double>(vtkTypeTraits<float>::Min());
2380 double max = static_cast<double>(vtkTypeTraits<float>::Max());
2381 val = vtkMath::ClampValue(val, min, max);
2382 }
2383
2384 *retVal = static_cast<float>(val);
2385}
2386VTK_ABI_NAMESPACE_END
2387} // end namespace vtk_detail
2388
2389VTK_ABI_NAMESPACE_BEGIN
2390//-----------------------------------------------------------------------------
2391#if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
2392#define VTK_MATH_ISINF_IS_INLINE
2393inline vtkTypeBool vtkMath::IsInf(double x)
2394{
2395#if defined(VTK_HAS_STD_ISINF)
2396 return std::isinf(x);
2397#else
2398 return (isinf(x) != 0); // Force conversion to bool
2399#endif
2400}
2401#endif
2402
2403//-----------------------------------------------------------------------------
2404#if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
2405#define VTK_MATH_ISNAN_IS_INLINE
2406inline vtkTypeBool vtkMath::IsNan(double x)
2407{
2408#if defined(VTK_HAS_STD_ISNAN)
2409 return std::isnan(x);
2410#else
2411 return (isnan(x) != 0); // Force conversion to bool
2412#endif
2413}
2414#endif
2415
2416//-----------------------------------------------------------------------------
2417#if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
2418#define VTK_MATH_ISFINITE_IS_INLINE
2419inline bool vtkMath::IsFinite(double x)
2420{
2421#if defined(VTK_HAS_STD_ISFINITE)
2422 return std::isfinite(x);
2423#elif defined(VTK_HAS_ISFINITE)
2424 return (isfinite(x) != 0); // Force conversion to bool
2425#else
2426 return (finite(x) != 0); // Force conversion to bool
2427#endif
2428}
2429#endif
2430
2431VTK_ABI_NAMESPACE_END
2432#endif
RealT mt
Definition PyrC2Basis.h:39
RealT ww
Definition PyrI2Basis.h:13
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
abstract superclass for arrays of numeric data
a simple class to control print indentation
Definition vtkIndent.h:108
performs common math operations
Definition vtkMath.h:188
static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1 &p1, const TupleRangeT2 &p2)
Compute distance squared between two points p1 and p2.
Definition vtkMath.h:2059
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:589
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:1790
static void XYZToProLab(const double xyz[3], double prolab[3])
Convert Color from the CIE XYZ system to ProLAB.
Definition vtkMath.h:1507
static double Norm2D(const double x[2])
Compute the norm of a 2-vector.
Definition vtkMath.h:865
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:1870
static void Subtract(const float a[3], const float b[3], float c[3])
Subtraction of two 3-vectors (float version).
Definition vtkMath.h:498
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:830
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:1883
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:473
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:677
static ReturnTypeT Dot(const TupleRangeT1 &a, const TupleRangeT2 &b)
Compute dot product between two points p1 and p2.
Definition vtkMath.h:613
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:1024
static void XYZToLab(const double xyz[3], double lab[3])
Convert Color from the CIE XYZ system to CIE-L*ab.
Definition vtkMath.h:1529
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static vtkTypeInt64 Factorial(int N)
Compute N factorial, N! = N*(N-1) * (N-2)...*3*2*1.
static vtkTypeInt64 Binomial(int m, int n)
The number of combinations of n objects from a pool of m objects (m>n).
static double Random()
Generate pseudo-random numbers distributed according to the uniform distribution between 0....
static void 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:1111
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:1518
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:581
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:546
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:1478
static void Assign(const double a[3], double b[3])
Assign values to a 3-vector (double version).
Definition vtkMath.h:457
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:892
static T Max(const T &a, const T &b)
Returns the maximum of the two arguments provided.
Definition vtkMath.h:1960
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:844
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:570
static void LabToRGB(double L, double a, double b, double *red, double *green, double *blue)
Convert color from the CIE-L*ab system to RGB.
static double Gaussian()
Generate pseudo-random numbers distributed according to the standard normal distribution.
static int Ceil(double x)
Rounds a double to the nearest integer not less than itself.
Definition vtkMath.h:1945
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:1483
~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:1007
static void RGBToXYZ(const double rgb[3], double xyz[3])
Convert color from the RGB system to CIE XYZ.
Definition vtkMath.h:1551
static void QuaternionToMatrix3x3(const float quat[4], float A[3][3])
Convert a quaternion to a 3x3 rotation matrix.
Definition vtkMath.h:2247
static int NearestPowerOfTwo(int x)
Compute the nearest power of two that is not less than x.
Definition vtkMath.h:1922
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:1134
static float Normalize2D(float v[2])
Normalize (in place) a 2-vector.
Definition vtkMath.h:1994
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:635
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:447
static float RadiansFromDegrees(float degrees)
Convert degrees into radians.
Definition vtkMath.h:1891
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:1825
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:462
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:1495
static vtkTypeBool AreBoundsInitialized(const double bounds[6])
Are the bounds initialized?
Definition vtkMath.h:1629
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:509
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:1592
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:2333
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:1540
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:2153
static void MultiplyScalar(double a[3], double s)
Multiplies a 3-vector by a scalar (double version).
Definition vtkMath.h:558
static double Dot2D(const double x[2], const double y[2])
Dot product of two 2-vectors.
Definition vtkMath.h:825
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:1566
static void ProLabToRGB(const double prolab[3], double rgb[3])
Convert color from the ProLab system to RGB.
Definition vtkMath.h:1577
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
Definition vtkMath.h:1936
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:523
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:891
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:1463
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:1903
static float Determinant2x2(const float c1[2], const float c2[2])
Compute determinant of 2x2 matrix.
Definition vtkMath.h:882
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:1614
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:621
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:682
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 bool IsPowerOfTwo(vtkTypeUInt64 x)
Returns true if integer is a power of two.
Definition vtkMath.h:1915
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:1966
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:697
static double Determinant3x3(const float A[3][3])
Return the determinant of a 3x3 matrix.
Definition vtkMath.h:2111
static float Dot2D(const float x[2], const float y[2])
Dot product of two 2-vectors.
Definition vtkMath.h:820
ConvolutionMode
Support the convolution operations.
Definition vtkMath.h:1796
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:1458
static void Add(VectorT1 &&a, VectorT2 &&b, VectorT3 &c)
Addition of two 3-vectors (double version).
Definition vtkMath.h:487
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:1067
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:1603
static float Norm2D(const float x[2])
Compute the norm of a 2-vector.
Definition vtkMath.h:859
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:534
static T Min(const T &a, const T &b)
Returns the minimum of the two arguments provided.
Definition vtkMath.h:1953
static void InvertMatrix(MatrixT1 &&M1, MatrixT2 &&M2)
Computes the inverse of input matrix M1 into M2.
Definition vtkMath.h:1090
static void Cross(VectorT1 &&a, VectorT2 &&b, VectorT3 &c)
Cross product of two 3-vectors.
Definition vtkMath.h:2067
static void MultiplyMatrix(MatrixT1 &&M1, MatrixT2 &&M2, MatrixT3 &&M3)
Multiply matrices such that M3 = M1 x M2.
Definition vtkMath.h:966
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:2124
static vtkTypeBool SolveLeastSquares(int numberOfSamples, double **xt, int xOrder, double **yt, int yOrder, double **mt, int checkHomogeneous=1)
Solves for the least squares best fit matrix for the equation X'M' = Y'.
static void Identity3x3(double A[3][3])
Set A to the identity matrix.
static void LUFactor3x3(double A[3][3], int index[3])
LU Factorization of a 3x3 matrix.
static vtkTypeBool LUFactorLinearSystem(double **A, int *index, int size)
Factor linear equations Ax = b using LU decomposition into the form A = LU where L is a unit lower tr...
static void RGBToLab(double red, double green, double blue, double *L, double *a, double *b)
Convert color from the RGB system to CIE-L*ab.
static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4])
Multiply two quaternions.
static 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 vtkMatrixUtilities::ScalarTypeExtractor< VectorT >::value_type SquaredNorm(VectorT &&x)
Computes the dot product between 2 vectors x and y.
Definition vtkMath.h:1043
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:994
Park and Miller Sequence of pseudo random numbers.
abstract base class for most VTK objects
Definition vtkObject.h:162
represent and manipulate 3D points
Definition vtkPoints.h:139
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:2357
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
double vtkDeterminant3x3(const T A[3][3])
Definition vtkMath.h:2104
int vtkIdType
Definition vtkType.h:332
#define max(a, b)