VTK  9.0.3
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 =========================================================================*/
39 #ifndef vtkMath_h
40 #define vtkMath_h
41 
42 #include "vtkCommonCoreModule.h" // For export macro
43 #include "vtkObject.h"
44 #include "vtkSmartPointer.h" // For vtkSmartPointer.
45 #include "vtkTypeTraits.h" // For type traits
46 
47 #include "vtkMathConfigure.h" // For <cmath> and VTK_HAS_ISNAN etc.
48 
49 #include <algorithm> // for std::clamp
50 #include <cassert> // assert() in inline implementations.
51 
52 #ifndef DBL_MIN
53 #define VTK_DBL_MIN 2.2250738585072014e-308
54 #else // DBL_MIN
55 #define VTK_DBL_MIN DBL_MIN
56 #endif // DBL_MIN
57 
58 #ifndef DBL_EPSILON
59 #define VTK_DBL_EPSILON 2.2204460492503131e-16
60 #else // DBL_EPSILON
61 #define VTK_DBL_EPSILON DBL_EPSILON
62 #endif // DBL_EPSILON
63 
64 #ifndef VTK_DBL_EPSILON
65 #ifndef DBL_EPSILON
66 #define VTK_DBL_EPSILON 2.2204460492503131e-16
67 #else // DBL_EPSILON
68 #define VTK_DBL_EPSILON DBL_EPSILON
69 #endif // DBL_EPSILON
70 #endif // VTK_DBL_EPSILON
71 
72 class vtkDataArray;
73 class vtkPoints;
74 class vtkMathInternal;
77 
78 namespace vtk_detail
79 {
80 // forward declaration
81 template <typename OutT>
82 void RoundDoubleToIntegralIfNecessary(double val, OutT* ret);
83 } // end namespace vtk_detail
84 
85 class VTKCOMMONCORE_EXPORT vtkMath : public vtkObject
86 {
87 public:
88  static vtkMath* New();
89  vtkTypeMacro(vtkMath, vtkObject);
90  void PrintSelf(ostream& os, vtkIndent indent) override;
91 
95  static double Pi() { return 3.141592653589793; }
96 
98 
101  static float RadiansFromDegrees(float degrees);
102  static double RadiansFromDegrees(double degrees);
104 
106 
109  static float DegreesFromRadians(float radians);
110  static double DegreesFromRadians(double radians);
112 
116 #if 1
117  static int Round(float f) { return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
118  static int Round(double f) { return static_cast<int>(f + (f >= 0.0 ? 0.5 : -0.5)); }
119 #endif
120 
125  template <typename OutT>
126  static void RoundDoubleToIntegralIfNecessary(double val, OutT* ret)
127  {
128  // Can't specialize template methods in a template class, so we move the
129  // implementations to a external namespace.
131  }
132 
138  static int Floor(double x);
139 
145  static int Ceil(double x);
146 
152  static int CeilLog2(vtkTypeUInt64 x);
153 
158  template <class T>
159  static T Min(const T& a, const T& b);
160 
165  template <class T>
166  static T Max(const T& a, const T& b);
167 
171  static bool IsPowerOfTwo(vtkTypeUInt64 x);
172 
178  static int NearestPowerOfTwo(int x);
179 
184  static vtkTypeInt64 Factorial(int N);
185 
191  static vtkTypeInt64 Binomial(int m, int n);
192 
204  static int* BeginCombination(int m, int n);
205 
216  static int NextCombination(int m, int n, int* combination);
217 
221  static void FreeCombination(int* combination);
222 
238  static void RandomSeed(int s);
239 
251  static int GetSeed();
252 
266  static double Random();
267 
280  static double Random(double min, double max);
281 
294  static double Gaussian();
295 
308  static double Gaussian(double mean, double std);
309 
313  static void Add(const float a[3], const float b[3], float c[3])
314  {
315  for (int i = 0; i < 3; ++i)
316  {
317  c[i] = a[i] + b[i];
318  }
319  }
320 
324  static void Add(const double a[3], const double b[3], double c[3])
325  {
326  for (int i = 0; i < 3; ++i)
327  {
328  c[i] = a[i] + b[i];
329  }
330  }
331 
335  static void Subtract(const float a[3], const float b[3], float c[3])
336  {
337  for (int i = 0; i < 3; ++i)
338  {
339  c[i] = a[i] - b[i];
340  }
341  }
342 
346  static void Subtract(const double a[3], const double b[3], double c[3])
347  {
348  for (int i = 0; i < 3; ++i)
349  {
350  c[i] = a[i] - b[i];
351  }
352  }
353 
358  static void MultiplyScalar(float a[3], float s)
359  {
360  for (int i = 0; i < 3; ++i)
361  {
362  a[i] *= s;
363  }
364  }
365 
370  static void MultiplyScalar2D(float a[2], float s)
371  {
372  for (int i = 0; i < 2; ++i)
373  {
374  a[i] *= s;
375  }
376  }
377 
382  static void MultiplyScalar(double a[3], double s)
383  {
384  for (int i = 0; i < 3; ++i)
385  {
386  a[i] *= s;
387  }
388  }
389 
394  static void MultiplyScalar2D(double a[2], double s)
395  {
396  for (int i = 0; i < 2; ++i)
397  {
398  a[i] *= s;
399  }
400  }
401 
405  static float Dot(const float a[3], const float b[3])
406  {
407  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
408  }
409 
413  static double Dot(const double a[3], const double b[3])
414  {
415  return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
416  }
417 
421  static void Outer(const float a[3], const float b[3], float c[3][3])
422  {
423  for (int i = 0; i < 3; ++i)
424  {
425  for (int j = 0; j < 3; ++j)
426  {
427  c[i][j] = a[i] * b[j];
428  }
429  }
430  }
431 
435  static void Outer(const double a[3], const double b[3], double c[3][3])
436  {
437  for (int i = 0; i < 3; ++i)
438  {
439  for (int j = 0; j < 3; ++j)
440  {
441  c[i][j] = a[i] * b[j];
442  }
443  }
444  }
445 
450  static void Cross(const float a[3], const float b[3], float c[3]);
451 
456  static void Cross(const double a[3], const double b[3], double c[3]);
457 
459 
462  static float Norm(const float* x, int n);
463  static double Norm(const double* x, int n);
465 
469  static float Norm(const float v[3]) { return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]); }
470 
474  static double Norm(const double v[3])
475  {
476  return std::sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
477  }
478 
483  static float Normalize(float v[3]);
484 
489  static double Normalize(double v[3]);
490 
492 
499  static void Perpendiculars(const double v1[3], double v2[3], double v3[3], double theta);
500  static void Perpendiculars(const float v1[3], float v2[3], float v3[3], double theta);
502 
504 
509  static bool ProjectVector(const float a[3], const float b[3], float projection[3]);
510  static bool ProjectVector(const double a[3], const double b[3], double projection[3]);
512 
514 
520  static bool ProjectVector2D(const float a[2], const float b[2], float projection[2]);
521  static bool ProjectVector2D(const double a[2], const double b[2], double projection[2]);
523 
528  static float Distance2BetweenPoints(const float p1[3], const float p2[3]);
529 
534  static double Distance2BetweenPoints(const double p1[3], const double p2[3]);
535 
539  static double AngleBetweenVectors(const double v1[3], const double v2[3]);
540 
545  static double GaussianAmplitude(const double variance, const double distanceFromMean);
546 
551  static double GaussianAmplitude(const double mean, const double variance, const double position);
552 
558  static double GaussianWeight(const double variance, const double distanceFromMean);
559 
565  static double GaussianWeight(const double mean, const double variance, const double position);
566 
570  static float Dot2D(const float x[2], const float y[2]) { return x[0] * y[0] + x[1] * y[1]; }
571 
575  static double Dot2D(const double x[2], const double y[2]) { return x[0] * y[0] + x[1] * y[1]; }
576 
580  static void Outer2D(const float x[2], const float y[2], float A[2][2])
581  {
582  for (int i = 0; i < 2; ++i)
583  {
584  for (int j = 0; j < 2; ++j)
585  {
586  A[i][j] = x[i] * y[j];
587  }
588  }
589  }
590 
594  static void Outer2D(const double x[2], const double y[2], double A[2][2])
595  {
596  for (int i = 0; i < 2; ++i)
597  {
598  for (int j = 0; j < 2; ++j)
599  {
600  A[i][j] = x[i] * y[j];
601  }
602  }
603  }
604 
609  static float Norm2D(const float x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
610 
615  static double Norm2D(const double x[2]) { return std::sqrt(x[0] * x[0] + x[1] * x[1]); }
616 
621  static float Normalize2D(float v[2]);
622 
627  static double Normalize2D(double v[2]);
628 
632  static float Determinant2x2(const float c1[2], const float c2[2])
633  {
634  return c1[0] * c2[1] - c2[0] * c1[1];
635  }
636 
638 
641  static double Determinant2x2(double a, double b, double c, double d) { return a * d - b * c; }
642  static double Determinant2x2(const double c1[2], const double c2[2])
643  {
644  return c1[0] * c2[1] - c2[0] * c1[1];
645  }
647 
649 
652  static void LUFactor3x3(float A[3][3], int index[3]);
653  static void LUFactor3x3(double A[3][3], int index[3]);
655 
657 
660  static void LUSolve3x3(const float A[3][3], const int index[3], float x[3]);
661  static void LUSolve3x3(const double A[3][3], const int index[3], double x[3]);
663 
665 
669  static void LinearSolve3x3(const float A[3][3], const float x[3], float y[3]);
670  static void LinearSolve3x3(const double A[3][3], const double x[3], double y[3]);
672 
674 
677  static void Multiply3x3(const float A[3][3], const float in[3], float out[3]);
678  static void Multiply3x3(const double A[3][3], const double in[3], double out[3]);
680 
682 
685  static void Multiply3x3(const float A[3][3], const float B[3][3], float C[3][3]);
686  static void Multiply3x3(const double A[3][3], const double B[3][3], double C[3][3]);
688 
694  static void MultiplyMatrix(const double* const* A, const double* const* B, unsigned int rowA,
695  unsigned int colA, unsigned int rowB, unsigned int colB, double** C);
696 
698 
702  static void Transpose3x3(const float A[3][3], float AT[3][3]);
703  static void Transpose3x3(const double A[3][3], double AT[3][3]);
705 
707 
711  static void Invert3x3(const float A[3][3], float AI[3][3]);
712  static void Invert3x3(const double A[3][3], double AI[3][3]);
714 
716 
719  static void Identity3x3(float A[3][3]);
720  static void Identity3x3(double A[3][3]);
722 
724 
727  static double Determinant3x3(const float A[3][3]);
728  static double Determinant3x3(const double A[3][3]);
730 
734  static float Determinant3x3(const float c1[3], const float c2[3], const float c3[3]);
735 
739  static double Determinant3x3(const double c1[3], const double c2[3], const double c3[3]);
740 
747  static double Determinant3x3(double a1, double a2, double a3, double b1, double b2, double b3,
748  double c1, double c2, double c3);
749 
751 
758  static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
759  static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
761 
763 
772  static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
773  static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
775 
777 
783  static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4]);
784  static void MultiplyQuaternion(const double q1[4], const double q2[4], double q[4]);
786 
788 
792  static void RotateVectorByNormalizedQuaternion(const float v[3], const float q[4], float r[3]);
793  static void RotateVectorByNormalizedQuaternion(const double v[3], const double q[4], double r[3]);
795 
797 
801  static void RotateVectorByWXYZ(const float v[3], const float q[4], float r[3]);
802  static void RotateVectorByWXYZ(const double v[3], const double q[4], double r[3]);
804 
806 
811  static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
812  static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
814 
816 
822  static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
823  static void Diagonalize3x3(const double A[3][3], double w[3], double V[3][3]);
825 
827 
837  const float A[3][3], float U[3][3], float w[3], float VT[3][3]);
839  const double A[3][3], double U[3][3], double w[3], double VT[3][3]);
841 
848  static vtkTypeBool SolveLinearSystem(double** A, double* x, int size);
849 
856  static vtkTypeBool InvertMatrix(double** A, double** AI, int size);
857 
864  double** A, double** AI, int size, int* tmp1Size, double* tmp2Size);
865 
888  static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size);
889 
895  static vtkTypeBool LUFactorLinearSystem(double** A, int* index, int size, double* tmpSize);
896 
905  static void LUSolveLinearSystem(double** A, int* index, double* x, int size);
906 
915  static double EstimateMatrixCondition(const double* const* A, int size);
916 
918 
926  static vtkTypeBool Jacobi(float** a, float* w, float** v);
927  static vtkTypeBool Jacobi(double** a, double* w, double** v);
929 
931 
940  static vtkTypeBool JacobiN(float** a, int n, float* w, float** v);
941  static vtkTypeBool JacobiN(double** a, int n, double* w, double** v);
943 
958  int numberOfSamples, double** xt, int xOrder, double** mt);
959 
974  static vtkTypeBool SolveLeastSquares(int numberOfSamples, double** xt, int xOrder, double** yt,
975  int yOrder, double** mt, int checkHomogeneous = 1);
976 
978 
985  static void RGBToHSV(const float rgb[3], float hsv[3])
986  {
987  RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
988  }
989  static void RGBToHSV(float r, float g, float b, float* h, float* s, float* v);
990  static void RGBToHSV(const double rgb[3], double hsv[3])
991  {
992  RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv + 1, hsv + 2);
993  }
994  static void RGBToHSV(double r, double g, double b, double* h, double* s, double* v);
996 
998 
1005  static void HSVToRGB(const float hsv[3], float rgb[3])
1006  {
1007  HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1008  }
1009  static void HSVToRGB(float h, float s, float v, float* r, float* g, float* b);
1010  static void HSVToRGB(const double hsv[3], double rgb[3])
1011  {
1012  HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb + 1, rgb + 2);
1013  }
1014  static void HSVToRGB(double h, double s, double v, double* r, double* g, double* b);
1016 
1018 
1021  static void LabToXYZ(const double lab[3], double xyz[3])
1022  {
1023  LabToXYZ(lab[0], lab[1], lab[2], xyz + 0, xyz + 1, xyz + 2);
1024  }
1025  static void LabToXYZ(double L, double a, double b, double* x, double* y, double* z);
1027 
1029 
1032  static void XYZToLab(const double xyz[3], double lab[3])
1033  {
1034  XYZToLab(xyz[0], xyz[1], xyz[2], lab + 0, lab + 1, lab + 2);
1035  }
1036  static void XYZToLab(double x, double y, double z, double* L, double* a, double* b);
1038 
1040 
1043  static void XYZToRGB(const double xyz[3], double rgb[3])
1044  {
1045  XYZToRGB(xyz[0], xyz[1], xyz[2], rgb + 0, rgb + 1, rgb + 2);
1046  }
1047  static void XYZToRGB(double x, double y, double z, double* r, double* g, double* b);
1049 
1051 
1054  static void RGBToXYZ(const double rgb[3], double xyz[3])
1055  {
1056  RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz + 0, xyz + 1, xyz + 2);
1057  }
1058  static void RGBToXYZ(double r, double g, double b, double* x, double* y, double* z);
1060 
1062 
1068  static void RGBToLab(const double rgb[3], double lab[3])
1069  {
1070  RGBToLab(rgb[0], rgb[1], rgb[2], lab + 0, lab + 1, lab + 2);
1071  }
1072  static void RGBToLab(double red, double green, double blue, double* L, double* a, double* b);
1074 
1076 
1079  static void LabToRGB(const double lab[3], double rgb[3])
1080  {
1081  LabToRGB(lab[0], lab[1], lab[2], rgb + 0, rgb + 1, rgb + 2);
1082  }
1083  static void LabToRGB(double L, double a, double b, double* red, double* green, double* blue);
1085 
1087 
1090  static void UninitializeBounds(double bounds[6])
1091  {
1092  bounds[0] = 1.0;
1093  bounds[1] = -1.0;
1094  bounds[2] = 1.0;
1095  bounds[3] = -1.0;
1096  bounds[4] = 1.0;
1097  bounds[5] = -1.0;
1098  }
1100 
1102 
1105  static vtkTypeBool AreBoundsInitialized(const double bounds[6])
1106  {
1107  if (bounds[1] - bounds[0] < 0.0)
1108  {
1109  return 0;
1110  }
1111  return 1;
1112  }
1114 
1119  template <class T>
1120  static T ClampValue(const T& value, const T& min, const T& max);
1121 
1123 
1127  static void ClampValue(double* value, const double range[2]);
1128  static void ClampValue(double value, const double range[2], double* clamped_value);
1129  static void ClampValues(double* values, int nb_values, const double range[2]);
1130  static void ClampValues(
1131  const double* values, int nb_values, const double range[2], double* clamped_values);
1133 
1140  static double ClampAndNormalizeValue(double value, const double range[2]);
1141 
1146  template <class T1, class T2>
1147  static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9]);
1148 
1154  template <class T>
1155  static void TensorFromSymmetricTensor(T tensor[9]);
1156 
1166  double range_min, double range_max, double scale = 1.0, double shift = 0.0);
1167 
1176  static vtkTypeBool GetAdjustedScalarRange(vtkDataArray* array, int comp, double range[2]);
1177 
1182  static vtkTypeBool ExtentIsWithinOtherExtent(const int extent1[6], const int extent2[6]);
1183 
1190  const double bounds1[6], const double bounds2[6], const double delta[3]);
1191 
1198  const double point[3], const double bounds[6], const double delta[3]);
1199 
1210  const double bounds[6], const double normal[3], const double point[3]);
1211 
1221  static double Solve3PointCircle(
1222  const double p1[3], const double p2[3], const double p3[3], double center[3]);
1223 
1227  static double Inf();
1228 
1232  static double NegInf();
1233 
1237  static double Nan();
1238 
1242  static vtkTypeBool IsInf(double x);
1243 
1247  static vtkTypeBool IsNan(double x);
1248 
1253  static bool IsFinite(double x);
1254 
1259  static int QuadraticRoot(double a, double b, double c, double min, double max, double* u);
1260 
1261 protected:
1262  vtkMath() {}
1263  ~vtkMath() override {}
1264 
1266 
1267 private:
1268  vtkMath(const vtkMath&) = delete;
1269  void operator=(const vtkMath&) = delete;
1270 };
1271 
1272 //----------------------------------------------------------------------------
1273 inline float vtkMath::RadiansFromDegrees(float x)
1274 {
1275  return x * 0.017453292f;
1276 }
1277 
1278 //----------------------------------------------------------------------------
1279 inline double vtkMath::RadiansFromDegrees(double x)
1280 {
1281  return x * 0.017453292519943295;
1282 }
1283 
1284 //----------------------------------------------------------------------------
1285 inline float vtkMath::DegreesFromRadians(float x)
1286 {
1287  return x * 57.2957795131f;
1288 }
1289 
1290 //----------------------------------------------------------------------------
1291 inline double vtkMath::DegreesFromRadians(double x)
1292 {
1293  return x * 57.29577951308232;
1294 }
1295 
1296 //----------------------------------------------------------------------------
1297 inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
1298 {
1299  return ((x != 0) & ((x & (x - 1)) == 0));
1300 }
1301 
1302 //----------------------------------------------------------------------------
1303 // Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1305 {
1306  unsigned int z = static_cast<unsigned int>(((x > 0) ? x - 1 : 0));
1307  z |= z >> 1;
1308  z |= z >> 2;
1309  z |= z >> 4;
1310  z |= z >> 8;
1311  z |= z >> 16;
1312  return static_cast<int>(z + 1);
1313 }
1314 
1315 //----------------------------------------------------------------------------
1316 // Modify the trunc() operation provided by static_cast<int>() to get floor(),
1317 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1318 inline int vtkMath::Floor(double x)
1319 {
1320  int i = static_cast<int>(x);
1321  return i - (i > x);
1322 }
1323 
1324 //----------------------------------------------------------------------------
1325 // Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1326 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1327 inline int vtkMath::Ceil(double x)
1328 {
1329  int i = static_cast<int>(x);
1330  return i + (i < x);
1331 }
1332 
1333 //----------------------------------------------------------------------------
1334 template <class T>
1335 inline T vtkMath::Min(const T& a, const T& b)
1336 {
1337  return (b <= a ? b : a);
1338 }
1339 
1340 //----------------------------------------------------------------------------
1341 template <class T>
1342 inline T vtkMath::Max(const T& a, const T& b)
1343 {
1344  return (b > a ? b : a);
1345 }
1346 
1347 //----------------------------------------------------------------------------
1348 inline float vtkMath::Normalize(float v[3])
1349 {
1350  float den = vtkMath::Norm(v);
1351  if (den != 0.0)
1352  {
1353  for (int i = 0; i < 3; ++i)
1354  {
1355  v[i] /= den;
1356  }
1357  }
1358  return den;
1359 }
1360 
1361 //----------------------------------------------------------------------------
1362 inline double vtkMath::Normalize(double v[3])
1363 {
1364  double den = vtkMath::Norm(v);
1365  if (den != 0.0)
1366  {
1367  for (int i = 0; i < 3; ++i)
1368  {
1369  v[i] /= den;
1370  }
1371  }
1372  return den;
1373 }
1374 
1375 //----------------------------------------------------------------------------
1376 inline float vtkMath::Normalize2D(float v[3])
1377 {
1378  float den = vtkMath::Norm2D(v);
1379  if (den != 0.0)
1380  {
1381  for (int i = 0; i < 2; ++i)
1382  {
1383  v[i] /= den;
1384  }
1385  }
1386  return den;
1387 }
1388 
1389 //----------------------------------------------------------------------------
1390 inline double vtkMath::Normalize2D(double v[3])
1391 {
1392  double den = vtkMath::Norm2D(v);
1393  if (den != 0.0)
1394  {
1395  for (int i = 0; i < 2; ++i)
1396  {
1397  v[i] /= den;
1398  }
1399  }
1400  return den;
1401 }
1402 
1403 //----------------------------------------------------------------------------
1404 inline float vtkMath::Determinant3x3(const float c1[3], const float c2[3], const float c3[3])
1405 {
1406  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1407  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1408 }
1409 
1410 //----------------------------------------------------------------------------
1411 inline double vtkMath::Determinant3x3(const double c1[3], const double c2[3], const double c3[3])
1412 {
1413  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1414  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1415 }
1416 
1417 //----------------------------------------------------------------------------
1419  double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3)
1420 {
1421  return (a1 * vtkMath::Determinant2x2(b2, b3, c2, c3) -
1422  b1 * vtkMath::Determinant2x2(a2, a3, c2, c3) + c1 * vtkMath::Determinant2x2(a2, a3, b2, b3));
1423 }
1424 
1425 //----------------------------------------------------------------------------
1426 inline float vtkMath::Distance2BetweenPoints(const float p1[3], const float p2[3])
1427 {
1428  return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1429  (p1[2] - p2[2]) * (p1[2] - p2[2]));
1430 }
1431 
1432 //----------------------------------------------------------------------------
1433 inline double vtkMath::Distance2BetweenPoints(const double p1[3], const double p2[3])
1434 {
1435  return ((p1[0] - p2[0]) * (p1[0] - p2[0]) + (p1[1] - p2[1]) * (p1[1] - p2[1]) +
1436  (p1[2] - p2[2]) * (p1[2] - p2[2]));
1437 }
1438 
1439 //----------------------------------------------------------------------------
1440 // Cross product of two 3-vectors. Result (a x b) is stored in c[3].
1441 inline void vtkMath::Cross(const float a[3], const float b[3], float c[3])
1442 {
1443  float Cx = a[1] * b[2] - a[2] * b[1];
1444  float Cy = a[2] * b[0] - a[0] * b[2];
1445  float Cz = a[0] * b[1] - a[1] * b[0];
1446  c[0] = Cx;
1447  c[1] = Cy;
1448  c[2] = Cz;
1449 }
1450 
1451 //----------------------------------------------------------------------------
1452 // Cross product of two 3-vectors. Result (a x b) is stored in c[3].
1453 inline void vtkMath::Cross(const double a[3], const double b[3], double c[3])
1454 {
1455  double Cx = a[1] * b[2] - a[2] * b[1];
1456  double Cy = a[2] * b[0] - a[0] * b[2];
1457  double Cz = a[0] * b[1] - a[1] * b[0];
1458  c[0] = Cx;
1459  c[1] = Cy;
1460  c[2] = Cz;
1461 }
1462 
1463 //----------------------------------------------------------------------------
1464 template <class T>
1465 inline double vtkDeterminant3x3(const T A[3][3])
1466 {
1467  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] -
1468  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];
1469 }
1470 
1471 //----------------------------------------------------------------------------
1472 inline double vtkMath::Determinant3x3(const float A[3][3])
1473 {
1474  return vtkDeterminant3x3(A);
1475 }
1476 
1477 //----------------------------------------------------------------------------
1478 inline double vtkMath::Determinant3x3(const double A[3][3])
1479 {
1480  return vtkDeterminant3x3(A);
1481 }
1482 
1483 //----------------------------------------------------------------------------
1484 template <class T>
1485 inline T vtkMath::ClampValue(const T& value, const T& min, const T& max)
1486 {
1487  assert("pre: valid_range" && min <= max);
1488 
1489 #if __cplusplus >= 201703L
1490  return std::clamp(value, min, max);
1491 #else
1492  // compilers are good at optimizing the ternary operator,
1493  // use '<' since it is preferred by STL for custom types
1494  T v = (min < value ? value : min);
1495  return (v < max ? v : max);
1496 #endif
1497 }
1498 
1499 //----------------------------------------------------------------------------
1500 inline void vtkMath::ClampValue(double* value, const double range[2])
1501 {
1502  if (value && range)
1503  {
1504  assert("pre: valid_range" && range[0] <= range[1]);
1505 
1506  *value = vtkMath::ClampValue(*value, range[0], range[1]);
1507  }
1508 }
1509 
1510 //----------------------------------------------------------------------------
1511 inline void vtkMath::ClampValue(double value, const double range[2], double* clamped_value)
1512 {
1513  if (range && clamped_value)
1514  {
1515  assert("pre: valid_range" && range[0] <= range[1]);
1516 
1517  *clamped_value = vtkMath::ClampValue(value, range[0], range[1]);
1518  }
1519 }
1520 
1521 // ---------------------------------------------------------------------------
1522 inline double vtkMath::ClampAndNormalizeValue(double value, const double range[2])
1523 {
1524  assert("pre: valid_range" && range[0] <= range[1]);
1525 
1526  double result;
1527  if (range[0] == range[1])
1528  {
1529  result = 0.0;
1530  }
1531  else
1532  {
1533  // clamp
1534  result = vtkMath::ClampValue(value, range[0], range[1]);
1535 
1536  // normalize
1537  result = (result - range[0]) / (range[1] - range[0]);
1538  }
1539 
1540  assert("post: valid_result" && result >= 0.0 && result <= 1.0);
1541 
1542  return result;
1543 }
1544 
1545 //-----------------------------------------------------------------------------
1546 template <class T1, class T2>
1547 inline void vtkMath::TensorFromSymmetricTensor(const T1 symmTensor[9], T2 tensor[9])
1548 {
1549  for (int i = 0; i < 3; ++i)
1550  {
1551  tensor[4 * i] = symmTensor[i];
1552  }
1553  tensor[1] = tensor[3] = symmTensor[3];
1554  tensor[2] = tensor[6] = symmTensor[5];
1555  tensor[5] = tensor[7] = symmTensor[4];
1556 }
1557 
1558 //-----------------------------------------------------------------------------
1559 template <class T>
1560 inline void vtkMath::TensorFromSymmetricTensor(T tensor[9])
1561 {
1562  tensor[6] = tensor[5]; // XZ
1563  tensor[7] = tensor[4]; // YZ
1564  tensor[8] = tensor[2]; // ZZ
1565  tensor[4] = tensor[1]; // YY
1566  tensor[5] = tensor[7]; // YZ
1567  tensor[2] = tensor[6]; // XZ
1568  tensor[1] = tensor[3]; // XY
1569 }
1570 
1571 namespace vtk_detail
1572 {
1573 // Can't specialize templates inside a template class, so we move the impl here.
1574 template <typename OutT>
1575 void RoundDoubleToIntegralIfNecessary(double val, OutT* ret)
1576 { // OutT is integral -- clamp and round
1577  if (!vtkMath::IsNan(val))
1578  {
1579  double min = static_cast<double>(vtkTypeTraits<OutT>::Min());
1580  double max = static_cast<double>(vtkTypeTraits<OutT>::Max());
1581  val = vtkMath::ClampValue(val, min, max);
1582  *ret = static_cast<OutT>((val >= 0.0) ? (val + 0.5) : (val - 0.5));
1583  }
1584  else
1585  *ret = 0;
1586 }
1587 template <>
1588 inline void RoundDoubleToIntegralIfNecessary(double val, double* retVal)
1589 { // OutT is double: passthrough
1590  *retVal = val;
1591 }
1592 template <>
1593 inline void RoundDoubleToIntegralIfNecessary(double val, float* retVal)
1594 { // OutT is float -- just clamp (as doubles, then the cast to float is well-defined.)
1595  if (!vtkMath::IsNan(val))
1596  {
1597  double min = static_cast<double>(vtkTypeTraits<float>::Min());
1598  double max = static_cast<double>(vtkTypeTraits<float>::Max());
1599  val = vtkMath::ClampValue(val, min, max);
1600  *retVal = static_cast<float>(val);
1601  }
1602  else
1603  *retVal = val;
1604 }
1605 } // end namespace vtk_detail
1606 
1607 //-----------------------------------------------------------------------------
1608 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1609 #define VTK_MATH_ISINF_IS_INLINE
1610 inline vtkTypeBool vtkMath::IsInf(double x)
1611 {
1612 #if defined(VTK_HAS_STD_ISINF)
1613  return std::isinf(x);
1614 #else
1615  return (isinf(x) != 0); // Force conversion to bool
1616 #endif
1617 }
1618 #endif
1619 
1620 //-----------------------------------------------------------------------------
1621 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1622 #define VTK_MATH_ISNAN_IS_INLINE
1623 inline vtkTypeBool vtkMath::IsNan(double x)
1624 {
1625 #if defined(VTK_HAS_STD_ISNAN)
1626  return std::isnan(x);
1627 #else
1628  return (isnan(x) != 0); // Force conversion to bool
1629 #endif
1630 }
1631 #endif
1632 
1633 //-----------------------------------------------------------------------------
1634 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1635 #define VTK_MATH_ISFINITE_IS_INLINE
1636 inline bool vtkMath::IsFinite(double x)
1637 {
1638 #if defined(VTK_HAS_STD_ISFINITE)
1639  return std::isfinite(x);
1640 #elif defined(VTK_HAS_ISFINITE)
1641  return (isfinite(x) != 0); // Force conversion to bool
1642 #else
1643  return (finite(x) != 0); // Force conversion to bool
1644 #endif
1645 }
1646 #endif
1647 
1648 #endif
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:50
vtkFrustumSelector is a vtkSelector that selects elements based on whether they are inside or interse...
a simple class to control print indentation
Definition: vtkIndent.h:34
performs common math operations
Definition: vtkMath.h:86
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:413
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)
static void Multiply3x3(const double A[3][3], const double B[3][3], double C[3][3])
static double Norm(const double *x, int n)
static int Round(float f)
Rounds a float to the nearest integer.
Definition: vtkMath.h:117
static int * BeginCombination(int m, int n)
Start iterating over "m choose n" objects.
static double Norm2D(const double x[2])
Compute the norm of a 2-vector.
Definition: vtkMath.h:615
static void XYZToRGB(double x, double y, double z, double *r, double *g, double *b)
static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4])
static void Subtract(const float a[3], const float b[3], float c[3])
Subtraction of two 3-vectors (float version).
Definition: vtkMath.h:335
static void LUSolve3x3(const double A[3][3], const int index[3], double x[3])
static void Multiply3x3(const double A[3][3], const double in[3], double out[3])
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:580
static bool ProjectVector(const double a[3], const double b[3], double projection[3])
static vtkSmartPointer< vtkMathInternal > Internal
Definition: vtkMath.h:1265
static float Norm(const float *x, int n)
Compute the norm of n-vector.
static vtkTypeBool ExtentIsWithinOtherExtent(const int extent1[6], const int extent2[6])
Return true if first 3D extent is within second 3D extent Extent is x-min, x-max, y-min,...
static void Add(const double a[3], const double b[3], double c[3])
Addition of two 3-vectors (double version).
Definition: vtkMath.h:324
static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v)
static float Norm(const float v[3])
Compute the norm of 3-vector (float version).
Definition: vtkMath.h:469
static vtkTypeBool Jacobi(double **a, double *w, double **v)
static void XYZToLab(const double xyz[3], double lab[3])
Convert Color from the CIE XYZ system to CIE-L*ab.
Definition: vtkMath.h:1032
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 double GaussianAmplitude(const double variance, const double distanceFromMean)
Compute the amplitude of a Gaussian function with mean=0 and specified variance.
static void SingularValueDecomposition3x3(const float A[3][3], float U[3][3], float w[3], float VT[3][3])
Perform singular value decomposition on a 3x3 matrix.
static double Nan()
Special IEEE-754 number used to represent Not-A-Number (Nan).
static void Perpendiculars(const float v1[3], float v2[3], float v3[3], double theta)
static double Gaussian(double mean, double std)
Generate pseudo-random numbers distributed according to the Gaussian distribution with mean mean and ...
static bool IsFinite(double x)
Test if a number has finite value i.e.
static void LUSolveLinearSystem(double **A, int *index, double *x, int size)
Solve linear equations Ax = b using LU decomposition A = LU where L is lower triangular matrix and U ...
static double EstimateMatrixCondition(const double *const *A, int size)
Estimate the condition number of a LU factored matrix.
static void LUFactor3x3(float A[3][3], int index[3])
LU Factorization of a 3x3 matrix.
static void FreeCombination(int *combination)
Free the "iterator" array created by vtkMath::BeginCombination.
static double Random(double min, double max)
Generate pseudo-random numbers distributed according to the uniform distribution between min and max.
static void TensorFromSymmetricTensor(const T1 symmTensor[6], T2 tensor[9])
Convert a 6-Component symmetric tensor into a 9-Component tensor, no allocation performed.
static void LabToXYZ(const double lab[3], double xyz[3])
Convert color from the CIE-L*ab system to CIE XYZ.
Definition: vtkMath.h:1021
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:405
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)
static vtkTypeBool GetAdjustedScalarRange(vtkDataArray *array, int comp, double range[2])
Get a vtkDataArray's scalar range for a given component.
static bool ProjectVector(const float a[3], const float b[3], float projection[3])
Compute the projection of vector a on vector b and return it in projection[3].
static void Cross(const float a[3], const float b[3], float c[3])
Cross product of two 3-vectors.
Definition: vtkMath.h:1441
static void MultiplyScalar2D(float a[2], float s)
Multiplies a 2-vector by a scalar (float version).
Definition: vtkMath.h:370
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:1005
static double Determinant2x2(const double c1[2], const double c2[2])
Definition: vtkMath.h:642
static T Max(const T &a, const T &b)
Returns the maximum of the two arguments provided.
Definition: vtkMath.h:1342
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:594
static void RandomSeed(int s)
Initialize seed value.
static double Normalize2D(double v[2])
Normalize (in place) a 2-vector.
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:394
static void LabToRGB(double L, double a, double b, double *red, double *green, double *blue)
static double Gaussian()
Generate pseudo-random numbers distributed according to the standard normal distribution.
static void Multiply3x3(const float A[3][3], const float in[3], float out[3])
Multiply a vector by a 3x3 matrix.
static int Ceil(double x)
Rounds a double to the nearest integer not less than itself.
Definition: vtkMath.h:1327
static void HSVToRGB(const double hsv[3], double rgb[3])
Definition: vtkMath.h:1010
static double Inf()
Special IEEE-754 number used to represent positive infinity.
static vtkMath * New()
static double GaussianAmplitude(const double mean, const double variance, const double position)
Compute the amplitude of a Gaussian function with specified mean and variance.
static float Normalize2D(float v[2])
Normalize (in place) a 2-vector.
static vtkTypeBool Jacobi(float **a, float *w, float **v)
Jacobi iteration for the solution of eigenvectors/eigenvalues of a 3x3 real symmetric matrix.
static int PlaneIntersectsAABB(const double bounds[6], const double normal[3], const double point[3])
Implements Plane / Axis-Aligned Bounding-Box intersection as described in Graphics Gems IV,...
static void RGBToXYZ(const double rgb[3], double xyz[3])
Convert color from the RGB system to CIE XYZ.
Definition: vtkMath.h:1054
static float Distance2BetweenPoints(const float p1[3], const float p2[3])
Compute distance squared between two points p1 and p2.
Definition: vtkMath.h:1426
static int NearestPowerOfTwo(int x)
Compute the nearest power of two that is not less than x.
Definition: vtkMath.h:1304
static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b)
static void SingularValueDecomposition3x3(const double A[3][3], double U[3][3], double w[3], double VT[3][3])
static void Invert3x3(const double A[3][3], double AI[3][3])
static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b)
static void MultiplyQuaternion(const double q1[4], const double q2[4], double q[4])
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:435
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 float RadiansFromDegrees(float degrees)
Convert degrees into radians.
Definition: vtkMath.h:1273
static void RotateVectorByWXYZ(const double v[3], const double q[4], double r[3])
static void Add(const float a[3], const float b[3], float c[3])
Addition of two 3-vectors (float version).
Definition: vtkMath.h:313
static int CeilLog2(vtkTypeUInt64 x)
Gives the exponent of the lowest power of two not less than x.
static vtkTypeBool AreBoundsInitialized(const double bounds[6])
Are the bounds initialized?
Definition: vtkMath.h:1105
static double Pi()
A mathematical constant.
Definition: vtkMath.h:95
static bool ProjectVector2D(const double a[2], const double b[2], double 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 double GaussianWeight(const double variance, const double distanceFromMean)
Compute the amplitude of an unnormalized Gaussian function with mean=0 and specified variance.
static void Subtract(const double a[3], const double b[3], double c[3])
Subtraction of two 3-vectors (double version).
Definition: vtkMath.h:346
static void Orthogonalize3x3(const double A[3][3], double B[3][3])
static void XYZToRGB(const double xyz[3], double rgb[3])
Convert color from the CIE XYZ system to RGB.
Definition: vtkMath.h:1043
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:1522
static void MultiplyScalar(double a[3], double s)
Multiplies a 3-vector by a scalar (double version).
Definition: vtkMath.h:382
static double Dot2D(const double x[2], const double y[2])
Dot product of two 2-vectors.
Definition: vtkMath.h:575
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])
~vtkMath() override
Definition: vtkMath.h:1263
static void RGBToLab(const double rgb[3], double lab[3])
Convert color from the RGB system to CIE-L*ab.
Definition: vtkMath.h:1068
static int Floor(double x)
Rounds a double to the nearest integer not greater than itself.
Definition: vtkMath.h:1318
static void RotateVectorByNormalizedQuaternion(const double v[3], const double q[4], double r[3])
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:641
static void RGBToHSV(const double rgb[3], double hsv[3])
Definition: vtkMath.h:990
static vtkTypeBool JacobiN(double **a, int n, double *w, double **v)
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:1285
static float Determinant2x2(const float c1[2], const float c2[2])
Compute determinant of 2x2 matrix.
Definition: vtkMath.h:632
static int Round(double f)
Definition: vtkMath.h:118
static vtkTypeBool IsInf(double x)
Test if a number is equal to the special floating point value infinity.
static void UninitializeBounds(double bounds[6])
Set the bounds to an uninitialized state.
Definition: vtkMath.h:1090
static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v)
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:421
static double Norm(const double v[3])
Compute the norm of 3-vector (double version).
Definition: vtkMath.h:474
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:126
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 void Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
Convert a 3x3 matrix into a quaternion.
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Returns true if integer is a power of two.
Definition: vtkMath.h:1297
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:1348
static void Transpose3x3(const double A[3][3], double AT[3][3])
static double Determinant3x3(const float A[3][3])
Return the determinant of a 3x3 matrix.
Definition: vtkMath.h:1472
static float Dot2D(const float x[2], const float y[2])
Dot product of two 2-vectors.
Definition: vtkMath.h:570
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:985
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 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:1079
static float Norm2D(const float x[2])
Compute the norm of a 2-vector.
Definition: vtkMath.h:609
static double GaussianWeight(const double mean, const double variance, const double position)
Compute the amplitude of an unnormalized Gaussian function with specified mean and variance.
static vtkTypeBool LUFactorLinearSystem(double **A, int *index, int size, double *tmpSize)
Thread safe version of LUFactorLinearSystem method.
static void LinearSolve3x3(const double A[3][3], const double x[3], double y[3])
static void XYZToLab(double x, double y, double z, double *L, double *a, double *b)
static void MultiplyScalar(float a[3], float s)
Multiplies a 3-vector by a scalar (float version).
Definition: vtkMath.h:358
static T Min(const T &a, const T &b)
Returns the minimum of the two arguments provided.
Definition: vtkMath.h:1335
static void QuaternionToMatrix3x3(const double quat[4], double A[3][3])
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:1485
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])
static void LUFactor3x3(double A[3][3], int index[3])
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)
static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4])
Multiply two quaternions.
static void QuaternionToMatrix3x3(const float quat[4], float A[3][3])
Convert a quaternion to a 3x3 rotation matrix.
vtkMath()
Definition: vtkMath.h:1262
static void ClampValues(const double *values, int nb_values, const double range[2], double *clamped_values)
static void Transpose3x3(const float A[3][3], float AT[3][3])
Transpose a 3x3 matrix.
static void ClampValues(double *values, int nb_values, const double range[2])
static int QuadraticRoot(double a, double b, double c, double min, double max, double *u)
find roots of ax^2+bx+c=0 in the interval min,max.
Park and Miller Sequence of pseudo random numbers.
abstract base class for most VTK objects
Definition: vtkObject.h:63
represent and manipulate 3D points
Definition: vtkPoints.h:34
@ point
Definition: vtkX3D.h:242
@ value
Definition: vtkX3D.h:226
@ scale
Definition: vtkX3D.h:235
@ range
Definition: vtkX3D.h:244
@ center
Definition: vtkX3D.h:236
@ position
Definition: vtkX3D.h:267
@ size
Definition: vtkX3D.h:259
@ index
Definition: vtkX3D.h:252
void RoundDoubleToIntegralIfNecessary(double val, OutT *ret)
Definition: vtkMath.h:1575
Template defining traits of native types used by VTK.
Definition: vtkTypeTraits.h:30
int vtkTypeBool
Definition: vtkABI.h:69
double vtkDeterminant3x3(const T A[3][3])
Definition: vtkMath.h:1465
#define max(a, b)