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_fdto2D.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 #include "thd.h"
00009 
00010 /*---------------------------------------------------------------
00011   Routine to extract a slice (fixed value of 3rd dimension) from
00012     a previously set up FD_brick structure.
00013   November 1995: may return an image of any legal type, not
00014                  just shorts.
00015 -----------------------------------------------------------------*/
00016 
00017 MRI_IMAGE * FD_brick_to_mri( int kslice , int ival , FD_brick * br )
00018 {
00019    MRI_IMAGE * im ;  /* output */
00020    register int ii,di,ei , jj,dj,ej , base , pp ;
00021    char * iar ;      /* brick in the input */
00022    MRI_TYPE typ ;
00023 
00024    /** desire a fake image **/
00025 
00026    if( ival < 0 ){
00027       im     = mri_new( br->n1 , br->n2 , MRI_short ) ;
00028       im->dx = br->del1 ;
00029       im->dy = br->del2 ;
00030       im->dz = br->del3 ;
00031       return im ;
00032    }
00033 
00034    /** otherwise, get ready for a real image **/
00035 
00036    if( ival >= br->dset->dblk->nvals ) return NULL ;
00037 
00038    iar = DSET_ARRAY(br->dset,ival) ;
00039 
00040    if( iar == NULL ){  /* if data needs to be loaded from disk */
00041       (void) THD_load_datablock( br->dset->dblk ) ;
00042       iar = DSET_ARRAY(br->dset,ival) ;
00043       if( iar == NULL ) return NULL ;
00044    }
00045 
00046    typ    = DSET_BRICK_TYPE(br->dset,ival) ;
00047    im     = mri_new( br->n1 , br->n2 , typ ) ;
00048    im->dx = br->del1 ;
00049    im->dy = br->del2 ;
00050    im->dz = br->del3 ;
00051 
00052    switch( typ ){
00053 
00054       default:             /* don't know what to do --> return nada */
00055          mri_free( im ) ;
00056          return NULL ;
00057 
00058       case MRI_byte:{
00059          register byte * ar  = MRI_BYTE_PTR(im) ;
00060          register byte * bar = (byte *) iar ;
00061 
00062          di = br->d1 ; dj = br->d2 ;  /* strides */
00063          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00064          base = br->start + kslice * br->d3 ;
00065 
00066          pp = 0 ;
00067          for( jj=0 ; jj != ej ; jj += dj )
00068             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00069       }
00070       break ;
00071 
00072       case MRI_short:{
00073          register short * ar  = MRI_SHORT_PTR(im) ;
00074          register short * bar = (short *) iar ;
00075 
00076          di = br->d1 ; dj = br->d2 ;  /* strides */
00077          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00078          base = br->start + kslice * br->d3 ;
00079 
00080          pp = 0 ;
00081          for( jj=0 ; jj != ej ; jj += dj )
00082             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00083       }
00084       break ;
00085 
00086       case MRI_float:{
00087          register float * ar  = MRI_FLOAT_PTR(im) ;
00088          register float * bar = (float *) iar ;
00089 
00090          di = br->d1 ; dj = br->d2 ;  /* strides */
00091          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00092          base = br->start + kslice * br->d3 ;
00093 
00094          pp = 0 ;
00095          for( jj=0 ; jj != ej ; jj += dj )
00096             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00097       }
00098       break ;
00099 
00100       case MRI_int:{
00101          register int * ar  = MRI_INT_PTR(im) ;
00102          register int * bar = (int *) iar ;
00103 
00104          di = br->d1 ; dj = br->d2 ;  /* strides */
00105          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00106          base = br->start + kslice * br->d3 ;
00107 
00108          pp = 0 ;
00109          for( jj=0 ; jj != ej ; jj += dj )
00110             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00111       }
00112       break ;
00113 
00114       case MRI_double:{
00115          register double * ar  = MRI_DOUBLE_PTR(im) ;
00116          register double * bar = (double *) iar ;
00117 
00118          di = br->d1 ; dj = br->d2 ;  /* strides */
00119          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00120          base = br->start + kslice * br->d3 ;
00121 
00122          pp = 0 ;
00123          for( jj=0 ; jj != ej ; jj += dj )
00124             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00125       }
00126       break ;
00127 
00128       case MRI_complex:{
00129          register complex * ar  = MRI_COMPLEX_PTR(im) ;
00130          register complex * bar = (complex *) iar ;
00131 
00132          di = br->d1 ; dj = br->d2 ;  /* strides */
00133          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00134          base = br->start + kslice * br->d3 ;
00135 
00136          pp = 0 ;
00137          for( jj=0 ; jj != ej ; jj += dj )
00138             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00139       }
00140       break ;
00141 
00142       case MRI_rgb:{                                           /* 15 Apr 2002 */
00143          register rgbyte * ar  = (rgbyte *) MRI_RGB_PTR(im) ;
00144          register rgbyte * bar = (rgbyte *) iar ;
00145 
00146          di = br->d1 ; dj = br->d2 ;  /* strides */
00147          ei = br->e1 ; ej = br->e2 ;  /* final indices */
00148          base = br->start + kslice * br->d3 ;
00149 
00150          pp = 0 ;
00151          for( jj=0 ; jj != ej ; jj += dj )
00152             for( ii=0 ; ii != ei ; ii += di ) ar[pp++] = bar[ii+(jj+base)] ;
00153       }
00154       break ;
00155 
00156    }
00157 
00158    if( DSET_BRICK_FACTOR(br->dset,ival) != 0.0 ){
00159       MRI_IMAGE * qim ;
00160 STATUS(" scaling to float");
00161       qim = mri_scale_to_float( DSET_BRICK_FACTOR(br->dset,ival) , im ) ;
00162       mri_free(im) ; im = qim ;
00163    }
00164 
00165    return im ;
00166 }
 

Powered by Plone

This site conforms to the following standards: