r101: *** empty log message ***
[ctsim.git] / include / ct.h
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 **   Name:          ct.h
5 **   Purpose:       Master header file for CTSim
6 **   Programmer:    Kevin Rosenberg
7 **   Date Started:  Aug 1984
8 **
9 **  This is part of the CTSim program
10 **  Copyright (C) 1983-2000 Kevin Rosenberg
11 **
12 **  $Id: ct.h,v 1.18 2000/06/19 17:58:20 kevin Exp $
13 **
14 **  This program is free software; you can redistribute it and/or modify
15 **  it under the terms of the GNU General Public License (version 2) as
16 **  published by the Free Software Foundation.
17 **
18 **  This program is distributed in the hope that it will be useful,
19 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
20 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21 **  GNU General Public License for more details.
22 **
23 **  You should have received a copy of the GNU General Public License
24 **  along with this program; if not, write to the Free Software
25 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
26 ******************************************************************************/
27
28 #ifndef CT_H
29 #define CT_H
30
31 #ifdef _WIN32
32   typedef long off_t;
33   #define HAVE_STRING_H 1
34   #include <fcntl.h>
35   #define snprintf _snprintf
36   #define vsnprintf _vsnprintf
37   #define strcasecmp stricmp
38   #define strncasecmp strnicmp
39 #endif
40
41 #ifdef HAVE_CONFIG_H
42   #include <config.h>
43 #endif
44 #ifdef HAVE_PNG
45   #include "png.h"
46 #endif
47 #ifdef HAVE_G2_H
48 extern "C" { 
49 #include "g2.h" 
50 }
51 #ifdef HAVE_X11
52 extern "C" {
53 #include "g2_X11.h"
54 }
55 #endif
56 #endif
57 #ifdef HAVE_STDIO_H
58 #include <stdio.h>
59 #endif
60 #ifdef HAVE_STRING_H
61 #include <string.h>
62 #endif
63 #ifdef HAVE_STDDEF_H
64 #include <stddef.h>
65 #endif
66 #ifdef HAVE_STDLIB_H
67 #include <stdlib.h>
68 #endif
69 #ifdef HAVE_STDARG_H
70 #include <stdarg.h>
71 #endif
72 #ifdef  HAVE_SYS_TYPES_H
73 #include <sys/types.h>
74 #endif
75 #ifdef HAVE_SYS_STAT_H
76 #include <sys/stat.h>
77 #endif
78 #ifdef HAVE_CTYPE_H
79 #include <ctype.h>
80 #endif
81 #ifdef HAVE_MATH_H
82 #include <math.h>
83 #endif
84 #ifdef HAVE_SYS_FCNTL_H
85 #include <sys/fcntl.h>
86 #endif
87 #ifdef HAVE_FCNTL_H
88 #include <fcntl.h>
89 #endif
90 #if defined(HAVE_GETOPT_H) || defined(HAVE_GETOPT_LONG)
91 #include <getopt.h>
92 #endif
93 #ifdef HAVE_UNISTD_H
94 #include <unistd.h>
95 #endif
96 #ifdef HAVE_SETJMP_H
97 #include <setjmp.h>
98 #endif
99 #ifdef HAVE_SYS_PARAM_H
100 #include <sys/param.h>          /* for htonl on FreeBSD */
101 #endif
102 #ifdef HAVE_NETINET_IN_H
103 #include <netinet/in.h>         /* for htonl on Linux/Solaris */
104 #endif
105 #ifdef HAVE_INTTYPES_H
106 #include <inttypes.h>           /* for htonl on Solaris */
107 #endif
108 #ifdef HAVE_STDINT_H
109 #include <stdint.h>             /* Standard ints on Linux */
110 #endif
111
112 #ifdef HAVE_MPI
113 #include "mpi++.h"
114 #include "mpiworld.h"
115 #endif
116
117 #include "kstddef.h"
118 #include "kmath.h"
119 #include "keyboard.h"
120 #include "cio.h"
121 #include "byteorder.h"
122
123 #ifdef HAVE_SGP
124   #include "ezplot.h"
125   #include "sgp.h"
126 #endif
127
128 #include <fstream>
129 #include <iostream>
130 #include <sstream>
131 #include <string>
132 #include <iterator>
133 #include <algorithm>
134 #include <exception>
135 #include <stdexcept>
136
137 using namespace std;
138
139 #include "array2d.h"
140 #include "imagefile.h"
141 #include "phantom.h"
142 #include "projections.h"
143 #include "scanner.h"
144
145 //----------------------------------------------------------------------//
146 //                              USER SYMBOLS                            //
147 //----------------------------------------------------------------------//
148
149 // Filter types
150 static const char O_FILTER_ABS_BANDLIMIT_STR[]= "abs_bandlimit";
151 static const char O_FILTER_ABS_SINC_STR[]=      "abs_sinc";
152 static const char O_FILTER_ABS_COS_STR[]=       "abs_cos";
153 static const char O_FILTER_ABS_HAMMING_STR[]=   "abs_hamming";
154 static const char O_FILTER_SHEPP_STR[]=         "shepp";
155 static const char O_FILTER_BANDLIMIT_STR[]=     "bandlimit";
156 static const char O_FILTER_SINC_STR[]=          "sinc";
157 static const char O_FILTER_COS_STR[]=           "cos";
158 static const char O_FILTER_HAMMING_STR[]=       "hamming";
159 static const char O_FILTER_TRIANGLE_STR[]=      "triangle";
160
161 typedef enum {     
162   FILTER_BANDLIMIT, 
163   FILTER_SINC,
164   FILTER_G_HAMMING,
165   FILTER_COSINE,
166   FILTER_TRIANGLE,
167   FILTER_ABS_BANDLIMIT,         // filter times |x| 
168   FILTER_ABS_SINC, 
169   FILTER_ABS_G_HAMMING,
170   FILTER_ABS_COSINE,
171   FILTER_SHEPP
172 } FilterType;
173
174
175 // Function domains 
176 static const char D_FREQ_STR[]=    "freq";
177 static const char D_SPATIAL_STR[]= "spatial";
178  
179 typedef enum {
180   D_FREQ = 1,
181   D_SPATIAL 
182 } DomainType;
183
184
185 /* interpolation methods */
186 static const char O_INTERP_NEAREST_STR[]=  "nearest";
187 static const char O_INTERP_LINEAR_STR[]=   "linear";
188 static const char O_INTERP_BSPLINE_STR[]=  "bspline";
189
190 #undef HAVE_BSPLINE_INTERP
191 typedef enum {          // Interpolation methods
192     I_NEAREST = 1,      // Nearest neighbor
193 #if HAVE_BSPLINE_INTERP
194     I_BSPLINE,
195     I_1BSPLINE,      // 1st order B-Spline 
196     I_2BSPLINE,
197     I_3BSPLINE,
198 #endif
199     I_LINEAR        // Linear interpolation 
200 } InterpolationType;
201
202
203 // Trace levels
204 static const char O_TRACE_NONE_STR[]=     "none";
205 static const char O_TRACE_TEXT_STR[]=     "text";
206 static const char O_TRACE_PHM_STR[]=      "phm";
207 static const char O_TRACE_RAYS_STR[]=     "rays";
208 static const char O_TRACE_PLOT_STR[]=     "plot";
209 static const char O_TRACE_CLIPPING_STR[]= "clipping";
210
211 enum {
212   TRACE_NONE,           /* No tracing */
213   TRACE_TEXT,           /* Minimal status */
214   TRACE_PHM,            /* Show phantom */
215   TRACE_RAYS,           /* Show all rays */
216   TRACE_PLOT,           /* Plot raysums */
217   TRACE_CLIPPING        /* Plot clipping */
218 };
219
220 // Standard phantomsa
221 static const char O_PHM_HERMAN_STR[]=    "herman";
222 static const char O_PHM_ROWLAND_STR[]=   "rowland";
223 static const char O_PHM_BROWLAND_STR[]=  "browland";
224 static const char O_PHM_UNITPULSE_STR[]= "unitpulse";
225 typedef enum {
226   O_PHM_HERMAN,               /* Herman head phantom */
227   O_PHM_ROWLAND,              /* Rowland head phantom */
228   O_PHM_BROWLAND,             /* Bordered Rowland head phantom */
229   O_PHM_UNITPULSE             /* Unit pulse phantom */
230 } PhantomType;
231
232 // Backproject types
233 static const char O_BPROJ_TRIG_STR[]=     "trig";
234 static const char O_BPROJ_TABLE_STR[]=    "table";
235 static const char O_BPROJ_DIFF_STR[]=     "diff";
236 static const char O_BPROJ_DIFF2_STR[]=    "diff2";
237 static const char O_BPROJ_IDIFF2_STR[]=   "idiff2";
238
239 typedef  enum {
240   O_BPROJ_TRIG,
241   O_BPROJ_TABLE,
242   O_BPROJ_DIFF,
243   O_BPROJ_DIFF2,
244   O_BPROJ_IDIFF2
245 } BackprojType;
246
247 // Convolution symmetries
248 typedef enum {
249     FUNC_EVEN = 1,    // function types, f[-n] = f[n] 
250     FUNC_ODD,         // f[-n] = -f[n] 
251     FUNC_BOTH         // function has both odd & even components 
252 } FunctionSymmetry;
253
254
255
256 #include "backprojectors.h"
257
258
259 /*************************************************************************
260  *  FUNCTION DECLARATIONS
261  ************************************************************************/
262
263 // convolve.cpp
264 double convolve (const double f1[], const double f2[], const double dx, const int n, const int np, const FunctionSymmetry func_type);
265
266 // dialogs.cpp 
267 bool phm_add_pelem_kb (Phantom& phm);
268 const Phantom& phm_select (Phantom& phm);
269 int interpolation_select (void);
270 int filter_select (double *filter_param);
271
272 // filter.cpp 
273 double *filter_generate (const FilterType filt_type, double bw, double xmin, double xmax, int n, double param, const DomainType domain, int numint);
274 double filter_spatial_response_calc (int filt_type, double x, double bw, double param, int n);
275 double filter_spatial_response_analytic (int filt_type, double x, double bw, double param);
276 double filter_frequency_response (int filt_type, double u, double bw, double param);
277 double sinc (double x, double mult);
278 double integral_abscos(double u, double w);
279
280 // options.cpp 
281 int opt_set_trace(const char *optarg);
282 const char *name_of_phantom(const int phmid);
283 int opt_set_phantom(const char *optarg);
284 InterpolationType opt_set_interpolation(const char *optarg);
285 const char *name_of_interpolation(int interp_type);
286 FilterType opt_set_filter(const char *optarg);
287 const char *name_of_filter(const int filter);
288 DomainType opt_set_filter_domain(const char *optarg);
289 const char *name_of_filter_domain(const DomainType domain);
290 BackprojType opt_set_backproj(const char *optarg);
291 const char *name_of_backproj(const BackprojType backproj);
292
293 // From phm2image.cpp 
294 void phm_to_imagefile (const Phantom& phm, ImageFile& im, const int col_start, const int col_count, const int nsample, const int trace);
295
296 // image.cpp 
297 void image_filter_response(ImageFile& im, const DomainType domain, double bw, const FilterType filt_type, double filt_param, const int opt_trace);
298 int image_display (const ImageFile& im);
299 int image_display_scale (const ImageFile& im, const int scale, const double pmin, const double pmax);
300
301 // From reconstr.cpp 
302 ImageFile& proj_reconst (ImageFile& im, Projections& rs, const FilterType filt_type, double filt_param, InterpolationType interp_type, int interp_param, const BackprojType backproj_type, int const ir_trace);
303
304 #endif
305