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  

testcox.c

Go to the documentation of this file.
00001 #include "cox_render.h"
00002 
00003 int main( int argc , char * argv[] )
00004 {
00005    THD_3dim_dataset *dset ;
00006    int iarg=1 ;
00007    char *cc1="x",*cc2="y",*cc3="z" ;
00008    float th1=0.0, th2=0.0, th3=0.0 ;
00009    float thx,thy,thz ;
00010    int   axx,ayy,azz ;
00011    char *fname="testcox.ppm" , fn[128] ;
00012    void * rhand ;
00013    int bot=1 , ii , nim=0 ;
00014    float omap[128] , bfac ;
00015    MRI_IMAGE * im , * brim ;
00016    int hbr[256] , nperc,ibot,itop,sum ;
00017    byte * bar ;
00018    double ctim ;
00019    int imode=CREN_TWOSTEP ;
00020 
00021    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00022       printf("Usage: testcox [-rotate a b c] [-out f] [-bot b] [-nn|-ts|-li] dset\n") ;
00023       exit(0) ;
00024    }
00025 
00026    enable_mcw_malloc() ;
00027 
00028    while( iarg < argc && argv[iarg][0] == '-' ){
00029 
00030       if( strcmp(argv[iarg],"-nn") == 0 ){
00031          imode = CREN_NN ;
00032          iarg++ ; continue ;
00033       }
00034 
00035       if( strcmp(argv[iarg],"-ts") == 0 ){
00036          imode = CREN_TWOSTEP ;
00037          iarg++ ; continue ;
00038       }
00039 
00040       if( strcmp(argv[iarg],"-li") == 0 ){
00041          imode = CREN_LINEAR ;
00042          iarg++ ; continue ;
00043       }
00044 
00045       if( strcmp(argv[iarg],"-bot") == 0 ){
00046          bot = strtod( argv[++iarg] , NULL ) ;
00047          iarg++ ; continue ;
00048       }
00049 
00050       if( strcmp(argv[iarg],"-rotate") == 0 ){
00051          th1 = (PI/180.0) * strtod( argv[++iarg] , &cc1 ) ;
00052          th2 = (PI/180.0) * strtod( argv[++iarg] , &cc2 ) ;
00053          th3 = (PI/180.0) * strtod( argv[++iarg] , &cc3 ) ;
00054 
00055          iarg++ ; continue ;
00056       }
00057 
00058       if( strcmp(argv[iarg],"-out") == 0 ){
00059          fname = argv[++iarg] ;
00060          iarg++ ; continue ;
00061       }
00062 
00063       fprintf(stderr,"Illegal option: %s\n",argv[iarg]); exit(1);
00064    }
00065 
00066    if( iarg >= argc ){fprintf(stderr,"No dataset?\n"); exit(1); }
00067 
00068    dset = THD_open_dataset( argv[iarg] ) ;
00069    if( dset == NULL ){fprintf(stderr,"Can't open dataset!\n");exit(1);}
00070    if( DSET_BRICK_TYPE(dset,0) != MRI_byte ){
00071       fprintf(stderr,"Non-byte dataset input!\n");exit(1);
00072    }
00073    DSET_mallocize(dset) ; DSET_load(dset) ;
00074    if( !DSET_LOADED(dset) ){
00075       fprintf(stderr,"Can't load dataset!\n");exit(1);
00076    }
00077 
00078    rhand = new_CREN_renderer() ;
00079 
00080 #if 0
00081    THD_rotangle_user_to_dset( dset ,
00082                               th1,*cc1  , th2,*cc2  , th3,*cc3 ,
00083                               &thx,&axx , &thy,&ayy , &thz,&azz ) ;
00084    CREN_set_viewpoint( rhand , axx,thx,ayy,thy,azz,thz ) ;
00085 #else
00086    CREN_set_angles( rhand , th1,th2,th3 ) ;
00087 #endif
00088 
00089    for( ii=0 ; ii < 128 ; ii++ )
00090       omap[ii] = (ii <= bot) ? 0.0
00091                              : (ii-bot)/(127.0-bot) ;
00092 
00093    CREN_set_opamap( rhand , omap , 1.0 ) ;
00094 
00095    brim = DSET_BRICK(dset,0) ; bar = MRI_BYTE_PTR(brim) ;
00096    mri_histobyte( brim , hbr ) ;
00097    nperc = 0.02 * brim->nvox ;
00098    for( sum=0,ibot=0   ; ibot < 128  && sum < nperc ; ibot++ ) sum += hbr[ibot] ;
00099    for( sum=0,itop=255 ; itop > ibot && sum < nperc ; itop-- ) sum += hbr[itop] ;
00100    if( ibot >= itop ){ ibot = 64 ; itop = 192 ; }
00101    bfac = 127.5 / (itop-ibot) ;
00102    for( ii=0 ; ii < brim->nvox ; ii++ )
00103            if( bar[ii] <= ibot ) bar[ii] = 0 ;
00104       else if( bar[ii] >= itop ) bar[ii] = 127 ;
00105       else                       bar[ii] = bfac * (bar[ii]-ibot) ;
00106 
00107 
00108    ctim = COX_cpu_time() ;
00109 
00110    CREN_set_databytes( rhand , brim->nx,brim->ny,brim->nz , bar ) ;
00111    CREN_dset_axes( rhand , dset ) ;
00112 
00113 #if 0
00114    CREN_set_render_mode( rhand , CREN_MIP_OPA ) ;
00115 #endif
00116 
00117    CREN_set_interp( rhand , imode ) ;
00118 
00119    for( th3=0 ; th3 < 360.0 ; th3+=5.0 ){
00120       CREN_set_angles( rhand , th1,th2,(PI/180.0)*th3 ) ;
00121       im = CREN_render( rhand, NULL ) ;  /* added NULL   2002.08.28 - rickr */
00122       if( im == NULL ){
00123         fprintf(stderr,"renderer fails!\n") ; exit(1) ;
00124       }
00125 
00126       sprintf(fn,"tc%03d.ppm",(int)rint(th3)) ;
00127       mri_write_pnm( fn, im ) ;
00128       fprintf(stderr,"+++ Output to file %s\n",fn);
00129       mri_free(im) ; nim++ ;
00130    }
00131    ctim = COX_cpu_time() - ctim ;
00132    fprintf(stderr,"+++ Rendering CPU time = %g s = %g/im\n",ctim,ctim/nim) ;
00133 
00134    exit(0) ;
00135 }
 

Powered by Plone

This site conforms to the following standards: