VAPOR3 3.9.4
LegacyVectorMath.h
Go to the documentation of this file.
1#pragma once
2
3#ifndef INCLUDE_DEPRECATED_LEGACY_VECTOR_MATH
4 #error LegacyVectorMath.h is deprecated. Please dont use unless necessary
5#endif
6
7#include <vapor/common.h>
8#include <vector>
9#include <math.h>
10#include <cstddef>
11
12namespace VAPoR {
13
14COMMON_API bool powerOf2(size_t n);
15COMMON_API size_t nextPowerOf2(size_t n);
16
17COMMON_API void computeGradientData(int dim[3], int numChan, unsigned char *volume, unsigned char *gradient);
18COMMON_API void makeModelviewMatrix(float *vpos, float *vdir, float *upvec, float *matrix);
19COMMON_API void makeModelviewMatrixD(double *vpos, double *vdir, double *upvec, double *matrix);
20COMMON_API void makeModelviewMatrixD(const std::vector<double> &vpos, const std::vector<double> &vdir, const std::vector<double> &upvec, double *matrix);
21COMMON_API void makeTransMatrix(float *transVec, float *matrix);
22COMMON_API void makeTransMatrix(double *transVec, double *matrix);
23COMMON_API void makeTransMatrix(const std::vector<double> &transVec, double *matrix);
24COMMON_API void makeScaleMatrix(const double *scaleVec, double *matrix);
25COMMON_API void vscale(float *v, float s);
26COMMON_API void vscale(double *v, double s);
27COMMON_API void vscale(std::vector<double> v, double s);
28COMMON_API void vmult(const float *v, float s, float *w);
29COMMON_API void vmult(const double *v, double s, double *w);
30COMMON_API void vhalf(const float *v1, const float *v2, float *half);
31COMMON_API void vcross(const float *v1, const float *v2, float *cross);
32COMMON_API void vcross(const double *v1, const double *v2, double *cross);
33COMMON_API void vreflect(const float *in, const float *mirror, float *out);
34COMMON_API void vtransform(const float *v, float *mat, float *vt);
35COMMON_API void vtransform(const float *v, float *mat, double *vt);
36COMMON_API void vtransform(const double *v, float *mat, double *vt);
37COMMON_API void vtransform(const double *v, double *mat, double *vt);
38COMMON_API void vtransform4(const float *v, float *mat, float *vt);
39COMMON_API void vtransform3(const float *v, float *mat, float *vt);
40COMMON_API void vtransform3(const double *v, double *mat, double *vt);
41COMMON_API void vtransform3t(const float *v, float *mat, float *vt);
42COMMON_API bool pointOnRight(double *pt1, double *pt2, const double *testPt);
43COMMON_API void mcopy(float *m1, float *m2);
44COMMON_API void mcopy(double *m1, double *m2);
45COMMON_API void mmult(float *m1, float *m2, float *prod);
46COMMON_API void mmult(double *m1, double *m2, double *prod);
47COMMON_API int minvert(const float *mat, float *result);
48COMMON_API int minvert(const double *mat, double *result);
49
50// Some routines to handle 3x3 rotation matrices, represented as 9 floats,
51// where the column index increments faster (like in 4x4 case
52COMMON_API void mmult33(const double *m1, const double *m2, double *result);
53
54// Same as above, but use the transpose (i.e. inverse for rotations) on the left
55COMMON_API void mmultt33(const double *m1Trans, const double *m2, double *result);
56
57// Determine a rotation matrix from (theta, phi, psi) (radians), that is,
58// find the rotation matrix that first rotates in (x,y) by psi, then takes the vector (0,0,1)
59// to the vector with direction (theta,phi) by rotating by phi in the (x,z) plane and then
60// rotating in the (x,y)plane by theta.
61COMMON_API void getRotationMatrix(double theta, double phi, double psi, double *matrix);
62
63// Determine a rotation matrix about an axis:
64COMMON_API void getAxisRotation(int axis, double rotation, double *matrix);
65
66// Determine the psi, phi, theta from a rotation matrix:
67COMMON_API void getRotAngles(double *theta, double *phi, double *psi, const double *matrix);
68COMMON_API int rayBoxIntersect(const float rayStart[3], const float rayDir[3], const float boxExts[6], float results[2]);
69COMMON_API int rayBoxIntersect(const double rayStart[3], const double rayDir[3], const double boxExts[6], double results[2]);
70// Determine the minimum and maximum projection of box corners to ray
71COMMON_API void rayBoxProject(std::vector<double> rayStart, std::vector<double> rayDir, const double boxExts[6], double results[2]);
72
73COMMON_API void qnormal(float *q);
74COMMON_API void qinv(const float q1[4], float q2[4]);
75COMMON_API void qmult(const float *q1, const float *q2, float *dest);
76COMMON_API void qmult(const double *q1, const double *q2, double *dest);
77COMMON_API void qmatrix(const float *q, float *m);
78COMMON_API void qmatrix(const double *q, double *m);
79COMMON_API float ProjectToSphere(float r, float x, float y);
80COMMON_API void CalcRotation(float *q, float newX, float newY, float oldX, float oldY, float ballsize);
81COMMON_API void CalcRotation(double *q, double newX, double newY, double oldX, double oldY, double ballsize);
82COMMON_API float ScalePoint(long pt, long origin, long size);
83COMMON_API void rvec2q(const float rvec[3], float radians, float q[4]);
84COMMON_API void rvec2q(const double rvec[3], double radians, double q[4]);
85COMMON_API void rotmatrix2q(float *m, float *q);
86COMMON_API void rotmatrix2q(double *m, double *q);
87COMMON_API float getScale(float *rotmatrix);
88COMMON_API void view2Quat(float vdir[3], float upvec[3], float q[4]);
89COMMON_API void quat2View(float quat[4], float vdir[3], float upvec[3]);
90COMMON_API void qlog(float quat[4], float lquat[4]);
91COMMON_API void qconj(float quat[4], float conj[4]);
92
93COMMON_API void slerp(float quat1[4], float quat2[4], float t, float result[4]);
94COMMON_API void squad(float quat1[4], float quat2[4], float s1[4], float s2[4], float t, float result[4]);
95
96COMMON_API void imagQuat2View(const float q[3], float vdir[3], float upvec[3]);
97
98COMMON_API void views2ImagQuats(float vdir1[3], float upvec1[3], float vdir2[3], float upvec2[3], float q1[3], float q2[3]);
99
100inline void vset(float *a, const float x, const float y, const float z)
101{
102 a[0] = x;
103 a[1] = y;
104 a[2] = z;
105}
106inline void vset(double *a, const double x, const double y, const double z)
107{
108 a[0] = x;
109 a[1] = y;
110 a[2] = z;
111}
112inline float vdot(const float *a, const float *b) { return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]); }
113inline float vdot(const float *a, const double *b) { return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]); }
114inline double vdot(const double *a, const double *b) { return (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]); }
115inline float vlength(const float *a) { return sqrt(vdot(a, a)); }
116inline double vlength(const double *a) { return sqrt(vdot(a, a)); }
117inline double vlength(const std::vector<double> a) { return sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); }
118inline float vdist(const float *a, const float *b) { return (sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]))); }
119inline double vdist(const double *a, const double *b) { return (sqrt((a[0] - b[0]) * (a[0] - b[0]) + (a[1] - b[1]) * (a[1] - b[1]) + (a[2] - b[2]) * (a[2] - b[2]))); }
120inline void vnormal(float *a) { vscale(a, 1 / vlength(a)); }
121inline void vnormal(double *a) { vscale(a, 1 / vlength(a)); }
122inline void vnormal(std::vector<double> a) { vscale(a, 1. / vlength(a)); }
123inline void vcopy(const float *a, float *b)
124{
125 b[0] = a[0];
126 b[1] = a[1];
127 b[2] = a[2];
128}
129inline void vcopy(const double *a, double *b)
130{
131 b[0] = a[0];
132 b[1] = a[1];
133 b[2] = a[2];
134}
135inline void vsub(const double *a, const float *b, float *c)
136{
137 c[0] = a[0] - b[0];
138 c[1] = a[1] - b[1];
139 c[2] = a[2] - b[2];
140}
141inline void vsub(const float *a, const float *b, float *c)
142{
143 c[0] = a[0] - b[0];
144 c[1] = a[1] - b[1];
145 c[2] = a[2] - b[2];
146}
147inline void vsub(const double *a, const double *b, double *c)
148{
149 c[0] = a[0] - b[0];
150 c[1] = a[1] - b[1];
151 c[2] = a[2] - b[2];
152}
153inline void vsub(const double *a, const std::vector<double> b, double *c)
154{
155 c[0] = a[0] - b[0];
156 c[1] = a[1] - b[1];
157 c[2] = a[2] - b[2];
158}
159inline void vsub(const std::vector<double> &a, const std::vector<double> &b, double *c)
160{
161 c[0] = a[0] - b[0];
162 c[1] = a[1] - b[1];
163 c[2] = a[2] - b[2];
164}
165inline void vadd(const float *a, const float *b, float *c)
166{
167 c[0] = a[0] + b[0];
168 c[1] = a[1] + b[1];
169 c[2] = a[2] + b[2];
170}
171inline void vadd(const double *a, const double *b, double *c)
172{
173 c[0] = a[0] + b[0];
174 c[1] = a[1] + b[1];
175 c[2] = a[2] + b[2];
176}
177inline void vzero(float *a) { a[0] = a[1] = a[2] = 0.f; }
178inline void vzero(double *a) { a[0] = a[1] = a[2] = 0.; }
179inline void qset(float *a, float x, float y, float z, float w)
180{
181 a[0] = x;
182 a[1] = y;
183 a[2] = z;
184 a[3] = w;
185}
186inline void qcopy(const float *a, float *b)
187{
188 b[0] = a[0];
189 b[1] = a[1];
190 b[2] = a[2];
191 b[3] = a[3];
192}
193inline void qcopy(const double *a, double *b)
194{
195 b[0] = a[0];
196 b[1] = a[1];
197 b[2] = a[2];
198 b[3] = a[3];
199}
200inline void qzero(float *a)
201{
202 a[0] = a[1] = a[2] = 0;
203 a[3] = 1;
204}
205inline void qzero(double *a)
206{
207 a[0] = a[1] = a[2] = 0.;
208 a[3] = 1.;
209}
210inline void qadd(const float *a, const float *b, float *c) { vadd(a, b, c), c[3] = a[3] + b[3]; }
211inline float qlength(const float q[4]) { return sqrt(q[0] * q[0] + q[1] * q[1] + q[2] * q[2] + q[3] * q[3]); }
212
213// Forward declarations for utility functions.
214// These should really go in glutil!
215
216int matrix4x4_inverse(const float *in, float *out);
217void matrix4x4_vec3_mult(const float m[16], const float a[4], float b[4]);
218void adjoint(const float *in, float *out);
219double det4x4(const float m[16]);
220double det2x2(double a, double b, double c, double d);
221double det3x3(double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3);
222
223}; // namespace VAPoR
#define COMMON_API
Definition: common.h:72
COMMON_API size_t nextPowerOf2(size_t n)
COMMON_API void squad(float quat1[4], float quat2[4], float s1[4], float s2[4], float t, float result[4])
COMMON_API void quat2View(float quat[4], float vdir[3], float upvec[3])
double det2x2(double a, double b, double c, double d)
float vdot(const float *a, const float *b)
COMMON_API void vtransform(const float *v, float *mat, float *vt)
COMMON_API void CalcRotation(float *q, float newX, float newY, float oldX, float oldY, float ballsize)
COMMON_API void getRotAngles(double *theta, double *phi, double *psi, const double *matrix)
void vcopy(const float *a, float *b)
COMMON_API void qmult(const float *q1, const float *q2, float *dest)
COMMON_API void rayBoxProject(std::vector< double > rayStart, std::vector< double > rayDir, const double boxExts[6], double results[2])
COMMON_API void getAxisRotation(int axis, double rotation, double *matrix)
void adjoint(const float *in, float *out)
COMMON_API void vtransform3(const float *v, float *mat, float *vt)
COMMON_API bool pointOnRight(double *pt1, double *pt2, const double *testPt)
COMMON_API void qnormal(float *q)
int matrix4x4_inverse(const float *in, float *out)
COMMON_API int minvert(const float *mat, float *result)
COMMON_API void vtransform4(const float *v, float *mat, float *vt)
COMMON_API void vreflect(const float *in, const float *mirror, float *out)
COMMON_API void qinv(const float q1[4], float q2[4])
void vset(float *a, const float x, const float y, const float z)
COMMON_API bool powerOf2(size_t n)
COMMON_API void makeModelviewMatrix(float *vpos, float *vdir, float *upvec, float *matrix)
void vadd(const float *a, const float *b, float *c)
COMMON_API void rotmatrix2q(float *m, float *q)
void vnormal(float *a)
COMMON_API void mmult33(const double *m1, const double *m2, double *result)
COMMON_API float ProjectToSphere(float r, float x, float y)
double det3x3(double a1, double a2, double a3, double b1, double b2, double b3, double c1, double c2, double c3)
COMMON_API void mcopy(float *m1, float *m2)
void qadd(const float *a, const float *b, float *c)
COMMON_API int rayBoxIntersect(const float rayStart[3], const float rayDir[3], const float boxExts[6], float results[2])
COMMON_API void computeGradientData(int dim[3], int numChan, unsigned char *volume, unsigned char *gradient)
COMMON_API void vcross(const float *v1, const float *v2, float *cross)
double det4x4(const float m[16])
float qlength(const float q[4])
void qcopy(const float *a, float *b)
COMMON_API void vtransform3t(const float *v, float *mat, float *vt)
float vdist(const float *a, const float *b)
COMMON_API void getRotationMatrix(double theta, double phi, double psi, double *matrix)
COMMON_API void views2ImagQuats(float vdir1[3], float upvec1[3], float vdir2[3], float upvec2[3], float q1[3], float q2[3])
COMMON_API void rvec2q(const float rvec[3], float radians, float q[4])
COMMON_API void qmatrix(const float *q, float *m)
COMMON_API void vmult(const float *v, float s, float *w)
COMMON_API void view2Quat(float vdir[3], float upvec[3], float q[4])
COMMON_API void slerp(float quat1[4], float quat2[4], float t, float result[4])
void qset(float *a, float x, float y, float z, float w)
void qzero(float *a)
COMMON_API void mmultt33(const double *m1Trans, const double *m2, double *result)
COMMON_API void qlog(float quat[4], float lquat[4])
COMMON_API void makeTransMatrix(float *transVec, float *matrix)
COMMON_API float ScalePoint(long pt, long origin, long size)
void vzero(float *a)
COMMON_API void qconj(float quat[4], float conj[4])
void matrix4x4_vec3_mult(const float m[16], const float a[4], float b[4])
COMMON_API void imagQuat2View(const float q[3], float vdir[3], float upvec[3])
COMMON_API float getScale(float *rotmatrix)
float vlength(const float *a)
COMMON_API void makeModelviewMatrixD(double *vpos, double *vdir, double *upvec, double *matrix)
COMMON_API void vscale(float *v, float s)
COMMON_API void mmult(float *m1, float *m2, float *prod)
COMMON_API void makeScaleMatrix(const double *scaleVec, double *matrix)
COMMON_API void vhalf(const float *v1, const float *v2, float *half)
void vsub(const double *a, const float *b, float *c)