TPCCLIB
Loading...
Searching...
No Matches
ehdrconv.c
Go to the documentation of this file.
1
7/*****************************************************************************/
8#include "tpcclibConfig.h"
9/*****************************************************************************/
10#include <stdio.h>
11#include <stdlib.h>
12#include <math.h>
13#include <string.h>
14#include <time.h>
15/*****************************************************************************/
16#include "libtpcmisc.h"
17#include "libtpcimgio.h"
18#include "ehdrconv.h"
19/*****************************************************************************/
20
21/*****************************************************************************/
26{
27 int i;
28
29 if(h1==NULL || h2==NULL) return(1);
30 memset(h2, 0, sizeof(ECAT7_mainheader));
32 h2->sw_version=72;
33 if(h1->system_type==12) h2->system_type=12096; /* for GE Advance in Turku */
34 else h2->system_type=h1->system_type;
35 switch(h1->file_type) {
36 case RAW_DATA:
38 strcpy(h2->magic_number, ECAT7S_MAGICNR);
39 break;
40 case IMAGE_DATA:
42 strcpy(h2->magic_number, ECAT7V_MAGICNR);
43 break;
44 case ATTN_DATA:
46 strcpy(h2->magic_number, ECAT7S_MAGICNR);
47 break;
48 case NORM_DATA:
50 strcpy(h2->magic_number, ECAT7S_MAGICNR);
51 break;
52 default: return(5);
53 }
54 strlcpy(h2->serial_number, h1->node_id, 10);
62 h2->intrinsic_tilt=15.0;
71 switch(h1->calibration_units) {
72 case 0: /* Unknown */
75 strcpy(h2->data_units, "");
76 break;
77 case 1: /* MBq/cc */
80 strcpy(h2->data_units, "MBq/cc");
81 break;
82 case 2: /* ECAT counts */
85 strcpy(h2->data_units, "ECAT counts/sec");
86 break;
87 case 3: /* uCi/cc */
90 strcpy(h2->data_units, "uCi/cc");
91 break;
92 case 4: /* LMRGlu */
93 case 5: /* LMRGlu umol/min/100g */
94 case 6: /* LMRGlu mg/min/100g */
97 strcpy(h2->data_units, "LMRGlu");
98 break;
99 case 7: /* nCi/cc */
100 h2->calibration_units=1;
102 strcpy(h2->data_units, "nCi/cc");
103 break;
104 case 8: /* Well counts */
105 case 9: /* Becquerels */
106 h2->calibration_units=1;
108 strcpy(h2->data_units, "Bq/cc");
109 break;
110 case 10: /* kBq/cc */
111 h2->calibration_units=1;
113 strcpy(h2->data_units, "kBq/cc");
114 break;
115 default:
116 h2->calibration_units=2;
118 strcpy(h2->data_units, "");
119 break;
120 }
122 strlcpy(h2->study_type, h1->study_name, 12);
123 strlcpy(h2->patient_id, h1->patient_id, 16);
124 strlcpy(h2->patient_name, h1->patient_name, 32);
125 h2->patient_sex=h1->patient_sex;
127 h2->patient_age=atof(h1->patient_age);
128 h2->patient_height=atof(h1->patient_height);
129 h2->patient_weight=atof(h1->patient_weight);
131 strlcpy(h2->operator_name, h1->operator_name, 32);
134 if(h2->acquisition_type==0 && h1->num_frames>1) h2->acquisition_type=4;
136 strlcpy(h2->facility_name, h1->facility_name, 20);
137 h2->num_planes=h1->num_planes; /* may need adjusting later */
138 h2->num_frames=h1->num_frames;
139 h2->num_gates=h1->num_gates;
140 h2->num_bed_pos=h1->num_bed_pos; if(h2->num_bed_pos>0) h2->num_bed_pos-=1;
142 for(i=0; i<15; i++) h2->bed_position[i]=h1->bed_offset[i];
148 h2->acquisition_mode=0;
149 h2->bin_size=0; /* this value must be read from scan subheader */
150 h2->branching_fraction=1.0;
152 h2->dosage=0.0;
154 h2->septa_state=h1->septa_type;
155 return(0);
156}
157/*****************************************************************************/
158
159/*****************************************************************************/
164{
165 if(h1==NULL || h2==NULL) return(1);
166 memset(h2, 0, sizeof(ECAT7_imageheader));
167 h2->data_type=h1->data_type;
168 h2->num_dimensions=3;
169 h2->x_dimension=h1->dimension_1;
170 h2->y_dimension=h1->dimension_2;
171 h2->z_dimension=1; /* Fill this later with plane number! */
172 h2->x_offset=h1->x_origin;
173 h2->y_offset=h1->y_origin;
174 h2->z_offset=0.0;
175 h2->recon_zoom=h1->recon_scale;
177 h2->image_min=h1->image_min;
178 h2->image_max=h1->image_max;
179 h2->x_pixel_size=h1->pixel_size;
180 h2->y_pixel_size=h1->pixel_size;
184 h2->filter_code=h1->filter_code;
185 h2->x_resolution=0.0;
186 h2->y_resolution=0.0;
187 h2->z_resolution=0.0;
188 h2->num_r_elements=0.0;
189 h2->num_angles=0.0;
193 h2->gate_duration=0;
194 h2->r_wave_offset=0;
195 h2->num_accepted_beats=0;
199 h2->filter_order=(short int)temp_roundf(h1->filter_params[3]);
202 strncpy(h2->annotation, h1->annotation, 40);
203 return(0);
204}
205/*****************************************************************************/
206
207/*****************************************************************************/
212{
213 if(h1==NULL || h2==NULL) return(1);
214 memset(h2, 0, sizeof(ECAT7_scanheader));
215 h2->data_type=h1->data_type;
216 h2->num_dimensions=4;
218 h2->num_angles=h1->dimension_2;
219 h2->corrections_applied=h1->processing_code; /* ??? */
220 h2->num_z_elements[0]=1; /* Fill these later with plane number(s) */
221 h2->ring_difference=0;
222 h2->storage_order=1; /* r, theta, z, d */
223 h2->axial_compression=0;
225 h2->v_resolution=0.0;
226 h2->z_resolution=0.0;
227 h2->w_resolution=0.0;
230 h2->num_accepted_beats=0;
232 h2->scan_min=h1->scan_min;
233 h2->scan_max=h1->scan_max;
234 h2->prompts=h1->prompts;
235 h2->delayed=h1->delayed;
236 h2->multiples=h1->multiples;
237 h2->net_trues=h1->net_trues;
238 h2->tot_avg_cor=h1->tot_avg_cor;
244 return(0);
245}
246/*****************************************************************************/
247
248/*****************************************************************************/
253{
254 if(h1==NULL || h2==NULL) return(1);
255 memset(h2, 0, sizeof(ECAT7_2Dnormheader));
256 h2->data_type=h1->data_type;
257 h2->num_dimensions=2;
259 h2->num_angles=h1->dimension_2;
260 h2->num_z_elements=1;
261 h2->ring_difference=0;
263 h2->norm_min=0.0;
264 h2->norm_max=0.0;
266 h2->norm_quality_factor=1.0;
268 h2->storage_order=1;
269 h2->span=0;
270 h2->z_elements[0]=1;
271 return(0);
272}
273/*****************************************************************************/
274
275/*****************************************************************************/
280{
281 struct tm scanStart;
282 time_t t;
283
284 //printf("ecatCopy7to63mainheader()\n");
285 if(h1==NULL || h2==NULL) return(1);
286 memset(h2, 0, sizeof(ECAT63_mainheader));
288 h2->sw_version=2;
289 h2->data_type=SUN_I2; /* fill later with better knowledge */
290 if(h1->system_type==12096) h2->system_type=12; /* for GE Advance in Turku */
291 else h2->system_type=h1->system_type;
292 h2->system_type=h1->system_type;
293 switch(h1->file_type) {
294 case ECAT7_2DSCAN: h2->file_type=RAW_DATA; break;
295 case ECAT7_IMAGE16: h2->file_type=IMAGE_DATA; break;
296 case ECAT7_ATTEN: h2->file_type=ATTN_DATA; break;
297 case ECAT7_2DNORM: h2->file_type=NORM_DATA; break;
298 case ECAT7_VOLUME8: h2->file_type=IMAGE_DATA; break;
299 case ECAT7_VOLUME16: h2->file_type=IMAGE_DATA; break;
300 case ECAT7_IMAGE8: h2->file_type=IMAGE_DATA; break;
301 case ECAT7_3DSCAN: h2->file_type=RAW_DATA; break;
302 case ECAT7_3DSCANFIT: h2->file_type=RAW_DATA; break;
303 case ECAT7_3DSCAN8: h2->file_type=RAW_DATA; break;
304 default: return(5);
305 }
306 strlcpy(h2->node_id, h1->serial_number, 10);
307 t=h1->scan_start_time;
308 if(gmtime_r(&t, &scanStart)!=NULL) {
309 h2->scan_start_year=scanStart.tm_year+1900;
310 h2->scan_start_month=scanStart.tm_mon+1;
311 h2->scan_start_day=scanStart.tm_mday;
312 h2->scan_start_hour=scanStart.tm_hour;
313 h2->scan_start_minute=scanStart.tm_min;
314 h2->scan_start_second=scanStart.tm_sec;
315 } else {
316 h2->scan_start_year=1900;
317 h2->scan_start_month=1;
318 h2->scan_start_day=1;
319 h2->scan_start_hour=0;
320 h2->scan_start_minute=0;
321 h2->scan_start_second=0;
322 }
323 strlcpy(h2->isotope_code, h1->isotope_name, 8);
326 h2->gantry_tilt=h1->gantry_tilt;
329 h2->rot_source_speed=0;
338 if(h1->calibration_units==0) {
339 h2->calibration_units=2;
340 } else if(h1->calibration_units==1) {
341 if(h1->calibration_units_label==0)
342 h2->calibration_units=9;
343 else if(strcasecmp(h1->data_units, "MBq/cc")==0)
344 h2->calibration_units=1;
345 else if(strcasecmp(h1->data_units, "MBq/mL")==0)
346 h2->calibration_units=1;
347 else if(strcasecmp(h1->data_units, "uCi/cc")==0)
348 h2->calibration_units=3;
349 else if(strcasecmp(h1->data_units, "uCi/mL")==0)
350 h2->calibration_units=3;
351 else if(strcasecmp(h1->data_units, "nCi/cc")==0)
352 h2->calibration_units=7;
353 else if(strcasecmp(h1->data_units, "Bq/cc")==0)
354 h2->calibration_units=9;
355 else if(strcasecmp(h1->data_units, "Bq/mL")==0)
356 h2->calibration_units=9;
357 else if(strcasecmp(h1->data_units, "kBq/cc")==0)
358 h2->calibration_units=10;
359 else if(strcasecmp(h1->data_units, "kBq/mL")==0)
360 h2->calibration_units=10;
361 else
362 h2->calibration_units=0;
363 } else {
364 h2->calibration_units=0;
365 }
367 strlcpy(h2->study_name, h1->study_type, 12);
368 strlcpy(h2->patient_id, h1->patient_id, 16);
369 strlcpy(h2->patient_name, h1->patient_name, 32);
370 h2->patient_sex=h1->patient_sex;
371 sprintf(h2->patient_age, "%-9.2f", h1->patient_age);
372 sprintf(h2->patient_height, "%-9.3f", h1->patient_height);
373 sprintf(h2->patient_weight, "%-9.3f", h1->patient_weight);
376 strlcpy(h2->operator_name, h1->operator_name, 32);
379 if(h2->acquisition_type==0 && h1->num_frames>1) h2->acquisition_type=4;
380 h2->bed_type=0;
381 h2->septa_type=h1->septa_state;
382 strlcpy(h2->facility_name, h1->facility_name, 20);
383 h2->num_planes=h1->num_planes; /* may need adjusting later */
384 h2->num_frames=h1->num_frames;
385 h2->num_gates=h1->num_gates;
386 h2->num_bed_pos=h1->num_bed_pos+1;
388 for(int i=0; i<15; i++) h2->bed_offset[i]=h1->bed_position[i];
393 h2->collimator=0;
394
396 return(0);
397}
398/*****************************************************************************/
399
400/*****************************************************************************/
405{
406 if(h1==NULL || h2==NULL) return(1);
407 memset(h2, 0, sizeof(ECAT63_imageheader));
408 h2->data_type=h1->data_type;
410 h2->dimension_1=h1->x_dimension;
411 h2->dimension_2=h1->y_dimension;
412 h2->x_origin=h1->x_offset;
413 h2->y_origin=h1->y_offset;
414 h2->recon_scale=h1->recon_zoom;
416 h2->image_min=h1->image_min;
417 h2->image_max=h1->image_max;
418 h2->pixel_size=h1->x_pixel_size;
422 h2->slice_location=h1->z_offset;
423 h2->recon_start_hour=0;
424 h2->recon_start_min=0;
425 h2->recon_start_sec=0;
426 h2->recon_duration=0;
427 h2->filter_code=h1->filter_code;
428 h2->scan_matrix_num=0;
429 h2->norm_matrix_num=0;
430 h2->atten_cor_mat_num=0;
432 h2->plane_eff_corr_fctr=1.0;
434 h2->loss_corr_fctr=1.0;
435 h2->processing_code=(short int)h1->processing_code;
436 h2->quant_units=0;
437 h2->recon_start_day=0;
438 h2->recon_start_month=0;
439 h2->recon_start_year=0;
440 h2->ecat_calibration_fctr=1.0;
441 h2->well_counter_cal_fctr=1.0;
445 h2->filter_params[3]=(float)h1->filter_order;
448 strncpy(h2->annotation, h1->annotation, 40);
449 return(0);
450}
451/*****************************************************************************/
452
453/*****************************************************************************/
458{
459 if(h1==NULL || h2==NULL) return(1);
460 memset(h2, 0, sizeof(ECAT63_scanheader));
461 h2->data_type=h1->data_type;
463 h2->dimension_2=h1->num_angles;
464 h2->smoothing=0;
465 h2->processing_code=h1->corrections_applied; /* ??? */
466 h2->sample_distance=0.0; /* this must be set from main header bin_size */
467 h2->isotope_halflife=0.0; /* fill this from main header */
468 h2->frame_duration_sec=(short int)(h1->frame_duration/1000);
472 h2->scan_min=h1->scan_min;
473 h2->scan_max=h1->scan_max;
474 h2->prompts=h1->prompts;
475 h2->delayed=h1->delayed;
476 h2->multiples=h1->multiples;
477 h2->net_trues=h1->net_trues;
478 h2->tot_avg_cor=h1->tot_avg_cor;
484 return(0);
485}
486/*****************************************************************************/
487
488/*****************************************************************************/
493{
494 if(h1==NULL || h2==NULL) return(1);
495 memset(h2, 0, sizeof(ECAT63_scanheader));
496 h2->data_type=h1->data_type;
498 h2->dimension_2=h1->num_angles;
499 h2->smoothing=0;
500 h2->processing_code=h1->corrections_applied; /* ??? */
501 /* this may need to be set from main header bin_size */
503 h2->isotope_halflife=0.0; /* fill this from main header */
504 h2->frame_duration_sec=(short int)(h1->frame_duration/1000);
508 h2->scan_min=h1->scan_min;
509 h2->scan_max=h1->scan_max;
510 h2->prompts=h1->prompts;
511 h2->delayed=h1->delayed;
512 h2->multiples=h1->multiples;
513 h2->net_trues=h1->net_trues;
514 h2->tot_avg_cor=h1->tot_avg_cor;
520 return(0);
521}
522/*****************************************************************************/
523
524/*****************************************************************************/
525
struct tm * gmtime_r(const time_t *t, struct tm *tm)
Convert time_t to GMT struct tm.
Definition datetime.c:22
time_t ecat63Scanstarttime(const ECAT63_mainheader *h)
Get calendar time from ECAT 6.3 main header.
Definition ecat63w.c:925
int ecatCopy7_2D_to63scanheader(ECAT7_2Dscanheader *h1, ECAT63_scanheader *h2)
Definition ehdrconv.c:492
int ecatCopy7to63scanheader(ECAT7_scanheader *h1, ECAT63_scanheader *h2)
Definition ehdrconv.c:457
int ecatCopy63to7imageheader(ECAT63_imageheader *h1, ECAT7_imageheader *h2)
Definition ehdrconv.c:163
int ecatCopy63to7normheader(ECAT63_normheader *h1, ECAT7_2Dnormheader *h2)
Definition ehdrconv.c:252
int ecatCopy63to7mainheader(ECAT63_mainheader *h1, ECAT7_mainheader *h2)
Definition ehdrconv.c:25
int ecatCopy7to63imageheader(ECAT7_imageheader *h1, ECAT63_imageheader *h2)
Definition ehdrconv.c:404
int ecatCopy7to63mainheader(ECAT7_mainheader *h1, ECAT63_mainheader *h2)
Definition ehdrconv.c:279
int ecatCopy63to7scanheader(ECAT63_scanheader *h1, ECAT7_scanheader *h2)
Definition ehdrconv.c:211
Header file for ehdrconv.c.
Header file for libtpcimgio.
#define ECAT7_VOLUME8
#define ATTN_DATA
#define ECAT7_ATTEN
#define ECAT7_3DSCAN
#define ECAT7_3DSCAN8
#define ECAT7_IMAGE16
#define ECAT7_3DSCANFIT
#define ECAT7_VOLUME16
#define RAW_DATA
#define ECAT7_IMAGE8
#define ECAT7_Head_First_Supine
#define NORM_DATA
#define IMAGE_DATA
#define ECAT7_2DNORM
#define SUN_I2
#define ECAT7_2DSCAN
Header file for libtpcmisc.
size_t strlcpy(char *dst, const char *src, size_t dstsize)
Definition strext.c:245
int temp_roundf(float e)
Definition petc99.c:20
short int recon_start_month
short int recon_start_day
short int slice_location
short int processing_code
short int recon_start_min
short int recon_start_year
short int num_dimensions
short int recon_start_hour
short int recon_start_sec
char radiopharmaceutical[32]
short int scan_start_month
short int coin_samp_mode
short int lwr_true_thres
short int compression_code
char patient_height[10]
short int wobble_speed
short int scan_start_second
short int num_bed_pos
short int transaxial_samp_mode
short int rot_source_speed
short int acquisition_type
short int calibration_units
short int scan_start_year
char original_file_name[20]
char study_description[32]
short int scan_start_day
short int transm_source_type
short int scan_start_minute
char user_process_code[10]
char patient_weight[10]
short int lwr_sctr_thres
short int axial_samp_mode
short int scan_start_hour
short int upr_true_thres
char physician_name[32]
short int system_type
short int dimension_1
short int dimension_2
short int dimension_2
short int processing_code
short int dimension_1
short int frame_duration_sec
short int z_elements[64]
short int num_dimensions
short int ring_difference
short int storage_order
short int num_z_elements
short int norm_quality_factor_code
short int num_r_elements
short int corrections_applied
float deadtime_correction_factor
short int num_r_elements
float filter_scatter_fraction
short int filter_code
short int image_max
short int image_min
float filter_cutoff_frequency
short int filter_order
short int y_dimension
short int z_dimension
short int num_dimensions
short int x_dimension
short int data_type
short int file_type
short int compression_code
float bed_position[15]
short int system_type
char facility_name[20]
short int num_frames
char operator_name[32]
short int coin_samp_mode
char data_units[32]
char magic_number[14]
float well_counter_corr_factor
char study_type[12]
char user_process_code[10]
short int angular_compression
short int calibration_units
char patient_name[32]
short int septa_state
short int num_gates
short int num_planes
short int lwr_true_thres
char physician_name[32]
short int wobble_speed
short int acquisition_mode
short int calibration_units_label
char serial_number[10]
short int num_bed_pos
float ecat_calibration_factor
short int sw_version
short int transm_source_type
short int acquisition_type
char study_description[32]
short int axial_samp_mode
char patient_id[16]
char radiopharmaceutical[32]
short int patient_orientation
short int upr_true_thres
short int lwr_sctr_thres
char original_file_name[32]
short int scan_min
short int num_r_elements
short int num_angles
short int data_type
float deadtime_correction_factor
short int num_dimensions
short int axial_compression
short int storage_order
short int scan_max
short int num_z_elements[64]
short int ring_difference
short int corrections_applied