1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * filename: m-structs.h                                                   *
3  *                                                                         *
4  * UTIL C-source: Medical Image Conversion Utility                         *
5  *                                                                         *
6  * purpose      : m-structs.c header file                                  *
7  *                                                                         *
8  * project      : (X)MedCon by Erik Nolf                                   *
9  *                                                                         *
10  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
11 /*
12  */
13 
14 /*
15    Copyright (C) 1997-2021 by Erik Nolf
16 
17    This program is free software; you can redistribute it and/or modify it
18    under the terms of the GNU General Public License as published by the
19    Free Software Foundation; either version 2, or (at your option) any later
20    version.
21 
22    This program is distributed in the hope that it will be useful, but
23    WITHOUT ANY WARRANTY; without even the implied warranty of
24    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
25    Public License for more details.
26 
27    You should have received a copy of the GNU General Public License along
28    with this program; if not, write to the Free Software Foundation, Inc.,
29    59 Place - Suite 330, Boston, MA 02111-1307, USA.  */
30 
31 #ifndef __M_STRUCTS_H__
32 #define __M_STRUCTS_H__
33 
34 /****************************************************************************
35                               D E F I N E S
36 *****************************************************************************/
37 
38 #define MDC_MAX_DIMS    8                   /* maximum number of dimensions */
39 
40 /* generic  info GN */
41 typedef struct General_Info_t {
42 
43         char study_date[MDC_MAXSTR];
44         char study_time[MDC_MAXSTR];
45         char series_date[MDC_MAXSTR];
46         char series_time[MDC_MAXSTR];
47         char acquisition_date[MDC_MAXSTR];
48         char acquisition_time[MDC_MAXSTR];
49         char image_date[MDC_MAXSTR];
50         char image_time[MDC_MAXSTR];
51 
52 } GN_INFO;
53 
54 /* specific info XA modality */
55 typedef struct Mod_XA_Info_t  {
56 
57   /* Image identification characteristics                  */
58   char ImageType[MDC_MAXSTR];               /* (0008,0008) */
59 
60   /* Number of samples (color planes) should be 1          */
61   Int16 Samples_Per_Pixel;                  /* (0028,0002) */
62 
63   /* Interpretation of pixel data should be MONOCROME2     */
64   char Photo_Interp[MDC_MAXSTR];            /* (0028,0004) */
65 
66   /* Frame Incr Pointer (0018,1063) Time (0018,1065) Vect  */
67   char Frame_Increment_Pointer[MDC_MAXSTR]; /* (0028,0009) */
68 
69   /* Relationship between pixel sample & X-ray intensity   */
70   char Pixel_Intensity_Rel[MDC_MAXSTR];    /* (0028,1040)  */
71   /* */
72   /* kvp Peak kilo voltage output of X-Ray generator used  */
73   char kvp[MDC_MAXSTR];                    /* (0018,0060)  */
74 
75   /* Radiation Setting                                     */
76   char Radiation_Setting[MDC_MAXSTR];      /* (0018,1155)  */
77 
78 } XA_INFO;
79 
80 /* specific info MR modality */
81 typedef struct Mod_MR_Info_t  {
82 
83   double repetition_time;
84   double echo_time;
85   double inversion_time;
86   double num_averages;
87   double imaging_freq;
88   double pixel_bandwidth;
89   double flip_angle;
90   double dbdt;
91   Uint32 transducer_freq;
92   char transducer_type[MDC_MAXSTR];
93   Uint32 pulse_repetition_freq;
94   char pulse_seq_name[MDC_MAXSTR];
95   char steady_state_pulse_seq[MDC_MAXSTR];
96   double slab_thickness;
97   double sampling_freq;
98 
99 } MR_INFO;
100 
101 typedef struct Modality_Info_t {
102 
103   GN_INFO gn_info;
104 /*XA_INFO xa_info;*/
105   MR_INFO mr_info;
106 
107 } MOD_INFO;
108 
109 /* static related data */
110 typedef struct Static_Data_t {
111 
112   char  label[MDC_MAXSTR];       /* label name of image    */ /* Ant/Post */
113   float total_counts;            /* total counts in image  */
114   float image_duration;          /* duration of image (ms) */
115   Int16 start_time_hour;         /* start time hour        */
116   Int16 start_time_minute;       /* start time minute      */
117   Int16 start_time_second;       /* start time second      */
118 
119 } STATIC_DATA;
120 
121 /* gated SPECT related data */
122 typedef struct Gated_Data_t {
123 
124   Int8  gspect_nesting;          /* gated spect nesting    */
125   float nr_projections;          /* number of projections  */
126   float extent_rotation;         /* extent of rotation     */
127   float study_duration;          /* study duration (ms)    */
128   float image_duration;          /* image duration (ms)    */
129   float time_per_proj;           /* time per proj  (ms)    */
130   float window_low;              /* lower  limit   (ms)    */
131   float window_high;             /* higher limit   (ms)    */
132   float cycles_observed;         /* cardiac cycles observed*/
133   float cycles_acquired;         /* cardiac cycles acquired*/
134 
135 } GATED_DATA;
136 
137 /* acquisition data */
138 typedef struct Acquisition_Data_t {
139 
140   Int16 rotation_direction;      /* direction of rotation  */
141   Int16 detector_motion;         /* type detector motion   */
142   float rotation_offset;         /* centre rotation offset */
143   float radial_position;         /* radial position        */
144   float angle_start;             /* start angle (interfile)*/ /* 180 - dicom */
145   float angle_step;              /* angular step           */
146   float scan_arc;                /* angular range          */
147 
148 } ACQ_DATA;
149 
150 /* dynamic data */
151 typedef struct Dynamic_Data_t {
152 
153   Uint32 nr_of_slices;           /* images in time frame   */
154   float time_frame_start;        /* start time frame (ms)  */
155   float time_frame_delay;        /* delay this frame (ms)  */
156   float time_frame_duration;     /* duration   frame (ms)  */
157   float delay_slices;            /* delay each slice (ms)  */
158 
159 } DYNAMIC_DATA;
160 
161 /* bed data */
162 typedef struct Bed_Data_t {
163 
164   float hoffset;                 /* horizon. position (mm) */
165   float voffset;                 /* vertical position (mm) */
166 
167 } BED_DATA;
168 
169 /* images related data */
170 typedef struct Image_Data_t {
171 
172   /*             **   general data   **                    */
173   Uint32 width,height;           /* image dimension        */
174   Int16 bits,type;               /* bits/pixel & datatype  */
175   Uint16 flags;                  /* extra flag             */
176   double min, max;               /* min/max pixelvalue     */
177   double qmin, qmax;             /* quantified min/max     */
178   double fmin, fmax;             /* min/max in whole frame */
179   double qfmin, qfmax;           /* in whole frame (quant) */
180   float rescale_slope;           /* rescale slope          */ /* auto filled */
181   float rescale_intercept;       /* rescale intercept      */ /* auto filled */
182   Uint32 frame_number;           /* part of frame (1-based)*/ /* auto filled */
183   float slice_start;             /* start    of slice (ms) */ /* auto filled */
184   Uint8 *buf;                    /* pointer to raw image   */
185   size_t load_location;          /* load start in file     */
186 
187   /*             **  internal items  **                    */
188   Int8   rescaled;               /* rescaled image?        */
189   double rescaled_min;           /* new rescaled max       */
190   double rescaled_max;           /* new rescaled min       */
191   double rescaled_fctr;          /* new rescaled fctr      */
192   double rescaled_slope;         /* new rescaled slope     */
193   double rescaled_intercept;     /* new rescaled intercept */
194 
195   /*             **   ecat64 items   **                    */
196   Int16 quant_units;             /* quantification units   */
197   Int16 calibr_units;            /* calibration units      */
198   float quant_scale;             /* quantification scale   */
199   float calibr_fctr;             /* calibration factor     */
200   float intercept;               /* scale intercept        */
201   float pixel_xsize;             /* pixel size X      (mm) */
202   float pixel_ysize;             /* pixel size Y      (mm) */
203   float slice_width;             /* slice width       (mm) */
204   float recon_scale;             /* recon magnification    */
205 
206   /*            **  Acr/Nema items   **                    */
207 
208   float image_pos_dev[3];        /* image posit  dev  (mm) */
209   float image_orient_dev[6];     /* image orient dev  (mm) */
210   float image_pos_pat[3];        /* image posit  pat  (mm) */
211   float image_orient_pat[6];     /* image orient pat  (mm) */
212   float slice_spacing;           /* space btw centres (mm) */
213   float ct_zoom_fctr;            /* CT image zoom factor   */
214 
215   /*            **  Miscellaneous    **                    */
216 
217   STATIC_DATA *sdata;            /* extra static entries   */ /* just one */
218 
219   unsigned char *plugb;          /* like to attach here?   */
220 
221 } IMG_DATA;
222 
223 /* the file information struct */
224 typedef struct File_Info_t {
225 
226   FILE *ifp;                     /* pointer to input file  */
227   FILE *ifp_raw;                 /* pointer to raw input   */
228   FILE *ofp;                     /* pointer to output file */
229   FILE *ofp_raw;                 /* pointer to raw output  */
230   char ipath[MDC_MAX_PATH+1];    /* path to input  file    */
231   char opath[MDC_MAX_PATH+1];    /* path to output file    */
232   char *idir;                    /* dir to input  file     */
233   char *odir;                    /* dir to output file     */
234   char *ifname;                  /* name of input file     */
235   char *ofname;                  /* name of output file    */
236   int  iformat;                  /* format of  input file  */
237   int  oformat;                  /* format of output file  */
238   int  modality;                 /* modality               */
239   Int8 rawconv;                  /* FRMT_RAW | FRMT_ASCII  */
240   Int8 endian;                   /* endian of file         */
241   Int8 compression;              /* file compression       */
242   Int8 truncated;                /* truncated file?        */
243   Int8 diff_type;                /* images with diff type? */
244   Int8 diff_size;                /* images with diff size? */
245   Int8 diff_scale;               /* images with diff scale?*/
246   Uint32 number;                 /* total number of images */  /* private */
247   Uint32 mwidth,mheight;         /* global max dimensions  */
248   Int16 bits, type;              /* global bits & datatype */
249   Int16 dim[MDC_MAX_DIMS];       /* [0] = # of dimensions  */
250                                  /* [1] = X-dim (pixels)   */
251                                  /* [2] = Y-dim (pixels)   */
252                                  /* [3] = Z-dim (planes)   */
253                                  /* [4] =       (frames)   */
254                                  /* [5] =       (gates)    */
255                                  /* [6] =       (beds)     */
256                                  /* ...                    */
257                                  /* values must be 1-based */
258 
259   float pixdim[MDC_MAX_DIMS];    /* [0] = # of dimensions  */
260                                  /* [1] = X-dim (mm)       */
261                                  /* [2] = Y-dim (mm)       */
262                                  /* [3] = Z-dim (mm)       */
263                                  /* [4] = time  (ms)       */
264                                  /* ...                    */
265 
266   double glmin, glmax;           /* global min/max value   */
267   double qglmin, qglmax;         /* quantified min/max     */
268 
269   Int8  contrast_remapped;       /* contrast remap applied */
270   float window_centre;           /* contrast window centre */
271   float window_width;            /* contrast window width  */
272 
273   Int8 slice_projection;         /* projection of images   */
274   Int8 pat_slice_orient;         /* combined flag          */
275   char pat_pos[MDC_MAXSTR];      /* patient position       */
276   char pat_orient[MDC_MAXSTR];   /* patient orientation    */
277   char  patient_sex[MDC_MAXSTR]; /* sex of patient         */
278   char  patient_name[MDC_MAXSTR];/* name of patient        */
279   char  patient_id[MDC_MAXSTR];  /* id   of patient        */
280   char  patient_dob[MDC_MAXSTR]; /* birth of patient       */ /* YYYYMMDD */
281   float patient_weight;          /* weight of patient (kg) */
282   float patient_height;          /* height of patient (m)  */
283   char operator_name[MDC_MAXSTR];/* name of scan operator  */
284   char study_descr[MDC_MAXSTR];  /* study description      */
285   char study_id[MDC_MAXSTR];     /* study id               */
286   Int16 study_date_day;          /* day of study   (1-31)  */
287   Int16 study_date_month;        /* month of study (1-12)  */
288   Int16 study_date_year;         /* year of study          */
289   Int16 study_time_hour;         /* hour of study          */
290   Int16 study_time_minute;       /* minute of study        */
291   Int16 study_time_second;       /* second of study        */
292   Int16 dose_time_hour;          /* hour   of dose start   */
293   Int16 dose_time_minute;        /* minute of dose start   */
294   Int16 dose_time_second;        /* second of dose start   */
295   Int32 nr_series;               /* series number          */
296   Int32 nr_acquisition;          /* acquisition number     */
297   Int32 nr_instance;             /* instance number        */
298   Int16 acquisition_type;        /* acquisition type       */
299   Int16 planar;                  /* planar or tomo  ?      */
300   Int16 decay_corrected;         /* decay corrected ?      */
301   Int16 flood_corrected;         /* flood corrected ?      */
302 
303   Int16 reconstructed;           /* reconstructed ?        */
304   char recon_method[MDC_MAXSTR]; /* reconstruction method  */
305 
306   char institution[MDC_MAXSTR];  /* name of institution    */
307   char manufacturer[MDC_MAXSTR]; /* name of manufacturer   */
308   char series_descr[MDC_MAXSTR]; /* series description     */
309   char radiopharma[MDC_MAXSTR];  /* radiopharmaceutical    */
310   char filter_type[MDC_MAXSTR];  /* filter type            */
311   char organ_code[MDC_MAXSTR];   /* organ                  */
312   char isotope_code[MDC_MAXSTR]; /* isotope                */
313   float isotope_halflife;        /* isotope halflife (sec) */
314   float injected_dose;           /* amount injected  (MBq) */
315   float gantry_tilt;             /* gantry tilt            */
316 
317   Uint8 map;                     /* indexed 256 colormap   */
318   Uint8 palette[768];            /* global palette         */
319   char *comment;                 /* whatever comment       */
320   Uint32 comm_length;            /* length of comment      */
321 
322   Uint32 gatednr;                /* number of gated entries*/ /* now 0 or 1 */
323   GATED_DATA *gdata;             /* array of GATED_DATA    */
324 
325   Uint32 acqnr;                  /* number acq. entries    */
326   ACQ_DATA *acqdata;             /* array ACQ_DATA entries */
327 
328   Uint32 dynnr;                  /* number of time frames  */
329   DYNAMIC_DATA *dyndata;         /* array of DYNAMIC_DATA  */
330 
331   Uint32 bednr;                  /* number bed positions   */
332   BED_DATA * beddata;            /* array of BED_DATA      */
333 
334   IMG_DATA *image;               /* array IMG_DATA images  */
335 
336   MOD_INFO *mod;                 /* modality related info  */
337 
338   unsigned char *pluga;          /* want to attach stuff?  */
339 
340 } FILEINFO;
341 
342 /****************************************************************************
343                             F U N C T I O N S
344 ****************************************************************************/
345 
346 char *MdcCheckFI(FILEINFO *fi);
347 int MdcGetStructMOD(FILEINFO *fi);
348 int MdcGetStructID(FILEINFO *fi, Uint32 number);
349 int MdcGetStructSD(FILEINFO *fi, Uint32 number);
350 int MdcGetStructGD(FILEINFO *fi, Uint32 number);
351 int MdcGetStructAD(FILEINFO *fi, Uint32 number);
352 int MdcGetStructDD(FILEINFO *fi, Uint32 number);
353 int MdcGetStructBD(FILEINFO *fi, Uint32 number);
354 void MdcInitMOD(MOD_INFO *mod);
355 void MdcInitID(IMG_DATA *id);
356 void MdcInitSD(STATIC_DATA *sd);
357 void MdcInitGD(GATED_DATA *gd);
358 void MdcInitAD(ACQ_DATA *acq);
359 void MdcInitDD(DYNAMIC_DATA *dd);
360 void MdcInitBD(BED_DATA *bd);
361 void MdcInitFI(FILEINFO *fi, const char *path);
362 char *MdcCopyMOD(MOD_INFO *mod, MOD_INFO *src);
363 char *MdcCopyID(IMG_DATA *dest, IMG_DATA *src, int COPY_IMAGE);
364 char *MdcCopySD(STATIC_DATA *dest, STATIC_DATA *src);
365 char *MdcCopyGD(GATED_DATA *dest, GATED_DATA *src);
366 char *MdcCopyAD(ACQ_DATA *dest, ACQ_DATA *src);
367 char *MdcCopyDD(DYNAMIC_DATA *dest, DYNAMIC_DATA *src);
368 char *MdcCopyBD(BED_DATA *dst, BED_DATA *src);
369 char *MdcCopyFI(FILEINFO *dest, FILEINFO *src, int COPY_IMAGES, int KEEP_FILES);
370 void MdcFreeMODs(FILEINFO *fi);
371 void MdcFreeIDs(FILEINFO *fi);
372 void MdcFreeODs(FILEINFO *fi);
373 void MdcResetIDs(FILEINFO *fi);
374 char *MdcResetODs(FILEINFO *fi);
375 void MdcCleanUpFI(FILEINFO *fi);
376 
377 #endif
378