1 /***************************************************************************** 2 Major portions of this software are copyrighted by the Medical College 3 of Wisconsin, 1994-2000, and are released under the Gnu General Public 4 License, Version 2. See the file README.Copyright for details. 5 ******************************************************************************/ 6 7 #include "mrilib.h" 8 #include "thd.h" 9 10 /*---------------------------------------------------------------- 11 Create an array of associated 3D datasets from an array of 12 datablocks 13 ------------------------------------------------------------------*/ 14 15 THD_3dim_dataset_array * THD_array_3dim_from_block(THD_datablock_array * blk_arr)16 THD_array_3dim_from_block( THD_datablock_array *blk_arr ) 17 { 18 THD_3dim_dataset_array *dset_arr ; 19 THD_3dim_dataset *dset ; 20 int id ; 21 RwcBoolean dset_ok = True , all_anat , all_func ; 22 23 ENTRY("THD_array_3dim_from_block") ; 24 25 INIT_3DARR( dset_arr ) ; 26 27 if( blk_arr == NULL || blk_arr->num <= 0 ) RETURN(dset_arr) ; 28 29 for( id=0 ; id < blk_arr->num ; id++ ){ 30 31 dset = THD_3dim_from_block( blk_arr->ar[id] ) ; 32 33 if( dset != NULL ) ADDTO_3DARR( dset_arr , dset ) ; 34 } 35 36 if( dset_arr->num <= 0 ) RETURN(dset_arr) ; 37 38 /******************************************************/ 39 /*-- now, check the set of datasets for consistency --*/ 40 /******************************************************/ 41 42 /*-- 1. Images should all be anatomy type or function type --*/ 43 44 all_anat = all_func = True ; 45 for( id=0 ; id < dset_arr->num ; id++ ){ 46 dset = dset_arr->ar[id] ; 47 all_anat = all_anat && ISANAT(dset) ; 48 all_func = all_func && ISFUNC(dset) ; 49 } 50 if( !all_anat && !all_func ){ /* 24 Nov 2009 */ 51 static int nwarn=0 ; 52 if( nwarn == 0 ) 53 WARNING_message("dataset %s: mixed ANAT and FUNC? in different views?", 54 DSET_HEADNAME(dset_arr->ar[0]) ) ; 55 nwarn++ ; 56 } 57 58 SORT_3DARR( dset_arr ) ; 59 60 /*-- 2. If all images are anat, nothing to do at this moment. --*/ 61 62 if( all_anat ){ 63 } /* end of dealing with all_anat case */ 64 65 /*-- 3. If all images are func .... --*/ 66 67 if( all_func ){ 68 #if 0 69 THD_3dim_dataset *dset0 ; 70 int jd ; 71 72 /* check for anat parents (should all have one) */ 73 74 for( id=0 ; id < dset_arr->num ; id++ ){ /* check for anat parent */ 75 dset = dset_arr->ar[id] ; 76 if( strlen(dset->anat_parent_name) == 0 ) 77 DSET_WARN("functional image has no anatomical parent!") ; 78 } 79 #endif 80 81 } /* end of dealing with all_func case */ 82 83 /*********************************************************/ 84 /*---------- if an error occurred, clean up -------------*/ 85 /*********************************************************/ 86 87 if( ! dset_ok ){ 88 89 /*-- delete data in subsidiary data structures --*/ 90 91 for( id=0 ; id < dset_arr->num ; id++ ){ 92 THD_delete_3dim_dataset( dset_arr->ar[id] , False ) ; 93 myRwcFree( dset_arr->ar[id] ) ; 94 } 95 96 FREE_3DARR( dset_arr ) ; 97 INIT_3DARR( dset_arr ) ; /* return a blank array */ 98 } 99 100 /*-- at last! 101 give the caller the list of (nearly) initialized datasets --*/ 102 103 RETURN(dset_arr) ; 104 } 105