VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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();
85  void PrintSelf(ostream& os, vtkIndent indent);
86 
88  static double Pi() { return 3.141592653589793; };
89 
91  VTK_LEGACY(static double DoublePi());
92 
94  VTK_LEGACY(static double DoubleTwoPi());
95 
97 
98  static float RadiansFromDegrees( float degrees);
99  static double RadiansFromDegrees( double degrees);
101 
103 
104  static float DegreesFromRadians( float radians);
105  static double DegreesFromRadians( double radians);
107 
109 
110  static int Round(float f) {
111  return static_cast<int>( f + ( f >= 0 ? 0.5 : -0.5 ) ); }
112  static int Round(double f) {
113  return static_cast<int>( f + ( f >= 0 ? 0.5 : -0.5 ) ); }
115 
118  static int Floor(double x);
119 
122  static int Ceil(double x);
123 
127  static int CeilLog2(vtkTypeUInt64 x);
128 
130  static bool IsPowerOfTwo(vtkTypeUInt64 x);
131 
135  static int NearestPowerOfTwo(int x);
136 
139  static vtkTypeInt64 Factorial( int N );
140 
144  static vtkTypeInt64 Binomial( int m, int n );
145 
152  static int* BeginCombination( int m, int n );
153 
160  static int NextCombination( int m, int n, int* combination );
161 
163  static void FreeCombination( int* combination);
164 
176  static void RandomSeed(int s);
177 
186  static int GetSeed();
187 
197  static double Random();
198 
207  static double Random( double min, double max );
208 
217  static double Gaussian();
218 
228  static double Gaussian( double mean, double std );
229 
231 
232  static void Add(const float a[3], const float b[3], float c[3]) {
233  for (int i = 0; i < 3; ++i)
234  c[i] = a[i] + b[i];
235  }
237 
239 
240  static void Add(const double a[3], const double b[3], double c[3]) {
241  for (int i = 0; i < 3; ++i)
242  c[i] = a[i] + b[i];
243  }
245 
247 
249  static void Subtract(const float a[3], const float b[3], float c[3]) {
250  for (int i = 0; i < 3; ++i)
251  c[i] = a[i] - b[i];
252  }
254 
256 
258  static void Subtract(const double a[3], const double b[3], double c[3]) {
259  for (int i = 0; i < 3; ++i)
260  c[i] = a[i] - b[i];
261  }
263 
265 
267  static void MultiplyScalar(float a[3], float s) {
268  for (int i = 0; i < 3; ++i)
269  a[i] *= s;
270  }
272 
274 
276  static void MultiplyScalar2D(float a[2], float s) {
277  for (int i = 0; i < 2; ++i)
278  a[i] *= s;
279  }
281 
283 
285  static void MultiplyScalar(double a[3], double s) {
286  for (int i = 0; i < 3; ++i)
287  a[i] *= s;
288  }
290 
292 
294  static void MultiplyScalar2D(double a[2], double s) {
295  for (int i = 0; i < 2; ++i)
296  a[i] *= s;
297  }
299 
301 
302  static float Dot(const float x[3], const float y[3]) {
303  return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
305 
307 
308  static double Dot(const double x[3], const double y[3]) {
309  return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
311 
313 
314  static void Outer(const float x[3], const float y[3], float A[3][3]) {
315  for (int i=0; i < 3; i++)
316  for (int j=0; j < 3; j++)
317  A[i][j] = x[i] * y[j];
318  }
320 
321 
322  static void Outer(const double x[3], const double y[3], double A[3][3]) {
323  for (int i=0; i < 3; i++)
324  for (int j=0; j < 3; j++)
325  A[i][j] = x[i] * y[j];
326  }
328 
330  static void Cross(const float x[3], const float y[3], float z[3]);
331 
334  static void Cross(const double x[3], const double y[3], double z[3]);
335 
337 
338  static float Norm(const float* x, int n);
339  static double Norm(const double* x, int n);
341 
343 
344  static float Norm(const float x[3]) {
345  return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] ) );};
347 
349 
350  static double Norm(const double x[3]) {
351  return sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] );};
353 
355  static float Normalize(float x[3]);
356 
359  static double Normalize(double x[3]);
360 
362 
367  static void Perpendiculars(const double x[3], double y[3], double z[3],
368  double theta);
369  static void Perpendiculars(const float x[3], float y[3], float z[3],
370  double theta);
372 
374 
377  static bool ProjectVector(const float a[3], const float b[3], float projection[3]);
378  static bool ProjectVector(const double a[3], const double b[3], double projection[3]);
380 
382 
386  static bool ProjectVector2D(const float a[2], const float b[2], float projection[2]);
387  static bool ProjectVector2D(const double a[2], const double b[2], double projection[2]);
389 
391  static float Distance2BetweenPoints(const float x[3], const float y[3]);
392 
395  static double Distance2BetweenPoints(const double x[3], const double y[3]);
396 
400  static double GaussianAmplitude(const double variance, const double distanceFromMean);
401 
405  static double GaussianAmplitude(const double mean, const double variance, const double position);
406 
411  static double GaussianWeight(const double variance, const double distanceFromMean);
412 
417  static double GaussianWeight(const double mean, const double variance, const double position);
418 
420 
421  static float Dot2D(const float x[2], const float y[2]) {
422  return ( x[0] * y[0] + x[1] * y[1] );};
424 
426 
427  static double Dot2D(const double x[2], const double y[2]) {
428  return ( x[0] * y[0] + x[1] * y[1] );};
430 
432 
433  static void Outer2D(const float x[2], const float y[2], float A[2][2])
434  {
435  for (int i=0; i < 2; i++)
436  {
437  for (int j=0; j < 2; j++)
438  {
439  A[i][j] = x[i] * y[j];
440  }
441  }
442  }
444 
445 
446  static void Outer2D(const double x[2], const double y[2], double A[2][2])
447  {
448  for (int i=0; i < 2; i++)
449  {
450  for (int j=0; j < 2; j++)
451  {
452  A[i][j] = x[i] * y[j];
453  }
454  }
455  }
457 
459 
460  static float Norm2D(const float x[2]) {
461  return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] ) );};
463 
465 
466  static double Norm2D(const double x[2]) {
467  return sqrt( x[0] * x[0] + x[1] * x[1] );};
469 
471  static float Normalize2D(float x[2]);
472 
475  static double Normalize2D(double x[2]);
476 
478 
479  static float Determinant2x2(const float c1[2], const float c2[2]) {
480  return (c1[0] * c2[1] - c2[0] * c1[1] );};
482 
484 
485  static double Determinant2x2(double a, double b, double c, double d) {
486  return (a * d - b * c);};
487  static double Determinant2x2(const double c1[2], const double c2[2]) {
488  return (c1[0] * c2[1] - c2[0] * c1[1] );};
490 
492 
493  static void LUFactor3x3(float A[3][3], int index[3]);
494  static void LUFactor3x3(double A[3][3], int index[3]);
496 
498 
499  static void LUSolve3x3(const float A[3][3], const int index[3],
500  float x[3]);
501  static void LUSolve3x3(const double A[3][3], const int index[3],
502  double x[3]);
504 
506 
508  static void LinearSolve3x3(const float A[3][3], const float x[3],
509  float y[3]);
510  static void LinearSolve3x3(const double A[3][3], const double x[3],
511  double y[3]);
513 
515 
516  static void Multiply3x3(const float A[3][3], const float in[3],
517  float out[3]);
518  static void Multiply3x3(const double A[3][3], const double in[3],
519  double out[3]);
521 
523 
524  static void Multiply3x3(const float A[3][3], const float B[3][3],
525  float C[3][3]);
526  static void Multiply3x3(const double A[3][3], const double B[3][3],
527  double C[3][3]);
529 
531 
533  static void MultiplyMatrix(const double **A, const double **B,
534  unsigned int rowA, unsigned int colA,
535  unsigned int rowB, unsigned int colB,
536  double **C);
538 
540 
542  static void Transpose3x3(const float A[3][3], float AT[3][3]);
543  static void Transpose3x3(const double A[3][3], double AT[3][3]);
545 
547 
549  static void Invert3x3(const float A[3][3], float AI[3][3]);
550  static void Invert3x3(const double A[3][3], double AI[3][3]);
552 
554 
555  static void Identity3x3(float A[3][3]);
556  static void Identity3x3(double A[3][3]);
558 
560 
561  static double Determinant3x3(float A[3][3]);
562  static double Determinant3x3(double A[3][3]);
564 
566 
567  static float Determinant3x3(const float c1[3],
568  const float c2[3],
569  const float c3[3]);
571 
573 
574  static double Determinant3x3(const double c1[3],
575  const double c2[3],
576  const double c3[3]);
578 
580 
582  static double Determinant3x3(double a1, double a2, double a3,
583  double b1, double b2, double b3,
584  double c1, double c2, double c3);
586 
588 
592  static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
593  static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
595 
597 
602  static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
603  static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
605 
607 
610  static void MultiplyQuaternion( const float q1[4], const float q2[4], float q[4] );
611  static void MultiplyQuaternion( const double q1[4], const double q2[4], double q[4] );
613 
615 
618  static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
619  static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
621 
623 
627  static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
628  static void Diagonalize3x3(const double A[3][3],double w[3],double V[3][3]);
630 
632 
639  static void SingularValueDecomposition3x3(const float A[3][3],
640  float U[3][3], float w[3],
641  float VT[3][3]);
642  static void SingularValueDecomposition3x3(const double A[3][3],
643  double U[3][3], double w[3],
644  double VT[3][3]);
646 
651  static int SolveLinearSystem(double **A, double *x, int size);
652 
656  static int InvertMatrix(double **A, double **AI, int size);
657 
659 
661  static int InvertMatrix(double **A, double **AI, int size,
662  int *tmp1Size, double *tmp2Size);
664 
680  static int LUFactorLinearSystem(double **A, int *index, int size);
681 
683 
685  static int LUFactorLinearSystem(double **A, int *index, int size,
686  double *tmpSize);
688 
690 
696  static void LUSolveLinearSystem(double **A, int *index,
697  double *x, int size);
699 
707  static double EstimateMatrixCondition(double **A, int size);
708 
710 
714  static int Jacobi(float **a, float *w, float **v);
715  static int Jacobi(double **a, double *w, double **v);
717 
719 
724  static int JacobiN(float **a, int n, float *w, float **v);
725  static int JacobiN(double **a, int n, double *w, double **v);
727 
729 
739  static int SolveHomogeneousLeastSquares(int numberOfSamples, double **xt, int xOrder,
740  double **mt);
742 
743 
745 
756  static int SolveLeastSquares(int numberOfSamples, double **xt, int xOrder,
757  double **yt, int yOrder, double **mt, int checkHomogeneous=1);
759 
761 
765  static void RGBToHSV(const float rgb[3], float hsv[3])
766  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
767  static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v);
768  static double* RGBToHSV(const double rgb[3]);
769  static double* RGBToHSV(double r, double g, double b);
770  static void RGBToHSV(const double rgb[3], double hsv[3])
771  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
772  static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v);
774 
776 
780  static void HSVToRGB(const float hsv[3], float rgb[3])
781  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
782  static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b);
783  static double* HSVToRGB(const double hsv[3]);
784  static double* HSVToRGB(double h, double s, double v);
785  static void HSVToRGB(const double hsv[3], double rgb[3])
786  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
787  static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b);
789 
791 
792  static void LabToXYZ(const double lab[3], double xyz[3]) {
793  LabToXYZ(lab[0], lab[1], lab[2], xyz+0, xyz+1, xyz+2);
794  }
795  static void LabToXYZ(double L, double a, double b,
796  double *x, double *y, double *z);
797  static double *LabToXYZ(const double lab[3]);
799 
801 
802  static void XYZToLab(const double xyz[3], double lab[3]) {
803  XYZToLab(xyz[0], xyz[1], xyz[2], lab+0, lab+1, lab+2);
804  }
805  static void XYZToLab(double x, double y, double z,
806  double *L, double *a, double *b);
807  static double *XYZToLab(const double xyz[3]);
809 
811 
812  static void XYZToRGB(const double xyz[3], double rgb[3]) {
813  XYZToRGB(xyz[0], xyz[1], xyz[2], rgb+0, rgb+1, rgb+2);
814  }
815  static void XYZToRGB(double x, double y, double z,
816  double *r, double *g, double *b);
817  static double *XYZToRGB(const double xyz[3]);
819 
821 
822  static void RGBToXYZ(const double rgb[3], double xyz[3]) {
823  RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz+0, xyz+1, xyz+2);
824  }
825  static void RGBToXYZ(double r, double g, double b,
826  double *x, double *y, double *z);
827  static double *RGBToXYZ(const double rgb[3]);
829 
831 
834  static void RGBToLab(const double rgb[3], double lab[3]) {
835  RGBToLab(rgb[0], rgb[1], rgb[2], lab+0, lab+1, lab+2);
836  }
837  static void RGBToLab(double red, double green, double blue,
838  double *L, double *a, double *b);
839  static double *RGBToLab(const double rgb[3]);
841 
843 
844  static void LabToRGB(const double lab[3], double rgb[3]) {
845  LabToRGB(lab[0], lab[1], lab[2], rgb+0, rgb+1, rgb+2);
846  }
847  static void LabToRGB(double L, double a, double b,
848  double *red, double *green, double *blue);
849  static double *LabToRGB(const double lab[3]);
851 
853 
854  static void UninitializeBounds(double bounds[6]){
855  bounds[0] = 1.0;
856  bounds[1] = -1.0;
857  bounds[2] = 1.0;
858  bounds[3] = -1.0;
859  bounds[4] = 1.0;
860  bounds[5] = -1.0;
861  }
863 
865 
866  static int AreBoundsInitialized(double bounds[6]){
867  if ( bounds[1]-bounds[0]<0.0 )
868  {
869  return 0;
870  }
871  return 1;
872  }
874 
876 
878  static void ClampValue(double *value, const double range[2]);
879  static void ClampValue(double value, const double range[2], double *clamped_value);
880  static void ClampValues(
881  double *values, int nb_values, const double range[2]);
882  static void ClampValues(
883  const double *values, int nb_values, const double range[2], double *clamped_values);
885 
887 
890  static double ClampAndNormalizeValue(double value,
891  const double range[2]);
893 
895 
901  static int GetScalarTypeFittingRange(
902  double range_min, double range_max,
903  double scale = 1.0, double shift = 0.0);
905 
907 
913  static int GetAdjustedScalarRange(
914  vtkDataArray *array, int comp, double range[2]);
916 
919  static int ExtentIsWithinOtherExtent(int extent1[6], int extent2[6]);
920 
924  static int BoundsIsWithinOtherBounds(double bounds1[6], double bounds2[6], double delta[3]);
925 
929  static int PointIsWithinBounds(double point[3], double bounds[6], double delta[3]);
930 
938  static double Solve3PointCircle(const double p1[3], const double p2[3], const double p3[3], double center[3]);
939 
941  static double Inf();
942 
944  static double NegInf();
945 
947  static double Nan();
948 
951  static int IsInf(double x);
952 
955  static int IsNan(double x);
956 
959  static bool IsFinite(double x);
960 
961 protected:
962  vtkMath() {}
963  ~vtkMath() {}
964 
965  static vtkMathInternal Internal;
966 private:
967  vtkMath(const vtkMath&); // Not implemented.
968  void operator=(const vtkMath&); // Not implemented.
969 };
970 
971 //----------------------------------------------------------------------------
972 inline float vtkMath::RadiansFromDegrees( float x )
973 {
974  return x * 0.017453292f;
975 }
976 
977 //----------------------------------------------------------------------------
978 inline double vtkMath::RadiansFromDegrees( double x )
979 {
980  return x * 0.017453292519943295;
981 }
982 
983 //----------------------------------------------------------------------------
984 inline float vtkMath::DegreesFromRadians( float x )
985 {
986  return x * 57.2957795131f;
987 }
988 
989 //----------------------------------------------------------------------------
990 inline double vtkMath::DegreesFromRadians( double x )
991 {
992  return x * 57.29577951308232;
993 }
994 
995 //----------------------------------------------------------------------------
996 inline vtkTypeInt64 vtkMath::Factorial( int N )
997 {
998  vtkTypeInt64 r = 1;
999  while ( N > 1 )
1000  {
1001  r *= N--;
1002  }
1003  return r;
1004 }
1005 
1006 //----------------------------------------------------------------------------
1007 inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
1008 {
1009  return ((x != 0) & ((x & (x - 1)) == 0));
1010 }
1011 
1012 //----------------------------------------------------------------------------
1013 // Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1015 {
1016  unsigned int z = ((x > 0) ? x - 1 : 0);
1017  z |= z >> 1;
1018  z |= z >> 2;
1019  z |= z >> 4;
1020  z |= z >> 8;
1021  z |= z >> 16;
1022  return static_cast<int>(z + 1);
1023 }
1024 
1025 //----------------------------------------------------------------------------
1026 // Modify the trunc() operation provided by static_cast<int>() to get floor(),
1027 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1028 inline int vtkMath::Floor(double x)
1029 {
1030  int i = static_cast<int>(x);
1031  return i - ( i > x );
1032 }
1033 
1034 //----------------------------------------------------------------------------
1035 // Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1036 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1037 inline int vtkMath::Ceil(double x)
1038 {
1039  int i = static_cast<int>(x);
1040  return i + ( i < x );
1041 }
1042 
1043 //----------------------------------------------------------------------------
1044 inline float vtkMath::Normalize(float x[3])
1045 {
1046  float den;
1047  if ( ( den = vtkMath::Norm( x ) ) != 0.0 )
1048  {
1049  for (int i=0; i < 3; i++)
1050  {
1051  x[i] /= den;
1052  }
1053  }
1054  return den;
1055 }
1056 
1057 //----------------------------------------------------------------------------
1058 inline double vtkMath::Normalize(double x[3])
1059 {
1060  double den;
1061  if ( ( den = vtkMath::Norm( x ) ) != 0.0 )
1062  {
1063  for (int i=0; i < 3; i++)
1064  {
1065  x[i] /= den;
1066  }
1067  }
1068  return den;
1069 }
1070 
1071 //----------------------------------------------------------------------------
1072 inline float vtkMath::Normalize2D(float x[3])
1073 {
1074  float den;
1075  if ( ( den = vtkMath::Norm2D( x ) ) != 0.0 )
1076  {
1077  for (int i=0; i < 2; i++)
1078  {
1079  x[i] /= den;
1080  }
1081  }
1082  return den;
1083 }
1084 
1085 //----------------------------------------------------------------------------
1086 inline double vtkMath::Normalize2D(double x[3])
1087 {
1088  double den;
1089  if ( ( den = vtkMath::Norm2D( x ) ) != 0.0 )
1090  {
1091  for (int i=0; i < 2; i++)
1092  {
1093  x[i] /= den;
1094  }
1095  }
1096  return den;
1097 }
1098 
1099 //----------------------------------------------------------------------------
1100 inline float vtkMath::Determinant3x3(const float c1[3],
1101  const float c2[3],
1102  const float c3[3])
1103 {
1104  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1105  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1106 }
1107 
1108 //----------------------------------------------------------------------------
1109 inline double vtkMath::Determinant3x3(const double c1[3],
1110  const double c2[3],
1111  const double c3[3])
1112 {
1113  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1114  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1115 }
1116 
1117 //----------------------------------------------------------------------------
1118 inline double vtkMath::Determinant3x3(double a1, double a2, double a3,
1119  double b1, double b2, double b3,
1120  double c1, double c2, double c3)
1121 {
1122  return ( a1 * vtkMath::Determinant2x2( b2, b3, c2, c3 )
1123  - b1 * vtkMath::Determinant2x2( a2, a3, c2, c3 )
1124  + c1 * vtkMath::Determinant2x2( a2, a3, b2, b3 ) );
1125 }
1126 
1127 //----------------------------------------------------------------------------
1128 inline float vtkMath::Distance2BetweenPoints(const float x[3],
1129  const float y[3])
1130 {
1131  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1132  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1133  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1134 }
1135 
1136 //----------------------------------------------------------------------------
1137 inline double vtkMath::Distance2BetweenPoints(const double x[3],
1138  const double y[3])
1139 {
1140  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1141  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1142  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1143 }
1144 
1145 //----------------------------------------------------------------------------
1146 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1147 inline void vtkMath::Cross(const float x[3], const float y[3], float z[3])
1148 {
1149  float Zx = x[1] * y[2] - x[2] * y[1];
1150  float Zy = x[2] * y[0] - x[0] * y[2];
1151  float Zz = x[0] * y[1] - x[1] * y[0];
1152  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1153 }
1154 
1155 //----------------------------------------------------------------------------
1156 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1157 inline void vtkMath::Cross(const double x[3], const double y[3], double z[3])
1158 {
1159  double Zx = x[1] * y[2] - x[2] * y[1];
1160  double Zy = x[2] * y[0] - x[0] * y[2];
1161  double Zz = x[0] * y[1] - x[1] * y[0];
1162  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1163 }
1164 
1165 //BTX
1166 //----------------------------------------------------------------------------
1167 template<class T>
1168 inline double vtkDeterminant3x3(T A[3][3])
1169 {
1170  return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] +
1171  A[2][0] * A[0][1] * A[1][2] - A[0][0] * A[2][1] * A[1][2] -
1172  A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1173 }
1174 //ETX
1175 
1176 //----------------------------------------------------------------------------
1177 inline double vtkMath::Determinant3x3(float A[3][3])
1178 {
1179  return vtkDeterminant3x3( A );
1180 }
1181 
1182 //----------------------------------------------------------------------------
1183 inline double vtkMath::Determinant3x3(double A[3][3])
1184 {
1185  return vtkDeterminant3x3( A );
1186 }
1187 
1188 //----------------------------------------------------------------------------
1189 inline void vtkMath::ClampValue(double *value, const double range[2])
1190 {
1191  if (value && range)
1192  {
1193  if (*value < range[0])
1194  {
1195  *value = range[0];
1196  }
1197  else if (*value > range[1])
1198  {
1199  *value = range[1];
1200  }
1201  }
1202 }
1203 
1204 //----------------------------------------------------------------------------
1206  double value, const double range[2], double *clamped_value)
1207 {
1208  if (range && clamped_value)
1209  {
1210  if (value < range[0])
1211  {
1212  *clamped_value = range[0];
1213  }
1214  else if (value > range[1])
1215  {
1216  *clamped_value = range[1];
1217  }
1218  else
1219  {
1220  *clamped_value = value;
1221  }
1222  }
1223 }
1224 
1225 // ---------------------------------------------------------------------------
1227  const double range[2])
1228 {
1229  assert("pre: valid_range" && range[0]<=range[1]);
1230 
1231  double result;
1232  if(range[0]==range[1])
1233  {
1234  result=0.0;
1235  }
1236  else
1237  {
1238  // clamp
1239  if(value<range[0])
1240  {
1241  result=range[0];
1242  }
1243  else
1244  {
1245  if(value>range[1])
1246  {
1247  result=range[1];
1248  }
1249  else
1250  {
1251  result=value;
1252  }
1253  }
1254 
1255  // normalize
1256  result=( result - range[0] ) / ( range[1] - range[0] );
1257  }
1258 
1259  assert("post: valid_result" && result>=0.0 && result<=1.0);
1260 
1261  return result;
1262 }
1263 
1264 //-----------------------------------------------------------------------------
1265 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1266 #define VTK_MATH_ISINF_IS_INLINE
1267 inline int vtkMath::IsInf(double x)
1268 {
1269 #if defined(VTK_HAS_STD_ISINF)
1270  return std::isinf(x);
1271 #else
1272  return (isinf(x) != 0); // Force conversion to bool
1273 #endif
1274 }
1275 #endif
1276 
1277 //-----------------------------------------------------------------------------
1278 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1279 #define VTK_MATH_ISNAN_IS_INLINE
1280 inline int vtkMath::IsNan(double x)
1281 {
1282 #if defined(VTK_HAS_STD_ISNAN)
1283  return std::isnan(x);
1284 #else
1285  return (isnan(x) != 0); // Force conversion to bool
1286 #endif
1287 }
1288 #endif
1289 
1290 //-----------------------------------------------------------------------------
1291 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1292 #define VTK_MATH_ISFINITE_IS_INLINE
1293 inline bool vtkMath::IsFinite(double x)
1294 {
1295 #if defined(VTK_HAS_STD_ISFINITE)
1296  return std::isfinite(x);
1297 #elif defined(VTK_HAS_ISFINITE)
1298  return (isfinite(x) != 0); // Force conversion to bool
1299 #else
1300  return (finite(x) != 0); // Force conversion to bool
1301 #endif
1302 }
1303 #endif
1304 
1305 #endif
static void MultiplyScalar2D(float a[2], float s)
Definition: vtkMath.h:276
GLsizeiptr size
Definition: vtkgl.h:11843
static bool IsFinite(double x)
static float Dot2D(const float x[2], const float y[2])
Definition: vtkMath.h:421
static void Cross(const float x[3], const float y[3], float z[3])
Definition: vtkMath.h:1147
GLclampf f
Definition: vtkgl.h:14181
GLboolean GLboolean GLboolean b
Definition: vtkgl.h:12312
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:792
GLclampf green
Definition: vtkgl.h:11313
static double Norm(const double x[3])
Definition: vtkMath.h:350
const GLdouble * v
Definition: vtkgl.h:11595
static double Pi()
Definition: vtkMath.h:88
static void ClampValue(double *value, const double range[2])
Definition: vtkMath.h:1189
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Definition: vtkMath.h:1007
GLuint index
Definition: vtkgl.h:11983
static void Outer(const float x[3], const float y[3], float A[3][3])
Definition: vtkMath.h:314
GLenum GLenum GLenum GLenum GLenum scale
Definition: vtkgl.h:15942
GLclampf GLclampf blue
Definition: vtkgl.h:11313
static float Determinant2x2(const float c1[2], const float c2[2])
Definition: vtkMath.h:479
#define VTKCOMMONCORE_EXPORT
static vtkTypeInt64 Factorial(int N)
Definition: vtkMath.h:996
static void RGBToHSV(const double rgb[3], double hsv[3])
Definition: vtkMath.h:770
GLuint in
Definition: vtkgl.h:16905
static int Round(float f)
Definition: vtkMath.h:110
GLsizei const GLfloat * value
Definition: vtkgl.h:12021
vtkMath()
Definition: vtkMath.h:962
static void RGBToHSV(const float rgb[3], float hsv[3])
Definition: vtkMath.h:765
static int AreBoundsInitialized(double bounds[6])
Definition: vtkMath.h:866
static double ClampAndNormalizeValue(double value, const double range[2])
Definition: vtkMath.h:1226
GLdouble GLdouble GLdouble r
Definition: vtkgl.h:11610
GLint GLint GLint GLint GLint GLint y
Definition: vtkgl.h:11318
static void Outer(const double x[3], const double y[3], double A[3][3])
Definition: vtkMath.h:322
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:619
GLdouble GLdouble z
Definition: vtkgl.h:11754
static void Add(const double a[3], const double b[3], double c[3])
Definition: vtkMath.h:240
static void XYZToRGB(const double xyz[3], double rgb[3])
Definition: vtkMath.h:812
static float Norm2D(const float x[2])
Definition: vtkMath.h:460
static float Normalize2D(float x[2])
GLint GLint GLint GLint GLint x
Definition: vtkgl.h:11318
static void UninitializeBounds(double bounds[6])
Definition: vtkMath.h:854
static int NearestPowerOfTwo(int x)
Definition: vtkMath.h:1014
GLubyte GLubyte GLubyte GLubyte w
Definition: vtkgl.h:12054
virtual void PrintSelf(ostream &os, vtkIndent indent)
static void RGBToXYZ(const double rgb[3], double xyz[3])
Definition: vtkMath.h:822
a simple class to control print indentation
Definition: vtkIndent.h:38
const GLubyte * c
Definition: vtkgl.h:15720
const GLfloat * m
Definition: vtkgl.h:18169
GLboolean GLenum GLenum GLvoid * values
Definition: vtkgl.h:11354
static float Dot(const float x[3], const float y[3])
Definition: vtkMath.h:302
static void Subtract(const float a[3], const float b[3], float c[3])
Definition: vtkMath.h:249
static void Subtract(const double a[3], const double b[3], double c[3])
Definition: vtkMath.h:258
static int Floor(double x)
Definition: vtkMath.h:1028
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:53
static double Determinant2x2(double a, double b, double c, double d)
Definition: vtkMath.h:485
static float RadiansFromDegrees(float degrees)
Definition: vtkMath.h:972
static void HSVToRGB(const double hsv[3], double rgb[3])
Definition: vtkMath.h:785
Park and Miller Sequence of pseudo random numbers.
static void MultiplyScalar(double a[3], double s)
Definition: vtkMath.h:285
static double Determinant3x3(float A[3][3])
Definition: vtkMath.h:1177
static float Normalize(float x[3])
Definition: vtkMath.h:1044
static void RGBToLab(const double rgb[3], double lab[3])
Definition: vtkMath.h:834
static float DegreesFromRadians(float radians)
Definition: vtkMath.h:984
static void Outer2D(const double x[2], const double y[2], double A[2][2])
Definition: vtkMath.h:446
#define VTK_LEGACY(method)
Definition: vtkSetGet.h:787
static void Outer2D(const float x[2], const float y[2], float A[2][2])
Definition: vtkMath.h:433
static int Ceil(double x)
Definition: vtkMath.h:1037
GLboolean GLboolean GLboolean GLboolean a
Definition: vtkgl.h:12312
performs common math operations
Definition: vtkMath.h:80
static double Dot2D(const double x[2], const double y[2])
Definition: vtkMath.h:427
GLuint64EXT * result
Definition: vtkgl.h:18868
static double Dot(const double x[3], const double y[3])
Definition: vtkMath.h:308
static void MultiplyScalar(float a[3], float s)
Definition: vtkMath.h:267
static void HSVToRGB(const float hsv[3], float rgb[3])
Definition: vtkMath.h:780
GLboolean GLboolean g
Definition: vtkgl.h:12312
GLdouble s
Definition: vtkgl.h:11594
~vtkMath()
Definition: vtkMath.h:963
static double Norm2D(const double x[2])
Definition: vtkMath.h:466
GLclampd n
Definition: vtkgl.h:14370
static int Round(double f)
Definition: vtkMath.h:112
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
static void MultiplyScalar2D(double a[2], double s)
Definition: vtkMath.h:294
static void LabToRGB(const double lab[3], double rgb[3])
Definition: vtkMath.h:844
static vtkMathInternal Internal
Definition: vtkMath.h:965
static vtkObject * New()
double vtkDeterminant3x3(T A[3][3])
Definition: vtkMath.h:1168
static float Norm(const float *x, int n)
static float Distance2BetweenPoints(const float x[3], const float y[3])
Definition: vtkMath.h:1128
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:487
GLenum GLint * range
Definition: vtkgl.h:14180
static float Norm(const float x[3])
Definition: vtkMath.h:344
static void Add(const float a[3], const float b[3], float c[3])
Definition: vtkMath.h:232
GLfloat GLfloat GLfloat GLfloat h
Definition: vtkgl.h:14364
#define max(a, b)
represent and manipulate 3D points
Definition: vtkPoints.h:39
static void XYZToLab(const double xyz[3], double lab[3])
Definition: vtkMath.h:802