00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #ifndef __mitkAnalyzeImageReader_h
00012 #define __mitkAnalyzeImageReader_h
00013
00014 #include "mitkVolumeReader.h"
00015
00016
00041
00042
00043
00044 namespace AnalyzeImageIO
00045 {
00050 enum DataTypeKeyValues {
00051 ANALYZE_DT_UNKNOWN =0,
00052 ANALYZE_DT_BINARY =1,
00053 ANALYZE_DT_UNSIGNED_CHAR=2,
00054 ANALYZE_DT_SIGNED_SHORT =4,
00055 ANALYZE_DT_SIGNED_INT =8,
00056 ANALYZE_DT_FLOAT =16,
00057 ANALYZE_DT_COMPLEX =32,
00058 ANALYZE_DT_DOUBLE =64,
00059 ANALYZE_DT_RGB =128,
00060 ANALYZE_DT_ALL =255,
00061
00062
00063 SPMANALYZE_DT_UNSIGNED_SHORT=132,
00064 SPMANALYZE_DT_UNSIGNED_INT =136
00065 };
00066
00071 enum DataTypeIndex {
00072 ANALYZE_DT_INDEX_UNKNOWN =0,
00073 ANALYZE_DT_INDEX_BINARY =1,
00074 ANALYZE_DT_INDEX_UNSIGNED_CHAR =2,
00075 ANALYZE_DT_INDEX_SIGNED_SHORT =3,
00076 ANALYZE_DT_INDEX_SIGNED_INT =4,
00077 ANALYZE_DT_INDEX_FLOAT =5,
00078 ANALYZE_DT_INDEX_COMPLEX =6,
00079 ANALYZE_DT_INDEX_DOUBLE =7,
00080 ANALYZE_DT_INDEX_RGB =8,
00081 ANALYZE_DT_INDEX_ALL =9,
00082
00083
00084 SPMANALYZE_DT_INDEX_UNSIGNED_SHORT =10,
00085 SPMANALYZE_DT_INDEX_UNSIGNED_INT =11
00086 };
00087
00103 typedef enum
00104 {
00105 ANALYZE_ORIENTATION_RPI_TRANSVERSE=0,
00106 ANALYZE_ORIENTATION_RIP_CORONAL =1,
00107 ANALYZE_ORIENTATION_PIR_SAGITTAL =2,
00108 ANALYZE_ORIENTATION_RAI_TRANSVERSE_FLIPPED=3,
00109 ANALYZE_ORIENTATION_RSP_CORONAL_FLIPPED=4,
00110 ANALYZE_ORIENTATION_PIL_SAGITTAL_FLIPPED=5
00111 } ;
00112
00119 struct header_key
00120 {
00121 int sizeof_hdr;
00126 char data_type[10];
00129 char db_name[18];
00131 int extents;
00134 short int session_error;
00136 char regular;
00137 char hkey_un0;
00138 };
00139
00148 struct image_dimension
00149 {
00150 short int dim[8];
00159 char vox_units[4];
00161 char cal_units[8];
00163 short int unused1;
00164 short int datatype;
00168 short int bitpix;
00170 short int dim_un0;
00171 float pixdim[8];
00182 float vox_offset;
00185 float roi_scale;
00190 float funused1;
00191 float funused2;
00192 float cal_max;
00196 float cal_min;
00197 int compressed;
00208 int verified;
00209 int glmax;
00219 int glmin;
00220 };
00221
00236 struct data_history
00237 {
00238 char descrip[80];
00239 char aux_file[24];
00242 char orient;
00285 char originator[10];
00286 char generated[10];
00287 char scannum[10];
00288 char patient_id[10];
00289 char exp_date[10];
00290 char exp_time[10];
00291 char hist_un0[3];
00292 int views;
00293 int vols_added;
00294 int start_field;
00295 int field_skip;
00296 int omax;
00300 int omin;
00301 int smax;
00302 int smin;
00303 };
00304
00319 struct dsr
00320 {
00321 struct header_key hk;
00322 struct image_dimension dime;
00323 struct data_history hist;
00324 };
00325
00326 }
00327
00328
00329 using namespace AnalyzeImageIO;
00330
00331
00356 class MITK_COMMON_API mitkAnalyzeImageReader : public mitkVolumeReader
00357 {
00358 public:
00359 MITK_TYPE(mitkAnalyzeImageReader, mitkVolumeReader)
00360
00361 virtual void PrintSelf(ostream &os);
00362
00363 mitkAnalyzeImageReader();
00364
00365 typedef std::streamoff SizeType;
00366
00367 typedef enum { BigEndian, LittleEndian, OrderNotApplicable } ByteOrder;
00368
00369 typedef enum { ASCII, Binary, TypeNotApplicable } FileType;
00370
00371 const char * GetFileExtensions() { return ".hdr .img .img.gz"; }
00372
00373 unsigned long long GetDataBytes();
00374
00375 protected:
00376 virtual ~mitkAnalyzeImageReader();
00377
00378 virtual bool Execute();
00379 bool ReadInfo();
00380 bool ReadData();
00381
00382 bool ReadBufferAsBinary(std::istream& os, void *buffer, SizeType numberOfBytesToBeRead);
00383 ByteOrder CheckAnalyzeEndian(const struct dsr &temphdr);
00384 void SwapHeaderBytesIfNecessary( struct dsr * const imageheader );
00385 void SwapBytesIfNecessary( void* buffer, unsigned long numberOfPixels );
00386
00387 int m_ComponentType;
00388 unsigned int m_NumberOfComponents;
00389 unsigned int m_NumberOfDimensions;
00390 int m_Dimensions[3];
00391 float m_Spacing[3];
00392
00393 private:
00394 mitkAnalyzeImageReader(const mitkAnalyzeImageReader&);
00395 void operator = (const mitkAnalyzeImageReader&);
00396
00397 ByteOrder m_ByteOrder;
00398 FileType m_FileType;
00399
00400 struct dsr m_Hdr;
00401 ByteOrder m_MachineByteOrder;
00402 };
00403
00404
00405 #endif
00406