VTK
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 =========================================================================*/
44 #ifndef vtkMath_h
45 #define vtkMath_h
46 
47 #include "vtkCommonCoreModule.h" // For export macro
48 #include "vtkObject.h"
49 
50 #include "vtkMathConfigure.h" // For <cmath> and VTK_HAS_ISNAN etc.
51 
52 #include <cassert> // assert() in inline implementations.
53 
54 #ifndef DBL_MIN
55 # define VTK_DBL_MIN 2.2250738585072014e-308
56 #else // DBL_MIN
57 # define VTK_DBL_MIN DBL_MIN
58 #endif // DBL_MIN
59 
60 #ifndef DBL_EPSILON
61 # define VTK_DBL_EPSILON 2.2204460492503131e-16
62 #else // DBL_EPSILON
63 # define VTK_DBL_EPSILON DBL_EPSILON
64 #endif // DBL_EPSILON
65 
66 #ifndef VTK_DBL_EPSILON
67 # ifndef DBL_EPSILON
68 # define VTK_DBL_EPSILON 2.2204460492503131e-16
69 # else // DBL_EPSILON
70 # define VTK_DBL_EPSILON DBL_EPSILON
71 # endif // DBL_EPSILON
72 #endif // VTK_DBL_EPSILON
73 
74 class vtkDataArray;
75 class vtkPoints;
76 class vtkMathInternal;
79 
81 {
82 public:
83  static vtkMath *New();
84  vtkTypeMacro(vtkMath,vtkObject);
85  void PrintSelf(ostream& os, vtkIndent indent);
86 
88  static double Pi() { return 3.141592653589793; };
89 
91 
92  static float RadiansFromDegrees( float degrees);
93  static double RadiansFromDegrees( double degrees);
95 
97 
98  static float DegreesFromRadians( float radians);
99  static double DegreesFromRadians( double radians);
101 
103 
104  static int Round(float f) {
105  return static_cast<int>( f + ( f >= 0 ? 0.5 : -0.5 ) ); }
106  static int Round(double f) {
107  return static_cast<int>( f + ( f >= 0 ? 0.5 : -0.5 ) ); }
109 
112  static int Floor(double x);
113 
116  static int Ceil(double x);
117 
121  static int CeilLog2(vtkTypeUInt64 x);
122 
124 
125  template<class T>
126  static T Min(const T & a, const T & b);
128 
130 
131  template<class T>
132  static T Max(const T & a, const T & b);
134 
136  static bool IsPowerOfTwo(vtkTypeUInt64 x);
137 
141  static int NearestPowerOfTwo(int x);
142 
145  static vtkTypeInt64 Factorial( int N );
146 
150  static vtkTypeInt64 Binomial( int m, int n );
151 
158  static int* BeginCombination( int m, int n );
159 
166  static int NextCombination( int m, int n, int* combination );
167 
169  static void FreeCombination( int* combination);
170 
182  static void RandomSeed(int s);
183 
192  static int GetSeed();
193 
203  static double Random();
204 
213  static double Random( double min, double max );
214 
223  static double Gaussian();
224 
234  static double Gaussian( double mean, double std );
235 
237 
238  static void Add(const float a[3], const float b[3], float c[3]) {
239  for (int i = 0; i < 3; ++i)
240  c[i] = a[i] + b[i];
241  }
243 
245 
246  static void Add(const double a[3], const double b[3], double c[3]) {
247  for (int i = 0; i < 3; ++i)
248  c[i] = a[i] + b[i];
249  }
251 
253 
255  static void Subtract(const float a[3], const float b[3], float c[3]) {
256  for (int i = 0; i < 3; ++i)
257  c[i] = a[i] - b[i];
258  }
260 
262 
264  static void Subtract(const double a[3], const double b[3], double c[3]) {
265  for (int i = 0; i < 3; ++i)
266  c[i] = a[i] - b[i];
267  }
269 
271 
273  static void MultiplyScalar(float a[3], float s) {
274  for (int i = 0; i < 3; ++i)
275  a[i] *= s;
276  }
278 
280 
282  static void MultiplyScalar2D(float a[2], float s) {
283  for (int i = 0; i < 2; ++i)
284  a[i] *= s;
285  }
287 
289 
291  static void MultiplyScalar(double a[3], double s) {
292  for (int i = 0; i < 3; ++i)
293  a[i] *= s;
294  }
296 
298 
300  static void MultiplyScalar2D(double a[2], double s) {
301  for (int i = 0; i < 2; ++i)
302  a[i] *= s;
303  }
305 
307 
308  static float Dot(const float x[3], const float y[3]) {
309  return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
311 
313 
314  static double Dot(const double x[3], const double y[3]) {
315  return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
317 
319 
320  static void Outer(const float x[3], const float y[3], float A[3][3]) {
321  for (int i=0; i < 3; i++)
322  for (int j=0; j < 3; j++)
323  A[i][j] = x[i] * y[j];
324  }
326 
327 
328  static void Outer(const double x[3], const double y[3], double A[3][3]) {
329  for (int i=0; i < 3; i++)
330  for (int j=0; j < 3; j++)
331  A[i][j] = x[i] * y[j];
332  }
334 
336  static void Cross(const float x[3], const float y[3], float z[3]);
337 
340  static void Cross(const double x[3], const double y[3], double z[3]);
341 
343 
344  static float Norm(const float* x, int n);
345  static double Norm(const double* x, int n);
347 
349 
350  static float Norm(const float x[3]) {
351  return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] ) );};
353 
355 
356  static double Norm(const double x[3]) {
357  return sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] );};
359 
361  static float Normalize(float x[3]);
362 
365  static double Normalize(double x[3]);
366 
368 
373  static void Perpendiculars(const double x[3], double y[3], double z[3],
374  double theta);
375  static void Perpendiculars(const float x[3], float y[3], float z[3],
376  double theta);
378 
380 
383  static bool ProjectVector(const float a[3], const float b[3], float projection[3]);
384  static bool ProjectVector(const double a[3], const double b[3], double projection[3]);
386 
388 
392  static bool ProjectVector2D(const float a[2], const float b[2], float projection[2]);
393  static bool ProjectVector2D(const double a[2], const double b[2], double projection[2]);
395 
397  static float Distance2BetweenPoints(const float x[3], const float y[3]);
398 
401  static double Distance2BetweenPoints(const double x[3], const double y[3]);
402 
404  static double AngleBetweenVectors(const double v1[3], const double v2[3]);
405 
409  static double GaussianAmplitude(const double variance, const double distanceFromMean);
410 
414  static double GaussianAmplitude(const double mean, const double variance, const double position);
415 
420  static double GaussianWeight(const double variance, const double distanceFromMean);
421 
426  static double GaussianWeight(const double mean, const double variance, const double position);
427 
429 
430  static float Dot2D(const float x[2], const float y[2]) {
431  return ( x[0] * y[0] + x[1] * y[1] );};
433 
435 
436  static double Dot2D(const double x[2], const double y[2]) {
437  return ( x[0] * y[0] + x[1] * y[1] );};
439 
441 
442  static void Outer2D(const float x[2], const float y[2], float A[2][2])
443  {
444  for (int i=0; i < 2; i++)
445  {
446  for (int j=0; j < 2; j++)
447  {
448  A[i][j] = x[i] * y[j];
449  }
450  }
451  }
453 
454 
455  static void Outer2D(const double x[2], const double y[2], double A[2][2])
456  {
457  for (int i=0; i < 2; i++)
458  {
459  for (int j=0; j < 2; j++)
460  {
461  A[i][j] = x[i] * y[j];
462  }
463  }
464  }
466 
468 
469  static float Norm2D(const float x[2]) {
470  return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] ) );};
472 
474 
475  static double Norm2D(const double x[2]) {
476  return sqrt( x[0] * x[0] + x[1] * x[1] );};
478 
480  static float Normalize2D(float x[2]);
481 
484  static double Normalize2D(double x[2]);
485 
487 
488  static float Determinant2x2(const float c1[2], const float c2[2]) {
489  return (c1[0] * c2[1] - c2[0] * c1[1] );};
491 
493 
494  static double Determinant2x2(double a, double b, double c, double d) {
495  return (a * d - b * c);};
496  static double Determinant2x2(const double c1[2], const double c2[2]) {
497  return (c1[0] * c2[1] - c2[0] * c1[1] );};
499 
501 
502  static void LUFactor3x3(float A[3][3], int index[3]);
503  static void LUFactor3x3(double A[3][3], int index[3]);
505 
507 
508  static void LUSolve3x3(const float A[3][3], const int index[3],
509  float x[3]);
510  static void LUSolve3x3(const double A[3][3], const int index[3],
511  double x[3]);
513 
515 
517  static void LinearSolve3x3(const float A[3][3], const float x[3],
518  float y[3]);
519  static void LinearSolve3x3(const double A[3][3], const double x[3],
520  double y[3]);
522 
524 
525  static void Multiply3x3(const float A[3][3], const float in[3],
526  float out[3]);
527  static void Multiply3x3(const double A[3][3], const double in[3],
528  double out[3]);
530 
532 
533  static void Multiply3x3(const float A[3][3], const float B[3][3],
534  float C[3][3]);
535  static void Multiply3x3(const double A[3][3], const double B[3][3],
536  double C[3][3]);
538 
540 
542  static void MultiplyMatrix(double **A, double **B,
543  unsigned int rowA, unsigned int colA,
544  unsigned int rowB, unsigned int colB,
545  double **C);
547 
549 
551  static void Transpose3x3(const float A[3][3], float AT[3][3]);
552  static void Transpose3x3(const double A[3][3], double AT[3][3]);
554 
556 
558  static void Invert3x3(const float A[3][3], float AI[3][3]);
559  static void Invert3x3(const double A[3][3], double AI[3][3]);
561 
563 
564  static void Identity3x3(float A[3][3]);
565  static void Identity3x3(double A[3][3]);
567 
569 
570  static double Determinant3x3(float A[3][3]);
571  static double Determinant3x3(double A[3][3]);
573 
575 
576  static float Determinant3x3(const float c1[3],
577  const float c2[3],
578  const float c3[3]);
580 
582 
583  static double Determinant3x3(const double c1[3],
584  const double c2[3],
585  const double c3[3]);
587 
589 
591  static double Determinant3x3(double a1, double a2, double a3,
592  double b1, double b2, double b3,
593  double c1, double c2, double c3);
595 
597 
601  static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
602  static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
604 
606 
611  static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
612  static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
614 
616 
619  static void MultiplyQuaternion( const float q1[4], const float q2[4], float q[4] );
620  static void MultiplyQuaternion( const double q1[4], const double q2[4], double q[4] );
622 
624 
627  static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
628  static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
630 
632 
636  static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
637  static void Diagonalize3x3(const double A[3][3],double w[3],double V[3][3]);
639 
641 
648  static void SingularValueDecomposition3x3(const float A[3][3],
649  float U[3][3], float w[3],
650  float VT[3][3]);
651  static void SingularValueDecomposition3x3(const double A[3][3],
652  double U[3][3], double w[3],
653  double VT[3][3]);
655 
660  static int SolveLinearSystem(double **A, double *x, int size);
661 
665  static int InvertMatrix(double **A, double **AI, int size);
666 
668 
670  static int InvertMatrix(double **A, double **AI, int size,
671  int *tmp1Size, double *tmp2Size);
673 
689  static int LUFactorLinearSystem(double **A, int *index, int size);
690 
692 
694  static int LUFactorLinearSystem(double **A, int *index, int size,
695  double *tmpSize);
697 
699 
705  static void LUSolveLinearSystem(double **A, int *index,
706  double *x, int size);
708 
716  static double EstimateMatrixCondition(double **A, int size);
717 
719 
724  static int Jacobi(float **a, float *w, float **v);
725  static int Jacobi(double **a, double *w, double **v);
727 
729 
735  static int JacobiN(float **a, int n, float *w, float **v);
736  static int JacobiN(double **a, int n, double *w, double **v);
738 
740 
750  static int SolveHomogeneousLeastSquares(int numberOfSamples, double **xt, int xOrder,
751  double **mt);
753 
754 
756 
767  static int SolveLeastSquares(int numberOfSamples, double **xt, int xOrder,
768  double **yt, int yOrder, double **mt, int checkHomogeneous=1);
770 
772 
776  static void RGBToHSV(const float rgb[3], float hsv[3])
777  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
778  static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v);
779  static double* RGBToHSV(const double rgb[3]);
780  static double* RGBToHSV(double r, double g, double b);
781  static void RGBToHSV(const double rgb[3], double hsv[3])
782  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
783  static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v);
785 
787 
791  static void HSVToRGB(const float hsv[3], float rgb[3])
792  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
793  static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b);
794  static double* HSVToRGB(const double hsv[3]);
795  static double* HSVToRGB(double h, double s, double v);
796  static void HSVToRGB(const double hsv[3], double rgb[3])
797  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
798  static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b);
800 
802 
803  static void LabToXYZ(const double lab[3], double xyz[3]) {
804  LabToXYZ(lab[0], lab[1], lab[2], xyz+0, xyz+1, xyz+2);
805  }
806  static void LabToXYZ(double L, double a, double b,
807  double *x, double *y, double *z);
808  static double *LabToXYZ(const double lab[3]);
810 
812 
813  static void XYZToLab(const double xyz[3], double lab[3]) {
814  XYZToLab(xyz[0], xyz[1], xyz[2], lab+0, lab+1, lab+2);
815  }
816  static void XYZToLab(double x, double y, double z,
817  double *L, double *a, double *b);
818  static double *XYZToLab(const double xyz[3]);
820 
822 
823  static void XYZToRGB(const double xyz[3], double rgb[3]) {
824  XYZToRGB(xyz[0], xyz[1], xyz[2], rgb+0, rgb+1, rgb+2);
825  }
826  static void XYZToRGB(double x, double y, double z,
827  double *r, double *g, double *b);
828  static double *XYZToRGB(const double xyz[3]);
830 
832 
833  static void RGBToXYZ(const double rgb[3], double xyz[3]) {
834  RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz+0, xyz+1, xyz+2);
835  }
836  static void RGBToXYZ(double r, double g, double b,
837  double *x, double *y, double *z);
838  static double *RGBToXYZ(const double rgb[3]);
840 
842 
845  static void RGBToLab(const double rgb[3], double lab[3]) {
846  RGBToLab(rgb[0], rgb[1], rgb[2], lab+0, lab+1, lab+2);
847  }
848  static void RGBToLab(double red, double green, double blue,
849  double *L, double *a, double *b);
850  static double *RGBToLab(const double rgb[3]);
852 
854 
855  static void LabToRGB(const double lab[3], double rgb[3]) {
856  LabToRGB(lab[0], lab[1], lab[2], rgb+0, rgb+1, rgb+2);
857  }
858  static void LabToRGB(double L, double a, double b,
859  double *red, double *green, double *blue);
860  static double *LabToRGB(const double lab[3]);
862 
864 
865  static void UninitializeBounds(double bounds[6]){
866  bounds[0] = 1.0;
867  bounds[1] = -1.0;
868  bounds[2] = 1.0;
869  bounds[3] = -1.0;
870  bounds[4] = 1.0;
871  bounds[5] = -1.0;
872  }
874 
876 
877  static int AreBoundsInitialized(double bounds[6]){
878  if ( bounds[1]-bounds[0]<0.0 )
879  {
880  return 0;
881  }
882  return 1;
883  }
885 
887 
889  static void ClampValue(double *value, const double range[2]);
890  static void ClampValue(double value, const double range[2], double *clamped_value);
891  static void ClampValues(
892  double *values, int nb_values, const double range[2]);
893  static void ClampValues(
894  const double *values, int nb_values, const double range[2], double *clamped_values);
896 
898 
901  static double ClampAndNormalizeValue(double value,
902  const double range[2]);
904 
906 
912  static int GetScalarTypeFittingRange(
913  double range_min, double range_max,
914  double scale = 1.0, double shift = 0.0);
916 
918 
924  static int GetAdjustedScalarRange(
925  vtkDataArray *array, int comp, double range[2]);
927 
930  static int ExtentIsWithinOtherExtent(int extent1[6], int extent2[6]);
931 
935  static int BoundsIsWithinOtherBounds(double bounds1[6], double bounds2[6], double delta[3]);
936 
940  static int PointIsWithinBounds(double point[3], double bounds[6], double delta[3]);
941 
950  static double Solve3PointCircle(const double p1[3], const double p2[3], const double p3[3], double center[3]);
951 
953  static double Inf();
954 
956  static double NegInf();
957 
959  static double Nan();
960 
963  static int IsInf(double x);
964 
967  static int IsNan(double x);
968 
971  static bool IsFinite(double x);
972 
973 protected:
974  vtkMath() {}
975  ~vtkMath() {}
976 
977  static vtkMathInternal Internal;
978 private:
979  vtkMath(const vtkMath&); // Not implemented.
980  void operator=(const vtkMath&); // Not implemented.
981 };
982 
983 //----------------------------------------------------------------------------
984 inline float vtkMath::RadiansFromDegrees( float x )
985 {
986  return x * 0.017453292f;
987 }
988 
989 //----------------------------------------------------------------------------
990 inline double vtkMath::RadiansFromDegrees( double x )
991 {
992  return x * 0.017453292519943295;
993 }
994 
995 //----------------------------------------------------------------------------
996 inline float vtkMath::DegreesFromRadians( float x )
997 {
998  return x * 57.2957795131f;
999 }
1000 
1001 //----------------------------------------------------------------------------
1002 inline double vtkMath::DegreesFromRadians( double x )
1003 {
1004  return x * 57.29577951308232;
1005 }
1006 
1007 //----------------------------------------------------------------------------
1008 inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
1009 {
1010  return ((x != 0) & ((x & (x - 1)) == 0));
1011 }
1012 
1013 //----------------------------------------------------------------------------
1014 // Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1016 {
1017  unsigned int z = ((x > 0) ? x - 1 : 0);
1018  z |= z >> 1;
1019  z |= z >> 2;
1020  z |= z >> 4;
1021  z |= z >> 8;
1022  z |= z >> 16;
1023  return static_cast<int>(z + 1);
1024 }
1025 
1026 //----------------------------------------------------------------------------
1027 // Modify the trunc() operation provided by static_cast<int>() to get floor(),
1028 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1029 inline int vtkMath::Floor(double x)
1030 {
1031  int i = static_cast<int>(x);
1032  return i - ( i > x );
1033 }
1034 
1035 //----------------------------------------------------------------------------
1036 // Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1037 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1038 inline int vtkMath::Ceil(double x)
1039 {
1040  int i = static_cast<int>(x);
1041  return i + ( i < x );
1042 }
1043 
1044 //----------------------------------------------------------------------------
1045 template<class T>
1046 inline T vtkMath::Min(const T & a, const T & b)
1047 {
1048  return (a < b ? a : b);
1049 }
1050 
1051 //----------------------------------------------------------------------------
1052 template<class T>
1053 inline T vtkMath::Max(const T & a, const T & b)
1054 {
1055  return (a > b ? a : b);
1056 }
1057 
1058 //----------------------------------------------------------------------------
1059 inline float vtkMath::Normalize(float x[3])
1060 {
1061  float den = vtkMath::Norm( x );
1062  if ( den != 0.0 )
1063  {
1064  for (int i=0; i < 3; i++)
1065  {
1066  x[i] /= den;
1067  }
1068  }
1069  return den;
1070 }
1071 
1072 //----------------------------------------------------------------------------
1073 inline double vtkMath::Normalize(double x[3])
1074 {
1075  double den = vtkMath::Norm( x );
1076  if ( den != 0.0 )
1077  {
1078  for (int i=0; i < 3; i++)
1079  {
1080  x[i] /= den;
1081  }
1082  }
1083  return den;
1084 }
1085 
1086 //----------------------------------------------------------------------------
1087 inline float vtkMath::Normalize2D(float x[3])
1088 {
1089  float den = vtkMath::Norm2D( x );
1090  if ( den != 0.0 )
1091  {
1092  for (int i=0; i < 2; i++)
1093  {
1094  x[i] /= den;
1095  }
1096  }
1097  return den;
1098 }
1099 
1100 //----------------------------------------------------------------------------
1101 inline double vtkMath::Normalize2D(double x[3])
1102 {
1103  double den = vtkMath::Norm2D( x );
1104  if ( den != 0.0 )
1105  {
1106  for (int i=0; i < 2; i++)
1107  {
1108  x[i] /= den;
1109  }
1110  }
1111  return den;
1112 }
1113 
1114 //----------------------------------------------------------------------------
1115 inline float vtkMath::Determinant3x3(const float c1[3],
1116  const float c2[3],
1117  const float c3[3])
1118 {
1119  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1120  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1121 }
1122 
1123 //----------------------------------------------------------------------------
1124 inline double vtkMath::Determinant3x3(const double c1[3],
1125  const double c2[3],
1126  const double c3[3])
1127 {
1128  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1129  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1130 }
1131 
1132 //----------------------------------------------------------------------------
1133 inline double vtkMath::Determinant3x3(double a1, double a2, double a3,
1134  double b1, double b2, double b3,
1135  double c1, double c2, double c3)
1136 {
1137  return ( a1 * vtkMath::Determinant2x2( b2, b3, c2, c3 )
1138  - b1 * vtkMath::Determinant2x2( a2, a3, c2, c3 )
1139  + c1 * vtkMath::Determinant2x2( a2, a3, b2, b3 ) );
1140 }
1141 
1142 //----------------------------------------------------------------------------
1143 inline float vtkMath::Distance2BetweenPoints(const float x[3],
1144  const float y[3])
1145 {
1146  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1147  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1148  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1149 }
1150 
1151 //----------------------------------------------------------------------------
1152 inline double vtkMath::Distance2BetweenPoints(const double x[3],
1153  const double y[3])
1154 {
1155  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1156  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1157  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1158 }
1159 
1160 //----------------------------------------------------------------------------
1161 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1162 inline void vtkMath::Cross(const float x[3], const float y[3], float z[3])
1163 {
1164  float Zx = x[1] * y[2] - x[2] * y[1];
1165  float Zy = x[2] * y[0] - x[0] * y[2];
1166  float Zz = x[0] * y[1] - x[1] * y[0];
1167  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1168 }
1169 
1170 //----------------------------------------------------------------------------
1171 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1172 inline void vtkMath::Cross(const double x[3], const double y[3], double z[3])
1173 {
1174  double Zx = x[1] * y[2] - x[2] * y[1];
1175  double Zy = x[2] * y[0] - x[0] * y[2];
1176  double Zz = x[0] * y[1] - x[1] * y[0];
1177  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1178 }
1179 
1180 //BTX
1181 //----------------------------------------------------------------------------
1182 template<class T>
1183 inline double vtkDeterminant3x3(T A[3][3])
1184 {
1185  return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] +
1186  A[2][0] * A[0][1] * A[1][2] - A[0][0] * A[2][1] * A[1][2] -
1187  A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1188 }
1189 //ETX
1190 
1191 //----------------------------------------------------------------------------
1192 inline double vtkMath::Determinant3x3(float A[3][3])
1193 {
1194  return vtkDeterminant3x3( A );
1195 }
1196 
1197 //----------------------------------------------------------------------------
1198 inline double vtkMath::Determinant3x3(double A[3][3])
1199 {
1200  return vtkDeterminant3x3( A );
1201 }
1202 
1203 //----------------------------------------------------------------------------
1204 inline void vtkMath::ClampValue(double *value, const double range[2])
1205 {
1206  if (value && range)
1207  {
1208  if (*value < range[0])
1209  {
1210  *value = range[0];
1211  }
1212  else if (*value > range[1])
1213  {
1214  *value = range[1];
1215  }
1216  }
1217 }
1218 
1219 //----------------------------------------------------------------------------
1221  double value, const double range[2], double *clamped_value)
1222 {
1223  if (range && clamped_value)
1224  {
1225  if (value < range[0])
1226  {
1227  *clamped_value = range[0];
1228  }
1229  else if (value > range[1])
1230  {
1231  *clamped_value = range[1];
1232  }
1233  else
1234  {
1235  *clamped_value = value;
1236  }
1237  }
1238 }
1239 
1240 // ---------------------------------------------------------------------------
1242  const double range[2])
1243 {
1244  assert("pre: valid_range" && range[0]<=range[1]);
1245 
1246  double result;
1247  if(range[0]==range[1])
1248  {
1249  result=0.0;
1250  }
1251  else
1252  {
1253  // clamp
1254  if(value<range[0])
1255  {
1256  result=range[0];
1257  }
1258  else
1259  {
1260  if(value>range[1])
1261  {
1262  result=range[1];
1263  }
1264  else
1265  {
1266  result=value;
1267  }
1268  }
1269 
1270  // normalize
1271  result=( result - range[0] ) / ( range[1] - range[0] );
1272  }
1273 
1274  assert("post: valid_result" && result>=0.0 && result<=1.0);
1275 
1276  return result;
1277 }
1278 
1279 //-----------------------------------------------------------------------------
1280 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1281 #define VTK_MATH_ISINF_IS_INLINE
1282 inline int vtkMath::IsInf(double x)
1283 {
1284 #if defined(VTK_HAS_STD_ISINF)
1285  return std::isinf(x);
1286 #else
1287  return (isinf(x) != 0); // Force conversion to bool
1288 #endif
1289 }
1290 #endif
1291 
1292 //-----------------------------------------------------------------------------
1293 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1294 #define VTK_MATH_ISNAN_IS_INLINE
1295 inline int vtkMath::IsNan(double x)
1296 {
1297 #if defined(VTK_HAS_STD_ISNAN)
1298  return std::isnan(x);
1299 #else
1300  return (isnan(x) != 0); // Force conversion to bool
1301 #endif
1302 }
1303 #endif
1304 
1305 //-----------------------------------------------------------------------------
1306 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1307 #define VTK_MATH_ISFINITE_IS_INLINE
1308 inline bool vtkMath::IsFinite(double x)
1309 {
1310 #if defined(VTK_HAS_STD_ISFINITE)
1311  return std::isfinite(x);
1312 #elif defined(VTK_HAS_ISFINITE)
1313  return (isfinite(x) != 0); // Force conversion to bool
1314 #else
1315  return (finite(x) != 0); // Force conversion to bool
1316 #endif
1317 }
1318 #endif
1319 
1320 #endif
static void MultiplyScalar2D(float a[2], float s)
Definition: vtkMath.h:282
static bool IsFinite(double x)
static float Dot2D(const float x[2], const float y[2])
Definition: vtkMath.h:430
static void Cross(const float x[3], const float y[3], float z[3])
Definition: vtkMath.h:1162
static int IsInf(double x)
abstract base class for most VTK objects
Definition: vtkObject.h:61
static void LabToXYZ(const double lab[3], double xyz[3])
Definition: vtkMath.h:803
static double Norm(const double x[3])
Definition: vtkMath.h:356
static double Pi()
Definition: vtkMath.h:88
static void ClampValue(double *value, const double range[2])
Definition: vtkMath.h:1204
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Definition: vtkMath.h:1008
static void Outer(const float x[3], const float y[3], float A[3][3])
Definition: vtkMath.h:320
static float Determinant2x2(const float c1[2], const float c2[2])
Definition: vtkMath.h:488
#define VTKCOMMONCORE_EXPORT
static void RGBToHSV(const double rgb[3], double hsv[3])
Definition: vtkMath.h:781
static int Round(float f)
Definition: vtkMath.h:104
vtkMath()
Definition: vtkMath.h:974
static void RGBToHSV(const float rgb[3], float hsv[3])
Definition: vtkMath.h:776
static int AreBoundsInitialized(double bounds[6])
Definition: vtkMath.h:877
static double ClampAndNormalizeValue(double value, const double range[2])
Definition: vtkMath.h:1241
static void Outer(const double x[3], const double y[3], double A[3][3])
Definition: vtkMath.h:328
static void Add(const double a[3], const double b[3], double c[3])
Definition: vtkMath.h:246
static void XYZToRGB(const double xyz[3], double rgb[3])
Definition: vtkMath.h:823
static float Norm2D(const float x[2])
Definition: vtkMath.h:469
static float Normalize2D(float x[2])
static void UninitializeBounds(double bounds[6])
Definition: vtkMath.h:865
static int NearestPowerOfTwo(int x)
Definition: vtkMath.h:1015
virtual void PrintSelf(ostream &os, vtkIndent indent)
static void RGBToXYZ(const double rgb[3], double xyz[3])
Definition: vtkMath.h:833
static T Min(const T &a, const T &b)
Definition: vtkMath.h:1046
a simple class to control print indentation
Definition: vtkIndent.h:38
static float Dot(const float x[3], const float y[3])
Definition: vtkMath.h:308
static void Subtract(const float a[3], const float b[3], float c[3])
Definition: vtkMath.h:255
static void Subtract(const double a[3], const double b[3], double c[3])
Definition: vtkMath.h:264
static int Floor(double x)
Definition: vtkMath.h:1029
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
static double Determinant2x2(double a, double b, double c, double d)
Definition: vtkMath.h:494
static float RadiansFromDegrees(float degrees)
Definition: vtkMath.h:984
static void HSVToRGB(const double hsv[3], double rgb[3])
Definition: vtkMath.h:796
Park and Miller Sequence of pseudo random numbers.
static void MultiplyScalar(double a[3], double s)
Definition: vtkMath.h:291
static double Determinant3x3(float A[3][3])
Definition: vtkMath.h:1192
static float Normalize(float x[3])
Definition: vtkMath.h:1059
static void RGBToLab(const double rgb[3], double lab[3])
Definition: vtkMath.h:845
static float DegreesFromRadians(float radians)
Definition: vtkMath.h:996
static void Outer2D(const double x[2], const double y[2], double A[2][2])
Definition: vtkMath.h:455
static void Outer2D(const float x[2], const float y[2], float A[2][2])
Definition: vtkMath.h:442
static int Ceil(double x)
Definition: vtkMath.h:1038
performs common math operations
Definition: vtkMath.h:80
static double Dot2D(const double x[2], const double y[2])
Definition: vtkMath.h:436
static double Dot(const double x[3], const double y[3])
Definition: vtkMath.h:314
static void MultiplyScalar(float a[3], float s)
Definition: vtkMath.h:273
static void HSVToRGB(const float hsv[3], float rgb[3])
Definition: vtkMath.h:791
~vtkMath()
Definition: vtkMath.h:975
static double Norm2D(const double x[2])
Definition: vtkMath.h:475
static int Round(double f)
Definition: vtkMath.h:106
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
static void MultiplyScalar2D(double a[2], double s)
Definition: vtkMath.h:300
static void LabToRGB(const double lab[3], double rgb[3])
Definition: vtkMath.h:855
static vtkMathInternal Internal
Definition: vtkMath.h:977
static vtkObject * New()
double vtkDeterminant3x3(T A[3][3])
Definition: vtkMath.h:1183
static float Norm(const float *x, int n)
static float Distance2BetweenPoints(const float x[3], const float y[3])
Definition: vtkMath.h:1143
static int IsNan(double x)
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
static double Determinant2x2(const double c1[2], const double c2[2])
Definition: vtkMath.h:496
static float Norm(const float x[3])
Definition: vtkMath.h:350
static void Add(const float a[3], const float b[3], float c[3])
Definition: vtkMath.h:238
#define max(a, b)
represent and manipulate 3D points
Definition: vtkPoints.h:38
static T Max(const T &a, const T &b)
Definition: vtkMath.h:1053
static void XYZToLab(const double xyz[3], double lab[3])
Definition: vtkMath.h:813