1 /***************************************************************************** 2 Major portions of this software are copyrighted by the Medical College 3 of Wisconsin, 1994-2000, and are released under the Gnu General Public 4 License, Version 2. See the file README.Copyright for details. 5 ******************************************************************************/ 6 7 #ifndef _MCW_MRIIMAGE_HEADER_ 8 #define _MCW_MRIIMAGE_HEADER_ 9 10 /**** define types ****/ 11 12 /*! The MRI_byte data type. */ 13 14 #ifndef TYPEDEF_byte 15 #define TYPEDEF_byte 16 typedef unsigned char byte ; 17 #endif 18 19 /*! RGBA data type; not used anywhere (yet). */ 20 21 #ifndef TYPEDEF_rgba 22 #define TYPEDEF_rgba 23 typedef struct { byte r,g,b,a ; } rgba ; /* 24 Aug 2001 */ 24 #endif 25 26 #define LOAD_rgba(s,rr,gg,bb,aa) ((s).r=(rr),(s).g=(gg),(s).b=(bb),(s).a=(bb)) 27 #define UNLOAD_rgba(s,rr,gg,bb,aa) ((rr)=(s).r,(gg)=(s).g,(bb)=(s).b,(aa)=(s).a) 28 29 /*! Integer flags for different image types. Sometimes called the "datum". */ 30 31 typedef enum MRI_TYPE { 32 MRI_byte , MRI_short , MRI_int , 33 MRI_float , MRI_double , MRI_complex , MRI_rgb , MRI_rgba , 34 MRI_fvect 35 } MRI_TYPE ; 36 37 #define MRI_KIND MRI_TYPE ; /* to alleviate stupidity */ 38 #define MRI_type MRI_TYPE ; 39 #define MRI_kind MRI_TYPE ; 40 41 #define MRI_rgbyte MRI_rgb 42 43 /*! The last MRI_TYPE yet defined. */ 44 45 #define LAST_MRI_TYPE 7 46 47 /*! Max value of a byte. */ 48 49 #define MRI_maxbyte 255 50 51 /*! Max value of a short. */ 52 53 #define MRI_maxshort 32767 54 55 /*! Max value of an int. */ 56 57 #define MRI_maxint 2147483647 58 59 /*! Determine if a MRI_TYPE is an integer type. */ 60 61 #define MRI_IS_INT_TYPE(typ) ((typ) < 3) 62 63 /*! I suppose that the next C makes this pleonastic. */ 64 65 #ifdef _SUNPERF_COMPLEX 66 # define TYPEDEF_complex 67 #endif 68 69 #ifndef TYPEDEF_complex 70 #define TYPEDEF_complex 71 typedef struct complex { float r , i ; } complex ; 72 #endif 73 74 /*-------*/ 75 76 /*! Triple to hold RGB bytes. */ 77 78 #ifndef TYPEDEF_rgbyte 79 #define TYPEDEF_rgbyte 80 typedef struct rgbyte { byte r,g,b ; } rgbyte ; /* 15 Feb 1999 */ 81 #endif 82 83 /*-------*/ 84 85 /** Mar 1996: Extended to images up to 7D; 86 Not all routines work with images > 2D -- 87 check top of file for "7D SAFE" comments **/ 88 89 #undef USE_MRI_LABELS 90 #ifdef USE_MRI_LABELS 91 # define MRI_LABEL_SIZE 4 92 #endif 93 94 #define INPUT_DELAY 1 95 #define BSWAP_DELAY 2 96 #define IS_PURGED 4 97 98 /*! Stores one image (1D to 7D). 99 Why 7D, you ask? Well, I originally only had 2D images here. 100 When extending AFNI from 3D to 3D+time and buckets, I thought 101 that I might use 4D images (x,y,z,t) as the basic element. 102 Instead, I decided to use an array of 3D images (in a THD_datablock), 103 but by then I'd extended this typedef to allow (x,y,z,t,u,v,w) dimensioned 104 arrays. I don't think anyplace ever uses more than 3D images, though. 105 */ 106 107 typedef struct MRI_IMAGE { 108 int nx ; /*!< 1st dimension of image */ 109 int ny ; /*!< 2nd dimension of image (1 for 1D image) */ 110 int nz ; /*!< 3rd dimension of image (1 for 2D image) */ 111 int nt ; /*!< 4th dimension of image (1 for 3D image) */ 112 int nu ; /*!< 5th dimension of image (1 for 4D image) */ 113 int nv ; /*!< 6th dimension of image (1 for 5D image) */ 114 int nw ; /*!< 7th dimension of image (1 for 6D image) */ 115 int nxy ; /*!< nx*ny */ 116 int nxyz ; /*!< nx*ny*nz */ 117 int nxyzt ; /*!< nx*ny*nz*nt */ 118 int nvox ; /*!< number of voxels total */ 119 int pixel_size ; /*!< bytes per pixel */ 120 121 MRI_TYPE kind ; /*!< one of the MRI_TYPE codes above */ 122 void *im ; /*!< pointer to actual pixel data */ 123 char *name ; /*!< string attached; may be NULL; might be filename */ 124 125 float dx ; /*!< physical pixel size, if != 0 */ 126 float dy ; /*!< physical pixel size, if != 0 */ 127 float dz ; /*!< physical pixel size, if != 0 */ 128 float dt ; /*!< physical pixel size, if != 0 */ 129 float du ; /*!< physical pixel size, if != 0 */ 130 float dv ; /*!< physical pixel size, if != 0 */ 131 float dw ; /*!< physical pixel size, if != 0 */ 132 float xo ; /*!< spatial origin of axis */ 133 float yo ; /*!< spatial origin of axis */ 134 float zo ; /*!< spatial origin of axis */ 135 float to ; /*!< spatial origin of axis */ 136 float uo ; /*!< spatial origin of axis */ 137 float vo ; /*!< spatial origin of axis */ 138 float wo ; /*!< spatial origin of axis */ 139 140 #ifdef USE_MRI_LABELS 141 char xlab[MRI_LABEL_SIZE] ; /*!< labels for each dimension */ 142 ylab[MRI_LABEL_SIZE] ; /*!< labels for each dimension */ 143 zlab[MRI_LABEL_SIZE] ; /*!< labels for each dimension */ 144 tlab[MRI_LABEL_SIZE] ; /*!< labels for each dimension */ 145 ulab[MRI_LABEL_SIZE] ; /*!< labels for each dimension */ 146 vlab[MRI_LABEL_SIZE] ; /*!< labels for each dimension */ 147 wlab[MRI_LABEL_SIZE] ; /*!< labels for each dimension */ 148 #endif 149 150 char *fname ; /*!< to read actual image data after delay */ 151 int foffset ; /*!< offset into fname of image data */ 152 int fondisk ; /*!< flag to indicate if is on disk (?) */ 153 154 int was_swapped ; /* 07 Mar 2002 */ 155 int vdim ; 156 } MRI_IMAGE ; 157 158 #ifdef USE_MRI_LABELS 159 /*! Copy auxiliary data from one MRI_IMAGE to another. */ 160 # define MRI_COPY_AUX(nn,oo) \ 161 ( (nn)->dx = (oo)->dx , (nn)->dy = (oo)->dy , (nn)->dz = (oo)->dz , \ 162 (nn)->dt = (oo)->dt , (nn)->du = (oo)->du , (nn)->dv = (oo)->dv , \ 163 (nn)->dw = (oo)->dw , \ 164 (nn)->xo = (oo)->xo , (nn)->yo = (oo)->yo , (nn)->zo = (oo)->zo , \ 165 (nn)->to = (oo)->to , (nn)->uo = (oo)->uo , (nn)->vo = (oo)->vo , \ 166 (nn)->wo = (oo)->wo , \ 167 strcpy((nn)->xlab,(oo)->xlab) , strcpy((nn)->ylab,(oo)->ylab) , \ 168 strcpy((nn)->zlab,(oo)->zlab) , strcpy((nn)->tlab,(oo)->tlab) , \ 169 strcpy((nn)->ulab,(oo)->ulab) , strcpy((nn)->vlab,(oo)->vlab) , \ 170 strcpy((nn)->wlab,(oo)->wlab) , \ 171 mri_add_name( (oo)->name , (nn) ) ) 172 #else 173 # define MRI_COPY_AUX(nn,oo) \ 174 ( (nn)->dx = (oo)->dx , (nn)->dy = (oo)->dy , (nn)->dz = (oo)->dz , \ 175 (nn)->dt = (oo)->dt , (nn)->du = (oo)->du , (nn)->dv = (oo)->dv , \ 176 (nn)->dw = (oo)->dw , \ 177 (nn)->xo = (oo)->xo , (nn)->yo = (oo)->yo , (nn)->zo = (oo)->zo , \ 178 (nn)->to = (oo)->to , (nn)->uo = (oo)->uo , (nn)->vo = (oo)->vo , \ 179 (nn)->wo = (oo)->wo , \ 180 mri_add_name( (oo)->name , (nn) ) ) 181 #endif 182 183 /*! Check if MRI_IMAGE is 1D (ny=1) */ 184 #define MRI_IS_1D(iq) ((iq)->ny == 1) 185 186 /*! Check if MRI_IMAGE is 2D (nz=1) */ 187 #define MRI_IS_2D(iq) ((iq)->ny > 1 && (iq)->nz == 1) 188 189 /*! Check if MRI_IMAGE is 3D (nt=1) */ 190 #define MRI_IS_3D(iq) ((iq)->nz > 1 && (iq)->nt == 1) 191 192 /*! Check if MRI_IMAGE is 4D (nu=1) */ 193 #define MRI_IS_4D(iq) ((iq)->nt > 1 && (iq)->nu == 1) 194 195 /*! Return dimensionality of MRI_IMAGE */ 196 197 #define MRI_DIMENSIONALITY mri_dimensionality 198 extern int mri_dimensionality(MRI_IMAGE *) ; 199 200 extern void *mri_data_pointer( MRI_IMAGE * ) ; 201 202 #define MRI_BYTE_PTR(iq) ((byte *)mri_data_pointer(iq)) 203 #define MRI_SHORT_PTR(iq) ((short *)mri_data_pointer(iq)) 204 #define MRI_INT_PTR(iq) ((int *)mri_data_pointer(iq)) 205 #define MRI_FLOAT_PTR(iq) ((float *)mri_data_pointer(iq)) 206 #define MRI_DOUBLE_PTR(iq) ((double *)mri_data_pointer(iq)) 207 #define MRI_COMPLEX_PTR(iq) ((complex *)mri_data_pointer(iq)) 208 #define MRI_RGB_PTR(iq) ((byte *)mri_data_pointer(iq)) 209 #define MRI_RGBA_PTR(iq) ((rgba *)mri_data_pointer(iq)) 210 211 #endif /* _MCW_MRIIMAGE_HEADER_ */ 212