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.3.1 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.3.1 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 --- Makefile | 18 +-- redist/os_generic.c | 337 ----------------------------------------------- redist/os_generic.h | 369 +++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 302 insertions(+), 422 deletions(-) delete mode 100644 redist/os_generic.c (limited to 'redist') diff --git a/Makefile b/Makefile index ac04d60..f95ca61 100644 --- a/Makefile +++ b/Makefile @@ -35,7 +35,7 @@ endif SBA:=redist/sba/sba_chkjac.o redist/sba/sba_crsm.o redist/sba/sba_lapack.o redist/sba/sba_levmar.o redist/sba/sba_levmar_wrap.o POSERS:=src/poser_dummy.o src/poser_daveortho.o src/poser_charlesslow.o src/poser_octavioradii.o src/poser_turveytori.o src/poser_epnp.o src/poser_sba.o -REDISTS:=redist/json_helpers.o redist/linmath.o redist/jsmn.o redist/os_generic.o redist/minimal_opencv.o +REDISTS:=redist/json_helpers.o redist/linmath.o redist/jsmn.o redist/minimal_opencv.o ifeq ($(UNAME), Darwin) REDISTS:=$(REDISTS) redist/hid-osx.c endif @@ -66,23 +66,23 @@ LIBSURVIVE_C:=$(LIBSURVIVE_O:.o=.c) testCocoa : testCocoa.c $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) -test : test.c ./lib/libsurvive.so redist/os_generic.o +test : test.c ./lib/libsurvive.so $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) -simple_pose_test : simple_pose_test.c ./lib/libsurvive.so redist/os_generic.o $(DRAWFUNCTIONS) +simple_pose_test : simple_pose_test.c ./lib/libsurvive.so $(DRAWFUNCTIONS) $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) -data_recorder : data_recorder.c ./lib/libsurvive.so redist/os_generic.c +data_recorder : data_recorder.c ./lib/libsurvive.so $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) -calibrate : calibrate.c ./lib/libsurvive.so redist/os_generic.c $(DRAWFUNCTIONS) +calibrate : calibrate.c ./lib/libsurvive.so $(DRAWFUNCTIONS) $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) -calibrate_client : calibrate_client.c ./lib/libsurvive.so redist/os_generic.c $(GRAPHICS_LOFI) +calibrate_client : calibrate_client.c ./lib/libsurvive.so $(GRAPHICS_LOFI) $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS) ## Still not working!!! Don't use. -static_calibrate : calibrate.c redist/os_generic.c $(DRAWFUNCTIONS) $(LIBSURVIVE_C) +static_calibrate : calibrate.c $(DRAWFUNCTIONS) $(LIBSURVIVE_C) tcc -o $@ $^ $(CFLAGS) $(LDFLAGS) -DTCC ./redist/dclhelpers_debuggable.c : ./redist/dclhelpers.c ./redist/dclhelpers.h ./redist/dclapack.h @@ -91,7 +91,7 @@ static_calibrate : calibrate.c redist/os_generic.c $(DRAWFUNCTIONS) $(LIBSURVIVE sed -i 's/#/\/\/#/g' ./redist/dclhelpers_debuggable.c -test_dcl: ./redist/test_dcl.c ./redist/dclhelpers.c ./redist/dclhelpers.h ./redist/dclapack.h redist/os_generic.c ./redist/minimal_opencv.c ./src/epnp/epnp.c +test_dcl: ./redist/test_dcl.c ./redist/dclhelpers.c ./redist/dclhelpers.h ./redist/dclapack.h ./redist/minimal_opencv.c ./src/epnp/epnp.c $(CC) -o $@ $^ $(LDFLAGS) $(CFLAGS_RELEASE) -DFLT=double test_dcl_debug: ./redist/test_dcl.c ./redist/dclhelpers_debuggable.c ./redist/dclhelpers.h ./redist/dclapack.h redist/os_generic.c @@ -114,7 +114,7 @@ lib/libsurvive.so : $(LIBSURVIVE_O) calibrate_tcc : $(LIBSURVIVE_C) - tcc -DRUNTIME_SYMNUM $(CFLAGS) -o $@ $^ $(LDFLAGS) calibrate.c redist/os_generic.c $(DRAWFUNCTIONS) redist/symbol_enumerator.c + tcc -DRUNTIME_SYMNUM $(CFLAGS) -o $@ $^ $(LDFLAGS) calibrate.c $(DRAWFUNCTIONS) redist/symbol_enumerator.c clean : rm -rf */*/*.o *.o src/*.o *~ src/*~ test simple_pose_test data_recorder calibrate testCocoa lib/libsurvive.so test_minimal_cv test_epnp test_epnp_ocv calibrate_client redist/*.o redist/*~ tools/data_server/data_server tools/lighthousefind/lighthousefind tools/lighthousefind_tori/lighthousefind-tori tools/plot_lighthouse/plot_lighthouse tools/process_rawcap/process_to_points redist/jsmntest redist/lintest 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.3.1 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.3.1 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 --- bindings/cs/Demo/App.config | 6 ++ bindings/cs/Demo/Demo.csproj | 86 +++++++++++++++++++++ bindings/cs/Demo/Program.cs | 32 ++++++++ bindings/cs/Demo/Properties/AssemblyInfo.cs | 36 +++++++++ bindings/cs/LibSurviveBinding.sln | 54 +++++++++++-- bindings/cs/LibSurviveBinding/Binding.cs | 33 -------- bindings/cs/LibSurviveBinding/Config_entry.cs | 31 -------- .../cs/LibSurviveBinding/LibSurviveBinding.csproj | 18 ----- bindings/cs/LibSurviveBinding/LightcapElement.cs | 6 -- bindings/cs/LibSurviveBinding/Program.cs | 62 --------------- bindings/cs/LibSurviveBinding/SurviveContext.cs | 44 ----------- bindings/cs/LibSurviveBinding/SurviveObject.cs | 6 -- bindings/cs/LibSurviveBinding/SurvivePose.cs | 6 -- bindings/cs/LibSurviveBinding/config_group.cs | 14 ---- bindings/cs/libsurvive.net/SurviveContext.cs | 90 ++++++++++++++++++++++ bindings/cs/libsurvive.net/cfunctions.cs | 84 ++++++++++++++++++++ bindings/cs/libsurvive.net/libsurvive.net.csproj | 7 ++ calibrate.c | 2 - include/libsurvive/survive.h | 63 ++++++++------- redist/symbol_enumerator.c | 5 +- src/survive.c | 5 ++ src/survive_playback.c | 2 +- winbuild/libsurvive/libsurvive.def | 2 + winbuild/libsurvive/libsurvive.vcxproj | 5 +- winbuild/libsurvive/libsurvive.vcxproj.filters | 3 + 25 files changed, 441 insertions(+), 261 deletions(-) create mode 100644 bindings/cs/Demo/App.config create mode 100644 bindings/cs/Demo/Demo.csproj create mode 100644 bindings/cs/Demo/Program.cs create mode 100644 bindings/cs/Demo/Properties/AssemblyInfo.cs delete mode 100644 bindings/cs/LibSurviveBinding/Binding.cs delete mode 100644 bindings/cs/LibSurviveBinding/Config_entry.cs delete mode 100644 bindings/cs/LibSurviveBinding/LibSurviveBinding.csproj delete mode 100644 bindings/cs/LibSurviveBinding/LightcapElement.cs delete mode 100644 bindings/cs/LibSurviveBinding/Program.cs delete mode 100644 bindings/cs/LibSurviveBinding/SurviveContext.cs delete mode 100644 bindings/cs/LibSurviveBinding/SurviveObject.cs delete mode 100644 bindings/cs/LibSurviveBinding/SurvivePose.cs delete mode 100644 bindings/cs/LibSurviveBinding/config_group.cs create mode 100644 bindings/cs/libsurvive.net/SurviveContext.cs create mode 100644 bindings/cs/libsurvive.net/cfunctions.cs create mode 100644 bindings/cs/libsurvive.net/libsurvive.net.csproj (limited to 'redist') diff --git a/bindings/cs/Demo/App.config b/bindings/cs/Demo/App.config new file mode 100644 index 0000000..731f6de --- /dev/null +++ b/bindings/cs/Demo/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/bindings/cs/Demo/Demo.csproj b/bindings/cs/Demo/Demo.csproj new file mode 100644 index 0000000..f347a5e --- /dev/null +++ b/bindings/cs/Demo/Demo.csproj @@ -0,0 +1,86 @@ + + + + + Debug + AnyCPU + {D3A43A2F-03B7-4A10-928F-686790036838} + Exe + Demo + Demo + v4.6.1 + 512 + true + publish\ + true + Disk + false + Foreground + 7 + Days + false + false + true + 0 + 1.0.0.%2a + false + false + true + + + AnyCPU + true + full + false + ..\x64\Debug\ + DEBUG;TRACE + prompt + 4 + false + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + {da1b12d7-a121-4d40-b363-4893e4f88b8a} + libsurvive.net + + + + + False + Microsoft .NET Framework 4.6.1 %28x86 and x64%29 + true + + + False + .NET Framework 3.5 SP1 + false + + + + \ No newline at end of file diff --git a/bindings/cs/Demo/Program.cs b/bindings/cs/Demo/Program.cs new file mode 100644 index 0000000..1644360 --- /dev/null +++ b/bindings/cs/Demo/Program.cs @@ -0,0 +1,32 @@ +using libsurvive; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Demo +{ + internal class MyHandler : SurviveContext + { + public MyHandler() + { + } + + public MyHandler(string[] args) : base(args) + { + } + } + class Program + { + static void Main(string[] args) + { + MyHandler handler = new MyHandler(args); + + while (handler.Poll() == 0) { + } + + } + + } +} diff --git a/bindings/cs/Demo/Properties/AssemblyInfo.cs b/bindings/cs/Demo/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..2c6a6c7 --- /dev/null +++ b/bindings/cs/Demo/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Demo")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Demo")] +[assembly: AssemblyCopyright("Copyright © 2018")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("d3a43a2f-03b7-4a10-928f-686790036838")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/bindings/cs/LibSurviveBinding.sln b/bindings/cs/LibSurviveBinding.sln index 539470c..b2e2f11 100644 --- a/bindings/cs/LibSurviveBinding.sln +++ b/bindings/cs/LibSurviveBinding.sln @@ -1,20 +1,62 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.27428.2015 +VisualStudioVersion = 15.0.27130.2003 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibSurviveBinding", "LibSurviveBinding\LibSurviveBinding.csproj", "{3DEFC8F7-C61E-4BC2-B743-E39453C6BA10}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Demo", "Demo\Demo.csproj", "{D3A43A2F-03B7-4A10-928F-686790036838}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "libsurvive.net", "libsurvive.net\libsurvive.net.csproj", "{DA1B12D7-A121-4D40-B363-4893E4F88B8A}" + ProjectSection(ProjectDependencies) = postProject + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F} = {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F} + EndProjectSection +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libsurvive", "..\..\winbuild\libsurvive\libsurvive.vcxproj", "{435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3DEFC8F7-C61E-4BC2-B743-E39453C6BA10}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3DEFC8F7-C61E-4BC2-B743-E39453C6BA10}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3DEFC8F7-C61E-4BC2-B743-E39453C6BA10}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3DEFC8F7-C61E-4BC2-B743-E39453C6BA10}.Release|Any CPU.Build.0 = Release|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Debug|x64.ActiveCfg = Debug|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Debug|x64.Build.0 = Debug|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Debug|x86.ActiveCfg = Debug|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Debug|x86.Build.0 = Debug|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Release|Any CPU.Build.0 = Release|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Release|x64.ActiveCfg = Release|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Release|x64.Build.0 = Release|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Release|x86.ActiveCfg = Release|Any CPU + {D3A43A2F-03B7-4A10-928F-686790036838}.Release|x86.Build.0 = Release|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Debug|x64.ActiveCfg = Debug|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Debug|x64.Build.0 = Debug|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Debug|x86.ActiveCfg = Debug|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Debug|x86.Build.0 = Debug|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Release|Any CPU.Build.0 = Release|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Release|x64.ActiveCfg = Release|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Release|x64.Build.0 = Release|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Release|x86.ActiveCfg = Release|Any CPU + {DA1B12D7-A121-4D40-B363-4893E4F88B8A}.Release|x86.Build.0 = Release|Any CPU + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Debug|Any CPU.ActiveCfg = Debug|x64 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Debug|Any CPU.Build.0 = Debug|x64 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Debug|x64.ActiveCfg = Debug|x64 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Debug|x64.Build.0 = Debug|x64 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Debug|x86.ActiveCfg = Debug|Win32 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Debug|x86.Build.0 = Debug|Win32 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Release|Any CPU.ActiveCfg = Release|Win32 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Release|x64.ActiveCfg = Release|x64 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Release|x64.Build.0 = Release|x64 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Release|x86.ActiveCfg = Release|Win32 + {435CFD2C-8724-42EE-8FDE-71EF7D2C6B2F}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/bindings/cs/LibSurviveBinding/Binding.cs b/bindings/cs/LibSurviveBinding/Binding.cs deleted file mode 100644 index f4f0652..0000000 --- a/bindings/cs/LibSurviveBinding/Binding.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace LibSurviveBinding -{ - class Binding - { - /* - typedef int (* htc_config_func) (SurviveObject* so, char* ct0conf, int len); - typedef void (* text_feedback_func) (SurviveContext* ctx, const char* fault ); - typedef void (* light_process_func) (SurviveObject* so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length, uint32_t lighthouse); - typedef void (* imu_process_func) (SurviveObject* so, int mask, FLT* accelgyro, uint32_t timecode, int id); - typedef void (* angle_process_func) (SurviveObject* so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh); - typedef void (* button_process_func) (SurviveObject* so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val); - typedef void (* raw_pose_func) (SurviveObject* so, uint8_t lighthouse, SurvivePose* pose); - typedef void (* lighthouse_pose_func) (SurviveContext* ctx, uint8_t lighthouse, SurvivePose* lighthouse_pose, - SurvivePose* object_pose); - */ - } - - public delegate int htc_config_func(IntPtr so, char ct0conf, int len); - public delegate void text_feedback_func(IntPtr ctx, string fault); - public delegate void light_process_func(IntPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse); - public delegate void imu_process_func(IntPtr so, int mask, double accelgyro, UInt32 timecode, int id); - public delegate void angle_process_func(IntPtr so, int sensor_id, int acode, UInt32 timecode, double length, double angle, UInt32 lh); - public delegate void button_process_func(IntPtr so, byte eventType, byte buttonId, byte axis1Id, UInt16 axis1Val, byte axis2Id, UInt16 axis2Val); - public delegate void raw_pose_func(IntPtr so, byte lighthouse, IntPtr pose); - public delegate void lighthouse_pose_func(IntPtr ctx, byte lighthouse, IntPtr lighthouse_pose, - IntPtr object_pose); - public delegate void handle_lightcap_func (IntPtr so, IntPtr le); - -} diff --git a/bindings/cs/LibSurviveBinding/Config_entry.cs b/bindings/cs/LibSurviveBinding/Config_entry.cs deleted file mode 100644 index 85a6701..0000000 --- a/bindings/cs/LibSurviveBinding/Config_entry.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace LibSurviveBinding -{ - - // internal class Config_entry - // { - // char[] tag; - // cval_type type; - // /** - // union { - //uint32_t i; - // FLT f; - // } - - // numeric; - // **/ - // char* data; - // uint32_t elements; - - // } - - // public enum cval_type - // { - // CONFIG_UNKNOWN = 0, - // CONFIG_FLOAT = 1, - // CONFIG_UINT32 = 2, - // CONFIG_STRING = 3, - // CONFIG_FLOAT_ARRAY = 4, - // } - - -} \ No newline at end of file diff --git a/bindings/cs/LibSurviveBinding/LibSurviveBinding.csproj b/bindings/cs/LibSurviveBinding/LibSurviveBinding.csproj deleted file mode 100644 index 646c16d..0000000 --- a/bindings/cs/LibSurviveBinding/LibSurviveBinding.csproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - Exe - netcoreapp2.0 - - - - - Always - - - - - - - - diff --git a/bindings/cs/LibSurviveBinding/LightcapElement.cs b/bindings/cs/LibSurviveBinding/LightcapElement.cs deleted file mode 100644 index ca51fb9..0000000 --- a/bindings/cs/LibSurviveBinding/LightcapElement.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LibSurviveBinding -{ - public class LightcapElement - { - } -} \ No newline at end of file diff --git a/bindings/cs/LibSurviveBinding/Program.cs b/bindings/cs/LibSurviveBinding/Program.cs deleted file mode 100644 index b6d0d8f..0000000 --- a/bindings/cs/LibSurviveBinding/Program.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace LibSurVive -{ - class Program - { - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - static extern IntPtr survive_init_internal(int argc, string[] args); - - public delegate void raw_pose_func(IntPtr so, byte lighthouse, IntPtr pose); - public delegate void lighthouse_pose_func(IntPtr ctx, byte lighthouse, IntPtr lighthouse_pose, IntPtr object_pose); - public delegate void light_process_func( IntPtr so, int sensor_id, int acode, int timeinsweep, - UInt32 timecode, UInt32 length, UInt32 lighthouse); - - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - static extern void survive_install_raw_pose_fn(IntPtr ctx, raw_pose_func fbp); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - static extern void survive_install_lighthouse_pose_fn(IntPtr ctx, lighthouse_pose_func fbp); - - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - static extern void survive_install_light_fn(IntPtr ctx, light_process_func fbp); - - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - static extern int survive_startup(IntPtr ctx); - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - static extern void survive_cal_install(IntPtr ctx); - - [DllImport("libsurvive", CallingConvention = CallingConvention.StdCall)] - static extern int survive_poll(IntPtr ctx); - - static void Main(string[] args) - { - IntPtr context = survive_init_internal(args.Length, args); - - survive_install_lighthouse_pose_fn(context, LighthousPos); - survive_install_raw_pose_fn(context, PositionUpdate); - survive_install_light_fn(context, LightUpdate); - - survive_startup(context); - survive_cal_install(context); - - while(survive_poll(context) == 0) {} - - } - - public static void LightUpdate( IntPtr so, int sensor_id, int acode, int timeinsweep, - UInt32 timecode, UInt32 length, UInt32 lighthouse) { - Console.WriteLine(timeinsweep); - } - - public static void PositionUpdate(IntPtr so, byte lighthouse, IntPtr pose) - { - Console.WriteLine(pose); - } - - public static void LighthousPos(IntPtr ctx, byte lighthouse, IntPtr lighthouse_pose, IntPtr object_pose) - { - - } - } -} diff --git a/bindings/cs/LibSurviveBinding/SurviveContext.cs b/bindings/cs/LibSurviveBinding/SurviveContext.cs deleted file mode 100644 index 2ba9b7c..0000000 --- a/bindings/cs/LibSurviveBinding/SurviveContext.cs +++ /dev/null @@ -1,44 +0,0 @@ -namespace LibSurviveBinding -{ - /* - public struct SurviveContext - { - text_feedback_func faultfunction; - text_feedback_func notefunction; - light_process_func lightproc; - imu_process_func imuproc; - angle_process_func angleproc; - button_process_func buttonproc; - raw_pose_func rawposeproc; - lighthouse_pose_func lighthouseposeproc; - htc_config_func configfunction; - handle_lightcap_func lightcapfunction; - - Config_group global_config_values; - Config_group* lh_config; //lighthouse configs - Config_group* temporary_config_values; //Set per-session, from command-line. Not saved but override global_config_values - - //Calibration data: - int activeLighthouses; - BaseStationData bsd[NUM_LIGHTHOUSES]; - SurviveCalData* calptr; //If and only if the calibration subsystem is attached. - struct SurviveRecordingData *recptr; // Iff recording is attached - SurviveObject** objs; - int objs_ct; - - void** drivers; - DeviceDriverCb* driverpolls; - DeviceDriverCb* drivercloses; - DeviceDriverMagicCb* drivermagics; - int driver_ct; - - SurviveState state; - - void* buttonservicethread; - ButtonQueue buttonQueue; - - void* user_ptr; - - } - */ -} \ No newline at end of file diff --git a/bindings/cs/LibSurviveBinding/SurviveObject.cs b/bindings/cs/LibSurviveBinding/SurviveObject.cs deleted file mode 100644 index bb9e3cd..0000000 --- a/bindings/cs/LibSurviveBinding/SurviveObject.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LibSurviveBinding -{ - public class SurviveObject - { - } -} \ No newline at end of file diff --git a/bindings/cs/LibSurviveBinding/SurvivePose.cs b/bindings/cs/LibSurviveBinding/SurvivePose.cs deleted file mode 100644 index 9808d89..0000000 --- a/bindings/cs/LibSurviveBinding/SurvivePose.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace LibSurviveBinding -{ - public class SurvivePose - { - } -} \ No newline at end of file diff --git a/bindings/cs/LibSurviveBinding/config_group.cs b/bindings/cs/LibSurviveBinding/config_group.cs deleted file mode 100644 index 8a2f00e..0000000 --- a/bindings/cs/LibSurviveBinding/config_group.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; - -namespace LibSurviveBinding -{ - /* - internal class Config_group - { - Config_entry config_entries; - UInt16 used_entries; - UInt16 max_entries; - - } - */ -} \ No newline at end of file diff --git a/bindings/cs/libsurvive.net/SurviveContext.cs b/bindings/cs/libsurvive.net/SurviveContext.cs new file mode 100644 index 0000000..1fb8c11 --- /dev/null +++ b/bindings/cs/libsurvive.net/SurviveContext.cs @@ -0,0 +1,90 @@ +using System; + +namespace libsurvive +{ + using SurviveContextPtr = IntPtr; + using SurviveObjectPtr = IntPtr; + using SurvivePosePtr = IntPtr; + + public class SurviveContext : IDisposable + { + protected IntPtr ctx; + + public void Dispose() + { + cfunctions.survive_close(ctx); + ctx = IntPtr.Zero; + } + + public SurviveContext() : this(null) { } + + public SurviveContext(string[] args) + { + string[] newArgs = new string[args.Length + 1]; + newArgs[0] = System.Reflection.Assembly.GetEntryAssembly().FullName; + Array.Copy(args, 0, newArgs, 1, args.Length); + + ctx = cfunctions.survive_init_internal(newArgs.Length, newArgs); + + cfunctions.survive_install_raw_pose_fn(ctx, PoseEvent); + cfunctions.survive_install_light_fn(ctx, LightEvent); + cfunctions.survive_install_lighthouse_pose_fn(ctx, LightHouseEvent); + cfunctions.survive_install_angle_fn(ctx, AngleEvent); + cfunctions.survive_install_button_fn(ctx, ButtonEvent); + cfunctions.survive_install_htc_config_fn(ctx, HTCConfigEvent); + cfunctions.survive_install_imu_fn(ctx, IMUEvent); + cfunctions.survive_install_error_fn(ctx, ErrorEvent); + cfunctions.survive_install_info_fn(ctx, InfoEvent); + } + + protected void InfoEvent(SurviveObjectPtr ctx, string fault) + { + Console.Out.WriteLine(fault); + } + + protected void ErrorEvent(SurviveObjectPtr ctx, string fault) + { + Console.Error.WriteLine(fault); + } + + protected void IMUEvent(SurviveObjectPtr so, int mask, double[] accelgyro, uint timecode, int id) + { + cfunctions.survive_default_imu_process(so, mask, accelgyro, timecode, id); + } + + protected int HTCConfigEvent(SurviveObjectPtr so, string ct0conf, int len) + { + return cfunctions.survive_default_htc_config_process(so, ct0conf, len); + } + + protected void ButtonEvent(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, ushort axis1Val, byte axis2Id, ushort axis2Val) + { + cfunctions.survive_default_button_process(so, eventType, buttonId, axis1Id, axis1Val, axis2Id, axis2Val); + } + + protected void AngleEvent(SurviveObjectPtr so, int sensor_id, int acode, uint timecode, double length, double angle, uint lh) + { + cfunctions.survive_default_angle_process(so, sensor_id, acode, timecode, length, angle, lh); + } + + protected void LightHouseEvent(SurviveObjectPtr ctx, byte lighthouse, ref SurvivePose lighthouse_pose, ref SurvivePose object_pose) + { + cfunctions.survive_default_lighthouse_pose_process(ctx, lighthouse, ref lighthouse_pose, ref object_pose); + } + + protected void LightEvent(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse) + { + cfunctions.survive_default_light_process(so, sensor_id, acode, timeinsweep, timecode, length, lighthouse); + } + + protected void PoseEvent(IntPtr so, byte lighthouse, ref SurvivePose pose) + { + cfunctions.survive_default_raw_pose_process(so, lighthouse, ref pose); + } + + public int Poll() + { + return cfunctions.survive_poll(ctx); + } + } +} \ No newline at end of file diff --git a/bindings/cs/libsurvive.net/cfunctions.cs b/bindings/cs/libsurvive.net/cfunctions.cs new file mode 100644 index 0000000..f9d88f0 --- /dev/null +++ b/bindings/cs/libsurvive.net/cfunctions.cs @@ -0,0 +1,84 @@ +using System; +using System.Collections.Generic; +using System.Runtime.InteropServices; +using System.Text; + +namespace libsurvive +{ + using SurviveContextPtr = IntPtr; + using SurviveObjectPtr = IntPtr; + using SurvivePosePtr = IntPtr; + + [StructLayout(LayoutKind.Sequential)] + public struct SurvivePose + { + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] + public double[] Pos; // Position in the form xyz + [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] + public double[] Rot; // Quaternion in the form wxyz + } + + class cfunctions + { + +#pragma warning disable IDE1006 // Naming Styles + [DllImport("libsurvive")] + public static extern SurviveContextPtr survive_init_internal(int argc, string[] args); + [DllImport("libsurvive")] + public static extern SurviveContextPtr survive_close(SurviveContextPtr ctx); + [DllImport("libsurvive")] + public static extern int survive_poll(SurviveContextPtr ctx); + [DllImport("libsurvive")] + public static extern int survive_startup(SurviveContextPtr ctx); + + [DllImport("libsurvive")] + public static extern void survive_install_htc_config_fn(SurviveContextPtr ctx, htc_config_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_info_fn(SurviveContextPtr ctx, text_feedback_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_error_fn(SurviveContextPtr ctx, text_feedback_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_imu_fn(SurviveContextPtr ctx, imu_process_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_angle_fn(SurviveContextPtr ctx, angle_process_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_button_fn(SurviveContextPtr ctx, button_process_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_raw_pose_fn(SurviveContextPtr ctx, raw_pose_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_lighthouse_pose_fn(SurviveContextPtr ctx, lighthouse_pose_func fbp); + [DllImport("libsurvive")] + public static extern void survive_install_light_fn(SurviveContextPtr ctx, light_process_func fbp); + [DllImport("libsurvive")] + public static extern void survive_cal_install(SurviveContextPtr ctx); + + [DllImport("libsurvive")] + public static extern void survive_default_light_process(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lh); + [DllImport("libsurvive")] + public static extern void survive_default_imu_process(SurviveObjectPtr so, int mode, double[] accelgyro, UInt32 timecode, int id); + [DllImport("libsurvive")] + public static extern void survive_default_angle_process(SurviveObjectPtr so, int sensor_id, int acode, UInt32 timecode, double length, double angle, UInt32 lh); + [DllImport("libsurvive")] + public static extern void survive_default_button_process(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, UInt16 axis1Val, byte axis2Id, UInt16 axis2Val); + [DllImport("libsurvive")] + public static extern void survive_default_raw_pose_process(SurviveObjectPtr so, byte lighthouse, ref SurvivePose pose); + [DllImport("libsurvive")] + public static extern void survive_default_lighthouse_pose_process(SurviveContextPtr ctx, byte lighthouse, ref SurvivePose lh_pose, + ref SurvivePose obj_pose); + [DllImport("libsurvive")] + public static extern int survive_default_htc_config_process(SurviveObjectPtr so, string ct0conf, int len); + +#pragma warning restore IDE1006 // Naming Styles + } + + public delegate int htc_config_func(SurviveObjectPtr so, string ct0conf, int len); + public delegate void text_feedback_func(SurviveContextPtr ctx, string fault); + public delegate void light_process_func(SurviveObjectPtr so, int sensor_id, int acode, int timeinsweep, UInt32 timecode, UInt32 length, UInt32 lighthouse); + public delegate void imu_process_func(SurviveObjectPtr so, int mask, double[] accelgyro, UInt32 timecode, int id); + public delegate void angle_process_func(SurviveObjectPtr so, int sensor_id, int acode, UInt32 timecode, double length, double angle, UInt32 lh); + public delegate void button_process_func(SurviveObjectPtr so, byte eventType, byte buttonId, byte axis1Id, UInt16 axis1Val, byte axis2Id, UInt16 axis2Val); + public delegate void raw_pose_func(SurviveObjectPtr so, byte lighthouse, ref SurvivePose pose); + public delegate void lighthouse_pose_func(SurviveContextPtr ctx, byte lighthouse, ref SurvivePose lighthouse_pose, + ref SurvivePose object_pose); + +} diff --git a/bindings/cs/libsurvive.net/libsurvive.net.csproj b/bindings/cs/libsurvive.net/libsurvive.net.csproj new file mode 100644 index 0000000..eac3503 --- /dev/null +++ b/bindings/cs/libsurvive.net/libsurvive.net.csproj @@ -0,0 +1,7 @@ + + + + netstandard1.6 + + + diff --git a/calibrate.c b/calibrate.c index 569c5cb..e21c310 100644 --- a/calibrate.c +++ b/calibrate.c @@ -404,8 +404,6 @@ void * SurviveThread(void *jnk) survive_install_angle_fn( ctx, my_angle_process ); survive_startup( ctx ); - - survive_cal_install( ctx ); if( !ctx ) diff --git a/include/libsurvive/survive.h b/include/libsurvive/survive.h index 8a1474b..85078f7 100644 --- a/include/libsurvive/survive.h +++ b/include/libsurvive/survive.h @@ -10,6 +10,13 @@ extern "C" { #endif + +#ifdef _WIN32 +#define SURVIVE_EXPORT __declspec(dllexport) +#else +#define SURVIVE_EXPORT +#endif + /** * This struct encodes what the last effective angles seen on a sensor were, and when they occured. */ @@ -203,7 +210,7 @@ struct SurviveContext void survive_verify_FLT_size(uint32_t user_size); // Baked in size of FLT to verify users of the library have the correct setting. -SurviveContext * survive_init_internal( int argc, char * const * argv ); +SURVIVE_EXPORT SurviveContext * survive_init_internal( int argc, char * const * argv ); /** * Call survive_init to get a populated SurviveContext pointer. @@ -224,20 +231,20 @@ static inline SurviveContext * survive_init( int argc, char * const * argv ) //For any of these, you may pass in 0 for the function pointer to use default behavior. //In general unless you are doing wacky things like recording or playing back data, you won't need to use this. -void survive_install_htc_config_fn( SurviveContext *ctx, htc_config_func fbp ); -void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_error_fn( SurviveContext * ctx, text_feedback_func fbp ); -void survive_install_light_fn( SurviveContext * ctx, light_process_func fbp ); -void survive_install_imu_fn( SurviveContext * ctx, imu_process_func fbp ); -void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp ); -void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp); -void survive_install_raw_pose_fn(SurviveContext * ctx, raw_pose_func fbp); -void survive_install_lighthouse_pose_fn(SurviveContext *ctx, lighthouse_pose_func fbp); -int survive_startup( SurviveContext * ctx ); -int survive_poll( SurviveContext * ctx ); -void survive_close( SurviveContext * ctx ); - -SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name ); +SURVIVE_EXPORT void survive_install_htc_config_fn( SurviveContext *ctx, htc_config_func fbp ); +SURVIVE_EXPORT void survive_install_info_fn( SurviveContext * ctx, text_feedback_func fbp ); +SURVIVE_EXPORT void survive_install_error_fn( SurviveContext * ctx, text_feedback_func fbp ); +SURVIVE_EXPORT void survive_install_light_fn( SurviveContext * ctx, light_process_func fbp ); +SURVIVE_EXPORT void survive_install_imu_fn( SurviveContext * ctx, imu_process_func fbp ); +SURVIVE_EXPORT void survive_install_angle_fn( SurviveContext * ctx, angle_process_func fbp ); +SURVIVE_EXPORT void survive_install_button_fn(SurviveContext * ctx, button_process_func fbp); +SURVIVE_EXPORT void survive_install_raw_pose_fn(SurviveContext * ctx, raw_pose_func fbp); +SURVIVE_EXPORT void survive_install_lighthouse_pose_fn(SurviveContext *ctx, lighthouse_pose_func fbp); +SURVIVE_EXPORT int survive_startup( SurviveContext * ctx ); +SURVIVE_EXPORT int survive_poll( SurviveContext * ctx ); +SURVIVE_EXPORT void survive_close( SurviveContext * ctx ); + +SURVIVE_EXPORT SurviveObject * survive_get_so_by_name( SurviveContext * ctx, const char * name ); //Utilitiy functions. int survive_simple_inflate( SurviveContext * ctx, const char * input, int inlen, char * output, int outlen ); @@ -249,30 +256,30 @@ int survive_send_magic( SurviveContext * ctx, int magic_code, void * data, int d #define SC_OVERRIDE 2 //Set, to new default value. #define SC_SETCONFIG 4 //Set, both in-memory and config file. Use in conjunction with SC_OVERRIDE. -FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ); -uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ); -const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ); +SURVIVE_EXPORT FLT survive_configf( SurviveContext * ctx, const char *tag, char flags, FLT def ); +SURVIVE_EXPORT uint32_t survive_configi( SurviveContext * ctx, const char *tag, char flags, uint32_t def ); +SURVIVE_EXPORT const char * survive_configs( SurviveContext * ctx, const char *tag, char flags, const char *def ); //Install the calibrator. -void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. +SURVIVE_EXPORT void survive_cal_install( SurviveContext * ctx ); //XXX This will be removed if not already done so. // Read back a human-readable string description of the calibration status -int survive_cal_get_status( SurviveContext * ctx, char * description, int description_length ); +SURVIVE_EXPORT int survive_cal_get_status( SurviveContext * ctx, char * description, int description_length ); // Induce haptic feedback -int survive_haptic(SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount); +SURVIVE_EXPORT int survive_haptic(SurviveObject * so, uint8_t reserved, uint16_t pulseHigh, uint16_t pulseLow, uint16_t repeatCount); //Call these from your callback if overridden. //Accept higher-level data. -void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length , uint32_t lh); -void survive_default_imu_process( SurviveObject * so, int mode, FLT * accelgyro, uint32_t timecode, int id ); -void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh ); -void survive_default_button_process(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val); -void survive_default_raw_pose_process(SurviveObject *so, uint8_t lighthouse, SurvivePose *pose); -void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *lh_pose, +SURVIVE_EXPORT void survive_default_light_process( SurviveObject * so, int sensor_id, int acode, int timeinsweep, uint32_t timecode, uint32_t length , uint32_t lh); +SURVIVE_EXPORT void survive_default_imu_process( SurviveObject * so, int mode, FLT * accelgyro, uint32_t timecode, int id ); +SURVIVE_EXPORT void survive_default_angle_process( SurviveObject * so, int sensor_id, int acode, uint32_t timecode, FLT length, FLT angle, uint32_t lh ); +SURVIVE_EXPORT void survive_default_button_process(SurviveObject * so, uint8_t eventType, uint8_t buttonId, uint8_t axis1Id, uint16_t axis1Val, uint8_t axis2Id, uint16_t axis2Val); +SURVIVE_EXPORT void survive_default_raw_pose_process(SurviveObject *so, uint8_t lighthouse, SurvivePose *pose); +SURVIVE_EXPORT void survive_default_lighthouse_pose_process(SurviveContext *ctx, uint8_t lighthouse, SurvivePose *lh_pose, SurvivePose *obj_pose); -int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); +SURVIVE_EXPORT int survive_default_htc_config_process(SurviveObject *so, char *ct0conf, int len); 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; } diff --git a/src/survive.c b/src/survive.c index 899d206..f46f128 100644 --- a/src/survive.c +++ b/src/survive.c @@ -111,6 +111,11 @@ SurviveContext *survive_init_internal(int argc, char *const *argv) { MANUAL_DRIVER_REGISTRATION(PoserDaveOrtho) MANUAL_DRIVER_REGISTRATION(PoserDummy) MANUAL_DRIVER_REGISTRATION(DriverRegHTCVive) + MANUAL_DRIVER_REGISTRATION(DriverRegPlayback) + + MANUAL_DRIVER_REGISTRATION(DisambiguatorCharles) + MANUAL_DRIVER_REGISTRATION(DisambiguatorStateBased) + MANUAL_DRIVER_REGISTRATION(DisambiguatorTurvey) #endif SurviveContext *ctx = calloc(1, sizeof(SurviveContext)); diff --git a/src/survive_playback.c b/src/survive_playback.c index 43a3c0b..c73dd2f 100644 --- a/src/survive_playback.c +++ b/src/survive_playback.c @@ -275,7 +275,7 @@ static int playback_poll(struct SurviveContext *ctx, void *_driver) { if (f && !feof(f) && !ferror(f)) { driver->lineno++; - char *line; + char *line = 0; if (driver->next_time_us == 0) { size_t n = 0; diff --git a/winbuild/libsurvive/libsurvive.def b/winbuild/libsurvive/libsurvive.def index fb2f05e..3a50ce6 100644 --- a/winbuild/libsurvive/libsurvive.def +++ b/winbuild/libsurvive/libsurvive.def @@ -10,6 +10,7 @@ EXPORTS survive_install_light_fn survive_install_imu_fn survive_install_angle_fn + survive_install_htc_config_fn survive_send_magic survive_cal_install survive_cal_get_status @@ -26,3 +27,4 @@ EXPORTS survive_default_lighthouse_pose_process quatnormalize quatrotatevector + \ No newline at end of file diff --git a/winbuild/libsurvive/libsurvive.vcxproj b/winbuild/libsurvive/libsurvive.vcxproj index acf8500..6268d63 100644 --- a/winbuild/libsurvive/libsurvive.vcxproj +++ b/winbuild/libsurvive/libsurvive.vcxproj @@ -27,7 +27,7 @@ - StaticLibrary + DynamicLibrary true v141 MultiByte @@ -77,7 +77,7 @@ Level3 Disabled - FLT=double;USE_DOUBLE;RUNTIME_SYMNUM;RUNTIME_SYMNUMX;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WINDOWS;_DEBUG;_LIB;%(PreprocessorDefinitions) + FLT=double;USE_DOUBLE;MANUAL_REGISTRATION;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WINDOWS;_DEBUG;_LIB;%(PreprocessorDefinitions) ..\..\winbuild;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) @@ -169,6 +169,7 @@ + diff --git a/winbuild/libsurvive/libsurvive.vcxproj.filters b/winbuild/libsurvive/libsurvive.vcxproj.filters index 717038c..5387108 100644 --- a/winbuild/libsurvive/libsurvive.vcxproj.filters +++ b/winbuild/libsurvive/libsurvive.vcxproj.filters @@ -105,6 +105,9 @@ Source Files + + Source Files + -- cgit v1.3.1 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 ++++++++++++++++++++++++- src/epnp/epnp.c | 2 +- src/poser_sba.c | 1 + src/survive.c | 5 +- src/survive_cal.c | 2 +- winbuild/calibrate/calibrate.vcxproj | 11 ++ winbuild/calibrate/calibrate.vcxproj.filters | 3 + winbuild/data_recorder/data_recorder.vcxproj | 1 + winbuild/libsurvive/libsurvive.vcxproj | 33 ++++- winbuild/libsurvive/libsurvive.vcxproj.filters | 37 ++++++ winbuild/libsurvive/packages.config | 5 + winbuild/test/test.vcxproj | 4 +- 12 files changed, 265 insertions(+), 11 deletions(-) create mode 100644 winbuild/libsurvive/packages.config (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; diff --git a/src/epnp/epnp.c b/src/epnp/epnp.c index 4b888aa..53a1d48 100644 --- a/src/epnp/epnp.c +++ b/src/epnp/epnp.c @@ -134,7 +134,7 @@ void epnp_choose_control_points(epnp *self) { // Take C1, C2, and C3 from PCA on the reference points: CvMat *PW0 = cvCreateMat(self->number_of_correspondences, 3, CV_64F); - double pw0tpw0[3 * 3] = {}, dc[3], uct[3 * 3]; + double pw0tpw0[3 * 3] = {0}, dc[3], uct[3 * 3]; CvMat PW0tPW0 = cvMat(3, 3, CV_64F, pw0tpw0); CvMat DC = cvMat(3, 1, CV_64F, dc); CvMat UCt = cvMat(3, 3, CV_64F, uct); diff --git a/src/poser_sba.c b/src/poser_sba.c index 0ad38ac..df28a2d 100644 --- a/src/poser_sba.c +++ b/src/poser_sba.c @@ -4,6 +4,7 @@ #endif #include +#include #include "poser.h" #include diff --git a/src/survive.c b/src/survive.c index f46f128..23b1e4c 100644 --- a/src/survive.c +++ b/src/survive.c @@ -110,6 +110,9 @@ SurviveContext *survive_init_internal(int argc, char *const *argv) { MANUAL_DRIVER_REGISTRATION(PoserCharlesSlow) MANUAL_DRIVER_REGISTRATION(PoserDaveOrtho) MANUAL_DRIVER_REGISTRATION(PoserDummy) + MANUAL_DRIVER_REGISTRATION(PoserEPNP) + MANUAL_DRIVER_REGISTRATION(PoserSBA) + MANUAL_DRIVER_REGISTRATION(DriverRegHTCVive) MANUAL_DRIVER_REGISTRATION(DriverRegPlayback) @@ -260,7 +263,7 @@ int survive_startup(SurviveContext *ctx) { // start the thread to process button data ctx->buttonservicethread = OGCreateThread(button_servicer, ctx); - PoserCB PreferredPoserCB = GetDriverByConfig(ctx, "Poser", "defaultposer", "TurveyTori", 2); + PoserCB PreferredPoserCB = GetDriverByConfig(ctx, "Poser", "defaultposer", "SBA", 2); ctx->lightcapfunction = GetDriverByConfig(ctx, "Disambiguator", "disambiguator", "Turvey", 2); const char *DriverName; diff --git a/src/survive_cal.c b/src/survive_cal.c index 25e43b9..2fc1896 100755 --- a/src/survive_cal.c +++ b/src/survive_cal.c @@ -187,7 +187,7 @@ void survive_cal_install( struct SurviveContext * ctx ) } const char * DriverName; - cd->ConfigPoserFn = GetDriverByConfig(ctx, "Poser", "configposer", "TurveyTori", 0); + cd->ConfigPoserFn = GetDriverByConfig(ctx, "Poser", "configposer", "SBA", 0); ootx_packet_clbk = ootx_packet_clbk_d; diff --git a/winbuild/calibrate/calibrate.vcxproj b/winbuild/calibrate/calibrate.vcxproj index 51519e6..d0b1c48 100644 --- a/winbuild/calibrate/calibrate.vcxproj +++ b/winbuild/calibrate/calibrate.vcxproj @@ -75,6 +75,7 @@ true + $(LibraryPath) false @@ -190,7 +191,17 @@ {435cfd2c-8724-42ee-8fde-71ef7d2c6b2f} + + + + + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/winbuild/calibrate/calibrate.vcxproj.filters b/winbuild/calibrate/calibrate.vcxproj.filters index dae64dc..1498023 100644 --- a/winbuild/calibrate/calibrate.vcxproj.filters +++ b/winbuild/calibrate/calibrate.vcxproj.filters @@ -36,4 +36,7 @@ Header Files + + + \ No newline at end of file diff --git a/winbuild/data_recorder/data_recorder.vcxproj b/winbuild/data_recorder/data_recorder.vcxproj index 59a1e77..e63d474 100644 --- a/winbuild/data_recorder/data_recorder.vcxproj +++ b/winbuild/data_recorder/data_recorder.vcxproj @@ -72,6 +72,7 @@ true + $(VC_LibraryPath_x64);$(WindowsSDK_LibraryPath_x64);$(NETFXKitsDir)Lib\um\x64 true diff --git a/winbuild/libsurvive/libsurvive.vcxproj b/winbuild/libsurvive/libsurvive.vcxproj index 6268d63..2451c22 100644 --- a/winbuild/libsurvive/libsurvive.vcxproj +++ b/winbuild/libsurvive/libsurvive.vcxproj @@ -56,6 +56,7 @@ + @@ -70,14 +71,17 @@ - + + $(IncludePath) + $(LibraryPath) + Level3 Disabled - FLT=double;USE_DOUBLE;MANUAL_REGISTRATION;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WINDOWS;_DEBUG;_LIB;%(PreprocessorDefinitions) + FLT=double;USE_DOUBLE;MANUAL_REGISTRATION;NOZLIB;_CRT_SECURE_NO_WARNINGS;HIDAPI;WINDOWS;_DEBUG;_LIB;HAVE_LAPACK_CONFIG_H;LAPACK_COMPLEX_STRUCTURE;%(PreprocessorDefinitions) ..\..\winbuild;..\..\include\libsurvive;..\..\redist;%(AdditionalIncludeDirectories) @@ -89,6 +93,10 @@ $(MSBuildProjectDirectory)\libsurvive.def + + libblas.lib;liblapacke.lib;liblapack.lib%(AdditionalDependencies) + %(AdditionalLibraryDirectories) + @@ -149,14 +157,23 @@ + + + + + + + + + @@ -183,8 +200,11 @@ + + + @@ -193,8 +213,13 @@ + - - + + + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + \ No newline at end of file diff --git a/winbuild/libsurvive/libsurvive.vcxproj.filters b/winbuild/libsurvive/libsurvive.vcxproj.filters index 5387108..ffddee9 100644 --- a/winbuild/libsurvive/libsurvive.vcxproj.filters +++ b/winbuild/libsurvive/libsurvive.vcxproj.filters @@ -108,6 +108,33 @@ Source Files + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + @@ -152,8 +179,18 @@ Source Files + + Source Files + + + Header Files + + + Source Files + + \ No newline at end of file diff --git a/winbuild/libsurvive/packages.config b/winbuild/libsurvive/packages.config new file mode 100644 index 0000000..c283d9d --- /dev/null +++ b/winbuild/libsurvive/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/winbuild/test/test.vcxproj b/winbuild/test/test.vcxproj index e6ee3fb..5ceff3d 100644 --- a/winbuild/test/test.vcxproj +++ b/winbuild/test/test.vcxproj @@ -72,6 +72,8 @@ true + $(LibraryPath) + $(VC_ReferencesPath_x64); true @@ -93,7 +95,7 @@ Console - setupapi.lib;dbghelp.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies) + setupapi.lib;dbghelp.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;libblas.lib;liblapacke.lib;liblapack.lib;%(AdditionalDependencies) true UseFastLinkTimeCodeGeneration -- cgit v1.3.1 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.3.1 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.3.1 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.3.1 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.3.1 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.3.1