VTK  9.2.6
vtkMath.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkMath.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================
15  Copyright 2011 Sandia Corporation.
16  Under the terms of Contract DE-AC04-94AL85000, there is a non-exclusive
17  license for use of this work by or on behalf of the
18  U.S. Government. Redistribution and use in source and binary forms, with
19  or without modification, are permitted provided that this Notice and any
20  statement of authorship are reproduced on all copies.
21 
22  Contact: pppebay@sandia.gov,dcthomp@sandia.gov
23 
24 =========================================================================*/
45 #ifndef vtkMath_h
46 #define vtkMath_h
47 
48 #include "vtkCommonCoreModule.h" // For export macro
49 #include "vtkMathPrivate.hxx" // For Matrix meta-class helpers
50 #include "vtkMatrixUtilities.h" // For Matrix wrapping / mapping
51 #include "vtkObject.h"
52 #include "vtkSmartPointer.h" // For vtkSmartPointer.
53 #include "vtkTypeTraits.h" // For type traits
54 
55 #include "vtkMathConfigure.h" // For <cmath> and VTK_HAS_ISNAN etc.
56 
57 #include <algorithm> // for std::clamp
58 #include <cassert> // assert() in inline implementations.
59 
60 #ifndef DBL_MIN
61 #define VTK_DBL_MIN 2.2250738585072014e-308
62 #else // DBL_MIN
63 #define VTK_DBL_MIN DBL_MIN
64 #endif // DBL_MIN
65 
66 #ifndef DBL_EPSILON
67 #define VTK_DBL_EPSILON 2.2204460492503131e-16
68 #else // DBL_EPSILON
69 #define VTK_DBL_EPSILON DBL_EPSILON
70 #endif // DBL_EPSILON
71 
72 #ifndef VTK_DBL_EPSILON
73 #ifndef DBL_EPSILON
74 #define VTK_DBL_EPSILON 2.2204460492503131e-16
75 #else // DBL_EPSILON
76 #define VTK_DBL_EPSILON DBL_EPSILON
77 #endif // DBL_EPSILON
78 #endif // VTK_DBL_EPSILON
79 
80 class vtkDataArray;
81 class vtkPoints;
82 class vtkMathInternal;
85 
86 namespace vtk_detail
87 {
88 // forward declaration
89 template <typename OutT>
90 void RoundDoubleToIntegralIfNecessary(double val, OutT* ret);
91 } // end namespace vtk_detail
92 
93 class VTKCOMMONCORE_EXPORT vtkMath : public vtkObject
94 {
95 public:
96  static vtkMath* New();
97  vtkTypeMacro(vtkMath, vtkObject);
98  void PrintSelf(ostream& os, vtkIndent indent) override;
99 
103  static constexpr double Pi() { return 3.141592653589793; }
104 
106 
109  static float RadiansFromDegrees(float degrees);
110  static double RadiansFromDegrees(double degrees);
112 
114 
117  static float DegreesFromRadians(float radians);
118  static double DegreesFromRadians(double radians);
120 
124 #if 1
125  static int Round(float f) { return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
126  static int Round(double f) { return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
127 #endif
128 
133  template <typename OutT>
134  static void RoundDoubleToIntegralIfNecessary(double val, OutT* ret)
135  {
136  // Can't specialize template methods in a template class, so we move the
137  // implementations to a external namespace.
139  }
140 
146  static int Floor(double x);
147 
153  static int Ceil(double x);
154 
160  static int CeilLog2(vtkTypeUInt64 x);
161 
166  template <class T>
167  static T Min(const T& a, const T& b);
168 
173  template <class T>
174  static T Max(const T& a, const T& b);
175 
179  static bool IsPowerOfTwo(vtkTypeUInt64 x);
180 
186  static int NearestPowerOfTwo(int x);
187 
192  static vtkTypeInt64 Factorial(int N);
193 
199  static vtkTypeInt64 Binomial(int m, int n);
200 
212  static int* BeginCombination(int m, int n);
213 
224  static int NextCombination(int m, int n, int* combination);
225 
229  static void FreeCombination(int* combination);
230 
246  static void RandomSeed(int s);
247 
259  static int GetSeed();
260 
274  static double Random();
275 
288  static double Random(double min, double max);
289 
302  static double Gaussian();
303 
316  static double Gaussian(double mean, double std);
317 
322  template <class VectorT1, class VectorT2>
323  static void Assign(const VectorT1& a, VectorT2&& b)
324  {
325  b[0] = a[0];
326  b[1] = a[1];
327  b[2] = a[2];
328  }
329 
333  static void Assign(const double a[3], double b[3]) { vtkMath::Assign<>(a, b); }
334 
338  static void Add(const float a[3], const float b[3], float c[3])
339  {
340  for (int i = 0; i < 3; ++i)
341  {
342  c[i] = a[i] + b[i];
343  }
344  }
345 
349  static void Add(const double a[3], const double b[3], double c[3])
350  {
351  for (int i = 0; i < 3; ++i)
352  {
353  c[i] = a[i] + b[i];
354  }
355  }
356 
360  static void Subtract(const float a[3], const float b[3], float c[3])
361  {
362  for (int i = 0; i < 3; ++i)
363  {
364  c[i] = a[i] - b[i];
365  }
366  }
367 
371  static void Subtract(const double a[3], const double b[3], double c[3])
372  {
373  for (int i = 0; i < 3; ++i)
374  {
375  c[i] = a[i] - b[i];
376  }
377  }
378 
384  template <class VectorT1, class VectorT2, class VectorT3>
385  static void Subtract(const VectorT1& a, const VectorT2& b, VectorT3&& c)
386  {
387  c[0] = a[0] - b[0];
388  c[1] = a[1] - b[1];
389  c[2] = a[2] - b[2];
390  }
391 
396  static void MultiplyScalar(float a[3], float s)
397  {
398  for (int i = 0; i < 3; ++i)
399  {
400  a[i] *= s;
401  }
402  }
403 
408  static void MultiplyScalar2D(float a[2], float s)
409  {
410  for (int i = 0; i < 2; ++i)
411  {
412  a[i] *= s;
413  }
414  }
415 
420  static void MultiplyScalar(double a[3], double s)
421  {
422  for (int i = 0; i < 3; ++i)
423  {
424  a[i] *= s;
425  }
426  }
427 
432  static void MultiplyScalar2D(double a[2], double s)
433  {
434  for (int i = 0; i < 2; ++i)
435  {
436  a[i] *= s;
437  }
438  }
439 
443  static float Dot(const float a[3], const float b[3])
444  {
445  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
446  }
447 
451  static double Dot(const double a[3], const double b[3])
452  {
453  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
454  }
455 
471  template <typename ReturnTypeT = double, typename TupleRangeT1, typename TupleRangeT2,
472  typename EnableT = typename std::conditional<!std::is_pointer<TupleRangeT1>::value &&
474  TupleRangeT1, TupleRangeT2>::type::value_type>
475  static ReturnTypeT Dot(const TupleRangeT1& a, const TupleRangeT2& b)
476  {
477  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
478  }
479 
483  static void Outer(const float a[3], const float b[3], float c[3][3])
484  {
485  for (int i = 0; i < 3; ++i)
486  {
487  for (int j = 0; j < 3; ++j)
488  {
489  c[i][j] = a[i] * b[j];
490  }
491  }
492  }
493 
497  static void Outer(const double a[3], const double b[3], double c[3][3])
498  {
499  for (int i = 0; i < 3; ++i)
500  {
501  for (int j = 0; j < 3; ++j)
502  {
503  c[i][j] = a[i] * b[j];
504  }
505  }
506  }
507 
512  static void Cross(const float a[3], const float b[3], float c[3]);
513 
518  static void Cross(const double a[3], const double b[3], double c[3]);
519 
521 
524  static float Norm(const float* x, int n);
525  static double Norm(const double* x, int n);
527 
531  static float Norm(const float v[3]) { return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); }
532 
536  static double Norm(const double v[3])
537  {
538  return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
539  }
540 
550  template <typename ReturnTypeT = double, typename TupleRangeT>
551  static ReturnTypeT SquaredNorm(const TupleRangeT& v)
552  {
553  return v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
554  }
555 
560  static float Normalize(float v[3]);
561 
566  static double Normalize(double v[3]);
567 
569 
576  static void Perpendiculars(const double v1[3], double v2[3], double v3[3], double theta);
577  static void Perpendiculars(const float v1[3], float v2[3], float v3[3], double theta);
579 
581 
586  static bool ProjectVector(const float a[3], const float b[3], float projection[3]);
587  static bool ProjectVector(const double a[3], const double b[3], double projection[3]);
589 
591 
597  static bool ProjectVector2D(const float a[2], const float b[2], float projection[2]);
598  static bool ProjectVector2D(const double a[2], const double b[2], double projection[2]);
600 
616  template <typename ReturnTypeT = double, typename TupleRangeT1, typename TupleRangeT2,
617  typename EnableT = typename std::conditional<!std::is_pointer<TupleRangeT1>::value &&
619  TupleRangeT1, TupleRangeT2>::type::value_type>
620  static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1& p1, const TupleRangeT2& p2);
621 
626  static float Distance2BetweenPoints(const float p1[3], const float p2[3]);
627 
632  static double Distance2BetweenPoints(const double p1[3], const double p2[3]);
633 
637  static double AngleBetweenVectors(const double v1[3], const double v2[3]);
638 
642  static double SignedAngleBetweenVectors(
643  const double v1[3], const double v2[3], const double vn[3]);
644 
649  static double GaussianAmplitude(const double variance, const double distanceFromMean);
650 
655  static double GaussianAmplitude(const double mean, const double variance, const double position);
656 
662  static double GaussianWeight(const double variance, const double distanceFromMean);
663 
669  static double GaussianWeight(const double mean, const double variance, const double position);
670 
674  static float Dot2D(const float x[2], const float y[2]) { return x[0] * y[0] + x[1] * y[1]; }
675 
679  static double Dot2D(const double x[2], const double y[2]) { return x[0] * y[0] + x[1] * y[1]; }
680 
684  static void Outer2D(const float x[2], const float y[2], float A[2][2])
685  {
686  for (int i = 0; i < 2; ++i)
687  {
688  for (int j = 0; j < 2; ++j)
689  {
690  A[i][j] = x[i] * y[j];
691  }
692  }
693  }
694 
698  static void Outer2D(const double x[2], const double y[2], double A[2][2])
699  {
700  for (int i = 0; i < 2; ++i)
701  {
702  for (int j = 0; j < 2; ++j)
703  {
704  A[i][j] = x[i] * y[j];
705  }
706  }
707  }
708 
713  static float Norm2D(const float x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
714 
719  static double Norm2D(const double x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
720 
725  static float Normalize2D(float v[2]);
726 
731  static double Normalize2D(double v[2]);
732 
736  static float Determinant2x2(const float c1[2], const float c2[2])
737  {
738  return c1[0] * c2[1] - c2[0] * c1[1];
739  }
740 
742 
745  static double Determinant2x2(double a, double b, double c, double d) { return a * d - b * c; }
746  static double Determinant2x2(const double c1[2], const double c2[2])
747  {
748  return c1[0] * c2[1] - c2[0] * c1[1];
749  }
751 
753 
756  static void LUFactor3x3(float A[3][3], int index[3]);
757  static void LUFactor3x3(double A[3][3], int index[3]);
759 
761 
764  static void LUSolve3x3(const float A[3][3], const int index[3], float x[3]);
765  static void LUSolve3x3(const double A[3][3], const int index[3], double x[3]);
767 
769 
773  static void LinearSolve3x3(const float A[3][3], const float x[3], float y[3]);
774  static void LinearSolve3x3(const double A[3][3], const double x[3], double y[3]);
776 
778 
781  static void Multiply3x3(const float A[3][3], const float v[3], float u[3]);
782  static void Multiply3x3(const double A[3][3], const double v[3], double u[3]);
784 
786 
789  static void Multiply3x3(const float A[3][3], const float B[3][3], float C[3][3]);
790  static void Multiply3x3(const double A[3][3], const double B[3][3], double C[3][3]);
792 
816  template <int RowsT, int MidDimT, int ColsT,
817  class LayoutT1 = vtkMatrixUtilities::Layout::Identity,
818  class LayoutT2 = vtkMatrixUtilities::Layout::Identity, class MatrixT1, class MatrixT2,
819  class MatrixT3>
820  static void MultiplyMatrix(const MatrixT1& M1, const MatrixT2& M2, MatrixT3&& M3)
821  {
822  vtkMathPrivate::MultiplyMatrix<RowsT, MidDimT, ColsT, LayoutT1, LayoutT2>::Compute(M1, M2, M3);
823  }
824 
845  template <int RowsT, int ColsT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
846  class MatrixT, class VectorT1, class VectorT2>
847  static void MultiplyMatrixWithVector(const MatrixT& M, const VectorT1& X, VectorT2&& Y)
848  {
849  vtkMathPrivate::MultiplyMatrix<RowsT, ColsT, 1, LayoutT>::Compute(M, X, Y);
850  }
851 
857  template <class ScalarT, int SizeT, class VectorT1, class VectorT2>
858  static ScalarT Dot(const VectorT1& x, const VectorT2& y)
859  {
860  return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
861  vtkMatrixUtilities::Layout::Identity, vtkMatrixUtilities::Layout::Transpose>::Compute(x, y);
862  }
863 
880  template <int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity, class MatrixT>
882  const MatrixT& M)
883  {
884  return vtkMathPrivate::Determinant<SizeT, LayoutT>::Compute(M);
885  }
886 
902  template <int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity, class MatrixT1,
903  class MatrixT2>
904  static void InvertMatrix(const MatrixT1& M1, MatrixT2&& M2)
905  {
906  vtkMathPrivate::InvertMatrix<SizeT, LayoutT>::Compute(M1, M2);
907  }
908 
922  template <int RowsT, int ColsT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
923  class MatrixT, class VectorT1, class VectorT2>
924  static void LinearSolve(const MatrixT& M, const VectorT1& x, VectorT2& y)
925  {
926  vtkMathPrivate::LinearSolve<RowsT, ColsT, LayoutT>::Compute(M, x, y);
927  }
928 
943  template <class ScalarT, int SizeT, class LayoutT = vtkMatrixUtilities::Layout::Identity,
944  class VectorT1, class MatrixT, class VectorT2>
945  static ScalarT Dot(const VectorT1& x, const MatrixT& M, const VectorT2& y)
946  {
947  ScalarT tmp[SizeT];
948  vtkMathPrivate::MultiplyMatrix<SizeT, SizeT, 1, LayoutT>::Compute(M, y, tmp);
949  return vtkMathPrivate::ContractRowWithCol<ScalarT, 1, SizeT, 1, 0, 0,
950  vtkMatrixUtilities::Layout::Identity, vtkMatrixUtilities::Layout::Transpose>::Compute(x, tmp);
951  }
952 
958  static void MultiplyMatrix(const double* const* A, const double* const* B, unsigned int rowA,
959  unsigned int colA, unsigned int rowB, unsigned int colB, double** C);
960 
962 
966  static void Transpose3x3(const float A[3][3], float AT[3][3]);
967  static void Transpose3x3(const double A[3][3], double AT[3][3]);
969 
971 
975  static void Invert3x3(const float A[3][3], float AI[3][3]);
976  static void Invert3x3(const double A[3][3], double AI[3][3]);
978 
980 
983  static void Identity3x3(float A[3][3]);
984  static void Identity3x3(double A[3][3]);
986 
988 
991  static double Determinant3x3(const float A[3][3]);
992  static double Determinant3x3(const double A[3][3]);
994 
998  static float Determinant3x3(const float c1[3], const float c2[3], const float c3[3]);
999 
1003  static double Determinant3x3(const double c1[3], const double c2[3], const double c3[3]);
1004 
1011  static double Determinant3x3(double a1, double a2, double a3, double b1, double b2, double b3,
1012  double c1, double c2, double c3);
1013 
1015 
1022  static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
1023  static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
1024  template <class QuaternionT, class MatrixT,
1025  class EnableT = typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::type>
1026  static void QuaternionToMatrix3x3(const QuaternionT& q, MatrixT&& A);
1028 
1030 
1039  static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
1040  static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
1041  template <class MatrixT, class QuaternionT,
1042  class EnableT = typename std::enable_if<!vtkMatrixUtilities::MatrixIs2DArray<MatrixT>()>::type>
1043  static void Matrix3x3ToQuaternion(const MatrixT& A, QuaternionT&& q);
1045 
1047 
1053  static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4]);
1054  static void MultiplyQuaternion(const double q1[4], const double q2[4], double q[4]);
1056 
1058 
1062  static void RotateVectorByNormalizedQuaternion(const float v[3], const float q[4], float r[3]);
1063  static void RotateVectorByNormalizedQuaternion(const double v[3], const double q[4], double r[3]);
1065 
1067 
1071  static void RotateVectorByWXYZ(const float v[3], const float q[4], float r[3]);
1072  static void RotateVectorByWXYZ(const double v[3], const double q[4], double r[3]);
1074 
1076 
1081  static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
1082  static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
1084 
1086 
1092  static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
1093  static void Diagonalize3x3(const double A[3][3], double w[3], double V[3][3]);
1095 
1097 
1106  static void SingularValueDecomposition3x3(
1107  const float A[3][3], float U[3][3], float w[3], float VT[3][3]);
1108  static void SingularValueDecomposition3x3(
1109  const double A[3][3], double U[3][3], double w[3], double VT[3][3]);
1111 
1119  static vtkTypeBool SolveLinearSystemGEPP2x2(
1120  double a00, double a01, double a10, double a11, double b0, double b1, double& x0, double& x1);
1121 
1130  static vtkTypeBool SolveLinearSystem(double** A, double* x, int size);
1131 
1138  static vtkTypeBool InvertMatrix(double** A, double** AI, int size);
1139 
1145  static vtkTypeBool InvertMatrix(
1146  double** A, double** AI, int size, int* tmp1Size, double* tmp2Size);
1147 
1170  static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size);
1171 
1177  static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size, double* tmpSize);
1178 
1187  static void LUSolveLinearSystem(double** A, int* index, double* x, int size);
1188 
1197  static double EstimateMatrixCondition(const double* const* A, int size);
1198 
1200 
1208  static vtkTypeBool Jacobi(float** a, float* w, float** v);
1209  static vtkTypeBool Jacobi(double** a, double* w, double** v);
1211 
1213 
1222  static vtkTypeBool JacobiN(float** a, int n, float* w, float** v);
1223  static vtkTypeBool JacobiN(double** a, int n, double* w, double** v);
1225 
1239  static vtkTypeBool SolveHomogeneousLeastSquares(
1240  int numberOfSamples, double** xt, int xOrder, double** mt);
1241 
1256  static vtkTypeBool SolveLeastSquares(int numberOfSamples, double** xt, int xOrder, double** yt,
1257  int yOrder, double** mt, int checkHomogeneous = 1);
1258 
1260 
1267  static void RGBToHSV(const float rgb[3], float hsv[3])
1268  {
1269  RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1270  }
1271  static void RGBToHSV(float r, float g, float b, float* h, float* s, float* v);
1272  static void RGBToHSV(const double rgb[3], double hsv[3])
1273  {
1274  RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
1275  }
1276  static void RGBToHSV(double r, double g, double b, double* h, double* s, double* v);
1278 
1280 
1287  static void HSVToRGB(const float hsv[3], float rgb[3])
1288  {
1289  HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1290  }
1291  static void HSVToRGB(float h, float s, float v, float* r, float* g, float* b);
1292  static void HSVToRGB(const double hsv[3], double rgb[3])
1293  {
1294  HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1295  }
1296  static void HSVToRGB(double h, double s, double v, double* r, double* g, double* b);
1298 
1300 
1303  static void LabToXYZ(const double lab[3], double xyz[3])
1304  {
1305  LabToXYZ(lab[0], lab[1], lab[2], xyz + 0, xyz + 1, xyz + 2);
1306  }
1307  static void LabToXYZ(double L, double a, double b, double* x, double* y, double* z);
1309 
1311 
1314  static void XYZToLab(const double xyz[3], double lab[3])
1315  {
1316  XYZToLab(xyz[0], xyz[1], xyz[2], lab + 0, lab + 1, lab + 2);
1317  }
1318  static void XYZToLab(double x, double y, double z, double* L, double* a, double* b);
1320 
1322 
1325  static void XYZToRGB(const double xyz[3], double rgb[3])
1326  {
1327  XYZToRGB(xyz[0], xyz[1], xyz[2], rgb + 0, rgb + 1, rgb + 2);
1328  }
1329  static void XYZToRGB(double x, double y, double z, double* r, double* g, double* b);
1331 
1333 
1336  static void RGBToXYZ(const double rgb[3], double xyz[3])
1337  {
1338  RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz + 0, xyz + 1, xyz + 2);
1339  }
1340  static void RGBToXYZ(double r, double g, double b, double* x, double* y, double* z);
1342 
1344 
1350  static void RGBToLab(const double rgb[3], double lab[3])
1351  {
1352  RGBToLab(rgb[0], rgb[1], rgb[2], lab + 0, lab + 1, lab + 2);
1353  }
1354  static void RGBToLab(double red, double green, double blue, double* L, double* a, double* b);
1356 
1358 
1361  static void LabToRGB(const double lab[3], double rgb[3])
1362  {
1363  LabToRGB(lab[0], lab[1], lab[2], rgb + 0, rgb + 1, rgb + 2);
1364  }
1365  static void LabToRGB(double L, double a, double b, double* red, double* green, double* blue);
1367 
1369 
1372  static void UninitializeBounds(double bounds[6])
1373  {
1374  bounds[0] = 1.0;
1375  bounds[1] = -1.0;
1376  bounds[2] = 1.0;
1377  bounds[3] = -1.0;
1378  bounds[4] = 1.0;
1379  bounds[5] = -1.0;
1380  }
1382 
1384 
1387  static vtkTypeBool AreBoundsInitialized(const double bounds[6])
1388  {
1389  if (bounds[1] - bounds[0] < 0.0)
1390  {
1391  return 0;
1392  }
1393  return 1;
1394  }
1396 
1401  template <class T>
1402  static T ClampValue(const T& value, const T& min, const T& max);
1403 
1405 
1409  static void ClampValue(double* value, const double range[2]);
1410  static void ClampValue(double value, const double range[2], double* clamped_value);
1411  static void ClampValues(double* values, int nb_values, const double range[2]);
1412  static void ClampValues(
1413  const double* values, int nb_values, const double range[2], double* clamped_values);
1415 
1422  static double ClampAndNormalizeValue(double value, const double range[2]);
1423 
1428  template <class T1, class T2>
1429  static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9]);
1430 
1436  template <class T>
1437  static void TensorFromSymmetricTensor(T tensor[9]);
1438 
1447  static int GetScalarTypeFittingRange(
1448  double range_min, double range_max, double scale = 1.0, double shift = 0.0);
1449 
1458  static vtkTypeBool GetAdjustedScalarRange(vtkDataArray* array, int comp, double range[2]);
1459 
1464  static vtkTypeBool ExtentIsWithinOtherExtent(const int extent1[6], const int extent2[6]);
1465 
1471  static vtkTypeBool BoundsIsWithinOtherBounds(
1472  const double bounds1[6], const double bounds2[6], const double delta[3]);
1473 
1479  static vtkTypeBool PointIsWithinBounds(
1480  const double point[3], const double bounds[6], const double delta[3]);
1481 
1491  static int PlaneIntersectsAABB(
1492  const double bounds[6], const double normal[3], const double point[3]);
1493 
1503  static double Solve3PointCircle(
1504  const double p1[3], const double p2[3], const double p3[3], double center[3]);
1505 
1509  static double Inf();
1510 
1514  static double NegInf();
1515 
1519  static double Nan();
1520 
1524  static vtkTypeBool IsInf(double x);
1525 
1529  static vtkTypeBool IsNan(double x);
1530 
1535  static bool IsFinite(double x);
1536 
1541  static int QuadraticRoot(double a, double b, double c, double min, double max, double* u);
1542 
1543  enum class ConvolutionMode
1544  {
1545  FULL,
1546  SAME,
1547  VALID
1548  };
1549 
1572  template <class Iter1, class Iter2, class Iter3>
1573  static void Convolve1D(Iter1 beginSample, Iter1 endSample, Iter2 beginKernel, Iter2 endKernel,
1574  Iter3 beginOut, Iter3 endOut, ConvolutionMode mode = ConvolutionMode::FULL)
1575  {
1576  int sampleSize = std::distance(beginSample, endSample);
1577  int kernelSize = std::distance(beginKernel, endKernel);
1578  int outSize = std::distance(beginOut, endOut);
1579 
1580  if (sampleSize <= 0 || kernelSize <= 0 || outSize <= 0)
1581  {
1582  return;
1583  }
1584 
1585  int begin = 0;
1586  int end = outSize;
1587 
1588  switch (mode)
1589  {
1590  case ConvolutionMode::SAME:
1591  begin = static_cast<int>(std::ceil(std::min(sampleSize, kernelSize) / 2.0)) - 1;
1592  end = begin + std::max(sampleSize, kernelSize);
1593  break;
1594  case ConvolutionMode::VALID:
1595  begin = std::min(sampleSize, kernelSize) - 1;
1596  end = begin + std::abs(sampleSize - kernelSize) + 1;
1597  break;
1598  case ConvolutionMode::FULL:
1599  default:
1600  break;
1601  }
1602 
1603  for (int i = begin; i < end; i++)
1604  {
1605  Iter3 out = beginOut + i - begin;
1606  *out = 0;
1607  for (int j = std::max(i - sampleSize + 1, 0); j <= std::min(i, kernelSize - 1); j++)
1608  {
1609  *out += *(beginSample + (i - j)) * *(beginKernel + j);
1610  }
1611  }
1612  }
1613 
1614 protected:
1615  vtkMath() = default;
1616  ~vtkMath() override = default;
1617 
1619 
1620 private:
1621  vtkMath(const vtkMath&) = delete;
1622  void operator=(const vtkMath&) = delete;
1623 };
1624 
1625 //----------------------------------------------------------------------------
1626 inline float vtkMath::RadiansFromDegrees(float x)
1627 {
1628  return x * 0.017453292f;
1629 }
1630 
1631 //----------------------------------------------------------------------------
1632 inline double vtkMath::RadiansFromDegrees(double x)
1633 {
1634  return x * 0.017453292519943295;
1635 }
1636 
1637 //----------------------------------------------------------------------------
1638 inline float vtkMath::DegreesFromRadians(float x)
1639 {
1640  return x * 57.2957795131f;
1641 }
1642 
1643 //----------------------------------------------------------------------------
1644 inline double vtkMath::DegreesFromRadians(double x)
1645 {
1646  return x * 57.29577951308232;
1647 }
1648 
1649 //----------------------------------------------------------------------------
1650 inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
1651 {
1652  return ((x != 0) & ((x & (x - 1)) == 0));
1653 }
1654 
1655 //----------------------------------------------------------------------------
1656 // Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1658 {
1659  unsigned int z = static_cast<unsigned int>(((x > 0) ? x - 1 : 0));
1660  z |= z >> 1;
1661  z |= z >> 2;
1662  z |= z >> 4;
1663  z |= z >> 8;
1664  z |= z >> 16;
1665  return static_cast<int>(z + 1);
1666 }
1667 
1668 //----------------------------------------------------------------------------
1669 // Modify the trunc() operation provided by static_cast<int>() to get floor(),
1670 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1671 inline int vtkMath::Floor(double x)
1672 {
1673  int i = static_cast<int>(x);
1674  return i - (i > x);
1675 }
1676 
1677 //----------------------------------------------------------------------------
1678 // Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1679 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1680 inline int vtkMath::Ceil(double x)
1681 {
1682  int i = static_cast<int>(x);
1683  return i + (i < x);
1684 }
1685 
1686 //----------------------------------------------------------------------------
1687 template <class T>
1688 inline T vtkMath::Min(const T& a, const T& b)
1689 {
1690  return (b <= a ? b : a);
1691 }
1692 
1693 //----------------------------------------------------------------------------
1694 template <class T>
1695 inline T vtkMath::Max(const T& a, const T& b)
1696 {
1697  return (b > a ? b : a);
1698 }
1699 
1700 //----------------------------------------------------------------------------
1701 inline float vtkMath::Normalize(float v[3])
1702 {
1703  float den = vtkMath::Norm(v);
1704  if (den != 0.0)
1705  {
1706  for (int i = 0; i < 3; ++i)
1707  {
1708  v[i] /= den;
1709  }
1710  }
1711  return den;
1712 }
1713 
1714 //----------------------------------------------------------------------------
1715 inline double vtkMath::Normalize(double v[3])
1716 {
1717  double den = vtkMath::Norm(v);
1718  if (den != 0.0)
1719  {
1720  for (int i = 0; i < 3; ++i)
1721  {
1722  v[i] /= den;
1723  }
1724  }
1725  return den;
1726 }
1727 
1728 //----------------------------------------------------------------------------
1729 inline float vtkMath::Normalize2D(float v[2])
1730 {
1731  float den = vtkMath::Norm2D(v);
1732  if (den != 0.0)
1733  {
1734  for (int i = 0; i < 2; ++i)
1735  {
1736  v[i] /= den;
1737  }
1738  }
1739  return den;
1740 }
1741 
1742 //----------------------------------------------------------------------------
1743 inline double vtkMath::Normalize2D(double v[2])
1744 {
1745  double den = vtkMath::Norm2D(v);
1746  if (den != 0.0)
1747  {
1748  for (int i = 0; i < 2; ++i)
1749  {
1750  v[i] /= den;
1751  }
1752  }
1753  return den;
1754 }
1755 
1756 //----------------------------------------------------------------------------
1757 inline float vtkMath::Determinant3x3(const float c1[3], const float c2[3], const float c3[3])
1758 {
1759  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1760  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1761 }
1762 
1763 //----------------------------------------------------------------------------
1764 inline double vtkMath::Determinant3x3(const double c1[3], const double c2[3], const double c3[3])
1765 {
1766  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1767  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1768 }
1769 
1770 //----------------------------------------------------------------------------
1772  double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3)
1773 {
1774  return (a1 * vtkMath::Determinant2x2(b2, b3, c2, c3) -
1775  b1 * vtkMath::Determinant2x2(a2, a3, c2, c3) + c1 * vtkMath::Determinant2x2(a2, a3, b2, b3));
1776 }
1777 
1778 //----------------------------------------------------------------------------
1779 inline float vtkMath::Distance2BetweenPoints(const float p1[3], const float p2[3])
1780 {
1781  return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1782  (p1[2] - p2[2]) * (p1[2] - p2[2]));
1783 }
1784 
1785 //----------------------------------------------------------------------------
1786 inline double vtkMath::Distance2BetweenPoints(const double p1[3], const double p2[3])
1787 {
1788  return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1789  (p1[2] - p2[2]) * (p1[2] - p2[2]));
1790 }
1791 
1792 //----------------------------------------------------------------------------
1793 template <typename ReturnTypeT, typename TupleRangeT1, typename TupleRangeT2, typename EnableT>
1794 inline ReturnTypeT vtkMath::Distance2BetweenPoints(const TupleRangeT1& p1, const TupleRangeT2& p2)
1795 {
1796  return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1797  (p1[2] - p2[2]) * (p1[2] - p2[2]));
1798 }
1799 
1800 //----------------------------------------------------------------------------
1801 // Cross product of two 3-vectors. Result (a x b) is stored in c[3].
1802 inline void vtkMath::Cross(const float a[3], const float b[3], float c[3])
1803 {
1804  float Cx = a[1] * b[2] - a[2] * b[1];
1805  float Cy = a[2] * b[0] - a[0] * b[2];
1806  float Cz = a[0] * b[1] - a[1] * b[0];
1807  c[0] = Cx;
1808  c[1] = Cy;
1809  c[2] = Cz;
1810 }
1811 
1812 //----------------------------------------------------------------------------
1813 // Cross product of two 3-vectors. Result (a x b) is stored in c[3].
1814 inline void vtkMath::Cross(const double a[3], const double b[3], double c[3])
1815 {
1816  double Cx = a[1] * b[2] - a[2] * b[1];
1817  double Cy = a[2] * b[0] - a[0] * b[2];
1818  double Cz = a[0] * b[1] - a[1] * b[0];
1819  c[0] = Cx;
1820  c[1] = Cy;
1821  c[2] = Cz;
1822 }
1823 
1824 //----------------------------------------------------------------------------
1825 template <class T>
1826 inline double vtkDeterminant3x3(const T A[3][3])
1827 {
1828  return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] + A[2][0] * A[0][1] * A[1][2] -
1829  A[0][0] * A[2][1] * A[1][2] - A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1830 }
1831 
1832 //----------------------------------------------------------------------------
1833 inline double vtkMath::Determinant3x3(const float A[3][3])
1834 {
1835  return vtkDeterminant3x3(A);
1836 }
1837 
1838 //----------------------------------------------------------------------------
1839 inline double vtkMath::Determinant3x3(const double A[3][3])
1840 {
1841  return vtkDeterminant3x3(A);
1842 }
1843 
1844 //----------------------------------------------------------------------------
1845 template <class T>
1846 inline T vtkMath::ClampValue(const T& value, const T& min, const T& max)
1847 {
1848  assert("pre: valid_range" && min <= max);
1849 
1850 #if __cplusplus >= 201703L
1851  return std::clamp(value, min, max);
1852 #else
1853  // compilers are good at optimizing the ternary operator,
1854  // use '<' since it is preferred by STL for custom types
1855  T v = (min < value ? value : min);
1856  return (v < max ? v : max);
1857 #endif
1858 }
1859 
1860 //----------------------------------------------------------------------------
1861 inline void vtkMath::ClampValue(double* value, const double range[2])
1862 {
1863  if (value && range)
1864  {
1865  assert("pre: valid_range" && range[0] <= range[1]);
1866 
1867  *value = vtkMath::ClampValue(*value, range[0], range[1]);
1868  }
1869 }
1870 
1871 //----------------------------------------------------------------------------
1872 inline void vtkMath::ClampValue(double value, const double range[2], double* clamped_value)
1873 {
1874  if (range && clamped_value)
1875  {
1876  assert("pre: valid_range" && range[0] <= range[1]);
1877 
1878  *clamped_value = vtkMath::ClampValue(value, range[0], range[1]);
1879  }
1880 }
1881 
1882 // ---------------------------------------------------------------------------
1883 inline double vtkMath::ClampAndNormalizeValue(double value, const double range[2])
1884 {
1885  assert("pre: valid_range" && range[0] <= range[1]);
1886 
1887  double result;
1888  if (range[0] == range[1])
1889  {
1890  result = 0.0;
1891  }
1892  else
1893  {
1894  // clamp
1895  result = vtkMath::ClampValue(value, range[0], range[1]);
1896 
1897  // normalize
1898  result = (result - range[0]) / (range[1] - range[0]);
1899  }
1900 
1901  assert("post: valid_result" && result >= 0.0 && result <= 1.0);
1902 
1903  return result;
1904 }
1905 
1906 //-----------------------------------------------------------------------------
1907 template <class T1, class T2>
1908 inline void vtkMath::TensorFromSymmetricTensor(const T1 symmTensor[9], T2 tensor[9])
1909 {
1910  for (int i = 0; i < 3; ++i)
1911  {
1912  tensor[4 * i] = symmTensor[i];
1913  }
1914  tensor[1] = tensor[3] = symmTensor[3];
1915  tensor[2] = tensor[6] = symmTensor[5];
1916  tensor[5] = tensor[7] = symmTensor[4];
1917 }
1918 
1919 //-----------------------------------------------------------------------------
1920 template <class T>
1921 inline void vtkMath::TensorFromSymmetricTensor(T tensor[9])
1922 {
1923  tensor[6] = tensor[5]; // XZ
1924  tensor[7] = tensor[4]; // YZ
1925  tensor[8] = tensor[2]; // ZZ
1926  tensor[4] = tensor[1]; // YY
1927  tensor[5] = tensor[7]; // YZ
1928  tensor[2] = tensor[6]; // XZ
1929  tensor[1] = tensor[3]; // XY
1930 }
1931 
1932 namespace
1933 {
1934 template <class QuaternionT, class MatrixT>
1935 inline void vtkQuaternionToMatrix3x3(const QuaternionT& quat, MatrixT& A)
1936 {
1938 
1939  Scalar ww = quat[0] * quat[0];
1940  Scalar wx = quat[0] * quat[1];
1941  Scalar wy = quat[0] * quat[2];
1942  Scalar wz = quat[0] * quat[3];
1943 
1944  Scalar xx = quat[1] * quat[1];
1945  Scalar yy = quat[2] * quat[2];
1946  Scalar zz = quat[3] * quat[3];
1947 
1948  Scalar xy = quat[1] * quat[2];
1949  Scalar xz = quat[1] * quat[3];
1950  Scalar yz = quat[2] * quat[3];
1951 
1952  Scalar rr = xx + yy + zz;
1953  // normalization factor, just in case quaternion was not normalized
1954  Scalar f = 1 / (ww + rr);
1955  Scalar s = (ww - rr) * f;
1956  f *= 2;
1957 
1959 
1960  Wrapper::template Get<0, 0>(A) = xx * f + s;
1961  Wrapper::template Get<1, 0>(A) = (xy + wz) * f;
1962  Wrapper::template Get<2, 0>(A) = (xz - wy) * f;
1963 
1964  Wrapper::template Get<0, 1>(A) = (xy - wz) * f;
1965  Wrapper::template Get<1, 1>(A) = yy * f + s;
1966  Wrapper::template Get<2, 1>(A) = (yz + wx) * f;
1967 
1968  Wrapper::template Get<0, 2>(A) = (xz + wy) * f;
1969  Wrapper::template Get<1, 2>(A) = (yz - wx) * f;
1970  Wrapper::template Get<2, 2>(A) = zz * f + s;
1971 }
1972 } // anonymous namespace
1973 
1974 //------------------------------------------------------------------------------
1975 inline void vtkMath::QuaternionToMatrix3x3(const float quat[4], float A[3][3])
1976 {
1977  vtkQuaternionToMatrix3x3(quat, A);
1978 }
1979 
1980 //------------------------------------------------------------------------------
1981 inline void vtkMath::QuaternionToMatrix3x3(const double quat[4], double A[3][3])
1982 {
1983  vtkQuaternionToMatrix3x3(quat, A);
1984 }
1985 
1986 //-----------------------------------------------------------------------------
1987 template <class QuaternionT, class MatrixT, class EnableT>
1988 inline void vtkMath::QuaternionToMatrix3x3(const QuaternionT& q, MatrixT&& A)
1989 {
1990  vtkQuaternionToMatrix3x3(q, A);
1991 }
1992 
1993 namespace
1994 {
1995 //------------------------------------------------------------------------------
1996 // The solution is based on
1997 // Berthold K. P. Horn (1987),
1998 // "Closed-form solution of absolute orientation using unit quaternions,"
1999 // Journal of the Optical Society of America A, 4:629-642
2000 template <class MatrixT, class QuaternionT>
2001 inline void vtkMatrix3x3ToQuaternion(const MatrixT& A, QuaternionT& quat)
2002 {
2004 
2005  Scalar N[4][4];
2006 
2008 
2009  // on-diagonal elements
2010  N[0][0] = Wrapper::template Get<0, 0>(A) + Wrapper::template Get<1, 1>(A) +
2011  Wrapper::template Get<2, 2>(A);
2012  N[1][1] = Wrapper::template Get<0, 0>(A) - Wrapper::template Get<1, 1>(A) -
2013  Wrapper::template Get<2, 2>(A);
2014  N[2][2] = -Wrapper::template Get<0, 0>(A) + Wrapper::template Get<1, 1>(A) -
2015  Wrapper::template Get<2, 2>(A);
2016  N[3][3] = -Wrapper::template Get<0, 0>(A) - Wrapper::template Get<1, 1>(A) +
2017  Wrapper::template Get<2, 2>(A);
2018 
2019  // off-diagonal elements
2020  N[0][1] = N[1][0] = Wrapper::template Get<2, 1>(A) - Wrapper::template Get<1, 2>(A);
2021  N[0][2] = N[2][0] = Wrapper::template Get<0, 2>(A) - Wrapper::template Get<2, 0>(A);
2022  N[0][3] = N[3][0] = Wrapper::template Get<1, 0>(A) - Wrapper::template Get<0, 1>(A);
2023 
2024  N[1][2] = N[2][1] = Wrapper::template Get<1, 0>(A) + Wrapper::template Get<0, 1>(A);
2025  N[1][3] = N[3][1] = Wrapper::template Get<0, 2>(A) + Wrapper::template Get<2, 0>(A);
2026  N[2][3] = N[3][2] = Wrapper::template Get<2, 1>(A) + Wrapper::template Get<1, 2>(A);
2027 
2028  Scalar eigenvectors[4][4], eigenvalues[4];
2029 
2030  // convert into format that JacobiN can use,
2031  // then use Jacobi to find eigenvalues and eigenvectors
2032  Scalar *NTemp[4], *eigenvectorsTemp[4];
2033  for (int i = 0; i < 4; ++i)
2034  {
2035  NTemp[i] = N[i];
2036  eigenvectorsTemp[i] = eigenvectors[i];
2037  }
2038  vtkMath::JacobiN(NTemp, 4, eigenvalues, eigenvectorsTemp);
2039 
2040  // the first eigenvector is the one we want
2041  quat[0] = eigenvectors[0][0];
2042  quat[1] = eigenvectors[1][0];
2043  quat[2] = eigenvectors[2][0];
2044  quat[3] = eigenvectors[3][0];
2045 }
2046 } // anonymous namespace
2047 
2048 //------------------------------------------------------------------------------
2049 inline void vtkMath::Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
2050 {
2051  vtkMatrix3x3ToQuaternion(A, quat);
2052 }
2053 
2054 //------------------------------------------------------------------------------
2055 inline void vtkMath::Matrix3x3ToQuaternion(const double A[3][3], double quat[4])
2056 {
2057  vtkMatrix3x3ToQuaternion(A, quat);
2058 }
2059 
2060 //-----------------------------------------------------------------------------
2061 template <class MatrixT, class QuaternionT, class EnableT>
2062 inline void vtkMath::Matrix3x3ToQuaternion(const MatrixT& A, QuaternionT&& q)
2063 {
2064  vtkMatrix3x3ToQuaternion(A, q);
2065 }
2066 
2067 namespace vtk_detail
2068 {
2069 // Can't specialize templates inside a template class, so we move the impl here.
2070 template <typename OutT>
2071 void RoundDoubleToIntegralIfNecessary(double val, OutT* ret)
2072 { // OutT is integral -- clamp and round
2073  if (!vtkMath::IsNan(val))
2074  {
2075  double min = static_cast<double>(vtkTypeTraits<OutT>::Min());
2076  double max = static_cast<double>(vtkTypeTraits<OutT>::Max());
2077  val = vtkMath::ClampValue(val, min, max);
2078  *ret = static_cast<OutT>((val >= 0.0) ? (val + 0.5) : (val - 0.5));
2079  }
2080  else
2081  *ret = 0;
2082 }
2083 template <>
2084 inline void RoundDoubleToIntegralIfNecessary(double val, double* retVal)
2085 { // OutT is double: passthrough
2086  *retVal = val;
2087 }
2088 template <>
2089 inline void RoundDoubleToIntegralIfNecessary(double val, float* retVal)
2090 { // OutT is float -- just clamp (as doubles, then the cast to float is well-defined.)
2091  if (!vtkMath::IsNan(val))
2092  {
2093  double min = static_cast<double>(vtkTypeTraits<float>::Min());
2094  double max = static_cast<double>(vtkTypeTraits<float>::Max());
2095  val = vtkMath::ClampValue(val, min, max);
2096  }
2097 
2098  *retVal = static_cast<float>(val);
2099 }
2100 } // end namespace vtk_detail
2101 
2102 //-----------------------------------------------------------------------------
2103 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
2104 #define VTK_MATH_ISINF_IS_INLINE
2105 inline vtkTypeBool vtkMath::IsInf(double x)
2106 {
2107 #if defined(VTK_HAS_STD_ISINF)
2108  return std::isinf(x);
2109 #else
2110  return (isinf(x) != 0); // Force conversion to bool
2111 #endif
2112 }
2113 #endif
2114 
2115 //-----------------------------------------------------------------------------
2116 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
2117 #define VTK_MATH_ISNAN_IS_INLINE
2118 inline vtkTypeBool vtkMath::IsNan(double x)
2119 {
2120 #if defined(VTK_HAS_STD_ISNAN)
2121  return std::isnan(x);
2122 #else
2123  return (isnan(x) != 0); // Force conversion to bool
2124 #endif
2125 }
2126 #endif
2127 
2128 //-----------------------------------------------------------------------------
2129 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
2130 #define VTK_MATH_ISFINITE_IS_INLINE
2131 inline bool vtkMath::IsFinite(double x)
2132 {
2133 #if defined(VTK_HAS_STD_ISFINITE)
2134  return std::isfinite(x);
2135 #elif defined(VTK_HAS_ISFINITE)
2136  return (isfinite(x) != 0); // Force conversion to bool
2137 #else
2138  return (finite(x) != 0); // Force conversion to bool
2139 #endif
2140 }
2141 #endif
2142 
2143 #endif
static void MultiplyScalar2D(float a[2], float s)
Multiplies a 2-vector by a scalar (float version).
Definition: vtkMath.h:408
static bool IsFinite(double x)
Test if a number has finite value i.e.
static float Dot2D(const float x[2], const float y[2])
Dot product of two 2-vectors.
Definition: vtkMath.h:674
static float Dot(const float a[3], const float b[3])
Dot product of two 3-vectors (float version).
Definition: vtkMath.h:443
static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9])
Convert a 6-Component symmetric tensor into a 9-Component tensor, no allocation performed.
abstract base class for most VTK objects
Definition: vtkObject.h:62
static void LabToXYZ(const double lab[3], double xyz[3])
Convert color from the CIE-L*ab system to CIE XYZ.
Definition: vtkMath.h:1303
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Returns true if integer is a power of two.
Definition: vtkMath.h:1650
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:497
void RoundDoubleToIntegralIfNecessary(double val, OutT *ret)
Definition: vtkMath.h:2071
static float Determinant2x2(const float c1[2], const float c2[2])
Compute determinant of 2x2 matrix.
Definition: vtkMath.h:736
static vtkSmartPointer< vtkMathInternal > Internal
Definition: vtkMath.h:1618
static void QuaternionToMatrix3x3(const float quat[4], float A[3][3])
Convert a quaternion to a 3x3 rotation matrix.
Definition: vtkMath.h:1975
static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
Convert a 3x3 matrix into a quaternion.
Definition: vtkMath.h:2049
static vtkTypeBool IsInf(double x)
Test if a number is equal to the special floating point value infinity.
static ScalarT Dot(const VectorT1 &x, const VectorT2 &y)
Computes the dot product between 2 vectors x and y.
Definition: vtkMath.h:858
static constexpr double Pi()
A mathematical constant.
Definition: vtkMath.h:103
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:1272
static vtkTypeBool IsNan(double x)
Test if a number is equal to the special floating point value Not-A-Number (Nan). ...
static int Round(float f)
Rounds a float to the nearest integer.
Definition: vtkMath.h:125
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:1267
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:1883
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:483
static void MultiplyMatrixWithVector(const MatrixT &M, const VectorT1 &X, VectorT2 &&Y)
Multiply matrix M with vector Y such that Y = M x X.
Definition: vtkMath.h:847
int vtkTypeBool
Definition: vtkABI.h:69
static void Add(const double a[3], const double b[3], double c[3])
Addition of two 3-vectors (double version).
Definition: vtkMath.h:349
static double Dot(const double a[3], const double b[3])
Dot product of two 3-vectors (double version).
Definition: vtkMath.h:451
static void XYZToRGB(const double xyz[3], double rgb[3])
Convert color from the CIE XYZ system to RGB.
Definition: vtkMath.h:1325
static float Norm2D(const float x[2])
Compute the norm of a 2-vector.
Definition: vtkMath.h:713
detail::ScalarTypeExtractor< std::is_array< DerefContainer >::value||std::is_pointer< DerefContainer >::value, ContainerT >::value_type value_type
static void UninitializeBounds(double bounds[6])
Set the bounds to an uninitialized state.
Definition: vtkMath.h:1372
double vtkDeterminant3x3(const T A[3][3])
Definition: vtkMath.h:1826
static int NearestPowerOfTwo(int x)
Compute the nearest power of two that is not less than x.
Definition: vtkMath.h:1657
static void RGBToXYZ(const double rgb[3], double xyz[3])
Convert color from the RGB system to CIE XYZ.
Definition: vtkMath.h:1336
static void LinearSolve(const MatrixT &M, const VectorT1 &x, VectorT2 &y)
This method solves linear systems M * x = y.
Definition: vtkMath.h:924
static T Min(const T &a, const T &b)
Returns the minimum of the two arguments provided.
Definition: vtkMath.h:1688
a simple class to control print indentation
Definition: vtkIndent.h:39
static float Normalize2D(float v[2])
Normalize (in place) a 2-vector.
Definition: vtkMath.h:1729
static void Subtract(const float a[3], const float b[3], float c[3])
Subtraction of two 3-vectors (float version).
Definition: vtkMath.h:360
static void Subtract(const double a[3], const double b[3], double c[3])
Subtraction of two 3-vectors (double version).
Definition: vtkMath.h:371
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
Definition: vtkMath.h:1671
static double Determinant3x3(const float A[3][3])
Return the determinant of a 3x3 matrix.
Definition: vtkMath.h:1833
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
static ReturnTypeT SquaredNorm(const TupleRangeT &v)
Compute the squared norm of a 3-vector.
Definition: vtkMath.h:551
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:1573
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:745
static float RadiansFromDegrees(float degrees)
Convert degrees into radians.
Definition: vtkMath.h:1626
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:1292
Park and Miller Sequence of pseudo random numbers.
static void MultiplyScalar(double a[3], double s)
Multiplies a 3-vector by a scalar (double version).
Definition: vtkMath.h:420
static void RGBToLab(const double rgb[3], double lab[3])
Convert color from the RGB system to CIE-L*ab.
Definition: vtkMath.h:1350
static float DegreesFromRadians(float radians)
Convert radians into degrees.
Definition: vtkMath.h:1638
static float Normalize(float v[3])
Normalize (in place) a 3-vector.
Definition: vtkMath.h:1701
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:698
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:684
static int Ceil(double x)
Rounds a double to the nearest integer not less than itself.
Definition: vtkMath.h:1680
performs common math operations
Definition: vtkMath.h:93
static double Dot2D(const double x[2], const double y[2])
Dot product of two 2-vectors.
Definition: vtkMath.h:679
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:134
static vtkTypeBool JacobiN(float **a, int n, float *w, float **v)
JacobiN iteration for the solution of eigenvectors/eigenvalues of a nxn real symmetric matrix...
static float Norm(const float v[3])
Compute the norm of 3-vector (float version).
Definition: vtkMath.h:531
static void MultiplyScalar(float a[3], float s)
Multiplies a 3-vector by a scalar (float version).
Definition: vtkMath.h:396
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:1287
static void Subtract(const VectorT1 &a, const VectorT2 &b, VectorT3 &&c)
Subtraction of two 3-vectors (templated version).
Definition: vtkMath.h:385
static T ClampValue(const T &value, const T &min, const T &max)
Clamp some value against a range, return the result.
Definition: vtkMath.h:1846
static double Norm2D(const double x[2])
Compute the norm of a 2-vector.
Definition: vtkMath.h:719
static void InvertMatrix(const MatrixT1 &M1, MatrixT2 &&M2)
Computes the inverse of input matrix M1 into M2.
Definition: vtkMath.h:904
static int Round(double f)
Definition: vtkMath.h:126
static ReturnTypeT Dot(const TupleRangeT1 &a, const TupleRangeT2 &b)
Compute dot product between two points p1 and p2.
Definition: vtkMath.h:475
static double Norm(const double v[3])
Compute the norm of 3-vector (double version).
Definition: vtkMath.h:536
static void MultiplyScalar2D(double a[2], double s)
Multiplies a 2-vector by a scalar (double version).
Definition: vtkMath.h:432
static void LabToRGB(const double lab[3], double rgb[3])
Convert color from the CIE-L*ab system to RGB.
Definition: vtkMath.h:1361
static vtkObject * New()
Create an object with Debug turned off, modified time initialized to zero, and reference counting on...
static float Norm(const float *x, int n)
Compute the norm of n-vector.
static void Cross(const float a[3], const float b[3], float c[3])
Cross product of two 3-vectors.
Definition: vtkMath.h:1802
static ScalarT Dot(const VectorT1 &x, const MatrixT &M, const VectorT2 &y)
Computes the dot product x^T M y, where x and y are vectors and M is a metric matrix.
Definition: vtkMath.h:945
static ReturnTypeT Distance2BetweenPoints(const TupleRangeT1 &p1, const TupleRangeT2 &p2)
Compute distance squared between two points p1 and p2.
Definition: vtkMath.h:1794
ConvolutionMode
Definition: vtkMath.h:1543
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
static double Determinant2x2(const double c1[2], const double c2[2])
Calculate the determinant of a 2x2 matrix: | a b | | c d |.
Definition: vtkMath.h:746
static void Add(const float a[3], const float b[3], float c[3])
Addition of two 3-vectors (float version).
Definition: vtkMath.h:338
Matrix wrapping class.
static void MultiplyMatrix(const MatrixT1 &M1, const MatrixT2 &M2, MatrixT3 &&M3)
Multiply matrices such that M3 = M1 x M2.
Definition: vtkMath.h:820
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:33
static vtkTypeBool AreBoundsInitialized(const double bounds[6])
Are the bounds initialized?
Definition: vtkMath.h:1387
#define max(a, b)
represent and manipulate 3D points
Definition: vtkPoints.h:39
static void Assign(const VectorT1 &a, VectorT2 &&b)
Assign values to a 3-vector (templated version).
Definition: vtkMath.h:323
static T Max(const T &a, const T &b)
Returns the maximum of the two arguments provided.
Definition: vtkMath.h:1695
static vtkMatrixUtilities::ScalarTypeExtractor< MatrixT >::value_type Determinant(const MatrixT &M)
Computes the determinant of input square SizeT x SizeT matrix M.
Definition: vtkMath.h:881
static void Assign(const double a[3], double b[3])
Assign values to a 3-vector (double version).
Definition: vtkMath.h:333
static void XYZToLab(const double xyz[3], double lab[3])
Convert Color from the CIE XYZ system to CIE-L*ab.
Definition: vtkMath.h:1314