Main Page   Modules   Compound List   File List   Compound Members   File Members  

fslio.h

Go to the documentation of this file.
00001 
00005 /*
00006     fslio.h  (Input and output routines for images in FSL)
00007 
00008     Mark Jenkinson
00009     FMRIB Image Analysis Group
00010 
00011 */
00012 
00013     
00014 /*
00015     The fslio.h file was originally part of FSL - FMRIB's Software Library
00016     http://www.fmrib.ox.ac.uk/fsl
00017     fslio.h has now been placed in the public domain.
00018    
00019     Developed at FMRIB (Oxford Centre for Functional Magnetic Resonance
00020     Imaging of the Brain), Department of Clinical Neurology, Oxford
00021     University, Oxford, UK
00022 */
00023 
00024 #if !defined(__FSLIO_H)
00025 #define __FSLIO_H
00026 
00027 #include <stdio.h>
00028 #include <nifti1_io.h>
00029 #include <znzlib.h>
00030 #include "dbh.h"
00031 
00032 #ifdef __cplusplus
00033 extern "C" {
00034 #endif
00035 
00036 
00037   /*
00038     Note that this library is similar to avwio but has changed in many ways.
00039     It is almost fully backwards compatible, but not quite, as it cannot write
00040     .nii.gz files using the old style functions.
00041 
00042     Recommended ways of reading and writing images are:
00043 
00044     Reading
00045     -------
00046       Use the FslOpen(), FslReadVolumes() and FslClose() functions.  e.g.
00047         FSLIO *fslio;
00048         void *buffer;
00049         int nvols;
00050         fslio = FslOpen("/some/path/name_of_file","rb");
00051           ... can now access header info via the FslGet calls ...
00052           ... allocate room for buffer ...
00053         FslReadVolumes(fslio,buffer,nvols);
00054           ... do something ...
00055         FslClose(fslio);
00056 
00057 
00058     Writing
00059     -------
00060       This is more complicated due to the nature of gzipped writing, which must be
00061       done in the correct order, and for single files (*.nii.gz) this means that 
00062       the header information must be written before any image data.
00063 
00064     (1)
00065       The best method to use is almost backwards compatible, but requires 
00066       an FslWriteHeader() call:
00067 
00068         FSLIO* fslio;
00069         fslio = FslOpen("/some/path/name_of_file","wb");
00070           ... set the appropriate header information using FslSet calls ...
00071         FslWriteHeader(fslio);
00072         
00073           ... now can write one or more volumes at a time using 
00074               FslWriteVolumes(fslio,buffer,nvols) ...
00075 
00076         FslClose(fslio); 
00077 
00078       This version is useful if your image data needs to be written from different blocks
00079       of memory.
00080 
00081     (2)
00082       Another method is available, but which is discouraged, is:
00083         FSLIO* fslio;
00084         fslio = FslOpen("/some/path/name_of_file","wb");
00085         
00086           ... set some appropriate header information using FslSet calls ...
00087           ... now can write one or more volumes at a time using 
00088               FslWriteVolumes(fslio,buffer,nvols) ...
00089           ... set more appropriate header information using FslSet calls ...
00090 
00091         FslClose(fslio);
00092 
00093       WARNING: this cannot write .nii.gz files as the header information cannot be
00094       written by FslClose() after the image data is written, which is how the previous
00095       versions have worked.
00096         
00097 
00098    */
00099 
00104 #define FSL_TYPE_ANALYZE         0
00105 #define FSL_TYPE_NIFTI           1
00106 #define FSL_TYPE_NIFTI_PAIR      2
00107 #define FSL_TYPE_MINC            4
00108 #define FSL_TYPE_ANALYZE_GZ    100
00109 #define FSL_TYPE_NIFTI_GZ      101
00110 #define FSL_TYPE_NIFTI_PAIR_GZ 102
00111 #define FSL_TYPE_MINC_GZ       104
00112 /* @} */
00113 
00114 #define FSL_RADIOLOGICAL        -1
00115 #define FSL_NEUROLOGICAL         1
00116 
00117 
00123 typedef struct 
00124 {
00125   znzFile fileptr;
00126   nifti_image *niftiptr;
00127 #ifdef USE_MINC
00128   minc_image *mincptr;
00129 #else
00130   void *mincptr;
00131 #endif
00132   int file_mode;
00133   int write_mode;
00134   int written_hdr;
00135 } FSLIO;
00136 
00137 
00138   /* basic file i/o commands */
00139 
00140 FSLIO *FslOpen(const char *filename, const char *opts);
00141 FSLIO *FslXOpen(const char *filename, const char *opts, int filetype);
00142 int FslSeekVolume(FSLIO *fslio, size_t vols);
00143 int FslClose(FSLIO *fslio);
00144 
00145   /* basic read and write commands */
00146 
00147 void* FslReadAllVolumes(FSLIO* fslio, char* filename);
00148 void  FslWriteAllVolumes(FSLIO *fslio, const void *buffer);
00149 
00150 size_t FslReadVolumes(FSLIO *fslio, void *buffer, size_t nvols);
00151 size_t FslWriteVolumes(FSLIO *fslio, const void *buffer, size_t nvols);
00152 
00153 void   FslWriteHeader(FSLIO *fslio);
00154 
00155   /* support functions for file names and types */
00156 
00157 int   FslFileExists(const char *filename);
00158 char *FslMakeBaseName(const char *fname);
00159 int   FslCheckForMultipleFileNames(const char* filename);
00160 int   FslGetEnvOutputType(void);
00161 
00162 void  FslSetIgnoreMFQ(int flag);
00163 int   FslGetIgnoreMFQ(void);
00164 void  FslSetOverrideOutputType(int type);
00165 int   FslGetOverrideOutputType(void);
00166 
00167 
00168 int  FslGetFileType(const FSLIO *fslio);
00169 void FslSetFileType(FSLIO *fslio, int filetype);
00170 int  FslIsSingleFileType(int filetype);
00171 int  FslIsCompressedFileType(int filetype);
00172 int  FslBaseFileType(int filetype);
00173 char* FslFileTypeString(int filetype);
00174 
00175 int  FslGetWriteMode(const FSLIO *fslio);
00176 void FslSetWriteMode(FSLIO *fslio, int mode);
00177 
00178 void AvwSwapHeader(struct dsr *avw);
00179 int  FslReadRawHeader(void *buffer, const char* filename);
00180 
00181 
00182   /* simple creation and clone/copy operations */
00183 
00184 FSLIO *FslInit(void);
00185 void   FslInitHeader(FSLIO *fslio, short t, 
00186                    size_t x, size_t y, size_t z, size_t v,
00187                    float vx, float vy, float vz, float tr,
00188                    size_t dim,
00189                    const char* units);
00190 void   FslSetInit(FSLIO* fslio);
00191 void   FslCloneHeader(FSLIO *dest, const FSLIO *src);
00192 
00193 
00194   /* get and set routines for properties */
00195 
00196 size_t FslGetVolSize(FSLIO *fslio);
00197 
00198 void FslSetDim(FSLIO *fslio, short x, short y, short z, short v);
00199 void FslGetDim(FSLIO *fslio, short *x, short *y, short *z, short *v);
00200 void FslSetDimensionality(FSLIO *fslio, size_t dim);
00201 void FslGetDimensionality(FSLIO *fslio, size_t *dim);
00202 void FslSetVoxDim(FSLIO *fslio, float x, float y, float z, float tr);
00203 void FslGetVoxDim(FSLIO *fslio, float *x, float *y, float *z, float *tr);
00204 void FslGetCalMinMax(FSLIO *fslio, float *min, float *max);
00205 void FslSetCalMinMax(FSLIO *fslio, float  min, float  max);
00206 void FslGetAuxFile(FSLIO *fslio,char *aux_file);
00207 void FslSetAuxFile(FSLIO *fslio,const char *aux_file);
00208 void FslSetTimeUnits(FSLIO *fslio, const char *units);
00209 void FslGetTimeUnits(FSLIO *fslio, char *units);
00210 void FslSetDataType(FSLIO *fslio, short t);
00211 size_t FslGetDataType(FSLIO *fslio, short *t);
00212 int    FslGetIntensityScaling(FSLIO *fslio, float *slope, float *intercept);
00213 void   FslSetIntent(FSLIO *fslio, short intent_code, float p1, float p2, float p3);
00214 short  FslGetIntent(FSLIO *fslio, short *intent_code, float *p1, float *p2,
00215                     float *p3);
00216 
00217 
00218 short FslGetStdXform(FSLIO *fslio, mat44 *stdmat);
00219 void  FslSetStdXform(FSLIO *fslio, short sform_code, mat44 stdmat);
00220 void  FslGetMMCoord(mat44 stdmat, float voxx, float voxy, float voxz, 
00221                     float *mmx, float *mmy, float *mmz);
00222 
00223 void  FslGetVoxCoord(mat44 stdmat, float mmx, float mmy, float mmz, 
00224                      float *voxx, float *voxy, float *voxz); 
00225 short FslGetRigidXform(FSLIO *fslio, mat44 *rigidmat);
00226 void  FslSetRigidXform(FSLIO *fslio, short qform_code, mat44 rigidmat);
00227 int   FslGetLeftRightOrder(FSLIO *fslio);
00228 
00229   /* these two functions are deprecated with the nifti/analyze support */
00230   /* please do all spatial coordinate origins via the Std and Rigid Xforms */
00231 void  FslSetAnalyzeSform(FSLIO *fslio, const short *orig, 
00232                          float dx, float dy, float dz);
00233 void  FslGetAnalyzeOrigin(FSLIO *fslio, short orig[5]);
00234 
00235   /* other read and write commands */
00236 
00237 size_t FslReadSliceSeries(FSLIO *fslio, void *buffer,short slice, size_t nvols);
00238 size_t FslReadRowSeries(FSLIO *fslio, void *buffer, short row, short slice, size_t nvols);
00239 size_t FslReadTimeSeries(FSLIO *fslio, void *buffer, short xVox, short yVox, short zVox, size_t nvols);
00240 
00241   /* miscellaneous helper stuff */
00242 
00243 mat33 mat44_to_mat33(mat44 x);
00244 
00245 
00246 
00247 /* added by KF pending discussion w/ Mark */
00248 typedef unsigned char   THIS_UINT8; 
00249 typedef char            THIS_INT8;
00250 typedef unsigned short  THIS_UINT16;
00251 typedef short           THIS_INT16;
00252 typedef unsigned int    THIS_UINT32;
00253 typedef int             THIS_INT32;
00254 typedef unsigned long   THIS_UINT64;
00255 typedef long            THIS_INT64;
00256 typedef float           THIS_FLOAT32;
00257 typedef double          THIS_FLOAT64;
00258 
00259 FSLIO * FslReadHeader(char *fname);
00260 double ****FslGetBufferAsScaledDouble(FSLIO *fslio);
00261 double ***FslGetVolumeAsScaledDouble(FSLIO *fslio, int vol);
00262 int  convertBufferToScaledDouble(double *outbuf, void *inbuf, long len, float slope, float inter, int nifti_datatype ) ;
00263 double ****d4matrix(int th, int zh,  int yh, int xh);
00264 double ***d3matrix(int zh,  int yh, int xh);
00265 
00266 
00267 #ifdef __cplusplus
00268 }
00269 #endif
00270 
00271 #endif
00272 
00273 
00274 

Generated at Thu Aug 28 16:47:55 2008 for nifti1_io by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000