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  

3dOverlap.c File Reference

#include "mrilib.h"

Go to the source code of this file.


Functions

int main (int argc, char *argv[])

Function Documentation

int main int    argc,
char *    argv[]
 

---------- Adapted from 3dZeropad.c by RWCox - 08 Aug 2001 ----------*

Definition at line 3 of file 3dOverlap.c.

References addto_args(), ADN_brick_fac, ADN_datum_all, ADN_func_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, AFNI_logger(), argc, calloc, DSET_delete, DSET_HEADNAME, DSET_load, DSET_LOADED, DSET_NVALS, DSET_NVOX, DSET_write, EDIT_dset_items(), EDIT_empty_copy(), EDIT_substitute_brick(), free, FUNC_FIM_TYPE, ISFUNC, machdep(), mainENTRY, mmm, PRINT_VERSION, THD_filename_ok(), THD_is_file(), THD_makemask(), THD_open_dataset(), tross_Copy_History(), and tross_Make_History().

00004 {
00005    int narg , nvox=0 , iv,ii,cnum ;
00006    THD_3dim_dataset * xset , * oset=NULL ;
00007    byte *mmm=NULL ;
00008    short *ccc=NULL , ctop ;
00009    char *psave=NULL ;       /* 22 Feb 2001 */
00010 
00011    /*-- read command line arguments --*/
00012 
00013    if( argc < 2 || strncmp(argv[1],"-help",5) == 0 ){
00014       printf("Usage: 3dOverlap [options] dset1 dset2 ...\n"
00015              "Output = count of number of voxels that are nonzero in ALL\n"
00016              "         of the input dataset sub-bricks\n"
00017              "The result is simply a number printed to stdout.  (If a single\n"
00018              "brick was input, this is just the count of the number of nonzero\n"
00019              "voxels in that brick.)\n"
00020              "Options:\n"
00021              "  -save ppp = Save the count of overlaps at each voxel into a\n"
00022              "              dataset with prefix 'ppp' (properly thresholded,\n"
00023              "              this could be used as a mask dataset).\n"
00024              "Example:\n"
00025              "  3dOverlap -save abcnum a+orig b+orig c+orig\n"
00026              "  3dmaskave -mask 'abcnum+orig<3..3>' a+orig\n"
00027             ) ;
00028       exit(0) ;
00029    }
00030 
00031    narg = 1 ;
00032 
00033    /*-- 20 Apr 2001: addto the arglist, if user wants to [RWCox] --*/
00034 
00035    mainENTRY("3dOverlap main") ; machdep() ; PRINT_VERSION("3dOverlap") ;
00036 
00037    { int new_argc ; char ** new_argv ;
00038      addto_args( argc , argv , &new_argc , &new_argv ) ;
00039      if( new_argv != NULL ){ argc = new_argc ; argv = new_argv ; }
00040    }
00041 
00042    AFNI_logger("3dOverlap",argc,argv) ;
00043 
00044    /* check options */
00045 
00046    while( narg < argc && argv[narg][0] == '-' ){
00047 
00048       if( strcmp(argv[narg],"-save") == 0 ){  /* 22 Feb 2001 */
00049          psave = argv[++narg] ;
00050          if( !THD_filename_ok(psave) ){
00051             fprintf(stderr,"** Illegal -save prefix!\n") ; exit(1) ;
00052          }
00053          narg++ ; continue ;
00054       }
00055 
00056       fprintf(stderr,"** Illegal option: %s\n",argv[narg]) ; exit(1) ;
00057    }
00058 
00059    /* loop over input datasets */
00060 
00061    ctop = 0 ;                      /* count of bricks */
00062    for( ; narg < argc ; narg++ ){
00063 
00064       xset = THD_open_dataset( argv[narg] ) ;
00065       if( xset == NULL ){
00066          fprintf(stderr,"*** Can't open dataset %s\n",argv[narg]); exit(1);
00067       }
00068       DSET_load(xset) ;
00069       if( !DSET_LOADED(xset) ){
00070          fprintf(stderr,"*** Can't load dataset %s\n",argv[narg]); exit(1);
00071       }
00072 
00073       if( nvox == 0 ){
00074          nvox = DSET_NVOX(xset) ; ccc = calloc(sizeof(short),nvox) ;
00075       } else if( DSET_NVOX(xset) != nvox ){
00076          fprintf(stderr,"*** Dataset %s doesn't match in size!\n",argv[narg]); exit(1);
00077       }
00078 
00079       for( iv=0 ; iv < DSET_NVALS(xset) ; iv++ ){
00080          mmm = THD_makemask( xset , iv , 1.0,-1.0 ) ;
00081          if( mmm == NULL ){
00082             fprintf(stderr,"*** %s[%d] counting fails!\n",argv[narg],iv); exit(1);
00083          }
00084          for( ii=0 ; ii < nvox ; ii++ ) if( mmm[ii] ) ccc[ii]++ ;
00085          free(mmm) ; ctop++ ;
00086       }
00087 
00088       if( psave != NULL && oset == NULL ){  /* 22 Feb 2001: make output dataset */
00089          oset = EDIT_empty_copy(xset) ;
00090          EDIT_dset_items( oset ,
00091                              ADN_prefix    , psave ,
00092                              ADN_nvals     , 1 ,
00093                              ADN_ntt       , 0 ,
00094                              ADN_brick_fac , NULL ,
00095                              ADN_datum_all , MRI_short ,
00096                           ADN_none ) ;
00097 
00098          if( ISFUNC(oset) )
00099             EDIT_dset_items( oset , ADN_func_type,FUNC_FIM_TYPE , ADN_none ) ;
00100 
00101          tross_Copy_History( xset , oset ) ;
00102          tross_Make_History( "3dOverlap" , argc,argv , oset ) ;
00103 
00104          if( THD_is_file(DSET_HEADNAME(oset)) ){
00105             fprintf(stderr,
00106                     "** Output file %s already exists -- will not overwrite!\n",
00107                     DSET_HEADNAME(oset) ) ;
00108             DSET_delete(oset) ; oset = NULL ; psave = NULL ;
00109           }
00110       }
00111 
00112       DSET_delete(xset) ;
00113    }
00114 
00115    /* tot up the results */
00116 
00117    cnum = 0 ;
00118    for( ii=0 ; ii < nvox ; ii++ ) if( ccc[ii] == ctop ) cnum++ ;
00119    printf("%d\n",cnum) ;
00120 
00121    if( oset != NULL ){
00122       EDIT_substitute_brick( oset , 0 , MRI_short , ccc ) ;
00123       DSET_write(oset) ;
00124    }
00125 
00126    exit(0) ;
00127 }
 

Powered by Plone

This site conforms to the following standards: