ecat7.h
Go to the documentation of this file.
00001 /******************************************************************************
00002 
00003   ecat7.h  (c) 2003-2010 Turku PET Centre
00004 
00005   Date:
00006   2003-07-26 Vesa Oikonen
00007   2003-08-03 VO
00008     Included definitions for patient orientation.
00009   2003-09-04 VO
00010     Introduced functions for 3D scan r/w.
00011   2003-10-08 VO
00012     ECAT7_MAGICNR changed from MATRIX7 to MATRIX72v
00013   2004-02-07 VO
00014     ECAT7_MAGICNR replaced by separate defines for image volumes and sinograms:
00015     ECAT7V_MAGICNR and ECAT7S_MAGICNR.
00016     Included define for sw_version = 72.
00017   2004-05-23 VO
00018     Introduced new function for ecat7p.c.
00019     Added a few comments.
00020   2004-06-27 VO
00021     Introduced new function for ecat7ml.c.
00022   2004-07-26 VO
00023     Comment style changes.
00024   2004-09-20 VO
00025     Added empty comments.
00026   2004-09-24 VO
00027     Added comments.
00028   2004-12-28 VO
00029     Introduced new function ecat7_is_scaling_needed().
00030   2007-02-27 VO
00031     Introduced new functions.
00032   2007-03-13 VO
00033     Introduced new functions.
00034   2007-03-27 VO
00035     Introduced new functions.
00036   2008-07-24 VO
00037     Introduced new functions.
00038   2010-08-19 VO
00039     Changed comment, not affecting compiled code.
00040 
00041 
00042 ******************************************************************************/
00043 #ifndef _ECAT7_H_
00044 #define _ECAT7_H_
00045 /*****************************************************************************/
00046 #ifndef MatBLKSIZE
00047 #define MatBLKSIZE 512
00048 #endif
00049 #ifndef MatFirstDirBlk
00050 #define MatFirstDirBlk 2
00051 #endif
00052 /*****************************************************************************/
00053 #define ECAT7V_MAGICNR "MATRIX72v"
00054 #define ECAT7S_MAGICNR "MATRIX7011"
00055 #define ECAT7_SW_VERSION 72
00056 /*****************************************************************************/
00058 #define ECAT7_BYTE      1
00059 #define ECAT7_VAXI2     2
00060 #define ECAT7_VAXI4     3
00061 #define ECAT7_VAXR4     4
00062 #define ECAT7_IEEER4    5
00063 #define ECAT7_SUNI2     6
00064 #define ECAT7_SUNI4     7
00065 /*****************************************************************************/
00067 #define ECAT7_UNKNOWN   0
00068 #define ECAT7_2DSCAN    1
00069 #define ECAT7_IMAGE16   2
00070 #define ECAT7_ATTEN     3
00071 #define ECAT7_2DNORM    4
00072 #define ECAT7_POLARMAP  5
00073 #define ECAT7_VOLUME8   6
00074 #define ECAT7_VOLUME16  7
00075 #define ECAT7_PROJ      8
00076 #define ECAT7_PROJ16    9
00077 #define ECAT7_IMAGE8    10
00078 #define ECAT7_3DSCAN    11
00079 #define ECAT7_3DSCAN8   12
00080 #define ECAT7_3DNORM    13
00081 #define ECAT7_3DSCANFIT 14
00082 /*****************************************************************************/
00084 #define ECAT7_Feet_First_Prone           0
00085 #define ECAT7_Head_First_Prone           1
00086 #define ECAT7_Feet_First_Supine          2
00087 #define ECAT7_Head_First_Supine          3
00088 #define ECAT7_Feet_First_Decubitus_Right 4
00089 #define ECAT7_Head_First_Decubitus_Right 5
00090 #define ECAT7_Feet_First_Decubitus_Left  6
00091 #define ECAT7_Head_First_Decubitus_Left  7
00092 #define ECAT7_Unknown_Orientation        8
00093 /*****************************************************************************/
00094 /* Backup file extension */
00095 #ifndef BACKUP_EXTENSION
00096 #define BACKUP_EXTENSION ".bak"
00097 #endif 
00098 /*****************************************************************************/
00099 char ecat7errmsg[128];
00100 /*****************************************************************************/
00101 int ECAT7_TEST;
00102 /*****************************************************************************/
00103 typedef struct ecat7_mainheader {  /* 512 bytes */
00105   char      magic_number[14];
00107   char      original_file_name[32];
00109   short int sw_version;
00111   short int system_type;
00113   short int file_type;
00115   char      serial_number[10];
00117   int       scan_start_time;
00119   char      isotope_name[8];
00121   float     isotope_halflife;
00123   char      radiopharmaceutical[32];
00125   float     gantry_tilt;
00127   float     gantry_rotation;
00129   float     bed_elevation;
00131   float     intrinsic_tilt;
00133   short int wobble_speed;
00135   short int transm_source_type;
00137   float     distance_scanned;
00139   float     transaxial_fov;
00141   short int angular_compression;
00143   short int coin_samp_mode;
00145   short int axial_samp_mode;
00146   float     ecat_calibration_factor;
00148   short int calibration_units;
00150   short int calibration_units_label;
00152   short int compression_code;
00154   char      study_type[12];
00156   char      patient_id[16];
00158   char      patient_name[32];
00160   char      patient_sex;
00162   char      patient_dexterity;
00164   float     patient_age;
00166   float     patient_height;
00168   float     patient_weight;
00172   int       patient_birth_date;
00174   char      physician_name[32];
00176   char      operator_name[32];
00178   char      study_description[32];
00181   short int acquisition_type;
00183   short int patient_orientation;
00185   char      facility_name[20];
00187   short int num_planes;
00189   short int num_frames;
00191   short int num_gates;
00193   short int num_bed_pos;
00195   float     init_bed_position;
00197   float     bed_position[15];
00199   float     plane_separation;
00201   short int lwr_sctr_thres;
00203   short int lwr_true_thres;
00205   short int upr_true_thres;
00207   char      user_process_code[10];
00209   short int acquisition_mode;
00211   float     bin_size;
00213   float     branching_fraction;
00215   int       dose_start_time;
00217   float     dosage;
00219   float     well_counter_corr_factor;
00221   char      data_units[32];
00223   short int septa_state;
00225   short int fill_cti[6];   
00226 } ECAT7_mainheader;
00227 /*****************************************************************************/
00228 typedef struct ecat7_imageheader {  /* 512 bytes */
00230   short int data_type;
00232   short int num_dimensions;
00234   short int x_dimension;
00236   short int y_dimension;
00238   short int z_dimension;
00240   float     x_offset;
00242   float     y_offset;
00244   float     z_offset;
00246   float     recon_zoom;
00248   float     scale_factor;
00250   short int image_min;
00252   short int image_max;
00254   float     x_pixel_size;
00256   float     y_pixel_size;
00258   float     z_pixel_size;
00260   int       frame_duration;
00262   int       frame_start_time;
00264   short int filter_code;
00266   float     x_resolution;
00268   float     y_resolution;
00270   float     z_resolution;
00272   float     num_r_elements;
00274   float     num_angles;
00276   float     z_rotation_angle;
00278   float     decay_corr_fctr;
00280   int       processing_code;
00282   int       gate_duration;
00284   int       r_wave_offset;
00286   int       num_accepted_beats;
00288   float     filter_cutoff_frequency;
00290   float     filter_resolution;
00292   float     filter_ramp_slope;
00294   short int filter_order;
00296   float     filter_scatter_fraction;
00298   float     filter_scatter_slope;
00300   char      annotation[40];
00302   float     mt_1_1;
00304   float     mt_1_2;
00306   float     mt_1_3;
00308   float     mt_2_1;
00310   float     mt_2_2;
00312   float     mt_2_3;
00314   float     mt_3_1;
00316   float     mt_3_2;
00318   float     mt_3_3;
00320   float     rfilter_cutoff;
00322   float     rfilter_resolution;
00324   short int rfilter_code;
00326   short int rfilter_order;
00328   float     zfilter_cutoff;
00330   float     zfilter_resolution;
00332   short int zfilter_code;
00334   short int zfilter_order;
00336   float     mt_1_4;
00338   float     mt_2_4;
00340   float     mt_3_4;
00342   short int scatter_type;
00344   short int recon_type;
00346   short int recon_views;
00348   short int fill_cti[87];
00350   short int fill_user[49];
00351 } ECAT7_imageheader;
00352 /*****************************************************************************/
00353 typedef struct ecat7_scanheader { /* 1024 bytes */
00355   short int data_type;
00357   short int num_dimensions;
00359   short int num_r_elements;
00361   short int num_angles;
00363   short int corrections_applied;
00365   short int num_z_elements[64];
00367   short int ring_difference;
00369   short int storage_order;
00371   short int axial_compression;
00373   float     x_resolution;
00375   float     v_resolution;
00377   float     z_resolution;
00379   float     w_resolution;
00381   short int fill_gate[6];
00383   int       gate_duration;
00385   int       r_wave_offset;
00387   int       num_accepted_beats;
00389   float     scale_factor;
00391   short int scan_min;
00393   short int scan_max;
00395   int       prompts;
00397   int       delayed;
00399   int       multiples;
00401   int       net_trues;
00403   float     tot_avg_cor;
00405   float     tot_avg_uncor;
00407   int       total_coin_rate;
00409   int       frame_start_time;
00411   int       frame_duration;
00413   float     deadtime_correction_factor;
00415   short int fill_cti[90];
00417   short int fill_user[50];
00419   float     uncor_singles[128];
00420 } ECAT7_scanheader;
00421 /*****************************************************************************/
00422 typedef struct ecat7_2Dscanheader { /* 512 bytes */
00423   short int data_type;
00424   short int num_dimensions;
00425   short int num_r_elements;
00426   short int num_angles;
00427   short int corrections_applied;
00428   short int num_z_elements;
00429   short int ring_difference;
00430   float     x_resolution;
00431   float     y_resolution;
00432   float     z_resolution;
00433   float     w_resolution;
00434   short int fill_gate[6];
00435   int       gate_duration;
00436   int       r_wave_offset;
00437   int       num_accepted_beats;
00438   float     scale_factor;
00439   short int scan_min;
00440   short int scan_max;
00441   int       prompts;
00442   int       delayed;
00443   int       multiples;
00444   int       net_trues;
00445   float     cor_singles[16];
00446   float     uncor_singles[16];
00447   float     tot_avg_cor;
00448   float     tot_avg_uncor;
00449   int       total_coin_rate;
00450   int       frame_start_time;
00451   int       frame_duration;
00452   float     deadtime_correction_factor;
00453   short int physical_planes[8];
00454   short int fill_cti[83];
00455   short int fill_user[50];
00456 } ECAT7_2Dscanheader;
00457 /*****************************************************************************/
00458 typedef struct ecat7_2Dnormheader {
00459   short int data_type;
00460   short int num_dimensions;
00461   short int num_r_elements;
00462   short int num_angles;
00463   short int num_z_elements;
00464   short int ring_difference;
00465   float     scale_factor;
00466   float     norm_min;
00467   float     norm_max;
00468   float     fov_source_width;
00469   float     norm_quality_factor;
00470   short int norm_quality_factor_code;
00471   short int storage_order;
00472   short int span;
00473   short int z_elements[64];
00474   short int fill_cti[123];
00475   short int fill_user[50];
00476 } ECAT7_2Dnormheader;
00477 /*****************************************************************************/
00478 typedef struct ecat7_attenheader {
00480   short int data_type;
00482   short int num_dimensions;
00484   short int attenuation_type;
00486   short int num_r_elements;
00488   short int num_angles;
00490   short int num_z_elements;
00492   short int ring_difference;
00494   float     x_resolution;
00496   float     y_resolution;
00498   float     z_resolution;
00500   float     w_resolution;
00502   float     scale_factor;
00504   float     x_offset;
00506   float     y_offset;
00508   float     x_radius;
00510   float     y_radius;
00512   float     tilt_angle;
00514   float     attenuation_coeff;
00516   float     attenuation_min;
00518   float     attenuation_max;
00520   float     skull_thickness;
00522   short int num_additional_atten_coeff;
00524   float     additional_atten_coeff[8];
00526   float     edge_finding_threshold;
00528   short int storage_order;
00530   short int span;
00532   short int z_elements[64];
00534   short int fill_cti[86];
00536   short int fill_user[50];
00537 } ECAT7_attenheader;
00538 /*****************************************************************************/
00539 typedef struct ecat7_normheader {
00540   short int data_type;
00542   short int num_r_elements;
00544   short int num_transaxial_crystals;
00546   short int num_crystal_rings;
00547   short int crystals_per_ring;
00549   short int num_geo_corr_planes;
00551   short int uld;
00553   short int lld;
00555   short int scatter_energy;
00557   float     norm_quality_factor;
00559   short int norm_quality_factor_code;
00561   float     ring_dtcor1[32];
00563   float     ring_dtcor2[32];
00565   float     crystal_dtcor[8];
00567   short int span;
00569   short int max_ring_diff;
00571   short int fill_cti[48];
00573   short int fill_user[50];
00574 } ECAT7_normheader;
00575 /*****************************************************************************/
00576 typedef struct ecat7_polmapheader {
00577   short int data_type;
00578   short int polar_map_type;         
00579   short int num_rings;
00580   short int sectors_per_ring[32];   
00581   float     ring_position[32];           
00582   short int ring_angle[32];      
00583   short int start_angle;   
00584   short int long_axis_left[3];         
00585   short int long_axis_right[3];   
00586   short int position_data;     
00587   short int image_min; 
00588   short int image_max;
00589   float     scale_factor;
00590   float     pixel_size;   
00591   int       frame_duration;
00592   int       frame_start_time;        
00593   short int processing_code;          
00594   short int quant_units;
00595   char      annotation[40];
00596   int       gate_duration;
00597   int       r_wave_offset;
00598   int       num_accepted_beats;
00599   char      polar_map_protocol[20];
00600   char      database_name[30];   
00601   short int fill_cti[27];       
00602   short int fill_user[27];
00603 } ECAT7_polmapheader;
00604 /*****************************************************************************/
00605 typedef struct {
00606   int id;
00607   int strtblk;
00608   int endblk;
00609   int status;
00610 } ECAT7_MatDir;
00611 typedef struct {
00612   int matrixNr;
00613   int matrixSpace;
00614   ECAT7_MatDir *matdir;
00615 } ECAT7_MATRIXLIST;
00616 typedef struct {
00617   int frame, plane, gate, data, bed;
00618 } ECAT7_Matval;
00619 /*****************************************************************************/
00620 /* Read functions */
00621 extern int ecat7ReadMainheader(FILE *fp, ECAT7_mainheader *h);
00622 extern int ecat7ReadImageheader(FILE *fp, int blk, ECAT7_imageheader *h);
00623 extern int ecat7ReadAttenheader(FILE *fp, int blk, ECAT7_attenheader *h);
00624 extern int ecat7ReadPolmapheader(FILE *fp, int blk, ECAT7_polmapheader *h);
00625 extern int ecat7ReadNormheader(FILE *fp, int blk, ECAT7_normheader *h);
00626 extern int ecat7ReadScanheader(FILE *fp, int blk, ECAT7_scanheader *h);
00627 extern int ecat7Read2DScanheader(FILE *fp, int blk, ECAT7_2Dscanheader *h);
00628 extern int ecat7Read2DNormheader(FILE *fp, int blk, ECAT7_2Dnormheader *h);
00629 extern int ecat7ReadMatrixdata(FILE *fp, int start_block, int block_nr,
00630       char *data, int dtype);
00631 extern float ecat7rFloat(void *bufi, int isvax, int islittle);
00632 extern int ecat7rInt(void *bufi, int isvax, int islittle);
00633 extern int ecat7ReadImageMatrix(FILE *fp, int first_block, int last_block,
00634       ECAT7_imageheader *h, float **fdata);
00635 extern int ecat7Read2DScanMatrix(FILE *fp, int first_block, int last_block,
00636       ECAT7_2Dscanheader *h, float **fdata);
00637 extern int ecat7ReadScanMatrix(FILE *fp, int first_block, int last_block,
00638       ECAT7_scanheader *h, float **fdata);
00639 extern int ecat7ReadPolarmapMatrix(FILE *fp, int first_block, int last_block,
00640       ECAT7_polmapheader *h, float **fdata);
00641 extern int ecat7pxlbytes(short int data_type);
00642 /*****************************************************************************/
00643 /* Matrix list functions */
00644 extern void ecat7InitMatlist(ECAT7_MATRIXLIST *mlist);
00645 extern void ecat7EmptyMatlist(ECAT7_MATRIXLIST *mlist);
00646 extern int ecat7ReadMatlist(FILE *fp, ECAT7_MATRIXLIST *ml);
00647 extern void ecat7PrintMatlist(ECAT7_MATRIXLIST *ml);
00648 extern int ecat7EnterMatrix(FILE *fp, int matrix_id, int block_nr);
00649 extern int ecat7_val_to_id(int frame, int plane, int gate, int data, int bed);
00650 extern void ecat7_id_to_val(int matrix_id, ECAT7_Matval *matval);
00651 extern void ecat7SortMatlistByPlane(ECAT7_MATRIXLIST *ml);
00652 extern void ecat7SortMatlistByFrame(ECAT7_MATRIXLIST *ml);
00653 extern int ecat7CheckMatlist(ECAT7_MATRIXLIST *ml);
00654 extern int ecat7DeleteLateFrames(ECAT7_MATRIXLIST *ml, int frame_nr);
00655 extern int ecat7GetPlaneAndFrameNr(ECAT7_MATRIXLIST *mlist, ECAT7_mainheader *h,
00656       int *plane_nr, int *frame_nr);
00657 extern int ecat7GetMatrixBlockSize(ECAT7_MATRIXLIST *mlist, int *blk_nr);
00658 extern int ecat7GetNums(ECAT7_MATRIXLIST *ml, ECAT7_mainheader *mh, FILE *fp,
00659       short int *num_planes, short int *num_frames, short int *num_gates,
00660       short int *num_bed_pos);
00661 extern int ecat7GatherMatlist(ECAT7_MATRIXLIST *ml, short int do_planes,
00662       short int do_frames, short int do_gates, short int do_beds);
00663 /*****************************************************************************/
00664 /* Write functions */
00665 extern int ecat7WriteMainheader(FILE *fp, ECAT7_mainheader *h);
00666 extern int ecat7WriteImageheader(FILE *fp, int blk, ECAT7_imageheader *h);
00667 extern int ecat7WriteAttenheader(FILE *fp, int blk, ECAT7_attenheader *h);
00668 extern int ecat7WritePolmapheader(FILE *fp, int blk, ECAT7_polmapheader *h);
00669 extern int ecat7WriteNormheader(FILE *fp, int blk, ECAT7_normheader *h);
00670 extern int ecat7WriteScanheader(FILE *fp, int blk, ECAT7_scanheader *h);
00671 extern int ecat7Write2DScanheader(FILE *fp, int blk, ECAT7_2Dscanheader *h);
00672 extern int ecat7Write2DNormheader(FILE *fp, int blk, ECAT7_2Dnormheader *h);
00673 extern int ecat7WritePolarmapMatrix(FILE *fp, int matrix_id,
00674       ECAT7_polmapheader *h, float *fdata);
00675 extern int ecat7WriteMatrixdata(FILE *fp, int start_block, char *data,
00676       int pxl_nr, int pxl_size);
00677 /*void ecat7wFloat(float *bufi, void *bufo, int tovax, int islittle);*/
00678 /*void ecat7wInt(int *bufi, void *bufo, int tovax, int islittle);*/
00679 extern FILE *ecat7Create(const char *fname, ECAT7_mainheader *h);
00680 extern int ecat7WriteImageMatrix(FILE *fp, int matrix_id, ECAT7_imageheader *h,
00681       float *fdata);
00682 extern int ecat7Write2DScanMatrix(FILE *fp, int matrix_id, ECAT7_2Dscanheader *h,
00683       float *fdata);
00684 extern int ecat7WriteScanMatrix(FILE *fp, int matrix_id, ECAT7_scanheader *h,
00685       float *fdata);
00686 extern int ecat7_is_scaling_needed(float amax, float *data, int nr);
00687 /*****************************************************************************/
00688 /* Printing functions */
00689 extern void ecat7PrintMainheader(ECAT7_mainheader *h, FILE *fp);
00690 extern void ecat7PrintImageheader(ECAT7_imageheader *h, FILE *fp);
00691 extern void ecat7PrintScanheader(ECAT7_scanheader *h, FILE *fp);
00692 extern void ecat7PrintAttenheader(ECAT7_attenheader *h, FILE *fp);
00693 extern void ecat7PrintPolmapheader(ECAT7_polmapheader *h, FILE *fp);
00694 extern void ecat7PrintNormheader(ECAT7_normheader *h, FILE *fp);
00695 extern void ecat7Print2DScanheader(ECAT7_2Dscanheader *h, FILE *fp);
00696 extern void ecat7Print2DNormheader(ECAT7_2Dnormheader *h, FILE *fp);
00697 extern int ecat7PrintSubheader(ECAT7_mainheader mh, FILE *fp,
00698       int plane, int frame, FILE *ofp);
00699 /* Descriptive strings for printing */
00700 extern char* ecat7filetype(short int file_type);
00701 extern char* ecat7acquisitiontype(short int acquisition_type);
00702 extern char* ecat7datatype(short int data_type);
00703 /*****************************************************************************/
00704 /* Header edit functions */
00705 extern int ecat7EditMHeader(ECAT7_mainheader *h, char *field, char *value);
00706 extern int ecat7EditSHeader(ECAT7_scanheader *h, char *field, char *value);
00707 extern int ecat7EditVHeader(ECAT7_imageheader *h, char *field, char *value);
00708 /*****************************************************************************/
00709 #endif
00710