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  

3dZFillin.c

Go to the documentation of this file.
00001 #include "mrilib.h"
00002 
00003 int main( int argc , char * argv[] )
00004 {
00005    int iarg=1 , dcode=0 , maxgap=2 , nftot=0 ;
00006    char * prefix="zfillin" , * dstr=NULL;
00007    THD_3dim_dataset * inset , * outset ;
00008    MRI_IMAGE * brim ;
00009    int verb=0 ;
00010 
00011    if( argc < 2 || strcmp(argv[1],"-help") == 0 ){
00012       printf("Usage: 3dZFillin [options] dataset\n"
00013              "Extracts 1D rows in the given direction from a 3D dataset,\n"
00014              "searches for zeros that are 'close' to nonzero values in the row,\n"
00015              "and replaces the zeros with the closest nonzero neighbor.\n"
00016              "\n"
00017              "OPTIONS:\n"
00018              " -maxstep N  = set the maximum distance to a neighbor\n"
00019              "                [default=2].\n"
00020              " -dir D     = set the direction of fill to 'D', which can\n"
00021              "                be one of the following:\n"
00022              "                  A-P, P-A, I-S, S-I, L-R, R-L, x, y, z\n"
00023              "                The first 6 are anatomical directions;\n"
00024              "                the last 3 are reference to the dataset\n"
00025              "                internal axes [no default value].\n"
00026              " -prefix P  = set the prefix to 'P' for the output dataset.\n"
00027              "\n"
00028              "N.B.: * If the input dataset has more than one sub-brick,\n"
00029              "        only the first one will be processed.\n"
00030              "      * At this time, 3dZFillin only works on byte-valued datasets\n"
00031              "\n"
00032              "This program's only purpose is to fill up the Talairach Daemon\n"
00033              "bricks obtained from the UT San Antonio database.\n"
00034              "\n"
00035             ) ;
00036       exit(0) ;
00037    }
00038 
00039    mainENTRY("3dZFillin main") ; machdep() ; AFNI_logger("3dZfillin",argc,argv) ;
00040    PRINT_VERSION(3dZFillin") ;
00041 
00042    /*-- scan args --*/
00043 
00044    while( iarg < argc && argv[iarg][0] == '-' ){
00045 
00046       if( strncmp(argv[iarg],"-verb",5) == 0 ){
00047          verb++ ; iarg++ ; continue ;
00048       }
00049 
00050       if( strcmp(argv[iarg],"-prefix") == 0 ){
00051          prefix = argv[++iarg] ;
00052          if( !THD_filename_ok(prefix) ){
00053             fprintf(stderr,"*** Illegal string after -prefix!\n"); exit(1) ;
00054          }
00055          iarg++ ; continue ;
00056       }
00057 
00058       if( strcmp(argv[iarg],"-maxstep") == 0 ){
00059          maxgap = strtol( argv[++iarg] , NULL , 10 ) ;
00060          if( maxgap < 1 ){
00061             fprintf(stderr,"*** Illegal value after -maxgap!\n"); exit(1);
00062          }
00063          iarg++ ; continue ;
00064       }
00065 
00066       if( strcmp(argv[iarg],"-dir") == 0 ){
00067          dstr = argv[++iarg] ;
00068          iarg++ ; continue ;
00069       }
00070 
00071       fprintf(stderr,"*** Illegal option: %s\n",argv[iarg]) ; exit(1) ;
00072    }
00073 
00074    if( dstr == NULL ){
00075       fprintf(stderr,"*** No -dir option on command line!\n"); exit(1);
00076    }
00077    if( iarg >= argc ){
00078       fprintf(stderr,"*** No input dataset on command line!\n"); exit(1);
00079    }
00080 
00081    inset = THD_open_dataset( argv[iarg] ) ;
00082    if( inset == NULL ){
00083       fprintf(stderr,"*** Can't open dataset %s\n",argv[iarg]); exit(1);
00084    }
00085 
00086    outset = EDIT_empty_copy( inset ) ;
00087    EDIT_dset_items( outset , ADN_prefix , prefix , ADN_none ) ;
00088    if( THD_is_file( DSET_HEADNAME(outset) ) ){
00089       fprintf(stderr,"** Output file %s exists -- cannot overwrite!\n",
00090               DSET_HEADNAME(outset) ) ;
00091       exit(1) ;
00092    }
00093 
00094    tross_Copy_History( inset , outset ) ;
00095    tross_Make_History( "3dZFillin" , argc,argv , outset ) ;
00096 
00097    if( DSET_NVALS(inset) > 1 ){
00098       fprintf(stderr,"++ WARNING: input dataset has more than one sub-brick!\n");
00099       EDIT_dset_items( outset ,
00100                          ADN_ntt   , 0 ,
00101                          ADN_nvals , 1 ,
00102                        ADN_none ) ;
00103    }
00104 
00105    if( DSET_BRICK_TYPE(outset,0) != MRI_byte ){
00106       fprintf(stderr,"*** This program only works on byte datasets!\n");
00107       exit(1) ;
00108    }
00109 
00110    switch( *dstr ){
00111       case 'x': dcode = 1 ; break ;
00112       case 'y': dcode = 2 ; break ;
00113       case 'z': dcode = 3 ; break ;
00114 
00115       default:
00116         if( *dstr == ORIENT_tinystr[outset->daxes->xxorient][0] ||
00117             *dstr == ORIENT_tinystr[outset->daxes->xxorient][1]   ) dcode = 1 ;
00118 
00119         if( *dstr == ORIENT_tinystr[outset->daxes->yyorient][0] ||
00120             *dstr == ORIENT_tinystr[outset->daxes->yyorient][1]   ) dcode = 2 ;
00121 
00122         if( *dstr == ORIENT_tinystr[outset->daxes->zzorient][0] ||
00123             *dstr == ORIENT_tinystr[outset->daxes->zzorient][1]   ) dcode = 3 ;
00124       break ;
00125    }
00126    if( dcode == 0 ){
00127       fprintf(stderr,"*** Illegal -dir direction!\n") ; exit(1) ;
00128    }
00129    if( verb )
00130       fprintf(stderr,"++ Direction = axis %d in dataset\n",dcode) ;
00131 
00132    DSET_load(inset) ;
00133    if( !DSET_LOADED(inset) ){
00134       fprintf(stderr,"*** Can't load dataset %s\n",argv[iarg]); exit(1);
00135    }
00136    brim = mri_copy( DSET_BRICK(inset,0) ) ;
00137    DSET_unload(inset) ;
00138    EDIT_substitute_brick( outset , 0 , brim->kind , mri_data_pointer(brim) ) ;
00139    nftot = THD_dataset_zfillin( outset , 0 , dcode , maxgap ) ;
00140    fprintf(stderr,"++ Number of voxels filled = %d\n",nftot) ;
00141    DSET_write(outset) ;
00142    fprintf(stderr,"++ output dataset: %s\n",DSET_BRIKNAME(outset)) ;
00143    exit(0) ;
00144 }
 

Powered by Plone

This site conforms to the following standards: