From 3fa72f4b765457ce369d1aa1495dc36c90a94ebf Mon Sep 17 00:00:00 2001 From: ultramn Date: Wed, 8 Mar 2017 21:03:05 -0800 Subject: Added OrthoSolve, it works great! --- dave/AffineSolve.c | 478 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 395 insertions(+), 83 deletions(-) (limited to 'dave/AffineSolve.c') diff --git a/dave/AffineSolve.c b/dave/AffineSolve.c index 36587e6..1eaf633 100644 --- a/dave/AffineSolve.c +++ b/dave/AffineSolve.c @@ -1,7 +1,6 @@ // // main.c -// AffineSolve -// +// Aff // Created by user on 3/2/17. // Copyright © 2017 user. All rights reserved. // @@ -10,10 +9,24 @@ #include #include #include +#include "dclapack.h" #define LH_ID 0 #define NUM_HMD 32 +#define MAX_POINTS 128 +//#define _ABS(a) ( (a)<=0 ? -(a) : (a) ) +#define _SIGN(a) ( (a)<=0 ? -1.0f : 1.0f ) +#define RANDF ( (float)rand() / (float)RAND_MAX ) +#define PI 3.14159265358979323846264 + +#define STEP_SIZE_ROT 1.0 +#define STEP_SIZE_POS 1.0 +#define FALLOFF 0.99999 +#define NITER 2000000 +#define TOO_SMALL 0.0001 +#define ORTHOG_PENALTY 1.0 + float hmd_pos[NUM_HMD][3]; void ReadHmdPoints() { @@ -31,17 +44,35 @@ void ReadHmdPoints() fclose(fin); } -#define MAX_POINTS 128 -#define _ABS(a) ( (a)<=0 ? -(a) : (a) ) -#define _SIGN(a) ( (a)<=0 ? -1.0f : 1.0f ) -#define RANDF ( (float)rand() / (float)RAND_MAX ) +float hmd_angle[NUM_HMD][2]; +void ReadPtinfo() +{ + // Initialize to -9999 + int i; + for (i=0; i 0 && err < bestErr) { x[1][0]=x_y; y[1][0]=y_y; z[1][0]=z_y; bestErr=err; } + z_y = -z_y; + } + y_y = -y_y; + } + x_y = -x_y; + } + printf("bestErr %f\n", bestErr); + + for (i=0; i Date: Wed, 8 Mar 2017 21:48:37 -0800 Subject: Added 1 million times runtime just for performance testing --- dave/AffineSolve.c | 48 ++++++++++++++++++++++++++---------------------- 1 file changed, 26 insertions(+), 22 deletions(-) (limited to 'dave/AffineSolve.c') diff --git a/dave/AffineSolve.c b/dave/AffineSolve.c index 1eaf633..ad9ccb5 100644 --- a/dave/AffineSolve.c +++ b/dave/AffineSolve.c @@ -142,7 +142,7 @@ void OrthoSolve( MUL(S,Xt,SXt,2,nPoints,3); INV(XXt,invXXt,3); MUL(SXt,invXXt,M,2,3,3); -PRINT(M,2,3); +//PRINT(M,2,3); // Double checking work FLOAT S_morph[2][MAX_POINTS]; @@ -201,15 +201,15 @@ for (i=0; i 0 && err < bestErr) { x[1][0]=x_y; y[1][0]=y_y; z[1][0]=z_y; bestErr=err; } @@ -253,15 +253,15 @@ for (i=0; i Date: Thu, 9 Mar 2017 02:38:10 -0500 Subject: switch to atan2 instead of asin. Take out of performance check and put into test mode again. --- dave/AffineSolve.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'dave/AffineSolve.c') diff --git a/dave/AffineSolve.c b/dave/AffineSolve.c index ad9ccb5..e848ade 100644 --- a/dave/AffineSolve.c +++ b/dave/AffineSolve.c @@ -314,6 +314,7 @@ PRINT(ab,2,1); T[2][0]=R[2][0]; T[2][1]=R[2][1]; T[2][2]=R[2][2]; T[2][3]=trans[2]; T[3][0]=0.0; T[3][1]=0.0; T[3][2]=0.0; T[3][3]=1.0; + PRINT_MAT(T,4,4); //------------------- // Plot the output points //------------------- @@ -321,11 +322,11 @@ PRINT(ab,2,1); float Tx = T[0][0]*X_in[0][i] + T[0][1]*X_in[1][i] + T[0][2]*X_in[2][i] + T[0][3]; float Ty = T[1][0]*X_in[0][i] + T[1][1]*X_in[1][i] + T[1][2]*X_in[2][i] + T[1][3]; float Tz = T[2][0]*X_in[0][i] + T[2][1]*X_in[1][i] + T[2][2]*X_in[2][i] + T[2][3]; - S_out[0][i] = asin(Tx / Ty); // horiz - S_out[1][i] = asin(Tz / Ty); // vert + S_out[0][i] = atan2(Tx, Ty); // horiz + S_out[1][i] = atan2(Tz, Ty); // vert //S_out[0][i] = Tx; //S_out[1][i] = Tz; -// printf("point %i Txyz %f %f %f in %f %f out %f %f morph %f %f\n", i, Tx,Ty,Tz, S_in[0][i], S_in[1][i], S_out[0][i], S_out[1][i], S_morph[0][i], S_morph[1][i]); + printf("point %i Txyz %f %f %f in %f %f out %f %f morph %f %f\n", i, Tx,Ty,Tz, S_in[0][i], S_in[1][i], S_out[0][i], S_out[1][i], S_morph[0][i], S_morph[1][i]); } // printf("xbar %f %f %f\n", xbar[0], xbar[1], xbar[2]); @@ -603,7 +604,7 @@ int main() //-------------------------------------------------- int loop; - for (loop=0; loop<1000000; loop++) + for (loop=0; loop<1; loop++) { // Run OrthoSolve OrthoSolve( -- cgit v1.2.3 From 9b792127fe2e2c4590b9e528dfd97e44d890d253 Mon Sep 17 00:00:00 2001 From: ultramn Date: Thu, 9 Mar 2017 16:51:41 -0800 Subject: fixed bug with error calculation --- dave/AffineSolve.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'dave/AffineSolve.c') diff --git a/dave/AffineSolve.c b/dave/AffineSolve.c index e848ade..f29e29e 100644 --- a/dave/AffineSolve.c +++ b/dave/AffineSolve.c @@ -242,7 +242,7 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); // Calculate the handedness FLOAT cx,cy,cz; CrossProduct(cx,cy,cz,x[0][0],x_y,x[2][0],y[0][0],y_y,y[2][0]); - FLOAT hand = cx*z[0][0] + cy*y_y + cz*z[2][0]; + FLOAT hand = cx*z[0][0] + cy*z_y + cz*z[2][0]; // printf("err %f hand %f\n", err, hand); // If we are the best right-handed frame so far -- cgit v1.2.3 From 3e39224bdd65b8a49de44f007add854dc626a209 Mon Sep 17 00:00:00 2001 From: ultramn Date: Thu, 9 Mar 2017 17:35:53 -0800 Subject: Added loop to try all z values --- dave/AffineSolve.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 5 deletions(-) (limited to 'dave/AffineSolve.c') diff --git a/dave/AffineSolve.c b/dave/AffineSolve.c index f29e29e..1c1d0f1 100644 --- a/dave/AffineSolve.c +++ b/dave/AffineSolve.c @@ -206,8 +206,8 @@ printf("fhat %f %f (len %f)\n", fhat[0][0], fhat[1][0], fhat_len); printf("uhat %f %f (len %f)\n", uhat[0][0], uhat[1][0], uhat_len); printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); */ - FLOAT ydist1 = 1.0 / uhat_len; //0.25*PI / uhat_len; - FLOAT ydist2 = 1.0 / rhat_len; //0.25*PI / rhat_len; +// FLOAT ydist1 = 1.0 / uhat_len; //0.25*PI / uhat_len; +// FLOAT ydist2 = 1.0 / rhat_len; //0.25*PI / rhat_len; FLOAT ydist = 1.0 / urhat_len; // printf("ydist1 %f ydist2 %f ydist %f\n", ydist1, ydist2, ydist); @@ -223,7 +223,7 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); FLOAT x_y = sqrt(1.0 - x[0][0]*x[0][0] - x[2][0]*x[2][0]); FLOAT y_y = sqrt(1.0 - y[0][0]*y[0][0] - y[2][0]*y[2][0]); FLOAT z_y = sqrt(1.0 - z[0][0]*z[0][0] - z[2][0]*z[2][0]); - +/* // Exhaustively flip the minus sign of the z axis until we find the right one . . . FLOAT bestErr = 9999.0; FLOAT xy_dot2 = x[0][0]*y[0][0] + x[2][0]*y[2][0]; @@ -243,7 +243,7 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); FLOAT cx,cy,cz; CrossProduct(cx,cy,cz,x[0][0],x_y,x[2][0],y[0][0],y_y,y[2][0]); FLOAT hand = cx*z[0][0] + cy*z_y + cz*z[2][0]; -// printf("err %f hand %f\n", err, hand); + printf("err %f hand %f\n", err, hand); // If we are the best right-handed frame so far if (hand > 0 && err < bestErr) { x[1][0]=x_y; y[1][0]=y_y; z[1][0]=z_y; bestErr=err; } @@ -253,7 +253,66 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); } x_y = -x_y; } -// printf("bestErr %f\n", bestErr); + printf("bestErr %f\n", bestErr); +*/ + + //------------------------- + // A test version of the rescaling to the proper length + //------------------------- + FLOAT ydist2; + FLOAT bestBestErr = 9999.0; + for (ydist2=ydist-0.1; ydist2 0 && err < bestErr) { x2[1][0]=x_y; y2[1][0]=y_y; z2[1][0]=z_y; bestErr=err; } + z_y = -z_y; + } + y_y = -y_y; + } + x_y = -x_y; + } + printf("ydist2 %f bestErr %f\n",ydist2,bestErr); + + if (bestErr < bestBestErr) { + memcpy(x,x2,3*sizeof(FLOAT)); + memcpy(y,y2,3*sizeof(FLOAT)); + memcpy(z,z2,3*sizeof(FLOAT)); + bestBestErr = bestErr; + } + } + + /* for (i=0; i Date: Thu, 9 Mar 2017 20:35:55 -0500 Subject: Update linmath to allow for transforming the pose solver for testing purposes. --- dave/AffineSolve.c | 50 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 6 deletions(-) (limited to 'dave/AffineSolve.c') diff --git a/dave/AffineSolve.c b/dave/AffineSolve.c index f29e29e..6e17f26 100644 --- a/dave/AffineSolve.c +++ b/dave/AffineSolve.c @@ -10,8 +10,8 @@ #include #include #include "dclapack.h" - -#define LH_ID 0 +#include +#define LH_ID 1 #define NUM_HMD 32 #define MAX_POINTS 128 @@ -209,7 +209,7 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); FLOAT ydist1 = 1.0 / uhat_len; //0.25*PI / uhat_len; FLOAT ydist2 = 1.0 / rhat_len; //0.25*PI / rhat_len; FLOAT ydist = 1.0 / urhat_len; -// printf("ydist1 %f ydist2 %f ydist %f\n", ydist1, ydist2, ydist); + //printf("ydist1 %f ydist2 %f ydist %f\n", ydist1, ydist2, ydist); //-------------------- // Rescale the axies to be of the proper length @@ -223,6 +223,9 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); FLOAT x_y = sqrt(1.0 - x[0][0]*x[0][0] - x[2][0]*x[2][0]); FLOAT y_y = sqrt(1.0 - y[0][0]*y[0][0] - y[2][0]*y[2][0]); FLOAT z_y = sqrt(1.0 - z[0][0]*z[0][0] - z[2][0]*z[2][0]); + if( x_y != x_y ) x_y = 0; + if( y_y != y_y ) y_y = 0; + if( z_y != z_y ) z_y = 0; // Exhaustively flip the minus sign of the z axis until we find the right one . . . FLOAT bestErr = 9999.0; @@ -243,17 +246,18 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); FLOAT cx,cy,cz; CrossProduct(cx,cy,cz,x[0][0],x_y,x[2][0],y[0][0],y_y,y[2][0]); FLOAT hand = cx*z[0][0] + cy*z_y + cz*z[2][0]; -// printf("err %f hand %f\n", err, hand); + printf("err %f hand %f\n", err, hand); // If we are the best right-handed frame so far - if (hand > 0 && err < bestErr) { x[1][0]=x_y; y[1][0]=y_y; z[1][0]=z_y; bestErr=err; } + //if (hand > 0 && err < bestErr) { x[1][0]=x_y; y[1][0]=y_y; z[1][0]=z_y; bestErr=err; } + if ( i == 0 && j == 1 && k == 0) { x[1][0]=x_y; y[1][0]=y_y; z[1][0]=z_y; bestErr=err; } z_y = -z_y; } y_y = -y_y; } x_y = -x_y; } -// printf("bestErr %f\n", bestErr); + printf("bestErr %f\n", bestErr); /* for (i=0; i Date: Thu, 9 Mar 2017 17:40:19 -0800 Subject: Added a loop to check the z values --- dave/AffineSolve.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'dave/AffineSolve.c') diff --git a/dave/AffineSolve.c b/dave/AffineSolve.c index 1c1d0f1..d036858 100644 --- a/dave/AffineSolve.c +++ b/dave/AffineSolve.c @@ -261,6 +261,7 @@ printf("rhat %f %f (len %f)\n", rhat[0][0], rhat[1][0], rhat_len); //------------------------- FLOAT ydist2; FLOAT bestBestErr = 9999.0; + FLOAT bestYdist = 0; for (ydist2=ydist-0.1; ydist2