Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

qunrot.c

Go to the documentation of this file.
00001 #define FLOAT_TYPE double  /* must be same as in thd_rot3d.c */
00002 #include "vecmat.h"
00003 #include "mrilib.h"
00004 
00005 /**********************************************************************************/
00006 
00007 #define ERREX(str) (fprintf(stderr,"*** %s\n",str),exit(1))
00008 
00009 int main( int argc , char * argv[] )
00010 {
00011    MRI_IMAGE * vecim ;
00012    float * vecar ;
00013    THD_fvec3 * xx , * yy ;
00014    int nvec , ii ;
00015    THD_vecmat rt ;
00016    char a[32],b[32],c[32],d[32] , *s ;
00017 
00018    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00019       printf("Usage: 3dTagalign vecfile1 vecfile2\n") ; exit(0) ;
00020    }
00021 
00022    /*-*/
00023 
00024    vecim = mri_read_ascii( argv[1] ) ;
00025    if( vecim == NULL ) ERREX("Can't open vecfile1\n") ;
00026    if( vecim->nx != 3 || vecim->ny < 4 ) ERREX("vecfile1 badly formed") ;
00027    nvec = vecim->ny ;
00028    vecar = MRI_FLOAT_PTR(vecim) ;
00029 
00030    xx = (THD_fvec3 *) malloc( sizeof(THD_fvec3) * nvec ) ;
00031    for( ii=0 ; ii < nvec ; ii++ ){
00032       LOAD_FVEC3( xx[ii] , vecar[3*ii+0],vecar[3*ii+1],vecar[3*ii+2]) ;
00033    }
00034    mri_free(vecim) ;
00035 
00036    /*-*/
00037 
00038    vecim = mri_read_ascii( argv[2] ) ;
00039    if( vecim == NULL ) ERREX("Can't open vecfile2\n") ;
00040    if( vecim->nx != 3 || vecim->ny != nvec ) ERREX("vecfile2 badly formed") ;
00041    vecar = MRI_FLOAT_PTR(vecim) ;
00042 
00043    yy = (THD_fvec3 *) malloc( sizeof(THD_fvec3) * nvec ) ;
00044    for( ii=0 ; ii < nvec ; ii++ ){
00045       LOAD_FVEC3( yy[ii] , vecar[3*ii+0],vecar[3*ii+1],vecar[3*ii+2]) ;
00046    }
00047    mri_free(vecim) ;
00048 
00049    rt = LSQ_rot_trans( nvec , xx , yy , NULL ) ;
00050 
00051    for( ii=0 ; ii < 3 ; ii++ ){
00052       s = MV_format_fval( rt.mm.mat[ii][0] ) ; strcpy(a,s) ;
00053       s = MV_format_fval( rt.mm.mat[ii][1] ) ; strcpy(b,s) ;
00054       s = MV_format_fval( rt.mm.mat[ii][2] ) ; strcpy(c,s) ;
00055       s = MV_format_fval( rt.vv.xyz[ii]    ) ; strcpy(d,s) ;
00056       printf("%s %s %s %s\n",a,b,c,d) ;
00057    }
00058 
00059    exit(0) ;
00060 }
 

Powered by Plone

This site conforms to the following standards: