[37] | 1 | /* file: rodr.mex.c |
---|
| 2 | ** author: Andrea Vedaldi |
---|
| 3 | ** description: Rodrigues formula |
---|
| 4 | **/ |
---|
| 5 | |
---|
| 6 | #include<mexutils.c> |
---|
| 7 | #include"bits/rodrigues.c" |
---|
| 8 | |
---|
| 9 | enum { |
---|
| 10 | IN_OM = 0 |
---|
| 11 | } ; |
---|
| 12 | |
---|
| 13 | enum { |
---|
| 14 | OUT_R=0, |
---|
| 15 | OUT_DR |
---|
| 16 | } ; |
---|
| 17 | |
---|
| 18 | /* ------------------------------------------------------------------- |
---|
| 19 | ** Driver |
---|
| 20 | ** ---------------------------------------------------------------- */ |
---|
| 21 | |
---|
| 22 | void |
---|
| 23 | mexFunction(int nout, mxArray *out[], |
---|
| 24 | int nin, const mxArray *in[]) |
---|
| 25 | { |
---|
| 26 | int k,K ; |
---|
| 27 | double const * om_pt ; |
---|
| 28 | double* R_pt ; |
---|
| 29 | double* dR_pt ; |
---|
| 30 | |
---|
| 31 | if(nin != 1) { |
---|
| 32 | mexErrMsgTxt("Exactly one argument required.") ; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | if(!uIsRealMatrix(in[IN_OM],-1,-1)) { |
---|
| 36 | mexErrMsgTxt("OM must be a DOUBLE array") ; |
---|
| 37 | } |
---|
| 38 | |
---|
| 39 | K = mxGetNumberOfElements(in[IN_OM]) ; |
---|
| 40 | if(K % 3 || K < 3) { |
---|
| 41 | mexErrMsgTxt("The number of elements of OM must be a multiple of 3") ; |
---|
| 42 | } |
---|
| 43 | K /= 3 ; |
---|
| 44 | om_pt = mxGetPr(in[IN_OM]) ; |
---|
| 45 | |
---|
| 46 | /* space for output (R) */ |
---|
| 47 | if( K == 1 ) { |
---|
| 48 | out[OUT_R] = mxCreateDoubleMatrix(3,3,mxREAL) ; |
---|
| 49 | } else { |
---|
| 50 | int dims [3] ; |
---|
| 51 | dims[0] = 3 ; dims[1] = 3 ; dims[2] = K ; |
---|
| 52 | out[OUT_R] = mxCreateNumericArray(3,dims,mxDOUBLE_CLASS,mxREAL) ; |
---|
| 53 | } |
---|
| 54 | R_pt = mxGetPr(out[OUT_R]) ; |
---|
| 55 | |
---|
| 56 | /* space for optional output (dR) */ |
---|
| 57 | dR_pt = NULL ; |
---|
| 58 | if( nout > 1 ) { |
---|
| 59 | if( K == 1 ) { |
---|
| 60 | out[OUT_DR] = mxCreateDoubleMatrix(9,3,mxREAL) ; |
---|
| 61 | } else { |
---|
| 62 | int dims [3] ; |
---|
| 63 | dims[0] = 9 ; dims[1] = 3 ; dims[2] = K ; |
---|
| 64 | out[OUT_DR] = mxCreateNumericArray(3,dims,mxDOUBLE_CLASS,mxREAL) ; |
---|
| 65 | } |
---|
| 66 | dR_pt = mxGetPr(out[OUT_DR]) ; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | /* ----------------------------------------------------------------- |
---|
| 70 | ** Process |
---|
| 71 | ** -------------------------------------------------------------- */ |
---|
| 72 | for(k = 0 ; k < K ; ++k) { |
---|
| 73 | vl_rodrigues(R_pt, dR_pt, om_pt) ; |
---|
| 74 | om_pt += 3 ; |
---|
| 75 | R_pt += 3*3 ; |
---|
| 76 | dR_pt += 9*3 ; |
---|
| 77 | } |
---|
| 78 | } |
---|