Doxygen Source Code Documentation
afni_fimmer.c File Reference
#include "afni.h"#include "mrilib.h"Go to the source code of this file.
Defines | |
| #define | METERIZE(ib) |
| #define | MAXUFUN 64 |
| #define | MAXTS 32 |
Functions | |
| int | AFNI_ts_in_library (MRI_IMAGE *tsim) |
| void | AFNI_fimmer_pickref_CB (Widget wcall, XtPointer cd, MCW_choose_cbs *cbs) |
| void | AFNI_fimmer_pickort_CB (Widget wcall, XtPointer cd, MCW_choose_cbs *cbs) |
| void | AFNI_fimmer_setref (Three_D_View *im3d, MRI_IMAGE *tsim) |
| void | AFNI_fimmer_setort (Three_D_View *im3d, MRI_IMAGE *tsim) |
| void | AFNI_fimmer_setignore (Three_D_View *im3d, int new_ignore) |
| void | AFNI_fimmer_setpolort (Three_D_View *im3d, int new_polort) |
| THD_3dim_dataset * | AFNI_fimmer_compute (Three_D_View *im3d, THD_3dim_dataset *dset_time, MRI_IMAGE *ref_ts, MRI_IMAGE *ort_ts, THD_session *sess, int code, int ucode) |
| void | AFNI_fimmer_execute (Three_D_View *im3d, int code, int ucode) |
| void | AFNI_fimmer_redisplay (int first_call, Three_D_View *im3d, THD_3dim_dataset *new_dset) |
| void | AFNI_add_interruptable (Widget w) |
| void | AFNI_process_interrupts (Widget w) |
Define Documentation
|
|
|
|
|
|
|
|
Value: do { meter_perc = (int) ( 100.0 * (ib) / nbrik ) ; \ if( meter_perc != meter_pold ){ \ MCW_set_meter( meter , meter_perc ) ; \ meter_pold = meter_perc ; \ } } while(0) |
Function Documentation
|
|
Definition at line 2031 of file afni_fimmer.c. References ADDTO_XTARR, XtPointer_array::ar, DESTROY_XTARR, GLOBAL_library, INIT_XTARR, AFNI_library_type::interruptables, MCW_set_widget_cursor(), NORMAL_cursorize, XtPointer_array::num, MCW_interruptables::widgets, and MCW_interruptables::windows. Referenced by RCREND_autocompute_CB(), RCREND_read_exec_CB(), REND_autocompute_CB(), and REND_read_exec_CB().
02032 {
02033 Window wwin , wroot , wpar ;
02034 int ii ;
02035 Window * wchild ;
02036 unsigned int nchild ;
02037
02038 /* input Widget is NULL is the signal to reset everything */
02039
02040 if( w == NULL ){
02041 if( GLOBAL_library.interruptables.windows != NULL ){ /* just toss this list */
02042 DESTROY_XTARR( GLOBAL_library.interruptables.windows ) ;
02043 GLOBAL_library.interruptables.windows = NULL ;
02044 }
02045
02046 if( GLOBAL_library.interruptables.widgets != NULL ){ /* must reset cursors */
02047 for( ii=0 ; ii < GLOBAL_library.interruptables.widgets->num ; ii++ )
02048 MCW_set_widget_cursor( GLOBAL_library.interruptables.widgets->ar[ii] , 0 );
02049
02050 DESTROY_XTARR( GLOBAL_library.interruptables.widgets ) ;
02051 GLOBAL_library.interruptables.widgets = NULL ;
02052 }
02053 return ;
02054 }
02055
02056 /* non-NULL widget --> add it and its sub-windows to the list */
02057
02058 if( ! XtIsRealized(w) ) return ;
02059 wwin = XtWindowOfObject(w) ; if( wwin == (Window) NULL ) return ;
02060
02061 /* get list of all sub-windows into wchild */
02062
02063 nchild = 0 ;
02064 (void) XQueryTree( XtDisplay(w) , wwin , &wroot , &wpar , &wchild , &nchild ) ;
02065
02066 if( GLOBAL_library.interruptables.windows == NULL ) /* initialize lists */
02067 INIT_XTARR( GLOBAL_library.interruptables.windows ) ;
02068
02069 if( GLOBAL_library.interruptables.widgets == NULL )
02070 INIT_XTARR( GLOBAL_library.interruptables.widgets ) ;
02071
02072 ADDTO_XTARR( GLOBAL_library.interruptables.windows , wwin ) ; /* add to lists */
02073 ADDTO_XTARR( GLOBAL_library.interruptables.widgets , w ) ;
02074
02075 for( ii=0 ; ii < nchild ; ii++ )
02076 ADDTO_XTARR( GLOBAL_library.interruptables.windows , wchild[ii] ) ;
02077
02078 XFree( wchild ) ; /* return this to Xlib */
02079
02080 NORMAL_cursorize( w) ;
02081
02082 return ;
02083 }
|
|
||||||||||||||||||||||||||||||||
|
01 Feb 2000: added ucode, for user written functions * Definition at line 268 of file afni_fimmer.c. References abs, ADN_brick_fac, ADN_datum_all, ADN_func_type, ADN_malloc_type, ADN_none, ADN_ntt, ADN_nvals, ADN_prefix, ADN_stat_aux, ADN_type, AFNI_3DDATA_VIEW, AFNI_CALL_fim_function, AFNI_GOOD_FUNC_DTYPE, calloc, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::dblk, DESTROY_IMARR, THD_diskptr::dimsizes, THD_datablock::diskptr, THD_slist_find::dset, DSET_ARRAY, DSET_BRICK, DSET_BRICK_BYTES, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_GRAPHABLE, DSET_NUM_TIMES, DSET_NVALS, DSET_PREFIX, EDIT_add_brick(), EDIT_BRICK_FACTOR, EDIT_BRICK_LABEL, EDIT_BRICK_TO_FICO, EDIT_clip_float(), EDIT_dset_items(), EDIT_empty_copy(), ENTRY, fd, FIM_ALPHA_MASK, FIM_AVER_MASK, FIM_BASE_MASK, FIM_BEST_MASK, FIM_CORR_MASK, FIM_PAVE_MASK, FIM_PERC_MASK, FIM_PTOP_MASK, FIM_SIGM_MASK, FIM_TOPL_MASK, Three_D_View::fimdata, FIND_PREFIX, MCW_function_list::flags, free, free_PCOR_references(), free_PCOR_voxel_corr(), FUNC_BUCK_TYPE, FUNC_COR_SCALE_SHORT, MCW_function_list::func_data, FUNC_FIM_TYPE, THD_3dim_dataset::func_type, MCW_function_list::funcs, GEN_FUNC_TYPE, generic_func, GLOBAL_library, HEAD_FUNC_TYPE, FIMdata::ignore, IM3D_OPEN, IMARR_SUBIMAGE, AFNI_fimmer_type::init_ignore, ISHEAD, ISVALID_SESSION, MRI_IMAGE::kind, malloc, MAX, MAX_STAT_AUX, MCW_popdown_meter(), MCW_popup_meter(), MCW_set_meter(), MCW_strncpy, METER_TOP_WIDE, MIN, mri_fix_data_pointer(), MRI_FLOAT_PTR, my_getenv(), new_PCOR_references(), new_PCOR_voxel_corr(), MCW_function_list::num, THD_datablock::nvals, FIMdata::nvox, MRI_IMAGE::nx, MRI_IMAGE::ny, FIMdata::ort_ts, PCOR_get_coef(), PCOR_get_pcor(), PCOR_get_perc(), PCOR_get_stdev(), PCOR_update_float(), FIMdata::polort, AFNI_fimmer_type::polort, FIMdata::ref_ts, AFNI_library_type::registered_fim, RETURN, STATUS, strtod(), THD_count_databricks(), THD_delete_3dim_dataset(), THD_dset_in_session(), THD_extract_many_series(), thd_floatscan(), THD_load_datablock(), THD_MAX_PREFIX, AFNI_widget_set::top_shell, Three_D_View::type, update_PCOR_references(), Three_D_View::vwid, and XtRealloc.
00272 {
00273 THD_3dim_dataset * new_dset=NULL ;
00274 char new_prefix[THD_MAX_PREFIX] ;
00275 char old_prefix[THD_MAX_PREFIX] ;
00276 THD_slist_find fff ;
00277 int ifim , it,iv , nvox , ngood_ref , ntime , it1 , dtyp , nxyz , itbot ;
00278 float * vval, * tsar, * aval, * rbest, * abest, * pbest, * pval, * bbest, * bval;
00279 int * indx ;
00280 short * bar ;
00281 short * ibest ; /* 15 Dec 1997 */
00282 void * ptr ;
00283 float stataux[MAX_STAT_AUX] ;
00284 float fthr , topval ;
00285 int nx_ref , ny_ref , ivec , nnow ;
00286 PCOR_references ** pc_ref ;
00287 PCOR_voxel_corr ** pc_vc ;
00288
00289 int fim_nref , nx_ort , ny_ort , internal_ort ;
00290 float * ortar ;
00291 static float * ref_vec = NULL ;
00292 static int nref_vec = -666 ;
00293
00294 int ibr_best , ibr_perc , ibr_fim , ibr_corr , ibr_base , nbrik ;
00295
00296 int polort = im3d->fimdata->polort , ip ; /* 30 May 1999 */
00297
00298 float top_perc = 0.0 ; /* 30 Aug 1999 */
00299
00300 int ibr_pave , ibr_aver ; /* 08 Sep 1999 */
00301 float * paval , * avval , * pabest , * avbest ; /* 08 Sep 1999 */
00302
00303 int ibr_ptop , ibr_topl , ibr_sigm ; /* 03 Jan 2000 */
00304 float * ptval , * tlval , *sgval ,
00305 * ptbest, * tlbest, *sgbest ;
00306
00307 #ifndef DONT_USE_METER
00308 Widget meter = NULL ;
00309 int meter_perc , meter_pold ;
00310 #endif
00311
00312 int nupdt = 0 , /* number of updates done yet */
00313 min_updt = 5 , /* min number needed for display */
00314 first_updt = 1 ; /* flag to indicate that first update is yet to be displayed */
00315
00316 ENTRY("AFNI_fimmer_compute") ;
00317
00318 /*--- check for legal inputs ---*/
00319
00320 if( ! DSET_GRAPHABLE(dset_time) ||
00321 ref_ts == NULL ||
00322 ref_ts->kind != MRI_float ||
00323 ! IM3D_OPEN(im3d) ||
00324 im3d->type != AFNI_3DDATA_VIEW ||
00325 (code == 0 && ucode == 0) || /* Jan 1998 & Feb 2000 */
00326 ref_ts->nx < DSET_NUM_TIMES(dset_time) ){
00327
00328 if(PRINT_TRACING)
00329 { char str[256] ;
00330 sprintf(str,"illegal inputs: ntime=%d num_ts=%d",
00331 DSET_NUM_TIMES(dset_time), (ref_ts==NULL) ? (0) : (ref_ts->nx) ) ;
00332 STATUS(str) ; }
00333
00334 RETURN(NULL) ;
00335 }
00336
00337 /** 13 Nov 1996: allow for orts **/
00338
00339 if( ort_ts != NULL ){
00340 nx_ort = ort_ts->nx ;
00341 ny_ort = ort_ts->ny ;
00342 ortar = MRI_FLOAT_PTR(ort_ts) ;
00343
00344 internal_ort = (nx_ort < DSET_NUM_TIMES(dset_time)) ;
00345 } else {
00346 internal_ort = 1 ;
00347 }
00348 fim_nref = (internal_ort) ? (polort+2) : (ny_ort+polort+2) ;
00349
00350 if( nref_vec < fim_nref ){
00351 ref_vec = (float *) XtRealloc( (char *)ref_vec, sizeof(float)*fim_nref ) ;
00352 nref_vec = fim_nref ;
00353 }
00354
00355 itbot = im3d->fimdata->init_ignore ;
00356 nx_ref = ref_ts->nx ;
00357 ny_ref = ref_ts->ny ;
00358 ntime = DSET_NUM_TIMES(dset_time) ;
00359 ngood_ref = 0 ;
00360 it1 = -1 ;
00361 for( ivec=0 ; ivec < ny_ref ; ivec++ ){
00362 tsar = MRI_FLOAT_PTR(ref_ts) + (ivec*nx_ref) ;
00363 ifim = 0 ;
00364 for( it=itbot ; it < ntime ; it++ ){
00365 if( tsar[it] < WAY_BIG ){ ifim++ ; if( it1 < 0 ) it1 = it ; }
00366 }
00367
00368 if( ifim < min_updt ){
00369 STATUS("ref_ts has too few good entries!") ;
00370 RETURN(NULL) ;
00371 }
00372
00373 ngood_ref = MAX( ifim , ngood_ref ) ;
00374 }
00375
00376 /** at this point, ngood_ref = max number of good reference points,
00377 and it1 = index of first point used in first reference **/
00378
00379 dtyp = DSET_BRICK_TYPE(dset_time,it1) ;
00380 if( ! AFNI_GOOD_FUNC_DTYPE(dtyp) ){
00381 STATUS("illegal input data type!") ;
00382 RETURN(NULL) ;
00383 }
00384
00385 /*--- Create a new prefix ---*/
00386
00387 MCW_strncpy( old_prefix , DSET_PREFIX(dset_time) , THD_MAX_PREFIX-3 ) ;
00388
00389 if( ! ISVALID_SESSION(sess) ){
00390 sprintf( new_prefix , "%s@%d" , old_prefix , 1 ) ;
00391 } else {
00392 for( ifim=1 ; ifim < 99 ; ifim++ ){
00393 sprintf( new_prefix , "%s@%d" , old_prefix , ifim ) ;
00394 fff = THD_dset_in_session( FIND_PREFIX , new_prefix , sess ) ;
00395 if( fff.dset == NULL ) break ;
00396 }
00397 if( ifim == 99 ){
00398 STATUS("can't create new prefix!") ;
00399 RETURN(NULL) ; /* can't make a new prefix! */
00400 }
00401 }
00402
00403 if(PRINT_TRACING)
00404 { char str[256] ;
00405 sprintf(str,"new prefix = %s",new_prefix) ; STATUS(str) ; }
00406
00407 /*--- FIM: find values above threshold to fim ---*/
00408
00409 THD_load_datablock( dset_time->dblk ) ;
00410
00411 nxyz = dset_time->dblk->diskptr->dimsizes[0]
00412 * dset_time->dblk->diskptr->dimsizes[1]
00413 * dset_time->dblk->diskptr->dimsizes[2] ;
00414
00415 /** find the mean of the first array,
00416 compute the threshold (fthr) from it,
00417 make indx[i] be the 3D index of the i-th voxel above threshold **/
00418
00419 switch( dtyp ){
00420
00421 case MRI_short:{
00422 short * dar = (short *) DSET_ARRAY(dset_time,it1) ;
00423 for( iv=0,fthr=0.0 ; iv < nxyz ; iv++ ) fthr += abs(dar[iv]) ;
00424 fthr = FIM_THR * fthr / nxyz ;
00425
00426 if(PRINT_TRACING)
00427 { char str[256] ; sprintf(str,"fthr = %g",fthr) ; STATUS(str) ; }
00428
00429 for( iv=0,nvox=0 ; iv < nxyz ; iv++ )
00430 if( abs(dar[iv]) > fthr ) nvox++ ;
00431 indx = (int *) malloc( sizeof(int) * nvox ) ;
00432 if( indx == NULL ){
00433 fprintf(stderr,"\n*** indx malloc failure in AFNI_fimmer_compute\n") ;
00434 RETURN(NULL) ;
00435 }
00436 for( iv=0,nvox=0 ; iv < nxyz ; iv++ )
00437 if( abs(dar[iv]) > fthr ) indx[nvox++] = iv ;
00438 }
00439 break ;
00440
00441 case MRI_float:{
00442 float * dar = (float *) DSET_ARRAY(dset_time,it1) ;
00443 for( iv=0,fthr=0.0 ; iv < nxyz ; iv++ ) fthr += fabs(dar[iv]) ;
00444 fthr = FIM_THR * fthr / nxyz ;
00445
00446 if(PRINT_TRACING)
00447 { char str[256] ; sprintf(str,"fthr = %g",fthr) ; STATUS(str) ; }
00448
00449 for( iv=0,nvox=0 ; iv < nxyz ; iv++ )
00450 if( fabs(dar[iv]) > fthr ) nvox++ ;
00451 indx = (int *) malloc( sizeof(int) * nvox ) ;
00452 if( indx == NULL ){
00453 fprintf(stderr,"\n*** indx malloc failure in AFNI_fimmer_compute\n") ;
00454 RETURN(NULL) ;
00455 }
00456 for( iv=0,nvox=0 ; iv < nxyz ; iv++ )
00457 if( fabs(dar[iv]) > fthr ) indx[nvox++] = iv ;
00458 }
00459 break ;
00460
00461 case MRI_byte:{
00462 byte * dar = (byte *) DSET_ARRAY(dset_time,it1) ;
00463 for( iv=0,fthr=0.0 ; iv < nxyz ; iv++ ) fthr += dar[iv] ;
00464 fthr = FIM_THR * fthr / nxyz ;
00465
00466 if(PRINT_TRACING)
00467 { char str[256] ; sprintf(str,"fthr = %g",fthr) ; STATUS(str) ; }
00468
00469 for( iv=0,nvox=0 ; iv < nxyz ; iv++ )
00470 if( dar[iv] > fthr ) nvox++ ;
00471 indx = (int *) malloc( sizeof(int) * nvox ) ;
00472 if( indx == NULL ){
00473 fprintf(stderr,"\n*** indx malloc failure in AFNI_fimmer_compute\n") ;
00474 RETURN(NULL) ;
00475 }
00476 for( iv=0,nvox=0 ; iv < nxyz ; iv++ )
00477 if( dar[iv] > fthr ) indx[nvox++] = iv ;
00478 }
00479 break ;
00480 }
00481
00482 if(PRINT_TRACING)
00483 { char str[256] ; sprintf(str,"number of voxels = %d",nvox) ; STATUS(str) ; }
00484
00485 /** 10 May 2000: check if nothing was found to work on **/
00486
00487 if( nvox == 0 ){
00488 fprintf(stderr,"\n*** no voxels to FIM on!"
00489 "\n*** try setting the Bkg Thresh lower"
00490 "\n [on the FIM -> Edit Ideal menu]\a\n") ;
00491 free(indx) ; RETURN(NULL) ;
00492 }
00493
00494 /** allocate space for voxel values **/
00495
00496 vval = (float *) malloc( sizeof(float) * nvox) ;
00497 if( vval == NULL ){
00498 fprintf(stderr,"\n*** vval malloc failure in AFNI_fimmer_compute\n") ;
00499 free(indx) ; RETURN(NULL) ;
00500 }
00501
00502 /** compute number of output bricks **/
00503
00504 ibr_fim=ibr_corr=ibr_best=ibr_perc=ibr_base = -1 ; nbrik = 0 ;
00505 ibr_pave = ibr_aver = -1 ;
00506 ibr_ptop = ibr_topl = ibr_sigm = -1 ;
00507
00508 if( (code & FIM_ALPHA_MASK)!= 0) { ibr_fim = nbrik; nbrik++; }
00509 if( (code & FIM_BEST_MASK) != 0 && ny_ref > 1){ ibr_best = nbrik; nbrik++; }
00510 if( (code & FIM_PERC_MASK) != 0) { ibr_perc = nbrik; nbrik++; }
00511 if( (code & FIM_PAVE_MASK) != 0) { ibr_pave = nbrik; nbrik++; }
00512 if( (code & FIM_BASE_MASK) != 0) { ibr_base = nbrik; nbrik++; }
00513 if( (code & FIM_AVER_MASK) != 0) { ibr_aver = nbrik; nbrik++; }
00514 if( (code & FIM_CORR_MASK) != 0) { ibr_corr = nbrik; nbrik++; }
00515 if( (code & FIM_PTOP_MASK) != 0) { ibr_ptop = nbrik; nbrik++; }
00516 if( (code & FIM_TOPL_MASK) != 0) { ibr_topl = nbrik; nbrik++; }
00517 if( (code & FIM_SIGM_MASK) != 0) { ibr_sigm = nbrik; nbrik++; }
00518
00519 /** 01 Feb 2000: if no normal FIM stuff (code), skip to the ucode stuff **/
00520
00521 if(PRINT_TRACING)
00522 { char str[256] ; sprintf(str,"number of bricks = %d",nbrik) ; STATUS(str) ; }
00523
00524 if( nbrik == 0 ){
00525
00526 #ifndef DONT_USE_METER
00527 meter = MCW_popup_meter( im3d->vwid->top_shell , METER_TOP_WIDE ) ;
00528 meter_pold = 0 ;
00529 #endif
00530
00531 goto ucode_stuff ; /* way below */
00532 }
00533
00534 /** normal case: do the normal recursive FIMming **/
00535
00536 if(PRINT_TRACING)
00537 { char str[256] ;
00538 sprintf(str,"code of FIM_MASKs = %d",code) ; STATUS(str) ; }
00539
00540 /** allocate extra space for comparing results from multiple ref vectors **/
00541
00542 if( ny_ref > 1 ){
00543 aval = (float *) malloc(sizeof(float) * nvox) ;
00544 rbest = (float *) malloc(sizeof(float) * nvox) ;
00545 abest = (float *) malloc(sizeof(float) * nvox) ;
00546 ibest = (short *) malloc(sizeof(short) * nvox) ; /* 15 Dec 1997 */
00547 pbest = (float *) malloc(sizeof(float) * nvox) ; /* 16 Jan 1998 */
00548 bbest = (float *) malloc(sizeof(float) * nvox) ; /* 16 Jan 1998 */
00549 pval = (float *) malloc(sizeof(float) * nvox) ; /* 16 Jan 1998 */
00550 bval = (float *) malloc(sizeof(float) * nvox) ; /* 16 Jan 1998 */
00551
00552 paval = (float *) malloc(sizeof(float) * nvox) ; /* 08 Sep 1999 */
00553 avval = (float *) malloc(sizeof(float) * nvox) ; /* 08 Sep 1999 */
00554 pabest = (float *) malloc(sizeof(float) * nvox) ; /* 16 Jan 1998 */
00555 avbest = (float *) malloc(sizeof(float) * nvox) ; /* 16 Jan 1998 */
00556
00557 ptval = (float *) malloc(sizeof(float) * nvox) ; /* 03 Jan 2000 */
00558 tlval = (float *) malloc(sizeof(float) * nvox) ; /* 03 Jan 2000 */
00559 sgval = (float *) malloc(sizeof(float) * nvox) ; /* 03 Jan 2000 */
00560 ptbest = (float *) malloc(sizeof(float) * nvox) ; /* 03 Jan 2000 */
00561 tlbest = (float *) malloc(sizeof(float) * nvox) ; /* 03 Jan 2000 */
00562 sgbest = (float *) malloc(sizeof(float) * nvox) ; /* 03 Jan 2000 */
00563
00564 if( sgbest == NULL ){
00565 fprintf(stderr,"\n*** 'best' malloc failure in AFNI_fimmer_compute\n") ;
00566 free(vval) ; free(indx) ;
00567 if( aval != NULL ) free(aval) ;
00568 if( rbest != NULL ) free(rbest) ;
00569 if( abest != NULL ) free(abest) ;
00570 if( ibest != NULL ) free(ibest) ; /* 15 Dec 1997 */
00571 if( pbest != NULL ) free(pbest) ; /* 16 Jan 1998 */
00572 if( bbest != NULL ) free(bbest) ; /* 16 Jan 1998 */
00573 if( pval != NULL ) free(pval) ; /* 16 Jan 1998 */
00574 if( bval != NULL ) free(bval) ; /* 16 Jan 1998 */
00575 if( paval != NULL ) free(paval) ; /* 08 Sep 1999 */
00576 if( avval != NULL ) free(avval) ; /* 08 Sep 1999 */
00577 if( pabest!= NULL ) free(pabest); /* 08 Sep 1999 */
00578 if( avbest!= NULL ) free(avbest); /* 08 Sep 1999 */
00579 if( ptval != NULL ) free(ptval) ; /* 03 Jan 2000 */
00580 if( tlval != NULL ) free(tlval) ; /* 03 Jan 2000 */
00581 if( sgval != NULL ) free(sgval) ; /* 03 Jan 2000 */
00582 if( ptbest!= NULL ) free(ptbest); /* 03 Jan 2000 */
00583 if( tlbest!= NULL ) free(tlbest); /* 03 Jan 2000 */
00584 if( sgbest!= NULL ) free(sgbest); /* 03 Jan 2000 */
00585 RETURN(NULL) ;
00586 }
00587 } else {
00588 aval = rbest = abest = pbest = bbest = pval = bval = NULL ;
00589 paval = avval = pabest = avbest = NULL ; /* 08 Sep 1999 */
00590 ptval = tlval = ptbest = tlbest = NULL ; /* 03 Jan 2000 */
00591 sgval = sgbest = NULL ; /* 03 Jan 2000 */
00592 ibest = NULL ; /* 15 Dec 1997 */
00593 }
00594
00595 if(PRINT_TRACING)
00596 { char str[256] ;
00597 sprintf(str,"nxyz = %d nvox = %d",nxyz,nvox) ; STATUS(str) ; }
00598
00599 /*--- FIM: initialize recursive updates ---*/
00600
00601 pc_ref = (PCOR_references **) malloc( sizeof(PCOR_references *) * ny_ref ) ;
00602 pc_vc = (PCOR_voxel_corr **) malloc( sizeof(PCOR_voxel_corr *) * ny_ref ) ;
00603
00604 if( pc_ref == NULL || pc_vc == NULL ){
00605 free(vval) ; free(indx) ; free(pc_ref) ; free(pc_vc) ;
00606 if( aval != NULL ) free(aval) ;
00607 if( rbest != NULL ) free(rbest) ;
00608 if( abest != NULL ) free(abest) ;
00609 if( ibest != NULL ) free(ibest) ; /* 15 Dec 1997 */
00610 if( pbest != NULL ) free(pbest) ; /* 16 Jan 1998 */
00611 if( bbest != NULL ) free(bbest) ; /* 16 Jan 1998 */
00612 if( pval != NULL ) free(pval) ; /* 16 Jan 1998 */
00613 if( bval != NULL ) free(bval) ; /* 16 Jan 1998 */
00614 if( paval != NULL ) free(paval) ; /* 08 Sep 1999 */
00615 if( avval != NULL ) free(avval) ; /* 08 Sep 1999 */
00616 if( pabest!= NULL ) free(pabest); /* 08 Sep 1999 */
00617 if( avbest!= NULL ) free(avbest); /* 08 Sep 1999 */
00618 if( ptval != NULL ) free(ptval) ; /* 03 Jan 2000 */
00619 if( tlval != NULL ) free(tlval) ; /* 03 Jan 2000 */
00620 if( sgval != NULL ) free(sgval) ; /* 03 Jan 2000 */
00621 if( ptbest!= NULL ) free(ptbest); /* 03 Jan 2000 */
00622 if( tlbest!= NULL ) free(tlbest); /* 03 Jan 2000 */
00623 if( sgbest!= NULL ) free(sgbest); /* 03 Jan 2000 */
00624 fprintf(stderr,"\n*** FIM initialization fails in AFNI_fimmer_compute\n") ;
00625 RETURN(NULL) ;
00626 }
00627
00628 ifim = 0 ;
00629 for( ivec=0 ; ivec < ny_ref ; ivec++ ){
00630 pc_ref[ivec] = new_PCOR_references( fim_nref ) ;
00631 pc_vc[ivec] = new_PCOR_voxel_corr( nvox , fim_nref ) ;
00632 if( pc_ref[ivec] == NULL || pc_vc[ivec] == NULL ) ifim++ ;
00633 }
00634
00635 if( ifim > 0 ){
00636 for( ivec=0 ; ivec < ny_ref ; ivec++ ){
00637 free_PCOR_references(pc_ref[ivec]) ;
00638 free_PCOR_voxel_corr(pc_vc[ivec]) ;
00639 }
00640 free(vval) ; free(indx) ; free(pc_ref) ; free(pc_vc) ;
00641 if( aval != NULL ) free(aval) ;
00642 if( rbest != NULL ) free(rbest) ;
00643 if( abest != NULL ) free(abest) ;
00644 if( ibest != NULL ) free(ibest) ; /* 15 Dec 1997 */
00645 if( pbest != NULL ) free(pbest) ; /* 16 Jan 1998 */
00646 if( bbest != NULL ) free(bbest) ; /* 16 Jan 1998 */
00647 if( pval != NULL ) free(pval) ; /* 16 Jan 1998 */
00648 if( bval != NULL ) free(bval) ; /* 16 Jan 1998 */
00649 if( paval != NULL ) free(paval) ; /* 08 Sep 1999 */
00650 if( avval != NULL ) free(avval) ; /* 08 Sep 1999 */
00651 if( pabest!= NULL ) free(pabest); /* 08 Sep 1999 */
00652 if( avbest!= NULL ) free(avbest); /* 08 Sep 1999 */
00653 if( ptval != NULL ) free(ptval) ; /* 03 Jan 2000 */
00654 if( tlval != NULL ) free(tlval) ; /* 03 Jan 2000 */
00655 if( sgval != NULL ) free(sgval) ; /* 03 Jan 2000 */
00656 if( ptbest!= NULL ) free(ptbest); /* 03 Jan 2000 */
00657 if( tlbest!= NULL ) free(tlbest); /* 03 Jan 2000 */
00658 if( sgbest!= NULL ) free(sgbest); /* 03 Jan 2000 */
00659 fprintf(stderr,"\n*** FIM initialization fails in AFNI_fimmer_compute\n") ;
00660 RETURN(NULL) ;
00661 }
00662
00663 /*--- Make a new dataset to hold the output ---*/
00664
00665 STATUS("making new dataset") ;
00666
00667 new_dset = EDIT_empty_copy( dset_time ) ;
00668
00669 if( nbrik == 1 && ucode == 0 ){ /* 1 brick out --> a 'fim' dataset */
00670 it = EDIT_dset_items( new_dset ,
00671 ADN_prefix , new_prefix ,
00672 ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00673 ADN_type , ISHEAD(dset_time)
00674 ? HEAD_FUNC_TYPE : GEN_FUNC_TYPE ,
00675 ADN_func_type , FUNC_FIM_TYPE ,
00676 ADN_nvals , 1 ,
00677 ADN_datum_all , MRI_short ,
00678 ADN_ntt , 0 ,
00679 ADN_none ) ;
00680 /* 2 bricks, 2nd corr --> 'fico' */
00681 } else if( nbrik == 2 && ibr_corr == 1 && ucode == 0 ){
00682 it = EDIT_dset_items( new_dset ,
00683 ADN_prefix , new_prefix ,
00684 ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00685 ADN_type , ISHEAD(dset_time)
00686 ? HEAD_FUNC_TYPE : GEN_FUNC_TYPE ,
00687 ADN_func_type , FUNC_COR_TYPE ,
00688 ADN_nvals , 2 ,
00689 ADN_datum_all , MRI_short ,
00690 ADN_ntt , 0 ,
00691 ADN_none ) ;
00692
00693 } else if( nbrik > 0 ){ /* otherwise --> 'fbuc' (bucket) */
00694 it = EDIT_dset_items( new_dset ,
00695 ADN_prefix , new_prefix ,
00696 ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
00697 ADN_type , ISHEAD(dset_time)
00698 ? HEAD_FUNC_TYPE : GEN_FUNC_TYPE ,
00699 ADN_func_type , FUNC_BUCK_TYPE ,
00700 ADN_nvals , nbrik ,
00701 ADN_datum_all , MRI_short ,
00702 ADN_ntt , 0 ,
00703 ADN_none ) ;
00704 } else {
00705 it = 999 ;
00706 }
00707
00708 if( it > 0 ){
00709 fprintf(stderr,
00710 "\n*** EDIT_dset_items error %d in AFNI_fimmer_compute\n",it) ;
00711 THD_delete_3dim_dataset( new_dset , False ) ;
00712 for( ivec=0 ; ivec < ny_ref ; ivec++ ){
00713 free_PCOR_references(pc_ref[ivec]) ;
00714 free_PCOR_voxel_corr(pc_vc[ivec]) ;
00715 }
00716 free(vval) ; free(indx) ; free(pc_ref) ; free(pc_vc) ;
00717 if( aval != NULL ) free(aval) ;
00718 if( rbest != NULL ) free(rbest) ;
00719 if( abest != NULL ) free(abest) ;
00720 if( ibest != NULL ) free(ibest) ; /* 15 Dec 1997 */
00721 if( pbest != NULL ) free(pbest) ; /* 16 Jan 1998 */
00722 if( bbest != NULL ) free(bbest) ; /* 16 Jan 1998 */
00723 if( pval != NULL ) free(pval) ; /* 16 Jan 1998 */
00724 if( bval != NULL ) free(bval) ; /* 16 Jan 1998 */
00725 if( paval != NULL ) free(paval) ; /* 08 Sep 1999 */
00726 if( avval != NULL ) free(avval) ; /* 08 Sep 1999 */
00727 if( pabest!= NULL ) free(pabest); /* 08 Sep 1999 */
00728 if( avbest!= NULL ) free(avbest); /* 08 Sep 1999 */
00729 if( ptval != NULL ) free(ptval) ; /* 03 Jan 2000 */
00730 if( tlval != NULL ) free(tlval) ; /* 03 Jan 2000 */
00731 if( sgval != NULL ) free(sgval) ; /* 03 Jan 2000 */
00732 if( ptbest!= NULL ) free(ptbest); /* 03 Jan 2000 */
00733 if( tlbest!= NULL ) free(tlbest); /* 03 Jan 2000 */
00734 if( sgbest!= NULL ) free(sgbest); /* 03 Jan 2000 */
00735 RETURN(NULL) ;
00736 }
00737
00738 /* modify labels for each brick */
00739
00740 if( ibr_fim >= 0 )
00741 EDIT_BRICK_LABEL( new_dset , ibr_fim , "Fit Coef" ) ;
00742 if( ibr_corr >= 0 )
00743 EDIT_BRICK_LABEL( new_dset , ibr_corr , "Correlation" ) ;
00744 if( ibr_best >= 0 )
00745 EDIT_BRICK_LABEL( new_dset , ibr_best , "Best Index" ) ;
00746 if( ibr_perc >= 0 )
00747 EDIT_BRICK_LABEL( new_dset , ibr_perc , "% Change" ) ;
00748 if( ibr_base >= 0 )
00749 EDIT_BRICK_LABEL( new_dset , ibr_base , "Baseline" ) ;
00750
00751 if( ibr_pave >= 0 )
00752 EDIT_BRICK_LABEL( new_dset , ibr_pave , "% From Ave" ) ; /* 08 Sep 1999 */
00753 if( ibr_aver >= 0 )
00754 EDIT_BRICK_LABEL( new_dset , ibr_aver , "Average" ) ;
00755
00756 if( ibr_ptop >= 0 )
00757 EDIT_BRICK_LABEL( new_dset , ibr_ptop , "% From Top" ) ; /* 03 Jan 2000 */
00758 if( ibr_topl >= 0 )
00759 EDIT_BRICK_LABEL( new_dset , ibr_topl , "Topline" ) ;
00760 if( ibr_sigm >= 0 )
00761 EDIT_BRICK_LABEL( new_dset , ibr_sigm , "Sigma Resid" ) ;
00762
00763 /*-- 30 Aug 1999: set limits on percent change --*/
00764
00765 if( ibr_perc >= 0 || ibr_pave >= 0 || ibr_ptop >= 0 ){
00766 char * cp = my_getenv("AFNI_FIM_PERCENT_LIMIT") ;
00767 if( cp != NULL ){
00768 float tp = strtod(cp,NULL) ;
00769 if( tp > 0.0 ) top_perc = tp ;
00770 }
00771 }
00772
00773 /* create bricks */
00774
00775 STATUS("making output bricks") ;
00776
00777 for( iv=0 ; iv < new_dset->dblk->nvals ; iv++ ){
00778 ptr = malloc( DSET_BRICK_BYTES(new_dset,iv) ) ;
00779 mri_fix_data_pointer( ptr , DSET_BRICK(new_dset,iv) ) ;
00780 }
00781
00782 if( THD_count_databricks(new_dset->dblk) < new_dset->dblk->nvals ){
00783 fprintf(stderr,
00784 "\n*** failure to malloc new bricks in AFNI_fimmer_compute\n") ;
00785 THD_delete_3dim_dataset( new_dset , False ) ;
00786 for( ivec=0 ; ivec < ny_ref ; ivec++ ){
00787 free_PCOR_references(pc_ref[ivec]) ;
00788 free_PCOR_voxel_corr(pc_vc[ivec]) ;
00789 }
00790 free(vval) ; free(indx) ; free(pc_ref) ; free(pc_vc) ;
00791 if( aval != NULL ) free(aval) ;
00792 if( rbest != NULL ) free(rbest) ;
00793 if( abest != NULL ) free(abest) ;
00794 if( ibest != NULL ) free(ibest) ; /* 15 Dec 1997 */
00795 if( pbest != NULL ) free(pbest) ; /* 16 Jan 1998 */
00796 if( bbest != NULL ) free(bbest) ; /* 16 Jan 1998 */
00797 if( pval != NULL ) free(pval) ; /* 16 Jan 1998 */
00798 if( bval != NULL ) free(bval) ; /* 16 Jan 1998 */
00799 if( paval != NULL ) free(paval) ; /* 08 Sep 1999 */
00800 if( avval != NULL ) free(avval) ; /* 08 Sep 1999 */
00801 if( pabest!= NULL ) free(pabest); /* 08 Sep 1999 */
00802 if( avbest!= NULL ) free(avbest); /* 08 Sep 1999 */
00803 if( ptval != NULL ) free(ptval) ; /* 03 Jan 2000 */
00804 if( tlval != NULL ) free(tlval) ; /* 03 Jan 2000 */
00805 if( sgval != NULL ) free(sgval) ; /* 03 Jan 2000 */
00806 if( ptbest!= NULL ) free(ptbest); /* 03 Jan 2000 */
00807 if( tlbest!= NULL ) free(tlbest); /* 03 Jan 2000 */
00808 if( sgbest!= NULL ) free(sgbest); /* 03 Jan 2000 */
00809 RETURN(NULL) ;
00810 }
00811
00812 /*---------------------------------*/
00813 /*--- FIM: do recursive updates ---*/
00814
00815 #ifndef DONT_USE_METER
00816 meter = MCW_popup_meter( im3d->vwid->top_shell , METER_TOP_WIDE ) ;
00817 meter_pold = 0 ;
00818 #endif
00819
00820 STATUS("starting recursive least squares") ;
00821
00822 for( it=itbot ; it < ntime ; it++ ){ /* loop over time */
00823
00824 nnow = 0 ; /* number of updates done at this time point */
00825
00826 for( ivec=0 ; ivec < ny_ref ; ivec++ ){ /* loop over ref vects */
00827
00828 tsar = MRI_FLOAT_PTR(ref_ts) + (ivec*nx_ref) ; /* ptr to vect */
00829 if( tsar[it] >= WAY_BIG ) continue ; /* skip this */
00830
00831 ref_vec[0] = 1.0 ; /* we always supply ort for constant */
00832 for( ip=1 ; ip <= polort ; ip++ ) /* 30 May 1999: */
00833 ref_vec[ip] = ref_vec[ip-1] * ((float)it) ; /* and polynomials */
00834
00835 if( internal_ort ){ /* no external orts */
00836 ref_vec[ip] = tsar[it] ; /* ref value */
00837 } else {
00838 for( iv=0 ; iv < ny_ort ; iv++ ) /* external */
00839 ref_vec[iv+ip] = ortar[it + iv*nx_ort] ; /* orts */
00840
00841 ref_vec[ny_ort+ip] = tsar[it] ; /* ref value */
00842 }
00843
00844 if(PRINT_TRACING)
00845 { char str[256] ;
00846 sprintf(str,"time index=%d ideal[%d]=%f" , it,ivec,tsar[it] ) ;
00847 STATUS(str) ; }
00848
00849 /* process the ort+ref update */
00850
00851 update_PCOR_references( ref_vec , pc_ref[ivec] ) ;
00852
00853 /* first time thru: load data from dataset */
00854
00855 if( nnow == 0 ){
00856 float fac ;
00857 switch( dtyp ){
00858 case MRI_short:{
00859 short * dar = (short *) DSET_ARRAY(dset_time,it) ;
00860 for( iv=0; iv < nvox; iv++ ) vval[iv] = (float) dar[indx[iv]];
00861 }
00862 break ;
00863
00864 case MRI_float:{
00865 float * dar = (float *) DSET_ARRAY(dset_time,it) ;
00866 for( iv=0; iv < nvox; iv++ ) vval[iv] = (float) dar[indx[iv]];
00867 }
00868 break ;
00869
00870 case MRI_byte:{
00871 byte * dar = (byte *) DSET_ARRAY(dset_time,it) ;
00872 for( iv=0; iv < nvox; iv++ ) vval[iv] = (float) dar[indx[iv]];
00873 }
00874 break ;
00875 }
00876 fac = DSET_BRICK_FACTOR(dset_time,it) ; /* 21 Jul 2004: Ooopsie. */
00877 if( fac > 0.0 )
00878 for( iv=0 ; iv < nvox ; iv++ ) vval[iv] *= fac ;
00879 }
00880
00881 /* process the data update */
00882
00883 PCOR_update_float( vval , pc_ref[ivec] , pc_vc[ivec] ) ;
00884 nnow++ ; /* one more update at this time point */
00885 } /* end of loop over ref vects */
00886
00887 if( nnow > 0 ) nupdt++ ; /* number of time points that had updates */
00888
00889 #ifndef DONT_USE_METER
00890 meter_perc = (int) ( 100.0 * nupdt / ngood_ref ) ;
00891 if( meter_perc != meter_pold ){
00892 MCW_set_meter( meter , meter_perc ) ;
00893 meter_pold = meter_perc ;
00894 }
00895 #endif
00896
00897 } /* end of loop over time */
00898
00899 /*-------------------------------------------*/
00900 /*--- Load final results into the dataset ---*/
00901
00902 /*--- set the statistical parameters ---*/
00903
00904 stataux[0] = nupdt ; /* number of points used */
00905 stataux[1] = (ny_ref==1) ? 1 : 2 ; /* number of references */
00906 stataux[2] = fim_nref - 1 ; /* number of orts */
00907 for( iv=3 ; iv < MAX_STAT_AUX ; iv++ ) stataux[iv] = 0.0 ;
00908
00909 if( ibr_corr >= 0 ){
00910 if( new_dset->func_type == FUNC_COR_TYPE )
00911 EDIT_dset_items( new_dset, ADN_stat_aux, stataux, ADN_none ) ;
00912
00913 EDIT_BRICK_TO_FICO( new_dset, ibr_corr, stataux[0],stataux[1],stataux[2] ) ;
00914 }
00915
00916 #ifndef DONT_USE_METER
00917 # define METERIZE(ib) do { meter_perc = (int) ( 100.0 * (ib) / nbrik ) ; \
00918 if( meter_perc != meter_pold ){ \
00919 MCW_set_meter( meter , meter_perc ) ; \
00920 meter_pold = meter_perc ; \
00921 } } while(0)
00922 #else
00923 # define METERIZE(ib) /*nada*/
00924 #endif
00925
00926 /*** Compute brick arrays for new dataset ***/
00927 /* [load scale factors into stataux, too] */
00928
00929 if( ny_ref == 1 ){
00930
00931 /*** Just 1 ref vector --> load values directly into dataset ***/
00932
00933 if( ibr_fim >= 0 ){
00934
00935 STATUS("getting 1 ref alpha") ;
00936
00937 PCOR_get_coef( pc_ref[0] , pc_vc[0] , vval ) ;
00938
00939 topval = 0.0 ;
00940 for( iv=0 ; iv < nvox ; iv++ )
00941 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
00942
00943 bar = DSET_ARRAY( new_dset , ibr_fim ) ;
00944 memset( bar , 0 , sizeof(short)*nxyz ) ;
00945
00946 if( topval > 0.0 ){
00947 topval = MRI_TYPE_maxval[MRI_short] / topval ;
00948 for( iv=0 ; iv < nvox ; iv++ )
00949 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
00950
00951 stataux[ibr_fim] = 1.0/topval ;
00952 } else {
00953 stataux[ibr_fim] = 0.0 ;
00954 }
00955
00956 METERIZE(ibr_fim) ;
00957 }
00958
00959 if( ibr_corr >= 0 ){
00960
00961 STATUS("getting 1 ref pcor") ;
00962
00963 PCOR_get_pcor( pc_ref[0] , pc_vc[0] , vval ) ;
00964
00965 bar = DSET_ARRAY( new_dset , ibr_corr ) ;
00966 memset( bar , 0 , sizeof(short)*nxyz ) ;
00967
00968 for( iv=0 ; iv < nvox ; iv++ )
00969 bar[indx[iv]] = (short)(FUNC_COR_SCALE_SHORT * vval[iv] + 0.499) ;
00970
00971 stataux[ibr_corr] = 1.0 / FUNC_COR_SCALE_SHORT ;
00972
00973 METERIZE(ibr_corr) ;
00974 }
00975
00976 if( ibr_perc >= 0 ){
00977
00978 STATUS("getting 1 ref perc") ;
00979
00980 PCOR_get_perc( pc_ref[0] , pc_vc[0] , vval , NULL , 0 ) ;
00981
00982 if( top_perc > 0.0 ) EDIT_clip_float( top_perc , nvox , vval ) ;
00983
00984 topval = 0.0 ;
00985 for( iv=0 ; iv < nvox ; iv++ )
00986 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
00987
00988 bar = DSET_ARRAY( new_dset , ibr_perc ) ;
00989 memset( bar , 0 , sizeof(short)*nxyz ) ;
00990
00991 if( topval > 0.0 ){
00992 topval = MRI_TYPE_maxval[MRI_short] / topval ;
00993 for( iv=0 ; iv < nvox ; iv++ )
00994 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
00995
00996 stataux[ibr_perc] = 1.0/topval ;
00997 } else {
00998 stataux[ibr_perc] = 0.0 ;
00999 }
01000
01001 METERIZE(ibr_perc) ;
01002 }
01003
01004 if( ibr_pave >= 0 ){ /* 08 Sep 1999 */
01005
01006 STATUS("getting 1 ref pave") ;
01007
01008 PCOR_get_perc( pc_ref[0] , pc_vc[0] , vval , NULL , 1 ) ;
01009
01010 if( top_perc > 0.0 ) EDIT_clip_float( top_perc , nvox , vval ) ;
01011
01012 topval = 0.0 ;
01013 for( iv=0 ; iv < nvox ; iv++ )
01014 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
01015
01016 bar = DSET_ARRAY( new_dset , ibr_pave ) ;
01017 memset( bar , 0 , sizeof(short)*nxyz ) ;
01018
01019 if( topval > 0.0 ){
01020 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01021 for( iv=0 ; iv < nvox ; iv++ )
01022 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
01023
01024 stataux[ibr_pave] = 1.0/topval ;
01025 } else {
01026 stataux[ibr_pave] = 0.0 ;
01027 }
01028
01029 METERIZE(ibr_pave) ;
01030 }
01031
01032 if( ibr_ptop >= 0 ){ /* 03 Jan 2000 */
01033
01034 STATUS("getting 1 ref ptop") ;
01035
01036 PCOR_get_perc( pc_ref[0] , pc_vc[0] , vval , NULL , 2 ) ;
01037
01038 if( top_perc > 0.0 ) EDIT_clip_float( top_perc , nvox , vval ) ;
01039
01040 topval = 0.0 ;
01041 for( iv=0 ; iv < nvox ; iv++ )
01042 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
01043
01044 bar = DSET_ARRAY( new_dset , ibr_ptop ) ;
01045 memset( bar , 0 , sizeof(short)*nxyz ) ;
01046
01047 if( topval > 0.0 ){
01048 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01049 for( iv=0 ; iv < nvox ; iv++ )
01050 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
01051
01052 stataux[ibr_ptop] = 1.0/topval ;
01053 } else {
01054 stataux[ibr_ptop] = 0.0 ;
01055 }
01056
01057 METERIZE(ibr_ptop) ;
01058 }
01059
01060 if( ibr_base >= 0 ){
01061
01062 STATUS("getting 1 ref base") ;
01063
01064 PCOR_get_perc( pc_ref[0] , pc_vc[0] , NULL , vval , 0 ) ;
01065
01066 topval = 0.0 ;
01067 for( iv=0 ; iv < nvox ; iv++ )
01068 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
01069
01070 bar = DSET_ARRAY( new_dset , ibr_base ) ;
01071 memset( bar , 0 , sizeof(short)*nxyz ) ;
01072
01073 if( topval > 0.0 ){
01074 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01075 for( iv=0 ; iv < nvox ; iv++ )
01076 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
01077
01078 stataux[ibr_base] = 1.0/topval ;
01079 } else {
01080 stataux[ibr_base] = 0.0 ;
01081 }
01082
01083 METERIZE(ibr_base) ;
01084 }
01085
01086 if( ibr_aver >= 0 ){ /* 08 Sep 1999 */
01087
01088 STATUS("getting 1 ref aver") ;
01089
01090 PCOR_get_perc( pc_ref[0] , pc_vc[0] , NULL , vval , 1 ) ;
01091
01092 topval = 0.0 ;
01093 for( iv=0 ; iv < nvox ; iv++ )
01094 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
01095
01096 bar = DSET_ARRAY( new_dset , ibr_aver ) ;
01097 memset( bar , 0 , sizeof(short)*nxyz ) ;
01098
01099 if( topval > 0.0 ){
01100 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01101 for( iv=0 ; iv < nvox ; iv++ )
01102 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
01103
01104 stataux[ibr_aver] = 1.0/topval ;
01105 } else {
01106 stataux[ibr_aver] = 0.0 ;
01107 }
01108
01109 METERIZE(ibr_aver) ;
01110 }
01111
01112 if( ibr_topl >= 0 ){ /* 03 Jan 2000 */
01113
01114 STATUS("getting 1 ref topl") ;
01115
01116 PCOR_get_perc( pc_ref[0] , pc_vc[0] , NULL , vval , 2 ) ;
01117
01118 topval = 0.0 ;
01119 for( iv=0 ; iv < nvox ; iv++ )
01120 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
01121
01122 bar = DSET_ARRAY( new_dset , ibr_topl ) ;
01123 memset( bar , 0 , sizeof(short)*nxyz ) ;
01124
01125 if( topval > 0.0 ){
01126 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01127 for( iv=0 ; iv < nvox ; iv++ )
01128 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
01129
01130 stataux[ibr_topl] = 1.0/topval ;
01131 } else {
01132 stataux[ibr_topl] = 0.0 ;
01133 }
01134
01135 METERIZE(ibr_topl) ;
01136 }
01137
01138 if( ibr_sigm >= 0 ){ /* 03 Jan 2000 */
01139
01140 STATUS("getting 1 ref sigm") ;
01141
01142 PCOR_get_stdev( pc_vc[0] , vval ) ;
01143
01144 topval = 0.0 ;
01145 for( iv=0 ; iv < nvox ; iv++ )
01146 if( fabs(vval[iv]) > topval ) topval = fabs(vval[iv]) ;
01147
01148 bar = DSET_ARRAY( new_dset , ibr_sigm ) ;
01149 memset( bar , 0 , sizeof(short)*nxyz ) ;
01150
01151 if( topval > 0.0 ){
01152 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01153 for( iv=0 ; iv < nvox ; iv++ )
01154 bar[indx[iv]] = (short)(topval * vval[iv] + 0.499) ;
01155
01156 stataux[ibr_sigm] = 1.0/topval ;
01157 } else {
01158 stataux[ibr_sigm] = 0.0 ;
01159 }
01160
01161 METERIZE(ibr_sigm) ;
01162 }
01163
01164 } else {
01165
01166 /*** Multiple references --> find best correlation at each voxel ***/
01167
01168 /*--- get first ref results into abest and rbest (best so far) ---*/
01169
01170 STATUS("getting first ref results") ;
01171
01172 PCOR_get_coef( pc_ref[0] , pc_vc[0] , abest ) ;
01173 PCOR_get_pcor( pc_ref[0] , pc_vc[0] , rbest ) ;
01174 PCOR_get_perc( pc_ref[0] , pc_vc[0] , pbest , bbest , 0 ) ;
01175 PCOR_get_perc( pc_ref[0] , pc_vc[0] , pabest, avbest, 1 ) ;
01176 PCOR_get_perc( pc_ref[0] , pc_vc[0] , ptbest, tlbest, 2 ) ;
01177 PCOR_get_stdev( pc_vc[0] , sgbest ) ;
01178
01179 for( iv=0 ; iv < nvox ; iv++ ) ibest[iv] = 1 ; /* 15 Dec 1997 */
01180
01181 /*--- for each succeeding ref vector,
01182 get results into aval and vval,
01183 if |vval| > |rbest|, then use that result instead ---*/
01184
01185 for( ivec=1 ; ivec < ny_ref ; ivec++ ){
01186
01187 STATUS(" == getting results for next ref") ;
01188
01189 PCOR_get_coef( pc_ref[ivec] , pc_vc[ivec] , aval ) ;
01190 PCOR_get_pcor( pc_ref[ivec] , pc_vc[ivec] , vval ) ;
01191 PCOR_get_perc( pc_ref[ivec] , pc_vc[ivec] , pval , bval , 0 ) ;
01192 PCOR_get_perc( pc_ref[ivec] , pc_vc[ivec] , paval, avval, 1 ) ;
01193 PCOR_get_perc( pc_ref[ivec] , pc_vc[ivec] , ptval, tlval, 2 ) ;
01194 PCOR_get_stdev( pc_vc[ivec] , sgval ) ;
01195
01196 STATUS(" == and finding the best results") ;
01197
01198 for( iv=0 ; iv < nvox ; iv++ ){
01199 if( fabs(vval[iv]) > fabs(rbest[iv]) ){
01200 rbest[iv] = vval[iv] ;
01201 abest[iv] = aval[iv] ;
01202 ibest[iv] = (ivec+1) ; /* 15 Dec 1997 */
01203 pbest[iv] = pval[iv] ; /* Jan 1998 */
01204 bbest[iv] = bval[iv] ;
01205 pabest[iv]= paval[iv] ; /* 08 Sep 1999 */
01206 avbest[iv]= avval[iv] ;
01207 ptbest[iv]= ptval[iv] ; /* 03 Jan 1999 */
01208 tlbest[iv]= tlval[iv] ;
01209 sgbest[iv]= sgval[iv] ;
01210 }
01211 }
01212 }
01213
01214 /*--- at this point, abest and rbest are the best
01215 results, so scale them into the dataset bricks ---*/
01216
01217 /** fim brick **/
01218
01219 if( ibr_fim >= 0 ){
01220
01221 if(PRINT_TRACING)
01222 { char str[256]; sprintf(str,"getting ibr_fim=%d",ibr_fim); STATUS(str); }
01223
01224 topval = 0.0 ;
01225 for( iv=0 ; iv < nvox ; iv++ )
01226 if( fabs(abest[iv]) > topval ) topval = fabs(abest[iv]) ;
01227
01228 bar = DSET_ARRAY( new_dset , ibr_fim ) ;
01229 memset( bar , 0 , sizeof(short)*nxyz ) ;
01230
01231 if( topval > 0.0 ){
01232 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01233 for( iv=0 ; iv < nvox ; iv++ )
01234 bar[indx[iv]] = (short)(topval * abest[iv] + 0.499) ;
01235
01236 stataux[ibr_fim] = 1.0/topval ;
01237 } else {
01238 stataux[ibr_fim] = 0.0 ;
01239 }
01240
01241 METERIZE(ibr_fim) ;
01242 }
01243
01244 /** threshold brick **/
01245
01246 if( ibr_corr >= 0 ){
01247
01248 if(PRINT_TRACING)
01249 { char str[256]; sprintf(str,"getting ibr_corr=%d",ibr_corr); STATUS(str); }
01250
01251 bar = DSET_ARRAY( new_dset , ibr_corr ) ;
01252 memset( bar , 0 , sizeof(short)*nxyz ) ;
01253
01254 for( iv=0 ; iv < nvox ; iv++ )
01255 bar[indx[iv]] = (short)(FUNC_COR_SCALE_SHORT * rbest[iv] + 0.499) ;
01256
01257 stataux[ibr_corr] = 1.0 / FUNC_COR_SCALE_SHORT ;
01258
01259 METERIZE(ibr_corr) ;
01260 }
01261
01262 /** best index brick (15 Dec 1997) */
01263
01264 if( ibr_best >= 0 ){
01265
01266 if(PRINT_TRACING)
01267 { char str[256]; sprintf(str,"getting ibr_best=%d",ibr_best); STATUS(str); }
01268
01269 bar = DSET_ARRAY( new_dset , ibr_best ) ;
01270 memset( bar , 0 , sizeof(short)*nxyz ) ;
01271 for( iv=0 ; iv < nvox ; iv++ ) bar[indx[iv]] = ibest[iv] ;
01272 stataux[ibr_best] = 0.0 ; /* no scaling */
01273
01274 METERIZE(ibr_best) ;
01275 }
01276
01277 /** perc brick */
01278
01279 if( ibr_perc >= 0 ){
01280
01281 if(PRINT_TRACING)
01282 { char str[256]; sprintf(str,"getting ibr_perc=%d",ibr_perc); STATUS(str); }
01283
01284 if( top_perc > 0.0 ) EDIT_clip_float( top_perc , nvox , pbest ) ;
01285
01286 topval = 0.0 ;
01287 for( iv=0 ; iv < nvox ; iv++ )
01288 if( fabs(pbest[iv]) > topval ) topval = fabs(pbest[iv]) ;
01289
01290 bar = DSET_ARRAY( new_dset , ibr_perc ) ;
01291 memset( bar , 0 , sizeof(short)*nxyz ) ;
01292
01293 if( topval > 0.0 ){
01294 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01295 for( iv=0 ; iv < nvox ; iv++ )
01296 bar[indx[iv]] = (short)(topval * pbest[iv] + 0.499) ;
01297
01298 stataux[ibr_perc] = 1.0/topval ;
01299 } else {
01300 stataux[ibr_perc] = 0.0 ;
01301 }
01302
01303 METERIZE(ibr_perc) ;
01304 }
01305
01306 /** pave brick [08 Sep 1999] */
01307
01308 if( ibr_pave >= 0 ){
01309
01310 if(PRINT_TRACING)
01311 { char str[256]; sprintf(str,"getting ibr_pave=%d",ibr_pave); STATUS(str); }
01312
01313 if( top_perc > 0.0 ) EDIT_clip_float( top_perc , nvox , pabest ) ;
01314
01315 topval = 0.0 ;
01316 for( iv=0 ; iv < nvox ; iv++ )
01317 if( fabs(pabest[iv]) > topval ) topval = fabs(pabest[iv]) ;
01318
01319 bar = DSET_ARRAY( new_dset , ibr_pave ) ;
01320 memset( bar , 0 , sizeof(short)*nxyz ) ;
01321
01322 if( topval > 0.0 ){
01323 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01324 for( iv=0 ; iv < nvox ; iv++ )
01325 bar[indx[iv]] = (short)(topval * pabest[iv] + 0.499) ;
01326
01327 stataux[ibr_pave] = 1.0/topval ;
01328 } else {
01329 stataux[ibr_pave] = 0.0 ;
01330 }
01331
01332 METERIZE(ibr_pave) ;
01333 }
01334
01335 /** ptop brick [03 Jan 2000] */
01336
01337 if( ibr_ptop >= 0 ){
01338
01339 if(PRINT_TRACING)
01340 { char str[256]; sprintf(str,"getting ibr_ptop=%d",ibr_ptop); STATUS(str); }
01341
01342 if( top_perc > 0.0 ) EDIT_clip_float( top_perc , nvox , ptbest ) ;
01343
01344 topval = 0.0 ;
01345 for( iv=0 ; iv < nvox ; iv++ )
01346 if( fabs(ptbest[iv]) > topval ) topval = fabs(ptbest[iv]) ;
01347
01348 bar = DSET_ARRAY( new_dset , ibr_ptop ) ;
01349 memset( bar , 0 , sizeof(short)*nxyz ) ;
01350
01351 if( topval > 0.0 ){
01352 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01353 for( iv=0 ; iv < nvox ; iv++ )
01354 bar[indx[iv]] = (short)(topval * ptbest[iv] + 0.499) ;
01355
01356 stataux[ibr_ptop] = 1.0/topval ;
01357 } else {
01358 stataux[ibr_ptop] = 0.0 ;
01359 }
01360
01361 METERIZE(ibr_ptop) ;
01362 }
01363
01364 /** base brick */
01365
01366 if( ibr_base >= 0 ){
01367
01368 if(PRINT_TRACING)
01369 { char str[256]; sprintf(str,"getting ibr_base=%d",ibr_base); STATUS(str); }
01370
01371 topval = 0.0 ;
01372 for( iv=0 ; iv < nvox ; iv++ )
01373 if( fabs(bbest[iv]) > topval ) topval = fabs(bbest[iv]) ;
01374
01375 bar = DSET_ARRAY( new_dset , ibr_base ) ;
01376 memset( bar , 0 , sizeof(short)*nxyz ) ;
01377
01378 if( topval > 0.0 ){
01379 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01380 for( iv=0 ; iv < nvox ; iv++ )
01381 bar[indx[iv]] = (short)(topval * bbest[iv] + 0.499) ;
01382
01383 stataux[ibr_base] = 1.0/topval ;
01384 } else {
01385 stataux[ibr_base] = 0.0 ;
01386 }
01387
01388 METERIZE(ibr_base) ;
01389 }
01390
01391 /** aver brick [08 Sep 1999] */
01392
01393 if( ibr_aver >= 0 ){
01394
01395 if(PRINT_TRACING)
01396 { char str[256]; sprintf(str,"getting ibr_aver=%d",ibr_aver); STATUS(str); }
01397
01398 topval = 0.0 ;
01399 for( iv=0 ; iv < nvox ; iv++ )
01400 if( fabs(avbest[iv]) > topval ) topval = fabs(avbest[iv]) ;
01401
01402 bar = DSET_ARRAY( new_dset , ibr_aver ) ;
01403 memset( bar , 0 , sizeof(short)*nxyz ) ;
01404
01405 if( topval > 0.0 ){
01406 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01407 for( iv=0 ; iv < nvox ; iv++ )
01408 bar[indx[iv]] = (short)(topval * avbest[iv] + 0.499) ;
01409
01410 stataux[ibr_aver] = 1.0/topval ;
01411 } else {
01412 stataux[ibr_aver] = 0.0 ;
01413 }
01414
01415 METERIZE(ibr_aver) ;
01416 }
01417
01418 /** topl brick [03 Jan 2000] */
01419
01420 if( ibr_topl >= 0 ){
01421
01422 if(PRINT_TRACING)
01423 { char str[256]; sprintf(str,"getting ibr_topl=%d",ibr_topl); STATUS(str); }
01424
01425 topval = 0.0 ;
01426 for( iv=0 ; iv < nvox ; iv++ )
01427 if( fabs(tlbest[iv]) > topval ) topval = fabs(tlbest[iv]) ;
01428
01429 bar = DSET_ARRAY( new_dset , ibr_topl ) ;
01430 memset( bar , 0 , sizeof(short)*nxyz ) ;
01431
01432 if( topval > 0.0 ){
01433 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01434 for( iv=0 ; iv < nvox ; iv++ )
01435 bar[indx[iv]] = (short)(topval * tlbest[iv] + 0.499) ;
01436
01437 stataux[ibr_topl] = 1.0/topval ;
01438 } else {
01439 stataux[ibr_topl] = 0.0 ;
01440 }
01441
01442 METERIZE(ibr_topl) ;
01443 }
01444
01445 /** sigm brick [03 Jan 2000]**/
01446
01447 if( ibr_sigm >= 0 ){
01448
01449 if(PRINT_TRACING)
01450 { char str[256]; sprintf(str,"getting ibr_sigm=%d",ibr_sigm); STATUS(str); }
01451
01452 topval = 0.0 ;
01453 for( iv=0 ; iv < nvox ; iv++ )
01454 if( fabs(sgbest[iv]) > topval ) topval = fabs(sgbest[iv]) ;
01455
01456 bar = DSET_ARRAY( new_dset , ibr_sigm ) ;
01457 memset( bar , 0 , sizeof(short)*nxyz ) ;
01458
01459 if( topval > 0.0 ){
01460 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01461 for( iv=0 ; iv < nvox ; iv++ )
01462 bar[indx[iv]] = (short)(topval * sgbest[iv] + 0.499) ;
01463
01464 stataux[ibr_sigm] = 1.0/topval ;
01465 } else {
01466 stataux[ibr_sigm] = 0.0 ;
01467 }
01468
01469 METERIZE(ibr_sigm) ;
01470 }
01471
01472 } /* end of multiple reference case */
01473
01474 /*** Set the brick factors for the new dataset,
01475 no matter how it was computed above. ***/
01476
01477 STATUS("setting brick_fac") ;
01478
01479 (void) EDIT_dset_items( new_dset , ADN_brick_fac , stataux , ADN_none ) ;
01480
01481 #ifndef DONT_USE_METER
01482 MCW_set_meter( meter , 100 ) ;
01483 #endif
01484
01485 /*--- End of recursive updates; now free temporary workspaces ---*/
01486
01487 for( ivec=0 ; ivec < ny_ref ; ivec++ ){
01488 free_PCOR_references(pc_ref[ivec]) ;
01489 free_PCOR_voxel_corr(pc_vc[ivec]) ;
01490 }
01491 free(pc_ref) ; free(pc_vc) ;
01492 if( aval != NULL ) free(aval) ;
01493 if( rbest != NULL ) free(rbest) ;
01494 if( abest != NULL ) free(abest) ;
01495 if( ibest != NULL ) free(ibest) ; /* 15 Dec 1997 */
01496 if( pbest != NULL ) free(pbest) ; /* 16 Jan 1998 */
01497 if( bbest != NULL ) free(bbest) ; /* 16 Jan 1998 */
01498 if( pval != NULL ) free(pval) ; /* 16 Jan 1998 */
01499 if( bval != NULL ) free(bval) ; /* 16 Jan 1998 */
01500 if( paval != NULL ) free(paval) ; /* 08 Sep 1999 */
01501 if( avval != NULL ) free(avval) ; /* 08 Sep 1999 */
01502 if( pabest!= NULL ) free(pabest); /* 08 Sep 1999 */
01503 if( avbest!= NULL ) free(avbest); /* 08 Sep 1999 */
01504 if( ptval != NULL ) free(ptval) ; /* 03 Jan 2000 */
01505 if( tlval != NULL ) free(tlval) ; /* 03 Jan 2000 */
01506 if( sgval != NULL ) free(sgval) ; /* 03 Jan 2000 */
01507 if( ptbest!= NULL ) free(ptbest); /* 03 Jan 2000 */
01508 if( tlbest!= NULL ) free(tlbest); /* 03 Jan 2000 */
01509 if( sgbest!= NULL ) free(sgbest); /* 03 Jan 2000 */
01510
01511 /*-----------------------------------------------------*/
01512 /*--- 01 Feb 2000: execute user specified functions ---*/
01513
01514 ucode_stuff:
01515
01516 #define MAXUFUN 64 /* should be at least sizeof(int) */
01517 #define MAXTS 32 /* number of timeseries to process at once */
01518
01519 if( ucode != 0 ){
01520 MCW_function_list * rlist = &(GLOBAL_library.registered_fim) ;
01521 int uuse[MAXUFUN] , nbrik[MAXUFUN] , brik1[MAXUFUN] ;
01522 void * udata[MAXUFUN] ;
01523 generic_func * ufunc[MAXUFUN] ;
01524 int nuse , uu , newbrik , oldbrik ;
01525 FIMdata fd ;
01526 MRI_IMAGE * tsim ;
01527 float * tsar , * val , ** vbr ;
01528 short * sar ;
01529 int nts , jts , nbad=0 ;
01530 MRI_IMARR * imar ;
01531
01532 /* mark which ones to execute */
01533
01534 for( newbrik=nuse=uu=0 ; uu < rlist->num && nuse < MAXUFUN ; uu++ ){
01535 if( (ucode & (1<<uu)) != 0 ){
01536 uuse [nuse] = uu ;
01537 ufunc[nuse] = rlist->funcs[uu] ; /* user_func for this func */
01538 nbrik[nuse] = rlist->flags[uu] ; /* new bricks for this func */
01539 udata[nuse] = rlist->func_data[uu] ; /* user_data for this func */
01540 brik1[nuse] = newbrik ; /* index of 1st brick */
01541 newbrik += nbrik[nuse] ; /* total number of new bricks */
01542 nuse++ ;
01543 }
01544 }
01545
01546 if( nuse == 0 ) goto final_exit ; /* shouldn't happen */
01547
01548 /* do the initialization calls to the user_func functions */
01549
01550 fd.ref_ts = ref_ts ;
01551 fd.ort_ts = ort_ts ;
01552 fd.nvox = nvox ;
01553 fd.ignore = im3d->fimdata->init_ignore ;
01554 fd.polort = polort ;
01555
01556 #ifndef DONT_USE_METER
01557 MCW_set_meter( meter , 0 ) ; meter_pold = 0.0 ;
01558 #endif
01559
01560 for( uu=0 ; uu < nuse ; uu++ )
01561 #if 0
01562 ufunc[uu]( ntime , NULL , udata[uu] , nbrik[uu] , (void *)(&fd) ) ;
01563 #else
01564 AFNI_CALL_fim_function( ufunc[uu] ,
01565 ntime, NULL, udata[uu], nbrik[uu], &fd ) ;
01566 #endif
01567
01568 /* loop over voxels,
01569 assemble time series,
01570 call functions to put results in val[],
01571 store float outputs in vbr[][] */
01572
01573 vbr = (float **) malloc(sizeof(float *)*newbrik) ;
01574 for( iv=0 ; iv < newbrik ; iv++ )
01575 vbr[iv] = (float *) malloc(sizeof(float)*nvox) ;
01576
01577 val = (float *) malloc(sizeof(float)*newbrik) ;
01578
01579 for( iv=0 ; iv < nvox ; iv+=MAXTS ){
01580 nts = MIN( MAXTS , nvox-iv ) ;
01581 imar = THD_extract_many_series( nts,indx+iv , dset_time ) ;
01582
01583 for( jts=0 ; jts < nts ; jts++ ){
01584 tsim = IMARR_SUBIMAGE(imar,jts) ; /* data */
01585 tsar = MRI_FLOAT_PTR(tsim) ;
01586
01587 for( uu=0 ; uu < nuse ; uu++ ){
01588 #if 0
01589 ufunc[uu]( ntime , tsar , /* func */
01590 udata[uu] , nbrik[uu] , (void *) val ) ;
01591 #else
01592 AFNI_CALL_fim_function( ufunc[uu] ,
01593 ntime, tsar, udata[uu], nbrik[uu], val ) ;
01594 #endif
01595
01596 for( it=0 ; it < nbrik[uu] ; it++ ) /* storage */
01597 vbr[it+brik1[uu]][iv+jts] = val[it] ;
01598 }
01599 }
01600
01601 DESTROY_IMARR(imar) ; /* garbage disposal */
01602
01603 #ifndef DONT_USE_METER
01604 meter_perc = (int) ( 100.0 * iv / nvox ) ;
01605 if( meter_perc != meter_pold ){
01606 MCW_set_meter( meter , meter_perc ) ;
01607 meter_pold = meter_perc ;
01608 }
01609 #endif
01610 }
01611 free(val) ; /* no longer needed */
01612 #ifndef DONT_USE_METER
01613 MCW_set_meter( meter , 100 ) ;
01614 #endif
01615
01616 /* if necessary, make the new dataset now */
01617
01618 if( new_dset != NULL ){
01619 oldbrik = DSET_NVALS(new_dset) ; /* number of bricks it has now */
01620 } else {
01621 oldbrik = 0 ;
01622
01623 new_dset = EDIT_empty_copy( dset_time ) ;
01624
01625 EDIT_dset_items( new_dset ,
01626 ADN_prefix , new_prefix ,
01627 ADN_malloc_type , DATABLOCK_MEM_MALLOC ,
01628 ADN_type , ISHEAD(dset_time)
01629 ? HEAD_FUNC_TYPE : GEN_FUNC_TYPE ,
01630 ADN_func_type , FUNC_BUCK_TYPE ,
01631 ADN_nvals , newbrik ,
01632 ADN_datum_all , MRI_short ,
01633 ADN_ntt , 0 ,
01634 ADN_none ) ;
01635 }
01636
01637 /* for each output brick:
01638 make short space for it,
01639 scale and stored floats into this space ,
01640 attach it to the output dataset as a new brick */
01641
01642 for( iv=0 ; iv < newbrik ; iv++ ){
01643 tsar = vbr[iv] ; /* float data */
01644 topval = 0.0 ; /* find range of data */
01645
01646 nbad += thd_floatscan( nvox , tsar ) ; /* 08 Aug 2000 */
01647
01648 for( it=0 ; it < nvox ; it++ )
01649 if( fabs(tsar[it]) > topval ) topval = fabs(tsar[it]) ;
01650
01651 sar = (short *) calloc(sizeof(short),nxyz) ; /* new brick */
01652
01653 if( topval > 0.0 ){ /* scale to shorts */
01654 topval = MRI_TYPE_maxval[MRI_short] / topval ;
01655 for( it=0 ; it < nvox ; it++ )
01656 sar[indx[it]] = (short)(topval * tsar[it] + 0.499) ;
01657
01658 topval = 1.0/topval ; /* scale factor */
01659 }
01660
01661 free(tsar) ;
01662
01663 if( oldbrik > 0 ){
01664 EDIT_add_brick( new_dset , MRI_short , topval , sar ) ;
01665 } else {
01666 mri_fix_data_pointer( sar , DSET_BRICK(new_dset,iv) ) ;
01667 EDIT_BRICK_FACTOR( new_dset , iv , topval ) ;
01668 }
01669 }
01670 free(vbr) ;
01671
01672 /* do the ending calls to user_func */
01673
01674 for( uu=0 ; uu < nuse ; uu++ )
01675 #if 0
01676 ufunc[uu]( -(brik1[uu]+oldbrik) , NULL ,
01677 udata[uu] , nbrik[uu] , (void *) new_dset ) ;
01678 #else
01679 AFNI_CALL_fim_function( ufunc[uu] ,
01680 -(brik1[uu]+oldbrik) , NULL ,
01681 udata[uu] , nbrik[uu] , new_dset ) ;
01682 #endif
01683
01684 if( nbad > 0 )
01685 fprintf(stderr,
01686 "++ Warning: %d bad floats computed by user fimfuncs!\n\a",
01687 nbad ) ;
01688
01689 } /* 01 Feb 2000: end of user_func addition to FIMming */
01690
01691 final_exit:
01692 free(vval) ; free(indx) ; /* can finally free these */
01693
01694 /*--- Return new dataset ---*/
01695
01696 #ifndef DONT_USE_METER
01697 MCW_popdown_meter(meter) ;
01698 #endif
01699
01700 RETURN(new_dset) ;
01701 }
|
|
||||||||||||||||
|
sigm brick [03 Jan 2000]* Definition at line 1904 of file afni_fimmer.c. References AFNI_3DDATA_VIEW, AFNI_fimmer_compute(), AFNI_fimmer_redisplay(), AFNI_force_adoption(), AFNI_make_descendants(), AFNI_SEE_FUNC_ON, Three_D_View::anat_now, BEEPIT, Three_D_View::dc, MCW_DC::display, DSET_GRAPHABLE, DSET_HEADNAME, ENTRY, Three_D_View::fimdata, AFNI_fimmer_type::fimdset, AFNI_fimmer_type::fimort, AFNI_fimmer_type::fimref, GLOBAL_library, AFNI_library_type::have_dummy_dataset, IM3D_OPEN, AFNI_fimmer_type::init_ignore, ISVALID_SESSION, MRI_IMAGE::name, THD_session::num_dsset, AFNI_fimmer_type::polort, SHOW_AFNI_PAUSE, SHOW_AFNI_READY, Three_D_View::ss_now, AFNI_library_type::sslist, THD_MAX_SESSION_SIZE, THD_write_3dim_dataset(), tross_Append_History(), tross_Copy_History(), and Three_D_View::type. Referenced by AFNI_gra_send_CB().
01905 {
01906 THD_3dim_dataset * new_dset , * dset_time ;
01907 MRI_IMAGE * ref_ts , * ort_ts ;
01908 THD_session * sess ;
01909 int ifunc ;
01910
01911 ENTRY("AFNI_fimmer_execute") ;
01912
01913 if( ! IM3D_OPEN(im3d) || im3d->type != AFNI_3DDATA_VIEW ) EXRETURN ;
01914 if( GLOBAL_library.have_dummy_dataset ){ BEEPIT ; EXRETURN ; }
01915
01916 #if 0
01917 dset_time = im3d->anat_now ;
01918 #else
01919 dset_time = im3d->fimdata->fimdset ;
01920 #endif
01921
01922 if( ! DSET_GRAPHABLE(dset_time) ){ XBell(im3d->dc->display,100) ; EXRETURN ; }
01923
01924 ref_ts = im3d->fimdata->fimref ;
01925 ort_ts = im3d->fimdata->fimort ;
01926 if( ref_ts == NULL ){ XBell(im3d->dc->display,100) ; EXRETURN ; }
01927
01928 sess = im3d->ss_now ;
01929 if( ! ISVALID_SESSION(sess) || sess->num_dsset >= THD_MAX_SESSION_SIZE ){
01930 XBell(im3d->dc->display,100) ; EXRETURN ;
01931 }
01932
01933 SHOW_AFNI_PAUSE ;
01934
01935 /*--- Start lots of CPU time ---*/
01936
01937 new_dset = AFNI_fimmer_compute( im3d, dset_time, ref_ts, ort_ts,
01938 sess, code,ucode ) ;
01939
01940 /*--- End lots of CPU time ---*/
01941
01942 if( new_dset == NULL ){
01943 SHOW_AFNI_READY ;
01944 XBell(im3d->dc->display,100) ; EXRETURN ;
01945 }
01946
01947 AFNI_fimmer_redisplay( 1 , im3d , new_dset ) ;
01948 AFNI_SEE_FUNC_ON(im3d) ;
01949
01950 /* Sep 1999: add some history */
01951
01952 { char his[512] ; int hh ;
01953 tross_Copy_History( dset_time , new_dset ) ;
01954 sprintf(his,"afni FIM: 3D+time=%s ignore=%d polort=%d",
01955 DSET_HEADNAME(dset_time) ,
01956 im3d->fimdata->init_ignore , im3d->fimdata->polort ) ;
01957 if( ref_ts->name != NULL ){
01958 hh = strlen(his) ; sprintf(his+hh," ref=%s",ref_ts->name) ;
01959 }
01960 if( ort_ts != NULL && ort_ts->name != NULL ){
01961 hh = strlen(his) ; sprintf(his+hh," ort=%s",ort_ts->name) ;
01962 }
01963 tross_Append_History( new_dset , his ) ;
01964 }
01965
01966 /* write to disk */
01967
01968 (void) THD_write_3dim_dataset( NULL,NULL , new_dset , True ) ;
01969
01970 /*** At this point, FIM is computed and written to disk ***/
01971
01972 AFNI_force_adoption( sess , False ) ;
01973 AFNI_make_descendants( GLOBAL_library.sslist ) ;
01974
01975 SHOW_AFNI_READY ;
01976 EXRETURN ;
01977 }
|
|
||||||||||||||||
|
Definition at line 61 of file afni_fimmer.c. References AFNI_3DDATA_VIEW, AFNI_fimmer_setort(), ENTRY, GLOBAL_library, IM3D_VALID, IMARR_COUNT, IMARR_SUBIMAGE, MCW_choose_cbs::ival, mcwCR_timeseries, MCW_choose_cbs::reason, AFNI_library_type::timeseries, and Three_D_View::type.
00063 {
00064 Three_D_View * im3d = (Three_D_View *) cd ;
00065 int its ;
00066 MRI_IMAGE * tsim ;
00067
00068 ENTRY("AFNI_fimmer_pickort_CB") ;
00069
00070 if( ! IM3D_VALID(im3d) || im3d->type != AFNI_3DDATA_VIEW ) EXRETURN ;
00071 if( cbs->reason != mcwCR_timeseries ) EXRETURN ; /* error */
00072
00073 its = cbs->ival ;
00074 if( its >= 0 && its < IMARR_COUNT(GLOBAL_library.timeseries) ){
00075
00076 tsim = IMARR_SUBIMAGE(GLOBAL_library.timeseries,its) ;
00077 AFNI_fimmer_setort( im3d , tsim ) ;
00078 }
00079
00080 EXRETURN ;
00081 }
|
|
||||||||||||||||
|
Definition at line 36 of file afni_fimmer.c. References AFNI_3DDATA_VIEW, AFNI_fimmer_setref(), ENTRY, Three_D_View::fimdata, GLOBAL_library, IM3D_VALID, IMARR_COUNT, IMARR_SUBIMAGE, MCW_choose_cbs::ival, mcwCR_timeseries, MCW_choose_cbs::reason, AFNI_fimmer_type::refadd_count, AFNI_library_type::timeseries, and Three_D_View::type.
00038 {
00039 Three_D_View * im3d = (Three_D_View *) cd ;
00040 int its ;
00041 MRI_IMAGE * tsim ;
00042
00043 ENTRY("AFNI_fimmer_pickref_CB") ;
00044
00045 if( ! IM3D_VALID(im3d) || im3d->type != AFNI_3DDATA_VIEW ) EXRETURN ;
00046 if( cbs->reason != mcwCR_timeseries ) EXRETURN ; /* error */
00047
00048 its = cbs->ival ;
00049 if( its >= 0 && its < IMARR_COUNT(GLOBAL_library.timeseries) ){
00050
00051 tsim = IMARR_SUBIMAGE(GLOBAL_library.timeseries,its) ;
00052 AFNI_fimmer_setref( im3d , tsim ) ;
00053 im3d->fimdata->refadd_count = 1 ;
00054 }
00055
00056 EXRETURN ;
00057 }
|
|
||||||||||||||||
|
Definition at line 1981 of file afni_fimmer.c. References AFNI_initialize_view(), AFNI_redisplay_func(), AFNI_reset_func_range(), AFNI_set_thr_pval(), Three_D_View::anat_now, DSET_NVALS, THD_session::dsset, ENTRY, AFNI_view_info::fim_index, AFNI_view_info::func_num, THD_session::num_dsset, Three_D_View::ss_now, STATUS, THD_load_statistics(), AFNI_view_info::thr_index, THD_3dim_dataset::view_type, and Three_D_View::vinfo. Referenced by AFNI_fimmer_execute().
01983 {
01984 int ifunc ;
01985 THD_session * sess = im3d->ss_now ;
01986
01987 ENTRY("AFNI_fimmer_redisplay") ;
01988
01989 if( first_call ){
01990
01991 STATUS("first_call mode") ;
01992
01993 /*** Fit the new dataset into its place in the session ***/
01994
01995 ifunc = sess->num_dsset ;
01996 sess->dsset[ifunc][new_dset->view_type] = new_dset ;
01997 sess->num_dsset ++ ;
01998 im3d->vinfo->func_num = ifunc ;
01999
02000 STATUS("loading statistics") ;
02001 THD_load_statistics( new_dset ) ;
02002
02003 im3d->vinfo->fim_index = 0 ;
02004 im3d->vinfo->thr_index = 1 ;
02005 if( DSET_NVALS(new_dset) == 1 ) im3d->vinfo->thr_index = 0 ;
02006
02007 AFNI_initialize_view( im3d->anat_now , im3d ) ;
02008
02009 } else {
02010
02011 STATUS("redisplay mode") ;
02012
02013 /*** Just redisplay the new dataset ***/
02014
02015 STATUS("loading statistics") ;
02016 THD_load_statistics( new_dset ) ;
02017 AFNI_reset_func_range( im3d ) ;
02018 AFNI_set_thr_pval( im3d ) ;
02019
02020 AFNI_redisplay_func( im3d ) ; /* 05 Mar 2002 */
02021 }
02022
02023 EXRETURN ;
02024 }
|
|
||||||||||||
|
Definition at line 197 of file afni_fimmer.c. References AFNI_3DDATA_VIEW, ALLOW_COMPUTE_FIM, Three_D_View::anat_now, drive_MCW_grapher(), DSET_GRAPHABLE, ENTRY, Three_D_View::fimdata, AFNI_fimmer_type::fimdset, Three_D_View::g123, Three_D_View::g231, Three_D_View::g312, graDR_setignore, IM3D_VALID, AFNI_fimmer_type::init_ignore, and Three_D_View::type. Referenced by AFNI_gra_send_CB().
00198 {
00199 int ii ;
00200
00201 ENTRY("AFNI_fimmer_setignore") ;
00202
00203 if( ! IM3D_VALID(im3d) || im3d->type != AFNI_3DDATA_VIEW ) EXRETURN ;
00204
00205 if( im3d->g123 != NULL )
00206 drive_MCW_grapher( im3d->g123 , graDR_setignore , (XtPointer) new_ignore ) ;
00207
00208 if( im3d->g231 != NULL )
00209 drive_MCW_grapher( im3d->g231 , graDR_setignore , (XtPointer) new_ignore ) ;
00210
00211 if( im3d->g312 != NULL )
00212 drive_MCW_grapher( im3d->g312 , graDR_setignore , (XtPointer) new_ignore ) ;
00213
00214 im3d->fimdata->init_ignore = new_ignore ;
00215
00216 if( DSET_GRAPHABLE(im3d->anat_now) )
00217 im3d->fimdata->fimdset = im3d->anat_now ;
00218
00219 ALLOW_COMPUTE_FIM(im3d) ;
00220 EXRETURN ;
00221 }
|
|
||||||||||||
|
Definition at line 141 of file afni_fimmer.c. References AFNI_3DDATA_VIEW, AFNI_ts_in_library(), ALLOW_COMPUTE_FIM, Three_D_View::anat_now, drive_MCW_grapher(), DSET_GRAPHABLE, ENTRY, Three_D_View::fimdata, AFNI_fimmer_type::fimdset, AFNI_fimmer_type::fimort, Three_D_View::g123, Three_D_View::g231, Three_D_View::g312, graDR_addort_ts, IM3D_VALID, mri_free(), MRI_IMAGE::name, STATUS, and Three_D_View::type. Referenced by AFNI_fimmer_pickort_CB(), and AFNI_gra_send_CB().
00142 {
00143 int ii ;
00144
00145 ENTRY("AFNI_fimmer_setort") ;
00146
00147 if( ! IM3D_VALID(im3d) || im3d->type != AFNI_3DDATA_VIEW ) EXRETURN ;
00148
00149 if(PRINT_TRACING)
00150 { char str[256] ;
00151 sprintf(str,"setting fimort to %s",
00152 (tsim==NULL) ? "Nothing" : (tsim->name==NULL) ? "NoName" : tsim->name) ;
00153 STATUS(str) ; }
00154
00155 if( im3d->g123 != NULL )
00156 drive_MCW_grapher( im3d->g123 , graDR_addort_ts , (XtPointer) tsim ) ;
00157
00158 if( im3d->g231 != NULL )
00159 drive_MCW_grapher( im3d->g231 , graDR_addort_ts , (XtPointer) tsim ) ;
00160
00161 if( im3d->g312 != NULL )
00162 drive_MCW_grapher( im3d->g312 , graDR_addort_ts , (XtPointer) tsim ) ;
00163
00164 ii = AFNI_ts_in_library( tsim ) ;
00165
00166 if(PRINT_TRACING)
00167 { char str[256] ; sprintf(str,"found new ort in library at ii=%d",ii) ;
00168 STATUS(str) ; }
00169
00170 ii = AFNI_ts_in_library( im3d->fimdata->fimort ) ;
00171
00172 /* 12 Nov 1996: fix problem with freeing old
00173 ort that might be in the library */
00174
00175 if(PRINT_TRACING)
00176 { char str[256] ; sprintf(str,"found old ort in library at ii=%d",ii) ;
00177 STATUS(str) ; }
00178
00179 if( ii < 0 && im3d->fimdata->fimort != NULL ){
00180 mri_free(im3d->fimdata->fimort) ;
00181 STATUS("freed old ort since wasn't in library") ;
00182 }
00183
00184 im3d->fimdata->fimort = tsim ;
00185
00186 if( DSET_GRAPHABLE(im3d->anat_now) )
00187 im3d->fimdata->fimdset = im3d->anat_now ;
00188
00189 ALLOW_COMPUTE_FIM(im3d) ;
00190 EXRETURN ;
00191 }
|
|
||||||||||||
|
Definition at line 227 of file afni_fimmer.c. References AFNI_3DDATA_VIEW, ALLOW_COMPUTE_FIM, Three_D_View::anat_now, drive_MCW_grapher(), DSET_GRAPHABLE, ENTRY, Three_D_View::fimdata, AFNI_fimmer_type::fimdset, Three_D_View::g123, Three_D_View::g231, Three_D_View::g312, graDR_polort, IM3D_VALID, AFNI_fimmer_type::polort, and Three_D_View::type. Referenced by AFNI_gra_send_CB().
00228 {
00229 int ii ;
00230
00231 ENTRY("AFNI_fimmer_setpolort") ;
00232
00233 if( ! IM3D_VALID(im3d) || im3d->type != AFNI_3DDATA_VIEW ) EXRETURN ;
00234
00235 if( im3d->g123 != NULL )
00236 drive_MCW_grapher( im3d->g123 , graDR_polort , (XtPointer) new_polort ) ;
00237
00238 if( im3d->g231 != NULL )
00239 drive_MCW_grapher( im3d->g231 , graDR_polort , (XtPointer) new_polort ) ;
00240
00241 if( im3d->g312 != NULL )
00242 drive_MCW_grapher( im3d->g312 , graDR_polort , (XtPointer) new_polort ) ;
00243
00244 im3d->fimdata->polort = new_polort ;
00245
00246 if( DSET_GRAPHABLE(im3d->anat_now) )
00247 im3d->fimdata->fimdset = im3d->anat_now ;
00248
00249 ALLOW_COMPUTE_FIM(im3d) ;
00250 EXRETURN ;
00251 }
|
|
||||||||||||
|
Definition at line 87 of file afni_fimmer.c. References AFNI_3DDATA_VIEW, AFNI_ts_in_library(), ALLOW_COMPUTE_FIM, Three_D_View::anat_now, drive_MCW_grapher(), DSET_GRAPHABLE, ENTRY, Three_D_View::fimdata, AFNI_fimmer_type::fimdset, AFNI_fimmer_type::fimref, Three_D_View::g123, Three_D_View::g231, Three_D_View::g312, graDR_addref_ts, IM3D_VALID, mri_free(), MRI_IMAGE::name, STATUS, and Three_D_View::type. Referenced by AFNI_closedown_3dview(), AFNI_fimmer_pickref_CB(), AFNI_gra_send_CB(), and MAIN_workprocess().
00088 {
00089 int ii ;
00090
00091 ENTRY("AFNI_fimmer_setref") ;
00092
00093 if( ! IM3D_VALID(im3d) || im3d->type != AFNI_3DDATA_VIEW ) EXRETURN ;
00094
00095 if(PRINT_TRACING)
00096 { char str[256] ;
00097 sprintf(str,"setting fimref to %s",
00098 (tsim==NULL) ? "Nothing" : (tsim->name==NULL) ? "NoName" : tsim->name) ;
00099 STATUS(str) ; }
00100
00101 if( im3d->g123 != NULL )
00102 drive_MCW_grapher( im3d->g123 , graDR_addref_ts , (XtPointer) tsim ) ;
00103
00104 if( im3d->g231 != NULL )
00105 drive_MCW_grapher( im3d->g231 , graDR_addref_ts , (XtPointer) tsim ) ;
00106
00107 if( im3d->g312 != NULL )
00108 drive_MCW_grapher( im3d->g312 , graDR_addref_ts , (XtPointer) tsim ) ;
00109
00110 ii = AFNI_ts_in_library( tsim ) ;
00111
00112 if(PRINT_TRACING)
00113 { char str[256] ; sprintf(str,"found new ref in library at ii=%d",ii) ;
00114 STATUS(str) ; }
00115
00116 ii = AFNI_ts_in_library( im3d->fimdata->fimref ) ;
00117
00118 /* 12 Nov 1996: fix problem with freeing old
00119 ref that might be in the library */
00120
00121 if(PRINT_TRACING)
00122 { char str[256] ; sprintf(str,"found old ref in library at ii=%d",ii) ;
00123 STATUS(str) ; }
00124
00125 if( ii < 0 && im3d->fimdata->fimref != NULL ){
00126 mri_free(im3d->fimdata->fimref) ;
00127 STATUS("freed old ref since wasn't in library") ;
00128 }
00129
00130 im3d->fimdata->fimref = tsim ;
00131
00132 if( DSET_GRAPHABLE(im3d->anat_now) )
00133 im3d->fimdata->fimdset = im3d->anat_now ;
00134
00135 ALLOW_COMPUTE_FIM(im3d) ;
00136 EXRETURN ;
00137 }
|
|
|
Definition at line 2087 of file afni_fimmer.c. References XtPointer_array::ar, ev, GLOBAL_library, AFNI_library_type::interruptables, XtPointer_array::num, and MCW_interruptables::windows. Referenced by RCREND_autocompute_CB(), RCREND_read_exec_CB(), REND_autocompute_CB(), and REND_read_exec_CB().
02088 {
02089 Display * dis = XtDisplay(w) ;
02090 XEvent ev ;
02091 int ii , nwin ;;
02092
02093 /* make sure server has everything from us, then make sure display is OK */
02094
02095 XFlush( dis ) ; XmUpdateDisplay( w ) ;
02096
02097 /* if no windows are set to allow interrupts, then go home to mother */
02098
02099 if( GLOBAL_library.interruptables.windows == NULL ||
02100 GLOBAL_library.interruptables.windows->num == 0 ) return ;
02101
02102 nwin = GLOBAL_library.interruptables.windows->num ;
02103
02104 /* check for events;
02105 if they are in a window on our list, let Xt handle them;
02106 loop until all pending events have been handled or discarded */
02107
02108 while( XCheckMaskEvent( dis ,
02109 ButtonPressMask | ButtonReleaseMask |
02110 ButtonMotionMask | PointerMotionMask |
02111 KeyPressMask | KeyReleaseMask , &ev ) ){
02112
02113 for( ii=0 ; ii < nwin ; ii++ ){
02114 if( ev.xany.window ==
02115 (Window) GLOBAL_library.interruptables.windows->ar[ii] ){
02116
02117 XtDispatchEvent( &ev ) ; /* was on our list! */
02118 break ;
02119 }
02120 }
02121
02122 if( ii == nwin ) XBell( dis , 100 ) ; /* beep for non-allowed event */
02123 XUngrabPointer( dis , CurrentTime ) ; /* 17 Jun 2005 */
02124 }
02125
02126 return ;
02127 }
|
|
|
Definition at line 17 of file afni_fimmer.c. References ENTRY, GLOBAL_library, IMARR_COUNT, IMARR_SUBIMAGE, RETURN, and AFNI_library_type::timeseries. Referenced by AFNI_fimmer_setort(), AFNI_fimmer_setref(), AFNI_gra_send_CB(), and PLUG_choose_timeseries_CB().
00018 {
00019 int its ;
00020
00021 ENTRY("AFNI_ts_in_library") ;
00022
00023 if( GLOBAL_library.timeseries != NULL &&
00024 IMARR_COUNT(GLOBAL_library.timeseries) > 0 && tsim != NULL ){
00025
00026 for( its=0 ; its < IMARR_COUNT(GLOBAL_library.timeseries) ; its++ )
00027 if( tsim == IMARR_SUBIMAGE(GLOBAL_library.timeseries,its) )
00028 RETURN(its) ;
00029 }
00030
00031 RETURN(-1) ;
00032 }
|