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  static bool IsPowerOfTwo(vtkTypeUInt64 x);
125 
129  static int NearestPowerOfTwo(int x);
130 
133  static vtkTypeInt64 Factorial( int N );
134 
138  static vtkTypeInt64 Binomial( int m, int n );
139 
146  static int* BeginCombination( int m, int n );
147 
154  static int NextCombination( int m, int n, int* combination );
155 
157  static void FreeCombination( int* combination);
158 
170  static void RandomSeed(int s);
171 
180  static int GetSeed();
181 
191  static double Random();
192 
201  static double Random( double min, double max );
202 
211  static double Gaussian();
212 
222  static double Gaussian( double mean, double std );
223 
225 
226  static void Add(const float a[3], const float b[3], float c[3]) {
227  for (int i = 0; i < 3; ++i)
228  c[i] = a[i] + b[i];
229  }
231 
233 
234  static void Add(const double a[3], const double b[3], double c[3]) {
235  for (int i = 0; i < 3; ++i)
236  c[i] = a[i] + b[i];
237  }
239 
241 
243  static void Subtract(const float a[3], const float b[3], float c[3]) {
244  for (int i = 0; i < 3; ++i)
245  c[i] = a[i] - b[i];
246  }
248 
250 
252  static void Subtract(const double a[3], const double b[3], double c[3]) {
253  for (int i = 0; i < 3; ++i)
254  c[i] = a[i] - b[i];
255  }
257 
259 
261  static void MultiplyScalar(float a[3], float s) {
262  for (int i = 0; i < 3; ++i)
263  a[i] *= s;
264  }
266 
268 
270  static void MultiplyScalar2D(float a[2], float s) {
271  for (int i = 0; i < 2; ++i)
272  a[i] *= s;
273  }
275 
277 
279  static void MultiplyScalar(double a[3], double s) {
280  for (int i = 0; i < 3; ++i)
281  a[i] *= s;
282  }
284 
286 
288  static void MultiplyScalar2D(double a[2], double s) {
289  for (int i = 0; i < 2; ++i)
290  a[i] *= s;
291  }
293 
295 
296  static float Dot(const float x[3], const float y[3]) {
297  return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
299 
301 
302  static double Dot(const double x[3], const double y[3]) {
303  return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
305 
307 
308  static void Outer(const float x[3], const float y[3], float A[3][3]) {
309  for (int i=0; i < 3; i++)
310  for (int j=0; j < 3; j++)
311  A[i][j] = x[i] * y[j];
312  }
314 
315 
316  static void Outer(const double x[3], const double y[3], double A[3][3]) {
317  for (int i=0; i < 3; i++)
318  for (int j=0; j < 3; j++)
319  A[i][j] = x[i] * y[j];
320  }
322 
324  static void Cross(const float x[3], const float y[3], float z[3]);
325 
328  static void Cross(const double x[3], const double y[3], double z[3]);
329 
331 
332  static float Norm(const float* x, int n);
333  static double Norm(const double* x, int n);
335 
337 
338  static float Norm(const float x[3]) {
339  return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] ) );};
341 
343 
344  static double Norm(const double x[3]) {
345  return sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] );};
347 
349  static float Normalize(float x[3]);
350 
353  static double Normalize(double x[3]);
354 
356 
361  static void Perpendiculars(const double x[3], double y[3], double z[3],
362  double theta);
363  static void Perpendiculars(const float x[3], float y[3], float z[3],
364  double theta);
366 
368 
371  static bool ProjectVector(const float a[3], const float b[3], float projection[3]);
372  static bool ProjectVector(const double a[3], const double b[3], double projection[3]);
374 
376 
380  static bool ProjectVector2D(const float a[2], const float b[2], float projection[2]);
381  static bool ProjectVector2D(const double a[2], const double b[2], double projection[2]);
383 
385  static float Distance2BetweenPoints(const float x[3], const float y[3]);
386 
389  static double Distance2BetweenPoints(const double x[3], const double y[3]);
390 
392  static double AngleBetweenVectors(const double v1[3], const double v2[3]);
393 
397  static double GaussianAmplitude(const double variance, const double distanceFromMean);
398 
402  static double GaussianAmplitude(const double mean, const double variance, const double position);
403 
408  static double GaussianWeight(const double variance, const double distanceFromMean);
409 
414  static double GaussianWeight(const double mean, const double variance, const double position);
415 
417 
418  static float Dot2D(const float x[2], const float y[2]) {
419  return ( x[0] * y[0] + x[1] * y[1] );};
421 
423 
424  static double Dot2D(const double x[2], const double y[2]) {
425  return ( x[0] * y[0] + x[1] * y[1] );};
427 
429 
430  static void Outer2D(const float x[2], const float y[2], float A[2][2])
431  {
432  for (int i=0; i < 2; i++)
433  {
434  for (int j=0; j < 2; j++)
435  {
436  A[i][j] = x[i] * y[j];
437  }
438  }
439  }
441 
442 
443  static void Outer2D(const double x[2], const double y[2], double A[2][2])
444  {
445  for (int i=0; i < 2; i++)
446  {
447  for (int j=0; j < 2; j++)
448  {
449  A[i][j] = x[i] * y[j];
450  }
451  }
452  }
454 
456 
457  static float Norm2D(const float x[2]) {
458  return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] ) );};
460 
462 
463  static double Norm2D(const double x[2]) {
464  return sqrt( x[0] * x[0] + x[1] * x[1] );};
466 
468  static float Normalize2D(float x[2]);
469 
472  static double Normalize2D(double x[2]);
473 
475 
476  static float Determinant2x2(const float c1[2], const float c2[2]) {
477  return (c1[0] * c2[1] - c2[0] * c1[1] );};
479 
481 
482  static double Determinant2x2(double a, double b, double c, double d) {
483  return (a * d - b * c);};
484  static double Determinant2x2(const double c1[2], const double c2[2]) {
485  return (c1[0] * c2[1] - c2[0] * c1[1] );};
487 
489 
490  static void LUFactor3x3(float A[3][3], int index[3]);
491  static void LUFactor3x3(double A[3][3], int index[3]);
493 
495 
496  static void LUSolve3x3(const float A[3][3], const int index[3],
497  float x[3]);
498  static void LUSolve3x3(const double A[3][3], const int index[3],
499  double x[3]);
501 
503 
505  static void LinearSolve3x3(const float A[3][3], const float x[3],
506  float y[3]);
507  static void LinearSolve3x3(const double A[3][3], const double x[3],
508  double y[3]);
510 
512 
513  static void Multiply3x3(const float A[3][3], const float in[3],
514  float out[3]);
515  static void Multiply3x3(const double A[3][3], const double in[3],
516  double out[3]);
518 
520 
521  static void Multiply3x3(const float A[3][3], const float B[3][3],
522  float C[3][3]);
523  static void Multiply3x3(const double A[3][3], const double B[3][3],
524  double C[3][3]);
526 
528 
530  static void MultiplyMatrix(double **A, double **B,
531  unsigned int rowA, unsigned int colA,
532  unsigned int rowB, unsigned int colB,
533  double **C);
535 
537 
539  static void Transpose3x3(const float A[3][3], float AT[3][3]);
540  static void Transpose3x3(const double A[3][3], double AT[3][3]);
542 
544 
546  static void Invert3x3(const float A[3][3], float AI[3][3]);
547  static void Invert3x3(const double A[3][3], double AI[3][3]);
549 
551 
552  static void Identity3x3(float A[3][3]);
553  static void Identity3x3(double A[3][3]);
555 
557 
558  static double Determinant3x3(float A[3][3]);
559  static double Determinant3x3(double A[3][3]);
561 
563 
564  static float Determinant3x3(const float c1[3],
565  const float c2[3],
566  const float c3[3]);
568 
570 
571  static double Determinant3x3(const double c1[3],
572  const double c2[3],
573  const double c3[3]);
575 
577 
579  static double Determinant3x3(double a1, double a2, double a3,
580  double b1, double b2, double b3,
581  double c1, double c2, double c3);
583 
585 
589  static void QuaternionToMatrix3x3(const float quat[4], float A[3][3]);
590  static void QuaternionToMatrix3x3(const double quat[4], double A[3][3]);
592 
594 
599  static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4]);
600  static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4]);
602 
604 
607  static void MultiplyQuaternion( const float q1[4], const float q2[4], float q[4] );
608  static void MultiplyQuaternion( const double q1[4], const double q2[4], double q[4] );
610 
612 
615  static void Orthogonalize3x3(const float A[3][3], float B[3][3]);
616  static void Orthogonalize3x3(const double A[3][3], double B[3][3]);
618 
620 
624  static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3]);
625  static void Diagonalize3x3(const double A[3][3],double w[3],double V[3][3]);
627 
629 
636  static void SingularValueDecomposition3x3(const float A[3][3],
637  float U[3][3], float w[3],
638  float VT[3][3]);
639  static void SingularValueDecomposition3x3(const double A[3][3],
640  double U[3][3], double w[3],
641  double VT[3][3]);
643 
648  static int SolveLinearSystem(double **A, double *x, int size);
649 
653  static int InvertMatrix(double **A, double **AI, int size);
654 
656 
658  static int InvertMatrix(double **A, double **AI, int size,
659  int *tmp1Size, double *tmp2Size);
661 
677  static int LUFactorLinearSystem(double **A, int *index, int size);
678 
680 
682  static int LUFactorLinearSystem(double **A, int *index, int size,
683  double *tmpSize);
685 
687 
693  static void LUSolveLinearSystem(double **A, int *index,
694  double *x, int size);
696 
704  static double EstimateMatrixCondition(double **A, int size);
705 
707 
712  static int Jacobi(float **a, float *w, float **v);
713  static int Jacobi(double **a, double *w, double **v);
715 
717 
723  static int JacobiN(float **a, int n, float *w, float **v);
724  static int JacobiN(double **a, int n, double *w, double **v);
726 
728 
738  static int SolveHomogeneousLeastSquares(int numberOfSamples, double **xt, int xOrder,
739  double **mt);
741 
742 
744 
755  static int SolveLeastSquares(int numberOfSamples, double **xt, int xOrder,
756  double **yt, int yOrder, double **mt, int checkHomogeneous=1);
758 
760 
764  static void RGBToHSV(const float rgb[3], float hsv[3])
765  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
766  static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v);
767  static double* RGBToHSV(const double rgb[3]);
768  static double* RGBToHSV(double r, double g, double b);
769  static void RGBToHSV(const double rgb[3], double hsv[3])
770  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
771  static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v);
773 
775 
779  static void HSVToRGB(const float hsv[3], float rgb[3])
780  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
781  static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b);
782  static double* HSVToRGB(const double hsv[3]);
783  static double* HSVToRGB(double h, double s, double v);
784  static void HSVToRGB(const double hsv[3], double rgb[3])
785  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
786  static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b);
788 
790 
791  static void LabToXYZ(const double lab[3], double xyz[3]) {
792  LabToXYZ(lab[0], lab[1], lab[2], xyz+0, xyz+1, xyz+2);
793  }
794  static void LabToXYZ(double L, double a, double b,
795  double *x, double *y, double *z);
796  static double *LabToXYZ(const double lab[3]);
798 
800 
801  static void XYZToLab(const double xyz[3], double lab[3]) {
802  XYZToLab(xyz[0], xyz[1], xyz[2], lab+0, lab+1, lab+2);
803  }
804  static void XYZToLab(double x, double y, double z,
805  double *L, double *a, double *b);
806  static double *XYZToLab(const double xyz[3]);
808 
810 
811  static void XYZToRGB(const double xyz[3], double rgb[3]) {
812  XYZToRGB(xyz[0], xyz[1], xyz[2], rgb+0, rgb+1, rgb+2);
813  }
814  static void XYZToRGB(double x, double y, double z,
815  double *r, double *g, double *b);
816  static double *XYZToRGB(const double xyz[3]);
818 
820 
821  static void RGBToXYZ(const double rgb[3], double xyz[3]) {
822  RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz+0, xyz+1, xyz+2);
823  }
824  static void RGBToXYZ(double r, double g, double b,
825  double *x, double *y, double *z);
826  static double *RGBToXYZ(const double rgb[3]);
828 
830 
833  static void RGBToLab(const double rgb[3], double lab[3]) {
834  RGBToLab(rgb[0], rgb[1], rgb[2], lab+0, lab+1, lab+2);
835  }
836  static void RGBToLab(double red, double green, double blue,
837  double *L, double *a, double *b);
838  static double *RGBToLab(const double rgb[3]);
840 
842 
843  static void LabToRGB(const double lab[3], double rgb[3]) {
844  LabToRGB(lab[0], lab[1], lab[2], rgb+0, rgb+1, rgb+2);
845  }
846  static void LabToRGB(double L, double a, double b,
847  double *red, double *green, double *blue);
848  static double *LabToRGB(const double lab[3]);
850 
852 
853  static void UninitializeBounds(double bounds[6]){
854  bounds[0] = 1.0;
855  bounds[1] = -1.0;
856  bounds[2] = 1.0;
857  bounds[3] = -1.0;
858  bounds[4] = 1.0;
859  bounds[5] = -1.0;
860  }
862 
864 
865  static int AreBoundsInitialized(double bounds[6]){
866  if ( bounds[1]-bounds[0]<0.0 )
867  {
868  return 0;
869  }
870  return 1;
871  }
873 
875 
877  static void ClampValue(double *value, const double range[2]);
878  static void ClampValue(double value, const double range[2], double *clamped_value);
879  static void ClampValues(
880  double *values, int nb_values, const double range[2]);
881  static void ClampValues(
882  const double *values, int nb_values, const double range[2], double *clamped_values);
884 
886 
889  static double ClampAndNormalizeValue(double value,
890  const double range[2]);
892 
894 
900  static int GetScalarTypeFittingRange(
901  double range_min, double range_max,
902  double scale = 1.0, double shift = 0.0);
904 
906 
912  static int GetAdjustedScalarRange(
913  vtkDataArray *array, int comp, double range[2]);
915 
918  static int ExtentIsWithinOtherExtent(int extent1[6], int extent2[6]);
919 
923  static int BoundsIsWithinOtherBounds(double bounds1[6], double bounds2[6], double delta[3]);
924 
928  static int PointIsWithinBounds(double point[3], double bounds[6], double delta[3]);
929 
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 bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
997 {
998  return ((x != 0) & ((x & (x - 1)) == 0));
999 }
1000 
1001 //----------------------------------------------------------------------------
1002 // Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1004 {
1005  unsigned int z = ((x > 0) ? x - 1 : 0);
1006  z |= z >> 1;
1007  z |= z >> 2;
1008  z |= z >> 4;
1009  z |= z >> 8;
1010  z |= z >> 16;
1011  return static_cast<int>(z + 1);
1012 }
1013 
1014 //----------------------------------------------------------------------------
1015 // Modify the trunc() operation provided by static_cast<int>() to get floor(),
1016 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1017 inline int vtkMath::Floor(double x)
1018 {
1019  int i = static_cast<int>(x);
1020  return i - ( i > x );
1021 }
1022 
1023 //----------------------------------------------------------------------------
1024 // Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1025 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1026 inline int vtkMath::Ceil(double x)
1027 {
1028  int i = static_cast<int>(x);
1029  return i + ( i < x );
1030 }
1031 
1032 //----------------------------------------------------------------------------
1033 inline float vtkMath::Normalize(float x[3])
1034 {
1035  float den = vtkMath::Norm( x );
1036  if ( den != 0.0 )
1037  {
1038  for (int i=0; i < 3; i++)
1039  {
1040  x[i] /= den;
1041  }
1042  }
1043  return den;
1044 }
1045 
1046 //----------------------------------------------------------------------------
1047 inline double vtkMath::Normalize(double x[3])
1048 {
1049  double den = vtkMath::Norm( x );
1050  if ( den != 0.0 )
1051  {
1052  for (int i=0; i < 3; i++)
1053  {
1054  x[i] /= den;
1055  }
1056  }
1057  return den;
1058 }
1059 
1060 //----------------------------------------------------------------------------
1061 inline float vtkMath::Normalize2D(float x[3])
1062 {
1063  float den = vtkMath::Norm2D( x );
1064  if ( den != 0.0 )
1065  {
1066  for (int i=0; i < 2; i++)
1067  {
1068  x[i] /= den;
1069  }
1070  }
1071  return den;
1072 }
1073 
1074 //----------------------------------------------------------------------------
1075 inline double vtkMath::Normalize2D(double x[3])
1076 {
1077  double den = vtkMath::Norm2D( x );
1078  if ( den != 0.0 )
1079  {
1080  for (int i=0; i < 2; i++)
1081  {
1082  x[i] /= den;
1083  }
1084  }
1085  return den;
1086 }
1087 
1088 //----------------------------------------------------------------------------
1089 inline float vtkMath::Determinant3x3(const float c1[3],
1090  const float c2[3],
1091  const float c3[3])
1092 {
1093  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1094  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1095 }
1096 
1097 //----------------------------------------------------------------------------
1098 inline double vtkMath::Determinant3x3(const double c1[3],
1099  const double c2[3],
1100  const double c3[3])
1101 {
1102  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1103  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1104 }
1105 
1106 //----------------------------------------------------------------------------
1107 inline double vtkMath::Determinant3x3(double a1, double a2, double a3,
1108  double b1, double b2, double b3,
1109  double c1, double c2, double c3)
1110 {
1111  return ( a1 * vtkMath::Determinant2x2( b2, b3, c2, c3 )
1112  - b1 * vtkMath::Determinant2x2( a2, a3, c2, c3 )
1113  + c1 * vtkMath::Determinant2x2( a2, a3, b2, b3 ) );
1114 }
1115 
1116 //----------------------------------------------------------------------------
1117 inline float vtkMath::Distance2BetweenPoints(const float x[3],
1118  const float y[3])
1119 {
1120  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1121  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1122  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1123 }
1124 
1125 //----------------------------------------------------------------------------
1126 inline double vtkMath::Distance2BetweenPoints(const double x[3],
1127  const double y[3])
1128 {
1129  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1130  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1131  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1132 }
1133 
1134 //----------------------------------------------------------------------------
1135 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1136 inline void vtkMath::Cross(const float x[3], const float y[3], float z[3])
1137 {
1138  float Zx = x[1] * y[2] - x[2] * y[1];
1139  float Zy = x[2] * y[0] - x[0] * y[2];
1140  float Zz = x[0] * y[1] - x[1] * y[0];
1141  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1142 }
1143 
1144 //----------------------------------------------------------------------------
1145 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1146 inline void vtkMath::Cross(const double x[3], const double y[3], double z[3])
1147 {
1148  double Zx = x[1] * y[2] - x[2] * y[1];
1149  double Zy = x[2] * y[0] - x[0] * y[2];
1150  double Zz = x[0] * y[1] - x[1] * y[0];
1151  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1152 }
1153 
1154 //BTX
1155 //----------------------------------------------------------------------------
1156 template<class T>
1157 inline double vtkDeterminant3x3(T A[3][3])
1158 {
1159  return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] +
1160  A[2][0] * A[0][1] * A[1][2] - A[0][0] * A[2][1] * A[1][2] -
1161  A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1162 }
1163 //ETX
1164 
1165 //----------------------------------------------------------------------------
1166 inline double vtkMath::Determinant3x3(float A[3][3])
1167 {
1168  return vtkDeterminant3x3( A );
1169 }
1170 
1171 //----------------------------------------------------------------------------
1172 inline double vtkMath::Determinant3x3(double A[3][3])
1173 {
1174  return vtkDeterminant3x3( A );
1175 }
1176 
1177 //----------------------------------------------------------------------------
1178 inline void vtkMath::ClampValue(double *value, const double range[2])
1179 {
1180  if (value && range)
1181  {
1182  if (*value < range[0])
1183  {
1184  *value = range[0];
1185  }
1186  else if (*value > range[1])
1187  {
1188  *value = range[1];
1189  }
1190  }
1191 }
1192 
1193 //----------------------------------------------------------------------------
1195  double value, const double range[2], double *clamped_value)
1196 {
1197  if (range && clamped_value)
1198  {
1199  if (value < range[0])
1200  {
1201  *clamped_value = range[0];
1202  }
1203  else if (value > range[1])
1204  {
1205  *clamped_value = range[1];
1206  }
1207  else
1208  {
1209  *clamped_value = value;
1210  }
1211  }
1212 }
1213 
1214 // ---------------------------------------------------------------------------
1216  const double range[2])
1217 {
1218  assert("pre: valid_range" && range[0]<=range[1]);
1219 
1220  double result;
1221  if(range[0]==range[1])
1222  {
1223  result=0.0;
1224  }
1225  else
1226  {
1227  // clamp
1228  if(value<range[0])
1229  {
1230  result=range[0];
1231  }
1232  else
1233  {
1234  if(value>range[1])
1235  {
1236  result=range[1];
1237  }
1238  else
1239  {
1240  result=value;
1241  }
1242  }
1243 
1244  // normalize
1245  result=( result - range[0] ) / ( range[1] - range[0] );
1246  }
1247 
1248  assert("post: valid_result" && result>=0.0 && result<=1.0);
1249 
1250  return result;
1251 }
1252 
1253 //-----------------------------------------------------------------------------
1254 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1255 #define VTK_MATH_ISINF_IS_INLINE
1256 inline int vtkMath::IsInf(double x)
1257 {
1258 #if defined(VTK_HAS_STD_ISINF)
1259  return std::isinf(x);
1260 #else
1261  return (isinf(x) != 0); // Force conversion to bool
1262 #endif
1263 }
1264 #endif
1265 
1266 //-----------------------------------------------------------------------------
1267 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1268 #define VTK_MATH_ISNAN_IS_INLINE
1269 inline int vtkMath::IsNan(double x)
1270 {
1271 #if defined(VTK_HAS_STD_ISNAN)
1272  return std::isnan(x);
1273 #else
1274  return (isnan(x) != 0); // Force conversion to bool
1275 #endif
1276 }
1277 #endif
1278 
1279 //-----------------------------------------------------------------------------
1280 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1281 #define VTK_MATH_ISFINITE_IS_INLINE
1282 inline bool vtkMath::IsFinite(double x)
1283 {
1284 #if defined(VTK_HAS_STD_ISFINITE)
1285  return std::isfinite(x);
1286 #elif defined(VTK_HAS_ISFINITE)
1287  return (isfinite(x) != 0); // Force conversion to bool
1288 #else
1289  return (finite(x) != 0); // Force conversion to bool
1290 #endif
1291 }
1292 #endif
1293 
1294 #endif
static void MultiplyScalar2D(float a[2], float s)
Definition: vtkMath.h:270
static bool IsFinite(double x)
static float Dot2D(const float x[2], const float y[2])
Definition: vtkMath.h:418
static void Cross(const float x[3], const float y[3], float z[3])
Definition: vtkMath.h:1136
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:791
static double Norm(const double x[3])
Definition: vtkMath.h:344
static double Pi()
Definition: vtkMath.h:88
static void ClampValue(double *value, const double range[2])
Definition: vtkMath.h:1178
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Definition: vtkMath.h:996
static void Outer(const float x[3], const float y[3], float A[3][3])
Definition: vtkMath.h:308
static float Determinant2x2(const float c1[2], const float c2[2])
Definition: vtkMath.h:476
#define VTKCOMMONCORE_EXPORT
static void RGBToHSV(const double rgb[3], double hsv[3])
Definition: vtkMath.h:769
static int Round(float f)
Definition: vtkMath.h:104
vtkMath()
Definition: vtkMath.h:962
static void RGBToHSV(const float rgb[3], float hsv[3])
Definition: vtkMath.h:764
static int AreBoundsInitialized(double bounds[6])
Definition: vtkMath.h:865
static double ClampAndNormalizeValue(double value, const double range[2])
Definition: vtkMath.h:1215
static void Outer(const double x[3], const double y[3], double A[3][3])
Definition: vtkMath.h:316
static void Add(const double a[3], const double b[3], double c[3])
Definition: vtkMath.h:234
static void XYZToRGB(const double xyz[3], double rgb[3])
Definition: vtkMath.h:811
static float Norm2D(const float x[2])
Definition: vtkMath.h:457
static float Normalize2D(float x[2])
static void UninitializeBounds(double bounds[6])
Definition: vtkMath.h:853
static int NearestPowerOfTwo(int x)
Definition: vtkMath.h:1003
virtual void PrintSelf(ostream &os, vtkIndent indent)
static void RGBToXYZ(const double rgb[3], double xyz[3])
Definition: vtkMath.h:821
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:296
static void Subtract(const float a[3], const float b[3], float c[3])
Definition: vtkMath.h:243
static void Subtract(const double a[3], const double b[3], double c[3])
Definition: vtkMath.h:252
static int Floor(double x)
Definition: vtkMath.h:1017
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:482
static float RadiansFromDegrees(float degrees)
Definition: vtkMath.h:972
static void HSVToRGB(const double hsv[3], double rgb[3])
Definition: vtkMath.h:784
Park and Miller Sequence of pseudo random numbers.
static void MultiplyScalar(double a[3], double s)
Definition: vtkMath.h:279
static double Determinant3x3(float A[3][3])
Definition: vtkMath.h:1166
static float Normalize(float x[3])
Definition: vtkMath.h:1033
static void RGBToLab(const double rgb[3], double lab[3])
Definition: vtkMath.h:833
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:443
static void Outer2D(const float x[2], const float y[2], float A[2][2])
Definition: vtkMath.h:430
static int Ceil(double x)
Definition: vtkMath.h:1026
performs common math operations
Definition: vtkMath.h:80
static double Dot2D(const double x[2], const double y[2])
Definition: vtkMath.h:424
static double Dot(const double x[3], const double y[3])
Definition: vtkMath.h:302
static void MultiplyScalar(float a[3], float s)
Definition: vtkMath.h:261
static void HSVToRGB(const float hsv[3], float rgb[3])
Definition: vtkMath.h:779
~vtkMath()
Definition: vtkMath.h:963
static double Norm2D(const double x[2])
Definition: vtkMath.h:463
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:288
static void LabToRGB(const double lab[3], double rgb[3])
Definition: vtkMath.h:843
static vtkMathInternal Internal
Definition: vtkMath.h:965
static vtkObject * New()
double vtkDeterminant3x3(T A[3][3])
Definition: vtkMath.h:1157
static float Norm(const float *x, int n)
static float Distance2BetweenPoints(const float x[3], const float y[3])
Definition: vtkMath.h:1117
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:484
static float Norm(const float x[3])
Definition: vtkMath.h:338
static void Add(const float a[3], const float b[3], float c[3])
Definition: vtkMath.h:226
#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:801