1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ir.h,v 1.22 2000/06/07 07:43:39 kevin Exp $
7 ** Revision 1.22 2000/06/07 07:43:39 kevin
8 ** *** empty log message ***
10 ** Revision 1.21 2000/06/07 03:49:54 kevin
11 ** *** empty log message ***
13 ** Revision 1.20 2000/06/07 02:30:27 kevin
14 ** Added C++ image files
16 ** Revision 1.19 2000/06/07 00:59:38 kevin
19 ** Revision 1.18 2000/06/05 01:32:45 kevin
20 ** Added C++ compatibility
22 ** Revision 1.17 2000/06/03 06:29:08 kevin
23 ** *** empty log message ***
25 ** Revision 1.16 2000/05/24 22:48:17 kevin
26 ** First functional version of SDF library for X-window
28 ** Revision 1.15 2000/05/16 04:33:17 kevin
29 ** Updated documentation
31 ** Revision 1.14 2000/05/11 14:07:00 kevin
32 ** Added support for Windows NT
34 ** Revision 1.13 2000/05/08 20:00:48 kevin
37 ** Revision 1.12 2000/05/07 12:46:19 kevin
38 ** made c++ compatible
40 ** Revision 1.11 2000/05/05 02:37:31 kevin
41 ** renamed phmelm to pelm
43 ** Revision 1.10 2000/05/04 18:16:34 kevin
44 ** renamed filter definitions
46 ** Revision 1.9 2000/05/04 04:29:18 kevin
47 ** *** empty log message ***
49 ** Revision 1.8 2000/05/04 04:25:55 kevin
50 ** Renamed phantom and phantom-element functions/variables
52 ** Revision 1.7 2000/05/03 19:51:41 kevin
53 ** function renaming for phantoms and phantom elements
55 ** Revision 1.6 2000/05/03 08:49:49 kevin
58 ** Revision 1.5 2000/05/02 20:00:25 kevin
59 ** *** empty log message ***
61 ** Revision 1.4 2000/05/02 15:31:39 kevin
64 ** Revision 1.3 2000/04/29 23:24:29 kevin
65 ** *** empty log message ***
67 ** Revision 1.2 2000/04/28 14:14:16 kevin
68 ** *** empty log message ***
70 ** Revision 1.1.1.1 2000/04/28 13:02:43 kevin
71 ** Initial CVS import for first public release
75 ** This program is free software; you can redistribute it and/or modify
76 ** it under the terms of the GNU General Public License (version 2) as
77 ** published by the Free Software Foundation.
79 ** This program is distributed in the hope that it will be useful,
80 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
81 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82 ** GNU General Public License for more details.
84 ** You should have received a copy of the GNU General Public License
85 ** along with this program; if not, write to the Free Software
86 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
87 ******************************************************************************/
89 /* ir.h Header File for Image Reconstruction System
90 * Programmer: Kevin Rosenberg
91 * Date Started: 7-1-84
99 int *b; /* Histogram array (# of elements in each bin) */
100 int nbin; /* Number of histogram bins */
101 double xmin, xmax, xinc; /* Limits of histogram boundaries */
104 typedef struct histo_st HISTOGRAM;
106 /*---------------------------------------------------------------------------*/
108 static const int POINTS_PER_CIRCLE=90;
120 PElmType type; /* pelm type (box, ellipse, etc) */
121 double atten; /* X-ray attenuation coefficient */
122 double cx,cy; /* center of pelm */
123 double u,v; /* size of pelm */
124 double rot; /* pelm rotation angle (in radians) */
125 double *x, *y; /* ptr to array of points in obj world coord */
126 int pts; /* number of points in outline arrays */
127 double xmin, xmax, ymin, ymax; /* pelm limits */
128 double radius; /* " */
129 GRFMTX_2D p_to_o; /* map from phantom to standard pelm coords */
130 GRFMTX_2D o_to_p; /* map from std pelm coords to phantom coords */
131 struct pelm_st *next; /* pointer to next pelm in phantom */
133 typedef struct pelm_st PELM;
136 P_PELMS, /* Phantom made of Pelms */
137 P_UNIT_PULSE, /* Special phantom, not made of pelms */
138 P_FILTER /* defined only by this type */
141 struct phm_st { /* Phantom structure */
142 PELM *pelm_list; /* pelm linked-list */
144 int n_pelm; /* number of pelms in phantom */
145 double xmin, xmax, ymin, ymax; /* extent of pelms in pelm coordinates */
146 double radius; /* " " */
148 typedef struct phm_st PHANTOM;
151 /*----------------------------------------------------------------------*/
153 /*----------------------------------------------------------------------*/
155 /* Ray sums are collected along an array of ndet detectors. The data
156 * for these detectors is stored in the structure DETECTARRAY
159 typedef float DETECT_TYPE;
162 DETECT_TYPE *detval; /* Pointer to array of values recorded by detector */
163 int ndet; /* Number of detectors in array */
164 double view_angle; /* View angle in radians */
166 typedef struct detarray_st DETARRAY;
176 ScannerGeometry geometry; /* Geometry of detectory */
177 int ndet; /* Number of detectors in array */
178 int nview; /* Number of rotated views */
179 int nsample; /* Number of rays per detector */
180 double detlen; /* Total length of detector array */
181 double rotlen; /* Rotation angle length in radians (norm 2PI) */
182 double det_inc; /* Increment between centers of detectors */
183 double rot_inc; /* Increment in rotation angle between views */
184 double radius; /* Radius of rotation. Distance from */
185 /* center of phm to center of det */
186 double phmlen; /* Maximum Length of phantom or area of interest */
188 double xd1,yd1,xd2,yd2; /* Coordinates of detector endpoints */
189 double xs1,ys1,xs2,ys2; /* Coordinates of source endpoints */
190 double angle; /* Starting angle */
193 typedef struct detector_st DETECTOR;
196 int fd; /* Disk file descriptor */
197 int file_mode; /* Current file mode (read or write) */
198 int header_size; /* Size of disk file header */
199 int geometry; /* Geometry of scanner */
200 struct detarray_st **view; /* Pointer to array of detarray_st pointers */
202 char remark[MAXREMARK+1]; /* description of raysum data */
203 double calctime; /* time required to calculate raysums */
205 int ndet; /* number of detectors in array */
206 int nview; /* number of rotated views */
207 double rot_start; /* starting view rotation */
208 double rot_inc; /* angle between rotations */
209 double det_start; /* distance of beginning detector to center */
211 double det_inc; /* increment between detectors */
212 double phmlen; /* Length of PHANTOM edge (phm is square) */
214 typedef struct raysum_st RAYSUM;
216 /*----------------------------------------------------------------------*/
218 /*----------------------------------------------------------------------*/
220 /* Codes for Coordinate Types */
221 /* Defines coords for pelm_is_point_inside() */
224 PELM_COORD, /* Normalized Pelm Coordinates */
225 PHM_COORD /* User's phantom Coordinates */
228 /* Codes for Filter types */
230 typedef enum { /* filter types for filter_generate() */
236 FILTER_ABS_BANDLIMIT, /* filter times |x| */
238 FILTER_ABS_G_HAMMING,
243 /* function domains */
245 static const char D_FREQ_STR[]= "freq";
246 static const char D_SPATIAL_STR[]= "spatial";
254 FUNC_EVEN = 1, /* function types, f[-n] = f[n] */
255 FUNC_ODD, /* f[-n] = -f[n] */
256 FUNC_BOTH /* function has both odd & even components */
259 /* interpolation methods */
260 #undef HAVE_BSPLINE_INTERP
261 typedef enum { /* Interpolation methods */
262 I_NEAREST = 1, /* Nearest neighbor */
263 #if HAVE_BSPLINE_INTERP
265 I_1BSPLINE, /* 1st order B-Spline */
269 I_LINEAR /* Linear interpolation */
272 /* Constants for sizing PHANTOM */
274 static const double PERCENT_PHM_SIZE_INCR=0.0; /* Fractional increase in phantom limits compared to pelm size */
275 static const int N_EXTRA_DETECTORS=4; /* Number of extra detectors widths when calculating detlen */
277 static const char O_TRACE_NONE_STR[]= "none";
278 static const char O_TRACE_TEXT_STR[]= "text";
279 static const char O_TRACE_PHM_STR[]= "phm";
280 static const char O_TRACE_RAYS_STR[]= "rays";
281 static const char O_TRACE_PLOT_STR[]= "plot";
282 static const char O_TRACE_CLIPPING_STR[]= "clipping";
285 TRACE_NONE, /* No tracing */
286 TRACE_TEXT, /* Minimal status */
287 TRACE_PHM, /* Show phantom */
288 TRACE_RAYS, /* Show all rays */
289 TRACE_PLOT, /* Plot raysums */
290 TRACE_CLIPPING /* Plot clipping */
294 O_PHM_HERMAN, /* Herman head phantom */
295 O_PHM_ROWLAND, /* Rowland head phantom */
296 O_PHM_BROWLAND, /* Bordered Rowland head phantom */
297 O_PHM_UNITPULSE /* Unit pulse phantom */
300 static const char O_PHM_HERMAN_STR[]= "herman";
301 static const char O_PHM_ROWLAND_STR[]= "rowland";
302 static const char O_PHM_BROWLAND_STR[]= "browland";
303 static const char O_PHM_UNITPULSE_STR[]= "unitpulse";
305 static const char O_INTERP_NEAREST_STR[]= "nearest";
306 static const char O_INTERP_LINEAR_STR[]= "linear";
307 static const char O_INTERP_BSPLINE_STR[]= "bspline";
309 static const char O_FILTER_ABS_BANDLIMIT_STR[]= "abs_bandlimit";
310 static const char O_FILTER_ABS_SINC_STR[]= "abs_sinc";
311 static const char O_FILTER_ABS_COS_STR[]= "abs_cos";
312 static const char O_FILTER_ABS_HAMMING_STR[]= "abs_hamming";
313 static const char O_FILTER_SHEPP_STR[]= "shepp";
314 static const char O_FILTER_BANDLIMIT_STR[]= "bandlimit";
315 static const char O_FILTER_SINC_STR[]= "sinc";
316 static const char O_FILTER_COS_STR[]= "cos";
317 static const char O_FILTER_HAMMING_STR[]= "hamming";
318 static const char O_FILTER_TRIANGLE_STR[]= "triangle";
328 static const char O_BPROJ_TRIG_STR[]= "trig";
329 static const char O_BPROJ_TABLE_STR[]= "table";
330 static const char O_BPROJ_DIFF_STR[]= "diff";
331 static const char O_BPROJ_DIFF2_STR[]= "diff2";
332 static const char O_BPROJ_IDIFF2_STR[]= "idiff2";
334 const static int RAYSUM_TRACE_ROW_TITLE=1;
335 const static int RAYSUM_TRACE_ROW_TITLE2=2;
336 const static int RAYSUM_TRACE_ROW_PHANT_ID=4;
337 const static int RAYSUM_TRACE_ROW_CHROMATIC=7;
338 const static int RAYSUM_TRACE_ROW_SCATTER=8;
339 const static int RAYSUM_TRACE_ROW_PHOT_STAT=9;
340 const static int RAYSUM_TRACE_ROW_NDET=12;
341 const static int RAYSUM_TRACE_ROW_NVIEW=13;
342 const static int RAYSUM_TRACE_ROW_SAMPLES=14;
343 const static int RAYSUM_TRACE_ROW_CURR_VIEW=17;
344 const static int RAYSUM_TRACE_ROW_ATTEN=18;
347 /*************************************************************************
348 * FUNCTION DECLARATIONS
349 ************************************************************************/
353 #endif /* __cplusplus */
356 #define MPI_MAX_PROCESS 128
361 int base_local_work_units;
362 int remainder_work_units;
363 int local_work_units[MPI_MAX_PROCESS];
364 int start_work_unit[MPI_MAX_PROCESS];
368 extern struct mpi_ct_st mpi_ct;
369 void mpi_ct_calc_work_units(const unsigned int global_work_units);
374 int bspline(int samples, int zoom_factor, int spline_order, double input[], double output[]);
377 double convolve(const double f1[], const double f2[], const double dx, const int n, const int np, const FunctionSymmetry func_type);
378 double convolve_both(const double f1[], const double f2[], const double dx, const int n, const int np);
381 int phm_add_pelm_kb(PHANTOM *phm);
382 PHANTOM *phm_select(void);
383 int interpolation_select(void);
384 int filter_select(double *filter_param);
387 double *filter_generate(const FilterType filt_type, double bw, double xmin, double xmax, int n, double param, const DomainType domain, int numint);
388 double filter_spatial_response_calc(int filt_type, double x, double bw, double param, int n);
389 double filter_spatial_response_analytic(int filt_type, double x, double bw, double param);
390 double filter_frequency_response(int filt_type, double u, double bw, double param);
391 double sinc(double x, double mult);
392 double integral_abscos(double u, double w);
395 int opt_set_trace(const char *optarg);
396 const char *name_of_phantom(const int phmid);
397 int opt_set_phantom(const char *optarg);
398 InterpolationType opt_set_interpolation(const char *optarg);
399 const char *name_of_interpolation(int interp_type);
400 FilterType opt_set_filter(const char *optarg);
401 const char *name_of_filter(const int filter);
402 DomainType opt_set_filter_domain(const char *optarg);
403 const char *name_of_filter_domain(const DomainType domain);
404 BackprojType opt_set_backproj(const char *optarg);
405 const char *name_of_backproj(const BackprojType backproj);
408 PHANTOM *phm_create(const int phmid);
409 PHANTOM *phm_create_from_file(const char *fname);
410 PHANTOM *phm_init(void);
411 void phm_free (PHANTOM *phm);
412 int phm_add_pelm_file(PHANTOM *phm, const char *fname);
413 void phm_add_pelm (PHANTOM *phm, const char *type, const double cx, const double cy,
414 const double u, const double v, const double rot, const double atten);
415 int pelm_make_points(PELM *obj);
416 void pelm_make_xform (PELM *obj);
417 PELM *pelm_alloc(void);
418 void calc_arc(double x[], double y[], const int pts, const double xcent, const double ycent,
419 const double r, const double start, const double stop);
420 void calc_ellipse(double x[], double y[], const int pts, const double u, const double v);
421 int circle_pts(double theta);
422 void phm_print(PHANTOM *phm);
424 void phm_show(const PHANTOM *phm);
425 void phm_draw(const PHANTOM *phm);
429 void phm_std_herman (PHANTOM *phm);
430 void phm_std_rowland (PHANTOM *phm);
431 void phm_std_rowland_bordered (PHANTOM *phm);
434 int raysum_collect(RAYSUM *rs, const DETECTOR *det, const PHANTOM *phm, const int start_view, const int trace, const int unit_pulse);
435 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);
436 double phm_ray_attenuation (const PHANTOM *phm, const double x1, const double y1, const double x2, const double y2);
437 double pelm_ray_attenuation (PELM *pelm, const double x1, const double y1, const double x2, const double y2);
438 int pelm_clip_line (const PELM *pelm, double *x1, double *y1, double *x2, double *y2);
439 void raysum_trace_show_param (const char *label, const char *fmt, int row, int color, ...);
442 DETECTOR *detector_create(const PHANTOM *phm, int geometry, int ndet, int nview, int nsample, const double rot_anglen);
443 void detector_free(DETECTOR *det);
446 RAYSUM *raysum_create(const char *fname, const int nview, const int ndet);
447 RAYSUM *raysum_create_from_det(const char *fname, const DETECTOR *det);
448 RAYSUM *raysum_open(const char *filename);
449 void raysum_alloc_views(RAYSUM *rs);
450 void raysum_free(RAYSUM *rs);
451 int raysum_is_open(RAYSUM *rs);
452 int raysum_close(RAYSUM *rs);
453 int raysum_read_header(RAYSUM *rs);
454 int raysum_write_header(RAYSUM *rs);
455 int raysum_read(RAYSUM *rs);
456 int raysum_write(RAYSUM *rs);
457 DETARRAY *detarray_alloc(const int n);
458 void detarray_free(DETARRAY *darray);
459 int detarray_read(RAYSUM *rs, DETARRAY *darray, const int view_num);
460 int detarray_write(RAYSUM *rs, const DETARRAY *darray, const int view_num);
461 int raysum_print(const RAYSUM *rs);
466 /* From phm2image.cpp */
467 void phm_to_imagefile (const PHANTOM *phm, ImageFile& im, const int col_start, const int col_count, const int nsample, const int trace);
468 int pelm_is_point_inside(PELM *obj, const double x, const double y, const CoordType coord_type);
471 void image_filter_response(ImageFile& im, const DomainType domain, double bw, const FilterType filt_type, double filt_param, const int opt_trace);
472 int image_display (const ImageFile& im);
473 int image_display_scale (const ImageFile& im, const int scale, const double pmin, const double pmax);
475 /* From reconstr.cpp */
476 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);
479 void backproj_init (const RAYSUM *rs, ImageFile& im, const BackprojType bproj_method);
480 int backproj_calc (const RAYSUM *rs, ImageFile& im, const double *t, const double view_angle, const int interp_type, const int bproj_method);
481 void backproj_term (const RAYSUM *rs, ImageFile& im, const int bproj_method);
483 void backproj_init_trig (const RAYSUM *rs, ImageFile& im);
484 int backproj_calc_trig (const RAYSUM *rs, ImageFile& im, const double *t,
485 const double view_angle, const int interp_type);
486 void backproj_term_trig (const RAYSUM *rs, ImageFile& im);
487 void backproj_init_table (const RAYSUM *rs, ImageFile& im);
488 int backproj_calc_table (const RAYSUM *rs, ImageFile& im, const double *t,
489 const double view_angle, const int interp_type);
490 void backproj_term_table (const RAYSUM *rs, ImageFile& im);
491 void backproj_init_d (const RAYSUM *rs, ImageFile& im);
492 int backproj_calc_d (const RAYSUM *rs, ImageFile& im, const double *t,
493 const double view_angle, const int interp_type);
494 void backproj_term_d (const RAYSUM *rs, ImageFile& im);
495 void backproj_init_d2 (const RAYSUM *rs, ImageFile& im);
496 int backproj_calc_d2 (const RAYSUM *rs, ImageFile& im, const double *t,
497 const double view_angle, const int interp_type);
498 void backproj_term_d2 (const RAYSUM *rs, ImageFile& im);
499 void backproj_init_id (const RAYSUM *rs, ImageFile& im);
500 int backproj_calc_id (const RAYSUM *rs, ImageFile& im, const double *t,
501 const double view_angle, const int interp_type);
502 void backproj_term_id (const RAYSUM *rs, ImageFile& im);
503 void backproj_init_id2 (const RAYSUM *rs, ImageFile& im);
504 int backproj_calc_id2 (const RAYSUM *rs, ImageFile& im, const double *t,
505 const double view_angle, const int interp_type);
506 void backproj_term_id2 (const RAYSUM *rs, ImageFile& im);
509 #endif /* __cplusplus */