Doxygen Source Code Documentation
thd_dsetdblk.c File Reference
#include "mrilib.h"
#include "thd.h"
Go to the source code of this file.
Defines | |
#define | USE_APPLICATOR |
Functions | |
void | THD_allow_empty_dataset (int n) |
THD_3dim_dataset * | THD_3dim_from_block (THD_datablock *blk) |
Variables | |
int | allow_nodata = 0 |
Define Documentation
|
With this macro defined, many of the attributes will actually be set in function THD_datablock_apply_atr() instead of herein. This change is to allow attributes read after the dataset struct is alread created to be useful, for the NIfTI-ization project. Definition at line 21 of file thd_dsetdblk.c. |
Function Documentation
|
Given a datablock, make it into a 3D dataset if possible. --------------------------------------------------------------------- Definition at line 27 of file thd_dsetdblk.c. References ADDTO_KILL, THD_marker_set::aflags, allow_nodata, THD_3dim_dataset::anat_parent, THD_3dim_dataset::anat_parent_idcode, THD_3dim_dataset::anat_parent_name, ATRNAME_ANATOMY_PARENT, ATRNAME_BRICK_STATS, ATRNAME_DATANAME, ATRNAME_DELTA, ATRNAME_IDANATPAR, ATRNAME_IDDATE, ATRNAME_IDSTRING, ATRNAME_IDWARPPAR, ATRNAME_KEYWORDS, ATRNAME_LABEL1, ATRNAME_LABEL2, ATRNAME_MARKSFLAG, ATRNAME_MARKSHELP, ATRNAME_MARKSLAB, ATRNAME_MARKSXYZ, ATRNAME_MINMAX, ATRNAME_ORIENT_SPECIFIC, ATRNAME_ORIGIN, ATRNAME_SCENE_TYPE, ATRNAME_STAT_AUX, ATRNAME_TAGSET_FLOATS, ATRNAME_TAGSET_LABELS, ATRNAME_TAGSET_NUM, ATRNAME_TAXIS_FLOATS, ATRNAME_TAXIS_NUMS, ATRNAME_TAXIS_OFFSETS, ATRNAME_TYPESTRING, ATRNAME_WARP_DATA, ATRNAME_WARP_PARENT, ATRNAME_WARP_TYPE, THD_statistics::bstat, ATR_string::ch, COPY_INTO_STRUCT, DATAXES_TYPE, MCW_idcode::date, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_3dim_dataset::death_mark, THD_diskptr::dimsizes, THD_datablock::diskptr, DSET_ERR, DSET_ERRN, DSET_HEADNAME, DSET_ONDISK, THD_timeaxis::dz_sl, ENTRY, FIRST_3DIM_TYPE, ATR_float::fl, THD_3dim_dataset::func_type, THD_diskptr::header_name, THD_marker_set::help, THD_3dim_dataset::idcode, ATR_int::in, INIT_KILL, INIT_STAT_AUX, INVALIDATE_BSTAT, ISFUNC, ISFUNCTYPE, ISVALID_DATABLOCK, ISVALID_DISKPTR, ISZERO_IDCODE, THD_3dim_dataset::keywords, THD_3dim_dataset::kl, THD_usertag::label, THD_usertaglist::label, THD_marker_set::label, THD_3dim_dataset::label1, THD_3dim_dataset::label2, LAST_3DIM_TYPE, LOAD_ZERO_MAT, MAPPING_LINEAR_FSIZE, MAPPING_LINEAR_FSTART, MAPPING_LINEAR_TYPE, THD_3dim_dataset::markers, MARKS_ASIZE, MARKS_ASTART, MARKS_FSIZE, MARKS_FSTART, MARKS_HSIZE, MARKS_HSTART, MARKS_LSIZE, MARKS_LSTART, MARKS_MAXFLAG, MARKS_MAXNUM, THD_mat33::mat, THD_brick_stats::max, MAX_TAG_NUM, MCW_IDDATE, MCW_IDSIZE, MCW_new_idcode, MCW_strncpy, THD_brick_stats::min, myXtNew, THD_statistics::nbstat, ATR_string::nch, ATR_float::nfl, ATR_int::nin, THD_timeaxis::nsl, THD_timeaxis::ntt, THD_usertaglist::num, THD_marker_set::numdef, THD_marker_set::numset, THD_datablock::nvals, THD_diskptr::nvals, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, ORI_A2P_TYPE, ORI_I2S_TYPE, ORI_L2R_TYPE, ORI_P2A_TYPE, ORI_R2L_TYPE, ORI_S2I_TYPE, THD_marker_set::ovcolor, THD_statistics::parent, THD_dataxes::parent, THD_3dim_dataset::parent, THD_datablock::parent, THD_diskptr::rank, THD_talairach_12_warp::resam_type, THD_affine_warp::resam_type, RETURN, THD_3dim_dataset::self_name, THD_3dim_dataset::self_warp, THD_usertag::set, STATISTICS_TYPE, THD_3dim_dataset::stats, STATUS, MCW_idcode::str, THD_usertaglist::tag, TAG_SETLABEL, THD_3dim_dataset::tagset, THD_3dim_dataset::taxis, THD_3dim_dataset::tcat_len, THD_3dim_dataset::tcat_list, THD_3dim_dataset::tcat_num, THD_datablock_apply_atr(), THD_DEFAULT_LABEL, THD_delete_3dim_dataset(), THD_FATAL_ERROR, THD_find_float_atr(), THD_find_int_atr(), THD_find_string_atr(), THD_MAX_LABEL, THD_MAX_NAME, THD_write_3dim_dataset(), THD_usertag::ti, TIMEAXIS_TYPE, THD_dataxes::to_dicomm, THD_timeaxis::toff_sl, THD_timeaxis::ttdel, THD_timeaxis::ttdur, THD_timeaxis::ttorg, THD_timeaxis::type, THD_statistics::type, THD_talairach_12_warp::type, THD_linear_mapping::type, THD_affine_warp::type, THD_marker_set::type, THD_dataxes::type, THD_3dim_dataset::type, UNITS_MSEC_TYPE, THD_timeaxis::units_type, THD_usertag::val, THD_marker_set::valid, THD_3dim_dataset::view_type, THD_3dim_dataset::vox_warp, THD_talairach_12_warp::warp, THD_affine_warp::warp, THD_3dim_dataset::warp, WARP_AFFINE_TYPE, THD_3dim_dataset::warp_parent, THD_3dim_dataset::warp_parent_idcode, THD_3dim_dataset::warp_parent_name, WARP_TALAIRACH_12_TYPE, THD_3dim_dataset::wod_daxes, THD_3dim_dataset::wod_flag, THD_usertag::x, XtMalloc, THD_dataxes::xxdel, THD_dataxes::xxmax, THD_dataxes::xxmin, THD_dataxes::xxorg, THD_dataxes::xxorient, THD_marker_set::xyz, THD_usertag::y, THD_dataxes::yydel, THD_dataxes::yymax, THD_dataxes::yymin, THD_dataxes::yyorg, THD_dataxes::yyorient, THD_usertag::z, ZERO_IDCODE, ZERO_STAT_AUX, THD_timeaxis::zorg_sl, THD_dataxes::zzdel, THD_dataxes::zzmax, THD_dataxes::zzmin, THD_dataxes::zzorg, and THD_dataxes::zzorient. Referenced by THD_array_3dim_from_block(), THD_niml_to_dataset(), and THD_open_one_dataset().
00028 { 00029 THD_3dim_dataset *dset ; 00030 THD_diskptr *dkptr ; 00031 THD_dataxes *daxes ; 00032 00033 Boolean dset_ok = True ; 00034 int iq ; 00035 00036 ATR_int *atr_int ; 00037 ATR_string *atr_str ; 00038 ATR_float *atr_flo ; 00039 00040 #if 0 00041 int new_idcode = 0 ; /* no longer needed */ 00042 #endif 00043 00044 ENTRY("THD_3dim_from_block") ; /* 29 Aug 2001 */ 00045 00046 /* sanity check */ 00047 00048 if( ! ISVALID_DATABLOCK(blk) || ! ISVALID_DISKPTR(blk->diskptr) ) 00049 RETURN( NULL ); 00050 00051 /*-- initialize a new 3D dataset --*/ 00052 00053 dset = myXtNew( THD_3dim_dataset ) ; /* uses XtCalloc() */ 00054 dset->dblk = blk ; 00055 dkptr = blk->diskptr ; 00056 00057 if( PRINT_TRACING ){ 00058 char str[256] ; 00059 sprintf(str,"rank=%d nvals=%d dim[0]=%d dim[1]=%d dim[2]=%d", 00060 dkptr->rank , dkptr->nvals , 00061 dkptr->dimsizes[0] , dkptr->dimsizes[1] , dkptr->dimsizes[2] ) ; 00062 STATUS(str) ; 00063 } 00064 00065 INIT_KILL(dset->kl) ; 00066 ADDTO_KILL(dset->kl,blk) ; 00067 00068 blk->parent = (XtPointer) dset ; 00069 dset->parent = NULL ; 00070 00071 daxes = dset->daxes = myXtNew(THD_dataxes) ; 00072 daxes->parent = (XtPointer) dset ; 00073 00074 dset->wod_daxes = NULL ; /* 02 Nov 1996 */ 00075 00076 dset->wod_flag = False ; /* set special flags */ 00077 dset->death_mark = 0 ; 00078 dset->tcat_list = NULL ; 00079 dset->tcat_num = 0 ; 00080 dset->tcat_len = NULL ; 00081 00082 ADDTO_KILL(dset->kl,daxes) ; 00083 00084 dset->stats = NULL ; 00085 #ifdef ALLOW_DATASET_VLIST 00086 dset->pts = NULL ; 00087 #endif 00088 dset->taxis = NULL ; 00089 dset->tagset = NULL ; /* 23 Oct 1998 */ 00090 00091 /*------------------*/ 00092 /*-- check for 3D --*/ 00093 /*------------------*/ 00094 00095 if( dkptr->rank != 3 ) DSET_ERRN("illegal # of dimensions",dkptr->rank) ; 00096 00097 /*--------------------------------------------------*/ 00098 /*-- find type of image from TYPESTRING attribute --*/ 00099 /*--------------------------------------------------*/ 00100 00101 atr_str = THD_find_string_atr( blk , ATRNAME_TYPESTRING ) ; 00102 if( atr_str == NULL ){ 00103 DSET_ERR("no TYPESTRING") ; 00104 dset->type = -1 ; 00105 } else { 00106 int type ; 00107 for( type=FIRST_3DIM_TYPE ; type <= LAST_3DIM_TYPE ; type++ ) 00108 if( strcmp( atr_str->ch , DATASET_typestr[type] ) == 0 ) break ; 00109 00110 if( type > LAST_3DIM_TYPE ) DSET_ERR("illegal TYPESTRING") ; 00111 dset->type = type ; 00112 } 00113 00114 /*-------------------------------------------------------*/ 00115 /*-- find view_type and func_type from SCENE_TYPE data --*/ 00116 /*-------------------------------------------------------*/ 00117 00118 atr_int = THD_find_int_atr( blk , ATRNAME_SCENE_TYPE ) ; 00119 if( atr_int == NULL ){ 00120 DSET_ERR("missing or illegal SCENE_TYPE") ; 00121 } else { 00122 dset->view_type = atr_int->in[0] ; 00123 dset->func_type = atr_int->in[1] ; 00124 00125 if( dset->type != atr_int->in[2] ){ 00126 DSET_ERR("non-matching SCENE_TYPE[2]") ; 00127 } 00128 } 00129 00130 /*-------------------------------------------------------*/ 00131 /*-- find identifier codes --*/ 00132 /*-------------------------------------------------------*/ 00133 00134 #ifndef USE_APPLICATOR 00135 atr_str = THD_find_string_atr( blk , ATRNAME_IDSTRING ) ; 00136 if( atr_str != NULL ){ 00137 MCW_strncpy( dset->idcode.str , atr_str->ch , MCW_IDSIZE ) ; 00138 atr_str = THD_find_string_atr( blk , ATRNAME_IDDATE ) ; 00139 if( atr_str == NULL ) 00140 MCW_strncpy( dset->idcode.date , "None" , MCW_IDDATE ) ; 00141 else 00142 MCW_strncpy( dset->idcode.date , atr_str->ch , MCW_IDDATE ) ; 00143 } 00144 #endif 00145 00146 ZERO_IDCODE(dset->anat_parent_idcode) ; 00147 ZERO_IDCODE(dset->warp_parent_idcode) ; 00148 00149 #ifndef USE_APPLICATOR 00150 atr_str = THD_find_string_atr( blk , ATRNAME_IDANATPAR ) ; 00151 if( atr_str != NULL ) 00152 MCW_strncpy( dset->anat_parent_idcode.str , atr_str->ch , MCW_IDSIZE ) ; 00153 00154 atr_str = THD_find_string_atr( blk , ATRNAME_IDWARPPAR ) ; 00155 if( atr_str != NULL ) 00156 MCW_strncpy( dset->warp_parent_idcode.str , atr_str->ch , MCW_IDSIZE ) ; 00157 #endif 00158 00159 /*--------------------------------*/ 00160 /*-- get data labels (optional) --*/ 00161 /*--------------------------------*/ 00162 00163 atr_str = THD_find_string_atr( blk , ATRNAME_LABEL1 ) ; 00164 if( atr_str == NULL ) 00165 atr_str = THD_find_string_atr( blk , ATRNAME_DATANAME ) ; 00166 00167 if( atr_str != NULL ){ 00168 MCW_strncpy( dset->label1 , atr_str->ch , THD_MAX_LABEL ) ; 00169 } else { 00170 MCW_strncpy( dset->label1 , THD_DEFAULT_LABEL , THD_MAX_LABEL ) ; 00171 } 00172 00173 atr_str = THD_find_string_atr( blk , ATRNAME_LABEL2 ) ; 00174 if( atr_str != NULL ){ 00175 MCW_strncpy( dset->label2 , atr_str->ch , THD_MAX_LABEL ) ; 00176 } else { 00177 MCW_strncpy( dset->label2 , THD_DEFAULT_LABEL , THD_MAX_LABEL ) ; 00178 } 00179 00180 dset->keywords = NULL ; 00181 #ifndef USE_APPLICATOR 00182 atr_str = THD_find_string_atr( blk , ATRNAME_KEYWORDS ) ; 00183 if( atr_str != NULL ) 00184 dset->keywords = XtNewString( atr_str->ch ) ; 00185 #endif 00186 00187 /*---------------------------------*/ 00188 /*-- get parent names (optional) --*/ 00189 /*---------------------------------*/ 00190 00191 dset->anat_parent_name[0] = '\0' ; 00192 dset->warp_parent_name[0] = '\0' ; 00193 MCW_strncpy( dset->self_name , THD_DEFAULT_LABEL , THD_MAX_NAME ) ; 00194 dset->anat_parent = dset->warp_parent = NULL ; /* must be set later */ 00195 00196 #ifndef USE_APPLICATOR 00197 atr_str = THD_find_string_atr( blk , ATRNAME_ANATOMY_PARENT ) ; 00198 if( atr_str != NULL && ISZERO_IDCODE(dset->anat_parent_idcode) ){ 00199 MCW_strncpy( dset->anat_parent_name , atr_str->ch , THD_MAX_NAME ) ; 00200 } 00201 00202 atr_str = THD_find_string_atr( blk , ATRNAME_WARP_PARENT ) ; 00203 if( atr_str != NULL && ISZERO_IDCODE(dset->warp_parent_idcode) ){ 00204 MCW_strncpy( dset->warp_parent_name , atr_str->ch , THD_MAX_NAME ) ; 00205 } 00206 00207 atr_str = THD_find_string_atr( blk , ATRNAME_DATANAME ) ; 00208 if( atr_str != NULL ){ 00209 MCW_strncpy( dset->self_name , atr_str->ch , THD_MAX_NAME ) ; 00210 } 00211 #endif 00212 00213 /*---------------------------*/ 00214 /*-- find axes orientation --*/ 00215 /*---------------------------*/ 00216 00217 daxes->type = DATAXES_TYPE ; 00218 daxes->nxx = dkptr->dimsizes[0] ; 00219 daxes->nyy = dkptr->dimsizes[1] ; 00220 daxes->nzz = dkptr->dimsizes[2] ; 00221 00222 atr_int = THD_find_int_atr( blk , ATRNAME_ORIENT_SPECIFIC ) ; 00223 if( atr_int == NULL ){ 00224 DSET_ERR("illegal or missing ORIENT_SPECIFIC") ; 00225 } else { 00226 daxes->xxorient = atr_int->in[0] ; 00227 daxes->yyorient = atr_int->in[1] ; 00228 daxes->zzorient = atr_int->in[2] ; 00229 } 00230 00231 /*----------------------*/ 00232 /*-- find axes origin --*/ 00233 /*----------------------*/ 00234 00235 atr_flo = THD_find_float_atr( blk , ATRNAME_ORIGIN ) ; 00236 if( atr_flo == NULL ){ 00237 DSET_ERR("illegal or missing ORIGIN") ; 00238 } else { 00239 daxes->xxorg = atr_flo->fl[0] ; 00240 daxes->yyorg = atr_flo->fl[1] ; 00241 daxes->zzorg = atr_flo->fl[2] ; 00242 } 00243 00244 /*------------------------*/ 00245 /*-- find axes spacings --*/ 00246 /*------------------------*/ 00247 00248 atr_flo = THD_find_float_atr( blk , ATRNAME_DELTA ) ; 00249 if( atr_flo == NULL ){ 00250 DSET_ERR("illegal or missing DELTA") ; 00251 } else { 00252 daxes->xxdel = atr_flo->fl[0] ; 00253 daxes->yydel = atr_flo->fl[1] ; 00254 daxes->zzdel = atr_flo->fl[2] ; 00255 } 00256 00257 /*---------------------------------------*/ 00258 /*-- set bounding box for this dataset --*/ 00259 /*---------------------------------------*/ 00260 00261 daxes->xxmin = daxes->xxorg ; 00262 daxes->xxmax = daxes->xxorg + (daxes->nxx-1) * daxes->xxdel ; 00263 if( daxes->xxmin > daxes->xxmax ){ 00264 float temp = daxes->xxmin ; 00265 daxes->xxmin = daxes->xxmax ; daxes->xxmax = temp ; 00266 } 00267 00268 daxes->yymin = daxes->yyorg ; 00269 daxes->yymax = daxes->yyorg + (daxes->nyy-1) * daxes->yydel ; 00270 if( daxes->yymin > daxes->yymax ){ 00271 float temp = daxes->yymin ; 00272 daxes->yymin = daxes->yymax ; daxes->yymax = temp ; 00273 } 00274 00275 daxes->zzmin = daxes->zzorg ; 00276 daxes->zzmax = daxes->zzorg + (daxes->nzz-1) * daxes->zzdel ; 00277 if( daxes->zzmin > daxes->zzmax ){ 00278 float temp = daxes->zzmin ; 00279 daxes->zzmin = daxes->zzmax ; daxes->zzmax = temp ; 00280 } 00281 00282 #ifdef EXTEND_BBOX 00283 daxes->xxmin -= 0.5 * fabs(daxes->xxdel) ; /* pushes edges back by 1/2 */ 00284 daxes->xxmax += 0.5 * fabs(daxes->xxdel) ; /* voxel dimensions (the box */ 00285 daxes->yymin -= 0.5 * fabs(daxes->yydel) ; /* defined above is based on */ 00286 daxes->yymax += 0.5 * fabs(daxes->yydel) ; /* voxel centers, not edges) */ 00287 daxes->zzmin -= 0.5 * fabs(daxes->zzdel) ; 00288 daxes->zzmax += 0.5 * fabs(daxes->zzdel) ; 00289 #endif 00290 00291 /*----------------------------------------------------------------*/ 00292 /*-- matrix that transforms to Dicom (left-posterior-superior) --*/ 00293 /*----------------------------------------------------------------*/ 00294 00295 /* At present, the code below just produces a permutation matrix. 00296 In the future, oblique scans may be allowed for by putting 00297 an arbitrary orthogonal matrix in here. (A non orthogonal 00298 matrix implies non-orthogonal image scan axes and/or a 00299 different set of units than mm, neither of which I will allow!) */ 00300 00301 LOAD_ZERO_MAT(daxes->to_dicomm) ; 00302 00303 switch( daxes->xxorient ){ 00304 case ORI_R2L_TYPE: 00305 case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][0] = 1.0 ; break ; 00306 case ORI_P2A_TYPE: 00307 case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][0] = 1.0 ; break ; 00308 case ORI_I2S_TYPE: 00309 case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][0] = 1.0 ; break ; 00310 00311 default: THD_FATAL_ERROR("illegal xxorient code") ; 00312 } 00313 00314 switch( daxes->yyorient ){ 00315 case ORI_R2L_TYPE: 00316 case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][1] = 1.0 ; break ; 00317 case ORI_P2A_TYPE: 00318 case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][1] = 1.0 ; break ; 00319 case ORI_I2S_TYPE: 00320 case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][1] = 1.0 ; break ; 00321 00322 default: THD_FATAL_ERROR("illegal yyorient code") ; 00323 } 00324 00325 switch( daxes->zzorient ){ 00326 case ORI_R2L_TYPE: 00327 case ORI_L2R_TYPE: daxes->to_dicomm.mat[0][2] = 1.0 ; break ; 00328 case ORI_P2A_TYPE: 00329 case ORI_A2P_TYPE: daxes->to_dicomm.mat[1][2] = 1.0 ; break ; 00330 case ORI_I2S_TYPE: 00331 case ORI_S2I_TYPE: daxes->to_dicomm.mat[2][2] = 1.0 ; break ; 00332 00333 default: THD_FATAL_ERROR("illegal zxorient code") ; 00334 } 00335 00336 /*------------------------------------*/ 00337 /*-- read set of markers (optional) --*/ 00338 /*------------------------------------*/ 00339 00340 dset->markers = NULL ; 00341 00342 #ifndef USE_APPLICATOR 00343 atr_flo = THD_find_float_atr( blk , ATRNAME_MARKSXYZ ) ; 00344 00345 if( atr_flo != NULL ){ 00346 dset->markers = myXtNew( THD_marker_set ) ; /* new set */ 00347 ADDTO_KILL(dset->kl , dset->markers) ; 00348 00349 /*-- copy floating coordinates into marker struct --*/ 00350 00351 COPY_INTO_STRUCT( *(dset->markers) , /* actual struct */ 00352 MARKS_FSTART , /* byte offset */ 00353 float , /* type being copied */ 00354 atr_flo->fl , /* start of source */ 00355 MARKS_FSIZE ) ; /* number of floats */ 00356 00357 /*----- must have labels along with coordinates -----*/ 00358 00359 atr_str = THD_find_string_atr( blk , ATRNAME_MARKSLAB ) ; 00360 if( atr_str == NULL ){ 00361 DSET_ERR("MARKS_XYZ present but not MARKS_LAB!") ; 00362 } else { 00363 int im , llen ; 00364 THD_ivec3 iv ; 00365 float xxdown,xxup , yydown,yyup , zzdown,zzup ; 00366 00367 /*-- copy labels into marker struct --*/ 00368 00369 COPY_INTO_STRUCT( *(dset->markers) , 00370 MARKS_LSTART , 00371 char , 00372 atr_str->ch , 00373 MARKS_LSIZE ) ; 00374 00375 /*-- check each marker for validity: 00376 non-blank label string, 00377 all coordinates inside bounding box --*/ 00378 00379 /** July 1995: extend bounding box a little, maybe **/ 00380 00381 #ifndef EXTEND_BBOX 00382 xxdown = daxes->xxmin - 0.501 * fabs(daxes->xxdel) ; 00383 xxup = daxes->xxmax + 0.501 * fabs(daxes->xxdel) ; 00384 yydown = daxes->yymin - 0.501 * fabs(daxes->yydel) ; 00385 yyup = daxes->yymax + 0.501 * fabs(daxes->yydel) ; 00386 zzdown = daxes->zzmin - 0.501 * fabs(daxes->zzdel) ; 00387 zzup = daxes->zzmax + 0.501 * fabs(daxes->zzdel) ; 00388 #else 00389 xxdown = daxes->xxmin ; 00390 xxup = daxes->xxmax ; 00391 yydown = daxes->yymin ; 00392 yyup = daxes->yymax ; 00393 zzdown = daxes->zzmin ; 00394 zzup = daxes->zzmax ; 00395 #endif 00396 00397 dset->markers->numdef = dset->markers->numset = 0 ; 00398 00399 for( im=0 ; im < MARKS_MAXNUM ; im++ ){ 00400 llen = strlen( &(dset->markers->label[im][0]) ) ; 00401 dset->markers->valid[im] = 00402 (llen > 0) && 00403 ( dset->markers->xyz[im][0] >= xxdown ) && 00404 ( dset->markers->xyz[im][0] <= xxup ) && 00405 ( dset->markers->xyz[im][1] >= yydown ) && 00406 ( dset->markers->xyz[im][1] <= yyup ) && 00407 ( dset->markers->xyz[im][2] >= zzdown ) && 00408 ( dset->markers->xyz[im][2] <= zzup ) ; 00409 00410 if( dset->markers->valid[im] ) (dset->markers->numset)++ ; 00411 00412 if( llen > 0 ) (dset->markers->numdef)++ ; 00413 00414 dset->markers->ovcolor[im] = -1 ; /* default color */ 00415 00416 } /* end of loop over markers */ 00417 } /* end of if marker labels exist */ 00418 00419 /*----- should also have help for each marker -----*/ 00420 00421 atr_str = THD_find_string_atr( blk , ATRNAME_MARKSHELP ) ; 00422 if( atr_str == NULL ){ 00423 int im ; 00424 for( im=0 ; im < MARKS_MAXNUM ; im++ ) 00425 dset->markers->help[im][0] = '\0' ; /* empty string */ 00426 } else { 00427 COPY_INTO_STRUCT( *(dset->markers) , 00428 MARKS_HSTART , 00429 char , 00430 atr_str->ch , 00431 MARKS_HSIZE ) ; 00432 } /* end of if marker help exists */ 00433 00434 /*----- should also have action flags for the marker set -----*/ 00435 00436 atr_int = THD_find_int_atr( blk , ATRNAME_MARKSFLAG ) ; 00437 if( atr_int == NULL ){ 00438 int im ; 00439 for( im=0 ; im < MARKS_MAXFLAG ; im++ ) 00440 dset->markers->aflags[im] = -1 ; 00441 } else { 00442 COPY_INTO_STRUCT( *(dset->markers) , 00443 MARKS_ASTART , 00444 int , 00445 atr_int->in , 00446 MARKS_ASIZE ) ; 00447 dset->markers->type = dset->markers->aflags[0] ; 00448 } /* end of if marker flags exist */ 00449 00450 } /* end of if markers exist */ 00451 #endif 00452 00453 /*--------------------------*/ 00454 /*-- read warp (optional) --*/ 00455 /*--------------------------*/ 00456 00457 dset->vox_warp = NULL ; /* 02 Nov 1996 */ 00458 dset->self_warp = NULL ; /* 26 Aug 2002 */ 00459 dset->warp = NULL ; 00460 00461 #ifndef USE_APPLICATOR 00462 atr_int = THD_find_int_atr( blk , ATRNAME_WARP_TYPE ) ; 00463 if( atr_int != NULL ){ /* no warp */ 00464 int wtype = atr_int->in[0] , rtype = atr_int->in[1] ; 00465 00466 dset->warp = myXtNew( THD_warp ) ; 00467 ADDTO_KILL( dset->kl , dset->warp ) ; 00468 00469 atr_flo = THD_find_float_atr( blk , ATRNAME_WARP_DATA ) ; 00470 if( atr_flo == NULL ){ 00471 DSET_ERR("illegal or missing WARP_DATA") ; 00472 } else { 00473 switch( wtype ){ 00474 00475 default: DSET_ERR("illegal WARP_TYPE warp code") ; break; 00476 00477 case WARP_AFFINE_TYPE:{ 00478 THD_affine_warp *ww = (THD_affine_warp *) dset->warp ; 00479 ww->type = wtype ; 00480 ww->resam_type = rtype ; 00481 ww->warp.type = MAPPING_LINEAR_TYPE ; 00482 00483 COPY_INTO_STRUCT( ww->warp , 00484 MAPPING_LINEAR_FSTART , 00485 float , 00486 atr_flo->fl , 00487 MAPPING_LINEAR_FSIZE ) ; 00488 } 00489 break ; /* end affine warp */ 00490 00491 case WARP_TALAIRACH_12_TYPE:{ 00492 THD_talairach_12_warp *ww = 00493 (THD_talairach_12_warp *) dset->warp ; 00494 int iw , ioff ; 00495 ww->type = wtype ; 00496 ww->resam_type = rtype ; 00497 for( iw=0 ; iw < 12 ; iw++ ){ 00498 ww->warp[iw].type = MAPPING_LINEAR_TYPE ; 00499 00500 ioff = iw * MAPPING_LINEAR_FSIZE ; 00501 00502 COPY_INTO_STRUCT( ww->warp[iw] , 00503 MAPPING_LINEAR_FSTART , 00504 float , 00505 &(atr_flo->fl[ioff]) , 00506 MAPPING_LINEAR_FSIZE ) ; 00507 00508 } /* end loop over 12 warps */ 00509 } 00510 break ; /* end talairach_12 warp */ 00511 00512 } /* end of switch on warp type */ 00513 } /* end of if on legal warp data */ 00514 } /* end of if on warp existing */ 00515 #endif 00516 00517 /*----- read statistics, if available -----*/ 00518 00519 #ifndef USE_APPLICATOR 00520 atr_flo = THD_find_float_atr( blk , ATRNAME_BRICK_STATS ) ; /* new style */ 00521 00522 if( atr_flo != NULL ){ /*** have new style statistics ***/ 00523 int qq ; 00524 dset->stats = myXtNew( THD_statistics ) ; 00525 dset->stats->type = STATISTICS_TYPE ; 00526 dset->stats->parent = (XtPointer) dset ; 00527 dset->stats->nbstat = blk->nvals ; 00528 dset->stats->bstat = (THD_brick_stats *) 00529 XtMalloc( sizeof(THD_brick_stats) * blk->nvals ) ; 00530 for( qq=0 ; qq < blk->nvals ; qq++ ){ 00531 if( 2*qq+1 < atr_flo->nfl ){ 00532 dset->stats->bstat[qq].min = atr_flo->fl[2*qq] ; 00533 dset->stats->bstat[qq].max = atr_flo->fl[2*qq+1] ; 00534 } else { 00535 INVALIDATE_BSTAT( dset->stats->bstat[qq] ) ; 00536 } 00537 } 00538 ADDTO_KILL( dset->kl , dset->stats->bstat ) ; 00539 ADDTO_KILL( dset->kl , dset->stats ) ; 00540 00541 } else { /**** check for old style (version 1.03-4) statistics ****/ 00542 00543 atr_int = THD_find_int_atr( blk , ATRNAME_MINMAX ) ; 00544 00545 if( atr_int == NULL ){ /*** no statistics at all ***/ 00546 dset->stats = NULL ; 00547 00548 } else { /*** have old style (integer) statistics ***/ 00549 int qq ; 00550 dset->stats = myXtNew( THD_statistics ) ; 00551 dset->stats->type = STATISTICS_TYPE ; 00552 dset->stats->parent = (XtPointer) dset ; 00553 dset->stats->nbstat = blk->nvals ; 00554 dset->stats->bstat = (THD_brick_stats *) 00555 XtMalloc( sizeof(THD_brick_stats) * blk->nvals ) ; 00556 for( qq=0 ; qq < blk->nvals ; qq++ ){ 00557 if( 2*qq+1 < atr_int->nin ){ 00558 dset->stats->bstat[qq].min = (float) atr_int->in[2*qq] ; 00559 dset->stats->bstat[qq].max = (float) atr_int->in[2*qq+1] ; 00560 } else { 00561 INVALIDATE_BSTAT( dset->stats->bstat[qq] ) ; 00562 } 00563 } 00564 ADDTO_KILL( dset->kl , dset->stats->bstat ) ; 00565 ADDTO_KILL( dset->kl , dset->stats ) ; 00566 } 00567 } 00568 #endif 00569 00570 /*--- read auxiliary statistics info, if any ---*/ 00571 00572 atr_flo = THD_find_float_atr( blk , ATRNAME_STAT_AUX ) ; 00573 00574 if( atr_flo != NULL ){ 00575 INIT_STAT_AUX( dset , atr_flo->nfl , atr_flo->fl ) ; 00576 iq = atr_flo->nfl ; 00577 } else { 00578 ZERO_STAT_AUX( dset ) ; 00579 iq = 0 ; 00580 } 00581 00582 if( ISFUNC(dset) && FUNC_need_stat_aux[dset->func_type] > iq ){ 00583 DSET_ERR("function type missing auxiliary statistical data") ; 00584 } 00585 00586 /*--- read time-dependent information, if any ---*/ 00587 00588 atr_int = THD_find_int_atr ( blk , ATRNAME_TAXIS_NUMS ) ; 00589 atr_flo = THD_find_float_atr( blk , ATRNAME_TAXIS_FLOATS ) ; 00590 00591 if( atr_int != NULL && atr_flo != NULL ){ 00592 int isfunc , nvals ; 00593 00594 dset->taxis = myXtNew( THD_timeaxis ) ; 00595 00596 dset->taxis->type = TIMEAXIS_TYPE ; 00597 dset->taxis->ntt = atr_int->in[0] ; 00598 dset->taxis->nsl = atr_int->in[1] ; 00599 dset->taxis->ttorg = atr_flo->fl[0] ; 00600 dset->taxis->ttdel = atr_flo->fl[1] ; 00601 dset->taxis->ttdur = atr_flo->fl[2] ; 00602 dset->taxis->zorg_sl = atr_flo->fl[3] ; 00603 dset->taxis->dz_sl = atr_flo->fl[4] ; 00604 00605 dset->taxis->units_type = atr_int->in[2] ; /* 21 Oct 1996 */ 00606 if( dset->taxis->units_type < 0 ) /* assign units */ 00607 dset->taxis->units_type = UNITS_MSEC_TYPE ; /* to the time axis */ 00608 00609 if( dset->taxis->nsl > 0 ){ 00610 atr_flo = THD_find_float_atr( blk , ATRNAME_TAXIS_OFFSETS ) ; 00611 if( atr_flo == NULL || atr_flo->nfl < dset->taxis->nsl ){ 00612 dset->taxis->nsl = 0 ; 00613 dset->taxis->toff_sl = NULL ; 00614 dset->taxis->zorg_sl = 0.0 ; 00615 dset->taxis->dz_sl = 0.0 ; 00616 } else { 00617 int ii ; 00618 dset->taxis->toff_sl = (float *) XtMalloc(sizeof(float)*dset->taxis->nsl) ; 00619 for( ii=0 ; ii < dset->taxis->nsl ; ii++ ) 00620 dset->taxis->toff_sl[ii] = atr_flo->fl[ii] ; 00621 } 00622 } else { 00623 dset->taxis->nsl = 0 ; 00624 dset->taxis->toff_sl = NULL ; 00625 dset->taxis->zorg_sl = 0.0 ; 00626 dset->taxis->dz_sl = 0.0 ; 00627 } 00628 00629 isfunc = ISFUNCTYPE(dset->type) ; 00630 nvals = (isfunc) ? FUNC_nvals[dset->func_type] 00631 : ANAT_nvals[dset->func_type] ; 00632 00633 if( nvals != 1 ) 00634 DSET_ERR("Illegal time-dependent dataset and func_type combination!") ; 00635 } 00636 00637 /*--- 23 Oct 1998: read the tagset information ---*/ 00638 00639 #ifndef USE_APPLICATOR 00640 atr_int = THD_find_int_atr ( blk , ATRNAME_TAGSET_NUM ) ; 00641 atr_flo = THD_find_float_atr ( blk , ATRNAME_TAGSET_FLOATS ) ; 00642 atr_str = THD_find_string_atr( blk , ATRNAME_TAGSET_LABELS ) ; 00643 00644 if( atr_int != NULL && atr_flo != NULL && atr_str != NULL ){ 00645 int nin=atr_int->nin , nfl=atr_flo->nfl , nch=atr_str->nch ; 00646 int ii , ntag , nfper , jj , kk ; 00647 00648 ntag = atr_int->in[0] ; /* number of tags */ 00649 nfper = atr_int->in[1] ; /* number of floats per tag */ 00650 00651 if( ntag > MAX_TAG_NUM ) ntag = MAX_TAG_NUM ; 00652 00653 dset->tagset = myXtNew( THD_usertaglist ) ; /* create tagset */ 00654 ADDTO_KILL( dset->kl , dset->tagset ) ; 00655 00656 dset->tagset->num = ntag ; 00657 strcpy( dset->tagset->label , "Bebe Rebozo" ) ; /* not used */ 00658 00659 /* read out tag values; allow for chance there isn't enough data */ 00660 00661 #undef TF 00662 #define TF(i,j) ( ((j)<nfper && (i)*nfper+(j)<nfl) ? atr_flo->fl[(i)*nfper+(j)] : -666.0 ) 00663 for( ii=0 ; ii < ntag ; ii++ ){ 00664 dset->tagset->tag[ii].x = TF(ii,0) ; /* coords */ 00665 dset->tagset->tag[ii].y = TF(ii,1) ; 00666 dset->tagset->tag[ii].z = TF(ii,2) ; 00667 dset->tagset->tag[ii].val = TF(ii,3) ; /* value */ 00668 dset->tagset->tag[ii].ti = TF(ii,4) ; /* time index; if < 0 ==> not set */ 00669 if( dset->tagset->tag[ii].ti >= 0 ){ 00670 dset->tagset->tag[ii].set = 1 ; 00671 } else { 00672 dset->tagset->tag[ii].set = 0 ; dset->tagset->tag[ii].ti = 0 ; 00673 } 00674 } 00675 #undef TF 00676 00677 /* read out tag labels; allow for empty labels */ 00678 00679 jj = 0 ; 00680 for( ii=0 ; ii < ntag ; ii++ ){ 00681 if( jj < nch ){ 00682 kk = strlen( atr_str->ch + jj ) ; 00683 if( kk > 0 ) TAG_SETLABEL( dset->tagset->tag[ii] , atr_str->ch + jj ) ; 00684 else sprintf( dset->tagset->tag[ii].label , "Tag %d" , ii+1 ) ; 00685 jj += kk+1 ; 00686 } else { 00687 sprintf( dset->tagset->tag[ii].label , "Tag %d" , ii+1 ) ; 00688 } 00689 } 00690 } 00691 #endif 00692 00693 /* 10 May 2005: new function to apply some attributes 00694 to dataset, rather than doing it here */ 00695 00696 #ifdef USE_APPLICATOR 00697 THD_datablock_apply_atr( dset ) ; 00698 #endif 00699 00700 /*--- check for the following conditions: 00701 if warp exists, warp_parent_name or _idcode must exist; 00702 if warp nonexists, warp_parent_name and _idcode must nonexist, 00703 AND data must exist on disk ---*/ 00704 00705 if( dset->warp != NULL ){ 00706 if( strlen(dset->warp_parent_name) <= 0 && 00707 ISZERO_IDCODE(dset->warp_parent_idcode) ) 00708 DSET_ERR("have warp but have no warp parent") ; 00709 00710 dset->wod_flag = !allow_nodata && !DSET_ONDISK(dset) ; 00711 } else { 00712 if( strlen(dset->warp_parent_name) > 0 || 00713 !ISZERO_IDCODE(dset->warp_parent_idcode) ) 00714 DSET_ERR("have no warp but have warp parent") ; 00715 00716 if( !allow_nodata && !DSET_ONDISK(dset) ) 00717 DSET_ERR("have no warp but have no data on disk as well") ; 00718 } 00719 00720 /* backup assignment of ID code if not assigned earlier */ 00721 00722 if( dset->idcode.str[0] == '\0' ) dset->idcode = MCW_new_idcode() ; 00723 00724 /*--- that's all the work for now; 00725 if any error was flagged, kill this dataset and return nothing ---*/ 00726 00727 if( dset_ok == False ){ 00728 fprintf(stderr,"PURGING dataset %s from memory\n",DSET_HEADNAME(dset)) ; 00729 THD_delete_3dim_dataset( dset , False ) ; 00730 RETURN(NULL) ; 00731 } 00732 00733 /*--- If we assigned a new dataset idcode, write it back to disk ---*/ 00734 /* (This code was for the old days, when there were datasets) 00735 (hanging around that hadn't yet been assigned ID codes. ) */ 00736 00737 #if 0 00738 if( dset != NULL && new_idcode ){ 00739 fprintf(stderr,"** Writing new ID code to dataset header %s\n", 00740 dset->dblk->diskptr->header_name ) ; 00741 THD_write_3dim_dataset( NULL , NULL , dset , False ) ; 00742 } 00743 #endif 00744 00745 RETURN( dset ); 00746 } |
|
Definition at line 13 of file thd_dsetdblk.c. References allow_nodata. Referenced by THD_fetch_dataset(), and THD_niml_to_dataset().
00013 { allow_nodata = n ; } |
Variable Documentation
|
Definition at line 11 of file thd_dsetdblk.c. Referenced by THD_3dim_from_block(), and THD_allow_empty_dataset(). |