Skip to content

AFNI/NIfTI Server

Sections
Personal tools
You are here: Home » AFNI » Documentation

Doxygen Source Code Documentation


Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals   Search  

edt_substbrick.c

Go to the documentation of this file.
00001 /*****************************************************************************
00002    Major portions of this software are copyrighted by the Medical College
00003    of Wisconsin, 1994-2000, and are released under the Gnu General Public
00004    License, Version 2.  See the file README.Copyright for details.
00005 ******************************************************************************/
00006 
00007 #include "mrilib.h"
00008 
00009 /*---------------------------------------------------------------------------
00010    Routine to substitute one brick array for another in a 3D dataset.
00011      dset  = dataset to be edited
00012      ival  = index of sub-brick to be replaced
00013      ftype = datum type of substitute array
00014      fim   = array of substitute data -- it may be NULL.  If it is not NULL,
00015              then should contain mri_datum_size(ftype) * nxx*nyy*nzz bytes.
00016              If it is NULL, then space will be calloc-ed.
00017 
00018    Notes: 1) The original brick (an MRI_IMAGE within an MRI_IMARR) is deleted
00019              from memory.  A new brick is put in its place.
00020           2) This can only be done on a brick that is malloc-ed, not mmap-ed!
00021           3) The brick_bytes and total_bytes field of the datablock are
00022              patched, but the brick_fac field is not changed here.
00023 -----------------------------------------------------------------------------*/
00024 
00025 void EDIT_substitute_brick(THD_3dim_dataset * dset, int ival, int ftype,void * fim)
00026 {
00027    THD_datablock * dblk ;
00028    MRI_IMAGE * newim , * oldim ;
00029    int nbytes , nullfim = (fim == NULL) ;
00030 
00031 ENTRY("EDIT_substitute_brick") ;
00032 
00033    /**-- Sanity Checks --**/
00034 
00035    if( ! ISVALID_3DIM_DATASET(dset) )                   EXRETURN; /* error! */
00036    if( dset->dblk->brick == NULL )                      EXRETURN; /* ditto! */
00037    if( dset->dblk->malloc_type != DATABLOCK_MEM_MALLOC )EXRETURN; /* ditto! */
00038    if( ival >= dset->dblk->nvals || ival < 0 )          EXRETURN; /* ditto! */
00039    if( ftype < 0 || ftype > LAST_MRI_TYPE )             EXRETURN; /* ditto! */
00040 
00041    oldim = DSET_BRICK(dset,ival) ; if( oldim == NULL )  EXRETURN; /* ditto! */
00042 
00043    newim  = mri_empty_conforming( oldim , ftype ) ;      /* new sub-brick */
00044    nbytes = newim->nvox * newim->pixel_size ;            /* how big it is */
00045    mri_free( oldim ) ;                                   /* kill old one  */
00046 
00047    if( nullfim ){                                        /* if needed, */
00048       fim = calloc( 1,nbytes ) ;                         /* make array */
00049       if( fim == NULL ){
00050         fprintf(stderr,"\n*** malloc error for dataset sub-brick\n") ; EXIT(1) ;
00051       }
00052    }
00053    mri_fix_data_pointer( fim , newim ) ;                 /* attach new data */
00054    DSET_BRICK(dset,ival) = newim ;                       /* put in dataset  */
00055 
00056    /** change the byte count for this sub-brick and the total dataset **/
00057 
00058    dset->dblk->total_bytes      += (nbytes - dset->dblk->brick_bytes[ival]) ;
00059    dset->dblk->brick_bytes[ival] = nbytes ;
00060 
00061    DSET_CRUSH_BSTAT(dset,ival) ;
00062 
00063    EXRETURN ;
00064 }
 

Powered by Plone

This site conforms to the following standards: