1 /* ----------------------------- MNI Header -----------------------------------
2 @NAME : test_fix_dicom_coords.c
3 @INPUT : argc, argv - name of one dicom stream file to read and fix
4 @OUTPUT : Prints new (0x20, 0x32) and (0x20, 0x37) and (0x20, 0x1041)
5 values
6 @DESCRIPTION: Test program for fix_dicom_coords function.
7 @CREATED : April 9, 2001 (Peter Neelin)
8 @MODIFIED :
9 ---------------------------------------------------------------------------- */
10
11 #ifndef public
12 # define public
13 # define private static
14 #endif
15
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
19 #include <acr_nema.h>
20
21 /* Dicom definitions */
22 DEFINE_ELEMENT(static, ACR_Image_Number , 0x0020, 0x0013, IS);
23 DEFINE_ELEMENT(static, SPI_Field_of_view , 0x0019, 0x1000, DS);
24 DEFINE_ELEMENT(static, SPI_Angulation_of_cc_axis , 0x0019, 0x1005, DS);
25 DEFINE_ELEMENT(static, SPI_Angulation_of_ap_axis , 0x0019, 0x1006, DS);
26 DEFINE_ELEMENT(static, SPI_Angulation_of_lr_axis , 0x0019, 0x1007, DS);
27 DEFINE_ELEMENT(static, SPI_Slice_orientation , 0x0019, 0x100a, DS);
28 DEFINE_ELEMENT(static, SPI_Off_center_lr , 0x0019, 0x100b, DS);
29 DEFINE_ELEMENT(static, SPI_Off_center_cc , 0x0019, 0x100c, DS);
30 DEFINE_ELEMENT(static, SPI_Off_center_ap , 0x0019, 0x100d, DS);
31
32 /* Function prototypes */
33 void calculate_dicom_coords(int orientation,
34 double angulation_lr, double angulation_ap,
35 double angulation_cc,
36 double off_centre_lr, double off_centre_ap,
37 double off_centre_cc,
38 double field_of_view,
39 double position[],
40 double row_dircos[], double col_dircos[],
41 double *location);
42 int convert_modified_imagenum(char *string);
43
44
45 /* MAIN PROGRAM */
main(int argc,char * argv[])46 int main(int argc, char *argv[])
47 {
48 char *filename, *pname;
49 FILE *fp;
50 Acr_File *afp;
51 Acr_Group group_list;
52 double position[3], row_dircos[3], col_dircos[3], location;
53 double angulation_lr, angulation_ap, angulation_cc;
54 double off_centre_lr, off_centre_ap, off_centre_cc;
55 double field_of_view;
56 int orientation;
57 char imagenum[128];
58 Acr_Status status;
59
60 /* Check arguments */
61 pname = argv[0];
62 if (argc != 2) {
63 (void) fprintf(stderr, "Usage: %s <filename>\n", pname);
64 return EXIT_FAILURE;
65 }
66 filename = argv[1];
67
68 /* Open input file */
69 if ((filename != NULL) && (strcmp(filename,"-") != 0)) {
70 fp = fopen(filename, "r");
71 if (fp == NULL) {
72 (void) fprintf(stderr, "%s: Error opening file %s\n",
73 pname, filename);
74 exit(EXIT_FAILURE);
75 }
76 }
77 else {
78 fp = stdin;
79 }
80
81 /* Connect to input stream */
82 afp=acr_file_initialize(fp, 0, acr_stdio_read);
83 (void) acr_test_dicom_file(afp);
84
85 /* Read in group list up to group */
86 status = acr_input_group_list(afp, &group_list, ACR_Image_Number->group_id);
87 if (status != ACR_OK) {
88 (void) fprintf(stderr, "Error reading input: %s\n",
89 acr_status_string(status));
90 exit(EXIT_FAILURE);
91 }
92
93 /* Free the afp and close the input */
94 acr_file_free(afp);
95 (void) fclose(fp);
96
97 /* Get the important numbers */
98 orientation = acr_find_int(group_list, SPI_Slice_orientation, 0);
99 angulation_lr = acr_find_double(group_list, SPI_Angulation_of_lr_axis, 0.0);
100 angulation_ap = acr_find_double(group_list, SPI_Angulation_of_ap_axis, 0.0);
101 angulation_cc = acr_find_double(group_list, SPI_Angulation_of_cc_axis, 0.0);
102 off_centre_lr = acr_find_double(group_list, SPI_Off_center_lr, 0.0);
103 off_centre_ap = acr_find_double(group_list, SPI_Off_center_ap, 0.0);
104 off_centre_cc = acr_find_double(group_list, SPI_Off_center_cc, 0.0);
105 field_of_view = acr_find_double(group_list, SPI_Field_of_view, 0.0);
106
107 /* Fix the values */
108 calculate_dicom_coords(orientation,
109 angulation_lr, angulation_ap, angulation_cc,
110 off_centre_lr, off_centre_ap, off_centre_cc,
111 field_of_view,
112 position, row_dircos, col_dircos, &location);
113
114 /* Print the results */
115 (void) printf("%.8g\\%.8g\\%.8g\t%.8g\\%.8g\\%.8g\\%.8g\\%.8g\\%.8g\t%.8g\n",
116 position[0], position[1], position[2],
117 row_dircos[0], row_dircos[1], row_dircos[2],
118 col_dircos[0], col_dircos[1], col_dircos[2],
119 location);
120
121 /* Fix the image num string */
122 (void) strcpy(imagenum, acr_find_string(group_list, ACR_Image_Number, ""));
123 (void) convert_modified_imagenum(imagenum);
124 (void) printf("\"%s\"\n", imagenum);
125
126 return EXIT_SUCCESS;
127 }
128