From 2522e65f844d464dab7b5910d8183c3ad8ac922c Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 25 Mar 2018 12:38:28 -0600 Subject: Fixed typo in linmath --- redist/linmath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'redist') diff --git a/redist/linmath.h b/redist/linmath.h index cacb1c6..5d5bed2 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -49,7 +49,7 @@ typedef FLT LinmathQuat[4]; // This is the [wxyz] quaternion, in wxyz format. typedef FLT LinmathPoint3d[3]; -typedef FLT linmathVec3d[3]; +typedef FLT LinmathVec3d[3]; typedef struct LinmathPose { LinmathPoint3d Pos; -- cgit v1.2.3 From 005713cf133df85f208ff0cb2117a6855b85a5a7 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 25 Mar 2018 21:22:53 -0600 Subject: Added PoseToMatrix function for debugability --- redist/linmath.c | 339 ++++++++++++++++++++++++++----------------------------- redist/linmath.h | 69 ++++++----- 2 files changed, 189 insertions(+), 219 deletions(-) (limited to 'redist') diff --git a/redist/linmath.c b/redist/linmath.c index d005074..c57410f 100644 --- a/redist/linmath.c +++ b/redist/linmath.c @@ -1,130 +1,120 @@ -//Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT license. +// Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT license. -#include #include "linmath.h" #include +#include #include -void cross3d( FLT * out, const FLT * a, const FLT * b ) -{ - out[0] = a[1]*b[2] - a[2]*b[1]; - out[1] = a[2]*b[0] - a[0]*b[2]; - out[2] = a[0]*b[1] - a[1]*b[0]; +void cross3d(FLT *out, const FLT *a, const FLT *b) { + out[0] = a[1] * b[2] - a[2] * b[1]; + out[1] = a[2] * b[0] - a[0] * b[2]; + out[2] = a[0] * b[1] - a[1] * b[0]; } -void sub3d( FLT * out, const FLT * a, const FLT * b ) -{ +void sub3d(FLT *out, const FLT *a, const FLT *b) { out[0] = a[0] - b[0]; out[1] = a[1] - b[1]; out[2] = a[2] - b[2]; } -void add3d( FLT * out, const FLT * a, const FLT * b ) -{ +void add3d(FLT *out, const FLT *a, const FLT *b) { out[0] = a[0] + b[0]; out[1] = a[1] + b[1]; out[2] = a[2] + b[2]; } -void scale3d( FLT * out, const FLT * a, FLT scalar ) -{ +void scale3d(FLT *out, const FLT *a, FLT scalar) { out[0] = a[0] * scalar; out[1] = a[1] * scalar; out[2] = a[2] * scalar; } -void normalize3d( FLT * out, const FLT * in ) -{ +void normalize3d(FLT *out, const FLT *in) { FLT r = ((FLT)1.) / FLT_SQRT(in[0] * in[0] + in[1] * in[1] + in[2] * in[2]); out[0] = in[0] * r; out[1] = in[1] * r; out[2] = in[2] * r; } -FLT dot3d( const FLT * a, const FLT * b ) -{ - return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; -} - -int compare3d( const FLT * a, const FLT * b, FLT epsilon ) -{ - if( !a || !b ) return 0; - if( a[2] - b[2] > epsilon ) return 1; - if( b[2] - a[2] > epsilon ) return -1; - if( a[1] - b[1] > epsilon ) return 1; - if( b[1] - a[1] > epsilon ) return -1; - if( a[0] - b[0] > epsilon ) return 1; - if( b[0] - a[0] > epsilon ) return -1; +FLT dot3d(const FLT *a, const FLT *b) { return a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } + +int compare3d(const FLT *a, const FLT *b, FLT epsilon) { + if (!a || !b) + return 0; + if (a[2] - b[2] > epsilon) + return 1; + if (b[2] - a[2] > epsilon) + return -1; + if (a[1] - b[1] > epsilon) + return 1; + if (b[1] - a[1] > epsilon) + return -1; + if (a[0] - b[0] > epsilon) + return 1; + if (b[0] - a[0] > epsilon) + return -1; return 0; } -void copy3d( FLT * out, const FLT * in ) -{ +void copy3d(FLT *out, const FLT *in) { out[0] = in[0]; out[1] = in[1]; out[2] = in[2]; } -FLT magnitude3d(const FLT * a ) -{ - return FLT_SQRT(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); -} +FLT magnitude3d(const FLT *a) { return FLT_SQRT(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); } -FLT anglebetween3d( FLT * a, FLT * b ) -{ +FLT anglebetween3d(FLT *a, FLT *b) { FLT an[3]; FLT bn[3]; - normalize3d( an, a ); - normalize3d( bn, b ); + normalize3d(an, a); + normalize3d(bn, b); FLT dot = dot3d(an, bn); - if( dot < -0.9999999 ) return LINMATHPI; - if( dot > 0.9999999 ) return 0; + if (dot < -0.9999999) + return LINMATHPI; + if (dot > 0.9999999) + return 0; return FLT_ACOS(dot); } // algorithm found here: http://inside.mines.edu/fs_home/gmurray/ArbitraryAxisRotation/ -void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle) -{ +void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle) { // TODO: this really should be external. normalize3d(axis, axis); FLT s = FLT_SIN(angle); FLT c = FLT_COS(angle); - FLT u=axis[0]; - FLT v=axis[1]; - FLT w=axis[2]; + FLT u = axis[0]; + FLT v = axis[1]; + FLT w = axis[2]; - FLT x=invec3[0]; - FLT y=invec3[1]; - FLT z=invec3[2]; + FLT x = invec3[0]; + FLT y = invec3[1]; + FLT z = invec3[2]; - outvec3[0] = u*(u*x + v*y + w*z)*(1-c) + x*c + (-w*y + v*z)*s; - outvec3[1] = v*(u*x + v*y + w*z)*(1-c) + y*c + ( w*x - u*z)*s; - outvec3[2] = w*(u*x + v*y + w*z)*(1-c) + z*c + (-v*x + u*y)*s; + outvec3[0] = u * (u * x + v * y + w * z) * (1 - c) + x * c + (-w * y + v * z) * s; + outvec3[1] = v * (u * x + v * y + w * z) * (1 - c) + y * c + (w * x - u * z) * s; + outvec3[2] = w * (u * x + v * y + w * z) * (1 - c) + z * c + (-v * x + u * y) * s; } -void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest) -{ +void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest) { FLT v0[3]; FLT v1[3]; normalize3d(v0, src); normalize3d(v1, dest); - FLT d = dot3d(v0, v1);// v0.dotProduct(v1); + FLT d = dot3d(v0, v1); // v0.dotProduct(v1); // If dot == 1, vectors are the same // If dot == -1, vectors are opposite - if (FLT_FABS(d - 1) < DEFAULT_EPSILON) - { + if (FLT_FABS(d - 1) < DEFAULT_EPSILON) { axis[0] = 0; axis[1] = 1; axis[2] = 0; *angle = 0; return; - } - else if (FLT_FABS(d + 1) < DEFAULT_EPSILON) - { + } else if (FLT_FABS(d + 1) < DEFAULT_EPSILON) { axis[0] = 0; axis[1] = 1; axis[2] = 0; @@ -137,33 +127,28 @@ void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest) *angle = FLT_ACOS(d / (v0Len * v1Len)); - //cross3d(c, v0, v1); + // cross3d(c, v0, v1); cross3d(axis, v1, v0); - } - -void axisanglefromquat(FLT *angle, FLT *axis, FLT *q) -{ +void axisanglefromquat(FLT *angle, FLT *axis, FLT *q) { // this way might be fine, too. - //FLT dist = FLT_SQRT((q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3])); + // FLT dist = FLT_SQRT((q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3])); // //*angle = 2 * FLT_ATAN2(dist, q[0]); - //axis[0] = q[1] / dist; - //axis[1] = q[2] / dist; - //axis[2] = q[3] / dist; - + // axis[0] = q[1] / dist; + // axis[1] = q[2] / dist; + // axis[2] = q[3] / dist; // Good mathematical foundation for this algorithm found here: // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm - FLT tmp[4] = { q[0], q[1], q[2], q[3] }; + FLT tmp[4] = {q[0], q[1], q[2], q[3]}; quatnormalize(tmp, q); - if (FLT_FABS(q[0] - 1) < FLT_EPSILON) - { + if (FLT_FABS(q[0] - 1) < FLT_EPSILON) { // we have a degenerate case where we're rotating approx. 0 degrees *angle = 0; axis[0] = 1; @@ -180,11 +165,14 @@ void axisanglefromquat(FLT *angle, FLT *axis, FLT *q) } /////////////////////////////////////QUATERNIONS////////////////////////////////////////// -//Originally from Mercury (Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman) -//Under the mit/X11 license. +// Originally from Mercury (Copyright (C) 2009 by Joshua Allen, Charles Lohr, Adam Lowman) +// Under the mit/X11 license. void quatsetnone(LinmathQuat q) { - q[0] = 1; q[1] = 0; q[2] = 0; q[3] = 0; + q[0] = 1; + q[1] = 0; + q[2] = 0; + q[3] = 0; } void quatcopy(LinmathQuat qout, const LinmathQuat qin) { @@ -195,9 +183,9 @@ void quatcopy(LinmathQuat qout, const LinmathQuat qin) { } void quatfromeuler(LinmathQuat q, const LinmathEulerAngle euler) { - FLT X = euler[0]/2.0f; //roll - FLT Y = euler[1]/2.0f; //pitch - FLT Z = euler[2]/2.0f; //yaw + FLT X = euler[0] / 2.0f; // roll + FLT Y = euler[1] / 2.0f; // pitch + FLT Z = euler[2] / 2.0f; // yaw FLT cx = FLT_COS(X); FLT sx = FLT_SIN(X); @@ -206,17 +194,17 @@ void quatfromeuler(LinmathQuat q, const LinmathEulerAngle euler) { FLT cz = FLT_COS(Z); FLT sz = FLT_SIN(Z); - //Correct according to - //http://en.wikipedia.org/wiki/Conversion_between_MQuaternions_and_Euler_angles - q[0] = cx*cy*cz+sx*sy*sz;//q1 - q[1] = sx*cy*cz-cx*sy*sz;//q2 - q[2] = cx*sy*cz+sx*cy*sz;//q3 - q[3] = cx*cy*sz-sx*sy*cz;//q4 - quatnormalize( q, q ); + // Correct according to + // http://en.wikipedia.org/wiki/Conversion_between_MQuaternions_and_Euler_angles + q[0] = cx * cy * cz + sx * sy * sz; // q1 + q[1] = sx * cy * cz - cx * sy * sz; // q2 + q[2] = cx * sy * cz + sx * cy * sz; // q3 + q[3] = cx * cy * sz - sx * sy * cz; // q4 + quatnormalize(q, q); } void quattoeuler(LinmathEulerAngle euler, const LinmathQuat q) { - //According to http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles (Oct 26, 2009) + // According to http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles (Oct 26, 2009) euler[0] = FLT_ATAN2(2 * (q[0] * q[1] + q[2] * q[3]), 1 - 2 * (q[1] * q[1] + q[2] * q[2])); euler[1] = FLT_ASIN(2 * (q[0] * q[2] - q[3] * q[1])); euler[2] = FLT_ATAN2(2 * (q[0] * q[3] + q[1] * q[2]), 1 - 2 * (q[2] * q[2] + q[3] * q[3])); @@ -224,15 +212,15 @@ void quattoeuler(LinmathEulerAngle euler, const LinmathQuat q) { void quatfromaxisangle(LinmathQuat q, const FLT *axis, FLT radians) { FLT v[3]; - normalize3d( v, axis ); - + normalize3d(v, axis); + FLT sn = FLT_SIN(radians / 2.0f); q[0] = FLT_COS(radians / 2.0f); q[1] = sn * v[0]; q[2] = sn * v[1]; q[3] = sn * v[2]; - quatnormalize( q, q ); + quatnormalize(q, q); } FLT quatmagnitude(const LinmathQuat q) { @@ -240,19 +228,19 @@ FLT quatmagnitude(const LinmathQuat q) { } FLT quatinvsqmagnitude(const LinmathQuat q) { - return ((FLT)1.)/FLT_SQRT((q[0]*q[0])+(q[1]*q[1])+(q[2]*q[2])+(q[3]*q[3])); + return ((FLT)1.) / FLT_SQRT((q[0] * q[0]) + (q[1] * q[1]) + (q[2] * q[2]) + (q[3] * q[3])); } void quatnormalize(LinmathQuat qout, const LinmathQuat qin) { - FLT imag = quatinvsqmagnitude( qin ); - quatscale( qout, qin, imag ); + FLT imag = quatinvsqmagnitude(qin); + quatscale(qout, qin, imag); } void quattomatrix(FLT *matrix44, const LinmathQuat qin) { FLT q[4]; quatnormalize(q, qin); - //Reduced calulation for speed + // Reduced calulation for speed FLT xx = 2 * q[1] * q[1]; FLT xy = 2 * q[1] * q[2]; FLT xz = 2 * q[1] * q[3]; @@ -265,7 +253,7 @@ void quattomatrix(FLT *matrix44, const LinmathQuat qin) { FLT zz = 2 * q[3] * q[3]; FLT zw = 2 * q[3] * q[0]; - //opengl major + // opengl major matrix44[0] = 1 - yy - zz; matrix44[1] = xy - zw; matrix44[2] = xz + yw; @@ -320,16 +308,16 @@ void quatfrommatrix33(FLT *q, const FLT *m) { } void quatfrommatrix(LinmathQuat q, const FLT *matrix44) { - //Algorithm from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ + // Algorithm from http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/ FLT tr = matrix44[0] + matrix44[5] + matrix44[10]; if (tr > 0) { - FLT S = FLT_SQRT(tr+1.0) * 2.; // S=4*qw + FLT S = FLT_SQRT(tr + 1.0) * 2.; // S=4*qw q[0] = 0.25f * S; q[1] = (matrix44[9] - matrix44[6]) / S; q[2] = (matrix44[2] - matrix44[8]) / S; q[3] = (matrix44[4] - matrix44[1]) / S; - } else if ((matrix44[0] > matrix44[5])&&(matrix44[0] > matrix44[10])) { + } else if ((matrix44[0] > matrix44[5]) && (matrix44[0] > matrix44[10])) { FLT S = FLT_SQRT(1.0 + matrix44[0] - matrix44[5] - matrix44[10]) * 2.; // S=4*qx q[0] = (matrix44[9] - matrix44[6]) / S; q[1] = 0.25f * S; @@ -350,13 +338,12 @@ void quatfrommatrix(LinmathQuat q, const FLT *matrix44) { } } - // Algorithm from http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToMatrix/ void quattomatrix33(FLT *matrix33, const LinmathQuat qin) { FLT q[4]; quatnormalize(q, qin); - //Reduced calulation for speed + // Reduced calulation for speed FLT xx = 2 * q[1] * q[1]; FLT xy = 2 * q[1] * q[2]; FLT xz = 2 * q[1] * q[3]; @@ -369,8 +356,7 @@ void quattomatrix33(FLT *matrix33, const LinmathQuat qin) { FLT zz = 2 * q[3] * q[3]; FLT zw = 2 * q[3] * q[0]; - - //opengl major + // opengl major matrix33[0] = 1 - yy - zz; matrix33[1] = xy + zw; matrix33[2] = xz - yw; @@ -393,8 +379,8 @@ void quatgetconjugate(LinmathQuat qout, const LinmathQuat qin) { void quatgetreciprocal(LinmathQuat qout, const LinmathQuat qin) { FLT m = quatinvsqmagnitude(qin); - quatgetconjugate( qout, qin ); - quatscale( qout, qout, m ); + quatgetconjugate(qout, qin); + quatscale(qout, qout, m); } void quatsub(LinmathQuat qout, const FLT *a, const FLT *b) { @@ -412,11 +398,11 @@ void quatadd(LinmathQuat qout, const FLT *a, const FLT *b) { } void quatrotateabout(LinmathQuat qout, const LinmathQuat q1, const LinmathQuat q2) { - //NOTE: Does not normalize - qout[0] = (q1[0]*q2[0])-(q1[1]*q2[1])-(q1[2]*q2[2])-(q1[3]*q2[3]); - qout[1] = (q1[0]*q2[1])+(q1[1]*q2[0])+(q1[2]*q2[3])-(q1[3]*q2[2]); - qout[2] = (q1[0]*q2[2])-(q1[1]*q2[3])+(q1[2]*q2[0])+(q1[3]*q2[1]); - qout[3] = (q1[0]*q2[3])+(q1[1]*q2[2])-(q1[2]*q2[1])+(q1[3]*q2[0]); + // NOTE: Does not normalize + qout[0] = (q1[0] * q2[0]) - (q1[1] * q2[1]) - (q1[2] * q2[2]) - (q1[3] * q2[3]); + qout[1] = (q1[0] * q2[1]) + (q1[1] * q2[0]) + (q1[2] * q2[3]) - (q1[3] * q2[2]); + qout[2] = (q1[0] * q2[2]) - (q1[1] * q2[3]) + (q1[2] * q2[0]) + (q1[3] * q2[1]); + qout[3] = (q1[0] * q2[3]) + (q1[1] * q2[2]) - (q1[2] * q2[1]) + (q1[3] * q2[0]); } void quatscale(LinmathQuat qout, const LinmathQuat qin, FLT s) { @@ -427,96 +413,87 @@ void quatscale(LinmathQuat qout, const LinmathQuat qin, FLT s) { } FLT quatinnerproduct(const LinmathQuat qa, const LinmathQuat qb) { - return (qa[0]*qb[0])+(qa[1]*qb[1])+(qa[2]*qb[2])+(qa[3]*qb[3]); + return (qa[0] * qb[0]) + (qa[1] * qb[1]) + (qa[2] * qb[2]) + (qa[3] * qb[3]); } void quatouterproduct(FLT *outvec3, LinmathQuat qa, LinmathQuat qb) { - outvec3[0] = (qa[0]*qb[1])-(qa[1]*qb[0])-(qa[2]*qb[3])+(qa[3]*qb[2]); - outvec3[1] = (qa[0]*qb[2])+(qa[1]*qb[3])-(qa[2]*qb[0])-(qa[3]*qb[1]); - outvec3[2] = (qa[0]*qb[3])-(qa[1]*qb[2])+(qa[2]*qb[1])-(qa[3]*qb[0]); + outvec3[0] = (qa[0] * qb[1]) - (qa[1] * qb[0]) - (qa[2] * qb[3]) + (qa[3] * qb[2]); + outvec3[1] = (qa[0] * qb[2]) + (qa[1] * qb[3]) - (qa[2] * qb[0]) - (qa[3] * qb[1]); + outvec3[2] = (qa[0] * qb[3]) - (qa[1] * qb[2]) + (qa[2] * qb[1]) - (qa[3] * qb[0]); } void quatevenproduct(LinmathQuat q, LinmathQuat qa, LinmathQuat qb) { - q[0] = (qa[0]*qb[0])-(qa[1]*qb[1])-(qa[2]*qb[2])-(qa[3]*qb[3]); - q[1] = (qa[0]*qb[1])+(qa[1]*qb[0]); - q[2] = (qa[0]*qb[2])+(qa[2]*qb[0]); - q[3] = (qa[0]*qb[3])+(qa[3]*qb[0]); + q[0] = (qa[0] * qb[0]) - (qa[1] * qb[1]) - (qa[2] * qb[2]) - (qa[3] * qb[3]); + q[1] = (qa[0] * qb[1]) + (qa[1] * qb[0]); + q[2] = (qa[0] * qb[2]) + (qa[2] * qb[0]); + q[3] = (qa[0] * qb[3]) + (qa[3] * qb[0]); } void quatoddproduct(FLT *outvec3, LinmathQuat qa, LinmathQuat qb) { - outvec3[0] = (qa[2]*qb[3])-(qa[3]*qb[2]); - outvec3[1] = (qa[3]*qb[1])-(qa[1]*qb[3]); - outvec3[2] = (qa[1]*qb[2])-(qa[2]*qb[1]); + outvec3[0] = (qa[2] * qb[3]) - (qa[3] * qb[2]); + outvec3[1] = (qa[3] * qb[1]) - (qa[1] * qb[3]); + outvec3[2] = (qa[1] * qb[2]) - (qa[2] * qb[1]); } void quatslerp(LinmathQuat q, const LinmathQuat qa, const LinmathQuat qb, FLT t) { FLT an[4]; FLT bn[4]; - quatnormalize( an, qa ); - quatnormalize( bn, qb ); - FLT cosTheta = quatinnerproduct(an,bn); + quatnormalize(an, qa); + quatnormalize(bn, qb); + FLT cosTheta = quatinnerproduct(an, bn); FLT sinTheta; - //Careful: If cosTheta is exactly one, or even if it's infinitesimally over, it'll + // Careful: If cosTheta is exactly one, or even if it's infinitesimally over, it'll // cause SQRT to produce not a number, and screw everything up. - if ( 1 - (cosTheta*cosTheta) <= 0 ) + if (1 - (cosTheta * cosTheta) <= 0) sinTheta = 0; else - sinTheta = FLT_SQRT(1 - (cosTheta*cosTheta)); + sinTheta = FLT_SQRT(1 - (cosTheta * cosTheta)); - FLT Theta = FLT_ACOS(cosTheta); //Theta is half the angle between the 2 MQuaternions + FLT Theta = FLT_ACOS(cosTheta); // Theta is half the angle between the 2 MQuaternions if (FLT_FABS(Theta) < DEFAULT_EPSILON) - quatcopy( q, qa ); - else if (FLT_FABS(sinTheta) < DEFAULT_EPSILON) - { - quatadd( q, qa, qb ); - quatscale( q, q, 0.5 ); - } - else - { + quatcopy(q, qa); + else if (FLT_FABS(sinTheta) < DEFAULT_EPSILON) { + quatadd(q, qa, qb); + quatscale(q, q, 0.5); + } else { FLT aside[4]; FLT bside[4]; - quatscale( bside, qb, FLT_SIN(t * Theta)); - quatscale( aside, qa, FLT_SIN((1 - t)*Theta)); - quatadd( q, aside, bside ); - quatscale( q, q, ((FLT)1.)/sinTheta ); + quatscale(bside, qb, FLT_SIN(t * Theta)); + quatscale(aside, qa, FLT_SIN((1 - t) * Theta)); + quatadd(q, aside, bside); + quatscale(q, q, ((FLT)1.) / sinTheta); } } void quatrotatevector(FLT *vec3out, const LinmathQuat quat, const FLT *vec3in) { - //See: http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/ + // See: http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/ FLT tmp[3]; FLT tmp2[3]; - cross3d( tmp, &quat[1], vec3in ); + cross3d(tmp, &quat[1], vec3in); tmp[0] += vec3in[0] * quat[0]; tmp[1] += vec3in[1] * quat[0]; tmp[2] += vec3in[2] * quat[0]; - cross3d( tmp2, &quat[1], tmp ); + cross3d(tmp2, &quat[1], tmp); vec3out[0] = vec3in[0] + 2 * tmp2[0]; vec3out[1] = vec3in[1] + 2 * tmp2[1]; vec3out[2] = vec3in[2] + 2 * tmp2[2]; } - // Matrix Stuff -Matrix3x3 inverseM33(const Matrix3x3 mat) -{ +Matrix3x3 inverseM33(const Matrix3x3 mat) { Matrix3x3 newMat; - for (int a = 0; a < 3; a++) - { - for (int b = 0; b < 3; b++) - { + for (int a = 0; a < 3; a++) { + for (int b = 0; b < 3; b++) { newMat.val[a][b] = mat.val[a][b]; } } - for (int i = 0; i < 3; i++) - { - for (int j = i + 1; j < 3; j++) - { + for (int i = 0; i < 3; i++) { + for (int j = i + 1; j < 3; j++) { FLT tmp = newMat.val[i][j]; newMat.val[i][j] = newMat.val[j][i]; newMat.val[j][i] = tmp; @@ -526,8 +503,7 @@ Matrix3x3 inverseM33(const Matrix3x3 mat) return newMat; } -void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3]) -{ +void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3]) { FLT q[4]; quatfrom2vectors(q, v1, v2); @@ -535,8 +511,7 @@ void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3]) quattomatrix33(&(m->val[0][0]), q); } -void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot) -{ +void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot) { out[0] = rot.val[0][0] * in[0] + rot.val[1][0] * in[1] + rot.val[2][0] * in[2]; out[1] = rot.val[0][1] * in[0] + rot.val[1][1] * in[1] + rot.val[2][1] * in[2]; out[2] = rot.val[0][2] * in[0] + rot.val[1][2] * in[1] + rot.val[2][2] * in[2]; @@ -544,7 +519,6 @@ void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot) return; } - // This function based on code from Object-oriented Graphics Rendering Engine // Copyright(c) 2000 - 2012 Torus Knot Software Ltd // under MIT license @@ -557,8 +531,7 @@ If you call this with a dest vector that is close to the inverse of this vector, we will rotate 180 degrees around a generated axis if since in this case ANY axis of rotation is valid. */ -void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest) -{ +void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest) { // Based on Stan Melax's article in Game Programming Gems // Copy, since cannot modify local @@ -567,32 +540,26 @@ void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest) normalize3d(v0, src); normalize3d(v1, dest); - FLT d = dot3d(v0, v1);// v0.dotProduct(v1); + FLT d = dot3d(v0, v1); // v0.dotProduct(v1); // If dot == 1, vectors are the same - if (d >= 1.0f) - { + if (d >= 1.0f) { quatsetnone(q); return; } - if (d < (1e-6f - 1.0f)) - { + if (d < (1e-6f - 1.0f)) { // Generate an axis - FLT unitX[3] = { 1, 0, 0 }; - FLT unitY[3] = { 0, 1, 0 }; - + FLT unitX[3] = {1, 0, 0}; + FLT unitY[3] = {0, 1, 0}; + FLT axis[3]; - cross3d(axis, unitX, src); // pick an angle - if ((axis[0] < 1.0e-35f) && - (axis[1] < 1.0e-35f) && - (axis[2] < 1.0e-35f)) // pick another if colinear + cross3d(axis, unitX, src); // pick an angle + if ((axis[0] < 1.0e-35f) && (axis[1] < 1.0e-35f) && (axis[2] < 1.0e-35f)) // pick another if colinear { cross3d(axis, unitY, src); } normalize3d(axis, axis); quatfromaxisangle(q, axis, LINMATHPI); - } - else - { + } else { FLT s = FLT_SQRT((1 + d) * 2); FLT invs = 1 / s; @@ -608,13 +575,9 @@ void quatfrom2vectors(FLT *q, const FLT *src, const FLT *dest) } } -void matrix44copy(FLT * mout, const FLT * minm ) -{ - memcpy( mout, minm, sizeof( FLT ) * 16 ); -} +void matrix44copy(FLT *mout, const FLT *minm) { memcpy(mout, minm, sizeof(FLT) * 16); } -void matrix44transpose(FLT * mout, const FLT * minm ) -{ +void matrix44transpose(FLT *mout, const FLT *minm) { mout[0] = minm[0]; mout[1] = minm[4]; mout[2] = minm[8]; @@ -634,7 +597,6 @@ void matrix44transpose(FLT * mout, const FLT * minm ) mout[13] = minm[7]; mout[14] = minm[11]; mout[15] = minm[15]; - } void ApplyPoseToPoint(LinmathPoint3d pout, const LinmathPose *pose, const LinmathPoint3d pin) { @@ -654,5 +616,18 @@ void InvertPose(LinmathPose *poseout, const LinmathPose *pose) { scale3d(poseout->Pos, poseout->Pos, -1); } +void PoseToMatrix(FLT *matrix44, const LinmathPose *pose_in) { + quattomatrix(matrix44, pose_in->Rot); + + /* + matrix44[12] = pose_in->Pos[0]; + matrix44[13] = pose_in->Pos[1]; + matrix44[14] = pose_in->Pos[2]; + */ + matrix44[3] = pose_in->Pos[0]; + matrix44[7] = pose_in->Pos[1]; + matrix44[11] = pose_in->Pos[2]; +} + LinmathQuat LinmathQuat_Identity = {1.0}; LinmathPose LinmathPose_Identity = {.Rot = {1.0}}; diff --git a/redist/linmath.h b/redist/linmath.h index 5d5bed2..1a73a06 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -1,18 +1,18 @@ -//Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT/x11 license. +// Copyright 2013,2016 <>< C. N. Lohr. This file licensed under the terms of the MIT/x11 license. #ifndef _LINMATH_H #define _LINMATH_H -//Yes, I know it's kind of arbitrary. +// Yes, I know it's kind of arbitrary. #define DEFAULT_EPSILON 0.001 -//For printf +// For printf #define PFTHREE(x) (x)[0], (x)[1], (x)[2] #define PFFOUR(x) (x)[0], (x)[1], (x)[2], (x)[3] #define LINMATHPI ((FLT)3.141592653589) -//uncomment the following line to use double precision instead of single precision. +// uncomment the following line to use double precision instead of single precision. //#define USE_DOUBLE #ifdef USE_DOUBLE @@ -20,11 +20,11 @@ #define FLT double #define FLT_SQRT sqrt #define FLT_TAN tan -#define FLT_SIN sin -#define FLT_COS cos -#define FLT_ACOS acos -#define FLT_ASIN asin -#define FLT_ATAN2 atan2 +#define FLT_SIN sin +#define FLT_COS cos +#define FLT_ACOS acos +#define FLT_ASIN asin +#define FLT_ATAN2 atan2 #define FLT_FABS__ fabs #else @@ -32,17 +32,17 @@ #define FLT float #define FLT_SQRT sqrtf #define FLT_TAN tanf -#define FLT_SIN sinf -#define FLT_COS cosf -#define FLT_ACOS acosf -#define FLT_ASIN asinf -#define FLT_ATAN2 atan2f +#define FLT_SIN sinf +#define FLT_COS cosf +#define FLT_ACOS acosf +#define FLT_ASIN asinf +#define FLT_ATAN2 atan2f #define FLT_FABS__ fabsf #endif #ifdef TCC -#define FLT_FABS(x) (((x)<0)?(-(x)):(x)) +#define FLT_FABS(x) (((x) < 0) ? (-(x)) : (x)) #else #define FLT_FABS FLT_FABS__ #endif @@ -59,33 +59,33 @@ typedef struct LinmathPose { extern LinmathQuat LinmathQuat_Identity; extern LinmathPose LinmathPose_Identity; -//NOTE: Inputs may never be output with cross product. -void cross3d( FLT * out, const FLT * a, const FLT * b ); +// NOTE: Inputs may never be output with cross product. +void cross3d(FLT *out, const FLT *a, const FLT *b); -void sub3d( FLT * out, const FLT * a, const FLT * b ); +void sub3d(FLT *out, const FLT *a, const FLT *b); -void add3d( FLT * out, const FLT * a, const FLT * b ); +void add3d(FLT *out, const FLT *a, const FLT *b); -void scale3d( FLT * out, const FLT * a, FLT scalar ); +void scale3d(FLT *out, const FLT *a, FLT scalar); -void normalize3d( FLT * out, const FLT * in ); +void normalize3d(FLT *out, const FLT *in); -FLT dot3d( const FLT * a, const FLT * b ); +FLT dot3d(const FLT *a, const FLT *b); -//Returns 0 if equal. If either argument is null, 0 will ALWAYS be returned. -int compare3d( const FLT * a, const FLT * b, FLT epsilon ); +// Returns 0 if equal. If either argument is null, 0 will ALWAYS be returned. +int compare3d(const FLT *a, const FLT *b, FLT epsilon); -void copy3d( FLT * out, const FLT * in ); +void copy3d(FLT *out, const FLT *in); -FLT magnitude3d(const FLT * a ); +FLT magnitude3d(const FLT *a); -FLT anglebetween3d( FLT * a, FLT * b ); +FLT anglebetween3d(FLT *a, FLT *b); void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle); void angleaxisfrom2vect(FLT *angle, FLT *axis, FLT *src, FLT *dest); void axisanglefromquat(FLT *angle, FLT *axis, LinmathQuat quat); -//Quaternion things... +// Quaternion things... typedef FLT LinmathEulerAngle[3]; @@ -126,10 +126,10 @@ void ApplyPoseToPose(LinmathPose *pout, const LinmathPose *lhs_pose, const Linma // by definition. void InvertPose(LinmathPose *poseout, const LinmathPose *pose_in); +void PoseToMatrix(FLT *mat44, const LinmathPose *pose_in); // Matrix Stuff -typedef struct -{ +typedef struct { FLT val[3][3]; // row, column } Matrix3x3; @@ -137,12 +137,7 @@ void rotate_vec(FLT *out, const FLT *in, Matrix3x3 rot); void rotation_between_vecs_to_m3(Matrix3x3 *m, const FLT v1[3], const FLT v2[3]); Matrix3x3 inverseM33(const Matrix3x3 mat); - -void matrix44copy(FLT * mout, const FLT * minm ); -void matrix44transpose(FLT * mout, const FLT * minm ); - +void matrix44copy(FLT *mout, const FLT *minm); +void matrix44transpose(FLT *mout, const FLT *minm); #endif - - - -- cgit v1.2.3 From d4cef29d1322a2d1ecf8b672485e39e388066e5f Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Mon, 26 Mar 2018 12:44:11 -0600 Subject: os_generic is now a header only library --- redist/os_generic.c | 337 ----------------------------------------------- redist/os_generic.h | 369 +++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 293 insertions(+), 413 deletions(-) delete mode 100644 redist/os_generic.c (limited to 'redist') diff --git a/redist/os_generic.c b/redist/os_generic.c deleted file mode 100644 index 3191357..0000000 --- a/redist/os_generic.c +++ /dev/null @@ -1,337 +0,0 @@ -#include "os_generic.h" - -#ifdef USE_WINDOWS - -#include - -void OGSleep( int is ) -{ - Sleep( is*1000 ); -} - -void OGUSleep( int ius ) -{ - Sleep( ius/1000 ); -} - -double OGGetAbsoluteTime() -{ - static LARGE_INTEGER lpf; - LARGE_INTEGER li; - - if( !lpf.QuadPart ) - { - QueryPerformanceFrequency( &lpf ); - } - - QueryPerformanceCounter( &li ); - return (double)li.QuadPart / (double)lpf.QuadPart; -} - - -double OGGetFileTime( const char * file ) -{ - FILETIME ft; - - HANDLE h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); - - if( h==INVALID_HANDLE_VALUE ) - return -1; - - GetFileTime( h, 0, 0, &ft ); - - CloseHandle( h ); - - return ft.dwHighDateTime + ft.dwLowDateTime; -} - - -og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter ) -{ - return (og_thread_t)CreateThread( 0, 0, (LPTHREAD_START_ROUTINE)routine, parameter, 0, 0 ); -} - -void * OGJoinThread( og_thread_t ot ) -{ - WaitForSingleObject( ot, INFINITE ); - CloseHandle( ot ); - return 0; -} - -void OGCancelThread( og_thread_t ot ) -{ - CloseHandle( ot ); -} - -og_mutex_t OGCreateMutex() -{ - return CreateMutex( 0, 0, 0 ); -} - -void OGLockMutex( og_mutex_t om ) -{ - WaitForSingleObject(om, INFINITE); -} - -void OGUnlockMutex( og_mutex_t om ) -{ - ReleaseMutex(om); -} - -void OGDeleteMutex( og_mutex_t om ) -{ - CloseHandle( om ); -} - - - -og_sema_t OGCreateSema() -{ - HANDLE sem = CreateSemaphore( 0, 0, 32767, 0 ); - return (og_sema_t)sem; -} - -int OGGetSema( og_sema_t os ) -{ - typedef LONG NTSTATUS; - HANDLE sem = (HANDLE)os; - typedef NTSTATUS (NTAPI *_NtQuerySemaphore)( - HANDLE SemaphoreHandle, - DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */ - PVOID SemaphoreInformation, /* but this is to much to dump here */ - ULONG SemaphoreInformationLength, - PULONG ReturnLength OPTIONAL - ); - - typedef struct _SEMAPHORE_BASIC_INFORMATION { - ULONG CurrentCount; - ULONG MaximumCount; - } SEMAPHORE_BASIC_INFORMATION; - - - static _NtQuerySemaphore NtQuerySemaphore; - SEMAPHORE_BASIC_INFORMATION BasicInfo; - NTSTATUS Status; - - if( !NtQuerySemaphore ) - { - NtQuerySemaphore = (_NtQuerySemaphore)GetProcAddress (GetModuleHandle ("ntdll.dll"), "NtQuerySemaphore"); - if( !NtQuerySemaphore ) - { - return -1; - } - } - - - Status = NtQuerySemaphore (sem, 0 /*SemaphoreBasicInformation*/, - &BasicInfo, sizeof (SEMAPHORE_BASIC_INFORMATION), NULL); - - if (Status == ERROR_SUCCESS) - { - return BasicInfo.CurrentCount; - } - - return -2; -} - -void OGLockSema( og_sema_t os ) -{ - WaitForSingleObject( (HANDLE)os, INFINITE ); -} - -void OGUnlockSema( og_sema_t os ) -{ - ReleaseSemaphore( (HANDLE)os, 1, 0 ); -} - -void OGDeleteSema( og_sema_t os ) -{ - CloseHandle( os ); -} - -#else - -#ifndef _GNU_SOURCE -# define _GNU_SOURCE -#endif - -#include -#include -#include -#include -#include -#include - -pthread_mutex_t g_RawMutexStart = PTHREAD_MUTEX_INITIALIZER; - -void OGSleep( int is ) -{ - sleep( is ); -} - -void OGUSleep( int ius ) -{ - usleep( ius ); -} - -double OGGetAbsoluteTime() -{ - struct timeval tv; - gettimeofday( &tv, 0 ); - return ((double)tv.tv_usec)/1000000. + (tv.tv_sec); -} - -double OGGetFileTime( const char * file ) -{ - struct stat buff; - - int r = stat( file, &buff ); - - if( r < 0 ) - { - return -1; - } - - return buff.st_mtime; -} - - - -og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter ) -{ - pthread_t * ret = (pthread_t *)malloc( sizeof( pthread_t ) ); - int r = pthread_create( ret, 0, routine, parameter ); - if( r ) - { - free( ret ); - return 0; - } - return (og_thread_t)ret; -} - -void * OGJoinThread( og_thread_t ot ) -{ - void * retval; - if( !ot ) - { - return 0; - } - pthread_join( *(pthread_t*)ot, &retval ); - free( ot ); - return retval; -} - -void OGCancelThread( og_thread_t ot ) -{ - if( !ot ) - { - return; - } - pthread_cancel( *(pthread_t*)ot ); - free( ot ); -} - -og_mutex_t OGCreateMutex() -{ - pthread_mutexattr_t mta; - og_mutex_t r = malloc( sizeof( pthread_mutex_t ) ); - - pthread_mutexattr_init(&mta); - pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE); - - pthread_mutex_init( (pthread_mutex_t *)r, &mta ); - - return r; -} - -void OGLockMutex( og_mutex_t om ) -{ - if( !om ) - { - return; - } - pthread_mutex_lock( (pthread_mutex_t*)om ); -} - -void OGUnlockMutex( og_mutex_t om ) -{ - if( !om ) - { - return; - } - pthread_mutex_unlock( (pthread_mutex_t*)om ); -} - -void OGDeleteMutex( og_mutex_t om ) -{ - if( !om ) - { - return; - } - - pthread_mutex_destroy( (pthread_mutex_t*)om ); - free( om ); -} - - - - -og_sema_t OGCreateSema() -{ - sem_t * sem = (sem_t *)malloc( sizeof( sem_t ) ); - sem_init( sem, 0, 0 ); - return (og_sema_t)sem; -} - -int OGGetSema( og_sema_t os ) -{ - int valp; - sem_getvalue( (sem_t *)os, &valp ); - return valp; -} - - -void OGLockSema( og_sema_t os ) -{ - sem_wait( (sem_t *)os ); -} - -void OGUnlockSema( og_sema_t os ) -{ - sem_post( (sem_t *)os ); -} - -void OGDeleteSema( og_sema_t os ) -{ - sem_destroy( (sem_t *)os ); - free(os); -} - - - -#endif - -//Date Stamp: 2012-02-15 - -/* - Copyright (c) 2011-2012 <>< Charles Lohr - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of this file. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. -*/ - diff --git a/redist/os_generic.h b/redist/os_generic.h index 0924030..853440a 100644 --- a/redist/os_generic.h +++ b/redist/os_generic.h @@ -1,76 +1,293 @@ -#ifndef _OS_GENERIC_H -#define _OS_GENERIC_H - -#if defined( WIN32 ) || defined (WINDOWS) || defined( _WIN32) -#define USE_WINDOWS -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -//Things that shouldn't be macro'd -double OGGetAbsoluteTime(); -void OGSleep( int is ); -void OGUSleep( int ius ); -double OGGetFileTime( const char * file ); - -//Threads and Mutices -typedef void* og_thread_t; -typedef void* og_mutex_t; -typedef void* og_sema_t; - -og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter ); -void * OGJoinThread( og_thread_t ot ); -void OGCancelThread( og_thread_t ot ); - -//Always a recrusive mutex. -og_mutex_t OGCreateMutex(); -void OGLockMutex( og_mutex_t om ); -void OGUnlockMutex( og_mutex_t om ); -void OGDeleteMutex( og_mutex_t om ); - -//Always a semaphore -og_sema_t OGCreateSema(); //Create a semaphore, comes locked initially. NOTE: Max count is 32767 -void OGLockSema( og_sema_t os ); -int OGGetSema( og_sema_t os ); //if <0 there was a failure. -void OGUnlockSema( og_sema_t os ); -void OGDeleteSema( og_sema_t os ); - -#ifdef __cplusplus -}; -#endif - - - -#endif - - -//Date Stamp: 2012-02-15 - -/* - NOTE: Portions (namely the top section) are part of headers from other - sources. - - Copyright (c) 2011-2012 <>< Charles Lohr - - Permission is hereby granted, free of charge, to any person obtaining a - copy of this software and associated documentation files (the "Software"), - to deal in the Software without restriction, including without limitation - the rights to use, copy, modify, merge, publish, distribute, sublicense, - and/or sell copies of the Software, and to permit persons to whom the - Software is furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in - all copies or substantial portions of this file. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - IN THE SOFTWARE. -*/ - +#ifndef _OS_GENERIC_H +#define _OS_GENERIC_H +/* + "osgeneric" Generic, platform independent tool for the following operations: + + Delay functions: + void OGSleep( int is ); + void OGUSleep( int ius ); + + Getting current time (may be time from program start, boot, or epoc) + double OGGetAbsoluteTime(); + double OGGetFileTime( const char * file ); + + Thread functions + og_thread_t OGCreateThread( void * (routine)( void * ), void * parameter ); + void * OGJoinThread( og_thread_t ot ); + void OGCancelThread( og_thread_t ot ); + + Mutex functions, used for protecting data structures. + (recursive on platforms where available.) + og_mutex_t OGCreateMutex(); + void OGLockMutex( og_mutex_t om ); + void OGUnlockMutex( og_mutex_t om ); + void OGDeleteMutex( og_mutex_t om ); + +//Always a semaphore (not recursive) +// og_sema_t OGCreateSema(); //Create a semaphore, comes locked initially. NOTE: Max count is 32767 +// void OGLockSema( og_sema_t os ); +// int OGGetSema( og_sema_t os ); //if <0 there was a failure. +// void OGUnlockSema( og_sema_t os ); +// void OGDeleteSema( og_sema_t os ); + + + + Copyright (c) 2011-2012,2013,2016,2018 <>< Charles Lohr + This file may be licensed under the MIT/x11 license or the NewBSD license. + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the "Software"), + to deal in the Software without restriction, including without limitation + the rights to use, copy, modify, merge, publish, distribute, sublicense, + and/or sell copies of the Software, and to permit persons to whom the + Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of this file. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + IN THE SOFTWARE. + + Date Stamp: 2018-03-25: Switched to header-only format. +*/ + +#define OSG_INLINE static inline + +// Threads and Mutices +typedef void *og_thread_t; +typedef void *og_mutex_t; +typedef void *og_sema_t; + +#if defined(WIN32) || defined(WINDOWS) || defined(_WIN32) +#define USE_WINDOWS +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef USE_WINDOWS + +#include + +OSG_INLINE void OGSleep(int is) { Sleep(is * 1000); } + +OSG_INLINE void OGUSleep(int ius) { Sleep(ius / 1000); } + +OSG_INLINE double OGGetAbsoluteTime() { + static LARGE_INTEGER lpf; + LARGE_INTEGER li; + + if (!lpf.QuadPart) { + QueryPerformanceFrequency(&lpf); + } + + QueryPerformanceCounter(&li); + return (double)li.QuadPart / (double)lpf.QuadPart; +} + +OSG_INLINE double OGGetFileTime(const char *file) { + FILETIME ft; + + HANDLE h = CreateFile(file, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); + + if (h == INVALID_HANDLE_VALUE) + return -1; + + GetFileTime(h, 0, 0, &ft); + + CloseHandle(h); + + return ft.dwHighDateTime + ft.dwLowDateTime; +} + +OSG_INLINE og_thread_t OGCreateThread(void *(routine)(void *), void *parameter) { + return (og_thread_t)CreateThread(0, 0, (LPTHREAD_START_ROUTINE)routine, parameter, 0, 0); +} + +OSG_INLINE void *OGJoinThread(og_thread_t ot) { + WaitForSingleObject(ot, INFINITE); + CloseHandle(ot); + return 0; +} + +OSG_INLINE void OGCancelThread(og_thread_t ot) { CloseHandle(ot); } + +OSG_INLINE og_mutex_t OGCreateMutex() { return CreateMutex(0, 0, 0); } + +OSG_INLINE void OGLockMutex(og_mutex_t om) { WaitForSingleObject(om, INFINITE); } + +OSG_INLINE void OGUnlockMutex(og_mutex_t om) { ReleaseMutex(om); } + +OSG_INLINE void OGDeleteMutex(og_mutex_t om) { CloseHandle(om); } + +OSG_INLINE og_sema_t OGCreateSema() { + HANDLE sem = CreateSemaphore(0, 0, 32767, 0); + return (og_sema_t)sem; +} + +OSG_INLINE int OGGetSema(og_sema_t os) { + typedef LONG NTSTATUS; + HANDLE sem = (HANDLE)os; + typedef NTSTATUS(NTAPI * _NtQuerySemaphore)( + HANDLE SemaphoreHandle, DWORD SemaphoreInformationClass, /* Would be SEMAPHORE_INFORMATION_CLASS */ + PVOID SemaphoreInformation, /* but this is to much to dump here */ + ULONG SemaphoreInformationLength, PULONG ReturnLength OPTIONAL); + + typedef struct _SEMAPHORE_BASIC_INFORMATION { + ULONG CurrentCount; + ULONG MaximumCount; + } SEMAPHORE_BASIC_INFORMATION; + + static _NtQuerySemaphore NtQuerySemaphore; + SEMAPHORE_BASIC_INFORMATION BasicInfo; + NTSTATUS Status; + + if (!NtQuerySemaphore) { + NtQuerySemaphore = (_NtQuerySemaphore)GetProcAddress(GetModuleHandle("ntdll.dll"), "NtQuerySemaphore"); + if (!NtQuerySemaphore) { + return -1; + } + } + + Status = + NtQuerySemaphore(sem, 0 /*SemaphoreBasicInformation*/, &BasicInfo, sizeof(SEMAPHORE_BASIC_INFORMATION), NULL); + + if (Status == ERROR_SUCCESS) { + return BasicInfo.CurrentCount; + } + + return -2; +} + +OSG_INLINE void OGLockSema(og_sema_t os) { WaitForSingleObject((HANDLE)os, INFINITE); } + +OSG_INLINE void OGUnlockSema(og_sema_t os) { ReleaseSemaphore((HANDLE)os, 1, 0); } + +OSG_INLINE void OGDeleteSema(og_sema_t os) { CloseHandle(os); } + +#else + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include + +OSG_INLINE void OGSleep(int is) { sleep(is); } + +OSG_INLINE void OGUSleep(int ius) { usleep(ius); } + +OSG_INLINE double OGGetAbsoluteTime() { + struct timeval tv; + gettimeofday(&tv, 0); + return ((double)tv.tv_usec) / 1000000. + (tv.tv_sec); +} + +OSG_INLINE double OGGetFileTime(const char *file) { + struct stat buff; + + int r = stat(file, &buff); + + if (r < 0) { + return -1; + } + + return buff.st_mtime; +} + +OSG_INLINE og_thread_t OGCreateThread(void *(routine)(void *), void *parameter) { + pthread_t *ret = malloc(sizeof(pthread_t)); + int r = pthread_create(ret, 0, routine, parameter); + if (r) { + free(ret); + return 0; + } + return (og_thread_t)ret; +} + +static void *OGJoinThread(og_thread_t ot) { + void *retval; + if (!ot) { + return 0; + } + pthread_join(*(pthread_t *)ot, &retval); + free(ot); + return retval; +} + +OSG_INLINE void OGCancelThread(og_thread_t ot) { + if (!ot) { + return; + } + pthread_cancel(*(pthread_t *)ot); + free(ot); +} + +OSG_INLINE og_mutex_t OGCreateMutex() { + pthread_mutexattr_t mta; + og_mutex_t r = malloc(sizeof(pthread_mutex_t)); + + pthread_mutexattr_init(&mta); + pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE); + + pthread_mutex_init((pthread_mutex_t *)r, &mta); + + return r; +} + +OSG_INLINE void OGLockMutex(og_mutex_t om) { + if (!om) { + return; + } + pthread_mutex_lock((pthread_mutex_t *)om); +} + +OSG_INLINE void OGUnlockMutex(og_mutex_t om) { + if (!om) { + return; + } + pthread_mutex_unlock((pthread_mutex_t *)om); +} + +OSG_INLINE void OGDeleteMutex(og_mutex_t om) { + if (!om) { + return; + } + + pthread_mutex_destroy((pthread_mutex_t *)om); + free(om); +} + +OSG_INLINE og_sema_t OGCreateSema() { + sem_t *sem = malloc(sizeof(sem_t)); + sem_init(sem, 0, 0); + return (og_sema_t)sem; +} + +OSG_INLINE int OGGetSema(og_sema_t os) { + int valp; + sem_getvalue(os, &valp); + return valp; +} + +OSG_INLINE void OGLockSema(og_sema_t os) { sem_wait(os); } + +OSG_INLINE void OGUnlockSema(og_sema_t os) { sem_post(os); } + +OSG_INLINE void OGDeleteSema(og_sema_t os) { + sem_destroy(os); + free(os); +} + +#endif + +#endif -- cgit v1.2.3 From c6e57ed971214377f4340b3b4343495d5b24cd88 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Wed, 28 Mar 2018 00:10:23 -0600 Subject: Compiler warns unused on non inlined statics --- redist/os_generic.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'redist') diff --git a/redist/os_generic.h b/redist/os_generic.h index 853440a..0d1c7e7 100644 --- a/redist/os_generic.h +++ b/redist/os_generic.h @@ -214,7 +214,7 @@ OSG_INLINE og_thread_t OGCreateThread(void *(routine)(void *), void *parameter) return (og_thread_t)ret; } -static void *OGJoinThread(og_thread_t ot) { +OSG_INLINE void *OGJoinThread(og_thread_t ot) { void *retval; if (!ot) { return 0; -- cgit v1.2.3 From 91f0cab811e983da63ea49f6e24afae283138a1c Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Wed, 28 Mar 2018 20:36:05 -0600 Subject: Functional C# in windows --- redist/symbol_enumerator.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'redist') diff --git a/redist/symbol_enumerator.c b/redist/symbol_enumerator.c index fcb3727..58bbfaa 100644 --- a/redist/symbol_enumerator.c +++ b/redist/symbol_enumerator.c @@ -60,7 +60,7 @@ BOOL WINAPI SymCleanup( HANDLE hProcess ); -BOOL CALLBACK __cdecl mycb( +BOOL mycb( PSYMBOL_INFO pSymInfo, ULONG SymbolSize, PVOID UserContext @@ -71,10 +71,11 @@ BOOL CALLBACK __cdecl mycb( int EnumerateSymbols( SymEnumeratorCallback cb ) { - HANDLE proc = GetCurrentProcess(); + HANDLE proc = GetCurrentProcess(); if( !SymInitialize( proc, 0, 1 ) ) return -1; if( !SymEnumSymbols( proc, 0, "*!*", &mycb, (void*)cb ) ) { + fprintf(stderr, "SymEnumSymbols returned %d\n", GetLastError()); SymCleanup(proc); return -2; } -- cgit v1.2.3 From 08cc0afc797d2225cf23fbc785e6a28cc8667285 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Wed, 28 Mar 2018 21:52:00 -0600 Subject: Nuget packaged up dependencies --- redist/minimal_opencv.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 169 insertions(+), 3 deletions(-) (limited to 'redist') diff --git a/redist/minimal_opencv.c b/redist/minimal_opencv.c index 50eb7df..e35e31d 100644 --- a/redist/minimal_opencv.c +++ b/redist/minimal_opencv.c @@ -1,5 +1,3 @@ -//#include "/home/justin/source/CLAPACK/INCLUDE/f2c.h" -//#include "/home/justin/source/CLAPACK/INCLUDE/clapack.h" #include #include @@ -10,8 +8,176 @@ #include "string.h" #include +#include + //#define DEBUG_PRINT +#ifdef _WIN3211 +#include "cblas.h" + +int CBLAS_CallFromC; +int RowMajorStrg; +void cblas_xerbla(int info, const char *rout, const char *form, ...) +{ + extern int RowMajorStrg; + char empty[1] = ""; + va_list argptr; + + va_start(argptr, form); + + if (RowMajorStrg) + { + if (strstr(rout, "gemm") != 0) + { + if (info == 5) info = 4; + else if (info == 4) info = 5; + else if (info == 11) info = 9; + else if (info == 9) info = 11; + } + else if (strstr(rout, "symm") != 0 || strstr(rout, "hemm") != 0) + { + if (info == 5) info = 4; + else if (info == 4) info = 5; + } + else if (strstr(rout, "trmm") != 0 || strstr(rout, "trsm") != 0) + { + if (info == 7) info = 6; + else if (info == 6) info = 7; + } + else if (strstr(rout, "gemv") != 0) + { + if (info == 4) info = 3; + else if (info == 3) info = 4; + } + else if (strstr(rout, "gbmv") != 0) + { + if (info == 4) info = 3; + else if (info == 3) info = 4; + else if (info == 6) info = 5; + else if (info == 5) info = 6; + } + else if (strstr(rout, "ger") != 0) + { + if (info == 3) info = 2; + else if (info == 2) info = 3; + else if (info == 8) info = 6; + else if (info == 6) info = 8; + } + else if ((strstr(rout, "her2") != 0 || strstr(rout, "hpr2") != 0) + && strstr(rout, "her2k") == 0) + { + if (info == 8) info = 6; + else if (info == 6) info = 8; + } + } + if (info) + fprintf(stderr, "Parameter %d to routine %s was incorrect\n", info, rout); + vfprintf(stderr, form, argptr); + va_end(argptr); + if (info && !info) + F77_xerbla(empty, &info); /* Force link of our F77 error handler */ + exit(-1); +} +void cblas_dgemm(const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE TransA, + const CBLAS_TRANSPOSE TransB, const int M, const int N, + const int K, const double alpha, const double *A, + const int lda, const double *B, const int ldb, + const double beta, double *C, const int ldc) +{ + char TA, TB; +#ifdef F77_CHAR + F77_CHAR F77_TA, F77_TB; +#else +#define F77_TA &TA +#define F77_TB &TB +#endif + +#ifdef F77_INT + F77_INT F77_M = M, F77_N = N, F77_K = K, F77_lda = lda, F77_ldb = ldb; + F77_INT F77_ldc = ldc; +#else +#define F77_M M +#define F77_N N +#define F77_K K +#define F77_lda lda +#define F77_ldb ldb +#define F77_ldc ldc +#endif + + RowMajorStrg = 0; + CBLAS_CallFromC = 1; + + if (layout == CblasColMajor) + { + if (TransA == CblasTrans) TA = 'T'; + else if (TransA == CblasConjTrans) TA = 'C'; + else if (TransA == CblasNoTrans) TA = 'N'; + else + { + cblas_xerbla(2, "cblas_dgemm", "Illegal TransA setting, %d\n", TransA); + CBLAS_CallFromC = 0; + RowMajorStrg = 0; + return; + } + + if (TransB == CblasTrans) TB = 'T'; + else if (TransB == CblasConjTrans) TB = 'C'; + else if (TransB == CblasNoTrans) TB = 'N'; + else + { + cblas_xerbla(3, "cblas_dgemm", "Illegal TransB setting, %d\n", TransB); + CBLAS_CallFromC = 0; + RowMajorStrg = 0; + return; + } + +#ifdef F77_CHAR + F77_TA = C2F_CHAR(&TA); + F77_TB = C2F_CHAR(&TB); +#endif + + F77_dgemm(F77_TA, F77_TB, &F77_M, &F77_N, &F77_K, &alpha, A, + &F77_lda, B, &F77_ldb, &beta, C, &F77_ldc); + } + else if (layout == CblasRowMajor) + { + RowMajorStrg = 1; + if (TransA == CblasTrans) TB = 'T'; + else if (TransA == CblasConjTrans) TB = 'C'; + else if (TransA == CblasNoTrans) TB = 'N'; + else + { + cblas_xerbla(2, "cblas_dgemm", "Illegal TransA setting, %d\n", TransA); + CBLAS_CallFromC = 0; + RowMajorStrg = 0; + return; + } + if (TransB == CblasTrans) TA = 'T'; + else if (TransB == CblasConjTrans) TA = 'C'; + else if (TransB == CblasNoTrans) TA = 'N'; + else + { + cblas_xerbla(2, "cblas_dgemm", "Illegal TransB setting, %d\n", TransB); + CBLAS_CallFromC = 0; + RowMajorStrg = 0; + return; + } +#ifdef F77_CHAR + F77_TA = C2F_CHAR(&TA); + F77_TB = C2F_CHAR(&TB); +#endif + + F77_dgemm(F77_TA, F77_TB, &F77_N, &F77_M, &F77_K, &alpha, B, + &F77_ldb, A, &F77_lda, &beta, C, &F77_ldc); + } + else cblas_xerbla(1, "cblas_dgemm", "Illegal layout setting, %d\n", layout); + CBLAS_CallFromC = 0; + RowMajorStrg = 0; + return; +} +#endif + + int cvRound(float f) { return roundf(f); } #define CV_Error(code, msg) assert(0 && msg); // cv::error( code, msg, CV_Func, __FILE__, __LINE__ ) @@ -27,7 +193,7 @@ void cvCopyTo(const CvMat *srcarr, CvMat *dstarr) { void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta, CvMat *dst, int tABC) { lapack_int rows1 = src1->rows; lapack_int cols1 = src1->cols; - + lapack_int rows2 = src2->rows; lapack_int cols2 = src2->cols; -- cgit v1.2.3 From d366c1dc70487246e1a1948e33d8a998f54a82ae Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Thu, 29 Mar 2018 10:18:56 -0600 Subject: Removed unused code --- redist/minimal_opencv.c | 170 +----------------------------------------------- 1 file changed, 1 insertion(+), 169 deletions(-) (limited to 'redist') diff --git a/redist/minimal_opencv.c b/redist/minimal_opencv.c index e35e31d..48bd85e 100644 --- a/redist/minimal_opencv.c +++ b/redist/minimal_opencv.c @@ -8,175 +8,7 @@ #include "string.h" #include -#include - -//#define DEBUG_PRINT - -#ifdef _WIN3211 -#include "cblas.h" - -int CBLAS_CallFromC; -int RowMajorStrg; -void cblas_xerbla(int info, const char *rout, const char *form, ...) -{ - extern int RowMajorStrg; - char empty[1] = ""; - va_list argptr; - - va_start(argptr, form); - - if (RowMajorStrg) - { - if (strstr(rout, "gemm") != 0) - { - if (info == 5) info = 4; - else if (info == 4) info = 5; - else if (info == 11) info = 9; - else if (info == 9) info = 11; - } - else if (strstr(rout, "symm") != 0 || strstr(rout, "hemm") != 0) - { - if (info == 5) info = 4; - else if (info == 4) info = 5; - } - else if (strstr(rout, "trmm") != 0 || strstr(rout, "trsm") != 0) - { - if (info == 7) info = 6; - else if (info == 6) info = 7; - } - else if (strstr(rout, "gemv") != 0) - { - if (info == 4) info = 3; - else if (info == 3) info = 4; - } - else if (strstr(rout, "gbmv") != 0) - { - if (info == 4) info = 3; - else if (info == 3) info = 4; - else if (info == 6) info = 5; - else if (info == 5) info = 6; - } - else if (strstr(rout, "ger") != 0) - { - if (info == 3) info = 2; - else if (info == 2) info = 3; - else if (info == 8) info = 6; - else if (info == 6) info = 8; - } - else if ((strstr(rout, "her2") != 0 || strstr(rout, "hpr2") != 0) - && strstr(rout, "her2k") == 0) - { - if (info == 8) info = 6; - else if (info == 6) info = 8; - } - } - if (info) - fprintf(stderr, "Parameter %d to routine %s was incorrect\n", info, rout); - vfprintf(stderr, form, argptr); - va_end(argptr); - if (info && !info) - F77_xerbla(empty, &info); /* Force link of our F77 error handler */ - exit(-1); -} -void cblas_dgemm(const CBLAS_LAYOUT layout, const CBLAS_TRANSPOSE TransA, - const CBLAS_TRANSPOSE TransB, const int M, const int N, - const int K, const double alpha, const double *A, - const int lda, const double *B, const int ldb, - const double beta, double *C, const int ldc) -{ - char TA, TB; -#ifdef F77_CHAR - F77_CHAR F77_TA, F77_TB; -#else -#define F77_TA &TA -#define F77_TB &TB -#endif - -#ifdef F77_INT - F77_INT F77_M = M, F77_N = N, F77_K = K, F77_lda = lda, F77_ldb = ldb; - F77_INT F77_ldc = ldc; -#else -#define F77_M M -#define F77_N N -#define F77_K K -#define F77_lda lda -#define F77_ldb ldb -#define F77_ldc ldc -#endif - - RowMajorStrg = 0; - CBLAS_CallFromC = 1; - - if (layout == CblasColMajor) - { - if (TransA == CblasTrans) TA = 'T'; - else if (TransA == CblasConjTrans) TA = 'C'; - else if (TransA == CblasNoTrans) TA = 'N'; - else - { - cblas_xerbla(2, "cblas_dgemm", "Illegal TransA setting, %d\n", TransA); - CBLAS_CallFromC = 0; - RowMajorStrg = 0; - return; - } - - if (TransB == CblasTrans) TB = 'T'; - else if (TransB == CblasConjTrans) TB = 'C'; - else if (TransB == CblasNoTrans) TB = 'N'; - else - { - cblas_xerbla(3, "cblas_dgemm", "Illegal TransB setting, %d\n", TransB); - CBLAS_CallFromC = 0; - RowMajorStrg = 0; - return; - } - -#ifdef F77_CHAR - F77_TA = C2F_CHAR(&TA); - F77_TB = C2F_CHAR(&TB); -#endif - - F77_dgemm(F77_TA, F77_TB, &F77_M, &F77_N, &F77_K, &alpha, A, - &F77_lda, B, &F77_ldb, &beta, C, &F77_ldc); - } - else if (layout == CblasRowMajor) - { - RowMajorStrg = 1; - if (TransA == CblasTrans) TB = 'T'; - else if (TransA == CblasConjTrans) TB = 'C'; - else if (TransA == CblasNoTrans) TB = 'N'; - else - { - cblas_xerbla(2, "cblas_dgemm", "Illegal TransA setting, %d\n", TransA); - CBLAS_CallFromC = 0; - RowMajorStrg = 0; - return; - } - if (TransB == CblasTrans) TA = 'T'; - else if (TransB == CblasConjTrans) TA = 'C'; - else if (TransB == CblasNoTrans) TA = 'N'; - else - { - cblas_xerbla(2, "cblas_dgemm", "Illegal TransB setting, %d\n", TransB); - CBLAS_CallFromC = 0; - RowMajorStrg = 0; - return; - } -#ifdef F77_CHAR - F77_TA = C2F_CHAR(&TA); - F77_TB = C2F_CHAR(&TB); -#endif - - F77_dgemm(F77_TA, F77_TB, &F77_N, &F77_M, &F77_K, &alpha, B, - &F77_ldb, A, &F77_lda, &beta, C, &F77_ldc); - } - else cblas_xerbla(1, "cblas_dgemm", "Illegal layout setting, %d\n", layout); - CBLAS_CallFromC = 0; - RowMajorStrg = 0; - return; -} -#endif - +#include int cvRound(float f) { return roundf(f); } #define CV_Error(code, msg) assert(0 && msg); // cv::error( code, msg, CV_Func, __FILE__, __LINE__ ) -- cgit v1.2.3 From ba4b64e3c7df19356ff867533b47257932df691f Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Thu, 29 Mar 2018 16:10:34 -0600 Subject: Made linmath sane for C++ inclusion --- redist/linmath.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'redist') diff --git a/redist/linmath.h b/redist/linmath.h index 1a73a06..71fd9b0 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -3,6 +3,10 @@ #ifndef _LINMATH_H #define _LINMATH_H +#ifdef __cplusplus +extern "C" { +#endif + // Yes, I know it's kind of arbitrary. #define DEFAULT_EPSILON 0.001 @@ -140,4 +144,8 @@ Matrix3x3 inverseM33(const Matrix3x3 mat); void matrix44copy(FLT *mout, const FLT *minm); void matrix44transpose(FLT *mout, const FLT *minm); +#ifdef __cplusplus +} +#endif + #endif -- cgit v1.2.3 From 030ec10de98b40750ed480499d84cf8b7bcd766c Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Fri, 30 Mar 2018 12:00:07 -0600 Subject: Don't export minimal opencv symbols --- redist/minimal_opencv.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) (limited to 'redist') diff --git a/redist/minimal_opencv.c b/redist/minimal_opencv.c index 48bd85e..371d6f8 100644 --- a/redist/minimal_opencv.c +++ b/redist/minimal_opencv.c @@ -10,7 +10,14 @@ #include #include -int cvRound(float f) { return roundf(f); } + +#ifdef _WIN32 +#define SURVIVE_LOCAL_ONLY +#else +#define SURVIVE_LOCAL_ONLY __attribute__ ((visibility ("hidden"))) +#endif + +SURVIVE_LOCAL_ONLY int cvRound(float f) { return roundf(f); } #define CV_Error(code, msg) assert(0 && msg); // cv::error( code, msg, CV_Func, __FILE__, __LINE__ ) const int DECOMP_SVD = 1; @@ -18,11 +25,11 @@ const int DECOMP_LU = 2; void print_mat(const CvMat *M); -void cvCopyTo(const CvMat *srcarr, CvMat *dstarr) { +SURVIVE_LOCAL_ONLY void cvCopyTo(const CvMat *srcarr, CvMat *dstarr) { memcpy(dstarr->data.db, srcarr->data.db, sizeof(double) * dstarr->rows * dstarr->cols); } -void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta, CvMat *dst, int tABC) { +SURVIVE_LOCAL_ONLY void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta, CvMat *dst, int tABC) { lapack_int rows1 = src1->rows; lapack_int cols1 = src1->cols; @@ -46,7 +53,7 @@ void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src lda, src2->data.db, ldb, beta, dst->data.db, dst->cols); } -void cvMulTransposed(const CvMat *src, CvMat *dst, int order, const CvMat *delta, double scale) { +SURVIVE_LOCAL_ONLY void cvMulTransposed(const CvMat *src, CvMat *dst, int order, const CvMat *delta, double scale) { lapack_int rows = src->rows; lapack_int cols = src->cols; @@ -65,14 +72,14 @@ void cvMulTransposed(const CvMat *src, CvMat *dst, int order, const CvMat *delta scale, src->data.db, cols, src->data.db, cols, beta, dst->data.db, dstCols); } -void *cvAlloc(size_t size) { return malloc(size); } +SURVIVE_LOCAL_ONLY void *cvAlloc(size_t size) { return malloc(size); } -static void icvCheckHuge(CvMat *arr) { +SURVIVE_LOCAL_ONLY static void icvCheckHuge(CvMat *arr) { if ((int64_t)arr->step * arr->rows > INT_MAX) arr->type &= ~CV_MAT_CONT_FLAG; } -CvMat *cvCreateMatHeader(int rows, int cols, int type) { +SURVIVE_LOCAL_ONLY CvMat *cvCreateMatHeader(int rows, int cols, int type) { type = CV_MAT_TYPE(type); assert(!(rows < 0 || cols < 0)); @@ -104,17 +111,17 @@ CvMat *cvCreateMatHeader(int rows, int cols, int type) { #define CV_DbgAssert assert -static inline void *cvAlignPtr(const void *ptr, int align) { +SURVIVE_LOCAL_ONLY static inline void *cvAlignPtr(const void *ptr, int align) { CV_DbgAssert((align & (align - 1)) == 0); return (void *)(((size_t)ptr + align - 1) & ~(size_t)(align - 1)); } -static inline int cvAlign(int size, int align) { +SURVIVE_LOCAL_ONLY static inline int cvAlign(int size, int align) { CV_DbgAssert((align & (align - 1)) == 0 && size < INT_MAX); return (size + align - 1) & -align; } -void cvCreateData(CvMat *arr) { +SURVIVE_LOCAL_ONLY void cvCreateData(CvMat *arr) { if (CV_IS_MAT_HDR_Z(arr)) { size_t step, total_size; CvMat *mat = (CvMat *)arr; @@ -142,14 +149,14 @@ void cvCreateData(CvMat *arr) { CV_Error(CV_StsBadArg, "unrecognized or unsupported array type"); } -CvMat *cvCreateMat(int height, int width, int type) { +SURVIVE_LOCAL_ONLY CvMat *cvCreateMat(int height, int width, int type) { CvMat *arr = cvCreateMatHeader(height, width, type); cvCreateData(arr); return arr; } -double cvInvert(const CvMat *srcarr, CvMat *dstarr, int method) { +SURVIVE_LOCAL_ONLY double cvInvert(const CvMat *srcarr, CvMat *dstarr, int method) { lapack_int inf; lapack_int rows = srcarr->rows; lapack_int cols = srcarr->cols; @@ -204,13 +211,13 @@ double cvInvert(const CvMat *srcarr, CvMat *dstarr, int method) { return 0; } -CvMat *cvCloneMat(const CvMat *mat) { +SURVIVE_LOCAL_ONLY CvMat *cvCloneMat(const CvMat *mat) { CvMat *rtn = cvCreateMat(mat->rows, mat->cols, mat->type); cvCopyTo(mat, rtn); return rtn; } -int cvSolve(const CvMat *Aarr, const CvMat *xarr, CvMat *Barr, int method) { +SURVIVE_LOCAL_ONLY int cvSolve(const CvMat *Aarr, const CvMat *xarr, CvMat *Barr, int method) { lapack_int inf; lapack_int arows = Aarr->rows; lapack_int acols = Aarr->cols; @@ -286,7 +293,7 @@ int cvSolve(const CvMat *Aarr, const CvMat *xarr, CvMat *Barr, int method) { return 0; } -void cvTranspose(const CvMat *M, CvMat *dst) { +SURVIVE_LOCAL_ONLY void cvTranspose(const CvMat *M, CvMat *dst) { bool inPlace = M == dst || M->data.db == dst->data.db; double *src = M->data.db; @@ -309,7 +316,7 @@ void cvTranspose(const CvMat *M, CvMat *dst) { } } -void cvSVD(CvMat *aarr, CvMat *warr, CvMat *uarr, CvMat *varr, int flags) { +SURVIVE_LOCAL_ONLY void cvSVD(CvMat *aarr, CvMat *warr, CvMat *uarr, CvMat *varr, int flags) { char jobu = 'A'; char jobvt = 'A'; @@ -347,13 +354,13 @@ void cvSVD(CvMat *aarr, CvMat *warr, CvMat *uarr, CvMat *varr, int flags) { } } -void cvSetZero(CvMat *arr) { +SURVIVE_LOCAL_ONLY void cvSetZero(CvMat *arr) { for (int i = 0; i < arr->rows; i++) for (int j = 0; j < arr->cols; j++) arr->data.db[i * arr->cols + j] = 0; } -void cvReleaseMat(CvMat **mat) { +SURVIVE_LOCAL_ONLY void cvReleaseMat(CvMat **mat) { assert(*(*mat)->refcount == 1); free((*mat)->refcount); free(*mat); -- cgit v1.2.3 From 2a5a0bde0fa45f86b1fcfbfd50bb779f25337573 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 1 Apr 2018 07:28:22 -0600 Subject: Fixed warnings about inline static functions being exported --- redist/minimal_opencv.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'redist') diff --git a/redist/minimal_opencv.c b/redist/minimal_opencv.c index 371d6f8..988dd0f 100644 --- a/redist/minimal_opencv.c +++ b/redist/minimal_opencv.c @@ -10,11 +10,10 @@ #include #include - #ifdef _WIN32 #define SURVIVE_LOCAL_ONLY #else -#define SURVIVE_LOCAL_ONLY __attribute__ ((visibility ("hidden"))) +#define SURVIVE_LOCAL_ONLY __attribute__((visibility("hidden"))) #endif SURVIVE_LOCAL_ONLY int cvRound(float f) { return roundf(f); } @@ -29,10 +28,11 @@ SURVIVE_LOCAL_ONLY void cvCopyTo(const CvMat *srcarr, CvMat *dstarr) { memcpy(dstarr->data.db, srcarr->data.db, sizeof(double) * dstarr->rows * dstarr->cols); } -SURVIVE_LOCAL_ONLY void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta, CvMat *dst, int tABC) { +SURVIVE_LOCAL_ONLY void cvGEMM(const CvMat *src1, const CvMat *src2, double alpha, const CvMat *src3, double beta, + CvMat *dst, int tABC) { lapack_int rows1 = src1->rows; lapack_int cols1 = src1->cols; - + lapack_int rows2 = src2->rows; lapack_int cols2 = src2->cols; @@ -74,7 +74,7 @@ SURVIVE_LOCAL_ONLY void cvMulTransposed(const CvMat *src, CvMat *dst, int order, SURVIVE_LOCAL_ONLY void *cvAlloc(size_t size) { return malloc(size); } -SURVIVE_LOCAL_ONLY static void icvCheckHuge(CvMat *arr) { +static void icvCheckHuge(CvMat *arr) { if ((int64_t)arr->step * arr->rows > INT_MAX) arr->type &= ~CV_MAT_CONT_FLAG; } @@ -111,12 +111,12 @@ SURVIVE_LOCAL_ONLY CvMat *cvCreateMatHeader(int rows, int cols, int type) { #define CV_DbgAssert assert -SURVIVE_LOCAL_ONLY static inline void *cvAlignPtr(const void *ptr, int align) { +static inline void *cvAlignPtr(const void *ptr, int align) { CV_DbgAssert((align & (align - 1)) == 0); return (void *)(((size_t)ptr + align - 1) & ~(size_t)(align - 1)); } -SURVIVE_LOCAL_ONLY static inline int cvAlign(int size, int align) { +static inline int cvAlign(int size, int align) { CV_DbgAssert((align & (align - 1)) == 0 && size < INT_MAX); return (size + align - 1) & -align; } -- cgit v1.2.3 From 558429f4d01462edb606fe51d592e9f9e3889425 Mon Sep 17 00:00:00 2001 From: Justin Berger Date: Sun, 1 Apr 2018 07:29:19 -0600 Subject: Added distance function to linmath --- redist/linmath.c | 5 +++++ redist/linmath.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'redist') diff --git a/redist/linmath.c b/redist/linmath.c index c57410f..01ae2b0 100644 --- a/redist/linmath.c +++ b/redist/linmath.c @@ -63,6 +63,11 @@ void copy3d(FLT *out, const FLT *in) { } FLT magnitude3d(const FLT *a) { return FLT_SQRT(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); } +FLT dist3d(const FLT *a, const FLT *b) { + LinmathPoint3d tmp; + sub3d(tmp, a, b); + return magnitude3d(tmp); +} FLT anglebetween3d(FLT *a, FLT *b) { FLT an[3]; diff --git a/redist/linmath.h b/redist/linmath.h index 71fd9b0..76e1322 100644 --- a/redist/linmath.h +++ b/redist/linmath.h @@ -6,7 +6,7 @@ #ifdef __cplusplus extern "C" { #endif - + // Yes, I know it's kind of arbitrary. #define DEFAULT_EPSILON 0.001 @@ -82,7 +82,7 @@ int compare3d(const FLT *a, const FLT *b, FLT epsilon); void copy3d(FLT *out, const FLT *in); FLT magnitude3d(const FLT *a); - +FLT dist3d(const FLT *a, const FLT *b); FLT anglebetween3d(FLT *a, FLT *b); void rotatearoundaxis(FLT *outvec3, FLT *invec3, FLT *axis, FLT angle); -- cgit v1.2.3