Doxygen Source Code Documentation
3dLRflip.c File Reference
#include "mrilib.h"
Go to the source code of this file.
Functions | |
int | main (int argc, char *argv[]) |
Function Documentation
|
compute the overall minimum and maximum voxel values for a dataset Definition at line 3 of file 3dLRflip.c. References ADN_none, ADN_prefix, AFNI_logger(), argc, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_load, DSET_LOADED, DSET_mallocize, DSET_NVALS, DSET_NX, DSET_NY, DSET_NZ, DSET_write, EDIT_dset_items(), free, THD_3dim_dataset::idcode, ISVALID_DSET, machdep(), mainENTRY, MCW_new_idcode, nz, ORI_L2R_TYPE, ORI_R2L_TYPE, STORAGE_BY_BRICK, THD_diskptr::storage_mode, THD_filename_ok(), THD_get_dset_row(), THD_open_dataset(), THD_put_dset_row(), tross_Make_History(), THD_dataxes::xxorient, THD_dataxes::yyorient, and THD_dataxes::zzorient.
00004 { 00005 THD_3dim_dataset *dset ; 00006 int iarg=1 ; 00007 char *prefix = "flip" ; 00008 void *row ; 00009 int nx,ny,nz , ii,jj,kk , dcode , ival ; 00010 00011 if( argc < 2 || strcmp(argv[1],"-help") == 0 ){ 00012 printf("Usage: 3dLRflip [-prefix ppp] dataset\n" 00013 "Flips the Left-to-Right rows of a dataset.\n" 00014 ) ; 00015 exit(0) ; 00016 } 00017 00018 mainENTRY("3dLRflip main"); machdep(); AFNI_logger("3dLRflip",argc,argv); 00019 00020 while( argv[iarg][0] == '-' ){ 00021 00022 if( strcmp(argv[iarg],"-prefix") == 0 ){ 00023 prefix = argv[++iarg] ; 00024 if( !THD_filename_ok(prefix) ){ 00025 fprintf(stderr,"** Illegal prefix: %s\n",prefix); exit(1); 00026 } 00027 iarg++ ; continue ; 00028 } 00029 } 00030 00031 /*-- read data --*/ 00032 00033 dset = THD_open_dataset(argv[iarg]) ; 00034 if( !ISVALID_DSET(dset) ){ fprintf(stderr,"** CAN'T open dataset\n");exit(1); } 00035 DSET_mallocize(dset) ; DSET_load(dset) ; 00036 if( !DSET_LOADED(dset) ){ fprintf(stderr,"** CAN'T load dataset\n");exit(1); } 00037 00038 nx=DSET_NX(dset); ny=DSET_NY(dset); nz=DSET_NZ(dset); 00039 00040 if( dset->daxes->xxorient == ORI_R2L_TYPE || 00041 dset->daxes->xxorient == ORI_L2R_TYPE ) dcode = 1 ; 00042 else 00043 if( dset->daxes->yyorient == ORI_R2L_TYPE || 00044 dset->daxes->yyorient == ORI_L2R_TYPE ) dcode = 2 ; 00045 else 00046 if( dset->daxes->zzorient == ORI_R2L_TYPE || 00047 dset->daxes->zzorient == ORI_L2R_TYPE ) dcode = 3 ; 00048 else 00049 { fprintf(stderr,"** Dataset has no L-R axis!\n"); exit(1); } 00050 00051 /* modify dataset name */ 00052 00053 dset->dblk->diskptr->storage_mode = STORAGE_BY_BRICK ; /* 14 Jan 2004 */ 00054 dset->idcode = MCW_new_idcode() ; /* 24 Aug 2003 - ooops */ 00055 EDIT_dset_items( dset , ADN_prefix , prefix , ADN_none ) ; 00056 tross_Make_History( "3dLRflip", argc,argv, dset ) ; 00057 00058 /* loop over bricks */ 00059 00060 for( ival=0 ; ival < DSET_NVALS(dset) ; ival++ ){ 00061 00062 switch( dcode ){ 00063 00064 case 1: /* flip x-axis rows */ 00065 for( kk=0 ; kk < nz ; kk++ ) 00066 for( jj=0 ; jj < ny ; jj++ ){ 00067 row = THD_get_dset_row( dset , ival , -dcode , 0,jj,kk ) ; 00068 THD_put_dset_row( dset , ival , dcode , 0,jj,kk , row ) ; 00069 free(row) ; 00070 } 00071 break ; 00072 00073 case 2: /* flip y-axis rows */ 00074 for( kk=0 ; kk < nz ; kk++ ) 00075 for( ii=0 ; ii < nx ; ii++ ){ 00076 row = THD_get_dset_row( dset , ival , -dcode , ii,0,kk ) ; 00077 THD_put_dset_row( dset , ival , dcode , ii,0,kk , row ) ; 00078 free(row) ; 00079 } 00080 break ; 00081 00082 case 3: /* flip z-axis rows */ 00083 for( jj=0 ; jj < ny ; jj++ ) 00084 for( ii=0 ; ii < nx ; ii++ ){ 00085 row = THD_get_dset_row( dset , ival , -dcode , ii,jj,0 ) ; 00086 THD_put_dset_row( dset , ival , dcode , ii,jj,0 , row ) ; 00087 free(row) ; 00088 } 00089 break ; 00090 00091 } 00092 } 00093 00094 /* done */ 00095 00096 DSET_write(dset) ; exit(0) ; 00097 } |