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  

thd_dsetto1D.c File Reference

#include "mrilib.h"
#include "thd.h"

Go to the source code of this file.


Functions

MRI_IMAGETHD_extract_series (int ind, THD_3dim_dataset *dset, int raw)
int THD_extract_array (int ind, THD_3dim_dataset *dset, int raw, void *uar)
MRI_IMARRTHD_extract_many_series (int ns, int *ind, THD_3dim_dataset *dset)

Function Documentation

int THD_extract_array int    ind,
THD_3dim_dataset   dset,
int    raw,
void *    uar
 

Definition at line 71 of file thd_dsetto1D.c.

References AFREALL, CABS, THD_3dim_dataset::dblk, DSET_ARRAY, DSET_BRICK_FACTOR, DSET_BRICK_TYPE, DSET_load, DSET_NVOX, ENTRY, far, ind, ISVALID_DSET, mri_datum_size(), THD_datablock::nvals, RETURN, THD_need_brick_factor(), and typ.

Referenced by do_xrestore_stuff(), THD_average_timeseries(), THD_extract_series(), THD_mean_brick(), THD_median_brick(), THD_outlier_count(), and THD_rms_brick().

00072 {
00073    MRI_TYPE typ ;
00074    int nv , ival , nb ;
00075    char  *iar ;      /* brick in the input */
00076    float *far=NULL ; /* non-raw output */
00077    static void *tar=NULL ; static int ntar=0 ;
00078 
00079 ENTRY("THD_extract_array") ;
00080 
00081    if( ind < 0             || uar == NULL           ||
00082        !ISVALID_DSET(dset) || ind >= DSET_NVOX(dset)  ) RETURN(-1) ;
00083 
00084    nv  = dset->dblk->nvals ;
00085    iar = DSET_ARRAY(dset,0) ;
00086    if( iar == NULL ){         /* load data from disk? */
00087      DSET_load(dset) ;
00088      iar = DSET_ARRAY(dset,0); if( iar == NULL ) RETURN(-1) ;
00089    }
00090    typ = DSET_BRICK_TYPE(dset,0) ;  /* raw data type */
00091 
00092    /* will extract nb bytes of raw data into array tar */
00093 
00094    nb = mri_datum_size(typ) * (nv+1) ;
00095    if( nb > ntar ){ tar = AFREALL(tar,void *,nb) ; ntar = nb ; }
00096    memset(tar,0,nb) ;
00097 
00098    if( !raw ) far = (float *) uar ;  /* non-raw output */
00099 
00100    switch( typ ){
00101 
00102       default:           /* don't know what to do --> return nada */
00103          RETURN(-1);
00104       break ;
00105 
00106       case MRI_byte:{
00107          byte *ar = (byte *)tar , *bar ;
00108          for( ival=0 ; ival < nv ; ival++ ){
00109             bar = (byte *) DSET_ARRAY(dset,ival) ;
00110             if( bar != NULL ) ar[ival] = bar[ind] ;
00111          }
00112          if( !raw ){
00113             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00114          }
00115       }
00116       break ;
00117 
00118       case MRI_short:{
00119          short *ar = (short *)tar , *bar ;
00120          for( ival=0 ; ival < nv ; ival++ ){
00121             bar = (short *) DSET_ARRAY(dset,ival) ;
00122             if( bar != NULL ) ar[ival] = bar[ind] ;
00123          }
00124          if( !raw ){
00125             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00126          }
00127       }
00128       break ;
00129 
00130       case MRI_float:{
00131          float *ar = (float *)tar , *bar ;
00132          for( ival=0 ; ival < nv ; ival++ ){
00133             bar = (float *) DSET_ARRAY(dset,ival) ;
00134             if( bar != NULL ) ar[ival] = bar[ind] ;
00135          }
00136          if( !raw ){
00137             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00138          }
00139       }
00140       break ;
00141 
00142       case MRI_int:{
00143          int *ar = (int *)tar , *bar ;
00144          for( ival=0 ; ival < nv ; ival++ ){
00145             bar = (int *) DSET_ARRAY(dset,ival) ;
00146             if( bar != NULL ) ar[ival] = bar[ind] ;
00147          }
00148          if( !raw ){
00149             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00150          }
00151       }
00152       break ;
00153 
00154       case MRI_double:{
00155          double *ar = (double *)tar , *bar ;
00156          for( ival=0 ; ival < nv ; ival++ ){
00157             bar = (double *) DSET_ARRAY(dset,ival) ;
00158             if( bar != NULL ) ar[ival] = bar[ind] ;
00159          }
00160          if( !raw ){
00161             for( ival=0 ; ival < nv ; ival++ ) far[ival] = ar[ival] ;
00162          }
00163       }
00164       break ;
00165 
00166       case MRI_complex:{
00167          complex *ar = (complex *)tar , *bar ;
00168          for( ival=0 ; ival < nv ; ival++ ){
00169             bar = (complex *) DSET_ARRAY(dset,ival) ;
00170             if( bar != NULL ) ar[ival] = bar[ind] ;
00171          }
00172          if( !raw ){
00173             for( ival=0 ; ival < nv ; ival++ ) far[ival] = CABS(ar[ival]) ;
00174          }
00175       }
00176       break ;
00177 
00178    }
00179 
00180    if( raw ){ memcpy(uar,tar,nb); RETURN(0); }
00181 
00182    if( THD_need_brick_factor(dset) ){
00183       for( ival=0 ; ival < nv ; ival++ )
00184          if( DSET_BRICK_FACTOR(dset,ival) > 0.0 )
00185            far[ival] *= DSET_BRICK_FACTOR(dset,ival) ;
00186    }
00187 
00188    RETURN(0);
00189 }

MRI_IMARR* THD_extract_many_series int    ns,
int *    ind,
THD_3dim_dataset   dset
 

Definition at line 196 of file thd_dsetto1D.c.

References ADDTO_IMARR, THD_datablock::brick_fac, THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, DESTROY_IMARR, DSET_ARRAY, DSET_BRICK_TYPE, MRI_IMAGE::dx, ENTRY, far, free, IMARR_SUBIMAGE, ind, INIT_IMARR, malloc, MRI_FLOAT_PTR, mri_free(), mri_mult_to_float(), mri_new(), mri_to_float(), THD_datablock::nvals, THD_dataxes::nxx, THD_dataxes::nyy, RETURN, THD_3dim_dataset::taxis, THD_load_datablock(), THD_need_brick_factor(), THD_timeof(), tt, THD_timeaxis::ttdel, UNITS_MSEC_TYPE, THD_timeaxis::units_type, MRI_IMAGE::xo, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by AFNI_fimmer_compute(), calculate_results(), and do_xrestore_stuff().

00197 {
00198    MRI_IMARR *imar ; /* output */
00199    MRI_IMAGE *im ;
00200    int nv , ival , kk ;
00201    char *iar ;      /* brick in the input */
00202    float **far ;    /* 27 Feb 2003: ptrs to output */
00203 
00204 ENTRY("THD_extract_many_series") ;
00205 
00206    if( ns <= 0 || ind == NULL | dset == NULL ) RETURN( NULL );
00207 
00208    /* try to load dataset */
00209 
00210    nv  = dset->dblk->nvals ;
00211    iar = DSET_ARRAY(dset,0) ;
00212    if( iar == NULL ){  /* if data needs to be loaded from disk */
00213      (void) THD_load_datablock( dset->dblk ) ;
00214      iar = DSET_ARRAY(dset,0) ;
00215      if( iar == NULL ) RETURN( NULL );
00216    }
00217 
00218    /* create output */
00219 
00220    far = (float **) malloc(sizeof(float *)*ns) ;  /* 27 Feb 2003 */
00221    INIT_IMARR(imar) ;
00222    for( kk=0 ; kk < ns ; kk++ ){
00223      im = mri_new( nv , 1 , MRI_float ) ;  /* N.B.: now does 0 fill */
00224      far[kk] = MRI_FLOAT_PTR(im) ;         /* ptr to kk-th output series */
00225      ADDTO_IMARR(imar,im) ;
00226    }
00227 
00228    /* fill the output */
00229 
00230    switch( DSET_BRICK_TYPE(dset,0) ){
00231 
00232       default:             /* don't know what to do --> return nada */
00233         DESTROY_IMARR(imar) ; free(far) ;
00234         RETURN( NULL );
00235 
00236       case MRI_byte:{
00237         byte * bar ;
00238         for( ival=0 ; ival < nv ; ival++ ){
00239           bar = (byte *) DSET_ARRAY(dset,ival) ;
00240           if( bar != NULL ){
00241             for( kk=0 ; kk < ns ; kk++ ){
00242               far[kk][ival] = (float)bar[ind[kk]] ;
00243             }
00244           }
00245         }
00246       }
00247       break ;
00248 
00249       case MRI_short:{
00250         short * bar ;
00251         for( ival=0 ; ival < nv ; ival++ ){
00252           bar = (short *) DSET_ARRAY(dset,ival) ;
00253           if( bar != NULL ){
00254             for( kk=0 ; kk < ns ; kk++ ){
00255               far[kk][ival] = (float)bar[ind[kk]] ;
00256             }
00257           }
00258         }
00259       }
00260       break ;
00261 
00262       case MRI_float:{
00263          float * bar ;
00264          for( ival=0 ; ival < nv ; ival++ ){
00265             bar = (float *) DSET_ARRAY(dset,ival) ;
00266             if( bar != NULL ){
00267               for( kk=0 ; kk < ns ; kk++ ){
00268                  far[kk][ival] = bar[ind[kk]] ;
00269               }
00270             }
00271          }
00272       }
00273       break ;
00274 
00275       case MRI_int:{
00276          int * bar ;
00277          for( ival=0 ; ival < nv ; ival++ ){
00278             bar = (int *) DSET_ARRAY(dset,ival) ;
00279             if( bar != NULL ){
00280               for( kk=0 ; kk < ns ; kk++ ){
00281                  far[kk][ival] = bar[ind[kk]] ;
00282               }
00283             }
00284          }
00285       }
00286       break ;
00287 
00288       case MRI_double:{
00289          double * bar ;
00290          for( ival=0 ; ival < nv ; ival++ ){
00291             bar = (double *) DSET_ARRAY(dset,ival) ;
00292             if( bar != NULL ){
00293               for( kk=0 ; kk < ns ; kk++ ){
00294                  far[kk][ival] = (float)bar[ind[kk]] ;
00295               }
00296             }
00297          }
00298       }
00299       break ;
00300 
00301       case MRI_complex:{
00302          complex * bar ;
00303          for( ival=0 ; ival < nv ; ival++ ){
00304             bar = (complex *) DSET_ARRAY(dset,ival) ;
00305             if( bar != NULL ){
00306               for( kk=0 ; kk < ns ; kk++ ){
00307                  far[kk][ival] = bar[ind[kk]].r ;
00308               }
00309             }
00310          }
00311       }
00312       break ;
00313 
00314    }
00315 
00316    /* scale outputs, if needed */
00317 
00318    if( THD_need_brick_factor(dset) ){
00319       MRI_IMAGE * qim ;
00320       for( kk=0 ; kk < ns ; kk++ ){
00321          im  = IMARR_SUBIMAGE(imar,kk) ;
00322          qim = mri_mult_to_float( dset->dblk->brick_fac , im ) ;
00323          mri_free(im) ;
00324          IMARR_SUBIMAGE(imar,kk) = qim ;
00325       }
00326    }
00327 
00328 #if 0  /* 27 Feb 2003 */
00329    /* convert to floats, if needed */
00330 
00331    if( IMARR_SUBIMAGE(imar,0)->kind != MRI_float ){
00332       MRI_IMAGE * qim ;
00333       for( kk=0 ; kk < ns ; kk++ ){
00334          im  = IMARR_SUBIMAGE(imar,kk) ;
00335          qim = mri_to_float( im ) ;
00336          mri_free(im) ;
00337          IMARR_SUBIMAGE(imar,kk) = qim ;
00338       }
00339    }
00340 #endif
00341 
00342    /* add time axis stuff to output images, if present */
00343 
00344    if( dset->taxis != NULL ){
00345       float zz , tt ;
00346       int kz ;
00347 
00348       for( kk=0 ; kk < ns ; kk++ ){
00349          kz = ind[kk] / ( dset->daxes->nxx * dset->daxes->nyy ) ;
00350          zz = dset->daxes->zzorg + kz * dset->daxes->zzdel ;
00351          tt = THD_timeof( 0 , zz , dset->taxis ) ;
00352          im = IMARR_SUBIMAGE(imar,kk) ;
00353          im->xo = tt ; im->dx = dset->taxis->ttdel ;   /* origin and delta */
00354          if( dset->taxis->units_type == UNITS_MSEC_TYPE ){ /* convert to sec */
00355             im->xo *= 0.001 ; im->dx *= 0.001 ;
00356          }
00357       }
00358    } else {
00359       for( kk=0 ; kk < ns ; kk++ ){
00360          im = IMARR_SUBIMAGE(imar,kk) ;
00361          im->xo = 0.0 ; im->dx = 1.0 ;
00362       }
00363    }
00364 
00365    free(far) ; RETURN(imar);
00366 }

MRI_IMAGE* THD_extract_series int    ind,
THD_3dim_dataset   dset,
int    raw
 

Definition at line 23 of file thd_dsetto1D.c.

References THD_3dim_dataset::daxes, THD_3dim_dataset::dblk, DSET_BRICK_TYPE, MRI_IMAGE::dx, ENTRY, ind, ISVALID_DSET, mri_data_pointer(), mri_free(), mri_new(), THD_datablock::nvals, THD_dataxes::nxx, THD_dataxes::nyy, RETURN, THD_3dim_dataset::taxis, THD_extract_array(), THD_timeof(), tt, THD_timeaxis::ttdel, typ, UNITS_MSEC_TYPE, THD_timeaxis::units_type, MRI_IMAGE::xo, THD_dataxes::zzdel, and THD_dataxes::zzorg.

Referenced by DSET2_func(), DSETN_func(), extract_ts_array(), init_floatvector_array(), main(), read_ts_array(), segment_imarr(), and THD_dataset_tshift().

00024 {
00025    int nv , typ , ii ;
00026    MRI_IMAGE *im ;
00027    void *imar ;
00028 
00029 ENTRY("THD_extract_series") ;
00030 
00031    if( !ISVALID_DSET(dset) ) RETURN(NULL) ;
00032 
00033    nv  = dset->dblk->nvals ;
00034    if( raw ) typ = DSET_BRICK_TYPE(dset,0) ;  /* type of output array */
00035    else      typ = MRI_float ;
00036 
00037    im   = mri_new( nv , 1 , typ ) ;           /* output image */
00038    imar = mri_data_pointer(im) ;
00039 
00040    ii = THD_extract_array( ind , dset , raw , imar ) ; /* get data */
00041 
00042    if( ii != 0 ){ mri_free(im) ; RETURN(NULL) ; }      /* bad */
00043 
00044    if( dset->taxis != NULL ){  /* 21 Oct 1996 */
00045       float zz , tt ;
00046       int kz = ind / ( dset->daxes->nxx * dset->daxes->nyy ) ;
00047 
00048       zz = dset->daxes->zzorg + kz * dset->daxes->zzdel ;
00049       tt = THD_timeof( 0 , zz , dset->taxis ) ;
00050 
00051       im->xo = tt ; im->dx = dset->taxis->ttdel ;   /* origin and delta */
00052 
00053       if( dset->taxis->units_type == UNITS_MSEC_TYPE ){ /* convert to sec */
00054          im->xo *= 0.001 ; im->dx *= 0.001 ;
00055       }
00056    } else {
00057       im->xo = 0.0 ; im->dx = 1.0 ;  /* 08 Nov 1996 */
00058    }
00059 
00060    RETURN(im) ;
00061 }
 

Powered by Plone

This site conforms to the following standards: