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  

mri_image.h

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 #ifndef _MCW_MRIIMAGE_HEADER_
00008 #define _MCW_MRIIMAGE_HEADER_
00009 
00010 /**** define types ****/
00011 
00012 /*! The MRI_byte data type. */
00013 
00014 #ifndef TYPEDEF_byte
00015 #define TYPEDEF_byte
00016 typedef unsigned char byte ;
00017 #endif
00018 
00019 /*! RGBA data type; not used anywhere (yet). */
00020 
00021 #ifndef TYPEDEF_rgba
00022 #define TYPEDEF_rgba
00023 typedef struct { byte r,g,b,a ; } rgba ;  /* 24 Aug 2001 */
00024 #endif
00025 
00026 #define LOAD_rgba(s,rr,gg,bb,aa)   ((s).r=(rr),(s).g=(gg),(s).b=(bb),(s).a=(bb))
00027 #define UNLOAD_rgba(s,rr,gg,bb,aa) ((rr)=(s).r,(gg)=(s).g,(bb)=(s).b,(aa)=(s).a)
00028 
00029 /*! Integer flags for different image types.  Sometimes called the "datum". */
00030 
00031 typedef enum MRI_TYPE {
00032          MRI_byte , MRI_short  , MRI_int  ,
00033         MRI_float , MRI_double , MRI_complex , MRI_rgb , MRI_rgba } MRI_TYPE ;
00034 
00035 #define MRI_KIND MRI_TYPE ;   /* to alleviate stupidity */
00036 #define MRI_type MRI_TYPE ;
00037 #define MRI_kind MRI_TYPE ;
00038 
00039 #define MRI_rgbyte MRI_rgb
00040 
00041 /*! The last MRI_TYPE yet defined. */
00042 
00043 #define LAST_MRI_TYPE 7
00044 
00045 /*! Max value of a byte. */
00046 
00047 #define MRI_maxbyte         255
00048 
00049 /*! Max value of a short. */
00050 
00051 #define MRI_maxshort      32767
00052 
00053 /*! Max value of an int. */
00054 
00055 #define MRI_maxint   2147483647
00056 
00057 /*! Determine if a MRI_TYPE is an integer type. */
00058 
00059 #define MRI_IS_INT_TYPE(typ) ((typ) < 3)
00060 
00061 /*! I suppose that the next C makes this pleonastic. */
00062 
00063 #ifdef _SUNPERF_COMPLEX
00064 # define TYPEDEF_complex
00065 #endif
00066 
00067 #ifndef TYPEDEF_complex
00068 #define TYPEDEF_complex
00069 typedef struct complex { float r , i ; } complex ;
00070 #endif
00071 
00072 /*-------*/
00073 
00074 /*! Triple to hold RGB bytes. */
00075 
00076 #ifndef TYPEDEF_rgbyte
00077 #define TYPEDEF_rgbyte
00078 typedef struct rgbyte { byte r,g,b ; } rgbyte ;  /* 15 Feb 1999 */
00079 #endif
00080 
00081 /*-------*/
00082 
00083 /*! A union type to hold all possible MRI_IMAGE types.
00084     This was created before I really understood how to use void *. */
00085 
00086 typedef union MRI_DATA {
00087          byte     *byte_data ;
00088          short    *short_data ;
00089          int      *int_data ;
00090          float    *float_data ;
00091          double   *double_data ;
00092          complex  *complex_data ;
00093          byte     *rgb_data ;      /* Apr 1996: not well supported yet */
00094          rgba     *rgba_data ;     /* Mar 2002 */
00095 } MRI_DATA ;
00096 
00097 /** Mar 1996: Extended to images up to 7D;
00098               Not all routines work with images > 2D --
00099               check top of file for "7D SAFE" comments **/
00100 
00101 #undef USE_MRI_LABELS
00102 #ifdef USE_MRI_LABELS
00103 #  define MRI_LABEL_SIZE 4
00104 #endif
00105 
00106 #define USE_MRI_DELAY   /* 01 Jan 1997 */
00107 #ifdef USE_MRI_DELAY
00108 #  define INPUT_DELAY  1
00109 #  define BSWAP_DELAY  2
00110 #endif
00111 
00112 /*! Stores one image (1D to 7D).
00113     Why 7D, you ask?  Well, I originally only had 2D images here.
00114     When extending AFNI from 3D to 3D+time and buckets, I thought
00115     that I might use 4D images (x,y,z,t) as the basic element.
00116     Instead, I decided to use an array of 3D images (in a THD_datablock),
00117     but by then I'd extended this typedef to allow (x,y,z,t,u,v,w) dimensioned
00118     arrays.  I don't think anyplace ever uses more than 3D images, though.
00119 */
00120 
00121 typedef struct MRI_IMAGE {
00122           int nx ;            /*!< 1st dimension of image */
00123           int ny ;            /*!< 2nd dimension of image (1 for 1D image) */
00124           int nz  ;           /*!< 3rd dimension of image (1 for 2D image) */
00125           int nt ;            /*!< 4th dimension of image (1 for 3D image) */
00126           int nu ;            /*!< 5th dimension of image (1 for 4D image) */
00127           int nv ;            /*!< 6th dimension of image (1 for 5D image) */
00128           int nw  ;           /*!< 7th dimension of image (1 for 6D image) */
00129           int nxy ;           /*!< nx*ny */
00130           int nxyz ;          /*!< nx*ny*nz */
00131           int nxyzt  ;        /*!< nx*ny*nz*nt */
00132           int nvox   ;        /*!< number of voxels total */
00133           int pixel_size ;    /*!< bytes per pixel */
00134 
00135           MRI_TYPE kind ;     /*!< one of the MRI_TYPE codes above */
00136           MRI_DATA im ;       /*!< pointer to actual pixel data */
00137           char *name ;        /*!< string attached; may be NULL; might be filename */
00138 
00139           float dx ;          /*!< physical pixel size, if != 0 */
00140           float dy ;          /*!< physical pixel size, if != 0 */
00141           float dz ;          /*!< physical pixel size, if != 0 */
00142           float dt ;          /*!< physical pixel size, if != 0 */
00143           float du ;          /*!< physical pixel size, if != 0 */
00144           float dv ;          /*!< physical pixel size, if != 0 */
00145           float dw ;          /*!< physical pixel size, if != 0 */
00146           float xo ;          /*!< spatial origin of axis */
00147           float yo ;          /*!< spatial origin of axis */
00148           float zo ;          /*!< spatial origin of axis */
00149           float to ;          /*!< spatial origin of axis */
00150           float uo ;          /*!< spatial origin of axis */
00151           float vo ;          /*!< spatial origin of axis */
00152           float wo ;          /*!< spatial origin of axis */
00153 
00154 #ifdef USE_MRI_LABELS
00155          char xlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00156               ylab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00157               zlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00158               tlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00159               ulab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00160               vlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00161               wlab[MRI_LABEL_SIZE] ;  /*!< labels for each dimension */
00162 #endif
00163 
00164 #ifdef USE_MRI_DELAY
00165          char *fname ;   /*!< to read actual image data after delay */
00166          int foffset ;   /*!< offset into fname of image data */
00167          int fondisk ;   /*!< flag to indicate if is on disk (?) */
00168 #endif
00169 
00170          int was_swapped ; /* 07 Mar 2002 */
00171 } MRI_IMAGE ;
00172 
00173 #ifdef USE_MRI_LABELS
00174 /*! Copy auxiliary data from one MRI_IMAGE to another. */
00175 #  define MRI_COPY_AUX(nn,oo)                                           \
00176     ( (nn)->dx = (oo)->dx , (nn)->dy = (oo)->dy , (nn)->dz = (oo)->dz , \
00177       (nn)->dt = (oo)->dt , (nn)->du = (oo)->du , (nn)->dv = (oo)->dv , \
00178       (nn)->dw = (oo)->dw ,                                             \
00179       (nn)->xo = (oo)->xo , (nn)->yo = (oo)->yo , (nn)->zo = (oo)->zo , \
00180       (nn)->to = (oo)->to , (nn)->uo = (oo)->uo , (nn)->vo = (oo)->vo , \
00181       (nn)->wo = (oo)->wo ,                                             \
00182       strcpy((nn)->xlab,(oo)->xlab) , strcpy((nn)->ylab,(oo)->ylab) ,   \
00183       strcpy((nn)->zlab,(oo)->zlab) , strcpy((nn)->tlab,(oo)->tlab) ,   \
00184       strcpy((nn)->ulab,(oo)->ulab) , strcpy((nn)->vlab,(oo)->vlab) ,   \
00185       strcpy((nn)->wlab,(oo)->wlab) ,                                   \
00186       mri_add_name( (oo)->name , (nn) ) )
00187 #else
00188 #  define MRI_COPY_AUX(nn,oo)                                           \
00189     ( (nn)->dx = (oo)->dx , (nn)->dy = (oo)->dy , (nn)->dz = (oo)->dz , \
00190       (nn)->dt = (oo)->dt , (nn)->du = (oo)->du , (nn)->dv = (oo)->dv , \
00191       (nn)->dw = (oo)->dw ,                                             \
00192       (nn)->xo = (oo)->xo , (nn)->yo = (oo)->yo , (nn)->zo = (oo)->zo , \
00193       (nn)->to = (oo)->to , (nn)->uo = (oo)->uo , (nn)->vo = (oo)->vo , \
00194       (nn)->wo = (oo)->wo ,                                             \
00195       mri_add_name( (oo)->name , (nn) ) )
00196 #endif
00197 
00198 /*! Check if MRI_IMAGE is 1D (ny=1) */
00199 #define MRI_IS_1D(iq)  ((iq)->ny == 1)
00200 
00201 /*! Check if MRI_IMAGE is 2D (nz=1) */
00202 #define MRI_IS_2D(iq)  ((iq)->ny > 1 && (iq)->nz == 1)
00203 
00204 /*! Check if MRI_IMAGE is 3D (nt=1) */
00205 #define MRI_IS_3D(iq)  ((iq)->nz > 1 && (iq)->nt == 1)
00206 
00207 /*! Check if MRI_IMAGE is 4D (nu=1) */
00208 #define MRI_IS_4D(iq)  ((iq)->nt > 1 && (iq)->nu == 1)
00209 
00210 /*! Return dimensionality of MRI_IMAGE */
00211 #define MRI_DIMENSIONALITY(iq)                     \
00212  ( ((iq)->ny == 1) ? 1 : ((iq)->nz == 1) ? 2 :     \
00213    ((iq)->nt == 1) ? 3 : ((iq)->nu == 1) ? 4 :     \
00214    ((iq)->nv == 1) ? 5 : ((iq)->nw == 1) ? 6 : 7 )
00215 
00216 #define MRI_BYTE_PTR(iq)    ((iq)->im.byte_data)
00217 #define MRI_SHORT_PTR(iq)   ((iq)->im.short_data)
00218 #define MRI_INT_PTR(iq)     ((iq)->im.int_data)
00219 #define MRI_FLOAT_PTR(iq)   ((iq)->im.float_data)
00220 #define MRI_DOUBLE_PTR(iq)  ((iq)->im.double_data)
00221 #define MRI_COMPLEX_PTR(iq) ((iq)->im.complex_data)
00222 #define MRI_RGB_PTR(iq)     ((iq)->im.rgb_data)
00223 #define MRI_RGBA_PTR(iq)    ((iq)->im.rgba_data)
00224 
00225 #define MRI_BYTE_2D(iq,ix,jy)    MRI_BYTE_PTR(iq)[(ix)+(jy)*(iq)->nx]
00226 #define MRI_SHORT_2D(iq,ix,jy)   MRI_SHORT_PTR(iq)[(ix)+(jy)*(iq)->nx]
00227 #define MRI_INT_2D(iq,ix,jy)     MRI_INT_PTR(iq)[(ix)+(jy)*(iq)->nx]
00228 #define MRI_FLOAT_2D(iq,ix,jy)   MRI_FLOAT_PTR(iq)[(ix)+(jy)*(iq)->nx]
00229 #define MRI_DOUBLE_2D(iq,ix,jy)  MRI_DOUBLE_PTR(iq)[(ix)+(jy)*(iq)->nx]
00230 #define MRI_COMPLEX_2D(iq,ix,jy) MRI_COMPLEX_PTR(iq)[(ix)+(jy)*(iq)->nx]
00231 
00232 #endif /* _MCW_MRIIMAGE_HEADER_ */
 

Powered by Plone

This site conforms to the following standards: