Go to the documentation of this file.
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);
124 static bool IsPowerOfTwo(vtkTypeUInt64
x);
129 static int NearestPowerOfTwo(
int x);
226 static void Add(
const float a[3],
const float b[3],
float c[3]) {
227 for (
int i = 0; i < 3; ++i)
234 static void Add(
const double a[3],
const double b[3],
double c[3]) {
235 for (
int i = 0; i < 3; ++i)
243 static void Subtract(
const float a[3],
const float b[3],
float c[3]) {
244 for (
int i = 0; i < 3; ++i)
252 static void Subtract(
const double a[3],
const double b[3],
double c[3]) {
253 for (
int i = 0; i < 3; ++i)
262 for (
int i = 0; i < 3; ++i)
271 for (
int i = 0; i < 2; ++i)
280 for (
int i = 0; i < 3; ++i)
289 for (
int i = 0; i < 2; ++i)
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] );};
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] );};
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];
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];
324 static void Cross(
const float x[3],
const float y[3],
float z[3]);
328 static void Cross(
const double x[3],
const double y[3],
double z[3]);
332 static float Norm(
const float*
x,
int n);
333 static double Norm(
const double*
x,
int n);
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] ) );};
344 static double Norm(
const double x[3]) {
345 return sqrt(
x[0] *
x[0] +
x[1] *
x[1] +
x[2] *
x[2] );};
349 static float Normalize(
float x[3]);
353 static double Normalize(
double x[3]);
372 static bool ProjectVector(
const double a[3],
const double b[3],
double projection[3]);
385 static float Distance2BetweenPoints(
const float x[3],
const float y[3]);
389 static double Distance2BetweenPoints(
const double x[3],
const double y[3]);
408 static double GaussianWeight(
const double variance,
const double distanceFromMean);
418 static float Dot2D(
const float x[2],
const float y[2]) {
419 return (
x[0] *
y[0] +
x[1] *
y[1] );};
424 static double Dot2D(
const double x[2],
const double y[2]) {
425 return (
x[0] *
y[0] +
x[1] *
y[1] );};
430 static void Outer2D(
const float x[2],
const float y[2],
float A[2][2])
432 for (
int i=0; i < 2; i++)
434 for (
int j=0; j < 2; j++)
436 A[i][j] =
x[i] *
y[j];
443 static void Outer2D(
const double x[2],
const double y[2],
double A[2][2])
445 for (
int i=0; i < 2; i++)
447 for (
int j=0; j < 2; j++)
449 A[i][j] =
x[i] *
y[j];
458 return static_cast<float> (sqrt(
x[0] *
x[0] +
x[1] *
x[1] ) );};
464 return sqrt(
x[0] *
x[0] +
x[1] *
x[1] );};
477 return (c1[0] * c2[1] - c2[0] * c1[1] );};
483 return (
a * d -
b *
c);};
485 return (c1[0] * c2[1] - c2[0] * c1[1] );};
523 static void Multiply3x3(
const double A[3][3],
const double B[3][3],
531 unsigned int rowA,
unsigned int colA,
532 unsigned int rowB,
unsigned int colB,
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]);
558 static double Determinant3x3(
float A[3][3]);
559 static double Determinant3x3(
double A[3][3]);
564 static float Determinant3x3(
const float c1[3],
571 static double Determinant3x3(
const double c1[3],
579 static double Determinant3x3(
double a1,
double a2,
double a3,
580 double b1,
double b2,
double b3,
581 double c1,
double c2,
double c3);
637 float U[3][3],
float w[3],
640 double U[3][3],
double w[3],
659 int *tmp1Size,
double *tmp2Size);
694 double *
x,
int size);
756 double **yt,
int yOrder,
double **mt,
int checkHomogeneous=1);
764 static void RGBToHSV(
const float rgb[3],
float hsv[3])
765 { RGBToHSV(rgb[0], rgb[1], rgb[2], hsv, hsv+1, hsv+2); }
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);
779 static void HSVToRGB(
const float hsv[3],
float rgb[3])
780 { HSVToRGB(hsv[0], hsv[1], hsv[2], rgb, rgb+1, rgb+2); }
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);
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);
795 double *
x,
double *
y,
double *
z);
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);
805 double *L,
double *
a,
double *
b);
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);
815 double *
r,
double *
g,
double *
b);
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);
825 double *
x,
double *
y,
double *
z);
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);
837 double *L,
double *
a,
double *
b);
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);
847 double *red,
double *
green,
double *
blue);
866 if ( bounds[1]-bounds[0]<0.0 )
877 static void ClampValue(
double *
value,
const double range[2]);
878 static void ClampValue(
double value,
const double range[2],
double *clamped_value);
880 double *
values,
int nb_values,
const double range[2]);
882 const double *
values,
int nb_values,
const double range[2],
double *clamped_values);
889 static double ClampAndNormalizeValue(
double value,
890 const double range[2]);
901 double range_min,
double range_max,
902 double scale = 1.0,
double shift = 0.0);
968 void operator=(
const vtkMath&);
974 return x * 0.017453292f;
980 return x * 0.017453292519943295;
986 return x * 57.2957795131f;
992 return x * 57.29577951308232;
998 return ((
x != 0) & ((
x & (
x - 1)) == 0));
1005 unsigned int z = ((
x > 0) ?
x - 1 : 0);
1011 return static_cast<int>(
z + 1);
1019 int i =
static_cast<int>(
x);
1020 return i - ( i >
x );
1028 int i =
static_cast<int>(
x);
1029 return i + ( i <
x );
1038 for (
int i=0; i < 3; i++)
1052 for (
int i=0; i < 3; i++)
1066 for (
int i=0; i < 2; i++)
1080 for (
int i=0; i < 2; i++)
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];
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];
1108 double b1,
double b2,
double b3,
1109 double c1,
double c2,
double c3)
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] ) );
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] ) );
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;
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;
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];
1195 double value,
const double range[2],
double *clamped_value)
1197 if (
range && clamped_value)
1201 *clamped_value =
range[0];
1205 *clamped_value =
range[1];
1209 *clamped_value =
value;
1216 const double range[2])
1218 assert(
"pre: valid_range" &&
range[0]<=
range[1]);
1248 assert(
"post: valid_result" &&
result>=0.0 &&
result<=1.0);
1254 #if defined(VTK_HAS_ISINF) || defined(VTK_HAS_STD_ISINF)
1255 #define VTK_MATH_ISINF_IS_INLINE
1258 #if defined(VTK_HAS_STD_ISINF)
1259 return std::isinf(
x);
1261 return (isinf(
x) != 0);
1267 #if defined(VTK_HAS_ISNAN) || defined(VTK_HAS_STD_ISNAN)
1268 #define VTK_MATH_ISNAN_IS_INLINE
1271 #if defined(VTK_HAS_STD_ISNAN)
1272 return std::isnan(
x);
1274 return (isnan(
x) != 0);
1280 #if defined(VTK_HAS_ISFINITE) || defined(VTK_HAS_STD_ISFINITE) || defined(VTK_HAS_FINITE)
1281 #define VTK_MATH_ISFINITE_IS_INLINE
1284 #if defined(VTK_HAS_STD_ISFINITE)
1285 return std::isfinite(
x);
1286 #elif defined(VTK_HAS_ISFINITE)
1287 return (isfinite(
x) != 0);
1289 return (finite(
x) != 0);
represent and manipulate 3D points
static int Ceil(double x)
static int GetScalarTypeFittingRange(double range_min, double range_max, double scale=1.0, double shift=0.0)
static void RGBToLab(const double rgb[3], double lab[3])
static void SingularValueDecomposition3x3(const float A[3][3], float U[3][3], float w[3], float VT[3][3])
static void Identity3x3(float A[3][3])
static void MultiplyScalar(double a[3], double s)
static float Norm(const float *x, int n)
static void RGBToHSV(const double rgb[3], double hsv[3])
#define VTKCOMMONCORE_EXPORT
GLfloat GLfloat GLfloat v2
static int Floor(double x)
Park and Miller Sequence of pseudo random numbers.
static float Distance2BetweenPoints(const float x[3], const float y[3])
static double * RGBToLab(const double rgb[3])
static int NearestPowerOfTwo(int x)
static void LUFactor3x3(double A[3][3], int index[3])
GLboolean GLboolean GLboolean b
static void LabToRGB(double L, double a, double b, double *red, double *green, double *blue)
static double Determinant2x2(double a, double b, double c, double d)
static void Multiply3x3(const float A[3][3], const float in[3], float out[3])
GLfloat GLfloat GLfloat GLfloat h
static void RGBToHSV(float r, float g, float b, float *h, float *s, float *v)
static void Diagonalize3x3(const float A[3][3], float w[3], float V[3][3])
static void RGBToHSV(const float rgb[3], float hsv[3])
static int Jacobi(float **a, float *w, float **v)
static void UninitializeBounds(double bounds[6])
static float Dot2D(const float x[2], const float y[2])
static void RGBToHSV(double r, double g, double b, double *h, double *s, double *v)
static double EstimateMatrixCondition(double **A, int size)
static float Normalize2D(float x[2])
static float Normalize(float x[3])
static double Norm(const double *x, int n)
static void LUSolveLinearSystem(double **A, int *index, double *x, int size)
static float DegreesFromRadians(float radians)
static double Norm2D(const double x[2])
static void Diagonalize3x3(const double A[3][3], double w[3], double V[3][3])
static double Norm(const double x[3])
static int LUFactorLinearSystem(double **A, int *index, int size, double *tmpSize)
GLenum GLenum GLenum GLenum GLenum scale
static void Multiply3x3(const double A[3][3], const double in[3], double out[3])
static void HSVToRGB(double h, double s, double v, double *r, double *g, double *b)
static void HSVToRGB(const double hsv[3], double rgb[3])
static void LUFactor3x3(float A[3][3], int index[3])
#define vtkTypeMacro(thisClass, superclass)
static double GaussianWeight(const double mean, const double variance, const double position)
static void XYZToRGB(double x, double y, double z, double *r, double *g, double *b)
static void MultiplyMatrix(double **A, double **B, unsigned int rowA, unsigned int colA, unsigned int rowB, unsigned int colB, double **C)
static float RadiansFromDegrees(float degrees)
static void XYZToRGB(const double xyz[3], double rgb[3])
abstract base class for most VTK objects
static int LUFactorLinearSystem(double **A, int *index, int size)
static int * BeginCombination(int m, int n)
static int InvertMatrix(double **A, double **AI, int size, int *tmp1Size, double *tmp2Size)
GLint GLint GLint GLint GLint x
static void Identity3x3(double A[3][3])
static void MultiplyScalar(float a[3], float s)
static int Jacobi(double **a, double *w, double **v)
static double Determinant3x3(float A[3][3])
static void MultiplyQuaternion(const float q1[4], const float q2[4], float q[4])
static void Subtract(const float a[3], const float b[3], float c[3])
abstract superclass for arrays of numeric data
static void HSVToRGB(float h, float s, float v, float *r, float *g, float *b)
static void LabToRGB(const double lab[3], double rgb[3])
static bool ProjectVector(const float a[3], const float b[3], float projection[3])
static double * RGBToXYZ(const double rgb[3])
static int JacobiN(double **a, int n, double *w, double **v)
static double ClampAndNormalizeValue(double value, const double range[2])
static double * LabToRGB(const double lab[3])
static void HSVToRGB(const float hsv[3], float rgb[3])
static double GaussianWeight(const double variance, const double distanceFromMean)
static void Subtract(const double a[3], const double b[3], double c[3])
static double Solve3PointCircle(const double p1[3], const double p2[3], const double p3[3], double center[3])
static int SolveHomogeneousLeastSquares(int numberOfSamples, double **xt, int xOrder, double **mt)
static int NextCombination(int m, int n, int *combination)
static void RandomSeed(int s)
static double * XYZToRGB(const double xyz[3])
static void LabToXYZ(const double lab[3], double xyz[3])
static void MultiplyScalar2D(float a[2], float s)
static void LabToXYZ(double L, double a, double b, double *x, double *y, double *z)
static void Add(const double a[3], const double b[3], double c[3])
static bool ProjectVector(const double a[3], const double b[3], double projection[3])
static void Invert3x3(const float A[3][3], float AI[3][3])
static double * HSVToRGB(const double hsv[3])
static void LinearSolve3x3(const double A[3][3], const double x[3], double y[3])
GLsizei const GLfloat * value
static void Transpose3x3(const float A[3][3], float AT[3][3])
GLboolean GLenum GLenum GLvoid * values
static void Perpendiculars(const double x[3], double y[3], double z[3], double theta)
static float Norm2D(const float x[2])
static void MultiplyScalar2D(double a[2], double s)
static int InvertMatrix(double **A, double **AI, int size)
static void Perpendiculars(const float x[3], float y[3], float z[3], double theta)
static int IsInf(double x)
a simple class to control print indentation
static int PointIsWithinBounds(double point[3], double bounds[6], double delta[3])
static void RGBToXYZ(double r, double g, double b, double *x, double *y, double *z)
static double * XYZToLab(const double xyz[3])
static void RGBToLab(double red, double green, double blue, double *L, double *a, double *b)
static double * RGBToHSV(const double rgb[3])
static double * HSVToRGB(double h, double s, double v)
static void Cross(const float x[3], const float y[3], float z[3])
static float Norm(const float x[3])
static void Outer(const float x[3], const float y[3], float A[3][3])
static bool ProjectVector2D(const double a[2], const double b[2], double projection[2])
static void LinearSolve3x3(const float A[3][3], const float x[3], float y[3])
static vtkMathInternal Internal
static double Normalize2D(double x[2])
static void Outer2D(const double x[2], const double y[2], double A[2][2])
static void Matrix3x3ToQuaternion(const double A[3][3], double quat[4])
static float Determinant2x2(const float c1[2], const float c2[2])
static void Transpose3x3(const double A[3][3], double AT[3][3])
static double GaussianAmplitude(const double variance, const double distanceFromMean)
static void Multiply3x3(const double A[3][3], const double B[3][3], double C[3][3])
GLboolean GLboolean GLboolean GLboolean a
static double GaussianAmplitude(const double mean, const double variance, const double position)
static vtkTypeInt64 Factorial(int N)
void PrintSelf(ostream &os, vtkIndent indent)
static int AreBoundsInitialized(double bounds[6])
static void QuaternionToMatrix3x3(const double quat[4], double A[3][3])
static void Orthogonalize3x3(const float A[3][3], float B[3][3])
static void XYZToLab(double x, double y, double z, double *L, double *a, double *b)
static float Dot(const float x[3], const float y[3])
static void LUSolve3x3(const double A[3][3], const int index[3], double x[3])
static double Random(double min, double max)
GLdouble GLdouble GLdouble r
static void LUSolve3x3(const float A[3][3], const int index[3], float x[3])
Gaussian sequence of pseudo random numbers implemented with the Box-Mueller transform.
GLint GLint GLint GLint GLint GLint y
static double Determinant2x2(const double c1[2], const double c2[2])
static double * LabToXYZ(const double lab[3])
static int SolveLeastSquares(int numberOfSamples, double **xt, int xOrder, double **yt, int yOrder, double **mt, int checkHomogeneous=1)
static double * RGBToHSV(double r, double g, double b)
static int JacobiN(float **a, int n, float *w, float **v)
performs common math operations
static bool IsPowerOfTwo(vtkTypeUInt64 x)
static void Outer(const double x[3], const double y[3], double A[3][3])
static void QuaternionToMatrix3x3(const float quat[4], float A[3][3])
static void SingularValueDecomposition3x3(const double A[3][3], double U[3][3], double w[3], double VT[3][3])
static int ExtentIsWithinOtherExtent(int extent1[6], int extent2[6])
static int Round(double f)
static void XYZToLab(const double xyz[3], double lab[3])
static bool ProjectVector2D(const float a[2], const float b[2], float projection[2])
static int GetAdjustedScalarRange(vtkDataArray *array, int comp, double range[2])
static void MultiplyQuaternion(const double q1[4], const double q2[4], double q[4])
static void RGBToXYZ(const double rgb[3], double xyz[3])
static void Orthogonalize3x3(const double A[3][3], double B[3][3])
static int Round(float f)
static void ClampValues(double *values, int nb_values, const double range[2])
static double AngleBetweenVectors(const double v1[3], const double v2[3])
static bool IsFinite(double x)
static double Dot2D(const double x[2], const double y[2])
static void Outer2D(const float x[2], const float y[2], float A[2][2])
static void Add(const float a[3], const float b[3], float c[3])
static int SolveLinearSystem(double **A, double *x, int size)
GLubyte GLubyte GLubyte GLubyte w
static int IsNan(double x)
static int BoundsIsWithinOtherBounds(double bounds1[6], double bounds2[6], double delta[3])
static void Invert3x3(const double A[3][3], double AI[3][3])
static vtkTypeInt64 Binomial(int m, int n)
VTKWRAPPINGJAVA_EXPORT jlong q(JNIEnv *env, jobject obj)
static void Matrix3x3ToQuaternion(const float A[3][3], float quat[4])
static double Dot(const double x[3], const double y[3])
double vtkDeterminant3x3(T A[3][3])
static void Multiply3x3(const float A[3][3], const float B[3][3], float C[3][3])
static double Gaussian(double mean, double std)
static void ClampValues(const double *values, int nb_values, const double range[2], double *clamped_values)
static void ClampValue(double *value, const double range[2])
static int CeilLog2(vtkTypeUInt64 x)
static void FreeCombination(int *combination)