ecat7.h
Go to the documentation of this file.
1 /******************************************************************************
2 
3  ecat7.h (c) 2003-2010 Turku PET Centre
4 
5  Date:
6  2003-07-26 Vesa Oikonen
7  2003-08-03 VO
8  Included definitions for patient orientation.
9  2003-09-04 VO
10  Introduced functions for 3D scan r/w.
11  2003-10-08 VO
12  ECAT7_MAGICNR changed from MATRIX7 to MATRIX72v
13  2004-02-07 VO
14  ECAT7_MAGICNR replaced by separate defines for image volumes and sinograms:
15  ECAT7V_MAGICNR and ECAT7S_MAGICNR.
16  Included define for sw_version = 72.
17  2004-05-23 VO
18  Introduced new function for ecat7p.c.
19  Added a few comments.
20  2004-06-27 VO
21  Introduced new function for ecat7ml.c.
22  2004-07-26 VO
23  Comment style changes.
24  2004-09-20 VO
25  Added empty comments.
26  2004-09-24 VO
27  Added comments.
28  2004-12-28 VO
29  Introduced new function ecat7_is_scaling_needed().
30  2007-02-27 VO
31  Introduced new functions.
32  2007-03-13 VO
33  Introduced new functions.
34  2007-03-27 VO
35  Introduced new functions.
36  2008-07-24 VO
37  Introduced new functions.
38  2010-08-19 VO
39  Changed comment, not affecting compiled code.
40 
41 
42 ******************************************************************************/
43 #ifndef _ECAT7_H_
44 #define _ECAT7_H_
45 /*****************************************************************************/
46 #ifndef MatBLKSIZE
47 #define MatBLKSIZE 512
48 #endif
49 #ifndef MatFirstDirBlk
50 #define MatFirstDirBlk 2
51 #endif
52 /*****************************************************************************/
53 #define ECAT7V_MAGICNR "MATRIX72v"
54 #define ECAT7S_MAGICNR "MATRIX7011"
55 #define ECAT7_SW_VERSION 72
56 /*****************************************************************************/
58 #define ECAT7_BYTE 1
59 #define ECAT7_VAXI2 2
60 #define ECAT7_VAXI4 3
61 #define ECAT7_VAXR4 4
62 #define ECAT7_IEEER4 5
63 #define ECAT7_SUNI2 6
64 #define ECAT7_SUNI4 7
65 /*****************************************************************************/
67 #define ECAT7_UNKNOWN 0
68 #define ECAT7_2DSCAN 1
69 #define ECAT7_IMAGE16 2
70 #define ECAT7_ATTEN 3
71 #define ECAT7_2DNORM 4
72 #define ECAT7_POLARMAP 5
73 #define ECAT7_VOLUME8 6
74 #define ECAT7_VOLUME16 7
75 #define ECAT7_PROJ 8
76 #define ECAT7_PROJ16 9
77 #define ECAT7_IMAGE8 10
78 #define ECAT7_3DSCAN 11
79 #define ECAT7_3DSCAN8 12
80 #define ECAT7_3DNORM 13
81 #define ECAT7_3DSCANFIT 14
82 /*****************************************************************************/
84 #define ECAT7_Feet_First_Prone 0
85 #define ECAT7_Head_First_Prone 1
86 #define ECAT7_Feet_First_Supine 2
87 #define ECAT7_Head_First_Supine 3
88 #define ECAT7_Feet_First_Decubitus_Right 4
89 #define ECAT7_Head_First_Decubitus_Right 5
90 #define ECAT7_Feet_First_Decubitus_Left 6
91 #define ECAT7_Head_First_Decubitus_Left 7
92 #define ECAT7_Unknown_Orientation 8
93 /*****************************************************************************/
94 /* Backup file extension */
95 #ifndef BACKUP_EXTENSION
96 #define BACKUP_EXTENSION ".bak"
97 #endif
98 /*****************************************************************************/
99 char ecat7errmsg[128];
100 /*****************************************************************************/
102 /*****************************************************************************/
103 typedef struct ecat7_mainheader { /* 512 bytes */
105  char magic_number[14];
109  short int sw_version;
111  short int system_type;
113  short int file_type;
115  char serial_number[10];
119  char isotope_name[8];
125  float gantry_tilt;
133  short int wobble_speed;
143  short int coin_samp_mode;
145  short int axial_samp_mode;
148  short int calibration_units;
152  short int compression_code;
154  char study_type[12];
156  char patient_id[16];
158  char patient_name[32];
164  float patient_age;
174  char physician_name[32];
176  char operator_name[32];
181  short int acquisition_type;
185  char facility_name[20];
187  short int num_planes;
189  short int num_frames;
191  short int num_gates;
193  short int num_bed_pos;
197  float bed_position[15];
201  short int lwr_sctr_thres;
203  short int lwr_true_thres;
205  short int upr_true_thres;
209  short int acquisition_mode;
211  float bin_size;
217  float dosage;
221  char data_units[32];
223  short int septa_state;
225  short int fill_cti[6];
227 /*****************************************************************************/
228 typedef struct ecat7_imageheader { /* 512 bytes */
230  short int data_type;
232  short int num_dimensions;
234  short int x_dimension;
236  short int y_dimension;
238  short int z_dimension;
240  float x_offset;
242  float y_offset;
244  float z_offset;
246  float recon_zoom;
250  short int image_min;
252  short int image_max;
264  short int filter_code;
274  float num_angles;
294  short int filter_order;
300  char annotation[40];
302  float mt_1_1;
304  float mt_1_2;
306  float mt_1_3;
308  float mt_2_1;
310  float mt_2_2;
312  float mt_2_3;
314  float mt_3_1;
316  float mt_3_2;
318  float mt_3_3;
324  short int rfilter_code;
326  short int rfilter_order;
332  short int zfilter_code;
334  short int zfilter_order;
336  float mt_1_4;
338  float mt_2_4;
340  float mt_3_4;
342  short int scatter_type;
344  short int recon_type;
346  short int recon_views;
348  short int fill_cti[87];
350  short int fill_user[49];
352 /*****************************************************************************/
353 typedef struct ecat7_scanheader { /* 1024 bytes */
355  short int data_type;
357  short int num_dimensions;
359  short int num_r_elements;
361  short int num_angles;
365  short int num_z_elements[64];
367  short int ring_difference;
369  short int storage_order;
371  short int axial_compression;
381  short int fill_gate[6];
391  short int scan_min;
393  short int scan_max;
395  int prompts;
397  int delayed;
403  float tot_avg_cor;
415  short int fill_cti[90];
417  short int fill_user[50];
419  float uncor_singles[128];
421 /*****************************************************************************/
422 typedef struct ecat7_2Dscanheader { /* 512 bytes */
423  short int data_type;
424  short int num_dimensions;
425  short int num_r_elements;
426  short int num_angles;
428  short int num_z_elements;
429  short int ring_difference;
434  short int fill_gate[6];
439  short int scan_min;
440  short int scan_max;
441  int prompts;
442  int delayed;
445  float cor_singles[16];
446  float uncor_singles[16];
447  float tot_avg_cor;
453  short int physical_planes[8];
454  short int fill_cti[83];
455  short int fill_user[50];
457 /*****************************************************************************/
458 typedef struct ecat7_2Dnormheader {
459  short int data_type;
460  short int num_dimensions;
461  short int num_r_elements;
462  short int num_angles;
463  short int num_z_elements;
464  short int ring_difference;
466  float norm_min;
467  float norm_max;
471  short int storage_order;
472  short int span;
473  short int z_elements[64];
474  short int fill_cti[123];
475  short int fill_user[50];
477 /*****************************************************************************/
478 typedef struct ecat7_attenheader {
480  short int data_type;
482  short int num_dimensions;
484  short int attenuation_type;
486  short int num_r_elements;
488  short int num_angles;
490  short int num_z_elements;
492  short int ring_difference;
504  float x_offset;
506  float y_offset;
508  float x_radius;
510  float y_radius;
512  float tilt_angle;
528  short int storage_order;
530  short int span;
532  short int z_elements[64];
534  short int fill_cti[86];
536  short int fill_user[50];
538 /*****************************************************************************/
539 typedef struct ecat7_normheader {
540  short int data_type;
542  short int num_r_elements;
546  short int num_crystal_rings;
547  short int crystals_per_ring;
551  short int uld;
553  short int lld;
555  short int scatter_energy;
561  float ring_dtcor1[32];
563  float ring_dtcor2[32];
565  float crystal_dtcor[8];
567  short int span;
569  short int max_ring_diff;
571  short int fill_cti[48];
573  short int fill_user[50];
575 /*****************************************************************************/
576 typedef struct ecat7_polmapheader {
577  short int data_type;
578  short int polar_map_type;
579  short int num_rings;
580  short int sectors_per_ring[32];
581  float ring_position[32];
582  short int ring_angle[32];
583  short int start_angle;
584  short int long_axis_left[3];
585  short int long_axis_right[3];
586  short int position_data;
587  short int image_min;
588  short int image_max;
590  float pixel_size;
593  short int processing_code;
594  short int quant_units;
595  char annotation[40];
600  char database_name[30];
601  short int fill_cti[27];
602  short int fill_user[27];
604 /*****************************************************************************/
605 typedef struct {
606  int id;
607  int strtblk;
608  int endblk;
609  int status;
610 } ECAT7_MatDir;
611 typedef struct {
612  int matrixNr;
616 typedef struct {
617  int frame, plane, gate, data, bed;
618 } ECAT7_Matval;
619 /*****************************************************************************/
620 /* Read functions */
621 extern int ecat7ReadMainheader(FILE *fp, ECAT7_mainheader *h);
622 extern int ecat7ReadImageheader(FILE *fp, int blk, ECAT7_imageheader *h);
623 extern int ecat7ReadAttenheader(FILE *fp, int blk, ECAT7_attenheader *h);
624 extern int ecat7ReadPolmapheader(FILE *fp, int blk, ECAT7_polmapheader *h);
625 extern int ecat7ReadNormheader(FILE *fp, int blk, ECAT7_normheader *h);
626 extern int ecat7ReadScanheader(FILE *fp, int blk, ECAT7_scanheader *h);
627 extern int ecat7Read2DScanheader(FILE *fp, int blk, ECAT7_2Dscanheader *h);
628 extern int ecat7Read2DNormheader(FILE *fp, int blk, ECAT7_2Dnormheader *h);
629 extern int ecat7ReadMatrixdata(FILE *fp, int start_block, int block_nr,
630  char *data, int dtype);
631 extern float ecat7rFloat(void *bufi, int isvax, int islittle);
632 extern int ecat7rInt(void *bufi, int isvax, int islittle);
633 extern int ecat7ReadImageMatrix(FILE *fp, int first_block, int last_block,
634  ECAT7_imageheader *h, float **fdata);
635 extern int ecat7Read2DScanMatrix(FILE *fp, int first_block, int last_block,
636  ECAT7_2Dscanheader *h, float **fdata);
637 extern int ecat7ReadScanMatrix(FILE *fp, int first_block, int last_block,
638  ECAT7_scanheader *h, float **fdata);
639 extern int ecat7ReadPolarmapMatrix(FILE *fp, int first_block, int last_block,
640  ECAT7_polmapheader *h, float **fdata);
641 extern int ecat7pxlbytes(short int data_type);
642 /*****************************************************************************/
643 /* Matrix list functions */
644 extern void ecat7InitMatlist(ECAT7_MATRIXLIST *mlist);
645 extern void ecat7EmptyMatlist(ECAT7_MATRIXLIST *mlist);
646 extern int ecat7ReadMatlist(FILE *fp, ECAT7_MATRIXLIST *ml);
647 extern void ecat7PrintMatlist(ECAT7_MATRIXLIST *ml);
648 extern int ecat7EnterMatrix(FILE *fp, int matrix_id, int block_nr);
649 extern int ecat7_val_to_id(int frame, int plane, int gate, int data, int bed);
650 extern void ecat7_id_to_val(int matrix_id, ECAT7_Matval *matval);
653 extern int ecat7CheckMatlist(ECAT7_MATRIXLIST *ml);
654 extern int ecat7DeleteLateFrames(ECAT7_MATRIXLIST *ml, int frame_nr);
656  int *plane_nr, int *frame_nr);
657 extern int ecat7GetMatrixBlockSize(ECAT7_MATRIXLIST *mlist, int *blk_nr);
658 extern int ecat7GetNums(ECAT7_MATRIXLIST *ml, ECAT7_mainheader *mh, FILE *fp,
659  short int *num_planes, short int *num_frames, short int *num_gates,
660  short int *num_bed_pos);
661 extern int ecat7GatherMatlist(ECAT7_MATRIXLIST *ml, short int do_planes,
662  short int do_frames, short int do_gates, short int do_beds);
663 /*****************************************************************************/
664 /* Write functions */
665 extern int ecat7WriteMainheader(FILE *fp, ECAT7_mainheader *h);
666 extern int ecat7WriteImageheader(FILE *fp, int blk, ECAT7_imageheader *h);
667 extern int ecat7WriteAttenheader(FILE *fp, int blk, ECAT7_attenheader *h);
668 extern int ecat7WritePolmapheader(FILE *fp, int blk, ECAT7_polmapheader *h);
669 extern int ecat7WriteNormheader(FILE *fp, int blk, ECAT7_normheader *h);
670 extern int ecat7WriteScanheader(FILE *fp, int blk, ECAT7_scanheader *h);
671 extern int ecat7Write2DScanheader(FILE *fp, int blk, ECAT7_2Dscanheader *h);
672 extern int ecat7Write2DNormheader(FILE *fp, int blk, ECAT7_2Dnormheader *h);
673 extern int ecat7WritePolarmapMatrix(FILE *fp, int matrix_id,
674  ECAT7_polmapheader *h, float *fdata);
675 extern int ecat7WriteMatrixdata(FILE *fp, int start_block, char *data,
676  int pxl_nr, int pxl_size);
677 /*void ecat7wFloat(float *bufi, void *bufo, int tovax, int islittle);*/
678 /*void ecat7wInt(int *bufi, void *bufo, int tovax, int islittle);*/
679 extern FILE *ecat7Create(const char *fname, ECAT7_mainheader *h);
680 extern int ecat7WriteImageMatrix(FILE *fp, int matrix_id, ECAT7_imageheader *h,
681  float *fdata);
682 extern int ecat7Write2DScanMatrix(FILE *fp, int matrix_id, ECAT7_2Dscanheader *h,
683  float *fdata);
684 extern int ecat7WriteScanMatrix(FILE *fp, int matrix_id, ECAT7_scanheader *h,
685  float *fdata);
686 extern int ecat7_is_scaling_needed(float amax, float *data, int nr);
687 /*****************************************************************************/
688 /* Printing functions */
689 extern void ecat7PrintMainheader(ECAT7_mainheader *h, FILE *fp);
690 extern void ecat7PrintImageheader(ECAT7_imageheader *h, FILE *fp);
691 extern void ecat7PrintScanheader(ECAT7_scanheader *h, FILE *fp);
692 extern void ecat7PrintAttenheader(ECAT7_attenheader *h, FILE *fp);
693 extern void ecat7PrintPolmapheader(ECAT7_polmapheader *h, FILE *fp);
694 extern void ecat7PrintNormheader(ECAT7_normheader *h, FILE *fp);
695 extern void ecat7Print2DScanheader(ECAT7_2Dscanheader *h, FILE *fp);
696 extern void ecat7Print2DNormheader(ECAT7_2Dnormheader *h, FILE *fp);
697 extern int ecat7PrintSubheader(ECAT7_mainheader mh, FILE *fp,
698  int plane, int frame, FILE *ofp);
699 /* Descriptive strings for printing */
700 extern char* ecat7filetype(short int file_type);
701 extern char* ecat7acquisitiontype(short int acquisition_type);
702 extern char* ecat7datatype(short int data_type);
703 /*****************************************************************************/
704 /* Header edit functions */
705 extern int ecat7EditMHeader(ECAT7_mainheader *h, char *field, char *value);
706 extern int ecat7EditSHeader(ECAT7_scanheader *h, char *field, char *value);
707 extern int ecat7EditVHeader(ECAT7_imageheader *h, char *field, char *value);
708 /*****************************************************************************/
709 #endif
710