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 <assert.h> // 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 
80 class VTKCOMMONCORE_EXPORT vtkMath : public vtkObject
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  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 
670  static int LUFactorLinearSystem(double **A, int *index, int size);
671 
673 
675  static int LUFactorLinearSystem(double **A, int *index, int size,
676  double *tmpSize);
678 
680 
686  static void LUSolveLinearSystem(double **A, int *index,
687  double *x, int size);
689 
697  static double EstimateMatrixCondition(double **A, int size);
698 
700 
704  static int Jacobi(float **a, float *w, float **v);
705  static int Jacobi(double **a, double *w, double **v);
707 
709 
714  static int JacobiN(float **a, int n, float *w, float **v);
715  static int JacobiN(double **a, int n, double *w, double **v);
717 
719 
729  static int SolveHomogeneousLeastSquares(int numberOfSamples, double **xt, int xOrder,
730  double **mt);
732 
733 
735 
746  static int SolveLeastSquares(int numberOfSamples, double **xt, int xOrder,
747  double **yt, int yOrder, double **mt, int checkHomogeneous=1);
749 
751 
755  static void RGBToHSV(const float rgb[3], float hsv[3])
756  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
757  static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v);
758  static double* RGBToHSV(const double rgb[3]);
759  static double* RGBToHSV(double r, double g, double b);
760  static void RGBToHSV(const double rgb[3], double hsv[3])
761  { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
762  static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v);
764 
766 
770  static void HSVToRGB(const float hsv[3], float rgb[3])
771  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
772  static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b);
773  static double* HSVToRGB(const double hsv[3]);
774  static double* HSVToRGB(double h, double s, double v);
775  static void HSVToRGB(const double hsv[3], double rgb[3])
776  { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
777  static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b);
779 
781 
782  static void LabToXYZ(const double lab[3], double xyz[3]) {
783  LabToXYZ(lab[0], lab[1], lab[2], xyz+0, xyz+1, xyz+2);
784  }
785  static void LabToXYZ(double L, double a, double b,
786  double *x, double *y, double *z);
787  static double *LabToXYZ(const double lab[3]);
789 
791 
792  static void XYZToLab(const double xyz[3], double lab[3]) {
793  XYZToLab(xyz[0], xyz[1], xyz[2], lab+0, lab+1, lab+2);
794  }
795  static void XYZToLab(double x, double y, double z,
796  double *L, double *a, double *b);
797  static double *XYZToLab(const double xyz[3]);
799 
801 
802  static void XYZToRGB(const double xyz[3], double rgb[3]) {
803  XYZToRGB(xyz[0], xyz[1], xyz[2], rgb+0, rgb+1, rgb+2);
804  }
805  static void XYZToRGB(double x, double y, double z,
806  double *r, double *g, double *b);
807  static double *XYZToRGB(const double xyz[3]);
809 
811 
812  static void RGBToXYZ(const double rgb[3], double xyz[3]) {
813  RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz+0, xyz+1, xyz+2);
814  }
815  static void RGBToXYZ(double r, double g, double b,
816  double *x, double *y, double *z);
817  static double *RGBToXYZ(const double rgb[3]);
819 
821 
824  static void RGBToLab(const double rgb[3], double lab[3]) {
825  RGBToLab(rgb[0], rgb[1], rgb[2], lab+0, lab+1, lab+2);
826  }
827  static void RGBToLab(double red, double green, double blue,
828  double *L, double *a, double *b);
829  static double *RGBToLab(const double rgb[3]);
831 
833 
834  static void LabToRGB(const double lab[3], double rgb[3]) {
835  LabToRGB(lab[0], lab[1], lab[2], rgb+0, rgb+1, rgb+2);
836  }
837  static void LabToRGB(double L, double a, double b,
838  double *red, double *green, double *blue);
839  static double *LabToRGB(const double lab[3]);
841 
843 
844  static void UninitializeBounds(double bounds[6]){
845  bounds[0] = 1.0;
846  bounds[1] = -1.0;
847  bounds[2] = 1.0;
848  bounds[3] = -1.0;
849  bounds[4] = 1.0;
850  bounds[5] = -1.0;
851  }
853 
855 
856  static int AreBoundsInitialized(double bounds[6]){
857  if ( bounds[1]-bounds[0]<0.0 )
858  {
859  return 0;
860  }
861  return 1;
862  }
864 
866 
868  static void ClampValue(double *value, const double range[2]);
869  static void ClampValue(double value, const double range[2], double *clamped_value);
870  static void ClampValues(
871  double *values, int nb_values, const double range[2]);
872  static void ClampValues(
873  const double *values, int nb_values, const double range[2], double *clamped_values);
875 
877 
880  static double ClampAndNormalizeValue(double value,
881  const double range[2]);
883 
885 
891  static int GetScalarTypeFittingRange(
892  double range_min, double range_max,
893  double scale = 1.0, double shift = 0.0);
895 
897 
903  static int GetAdjustedScalarRange(
904  vtkDataArray *array, int comp, double range[2]);
906 
909  static int ExtentIsWithinOtherExtent(int extent1[6], int extent2[6]);
910 
914  static int BoundsIsWithinOtherBounds(double bounds1[6], double bounds2[6], double delta[3]);
915 
919  static int PointIsWithinBounds(double point[3], double bounds[6], double delta[3]);
920 
928  static double Solve3PointCircle(const double p1[3], const double p2[3], const double p3[3], double center[3]);
929 
931  static double Inf();
932 
934  static double NegInf();
935 
937  static double Nan();
938 
941  static int IsInf(double x);
942 
945  static int IsNan(double x);
946 
949  static bool IsFinite(double x);
950 
951 protected:
952  vtkMath() {};
953  ~vtkMath() {};
954 
955  static vtkMathInternal Internal;
956 private:
957  vtkMath(const vtkMath&); // Not implemented.
958  void operator=(const vtkMath&); // Not implemented.
959 };
960 
961 //----------------------------------------------------------------------------
962 inline float vtkMath::RadiansFromDegrees( float x )
963 {
964  return x * 0.017453292f;
965 }
966 
967 //----------------------------------------------------------------------------
968 inline double vtkMath::RadiansFromDegrees( double x )
969 {
970  return x * 0.017453292519943295;
971 }
972 
973 //----------------------------------------------------------------------------
974 inline float vtkMath::DegreesFromRadians( float x )
975 {
976  return x * 57.2957795131f;
977 }
978 
979 //----------------------------------------------------------------------------
980 inline double vtkMath::DegreesFromRadians( double x )
981 {
982  return x * 57.29577951308232;
983 }
984 
985 //----------------------------------------------------------------------------
986 inline vtkTypeInt64 vtkMath::Factorial( int N )
987 {
988  vtkTypeInt64 r = 1;
989  while ( N > 1 )
990  {
991  r *= N--;
992  }
993  return r;
994 }
995 
996 //----------------------------------------------------------------------------
997 inline bool vtkMath::IsPowerOfTwo(vtkTypeUInt64 x)
998 {
999  return ((x != 0) & ((x & (x - 1)) == 0));
1000 }
1001 
1002 //----------------------------------------------------------------------------
1003 // Credit goes to Peter Hart and William Lewis on comp.lang.python 1997
1005 {
1006  unsigned int z = ((x > 0) ? x - 1 : 0);
1007  z |= z >> 1;
1008  z |= z >> 2;
1009  z |= z >> 4;
1010  z |= z >> 8;
1011  z |= z >> 16;
1012  return static_cast<int>(z + 1);
1013 }
1014 
1015 //----------------------------------------------------------------------------
1016 // Modify the trunc() operation provided by static_cast<int>() to get floor(),
1017 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1018 inline int vtkMath::Floor(double x)
1019 {
1020  int i = static_cast<int>(x);
1021  return i - ( i > x );
1022 }
1023 
1024 //----------------------------------------------------------------------------
1025 // Modify the trunc() operation provided by static_cast<int>() to get ceil(),
1026 // Note that in C++ conditions evaluate to values of 1 or 0 (true or false).
1027 inline int vtkMath::Ceil(double x)
1028 {
1029  int i = static_cast<int>(x);
1030  return i + ( i < x );
1031 }
1032 
1033 //----------------------------------------------------------------------------
1034 inline float vtkMath::Normalize(float x[3])
1035 {
1036  float den;
1037  if ( ( den = vtkMath::Norm( x ) ) != 0.0 )
1038  {
1039  for (int i=0; i < 3; i++)
1040  {
1041  x[i] /= den;
1042  }
1043  }
1044  return den;
1045 }
1046 
1047 //----------------------------------------------------------------------------
1048 inline double vtkMath::Normalize(double x[3])
1049 {
1050  double den;
1051  if ( ( den = vtkMath::Norm( x ) ) != 0.0 )
1052  {
1053  for (int i=0; i < 3; i++)
1054  {
1055  x[i] /= den;
1056  }
1057  }
1058  return den;
1059 }
1060 
1061 //----------------------------------------------------------------------------
1062 inline float vtkMath::Normalize2D(float x[3])
1063 {
1064  float den;
1065  if ( ( den = vtkMath::Norm2D( x ) ) != 0.0 )
1066  {
1067  for (int i=0; i < 2; i++)
1068  {
1069  x[i] /= den;
1070  }
1071  }
1072  return den;
1073 }
1074 
1075 //----------------------------------------------------------------------------
1076 inline double vtkMath::Normalize2D(double x[3])
1077 {
1078  double den;
1079  if ( ( den = vtkMath::Norm2D( x ) ) != 0.0 )
1080  {
1081  for (int i=0; i < 2; i++)
1082  {
1083  x[i] /= den;
1084  }
1085  }
1086  return den;
1087 }
1088 
1089 //----------------------------------------------------------------------------
1090 inline float vtkMath::Determinant3x3(const float c1[3],
1091  const float c2[3],
1092  const float c3[3])
1093 {
1094  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1095  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1096 }
1097 
1098 //----------------------------------------------------------------------------
1099 inline double vtkMath::Determinant3x3(const double c1[3],
1100  const double c2[3],
1101  const double c3[3])
1102 {
1103  return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1104  c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1105 }
1106 
1107 //----------------------------------------------------------------------------
1108 inline double vtkMath::Determinant3x3(double a1, double a2, double a3,
1109  double b1, double b2, double b3,
1110  double c1, double c2, double c3)
1111 {
1112  return ( a1 * vtkMath::Determinant2x2( b2, b3, c2, c3 )
1113  - b1 * vtkMath::Determinant2x2( a2, a3, c2, c3 )
1114  + c1 * vtkMath::Determinant2x2( a2, a3, b2, b3 ) );
1115 }
1116 
1117 //----------------------------------------------------------------------------
1118 inline float vtkMath::Distance2BetweenPoints(const float x[3],
1119  const float y[3])
1120 {
1121  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1122  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1123  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1124 }
1125 
1126 //----------------------------------------------------------------------------
1127 inline double vtkMath::Distance2BetweenPoints(const double x[3],
1128  const double y[3])
1129 {
1130  return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1131  + ( x[1] - y[1] ) * ( x[1] - y[1] )
1132  + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1133 }
1134 
1135 //----------------------------------------------------------------------------
1136 // Cross product of two 3-vectors. Result (a x b) is stored in z[3].
1137 inline void vtkMath::Cross(const float x[3], const float y[3], float z[3])
1138 {
1139  float Zx = x[1] * y[2] - x[2] * y[1];
1140  float Zy = x[2] * y[0] - x[0] * y[2];
1141  float Zz = x[0] * y[1] - x[1] * y[0];
1142  z[0] = Zx; z[1] = Zy; z[2] = Zz;
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 double x[3], const double y[3], double z[3])
1148 {
1149  double Zx = x[1] * y[2] - x[2] * y[1];
1150  double Zy = x[2] * y[0] - x[0] * y[2];
1151  double Zz = x[0] * y[1] - x[1] * y[0];
1152  z[0] = Zx; z[1] = Zy; z[2] = Zz;
1153 }
1154 
1155 //BTX
1156 //----------------------------------------------------------------------------
1157 template<class T>
1158 inline double vtkDeterminant3x3(T A[3][3])
1159 {
1160  return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] +
1161  A[2][0] * A[0][1] * A[1][2] - A[0][0] * A[2][1] * A[1][2] -
1162  A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1163 }
1164 //ETX
1165 
1166 //----------------------------------------------------------------------------
1167 inline double vtkMath::Determinant3x3(float A[3][3])
1168 {
1169  return vtkDeterminant3x3( A );
1170 }
1171 
1172 //----------------------------------------------------------------------------
1173 inline double vtkMath::Determinant3x3(double A[3][3])
1174 {
1175  return vtkDeterminant3x3( A );
1176 }
1177 
1178 //----------------------------------------------------------------------------
1179 inline void vtkMath::ClampValue(double *value, const double range[2])
1180 {
1181  if (value && range)
1182  {
1183  if (*value < range[0])
1184  {
1185  *value = range[0];
1186  }
1187  else if (*value > range[1])
1188  {
1189  *value = range[1];
1190  }
1191  }
1192 }
1193 
1194 //----------------------------------------------------------------------------
1196  double value, const double range[2], double *clamped_value)
1197 {
1198  if (range && clamped_value)
1199  {
1200  if (value < range[0])
1201  {
1202  *clamped_value = range[0];
1203  }
1204  else if (value > range[1])
1205  {
1206  *clamped_value = range[1];
1207  }
1208  else
1209  {
1210  *clamped_value = value;
1211  }
1212  }
1213 }
1214 
1215 // ---------------------------------------------------------------------------
1216 inline double vtkMath::ClampAndNormalizeValue(double value,
1217  const double range[2])
1218 {
1219  assert("pre: valid_range" && range[0]<=range[1]);
1220 
1221  double result;
1222  if(range[0]==range[1])
1223  {
1224  result=0.0;
1225  }
1226  else
1227  {
1228  // clamp
1229  if(value<range[0])
1230  {
1231  result=range[0];
1232  }
1233  else
1234  {
1235  if(value>range[1])
1236  {
1237  result=range[1];
1238  }
1239  else
1240  {
1241  result=value;
1242  }
1243  }
1244 
1245  // normalize
1246  result=( result - range[0] ) / ( range[1] - range[0] );
1247  }
1248 
1249  assert("post: valid_result" && result>=0.0 && result<=1.0);
1250 
1251  return result;
1252 }
1253 
1254 //-----------------------------------------------------------------------------
1255 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1256 #define VTK_MATH_ISINF_IS_INLINE
1257 inline int vtkMath::IsInf(double x)
1258 {
1259  using namespace std; // Could be isinf() or std::isinf()
1260  return (isinf(x) != 0); // Force conversion to bool
1261 }
1262 #endif
1263 
1264 //-----------------------------------------------------------------------------
1265 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1266 #define VTK_MATH_ISNAN_IS_INLINE
1267 inline int vtkMath::IsNan(double x)
1268 {
1269  using namespace std; // Could be isnan() or std::isnan()
1270  return (isnan(x) != 0); // Force conversion to bool
1271 }
1272 #endif
1273 
1274 //-----------------------------------------------------------------------------
1275 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1276 #define VTK_MATH_ISFINITE_IS_INLINE
1277 inline bool vtkMath::IsFinite(double x)
1278 {
1279 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE)
1280  using namespace std; // Could be isfinite() or std::isfinite()
1281  return (isfinite(x) != 0); // Force conversion to bool
1282 #else
1283  return (finite(x) != 0); // Force conversion to bool
1284 #endif
1285 }
1286 #endif
1287 
1288 #endif
static void MultiplyScalar2D(float a[2], float s)
Definition: vtkMath.h:276
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:1137
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:782
static double Norm(const double x[3])
Definition: vtkMath.h:350
static double Pi()
Definition: vtkMath.h:88
static void ClampValue(double *value, const double range[2])
Definition: vtkMath.h:1179
static bool IsPowerOfTwo(vtkTypeUInt64 x)
Definition: vtkMath.h:997
static void Outer(const float x[3], const float y[3], float A[3][3])
Definition: vtkMath.h:314
static float Determinant2x2(const float c1[2], const float c2[2])
Definition: vtkMath.h:479
static vtkTypeInt64 Factorial(int N)
Definition: vtkMath.h:986
static void RGBToHSV(const double rgb[3], double hsv[3])
Definition: vtkMath.h:760
static int Round(float f)
Definition: vtkMath.h:110
vtkMath()
Definition: vtkMath.h:952
static void RGBToHSV(const float rgb[3], float hsv[3])
Definition: vtkMath.h:755
static int AreBoundsInitialized(double bounds[6])
Definition: vtkMath.h:856
static double ClampAndNormalizeValue(double value, const double range[2])
Definition: vtkMath.h:1216
static void Outer(const double x[3], const double y[3], double A[3][3])
Definition: vtkMath.h:322
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:802
static float Norm2D(const float x[2])
Definition: vtkMath.h:460
static float Normalize2D(float x[2])
static void UninitializeBounds(double bounds[6])
Definition: vtkMath.h:844
static int NearestPowerOfTwo(int x)
Definition: vtkMath.h:1004
virtual void PrintSelf(ostream &os, vtkIndent indent)
static void RGBToXYZ(const double rgb[3], double xyz[3])
Definition: vtkMath.h:812
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: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:1018
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:962
static void HSVToRGB(const double hsv[3], double rgb[3])
Definition: vtkMath.h:775
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:1167
static float Normalize(float x[3])
Definition: vtkMath.h:1034
static void RGBToLab(const double rgb[3], double lab[3])
Definition: vtkMath.h:824
static float DegreesFromRadians(float radians)
Definition: vtkMath.h:974
static void Outer2D(const double x[2], const double y[2], double A[2][2])
Definition: vtkMath.h:446
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:1027
performs common math operations
Definition: vtkMath.h:80
static double Dot2D(const double x[2], const double y[2])
Definition: vtkMath.h:427
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:770
~vtkMath()
Definition: vtkMath.h:953
static double Norm2D(const double x[2])
Definition: vtkMath.h:466
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:834
static vtkObject * New()
double vtkDeterminant3x3(T A[3][3])
Definition: vtkMath.h:1158
static float Norm(const float *x, int n)
static float Distance2BetweenPoints(const float x[3], const float y[3])
Definition: vtkMath.h:1118
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
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
represent and manipulate 3D points
Definition: vtkPoints.h:39
static void XYZToLab(const double xyz[3], double lab[3])
Definition: vtkMath.h:792