55 # define VTK_DBL_MIN 2.2250738585072014e-308
57 # define VTK_DBL_MIN DBL_MIN
61 # define VTK_DBL_EPSILON 2.2204460492503131e-16
63 # define VTK_DBL_EPSILON DBL_EPSILON
66 #ifndef VTK_DBL_EPSILON
68 # define VTK_DBL_EPSILON 2.2204460492503131e-16
70 # define VTK_DBL_EPSILON DBL_EPSILON
71 # endif // DBL_EPSILON
72 #endif // VTK_DBL_EPSILON
76 class vtkMathInternal;
88 static double Pi() {
return 3.141592653589793; };
92 static float RadiansFromDegrees(
float degrees);
93 static double RadiansFromDegrees(
double degrees);
98 static float DegreesFromRadians(
float radians);
99 static double DegreesFromRadians(
double radians);
105 return static_cast<int>( f + ( f >= 0 ? 0.5 : -0.5 ) ); }
107 return static_cast<int>( f + ( f >= 0 ? 0.5 : -0.5 ) ); }
112 static int Floor(
double x);
116 static int Ceil(
double x);
121 static int CeilLog2(vtkTypeUInt64 x);
126 static T Min(
const T & a,
const T & b);
132 static T Max(
const T & a,
const T & b);
136 static bool IsPowerOfTwo(vtkTypeUInt64 x);
141 static int NearestPowerOfTwo(
int x);
145 static vtkTypeInt64 Factorial(
int N );
150 static vtkTypeInt64 Binomial(
int m,
int n );
158 static int* BeginCombination(
int m,
int n );
166 static int NextCombination(
int m,
int n,
int* combination );
169 static void FreeCombination(
int* combination);
182 static void RandomSeed(
int s);
192 static int GetSeed();
203 static double Random();
213 static double Random(
double min,
double max );
223 static double Gaussian();
234 static double Gaussian(
double mean,
double std );
238 static void Add(
const float a[3],
const float b[3],
float c[3]) {
239 for (
int i = 0; i < 3; ++i)
246 static void Add(
const double a[3],
const double b[3],
double c[3]) {
247 for (
int i = 0; i < 3; ++i)
255 static void Subtract(
const float a[3],
const float b[3],
float c[3]) {
256 for (
int i = 0; i < 3; ++i)
264 static void Subtract(
const double a[3],
const double b[3],
double c[3]) {
265 for (
int i = 0; i < 3; ++i)
274 for (
int i = 0; i < 3; ++i)
283 for (
int i = 0; i < 2; ++i)
292 for (
int i = 0; i < 3; ++i)
301 for (
int i = 0; i < 2; ++i)
308 static float Dot(
const float x[3],
const float y[3]) {
309 return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
314 static double Dot(
const double x[3],
const double y[3]) {
315 return ( x[0] * y[0] + x[1] * y[1] + x[2] * y[2] );};
320 static void Outer(
const float x[3],
const float y[3],
float A[3][3]) {
321 for (
int i=0; i < 3; i++)
322 for (
int j=0; j < 3; j++)
323 A[i][j] = x[i] * y[j];
328 static void Outer(
const double x[3],
const double y[3],
double A[3][3]) {
329 for (
int i=0; i < 3; i++)
330 for (
int j=0; j < 3; j++)
331 A[i][j] = x[i] * y[j];
336 static void Cross(
const float x[3],
const float y[3],
float z[3]);
340 static void Cross(
const double x[3],
const double y[3],
double z[3]);
344 static float Norm(
const float* x,
int n);
345 static double Norm(
const double* x,
int n);
350 static float Norm(
const float x[3]) {
351 return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] ) );};
356 static double Norm(
const double x[3]) {
357 return sqrt( x[0] * x[0] + x[1] * x[1] + x[2] * x[2] );};
361 static float Normalize(
float x[3]);
365 static double Normalize(
double x[3]);
373 static void Perpendiculars(
const double x[3],
double y[3],
double z[3],
375 static void Perpendiculars(
const float x[3],
float y[3],
float z[3],
383 static bool ProjectVector(
const float a[3],
const float b[3],
float projection[3]);
384 static bool ProjectVector(
const double a[3],
const double b[3],
double projection[3]);
392 static bool ProjectVector2D(
const float a[2],
const float b[2],
float projection[2]);
393 static bool ProjectVector2D(
const double a[2],
const double b[2],
double projection[2]);
397 static float Distance2BetweenPoints(
const float x[3],
const float y[3]);
401 static double Distance2BetweenPoints(
const double x[3],
const double y[3]);
404 static double AngleBetweenVectors(
const double v1[3],
const double v2[3]);
409 static double GaussianAmplitude(
const double variance,
const double distanceFromMean);
414 static double GaussianAmplitude(
const double mean,
const double variance,
const double position);
420 static double GaussianWeight(
const double variance,
const double distanceFromMean);
426 static double GaussianWeight(
const double mean,
const double variance,
const double position);
430 static float Dot2D(
const float x[2],
const float y[2]) {
431 return ( x[0] * y[0] + x[1] * y[1] );};
436 static double Dot2D(
const double x[2],
const double y[2]) {
437 return ( x[0] * y[0] + x[1] * y[1] );};
442 static void Outer2D(
const float x[2],
const float y[2],
float A[2][2])
444 for (
int i=0; i < 2; i++)
446 for (
int j=0; j < 2; j++)
448 A[i][j] = x[i] * y[j];
455 static void Outer2D(
const double x[2],
const double y[2],
double A[2][2])
457 for (
int i=0; i < 2; i++)
459 for (
int j=0; j < 2; j++)
461 A[i][j] = x[i] * y[j];
470 return static_cast<float> (sqrt( x[0] * x[0] + x[1] * x[1] ) );};
475 static double Norm2D(
const double x[2]) {
476 return sqrt( x[0] * x[0] + x[1] * x[1] );};
480 static float Normalize2D(
float x[2]);
484 static double Normalize2D(
double x[2]);
489 return (c1[0] * c2[1] - c2[0] * c1[1] );};
495 return (a * d - b * c);};
497 return (c1[0] * c2[1] - c2[0] * c1[1] );};
502 static void LUFactor3x3(
float A[3][3],
int index[3]);
503 static void LUFactor3x3(
double A[3][3],
int index[3]);
508 static void LUSolve3x3(
const float A[3][3],
const int index[3],
510 static void LUSolve3x3(
const double A[3][3],
const int index[3],
517 static void LinearSolve3x3(
const float A[3][3],
const float x[3],
519 static void LinearSolve3x3(
const double A[3][3],
const double x[3],
525 static void Multiply3x3(
const float A[3][3],
const float in[3],
527 static void Multiply3x3(
const double A[3][3],
const double in[3],
533 static void Multiply3x3(
const float A[3][3],
const float B[3][3],
535 static void Multiply3x3(
const double A[3][3],
const double B[3][3],
542 static void MultiplyMatrix(
double **A,
double **B,
543 unsigned int rowA,
unsigned int colA,
544 unsigned int rowB,
unsigned int colB,
551 static void Transpose3x3(
const float A[3][3],
float AT[3][3]);
552 static void Transpose3x3(
const double A[3][3],
double AT[3][3]);
558 static void Invert3x3(
const float A[3][3],
float AI[3][3]);
559 static void Invert3x3(
const double A[3][3],
double AI[3][3]);
564 static void Identity3x3(
float A[3][3]);
565 static void Identity3x3(
double A[3][3]);
570 static double Determinant3x3(
float A[3][3]);
571 static double Determinant3x3(
double A[3][3]);
576 static float Determinant3x3(
const float c1[3],
583 static double Determinant3x3(
const double c1[3],
591 static double Determinant3x3(
double a1,
double a2,
double a3,
592 double b1,
double b2,
double b3,
593 double c1,
double c2,
double c3);
601 static void QuaternionToMatrix3x3(
const float quat[4],
float A[3][3]);
602 static void QuaternionToMatrix3x3(
const double quat[4],
double A[3][3]);
611 static void Matrix3x3ToQuaternion(
const float A[3][3],
float quat[4]);
612 static void Matrix3x3ToQuaternion(
const double A[3][3],
double quat[4]);
619 static void MultiplyQuaternion(
const float q1[4],
const float q2[4],
float q[4] );
620 static void MultiplyQuaternion(
const double q1[4],
const double q2[4],
double q[4] );
627 static void Orthogonalize3x3(
const float A[3][3],
float B[3][3]);
628 static void Orthogonalize3x3(
const double A[3][3],
double B[3][3]);
636 static void Diagonalize3x3(
const float A[3][3],
float w[3],
float V[3][3]);
637 static void Diagonalize3x3(
const double A[3][3],
double w[3],
double V[3][3]);
648 static void SingularValueDecomposition3x3(
const float A[3][3],
649 float U[3][3],
float w[3],
651 static void SingularValueDecomposition3x3(
const double A[3][3],
652 double U[3][3],
double w[3],
660 static int SolveLinearSystem(
double **A,
double *x,
int size);
665 static int InvertMatrix(
double **A,
double **AI,
int size);
670 static int InvertMatrix(
double **A,
double **AI,
int size,
671 int *tmp1Size,
double *tmp2Size);
689 static int LUFactorLinearSystem(
double **A,
int *
index,
int size);
694 static int LUFactorLinearSystem(
double **A,
int *
index,
int size,
705 static void LUSolveLinearSystem(
double **A,
int *
index,
706 double *x,
int size);
716 static double EstimateMatrixCondition(
double **A,
int size);
724 static int Jacobi(
float **a,
float *w,
float **v);
725 static int Jacobi(
double **a,
double *w,
double **v);
735 static int JacobiN(
float **a,
int n,
float *w,
float **v);
736 static int JacobiN(
double **a,
int n,
double *w,
double **v);
750 static int SolveHomogeneousLeastSquares(
int numberOfSamples,
double **xt,
int xOrder,
767 static int SolveLeastSquares(
int numberOfSamples,
double **xt,
int xOrder,
768 double **yt,
int yOrder,
double **mt,
int checkHomogeneous=1);
776 static void RGBToHSV(
const float rgb[3],
float hsv[3])
777 { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
778 static void RGBToHSV(
float r,
float g,
float b,
float *h,
float *s,
float *v);
779 static double* RGBToHSV(
const double rgb[3]);
780 static double* RGBToHSV(
double r,
double g,
double b);
781 static void RGBToHSV(
const double rgb[3],
double hsv[3])
782 { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
783 static void RGBToHSV(
double r,
double g,
double b,
double *h,
double *s,
double *v);
791 static void HSVToRGB(
const float hsv[3],
float rgb[3])
792 { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
793 static void HSVToRGB(
float h,
float s,
float v,
float *r,
float *g,
float *b);
794 static double* HSVToRGB(
const double hsv[3]);
795 static double* HSVToRGB(
double h,
double s,
double v);
796 static void HSVToRGB(
const double hsv[3],
double rgb[3])
797 { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
798 static void HSVToRGB(
double h,
double s,
double v,
double *r,
double *g,
double *b);
803 static void LabToXYZ(
const double lab[3],
double xyz[3]) {
804 LabToXYZ(lab[0], lab[1], lab[2], xyz+0, xyz+1, xyz+2);
806 static void LabToXYZ(
double L,
double a,
double b,
807 double *x,
double *y,
double *z);
808 static double *LabToXYZ(
const double lab[3]);
813 static void XYZToLab(
const double xyz[3],
double lab[3]) {
814 XYZToLab(xyz[0], xyz[1], xyz[2], lab+0, lab+1, lab+2);
816 static void XYZToLab(
double x,
double y,
double z,
817 double *L,
double *a,
double *b);
818 static double *XYZToLab(
const double xyz[3]);
823 static void XYZToRGB(
const double xyz[3],
double rgb[3]) {
824 XYZToRGB(xyz[0], xyz[1], xyz[2], rgb+0, rgb+1, rgb+2);
826 static void XYZToRGB(
double x,
double y,
double z,
827 double *r,
double *g,
double *b);
828 static double *XYZToRGB(
const double xyz[3]);
833 static void RGBToXYZ(
const double rgb[3],
double xyz[3]) {
834 RGBToXYZ(rgb[0], rgb[1], rgb[2], xyz+0, xyz+1, xyz+2);
836 static void RGBToXYZ(
double r,
double g,
double b,
837 double *x,
double *y,
double *z);
838 static double *RGBToXYZ(
const double rgb[3]);
845 static void RGBToLab(
const double rgb[3],
double lab[3]) {
846 RGBToLab(rgb[0], rgb[1], rgb[2], lab+0, lab+1, lab+2);
848 static void RGBToLab(
double red,
double green,
double blue,
849 double *L,
double *a,
double *b);
850 static double *RGBToLab(
const double rgb[3]);
855 static void LabToRGB(
const double lab[3],
double rgb[3]) {
856 LabToRGB(lab[0], lab[1], lab[2], rgb+0, rgb+1, rgb+2);
858 static void LabToRGB(
double L,
double a,
double b,
859 double *red,
double *green,
double *blue);
860 static double *LabToRGB(
const double lab[3]);
878 if ( bounds[1]-bounds[0]<0.0 )
889 static void ClampValue(
double *
value,
const double range[2]);
890 static void ClampValue(
double value,
const double range[2],
double *clamped_value);
891 static void ClampValues(
892 double *values,
int nb_values,
const double range[2]);
893 static void ClampValues(
894 const double *values,
int nb_values,
const double range[2],
double *clamped_values);
901 static double ClampAndNormalizeValue(
double value,
902 const double range[2]);
912 static int GetScalarTypeFittingRange(
913 double range_min,
double range_max,
914 double scale = 1.0,
double shift = 0.0);
924 static int GetAdjustedScalarRange(
930 static int ExtentIsWithinOtherExtent(
int extent1[6],
int extent2[6]);
935 static int BoundsIsWithinOtherBounds(
double bounds1[6],
double bounds2[6],
double delta[3]);
940 static int PointIsWithinBounds(
double point[3],
double bounds[6],
double delta[3]);
950 static double Solve3PointCircle(
const double p1[3],
const double p2[3],
const double p3[3],
double center[3]);
956 static double NegInf();
963 static int IsInf(
double x);
967 static int IsNan(
double x);
971 static bool IsFinite(
double x);
980 void operator=(
const vtkMath&);
986 return x * 0.017453292f;
992 return x * 0.017453292519943295;
998 return x * 57.2957795131f;
1004 return x * 57.29577951308232;
1010 return ((x != 0) & ((x & (x - 1)) == 0));
1017 unsigned int z = ((x > 0) ? x - 1 : 0);
1023 return static_cast<int>(z + 1);
1031 int i =
static_cast<int>(x);
1032 return i - ( i > x );
1040 int i =
static_cast<int>(x);
1041 return i + ( i < x );
1048 return (a < b ? a : b);
1055 return (a > b ? a : b);
1064 for (
int i=0; i < 3; i++)
1078 for (
int i=0; i < 3; i++)
1092 for (
int i=0; i < 2; i++)
1106 for (
int i=0; i < 2; i++)
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];
1128 return c1[0] * c2[1] * c3[2] + c2[0] * c3[1] * c1[2] + c3[0] * c1[1] * c2[2] -
1129 c1[0] * c3[1] * c2[2] - c2[0] * c1[1] * c3[2] - c3[0] * c2[1] * c1[2];
1134 double b1,
double b2,
double b3,
1135 double c1,
double c2,
double c3)
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] ) );
1155 return ( ( x[0] - y[0] ) * ( x[0] - y[0] )
1156 + ( x[1] - y[1] ) * ( x[1] - y[1] )
1157 + ( x[2] - y[2] ) * ( x[2] - y[2] ) );
1164 float Zx = x[1] * y[2] - x[2] * y[1];
1165 float Zy = x[2] * y[0] - x[0] * y[2];
1166 float Zz = x[0] * y[1] - x[1] * y[0];
1167 z[0] = Zx; z[1] = Zy; z[2] = Zz;
1174 double Zx = x[1] * y[2] - x[2] * y[1];
1175 double Zy = x[2] * y[0] - x[0] * y[2];
1176 double Zz = x[0] * y[1] - x[1] * y[0];
1177 z[0] = Zx; z[1] = Zy; z[2] = Zz;
1185 return A[0][0] * A[1][1] * A[2][2] + A[1][0] * A[2][1] * A[0][2] +
1186 A[2][0] * A[0][1] * A[1][2] - A[0][0] * A[2][1] * A[1][2] -
1187 A[1][0] * A[0][1] * A[2][2] - A[2][0] * A[1][1] * A[0][2];
1208 if (*value < range[0])
1212 else if (*value > range[1])
1221 double value,
const double range[2],
double *clamped_value)
1223 if (range && clamped_value)
1225 if (value < range[0])
1227 *clamped_value = range[0];
1229 else if (value > range[1])
1231 *clamped_value = range[1];
1235 *clamped_value =
value;
1242 const double range[2])
1244 assert(
"pre: valid_range" && range[0]<=range[1]);
1247 if(range[0]==range[1])
1271 result=( result - range[0] ) / ( range[1] - range[0] );
1274 assert(
"post: valid_result" && result>=0.0 && result<=1.0);
1280 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1281 #define VTK_MATH_ISINF_IS_INLINE
1284 #if defined(VTK_HAS_STD_ISINF)
1285 return std::isinf(x);
1287 return (isinf(x) != 0);
1293 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1294 #define VTK_MATH_ISNAN_IS_INLINE
1297 #if defined(VTK_HAS_STD_ISNAN)
1298 return std::isnan(x);
1300 return (isnan(x) != 0);
1306 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1307 #define VTK_MATH_ISFINITE_IS_INLINE
1310 #if defined(VTK_HAS_STD_ISFINITE)
1311 return std::isfinite(x);
1312 #elif defined(VTK_HAS_ISFINITE)
1313 return (isfinite(x) != 0);
1315 return (finite(x) != 0);
static void MultiplyScalar2D(float a[2], float s)
static bool IsFinite(double x)
static float Dot2D(const float x[2], const float y[2])
static void Cross(const float x[3], const float y[3], float z[3])
static int IsInf(double x)
abstract base class for most VTK objects
static void LabToXYZ(const double lab[3], double xyz[3])
static double Norm(const double x[3])
static void ClampValue(double *value, const double range[2])
static bool IsPowerOfTwo(vtkTypeUInt64 x)
static void Outer(const float x[3], const float y[3], float A[3][3])
static float Determinant2x2(const float c1[2], const float c2[2])
#define VTKCOMMONCORE_EXPORT
static void RGBToHSV(const double rgb[3], double hsv[3])
static int Round(float f)
static void RGBToHSV(const float rgb[3], float hsv[3])
static int AreBoundsInitialized(double bounds[6])
static double ClampAndNormalizeValue(double value, const double range[2])
static void Outer(const double x[3], const double y[3], double A[3][3])
static void Add(const double a[3], const double b[3], double c[3])
static void XYZToRGB(const double xyz[3], double rgb[3])
static float Norm2D(const float x[2])
static float Normalize2D(float x[2])
static void UninitializeBounds(double bounds[6])
static int NearestPowerOfTwo(int x)
virtual void PrintSelf(ostream &os, vtkIndent indent)
static void RGBToXYZ(const double rgb[3], double xyz[3])
static T Min(const T &a, const T &b)
a simple class to control print indentation
static float Dot(const float x[3], const float y[3])
static void Subtract(const float a[3], const float b[3], float c[3])
static void Subtract(const double a[3], const double b[3], double c[3])
static int Floor(double x)
abstract superclass for arrays of numeric data
static double Determinant2x2(double a, double b, double c, double d)
static float RadiansFromDegrees(float degrees)
static void HSVToRGB(const double hsv[3], double rgb[3])
Park and Miller Sequence of pseudo random numbers.
static void MultiplyScalar(double a[3], double s)
static double Determinant3x3(float A[3][3])
static float Normalize(float x[3])
static void RGBToLab(const double rgb[3], double lab[3])
static float DegreesFromRadians(float radians)
static void Outer2D(const double x[2], const double y[2], double A[2][2])
static void Outer2D(const float x[2], const float y[2], float A[2][2])
static int Ceil(double x)
performs common math operations
static double Dot2D(const double x[2], const double y[2])
static double Dot(const double x[3], const double y[3])
static void MultiplyScalar(float a[3], float s)
static void HSVToRGB(const float hsv[3], float rgb[3])
static double Norm2D(const double x[2])
static int Round(double f)
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
static void MultiplyScalar2D(double a[2], double s)
static void LabToRGB(const double lab[3], double rgb[3])
static vtkMathInternal Internal
double vtkDeterminant3x3(T A[3][3])
static float Norm(const float *x, int n)
static float Distance2BetweenPoints(const float x[3], const float y[3])
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])
static float Norm(const float x[3])
static void Add(const float a[3], const float b[3], float c[3])
represent and manipulate 3D points
static T Max(const T &a, const T &b)
static void XYZToLab(const double xyz[3], double lab[3])