char * STAVG_main( PLUGIN_interface * plint ) { MCW_idcode * idc ; /* input dataset idcode */ THD_3dim_dataset * old_dset , * new_dset ; /* input and output datasets */ char * new_prefix , * str , * str2; /* strings from user */ int meth; /* chosen computation method */ int new_datum , /* control parameters */ old_datum , ntime ; int te, ne, tinc, kim, nia; int numepochs, minlength, maxlength, lastindex, navgpts; int nvox , perc , new_units, old_units ; int ii, ibot,itop , kk, jj; int no1, user_maxlength, delta; int *pEpochLength, *pTimeIndex; int nx, ny, nz, npix; float *pNumAvg; float old_dtime; MRI_IMAGE * stimim; MRI_IMARR *avgimar; byte ** bptr = NULL ; /* one of these will be the array of */ short ** sptr = NULL ; /* pointers to input dataset sub-bricks */ float ** fptr = NULL ; /* (depending on input datum type) */ float * fxar = NULL ; /* array loaded from input dataset */ float * stimar = NULL ; float ** fout = NULL ; /* will be array of output floats */ float * tar = NULL ; /* will be array of taper coefficients */ float * nstimar; /*--------------------------------------------------------------------*/ /*----- Check inputs from AFNI to see if they are reasonable-ish -----*/ /*--------- go to first input line ---------*/ PLUTO_next_option(plint) ; idc = PLUTO_get_idcode(plint) ; /* get dataset item */ old_dset = PLUTO_find_dset(idc) ; /* get ptr to dataset */ if( old_dset == NULL ) return "*************************\n" "Cannot find Input Dataset\n" "*************************" ; ntime = DSET_NUM_TIMES(old_dset) ; if( ntime < 2 ) return "*****************************\n" "Dataset has only 1 time point\n" "*****************************" ; ii = DSET_NVALS_PER_TIME(old_dset) ; if( ii > 1 ) return "************************************\n" "Dataset has > 1 value per time point\n" "************************************" ; old_datum = DSET_BRICK_TYPE( old_dset , 0 ) ; /* get old dataset datum type */ new_datum = old_datum; old_dtime = DSET_TIMESTEP(old_dset); old_units = DSET_TIMEUNITS(old_dset); nvox = old_dset->daxes->nxx * old_dset->daxes->nyy * old_dset->daxes->nzz; npix = old_dset->daxes->nxx * old_dset->daxes->nyy; nx = old_dset->daxes->nxx; new_prefix = PLUTO_get_string(plint) ; /* get string item (the output prefix) */ if( ! PLUTO_prefix_ok(new_prefix) ) /* check if it is OK */ return "************************\n" "Output Prefix is illegal\n" "************************" ; /*--------- go to next input line ---------*/ PLUTO_next_option(plint); stimim = PLUTO_get_timeseries(plint); if( stimim == NULL ) return "Please specify stimulus timing"; if( stimim->nx < ntime ){ return "**************************************\n" "Not enough pts in stimulus time-series\n" "**************************************"; } stimar = MRI_FLOAT_PTR(stimim); delta = PLUTO_get_number(plint); if( abs(delta) > ntime ){ return "************************\n" "Delta shift is too large\n" "************************"; } /*initialize variables if not user specified */ user_maxlength = ntime; no1 = 0; /*--------- go to next input line ---------*/ PLUTO_next_option(plint); str = PLUTO_get_string(plint) ; /* get string item (the method) */ meth = PLUTO_string_index( str , /* find it in list it is from */ _STAVG_NUM_METHODS , method_strings ) ; /*--------- see if the 4th option line is present --------*/ str = PLUTO_get_optiontag( plint ) ; if( str != NULL ){ user_maxlength = (int) PLUTO_get_number(plint) ; str2 = PLUTO_get_string(plint) ; /* get string item (the method) */ no1 = PLUTO_string_index( str2 , /* find it in list it is from */ 2 , yes_no_strings) ; } /*------------------------------------------------------*/ /*---------- At this point, the inputs are OK ----------*/ PLUTO_popup_meter( plint ) ; /* popup a progress meter */ /*________________[ Main Code ]_________________________*/ fout = avg_epochs( old_dset, stimar, user_maxlength, 1, meth, plint ); if( fout == NULL ) return " \nError in avg_epochs() function!\n " ; if( RMB_DEBUG ) fprintf(stderr, "Done with avg_epochs\n"); maxlength = M_maxlength; /*______________________________________________________*/ new_dset = EDIT_empty_copy( old_dset ) ; /* start with copy of old one */ { char * his = PLUTO_commandstring(plint) ; tross_Copy_History( old_dset , new_dset ) ; tross_Append_History( new_dset , his ) ; free( his ) ; } /*-- edit some of its internal parameters --*/ ii = EDIT_dset_items( new_dset , ADN_prefix , new_prefix , /* filename prefix */ ADN_malloc_type , DATABLOCK_MEM_MALLOC , /* store in memory */ ADN_datum_all , new_datum , /* atomic datum */ ADN_nvals , maxlength , /* # sub-bricks */ ADN_ntt , maxlength , /* # time points */ /* ADN_ttorg , old_dtime , */ /* time origin */ /* ADN_ttdel , old_dtime , */ /* time step */ /* ADN_ttdur , old_dtime , */ /* time duration */ /* ADN_nsl , 0 , */ /* z-axis time slicing */ /* ADN_tunits , old_units , */ /* time units */ ADN_none ) ; if( ii != 0 ){ THD_delete_3dim_dataset( new_dset , False ) ; FREE_WORKSPACE ; return "***********************************\n" "Error while creating output dataset\n" "***********************************" ; } /*------------------------------------------------------------*/ /*------- The output is now in fout[kk][ii], for kk=0..maxlength-1 , ii=0..nvox-1. We must now put this into the output dataset -------*/ switch( new_datum ){ /*** output is floats is the simplest: we just have to attach the fout bricks to the dataset ***/ case MRI_float: for( kk=0 ; kk < maxlength ; kk++ ) EDIT_substitute_brick( new_dset , kk , MRI_float , fout[kk] ) ; break ; /*** output is shorts: we have to create a scaled sub-brick from fout ***/ case MRI_short:{ short * bout ; float fac ; for( kk=0 ; kk < maxlength ; kk++ ){ /* loop over sub-bricks */ /*-- get output sub-brick --*/ bout = (short *) malloc( sizeof(short) * nvox ) ; if( bout == NULL ){ fprintf(stderr,"\nFinal malloc error in plug_stavg!\n\a") ; return("Final malloc error in plug_stavg!"); ; /* exit(1) ;*/ } /*-- find scaling and then scale --*/ /*fac = MCW_vol_amax( nvox,1,1 , MRI_float , fout[kk] ) ;*/ fac = 1.0; EDIT_coerce_scale_type( nvox,fac , MRI_float,fout[kk] , MRI_short,bout ) ; free( fout[kk] ) ; /* don't need this anymore */ /*-- put output brick into dataset, and store scale factor --*/ EDIT_substitute_brick( new_dset , kk , MRI_short , bout ) ; } } break ; /*** output is bytes (byte = unsigned char) we have to create a scaled sub-brick from fout ***/ case MRI_byte:{ byte * bout ; float fac ; for( kk=0 ; kk < maxlength ; kk++ ){ /* loop over sub-bricks */ /*-- get output sub-brick --*/ bout = (byte *) malloc( sizeof(byte) * nvox ) ; if( bout == NULL ){ fprintf(stderr,"\nFinal malloc error in plug_stavg!\n\a") ; return("Final malloc error in plug_stavg!"); ; /* exit(1) ;*/ } /*-- find scaling and then scale --*/ fac = 1.0; EDIT_coerce_scale_type( nvox,fac , MRI_float,fout[kk] , MRI_byte,bout ) ; free( fout[kk] ) ; /* don't need this anymore */ /*-- put output brick into dataset, and store scale factor --*/ EDIT_substitute_brick( new_dset , kk , MRI_byte , bout ) ; } } break ; } /* end of switch on output data type */ /*-------------- Cleanup and go home ----------------*/ PLUTO_set_meter( plint , 100 ) ; /* set progress meter to 100% */ PLUTO_add_dset( plint , new_dset , DSET_ACTION_MAKE_CURRENT ) ; FREE_WORKSPACE ; return NULL ; /* null string returned means all was OK */ }
static void EXTRACT_tsfunc( double T0 , double TR , int npts , float ts[] , double ts_mean , double ts_slope , void * udp , float * dumb) { static int nvox , ncall ; extract_data uda,*ud; float xcor=0.0 , tmp=0.0 , tmp2 = 0.0 , dtx = 0.0 ,\ slp = 0.0 , vts = 0.0 , vrvec = 0.0 , rxcorCoef = 0.0; int i , is_ts_null , status , opt , actv , zpos , ypos , xpos , hit; ud = &uda; ud = (extract_data *) udp; /** is this a "notification"? **/ if( dumb == NULL ){ if( npts > 0 ){ /* the "start notification" */ PLUTO_popup_meter( global_plint ) ; /* progress meter */ nvox = npts ; /* keep track of */ ncall = 0 ; /* number of calls */ } else { /* the "end notification" */ PLUTO_set_meter( global_plint , 100 ) ; /* set meter to 100% */ } return ; } hit = 0; ud->ln = npts; if (ud->iloc != -1) /* for each ncall, find out if this index is wanted*/ { *dumb = ud->fail; for (i=0;i<ud->nrows;++i) { if (ud->indvect[i] == (float)ncall) { hit = 1; *dumb = ud->pass; writets (ud,ts,ncall); i = ud->nrows; } } } else { *dumb = ud->fail; indexTOxyz (ud, ncall, &xpos , &ypos , &zpos); for (i=0;i<ud->nrows;++i) { if (ud->xyzvect[i].x == (float)xpos) { if (ud->xyzvect[i].y == (float)ypos) { if (ud->xyzvect[i].z == (float)zpos) { hit = 1; *dumb = ud->pass; writets (ud,ts,ncall); i = ud->nrows; } } } } } /* the output brick generated here is practically useless, it has 1 at the voxels whos time courses were used and 0 where nothing was extracted */ if (ud->errcode == 0) /* if there are no errors, proceed */ {/* */ }/* ud->errcode == 0 outer loop */ /** set the progress meter to the % of completion **/ ncall++ ; PLUTO_set_meter( global_plint , (100*ncall)/nvox ) ; ud->errcode = 0; /* Rest error to nothing */ return ; }
static char *Fourier_Filter_Driver(PLUGIN_interface *plint, THD_3dim_dataset *input, float low_fc, float high_fc, int ignore, int autocorr, int retrend, char *output_prefix) { #else static char *Fourier_Filter_Driver(THD_3dim_dataset *input, float low_fc, float high_fc, int ignore, int autocorr, int retrend, char *output_prefix) { #endif int i, j; int ntimes, nvox; float **out_data, *out_temp, *scale, *input_data_f, period; byte *input_data_b; short *input_data_s; THD_3dim_dataset *output=NULL; char *err; /* should be a valid 3d+time input */ DSET_load(input); ntimes = DSET_NUM_TIMES(input); nvox = DSET_NVOX(input); /* Create a float array for the output */ out_data = (float **)My_Malloc(ntimes * sizeof(float *)); for (i=0; i<ntimes; out_data[i++] = (float *)My_Malloc(nvox * sizeof(float))); /* Create the tempory float array */ out_temp = (float *)My_Malloc(ntimes*sizeof(float)); /* Get the scale factors for later */ scale = (float *)My_Malloc(ntimes*sizeof(float)); for (i=0; i<ntimes; i++) { if (!DSET_BRICK_FACTOR(input,i)) scale[i] = 1.0; else scale[i] = DSET_BRICK_FACTOR(input,i); } /* get the sampling period */ period = DSET_TIMESTEP(input); switch (DSET_TIMEUNITS(input)) { case UNITS_MSEC_TYPE: {period/=1000; break; } case UNITS_SEC_TYPE: break; case UNITS_HZ_TYPE: return ("FIlter_Driver Error:\nHmm, you would think I could handle a 3d+time that is already\nfrequency, but Im lame"); default: return("Filter_Driver Error:\nI dont understand the units of the 3d+time"); } #ifdef IN_FOURIER_PLUGIN PLUTO_popup_meter(plint); #endif /* Loop over voxels, pull out the time series and filter */ for (i=0; i< nvox; i++) { for (j=0; j<ntimes; j++) { switch(DSET_BRICK_TYPE(input,j)) { case MRI_byte: { input_data_b = (byte *)DSET_ARRAY(input,j); out_temp[j] = scale[j] * (float)input_data_b[i]; break; } case MRI_short: { input_data_s = (short *)DSET_ARRAY(input,j); out_temp[j] = scale[j] * (float)input_data_s[i]; break; } case MRI_float: { input_data_f = (float *)DSET_ARRAY(input,j); out_temp[j] = scale[j] * input_data_f[i]; break; } default : { return("FIlter_Driver Error:\nInvalid data type for one of the sub-bricks"); } } } err = filter(out_temp, low_fc, high_fc, ntimes, period, ignore, retrend, FALSE); if (err != NULL) return err; for(j=0; j<ntimes; j++) out_data[j][i] = out_temp[j]; #ifdef IN_FOURIER_PLUGIN PLUTO_set_meter(plint, (int)(100.0*((float)i/(float)nvox))); #endif } /* create new dataset and convert, etc. */ output = EDIT_empty_copy(input); tross_Copy_History(output,input) ; /* Jul 2010 */ #if defined(ARGC) && defined(ARGV) tross_Make_History( "3dFourier" , ARGC,ARGV , output ) ; #endif j=EDIT_dset_items(output, ADN_prefix, output_prefix, ADN_none); for (j=0; j<ntimes; j++) { switch(DSET_BRICK_TYPE(input,j)) { case MRI_byte: { input_data_b = (byte *)My_Malloc(nvox*sizeof(byte)); for (i=0; i<nvox; i++) input_data_b[i] = (byte)(out_data[j][i] / scale[j]); EDIT_substitute_brick(output, j, MRI_byte, (byte *)input_data_b); break; } case MRI_short: { input_data_s = (short *)My_Malloc(nvox*sizeof(short)); for (i=0; i<nvox; i++) input_data_s[i] = (short)(out_data[j][i] / scale[j]); EDIT_substitute_brick(output, j, MRI_short, (short *)input_data_s); break; } case MRI_float: { input_data_f = (float *)My_Malloc(nvox*sizeof(float)); for (i=0; i<nvox; i++) input_data_f[i] = (float)(out_data[j][i] / scale[j]); EDIT_substitute_brick(output, j, MRI_float, (float *)input_data_f); break; } } #ifdef IN_FOURIER_PLUGIN PLUTO_set_meter(plint, (int)(100.0*((float)j/(float)ntimes))); #endif } /* Write out the new brick at let the memory be free */ #ifdef IN_FOURIER_PLUGIN PLUTO_add_dset(plint, output, DSET_ACTION_MAKE_CURRENT); #else DSET_write(output); #endif DSET_unload(input); DSET_unload(output); for (i=0; i<ntimes; free(out_data[i++])); free (out_data); free (scale); free (out_temp); #ifdef IN_FOURIER_PLUGIN PLUTO_popdown_meter(plint); #endif return NULL; }
static void DELAY_tsfuncV2( double T0 , double TR , int npts , float ts[] , double ts_mean , double ts_slope , void * udp , int nbrick , float * buckar) { static int nvox , ncall ; hilbert_data_V2 uda,*ud; float del, xcorCoef, buckara[4]; float xcor=0.0 , tmp=0.0 , tmp2 = 0.0 , dtx = 0.0 ,\ delu = 0.0 , slp = 0.0 , vts = 0.0 , vrvec = 0.0 ; int i , is_ts_null , status , opt , actv , zpos , ypos , xpos ; ud = &uda; ud = (hilbert_data_V2 *) udp; /** is this a "notification"? **/ if( buckar == NULL ){ if( npts > 0 ){ /* the "start notification" */ PLUTO_popup_meter( global_plint ) ; /* progress meter */ nvox = npts ; /* keep track of */ ncall = 0 ; /* number of calls */ } else { /* the "end notification" */ opt = 0; /* cleanup in hdelay */ #if 0 status = hilbertdelay_V2 (ts,ud->rvec,ud->ln,ud->Nseg,ud->Pover,opt,ud->dtrnd,dtx,ud->biasrem,&tmp,&slp,&xcor,&tmp2,&vts,&vrvec); /* cleanup time */ #else hilbertdelay_V2reset(); #endif PLUTO_set_meter( global_plint , 100 ) ; /* set meter to 100% */ } return ; } /* In the old version, I had to check for a match between the lengths of the reference time series and FMRI time series This is now done before the function is called. */ if (is_vect_null (ts,npts) == 1) /* check for null vectors */ { ud->errcode = ERROR_NULLTIMESERIES; error_report (ud , ncall ); /* report the error */ del = 0.0; /* Set all the variables to Null and don't set xcorCoef to an impossible value*/ xcorCoef = 0.0; /* because the data might still be OK */ xcor = 0.0; } if (ud->errcode == 0) /* if there are no errors, proceed */ {/* ud->errcode == 0 outer loop */ opt = 1; /* activate hdelay */ /* transform dtx from seconds to sampling units and correct for the number of points ignored*/ if (ud->Dsamp == YUP) dtx = (float) (T0 / TR) - ud->ignore; else dtx = 0.0; ud->errcode = hilbertdelay_V2 (ts,ud->rvec,ud->ln,ud->Nseg,ud->Pover,opt,ud->dtrnd,dtx,ud->biasrem,&delu,&slp,&xcor,&xcorCoef,&vts,&vrvec); /* cleanup time */ if (ud->errcode == 0) /* If there are no errors, proceed */ { /*ud->errcode == 0 inner loop */ hunwrap (delu, (float)(1/TR), ud->T, slp, ud->wrp, ud->unt, 0, 1.0, &del ); actv = 1; /* assume voxel is active */ if (xcorCoef < ud->co) actv = 0; /* determine if voxel is activated using xcorCoef */ if ((actv == 1) && (ud->out == YUP)) /* if voxel is truly activated, write results to file without modifying return value */ { indexTOxyz ( ud , ncall, &xpos , &ypos , &zpos); fprintf (ud->outwrite,"%d\t%d\t%d\t%d\t%f\t%f\t%f\t%f\t%f\n", ncall , xpos , ypos , zpos , delu , del , xcor , xcorCoef , vts); if (ud->outts == YUP) { writets (ud,ts); } } }/*ud->errcode == 0 inner loop */ else if (ud->errcode == ERROR_LONGDELAY) { error_report ( ud , ncall); del = 0.0; /* Set all the variables to Null and don't set xcorCoef to an impossible value*/ xcorCoef = 0.0; /* because the data might still be OK */ xcor = 0.0; } else if (ud->errcode != 0) { error_report ( ud , ncall); del = 0.0; /* Set all the variables to Null and set xcorCoef to an impossible value*/ xcorCoef = NOWAYXCORCOEF; xcor = 0.0; } }/* ud->errcode == 0 outer loop */ /* Now fill up the bucket array */ buckar[DELINDX] = del; buckar[COVINDX] = xcor; buckar[COFINDX] = xcorCoef; buckar[VARINDX] = vts; /** set the progress meter to the % of completion **/ ncall++ ; PLUTO_set_meter( global_plint , (100*ncall)/nvox ) ; ud->errcode = 0; /* Rest error to nothing */ return ; }
char * IMREG_main( PLUGIN_interface * plint ) { MCW_idcode * idc ; /* input dataset idcode */ THD_3dim_dataset * old_dset , * new_dset ; /* input and output datasets */ char * new_prefix , * str ; /* strings from user */ int base , ntime , datum , nx,ny,nz , ii,kk , npix ; float dx,dy,dz ; MRI_IMARR * ims_in , * ims_out ; MRI_IMAGE * im , * imbase ; byte ** bptr = NULL , ** bout = NULL ; short ** sptr = NULL , ** sout = NULL ; float ** fptr = NULL , ** fout = NULL ; float * dxar = NULL , * dyar = NULL , * phiar = NULL ; /*--------------------------------------------------------------------*/ /*----- Check inputs from AFNI to see if they are reasonable-ish -----*/ /*--------- go to first input line ---------*/ PLUTO_next_option(plint) ; idc = PLUTO_get_idcode(plint) ; /* get dataset item */ old_dset = PLUTO_find_dset(idc) ; /* get ptr to dataset */ if( old_dset == NULL ) return "*************************\n" "Cannot find Input Dataset\n" "*************************" ; ntime = DSET_NUM_TIMES(old_dset) ; if( ntime < 2 ) return "*****************************\n" "Dataset has only 1 time point\n" "*****************************" ; ii = DSET_NVALS_PER_TIME(old_dset) ; if( ii > 1 ) return "************************************\n" "Dataset has > 1 value per time point\n" "************************************" ; nx = old_dset->daxes->nxx ; dx = old_dset->daxes->xxdel ; ny = old_dset->daxes->nyy ; dy = old_dset->daxes->yydel ; npix = nx*ny ; nz = old_dset->daxes->nzz ; dz = old_dset->daxes->zzdel ; if( nx != ny || fabs(dx) != fabs(dy) ) { #ifdef IMREG_DEBUG fprintf(stderr,"\nIMREG: nx=%d ny=%d nz=%d dx=%f dy=%f dz=%f\n", nx,ny,nz,dx,dy,dz ) ; #endif return "***********************************\n" "Dataset does not have square slices\n" "***********************************" ; } new_prefix = PLUTO_get_string(plint) ; /* get string item (the output prefix) */ if( ! PLUTO_prefix_ok(new_prefix) ) /* check if it is OK */ return "************************\n" "Output Prefix is illegal\n" "************************" ; /*--------- go to next input line ---------*/ PLUTO_next_option(plint) ; base = PLUTO_get_number(plint) ; if( base >= ntime ) return "********************\n" "Base value too large\n" "********************" ; /*--------- see if the 3rd option line is present --------*/ str = PLUTO_get_optiontag( plint ) ; if( str != NULL ) { float fsig , fdxy , fdph ; fsig = PLUTO_get_number(plint) * 0.42466090 ; fdxy = PLUTO_get_number(plint) ; fdph = PLUTO_get_number(plint) ; mri_align_params( 0 , 0.0,0.0,0.0 , fsig,fdxy,fdph ) ; /* fprintf(stderr,"Set fine params = %f %f %f\n",fsig,fdxy,fdph) ; */ } /*------------- ready to compute new dataset -----------*/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: loading dataset\n") ; #endif DSET_load( old_dset ) ; /*** 1) Copy the dataset in toto ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: Copying dataset\n") ; #endif new_dset = PLUTO_copy_dset( old_dset , new_prefix ) ; if( new_dset == NULL ) return "****************************\n" "Failed to copy input dataset\n" "****************************" ; /*** 2) Make an array of empty images ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: making empty images\n") ; #endif datum = DSET_BRICK_TYPE(new_dset,0) ; INIT_IMARR(ims_in) ; for( ii=0 ; ii < ntime ; ii++ ) { im = mri_new_vol_empty( nx , ny , 1 , datum ) ; ADDTO_IMARR(ims_in,im) ; } imbase = mri_new_vol_empty( nx , ny , 1 , datum ) ; dxar = (float *) malloc( sizeof(float) * ntime ) ; dyar = (float *) malloc( sizeof(float) * ntime ) ; phiar = (float *) malloc( sizeof(float) * ntime ) ; /*** 3) Get pointers to sub-bricks in old and new datasets ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: getting input brick pointers\n") ; #endif switch( datum ) { /* pointer type depends on input datum type */ case MRI_byte: bptr = (byte **) malloc( sizeof(byte *) * ntime ) ; bout = (byte **) malloc( sizeof(byte *) * ntime ) ; for( ii=0 ; ii < ntime ; ii++ ) { bptr[ii] = (byte *) DSET_ARRAY(old_dset,ii) ; bout[ii] = (byte *) DSET_ARRAY(new_dset,ii) ; } break ; case MRI_short: sptr = (short **) malloc( sizeof(short *) * ntime ) ; sout = (short **) malloc( sizeof(short *) * ntime ) ; for( ii=0 ; ii < ntime ; ii++ ) { sptr[ii] = (short *) DSET_ARRAY(old_dset,ii) ; sout[ii] = (short *) DSET_ARRAY(new_dset,ii) ; } #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: sptr[0] = %p sout[0] = %p\n",sptr[0],sout[0]) ; #endif break ; case MRI_float: fptr = (float **) malloc( sizeof(float *) * ntime ) ; fout = (float **) malloc( sizeof(float *) * ntime ) ; for( ii=0 ; ii < ntime ; ii++ ) { fptr[ii] = (float *) DSET_ARRAY(old_dset,ii) ; fout[ii] = (float *) DSET_ARRAY(new_dset,ii) ; } break ; } /*** 4) Loop over slices ***/ PLUTO_popup_meter(plint) ; for( kk=0 ; kk < nz ; kk++ ) { /*** 4a) Setup ims_in images to point to input slices ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: slice %d -- setup input images\n",kk) ; #endif for( ii=0 ; ii < ntime ; ii++ ) { im = IMARR_SUBIMAGE(ims_in,ii) ; switch( datum ) { case MRI_byte: mri_fix_data_pointer( bptr[ii] + kk*npix, im ) ; break ; case MRI_short: mri_fix_data_pointer( sptr[ii] + kk*npix, im ) ; break ; case MRI_float: mri_fix_data_pointer( fptr[ii] + kk*npix, im ) ; break ; } } /*** 4b) Setup im to point to base image ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: slice %d -- setup base image\n",kk) ; #endif switch( datum ) { case MRI_byte: mri_fix_data_pointer( bptr[base] + kk*npix, imbase ) ; break ; case MRI_short: mri_fix_data_pointer( sptr[base] + kk*npix, imbase ) ; break ; case MRI_float: mri_fix_data_pointer( fptr[base] + kk*npix, imbase ) ; break ; } /*** 4c) Register this slice at all times ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: slice %d -- register\n",kk) ; #endif ims_out = mri_align_dfspace( imbase , NULL , ims_in , ALIGN_REGISTER_CODE , dxar,dyar,phiar ) ; if( ims_out == NULL ) fprintf(stderr,"IMREG: mri_align_dfspace return NULL\n") ; /*** 4d) Put the output back in on top of the input; note that the output is always in MRI_float format ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: slice %d -- put output back into dataset\n",kk) ; #endif for( ii=0 ; ii < ntime ; ii++ ) { switch( datum ) { case MRI_byte: im = mri_to_mri( MRI_byte , IMARR_SUBIMAGE(ims_out,ii) ) ; memcpy( bout[ii] + kk*npix , MRI_BYTE_PTR(im) , sizeof(byte)*npix ) ; mri_free(im) ; break ; case MRI_short: #ifdef IMREG_DEBUG if( ii==0 )fprintf(stderr,"IMREG: conversion to short at ii=%d\n",ii) ; #endif im = mri_to_mri( MRI_short , IMARR_SUBIMAGE(ims_out,ii) ) ; #ifdef IMREG_DEBUG if( ii==0 )fprintf(stderr,"IMREG: copying to %p from %p\n",sout[ii] + kk*npix,MRI_SHORT_PTR(im)) ; #endif memcpy( sout[ii] + kk*npix , MRI_SHORT_PTR(im) , sizeof(short)*npix ) ; #ifdef IMREG_DEBUG if( ii==0 )fprintf(stderr,"IMREG: freeing\n") ; #endif mri_free(im) ; break ; case MRI_float: im = IMARR_SUBIMAGE(ims_out,ii) ; memcpy( fout[ii] + kk*npix , MRI_FLOAT_PTR(im) , sizeof(float)*npix ) ; break ; } } PLUTO_set_meter(plint, (100*(kk+1))/nz ) ; /*** 4e) Destroy the output images ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: destroying aligned output\n") ; #endif DESTROY_IMARR( ims_out ) ; } /*** 5) Destroy the empty images and other workspaces ***/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: destroy workspaces\n") ; #endif mri_clear_data_pointer(imbase) ; mri_free(imbase) ; for( ii=0 ; ii < ntime ; ii++ ) { im = IMARR_SUBIMAGE(ims_in,ii) ; mri_clear_data_pointer(im) ; } DESTROY_IMARR(ims_in) ; FREE_WORKSPACE ; /*------------- let AFNI know about the new dataset ------------*/ #ifdef IMREG_DEBUG fprintf(stderr,"IMREG: send result to AFNI\n") ; #endif PLUTO_add_dset( plint , new_dset , DSET_ACTION_MAKE_CURRENT ) ; return NULL ; /* null string returned means all was OK */ }