Doxygen Source Code Documentation
r_new_resam_dset.h File Reference
Go to the source code of this file.
Functions | |
| THD_3dim_dataset * | r_new_resam_dset (THD_3dim_dataset *din, THD_3dim_dataset *min, double dx, double dy, double dz, char orient[], int resam_mode, int *sublist) |
| int | r_dxyz_mod_dataxes (double dx, double dy, double dz, THD_dataxes *daxin, THD_dataxes *daxout) |
| int | r_fill_resampled_data_brick (THD_3dim_dataset *dset, int resam_mode) |
| int | r_orient_str2vec (char ostr[], THD_ivec3 *ovec) |
| Boolean | r_is_valid_orient_str (char ostr[]) |
Function Documentation
|
||||||||||||||||||||||||
|
Definition at line 298 of file r_new_resam_dset.c. References ISVALID_DATAXES, THD_dataxes::nxx, THD_dataxes::nyy, THD_dataxes::nzz, THD_dataxes::xxdel, THD_dataxes::xxmax, THD_dataxes::xxmin, THD_dataxes::xxorg, THD_dataxes::yydel, THD_dataxes::yymax, THD_dataxes::yymin, THD_dataxes::yyorg, THD_dataxes::zzdel, THD_dataxes::zzmax, THD_dataxes::zzmin, and THD_dataxes::zzorg. Referenced by r_new_resam_dset().
00301 {
00302 double rex, rey, rez;
00303 double lxx, lyy, lzz;
00304 int ret_val;
00305
00306 if ( ! ISVALID_DATAXES( daxin ) || ! ISVALID_DATAXES( daxout ) )
00307 return -1;
00308
00309 *daxout = *daxin; /* start with a copy */
00310
00311 if ( dx <= 0.0 || dy <= 0.0 || dz <= 0.0 )
00312 return -1; /* having duplicated the structures */
00313
00314 rex = (daxout->xxdel > 0) ? dx : -dx; /* signed voxel sizes */
00315 rey = (daxout->yydel > 0) ? dy : -dy;
00316 rez = (daxout->zzdel > 0) ? dz : -dz;
00317
00318 lxx = daxin->nxx * daxin->xxdel; /* signed lengths of data box */
00319 lyy = daxin->nyy * daxin->yydel;
00320 lzz = daxin->nzz * daxin->zzdel;
00321
00322 daxout->nxx = (int)( lxx/rex + 0.499 ); /* so this is > 0 */
00323 daxout->nyy = (int)( lyy/rey + 0.499 );
00324 daxout->nzz = (int)( lzz/rez + 0.499 );
00325
00326 /* go from old edge to old center, then back out to new edge */
00327 daxout->xxorg = daxin->xxorg + 0.5*(lxx - daxin->xxdel)
00328 - 0.5*(daxout->nxx - 1)*rex;
00329
00330 daxout->yyorg = daxin->yyorg + 0.5*(lyy - daxin->yydel)
00331 - 0.5*(daxout->nyy - 1)*rey;
00332
00333 daxout->zzorg = daxin->zzorg + 0.5*(lzz - daxin->zzdel)
00334 - 0.5*(daxout->nzz - 1)*rez;
00335
00336 /* dave new dimensions */
00337 daxout->xxdel = rex;
00338 daxout->yydel = rey;
00339 daxout->zzdel = rez;
00340
00341 /* create a new bounding box */
00342 /* (note that xxdel<0 implies we must swap min/max) */
00343 daxout->xxmin = daxout->xxorg;
00344 daxout->xxmax = daxout->xxorg + (daxout->nxx-1)*daxout->xxdel;
00345 if ( daxout->xxmin > daxout->xxmax )
00346 {
00347 double tmp = daxout->xxmin;
00348 daxout->xxmin = daxout->xxmax;
00349 daxout->xxmax = tmp;
00350 }
00351
00352 daxout->yymin = daxout->yyorg;
00353 daxout->yymax = daxout->yyorg + (daxout->nyy-1)*daxout->yydel;
00354 if ( daxout->yymin > daxout->yymax )
00355 {
00356 double tmp = daxout->yymin;
00357 daxout->yymin = daxout->yymax;
00358 daxout->yymax = tmp;
00359 }
00360
00361 daxout->zzmin = daxout->zzorg;
00362 daxout->zzmax = daxout->zzorg + (daxout->nzz-1)*daxout->zzdel;
00363 if ( daxout->zzmin > daxout->zzmax )
00364 {
00365 double tmp = daxout->zzmin;
00366 daxout->zzmin = daxout->zzmax;
00367 daxout->zzmax = tmp;
00368 }
00369
00370 #ifdef EXTEND_BBOX
00371 daxout->xxmin -= 0.5 * daxout->xxdel;
00372 daxout->xxmax += 0.5 * daxout->xxdel;
00373 daxout->yymin -= 0.5 * daxout->yydel;
00374 daxout->yymax += 0.5 * daxout->yydel;
00375 daxout->zzmin -= 0.5 * daxout->zzdel;
00376 daxout->zzmax += 0.5 * daxout->zzdel;
00377 #endif
00378
00379 return ret_val = 0;
00380 }
|
|
||||||||||||
|
Definition at line 205 of file r_new_resam_dset.c. References ADDTO_KILL, AFNI_dataset_slice(), THD_diskptr::byte_order, DATABLOCK_MEM_MALLOC, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, DBLK_BRICK_FACTOR, THD_datablock::diskptr, dptr, DSET_BRICK_TYPE, DSET_LOADED, DSET_lock, EDIT_substitute_brick(), FAIL, free, IDENTITY_WARP, THD_3dim_dataset::kl, malloc, THD_datablock::malloc_type, mri_data_pointer(), mri_datum_size(), mri_free(), mri_short_order(), myXtNew, THD_diskptr::nvals, THD_dataxes::nxx, THD_dataxes::nyy, nz, THD_dataxes::nzz, STORAGE_BY_BRICK, THD_diskptr::storage_mode, THD_load_statistics(), this_file, THD_3dim_dataset::warp, and THD_3dim_dataset::wod_flag. Referenced by r_new_resam_dset().
00206 {
00207 THD_diskptr * diskptr = dset->dblk->diskptr;
00208 MRI_IMAGE * im;
00209 char * newdata, * dptr;
00210 float bfac;
00211 int ival, dsize;
00212 int nx, ny, nz, nxy, nxyz, nv;
00213 int slice;
00214
00215 if ( DSET_LOADED(dset) )
00216 {
00217 fprintf( stderr, "error <%s>: trying to fill pre-loaded dataset\n",
00218 this_file );
00219 return FAIL;
00220 }
00221
00222 DSET_lock(dset); /* since it will just sit in memory for now */
00223
00224 /* a basic warp is needed if header is written out - PLUTO_add_dset() */
00225 dset->warp = myXtNew( THD_warp );
00226 *dset->warp = IDENTITY_WARP;
00227 ADDTO_KILL( dset->kl, dset->warp );
00228
00229 diskptr->byte_order = mri_short_order();
00230 diskptr->storage_mode = STORAGE_BY_BRICK;
00231
00232 /* note new dimensions */
00233 nx = dset->daxes->nxx; ny = dset->daxes->nyy; nz = dset->daxes->nzz;
00234 nv = diskptr->nvals;
00235
00236 nxy = nx * ny;
00237 nxyz = nx * ny * nz;
00238
00239 /* recompute sub-bricks */
00240 for ( ival = 0; ival < nv; ival++ ) /* for each sub-brick */
00241 {
00242 /* first create memory to deposit the slices into */
00243 dsize = mri_datum_size( DSET_BRICK_TYPE(dset, ival) );
00244
00245 if ( (newdata = (char *)malloc( nxyz * dsize )) == NULL )
00246 {
00247 fprintf( stderr, "r frdb: alloc failure: %d bytes!\n",
00248 nxyz * dsize );
00249 return FAIL;
00250 }
00251
00252 dptr = newdata; /* we will copy images at dptr */
00253
00254 /* force return of unscaled slices for output - reset fac at end */
00255 bfac = DBLK_BRICK_FACTOR(dset->dblk,ival);
00256 DBLK_BRICK_FACTOR(dset->dblk,ival) = 0.0;
00257
00258 /* for each slice, insert it into memory */
00259 for ( slice = 0; slice < nz; slice++)
00260 {
00261 im = AFNI_dataset_slice( dset, 3, slice, ival, resam );
00262 if ( im == NULL )
00263 {
00264 fprintf( stderr, "r_fill_resampled_data_brick: failure to "
00265 "compute dataset slice %d\n", slice );
00266 free( newdata );
00267 return FAIL;
00268 }
00269
00270 memcpy( (void *)dptr, mri_data_pointer(im), nxy*dsize );
00271 mri_free( im );
00272 dptr += nxy*dsize;
00273 }
00274
00275 DBLK_BRICK_FACTOR(dset->dblk,ival) = bfac;
00276 /* we now have the raw brick data, so insert it into the brick */
00277 EDIT_substitute_brick(dset, ival, DSET_BRICK_TYPE(dset,ival),
00278 (void *)newdata);
00279 }
00280
00281 dset->dblk->malloc_type = DATABLOCK_MEM_MALLOC;
00282 dset->wod_flag = False; /* since data is now in memory */
00283
00284 /* recompute statistics */
00285 THD_load_statistics( dset );
00286
00287 return 0; /* OK */
00288 }
|
|
|
Definition at line 389 of file r_new_resam_dset.c. Referenced by valid_resam_inputs().
00390 {
00391 int o1, o2, o3;
00392
00393 if ( ostr == NULL )
00394 return False;
00395
00396 o1 = ORCODE(toupper(ostr[0]));
00397 o2 = ORCODE(toupper(ostr[1]));
00398 o3 = ORCODE(toupper(ostr[2]));
00399
00400 if ( ( o1 != ILLEGAL_TYPE ) &&
00401 ( o2 != ILLEGAL_TYPE ) &&
00402 ( o3 != ILLEGAL_TYPE ) &&
00403 OR3OK(o1,o2,o3) )
00404 return True;
00405 else
00406 return False;
00407 }
|
|
||||||||||||||||||||||||||||||||||||
|
Definition at line 74 of file r_new_resam_dset.c. References ADN_none, ADN_prefix, apply_dataxes(), apply_orientation(), DATAXES_TYPE, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, THD_datablock::diskptr, DSET_delete, EDIT_dset_items(), EDIT_empty_copy(), THD_3dim_dataset::idcode, ISVALID_3DIM_DATASET, LR_RESAM_IN_FAIL, LR_RESAM_IN_REORIENT, LR_RESAM_IN_RESAM, THD_dataxes::parent, r_dxyz_mod_dataxes(), r_fill_resampled_data_brick(), THD_copy_dset_subs(), THD_delete_3dim_dataset(), THD_init_diskptr_names(), THD_oriented_brick(), this_file, THD_warp::type, THD_dataxes::type, valid_resam_inputs(), THD_3dim_dataset::view_type, THD_3dim_dataset::vox_warp, THD_3dim_dataset::warp_parent, THD_3dim_dataset::warp_parent_idcode, THD_3dim_dataset::wod_daxes, and THD_3dim_dataset::wod_flag. Referenced by main(), RCREND_reload_dataset(), and RCREND_reload_func_dset().
00084 {
00085 THD_3dim_dataset * dout;
00086 THD_3dim_dataset * dtmp;
00087 THD_dataxes new_daxes;
00088 FD_brick * fdb = NULL;
00089 int work;
00090 char * l_orient, l_orient_s[4] = "";
00091
00092 /* if we have a master, do not rely on orient - use local memory */
00093 if ( min ) l_orient = l_orient_s;
00094 else l_orient = orient;
00095
00096 work = valid_resam_inputs( din, min, dx, dy, dz, l_orient, resam );
00097
00098 if ( work == LR_RESAM_IN_FAIL )
00099 return NULL;
00100
00101 if ( sublist )
00102 dtmp = THD_copy_dset_subs(din, sublist);
00103 else
00104 dtmp = din;
00105
00106 dout = EDIT_empty_copy( dtmp ); /* create new brick */
00107 if( ! ISVALID_3DIM_DATASET( dout ) )
00108 {
00109 fprintf( stderr, "ERROR: <%s> - failed to duplicate datset at %p\n",
00110 this_file, din );
00111 return NULL;
00112 }
00113
00114 /* give junk name */
00115 EDIT_dset_items(dout, ADN_prefix, "junk_resample", ADN_none );
00116
00117 /* possibly update view type to that of the master */
00118 if ( min &&
00119 (dout->view_type != min->view_type) &&
00120 (dout->dblk && dout->dblk->diskptr) )
00121 {
00122 dout->view_type = min->view_type;
00123 THD_init_diskptr_names( dout->dblk->diskptr, NULL, NULL, NULL,
00124 min->view_type, True );
00125 }
00126
00127
00128 /* re-orient the brick? */
00129 if ( work & LR_RESAM_IN_REORIENT )
00130 {
00131 if ( ( fdb = THD_oriented_brick( dout, l_orient ) ) == NULL )
00132 {
00133 fprintf( stderr, "<%s>: failed to create THD_brick with orient "
00134 "string <%.6s>\n", this_file, l_orient );
00135 THD_delete_3dim_dataset( dout, FALSE );
00136 return NULL;
00137 }
00138
00139 if ( apply_orientation( dout, fdb, l_orient ) != 0 )
00140 {
00141 THD_delete_3dim_dataset( dout, FALSE );
00142 return NULL;
00143 }
00144 }
00145
00146 new_daxes = *dout->daxes; /* in case we don't resample */
00147
00148 /* resample the brick? */
00149 if ( work & LR_RESAM_IN_RESAM )
00150 {
00151 /*-- given dx, dy and dz, create a new THD_dataxes structure ---- */
00152 new_daxes.type = DATAXES_TYPE;
00153
00154 /* fill new_daxes, from the master, new dxyz, or both */
00155 if ( min && dx == 0.0 ) new_daxes = *min->daxes;
00156 else
00157 {
00158 /* possibly start with master (must have master's orient) */
00159 if ( min ) *dout->daxes = *min->daxes;
00160
00161 if ( r_dxyz_mod_dataxes(dx, dy, dz, dout->daxes, &new_daxes) != 0 )
00162 {
00163 THD_delete_3dim_dataset( dout, FALSE );
00164 return NULL;
00165 }
00166 }
00167
00168 if ( apply_dataxes( dout, &new_daxes ) != 0 )
00169 {
00170 THD_delete_3dim_dataset( dout, FALSE );
00171 return NULL;
00172 }
00173 }
00174
00175 /* needed by THD_load_datablock() */
00176 dout->warp_parent = dtmp;
00177 dout->warp_parent_idcode = dtmp->idcode; /* needed for HEAD write */
00178
00179 /* needed to warp from parent */
00180 dout->wod_flag = True; /* mark for WOD */
00181 dout->vox_warp->type = ILLEGAL_TYPE; /* mark fo recomputation */
00182 *dout->wod_daxes = new_daxes; /* used for actual warp */
00183
00184 dout->daxes->parent = (XtPointer)dout; /* parent is new dset */
00185
00186 if ( r_fill_resampled_data_brick( dout, resam ) != 0 )
00187 {
00188 THD_delete_3dim_dataset( dout, FALSE );
00189 dout = NULL;
00190 }
00191
00192 if ( sublist ) DSET_delete(dtmp);
00193
00194 return dout;
00195 }
|
|
||||||||||||
|
Definition at line 416 of file r_new_resam_dset.c. References THD_ivec3::ijk, OR3OK, ORCODE, and this_file. Referenced by apply_orientation().
00417 {
00418 int o1, o2, o3;
00419
00420 if ( !ostr || !ovec )
00421 {
00422 fprintf( stderr, "%s: r_orient_str2vec - invalid parameter pair "
00423 "(%p,%p)\n", this_file, ostr, ovec );
00424 return -1;
00425 }
00426
00427 ovec->ijk[0] = o1 = ORCODE(toupper(ostr[0]));
00428 ovec->ijk[1] = o2 = ORCODE(toupper(ostr[1]));
00429 ovec->ijk[2] = o3 = ORCODE(toupper(ostr[2]));
00430
00431 if ( ( o1 == ILLEGAL_TYPE ) ||
00432 ( o2 == ILLEGAL_TYPE ) ||
00433 ( o3 == ILLEGAL_TYPE ) ||
00434 ( !OR3OK(o1,o2,o3) ) )
00435 {
00436 fprintf( stderr, "%s: r_orient_str2vec - bad ostr <%.4s>\n",
00437 this_file, ostr );
00438 return -2;
00439 }
00440
00441 return 0;
00442 }
|