1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * filename: m-anlz.h                                                      *
3  *                                                                         *
4  * UTIL C-source: Medical Image Conversion Utility                         *
5  *                                                                         *
6  * purpose      : m-anlz.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_ANLZ_H__
32 #define __M_ANLZ_H__
33 
34 /****************************************************************************
35                               D E F I N E S
36 ****************************************************************************/
37 
38 #define MDC_ANLZ_SIG   'r'
39 
40 #define MDC_ANLZ_MAX_DIMS             8  /* maximum number of dimensions */
41 
42 /* datatypes */
43 #define MDC_ANLZ_DT_UNKNOWN           0
44 #define MDC_ANLZ_DT_BINARY            1  /* 1-bit     */
45 #define MDC_ANLZ_DT_UNSIGNED_CHAR     2  /* Uint8     */
46 #define MDC_ANLZ_DT_SIGNED_SHORT      4  /* Int16     */
47 #define MDC_ANLZ_DT_SIGNED_INT        8  /* Int32     */
48 #define MDC_ANLZ_DT_FLOAT            16  /* float     */
49 #define MDC_ANLZ_DT_COMPLEX          32  /* 2 x float */ /* unsupported */
50 #define MDC_ANLZ_DT_DOUBLE           64  /* double    */
51 #define MDC_ANLZ_DT_RGB             128  /* 3 x Uint8 */ /* unsupported */
52 #define MDC_ANLZ_DT_ALL             255  /* All       */ /* unsupported */
53 
54 /* orient types */
55 #define MDC_ANLZ_TRANS_UNFLIPPED      0
56 #define MDC_ANLZ_CORON_UNFLIPPED      1
57 #define MDC_ANLZ_SAGIT_UNFLIPPED      2
58 #define MDC_ANLZ_TRANS_FLIPPED        3
59 #define MDC_ANLZ_CORON_FLIPPED        4
60 #define MDC_ANLZ_SAGIT_FLIPPED        5
61 
62 typedef struct Header_Key_t {
63         Int32  sizeof_hdr;               /* 348 or 148                 */
64         char data_type[10];              /* "dsr"                      */
65         char db_name[18];                /* filename without extension */
66         Int32 extents;
67         Int16 session_error;
68         char regular;                    /* 'r'                        */
69         char hkey_un0;
70 } MDC_ANLZ_HEADER_KEY;
71 
72 #define MDC_ANLZ_HK_SIZE 40
73 
74 typedef struct Image_Dimensions_t {
75         Int16 dim[MDC_ANLZ_MAX_DIMS];    /* [0] = # of dimensions      */
76                                          /* [1] = X-dim                */
77                                          /* [2] = Y-dim                */
78                                          /* [3] = Z-dim                */
79                                          /* [4] = t-dim                */
80                                          /* ...                        */
81         char avw_vox_units[4];           /* AVW real world dim units   */
82         char avw_cal_units[8];           /* AVW real world pix units   */
83         Int16 unused1;
84         Int16 datatype;                  /* pixel type                 */
85                                          /*  0 = Unknown   1 = one-bit */
86                                          /*  2 = Uint8     4 = Int16   */
87                                          /*  8 = Int32    16 = float   */
88                                          /* 32 = complex  64 = double  */
89 
90         Int16 bitpix;                    /* bits per pixel             */
91         Int16 dim_un0;
92         float pixdim[MDC_ANLZ_MAX_DIMS]; /* [0] = # of dimensions      */
93                                          /* [1] = X-dim (mm)           */
94                                          /* [2] = Y-dim (mm)           */
95                                          /* [3] = Z-dim (mm)           */
96                                          /* [4] = t-dim (ms)           */
97                                          /* ...                        */
98         float avw_vox_offset;            /* AVW offset to pixel data   */
99         float spm_pix_rescale;           /* SPM pixel rescale factor   */
100         float funused1;
101         float funused2;
102         float avw_cal_max;               /* AVW max calibrated values  */
103         float avw_cal_min;               /* AVW min calibrated values  */
104         float compressed;
105         float verified;
106         Int32 glmax,glmin;
107 } MDC_ANLZ_IMAGE_DIMS;
108 
109 #define MDC_ANLZ_IMD_SIZE 108
110 
111 typedef struct Data_History_t {
112         char descrip[80];
113         char aux_file[24];
114         char orient;                     /* patient orientation        */
115                                          /* 0 = transverse unflipped   */
116                                          /* 1 = coronal unflipped      */
117                                          /* 2 = sagittal unflipped     */
118                                          /* 3 = transverse flipped     */
119                                          /* 4 = coronal flipped        */
120                                          /* 5 = sagittal flipped       */
121 
122         char originator[10];
123         char generated[10];
124         char scannum[10];
125         char patient_id[10];
126         char exp_date[10];
127         char exp_time[10];
128         char hist_un0[3];
129         Int32 views;
130         Int32 vols_added;
131         Int32 start_field;
132         Int32 field_skip;
133         Int32 omax, omin;
134         Int32 smax, smin;
135 } MDC_ANLZ_DATA_HIST;
136 
137 #define MDC_ANLZ_DH_SIZE 200
138 
139 
140 typedef struct MdcSpmOpt_t {
141         Int16 origin_x;
142         Int16 origin_y;
143         Int16 origin_z;
144         float offset;
145 } MDC_SPMOPT;
146 
147 /****************************************************************************
148                             F U N C T I O N S
149 ****************************************************************************/
150 
151 int MdcCheckANLZ(FILEINFO *fi);
152 const char *MdcReadANLZ(FILEINFO *fi);
153 const char *MdcWriteANLZ(FILEINFO *fi);
154 int MdcWriteHeaderKey(FILEINFO *fi);
155 int MdcWriteImageDimension(FILEINFO *fi, MDC_SPMOPT *opt);
156 int MdcWriteDataHistory(FILEINFO *fi, MDC_SPMOPT *opt);
157 char *MdcWriteImagesData(FILEINFO *fi);
158 void MdcGetSpmOpt(FILEINFO *fi, MDC_SPMOPT *opt);
159 
160 #endif
161 
162