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();
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 
398  static double AngleBetweenVectors(const double v1[3], const double v2[3]);
399 
403  static double GaussianAmplitude(const double variance, const double distanceFromMean);
404 
408  static double GaussianAmplitude(const double mean, const double variance, const double position);
409 
414  static double GaussianWeight(const double variance, const double distanceFromMean);
415 
420  static double GaussianWeight(const double mean, const double variance, const double position);
421 
423 
424  static float Dot2D(const float x[2], const float y[2]) {
425  return ( x[0] * y[0] + x[1] * y[1] );};
427 
429 
430  static double Dot2D(const double x[2], const double y[2]) {
431  return ( x[0] * y[0] + x[1] * y[1] );};
433 
435 
436  static void Outer2D(const float x[2], const float y[2], float A[2][2])
437  {
438  for (int i=0; i < 2; i++)
439  {
440  for (int j=0; j < 2; j++)
441  {
442  A[i][j] = x[i] * y[j];
443  }
444  }
445  }
447 
448 
449  static void Outer2D(const double x[2], const double y[2], double A[2][2])
450  {
451  for (int i=0; i < 2; i++)
452  {
453  for (int j=0; j < 2; j++)
454  {
455  A[i][j] = x[i] * y[j];
456  }
457  }
458  }
460 
462 
463  static float Norm2D(const float x[2]) {
464  return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] ) );};
466 
468 
469  static double Norm2D(const double x[2]) {
470  return sqrt( x[0] * x[0] + x[1] * x[1] );};
472 
474  static float Normalize2D(float x[2]);
475 
478  static double Normalize2D(double x[2]);
479 
481 
482  static float Determinant2x2(const float c1[2], const float c2[2]) {
483  return (c1[0] * c2[1] - c2[0] * c1[1] );};
485 
487 
488  static double Determinant2x2(double a, double b, double c, double d) {
489  return (a * d - b * c);};
490  static double Determinant2x2(const double c1[2], const double c2[2]) {
491  return (c1[0] * c2[1] - c2[0] * c1[1] );};
493 
495 
496  static void LUFactor3x3(float A[3][3], int index[3]);
497  static void LUFactor3x3(double A[3][3], int index[3]);
499 
501 
502  static void LUSolve3x3(const float A[3][3], const int index[3],
503  float x[3]);
504  static void LUSolve3x3(const double A[3][3], const int index[3],
505  double x[3]);
507 
509 
511  static void LinearSolve3x3(const float A[3][3], const float x[3],
512  float y[3]);
513  static void LinearSolve3x3(const double A[3][3], const double x[3],
514  double y[3]);
516 
518 
519  static void Multiply3x3(const float A[3][3], const float in[3],
520  float out[3]);
521  static void Multiply3x3(const double A[3][3], const double in[3],
522  double out[3]);
524 
526 
527  static void Multiply3x3(const float A[3][3], const float B[3][3],
528  float C[3][3]);
529  static void Multiply3x3(const double A[3][3], const double B[3][3],
530  double C[3][3]);
532 
534 
536  static void MultiplyMatrix(double **A, double **B,
537  unsigned int rowA, unsigned int colA,
538  unsigned int rowB, unsigned int colB,
539  double **C);
541 
543 
545  static void Transpose3x3(const float A[3][3], float AT[3][3]);
546  static void Transpose3x3(const double A[3][3], double AT[3][3]);
548 
550 
552  static void Invert3x3(const float A[3][3], float AI[3][3]);
553  static void Invert3x3(const double A[3][3], double AI[3][3]);
555 
557 
558  static void Identity3x3(float A[3][3]);
559  static void Identity3x3(double A[3][3]);
561 
563 
564  static double Determinant3x3(float A[3][3]);
565  static double Determinant3x3(double A[3][3]);
567 
569 
570  static float Determinant3x3(const float c1[3],
571  const float c2[3],
572  const float c3[3]);
574 
576 
577  static double Determinant3x3(const double c1[3],
578  const double c2[3],
579  const double c3[3]);
581 
583 
585  static double Determinant3x3(double a1, double a2, double a3,
586  double b1, double b2, double b3,
587  double c1, double c2, double c3);
589 
591 
595  static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
596  static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
598 
600 
605  static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
606  static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
608 
610 
613  static void MultiplyQuaternion( const float q1[4], const float q2[4], float q[4] );
614  static void MultiplyQuaternion( const double q1[4], const double q2[4], double q[4] );
616 
618 
621  static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
622  static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
624 
626 
630  static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
631  static void Diagonalize3x3(const double A[3][3],double w[3],double V[3][3]);
633 
635 
642  static void SingularValueDecomposition3x3(const float A[3][3],
643  float U[3][3], float w[3],
644  float VT[3][3]);
645  static void SingularValueDecomposition3x3(const double A[3][3],
646  double U[3][3], double w[3],
647  double VT[3][3]);
649 
654  static int SolveLinearSystem(double **A, double *x, int size);
655 
659  static int InvertMatrix(double **A, double **AI, int size);
660 
662 
664  static int InvertMatrix(double **A, double **AI, int size,
665  int *tmp1Size, double *tmp2Size);
667 
683  static int LUFactorLinearSystem(double **A, int *index, int size);
684 
686 
688  static int LUFactorLinearSystem(double **A, int *index, int size,
689  double *tmpSize);
691 
693 
699  static void LUSolveLinearSystem(double **A, int *index,
700  double *x, int size);
702 
710  static double EstimateMatrixCondition(double **A, int size);
711 
713 
718  static int Jacobi(float **a, float *w, float **v);
719  static int Jacobi(double **a, double *w, double **v);
721 
723 
729  static int JacobiN(float **a, int n, float *w, float **v);
730  static int JacobiN(double **a, int n, double *w, double **v);
732 
734 
744  static int SolveHomogeneousLeastSquares(int numberOfSamples, double **xt, int xOrder,
745  double **mt);
747 
748 
750 
761  static int SolveLeastSquares(int numberOfSamples, double **xt, int xOrder,
762  double **yt, int yOrder, double **mt, int checkHomogeneous=1);
764 
766 
770  static void RGBToHSV(const float rgb[3], float hsv[3])
771  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
772  static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v);
773  static double* RGBToHSV(const double rgb[3]);
774  static double* RGBToHSV(double r, double g, double b);
775  static void RGBToHSV(const double rgb[3], double hsv[3])
776  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
777  static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v);
779 
781 
785  static void HSVToRGB(const float hsv[3], float rgb[3])
786  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
787  static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b);
788  static double* HSVToRGB(const double hsv[3]);
789  static double* HSVToRGB(double h, double s, double v);
790  static void HSVToRGB(const double hsv[3], double rgb[3])
791  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
792  static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b);
794 
796 
797  static void LabToXYZ(const double lab[3], double xyz[3]) {
798  LabToXYZ(lab[0], lab[1], lab[2], xyz+0, xyz+1, xyz+2);
799  }
800  static void LabToXYZ(double L, double a, double b,
801  double *x, double *y, double *z);
802  static double *LabToXYZ(const double lab[3]);
804 
806 
807  static void XYZToLab(const double xyz[3], double lab[3]) {
808  XYZToLab(xyz[0], xyz[1], xyz[2], lab+0, lab+1, lab+2);
809  }
810  static void XYZToLab(double x, double y, double z,
811  double *L, double *a, double *b);
812  static double *XYZToLab(const double xyz[3]);
814 
816 
817  static void XYZToRGB(const double xyz[3], double rgb[3]) {
818  XYZToRGB(xyz[0], xyz[1], xyz[2], rgb+0, rgb+1, rgb+2);
819  }
820  static void XYZToRGB(double x, double y, double z,
821  double *r, double *g, double *b);
822  static double *XYZToRGB(const double xyz[3]);
824 
826 
827  static void RGBToXYZ(const double rgb[3], double xyz[3]) {
828  RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz+0, xyz+1, xyz+2);
829  }
830  static void RGBToXYZ(double r, double g, double b,
831  double *x, double *y, double *z);
832  static double *RGBToXYZ(const double rgb[3]);
834 
836 
839  static void RGBToLab(const double rgb[3], double lab[3]) {
840  RGBToLab(rgb[0], rgb[1], rgb[2], lab+0, lab+1, lab+2);
841  }
842  static void RGBToLab(double red, double green, double blue,
843  double *L, double *a, double *b);
844  static double *RGBToLab(const double rgb[3]);
846 
848 
849  static void LabToRGB(const double lab[3], double rgb[3]) {
850  LabToRGB(lab[0], lab[1], lab[2], rgb+0, rgb+1, rgb+2);
851  }
852  static void LabToRGB(double L, double a, double b,
853  double *red, double *green, double *blue);
854  static double *LabToRGB(const double lab[3]);
856 
858 
859  static void UninitializeBounds(double bounds[6]){
860  bounds[0] = 1.0;
861  bounds[1] = -1.0;
862  bounds[2] = 1.0;
863  bounds[3] = -1.0;
864  bounds[4] = 1.0;
865  bounds[5] = -1.0;
866  }
868 
870 
871  static int AreBoundsInitialized(double bounds[6]){
872  if ( bounds[1]-bounds[0]<0.0 )
873  {
874  return 0;
875  }
876  return 1;
877  }
879 
881 
883  static void ClampValue(double *value, const double range[2]);
884  static void ClampValue(double value, const double range[2], double *clamped_value);
885  static void ClampValues(
886  double *values, int nb_values, const double range[2]);
887  static void ClampValues(
888  const double *values, int nb_values, const double range[2], double *clamped_values);
890 
892 
895  static double ClampAndNormalizeValue(double value,
896  const double range[2]);
898 
900 
906  static int GetScalarTypeFittingRange(
907  double range_min, double range_max,
908  double scale = 1.0, double shift = 0.0);
910 
912 
918  static int GetAdjustedScalarRange(
919  vtkDataArray *array, int comp, double range[2]);
921 
924  static int ExtentIsWithinOtherExtent(int extent1[6], int extent2[6]);
925 
929  static int BoundsIsWithinOtherBounds(double bounds1[6], double bounds2[6], double delta[3]);
930 
934  static int PointIsWithinBounds(double point[3], double bounds[6], double delta[3]);
935 
944  static double Solve3PointCircle(const double p1[3], const double p2[3], const double p3[3], double center[3]);
945 
947  static double Inf();
948 
950  static double NegInf();
951 
953  static double Nan();
954 
957  static int IsInf(double x);
958 
961  static int IsNan(double x);
962 
965  static bool IsFinite(double x);
966 
967 protected:
968  vtkMath() {}
969  ~vtkMath() {}
970 
971  static vtkMathInternal Internal;
972 private:
973  vtkMath(const vtkMath&); // Not implemented.
974  void operator=(const vtkMath&); // Not implemented.
975 };
976 
977 //----------------------------------------------------------------------------
978 inline float vtkMath::RadiansFromDegrees( float x )
979 {
980  return x * 0.017453292f;
981 }
982 
983 //----------------------------------------------------------------------------
984 inline double vtkMath::RadiansFromDegrees( double x )
985 {
986  return x * 0.017453292519943295;
987 }
988 
989 //----------------------------------------------------------------------------
990 inline float vtkMath::DegreesFromRadians( float x )
991 {
992  return x * 57.2957795131f;
993 }
994 
995 //----------------------------------------------------------------------------
996 inline double vtkMath::DegreesFromRadians( double x )
997 {
998  return x * 57.29577951308232;
999 }
1000 
1001 //----------------------------------------------------------------------------
1002 inline vtkTypeInt64 vtkMath::Factorial( int N )
1003 {
1004  vtkTypeInt64 r = 1;
1005  while ( N > 1 )
1006  {
1007  r *= N--;
1008  }
1009  return r;
1010 }
1011 
1012 //----------------------------------------------------------------------------
1013 inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
1014 {
1015  return ((x != 0) & ((x & (x - 1)) == 0));
1016 }
1017 
1018 //----------------------------------------------------------------------------
1019 // Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1021 {
1022  unsigned int z = ((x > 0) ? x - 1 : 0);
1023  z |= z >> 1;
1024  z |= z >> 2;
1025  z |= z >> 4;
1026  z |= z >> 8;
1027  z |= z >> 16;
1028  return static_cast<int>(z + 1);
1029 }
1030 
1031 //----------------------------------------------------------------------------
1032 // Modify the trunc() operation provided by static_cast<int>() to get floor(),
1033 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1034 inline int vtkMath::Floor(double x)
1035 {
1036  int i = static_cast<int>(x);
1037  return i - ( i > x );
1038 }
1039 
1040 //----------------------------------------------------------------------------
1041 // Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1042 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1043 inline int vtkMath::Ceil(double x)
1044 {
1045  int i = static_cast<int>(x);
1046  return i + ( i < x );
1047 }
1048 
1049 //----------------------------------------------------------------------------
1050 inline float vtkMath::Normalize(float x[3])
1051 {
1052  float den = vtkMath::Norm( x );
1053  if ( den != 0.0 )
1054  {
1055  for (int i=0; i < 3; i++)
1056  {
1057  x[i] /= den;
1058  }
1059  }
1060  return den;
1061 }
1062 
1063 //----------------------------------------------------------------------------
1064 inline double vtkMath::Normalize(double x[3])
1065 {
1066  double den = vtkMath::Norm( x );
1067  if ( den != 0.0 )
1068  {
1069  for (int i=0; i < 3; i++)
1070  {
1071  x[i] /= den;
1072  }
1073  }
1074  return den;
1075 }
1076 
1077 //----------------------------------------------------------------------------
1078 inline float vtkMath::Normalize2D(float x[3])
1079 {
1080  float den = vtkMath::Norm2D( x );
1081  if ( den != 0.0 )
1082  {
1083  for (int i=0; i < 2; i++)
1084  {
1085  x[i] /= den;
1086  }
1087  }
1088  return den;
1089 }
1090 
1091 //----------------------------------------------------------------------------
1092 inline double vtkMath::Normalize2D(double x[3])
1093 {
1094  double den = vtkMath::Norm2D( x );
1095  if ( den != 0.0 )
1096  {
1097  for (int i=0; i < 2; i++)
1098  {
1099  x[i] /= den;
1100  }
1101  }
1102  return den;
1103 }
1104 
1105 //----------------------------------------------------------------------------
1106 inline float vtkMath::Determinant3x3(const float c1[3],
1107  const float c2[3],
1108  const float c3[3])
1109 {
1110  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1111  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1112 }
1113 
1114 //----------------------------------------------------------------------------
1115 inline double vtkMath::Determinant3x3(const double c1[3],
1116  const double c2[3],
1117  const double 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(double a1, double a2, double a3,
1125  double b1, double b2, double b3,
1126  double c1, double c2, double c3)
1127 {
1128  return ( a1 * vtkMath::Determinant2x2( b2, b3, c2, c3 )
1129  - b1 * vtkMath::Determinant2x2( a2, a3, c2, c3 )
1130  + c1 * vtkMath::Determinant2x2( a2, a3, b2, b3 ) );
1131 }
1132 
1133 //----------------------------------------------------------------------------
1134 inline float vtkMath::Distance2BetweenPoints(const float x[3],
1135  const float y[3])
1136 {
1137  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1138  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1139  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1140 }
1141 
1142 //----------------------------------------------------------------------------
1143 inline double vtkMath::Distance2BetweenPoints(const double x[3],
1144  const double 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 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1153 inline void vtkMath::Cross(const float x[3], const float y[3], float z[3])
1154 {
1155  float Zx = x[1] * y[2] - x[2] * y[1];
1156  float Zy = x[2] * y[0] - x[0] * y[2];
1157  float Zz = x[0] * y[1] - x[1] * y[0];
1158  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1159 }
1160 
1161 //----------------------------------------------------------------------------
1162 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1163 inline void vtkMath::Cross(const double x[3], const double y[3], double z[3])
1164 {
1165  double Zx = x[1] * y[2] - x[2] * y[1];
1166  double Zy = x[2] * y[0] - x[0] * y[2];
1167  double Zz = x[0] * y[1] - x[1] * y[0];
1168  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1169 }
1170 
1171 //BTX
1172 //----------------------------------------------------------------------------
1173 template<class T>
1174 inline double vtkDeterminant3x3(T A[3][3])
1175 {
1176  return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] +
1177  A[2][0] * A[0][1] * A[1][2] - A[0][0] * A[2][1] * A[1][2] -
1178  A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1179 }
1180 //ETX
1181 
1182 //----------------------------------------------------------------------------
1183 inline double vtkMath::Determinant3x3(float A[3][3])
1184 {
1185  return vtkDeterminant3x3( A );
1186 }
1187 
1188 //----------------------------------------------------------------------------
1189 inline double vtkMath::Determinant3x3(double A[3][3])
1190 {
1191  return vtkDeterminant3x3( A );
1192 }
1193 
1194 //----------------------------------------------------------------------------
1195 inline void vtkMath::ClampValue(double *value, const double range[2])
1196 {
1197  if (value && range)
1198  {
1199  if (*value < range[0])
1200  {
1201  *value = range[0];
1202  }
1203  else if (*value > range[1])
1204  {
1205  *value = range[1];
1206  }
1207  }
1208 }
1209 
1210 //----------------------------------------------------------------------------
1212  double value, const double range[2], double *clamped_value)
1213 {
1214  if (range && clamped_value)
1215  {
1216  if (value < range[0])
1217  {
1218  *clamped_value = range[0];
1219  }
1220  else if (value > range[1])
1221  {
1222  *clamped_value = range[1];
1223  }
1224  else
1225  {
1226  *clamped_value = value;
1227  }
1228  }
1229 }
1230 
1231 // ---------------------------------------------------------------------------
1233  const double range[2])
1234 {
1235  assert("pre: valid_range" && range[0]<=range[1]);
1236 
1237  double result;
1238  if(range[0]==range[1])
1239  {
1240  result=0.0;
1241  }
1242  else
1243  {
1244  // clamp
1245  if(value<range[0])
1246  {
1247  result=range[0];
1248  }
1249  else
1250  {
1251  if(value>range[1])
1252  {
1253  result=range[1];
1254  }
1255  else
1256  {
1257  result=value;
1258  }
1259  }
1260 
1261  // normalize
1262  result=( result - range[0] ) / ( range[1] - range[0] );
1263  }
1264 
1265  assert("post: valid_result" && result>=0.0 && result<=1.0);
1266 
1267  return result;
1268 }
1269 
1270 //-----------------------------------------------------------------------------
1271 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1272 #define VTK_MATH_ISINF_IS_INLINE
1273 inline int vtkMath::IsInf(double x)
1274 {
1275 #if defined(VTK_HAS_STD_ISINF)
1276  return std::isinf(x);
1277 #else
1278  return (isinf(x) != 0); // Force conversion to bool
1279 #endif
1280 }
1281 #endif
1282 
1283 //-----------------------------------------------------------------------------
1284 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1285 #define VTK_MATH_ISNAN_IS_INLINE
1286 inline int vtkMath::IsNan(double x)
1287 {
1288 #if defined(VTK_HAS_STD_ISNAN)
1289  return std::isnan(x);
1290 #else
1291  return (isnan(x) != 0); // Force conversion to bool
1292 #endif
1293 }
1294 #endif
1295 
1296 //-----------------------------------------------------------------------------
1297 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1298 #define VTK_MATH_ISFINITE_IS_INLINE
1299 inline bool vtkMath::IsFinite(double x)
1300 {
1301 #if defined(VTK_HAS_STD_ISFINITE)
1302  return std::isfinite(x);
1303 #elif defined(VTK_HAS_ISFINITE)
1304  return (isfinite(x) != 0); // Force conversion to bool
1305 #else
1306  return (finite(x) != 0); // Force conversion to bool
1307 #endif
1308 }
1309 #endif
1310 
1311 #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:424
static void Cross(const float x[3], const float y[3], float z[3])
Definition: vtkMath.h:1153
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:797
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:1195
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Definition: vtkMath.h:1013
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:482
#define VTKCOMMONCORE_EXPORT
static vtkTypeInt64 Factorial(int N)
Definition: vtkMath.h:1002
static void RGBToHSV(const double rgb[3], double hsv[3])
Definition: vtkMath.h:775
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:968
static void RGBToHSV(const float rgb[3], float hsv[3])
Definition: vtkMath.h:770
static int AreBoundsInitialized(double bounds[6])
Definition: vtkMath.h:871
static double ClampAndNormalizeValue(double value, const double range[2])
Definition: vtkMath.h:1232
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:632
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:817
static float Norm2D(const float x[2])
Definition: vtkMath.h:463
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:859
GLfloat GLfloat GLfloat v2
Definition: vtkgl.h:12015
static int NearestPowerOfTwo(int x)
Definition: vtkMath.h:1020
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:827
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:1034
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:488
static float RadiansFromDegrees(float degrees)
Definition: vtkMath.h:978
static void HSVToRGB(const double hsv[3], double rgb[3])
Definition: vtkMath.h:790
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:1183
static float Normalize(float x[3])
Definition: vtkMath.h:1050
static void RGBToLab(const double rgb[3], double lab[3])
Definition: vtkMath.h:839
static float DegreesFromRadians(float radians)
Definition: vtkMath.h:990
static void Outer2D(const double x[2], const double y[2], double A[2][2])
Definition: vtkMath.h:449
#define VTK_LEGACY(method)
Definition: vtkSetGet.h:800
static void Outer2D(const float x[2], const float y[2], float A[2][2])
Definition: vtkMath.h:436
static int Ceil(double x)
Definition: vtkMath.h:1043
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:430
GLuint64EXT * result
Definition: vtkgl.h:18868
static double Dot(const double x[3], const double y[3])
Definition: vtkMath.h:308
GLfloat GLfloat v1
Definition: vtkgl.h:12014
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:785
GLboolean GLboolean g
Definition: vtkgl.h:12312
GLdouble s
Definition: vtkgl.h:11594
~vtkMath()
Definition: vtkMath.h:969
static double Norm2D(const double x[2])
Definition: vtkMath.h:469
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:849
static vtkMathInternal Internal
Definition: vtkMath.h:971
static vtkObject * New()
double vtkDeterminant3x3(T A[3][3])
Definition: vtkMath.h:1174
static float Norm(const float *x, int n)
static float Distance2BetweenPoints(const float x[3], const float y[3])
Definition: vtkMath.h:1134
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:490
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:38
static void XYZToLab(const double xyz[3], double lab[3])
Definition: vtkMath.h:807