1 /*****************************************************************************
5 ** Purpose: Master Image Reconstruction Header
6 ** Programmer: Kevin Rosenberg
7 ** Date Started: July 1, 1984
9 ** This is part of the CTSim program
10 ** Copyright (C) 1983-2000 Kevin Rosenberg
12 ** $Id: ir.h,v 1.25 2000/06/10 22:33:11 kevin Exp $
15 ** This program is free software; you can redistribute it and/or modify
16 ** it under the terms of the GNU General Public License (version 2) as
17 ** published by the Free Software Foundation.
19 ** This program is distributed in the hope that it will be useful,
20 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
21 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 ** GNU General Public License for more details.
24 ** You should have received a copy of the GNU General Public License
25 ** along with this program; if not, write to the Free Software
26 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 ******************************************************************************/
34 int *b; /* Histogram array (# of elements in each bin) */
35 int nbin; /* Number of histogram bins */
36 double xmin, xmax, xinc; /* Limits of histogram boundaries */
39 typedef struct histo_st HISTOGRAM;
41 /*---------------------------------------------------------------------------*/
43 static const int POINTS_PER_CIRCLE=90;
55 PElmType type; /* pelm type (box, ellipse, etc) */
56 double atten; /* X-ray attenuation coefficient */
57 double cx,cy; /* center of pelm */
58 double u,v; /* size of pelm */
59 double rot; /* pelm rotation angle (in radians) */
60 double *x, *y; /* ptr to array of points in obj world coord */
61 int pts; /* number of points in outline arrays */
62 double xmin, xmax, ymin, ymax; /* pelm limits */
63 double radius; /* " */
64 GRFMTX_2D p_to_o; /* map from phantom to standard pelm coords */
65 GRFMTX_2D o_to_p; /* map from std pelm coords to phantom coords */
66 struct pelm_st *next; /* pointer to next pelm in phantom */
68 typedef struct pelm_st PELM;
71 P_PELMS, /* Phantom made of Pelms */
72 P_UNIT_PULSE, /* Special phantom, not made of pelms */
73 P_FILTER /* defined only by this type */
76 struct phm_st { /* Phantom structure */
77 PELM *pelm_list; /* pelm linked-list */
79 int n_pelm; /* number of pelms in phantom */
80 double xmin, xmax, ymin, ymax; /* extent of pelms in pelm coordinates */
81 double radius; /* " " */
83 typedef struct phm_st PHANTOM;
86 /*----------------------------------------------------------------------*/
88 /*----------------------------------------------------------------------*/
90 /* Ray sums are collected along an array of ndet detectors. The data
91 * for these detectors is stored in the structure DETECTARRAY
94 typedef float DETECT_TYPE;
97 DETECT_TYPE *detval; /* Pointer to array of values recorded by detector */
98 int ndet; /* Number of detectors in array */
99 double view_angle; /* View angle in radians */
101 typedef struct detarray_st DETARRAY;
111 ScannerGeometry geometry; /* Geometry of detectory */
112 int ndet; /* Number of detectors in array */
113 int nview; /* Number of rotated views */
114 int nsample; /* Number of rays per detector */
115 double detlen; /* Total length of detector array */
116 double rotlen; /* Rotation angle length in radians (norm 2PI) */
117 double det_inc; /* Increment between centers of detectors */
118 double rot_inc; /* Increment in rotation angle between views */
119 double radius; /* Radius of rotation. Distance from */
120 /* center of phm to center of det */
121 double phmlen; /* Maximum Length of phantom or area of interest */
123 double xd1,yd1,xd2,yd2; /* Coordinates of detector endpoints */
124 double xs1,ys1,xs2,ys2; /* Coordinates of source endpoints */
125 double angle; /* Starting angle */
128 typedef struct detector_st DETECTOR;
131 int fd; /* Disk file descriptor */
132 int file_mode; /* Current file mode (read or write) */
133 int header_size; /* Size of disk file header */
134 int geometry; /* Geometry of scanner */
135 struct detarray_st **view; /* Pointer to array of detarray_st pointers */
137 char remark[MAXREMARK+1]; /* description of raysum data */
138 double calctime; /* time required to calculate raysums */
140 int ndet; /* number of detectors in array */
141 int nview; /* number of rotated views */
142 double rot_start; /* starting view rotation */
143 double rot_inc; /* angle between rotations */
144 double det_start; /* distance of beginning detector to center */
146 double det_inc; /* increment between detectors */
147 double phmlen; /* Length of PHANTOM edge (phm is square) */
149 typedef struct raysum_st RAYSUM;
151 /*----------------------------------------------------------------------*/
153 /*----------------------------------------------------------------------*/
155 /* Codes for Coordinate Types */
156 /* Defines coords for pelm_is_point_inside() */
159 PELM_COORD, /* Normalized Pelm Coordinates */
160 PHM_COORD /* User's phantom Coordinates */
163 /* Codes for Filter types */
165 typedef enum { /* filter types for filter_generate() */
171 FILTER_ABS_BANDLIMIT, /* filter times |x| */
173 FILTER_ABS_G_HAMMING,
178 /* function domains */
180 static const char D_FREQ_STR[]= "freq";
181 static const char D_SPATIAL_STR[]= "spatial";
189 FUNC_EVEN = 1, /* function types, f[-n] = f[n] */
190 FUNC_ODD, /* f[-n] = -f[n] */
191 FUNC_BOTH /* function has both odd & even components */
194 /* interpolation methods */
195 #undef HAVE_BSPLINE_INTERP
196 typedef enum { /* Interpolation methods */
197 I_NEAREST = 1, /* Nearest neighbor */
198 #if HAVE_BSPLINE_INTERP
200 I_1BSPLINE, /* 1st order B-Spline */
204 I_LINEAR /* Linear interpolation */
207 /* Constants for sizing PHANTOM */
209 static const double PERCENT_PHM_SIZE_INCR=0.0; /* Fractional increase in phantom limits compared to pelm size */
210 static const int N_EXTRA_DETECTORS=4; /* Number of extra detectors widths when calculating detlen */
212 static const char O_TRACE_NONE_STR[]= "none";
213 static const char O_TRACE_TEXT_STR[]= "text";
214 static const char O_TRACE_PHM_STR[]= "phm";
215 static const char O_TRACE_RAYS_STR[]= "rays";
216 static const char O_TRACE_PLOT_STR[]= "plot";
217 static const char O_TRACE_CLIPPING_STR[]= "clipping";
220 TRACE_NONE, /* No tracing */
221 TRACE_TEXT, /* Minimal status */
222 TRACE_PHM, /* Show phantom */
223 TRACE_RAYS, /* Show all rays */
224 TRACE_PLOT, /* Plot raysums */
225 TRACE_CLIPPING /* Plot clipping */
229 O_PHM_HERMAN, /* Herman head phantom */
230 O_PHM_ROWLAND, /* Rowland head phantom */
231 O_PHM_BROWLAND, /* Bordered Rowland head phantom */
232 O_PHM_UNITPULSE /* Unit pulse phantom */
235 static const char O_PHM_HERMAN_STR[]= "herman";
236 static const char O_PHM_ROWLAND_STR[]= "rowland";
237 static const char O_PHM_BROWLAND_STR[]= "browland";
238 static const char O_PHM_UNITPULSE_STR[]= "unitpulse";
240 static const char O_INTERP_NEAREST_STR[]= "nearest";
241 static const char O_INTERP_LINEAR_STR[]= "linear";
242 static const char O_INTERP_BSPLINE_STR[]= "bspline";
244 static const char O_FILTER_ABS_BANDLIMIT_STR[]= "abs_bandlimit";
245 static const char O_FILTER_ABS_SINC_STR[]= "abs_sinc";
246 static const char O_FILTER_ABS_COS_STR[]= "abs_cos";
247 static const char O_FILTER_ABS_HAMMING_STR[]= "abs_hamming";
248 static const char O_FILTER_SHEPP_STR[]= "shepp";
249 static const char O_FILTER_BANDLIMIT_STR[]= "bandlimit";
250 static const char O_FILTER_SINC_STR[]= "sinc";
251 static const char O_FILTER_COS_STR[]= "cos";
252 static const char O_FILTER_HAMMING_STR[]= "hamming";
253 static const char O_FILTER_TRIANGLE_STR[]= "triangle";
263 static const char O_BPROJ_TRIG_STR[]= "trig";
264 static const char O_BPROJ_TABLE_STR[]= "table";
265 static const char O_BPROJ_DIFF_STR[]= "diff";
266 static const char O_BPROJ_DIFF2_STR[]= "diff2";
267 static const char O_BPROJ_IDIFF2_STR[]= "idiff2";
269 const static int RAYSUM_TRACE_ROW_TITLE=1;
270 const static int RAYSUM_TRACE_ROW_TITLE2=2;
271 const static int RAYSUM_TRACE_ROW_PHANT_ID=4;
272 const static int RAYSUM_TRACE_ROW_CHROMATIC=7;
273 const static int RAYSUM_TRACE_ROW_SCATTER=8;
274 const static int RAYSUM_TRACE_ROW_PHOT_STAT=9;
275 const static int RAYSUM_TRACE_ROW_NDET=12;
276 const static int RAYSUM_TRACE_ROW_NVIEW=13;
277 const static int RAYSUM_TRACE_ROW_SAMPLES=14;
278 const static int RAYSUM_TRACE_ROW_CURR_VIEW=17;
279 const static int RAYSUM_TRACE_ROW_ATTEN=18;
282 /*************************************************************************
283 * FUNCTION DECLARATIONS
284 ************************************************************************/
287 double convolve (const double f1[], const double f2[], const double dx, const int n, const int np, const FunctionSymmetry func_type);
288 double convolve_both (const double f1[], const double f2[], const double dx, const int n, const int np);
291 int phm_add_pelm_kb (PHANTOM *phm);
292 PHANTOM *phm_select (void);
293 int interpolation_select (void);
294 int filter_select (double *filter_param);
297 double *filter_generate (const FilterType filt_type, double bw, double xmin, double xmax, int n, double param, const DomainType domain, int numint);
298 double filter_spatial_response_calc (int filt_type, double x, double bw, double param, int n);
299 double filter_spatial_response_analytic (int filt_type, double x, double bw, double param);
300 double filter_frequency_response (int filt_type, double u, double bw, double param);
301 double sinc (double x, double mult);
302 double integral_abscos(double u, double w);
305 int opt_set_trace(const char *optarg);
306 const char *name_of_phantom(const int phmid);
307 int opt_set_phantom(const char *optarg);
308 InterpolationType opt_set_interpolation(const char *optarg);
309 const char *name_of_interpolation(int interp_type);
310 FilterType opt_set_filter(const char *optarg);
311 const char *name_of_filter(const int filter);
312 DomainType opt_set_filter_domain(const char *optarg);
313 const char *name_of_filter_domain(const DomainType domain);
314 BackprojType opt_set_backproj(const char *optarg);
315 const char *name_of_backproj(const BackprojType backproj);
318 PHANTOM *phm_create(const int phmid);
319 PHANTOM *phm_create_from_file(const char *fname);
320 PHANTOM *phm_init(void);
321 void phm_free (PHANTOM *phm);
322 int phm_add_pelm_file(PHANTOM *phm, const char *fname);
323 void phm_add_pelm (PHANTOM *phm, const char *type, const double cx, const double cy,
324 const double u, const double v, const double rot, const double atten);
325 int pelm_make_points(PELM *obj);
326 void pelm_make_xform (PELM *obj);
327 PELM *pelm_alloc(void);
328 void calc_arc(double x[], double y[], const int pts, const double xcent, const double ycent,
329 const double r, const double start, const double stop);
330 void calc_ellipse(double x[], double y[], const int pts, const double u, const double v);
331 int circle_pts(double theta);
332 void phm_print(PHANTOM *phm);
334 void phm_show(const PHANTOM *phm);
335 void phm_draw(const PHANTOM *phm);
339 void phm_std_herman (PHANTOM *phm);
340 void phm_std_rowland (PHANTOM *phm);
341 void phm_std_rowland_bordered (PHANTOM *phm);
344 int raysum_collect(RAYSUM *rs, const DETECTOR *det, const PHANTOM *phm, const int start_view, const int trace, const int unit_pulse);
345 void rayview(const PHANTOM *phm, DETARRAY *darray, const DETECTOR *det, const double xd1, const double yd1, const double xd2, const double yd2, const double xs1, const double ys1, const double xs2, const double ys2, const int unit_pulse);
346 double phm_ray_attenuation (const PHANTOM *phm, const double x1, const double y1, const double x2, const double y2);
347 double pelm_ray_attenuation (PELM *pelm, const double x1, const double y1, const double x2, const double y2);
348 int pelm_clip_line (const PELM *pelm, double& x1, double& y1, double& x2, double& y2);
349 void raysum_trace_show_param (const char *label, const char *fmt, int row, int color, ...);
352 DETECTOR *detector_create(const PHANTOM *phm, const ScannerGeometry geometry, int ndet, int nview, int nsample, const double rot_anglen);
353 void detector_free(DETECTOR *det);
356 RAYSUM *raysum_create(const char *fname, const int nview, const int ndet);
357 RAYSUM *raysum_create_from_det(const char *fname, const DETECTOR *det);
358 RAYSUM *raysum_open(const char *filename);
359 void raysum_alloc_views(RAYSUM *rs);
360 void raysum_free(RAYSUM *rs);
361 int raysum_is_open(RAYSUM *rs);
362 int raysum_close(RAYSUM *rs);
363 int raysum_read_header(RAYSUM *rs);
364 int raysum_write_header(RAYSUM *rs);
365 int raysum_read(RAYSUM *rs);
366 int raysum_write(RAYSUM *rs);
367 void raysum_print(const RAYSUM *rs);
368 void raysum_print_info(const RAYSUM *rs);
369 DETARRAY *detarray_alloc(const int n);
370 void detarray_free(DETARRAY *darray);
371 int detarray_read(RAYSUM *rs, DETARRAY *darray, const int view_num);
372 int detarray_write(RAYSUM *rs, const DETARRAY *darray, const int view_num);
374 /* From phm2image.cpp */
375 void phm_to_imagefile (const PHANTOM *phm, ImageFile& im, const int col_start, const int col_count, const int nsample, const int trace);
376 int pelm_is_point_inside(PELM *obj, const double x, const double y, const CoordType coord_type);
379 void image_filter_response(ImageFile& im, const DomainType domain, double bw, const FilterType filt_type, double filt_param, const int opt_trace);
380 int image_display (const ImageFile& im);
381 int image_display_scale (const ImageFile& im, const int scale, const double pmin, const double pmax);
383 /* From reconstr.cpp */
384 ImageFile& proj_reconst (ImageFile& im, RAYSUM *rs, const FilterType filt_type, double filt_param, InterpolationType interp_type, int interp_param, const BackprojType backproj_type, int const ir_trace);
387 void backproj_init (const RAYSUM *rs, ImageFile& im, const BackprojType bproj_method);
388 int backproj_calc (const RAYSUM *rs, ImageFile& im, const double *t, const double view_angle, const int interp_type, const int bproj_method);
389 void backproj_term (const RAYSUM *rs, ImageFile& im, const int bproj_method);
391 void backproj_init_trig (const RAYSUM *rs, ImageFile& im);
392 int backproj_calc_trig (const RAYSUM *rs, ImageFile& im, const double *t,
393 const double view_angle, const int interp_type);
394 void backproj_term_trig (const RAYSUM *rs, ImageFile& im);
395 void backproj_init_table (const RAYSUM *rs, ImageFile& im);
396 int backproj_calc_table (const RAYSUM *rs, ImageFile& im, const double *t,
397 const double view_angle, const int interp_type);
398 void backproj_term_table (const RAYSUM *rs, ImageFile& im);
399 void backproj_init_d (const RAYSUM *rs, ImageFile& im);
400 int backproj_calc_d (const RAYSUM *rs, ImageFile& im, const double *t,
401 const double view_angle, const int interp_type);
402 void backproj_term_d (const RAYSUM *rs, ImageFile& im);
403 void backproj_init_d2 (const RAYSUM *rs, ImageFile& im);
404 int backproj_calc_d2 (const RAYSUM *rs, ImageFile& im, const double *t,
405 const double view_angle, const int interp_type);
406 void backproj_term_d2 (const RAYSUM *rs, ImageFile& im);
407 void backproj_init_id (const RAYSUM *rs, ImageFile& im);
408 int backproj_calc_id (const RAYSUM *rs, ImageFile& im, const double *t,
409 const double view_angle, const int interp_type);
410 void backproj_term_id (const RAYSUM *rs, ImageFile& im);
411 void backproj_init_id2 (const RAYSUM *rs, ImageFile& im);
412 int backproj_calc_id2 (const RAYSUM *rs, ImageFile& im, const double *t,
413 const double view_angle, const int interp_type);
414 void backproj_term_id2 (const RAYSUM *rs, ImageFile& im);