paramDecomp.c
Go to the documentation of this file.
00001 /*******************************************************
00002  *
00003  * Author: Takeshi Mita, Shinsaku Hiura, Hirokazu Kato
00004  *
00005  *         tmita@inolab.sys.es.osaka-u.ac.jp
00006  *         shinsaku@sys.es.osaka-u.ac.jp
00007  *         kato@sys.im.hiroshima-cu.ac.jp
00008  *
00009  * Revision: 4.1
00010  * Date: 01/12/07
00011  *
00012 *******************************************************/
00013 
00014 #include <stdio.h>
00015 #include <math.h>
00016 #include <AR/param.h>
00017 #include <AR/matrix.h>
00018 
00019 static double norm( double a, double b, double c );
00020 static double dot( double a1, double a2, double a3,
00021                    double b1, double b2, double b3 );
00022 
00023 int  arParamDecomp( ARParam *source, ARParam *icpara, double trans[3][4] )
00024 {
00025     icpara->xsize          = source->xsize;
00026     icpara->ysize          = source->ysize;
00027     icpara->dist_factor[0] = source->dist_factor[0];
00028     icpara->dist_factor[1] = source->dist_factor[1];
00029     icpara->dist_factor[2] = source->dist_factor[2];
00030     icpara->dist_factor[3] = source->dist_factor[3];
00031 
00032     return arParamDecompMat( source->mat, icpara->mat, trans );
00033 }
00034 
00035 int  arParamDecompMat( double source[3][4], double cpara[3][4], double trans[3][4] )
00036 {
00037     int       r, c;
00038     double    Cpara[3][4];
00039     double    rem1, rem2, rem3;
00040 
00041     if( source[2][3] >= 0 ) {
00042         for( r = 0; r < 3; r++ ){
00043             for( c = 0; c < 4; c++ ){
00044                 Cpara[r][c] = source[r][c];
00045             }
00046         }
00047     }
00048     else {
00049         for( r = 0; r < 3; r++ ){
00050             for( c = 0; c < 4; c++ ){
00051                 Cpara[r][c] = -(source[r][c]);
00052             }
00053         }
00054     }
00055 
00056     for( r = 0; r < 3; r++ ){
00057         for( c = 0; c < 4; c++ ){
00058             cpara[r][c] = 0.0;
00059         }
00060     }
00061     cpara[2][2] = norm( Cpara[2][0], Cpara[2][1], Cpara[2][2] );
00062     trans[2][0] = Cpara[2][0] / cpara[2][2];
00063     trans[2][1] = Cpara[2][1] / cpara[2][2];
00064     trans[2][2] = Cpara[2][2] / cpara[2][2];
00065     trans[2][3] = Cpara[2][3] / cpara[2][2];
00066         
00067     cpara[1][2] = dot( trans[2][0], trans[2][1], trans[2][2],
00068                        Cpara[1][0], Cpara[1][1], Cpara[1][2] );
00069     rem1 = Cpara[1][0] - cpara[1][2] * trans[2][0];
00070     rem2 = Cpara[1][1] - cpara[1][2] * trans[2][1];
00071     rem3 = Cpara[1][2] - cpara[1][2] * trans[2][2];
00072     cpara[1][1] = norm( rem1, rem2, rem3 );
00073     trans[1][0] = rem1 / cpara[1][1];
00074     trans[1][1] = rem2 / cpara[1][1];
00075     trans[1][2] = rem3 / cpara[1][1];
00076 
00077     cpara[0][2] = dot( trans[2][0], trans[2][1], trans[2][2],
00078                        Cpara[0][0], Cpara[0][1], Cpara[0][2] );
00079     cpara[0][1] = dot( trans[1][0], trans[1][1], trans[1][2],
00080                        Cpara[0][0], Cpara[0][1], Cpara[0][2] );
00081     rem1 = Cpara[0][0] - cpara[0][1]*trans[1][0] - cpara[0][2]*trans[2][0];
00082     rem2 = Cpara[0][1] - cpara[0][1]*trans[1][1] - cpara[0][2]*trans[2][1];
00083     rem3 = Cpara[0][2] - cpara[0][1]*trans[1][2] - cpara[0][2]*trans[2][2];
00084     cpara[0][0] = norm( rem1, rem2, rem3 );
00085     trans[0][0] = rem1 / cpara[0][0];
00086     trans[0][1] = rem2 / cpara[0][0];
00087     trans[0][2] = rem3 / cpara[0][0];
00088 
00089     trans[1][3] = (Cpara[1][3] - cpara[1][2]*trans[2][3]) / cpara[1][1];
00090     trans[0][3] = (Cpara[0][3] - cpara[0][1]*trans[1][3]
00091                                - cpara[0][2]*trans[2][3]) / cpara[0][0];
00092 
00093     for( r = 0; r < 3; r++ ){
00094         for( c = 0; c < 3; c++ ){
00095             cpara[r][c] /= cpara[2][2];
00096         }
00097     }
00098 
00099     return 0;
00100 }
00101 
00102 int arsParamGetMat( double matL[3][4], double matR[3][4],
00103                     double cparaL[3][4], double cparaR[3][4], double matL2R[3][4] )
00104 {
00105     ARMat    *t1, *t2, *t3;
00106     double   transL[3][4], transR[3][4];
00107     int      i, j;
00108 
00109     arParamDecompMat( matL, cparaL, transL );
00110     arParamDecompMat( matR, cparaR, transR );
00111 
00112     t1 = arMatrixAlloc( 4, 4 );
00113     t2 = arMatrixAlloc( 4, 4 );
00114     for( j = 0; j < 3; j++ ) {
00115        for( i = 0; i < 4; i++ ) {
00116             t1->m[j*4+i] = transL[j][i];
00117             t2->m[j*4+i] = transR[j][i];
00118         }
00119     }
00120     t1->m[12] = t1->m[13] = t1->m[14] = 0.0;
00121     t1->m[15] = 1.0;
00122     t2->m[12] = t2->m[13] = t2->m[14] = 0.0;
00123     t2->m[15] = 1.0;
00124 
00125     if( arMatrixSelfInv(t1) != 0 ) {
00126         arMatrixFree( t1 );
00127         arMatrixFree( t2 );
00128         return -1;
00129     }
00130     t3 = arMatrixAllocMul(t2, t1);
00131     if( t3 == NULL ) {
00132         arMatrixFree( t1 );
00133         arMatrixFree( t2 );
00134         return -1;
00135     }
00136 
00137     for( j = 0; j < 3; j++ ) {
00138        for( i = 0; i < 4; i++ ) {
00139             matL2R[j][i] = t3->m[j*4+i];
00140         }
00141     }
00142 
00143     arMatrixFree( t1 );
00144     arMatrixFree( t2 );
00145     arMatrixFree( t3 );
00146 
00147     return 0;
00148 }
00149 
00150 
00151 static double norm( double a, double b, double c )
00152 {
00153     return( sqrt( a*a + b*b + c*c ) );
00154 }
00155 
00156 static double dot( double a1, double a2, double a3,
00157                    double b1, double b2, double b3 )
00158 {
00159     return( a1 * b1 + a2 * b2 + a3 * b3 );
00160 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines


ar_recog
Author(s): Graylin Trevor Jay and Christopher Crick
autogenerated on Fri Jan 25 2013 12:15:00