1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ir.h,v 1.13 2000/05/08 20:00:48 kevin Exp $
7 ** Revision 1.13 2000/05/08 20:00:48 kevin
10 ** Revision 1.12 2000/05/07 12:46:19 kevin
11 ** made c++ compatible
13 ** Revision 1.11 2000/05/05 02:37:31 kevin
14 ** renamed phmelm to pelm
16 ** Revision 1.10 2000/05/04 18:16:34 kevin
17 ** renamed filter definitions
19 ** Revision 1.9 2000/05/04 04:29:18 kevin
20 ** *** empty log message ***
22 ** Revision 1.8 2000/05/04 04:25:55 kevin
23 ** Renamed phantom and phantom-element functions/variables
25 ** Revision 1.7 2000/05/03 19:51:41 kevin
26 ** function renaming for phantoms and phantom elements
28 ** Revision 1.6 2000/05/03 08:49:49 kevin
31 ** Revision 1.5 2000/05/02 20:00:25 kevin
32 ** *** empty log message ***
34 ** Revision 1.4 2000/05/02 15:31:39 kevin
37 ** Revision 1.3 2000/04/29 23:24:29 kevin
38 ** *** empty log message ***
40 ** Revision 1.2 2000/04/28 14:14:16 kevin
41 ** *** empty log message ***
43 ** Revision 1.1.1.1 2000/04/28 13:02:43 kevin
44 ** Initial CVS import for first public release
48 ** This program is free software; you can redistribute it and/or modify
49 ** it under the terms of the GNU General Public License (version 2) as
50 ** published by the Free Software Foundation.
52 ** This program is distributed in the hope that it will be useful,
53 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
54 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55 ** GNU General Public License for more details.
57 ** You should have received a copy of the GNU General Public License
58 ** along with this program; if not, write to the Free Software
59 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
60 ******************************************************************************/
62 /* ir.h Header File for Image Reconstruction System
63 * Programmer: Kevin Rosenberg
64 * Date Started: 7-1-84
72 #endif /* __cplusplus */
75 #define MPI_MAX_PROCESS 128
80 int base_local_work_units;
81 int remainder_work_units;
82 int local_work_units[MPI_MAX_PROCESS];
83 int start_work_unit[MPI_MAX_PROCESS];
87 extern struct mpi_ct_st mpi_ct;
88 void mpi_ct_calc_work_units(const unsigned int global_work_units);
93 int *b; /* Histogram array (# of elements in each bin) */
94 int nbin; /* Number of histogram bins */
95 double xmin, xmax, xinc; /* Limits of histogram boundaries */
98 typedef struct histo_st HISTOGRAM;
100 /*---------------------------------------------------------------------------*/
102 static const int POINTS_PER_CIRCLE=90;
105 typedef FMTX_2D IMAGE_ARRAY; /* use 2d floating point matrix */
106 typedef float IMAGE_ELEM_VAL; /* use floats for image storing */
109 IMAGE_ARRAY v; /* values of voxels in matrix form */
110 SDF_2D *dfp_2d; /* Pointer to disk image file */
111 int nx, ny; /* size of voxel matrix */
112 double xmin, xmax, ymin, ymax; /* extent of voxel matrix in phm coord */
113 char remark[MAXREMARK+1]; /* description of voxel data */
114 float calctime; /* time to calculate voxels in seconds */
116 typedef struct image_st IMAGE;
127 PElmType type; /* pelm type (box, ellipse, etc) */
128 double atten; /* X-ray attenuation coefficient */
129 double cx,cy; /* center of pelm */
130 double u,v; /* size of pelm */
131 double rot; /* pelm rotation angle (in radians) */
132 double *x, *y; /* ptr to array of points in obj world coord */
133 int pts; /* number of points in outline arrays */
134 double xmin, xmax, ymin, ymax; /* pelm limits */
135 double radius; /* " */
136 GRFMTX_2D p_to_o; /* map from phantom to standard pelm coords */
137 GRFMTX_2D o_to_p; /* map from std pelm coords to phantom coords */
138 struct pelm_st *next; /* pointer to next pelm in phantom */
140 typedef struct pelm_st PELM;
143 P_PELMS, /* Phantom made of Pelms */
144 P_UNIT_PULSE, /* Special phantom, not made of pelms */
145 P_FILTER /* defined only by this type */
148 struct phm_st { /* Phantom structure */
149 PELM *pelm_list; /* pelm linked-list */
151 int n_pelm; /* number of pelms in phantom */
152 double xmin, xmax, ymin, ymax; /* extent of pelms in pelm coordinates */
153 double radius; /* " " */
155 typedef struct phm_st PHANTOM;
158 /*----------------------------------------------------------------------*/
160 /*----------------------------------------------------------------------*/
162 /* Ray sums are collected along an array of ndet detectors. The data
163 * for these detectors is stored in the structure DETECTARRAY
166 typedef float DETECT_TYPE;
169 DETECT_TYPE *detval; /* Pointer to array of values recorded by detector */
170 int ndet; /* Number of detectors in array */
171 double view_angle; /* View angle in radians */
173 typedef struct detarray_st DETARRAY;
183 ScannerGeometry geometry; /* Geometry of detectory */
184 int ndet; /* Number of detectors in array */
185 int nview; /* Number of rotated views */
186 int nsample; /* Number of rays per detector */
187 double detlen; /* Total length of detector array */
188 double rotlen; /* Rotation angle length in radians (norm 2PI) */
189 double det_inc; /* Increment between centers of detectors */
190 double rot_inc; /* Increment in rotation angle between views */
191 double radius; /* Radius of rotation. Distance from */
192 /* center of phm to center of det */
193 double phmlen; /* Maximum Length of phantom or area of interest */
195 double xd1,yd1,xd2,yd2; /* Coordinates of detector endpoints */
196 double xs1,ys1,xs2,ys2; /* Coordinates of source endpoints */
197 double angle; /* Starting angle */
200 typedef struct detector_st DETECTOR;
207 struct detarray_st **view; /* Pointer to array of detarray_st pointers */
209 char remark[MAXREMARK+1]; /* description of raysum data */
210 double calctime; /* time required to calculate raysums */
212 int ndet; /* number of detectors in array */
213 int nview; /* number of rotated views */
214 double rot_start; /* starting view rotation */
215 double rot_inc; /* angle between rotations */
216 double det_start; /* distance of beginning detector to center */
218 double det_inc; /* increment between detectors */
219 double phmlen; /* Length of PHANTOM edge (phm is square) */
221 typedef struct raysum_st RAYSUM;
223 /*----------------------------------------------------------------------*/
225 /*----------------------------------------------------------------------*/
227 /* Codes for Coordinate Types */
228 /* Defines coords for pelm_is_point_inside() */
231 PELM_COORD, /* Normalized Pelm Coordinates */
232 PHM_COORD /* User's phantom Coordinates */
235 /* Codes for Filter types */
237 typedef enum { /* filter types for filter_generate() */
243 FILTER_ABS_BANDLIMIT, /* filter times |x| */
245 FILTER_ABS_G_HAMMING,
250 /* function domains */
252 static const char D_FREQ_STR[]= "freq";
253 static const char D_SPATIAL_STR[]= "spatial";
261 FUNC_EVEN, /* function types, f[-n] = f[n] */
262 FUNC_ODD, /* f[-n] = -f[n] */
263 FUNC_BOTH /* function has both odd & even components */
266 /* interpolation methods */
267 typedef enum { /* Interpolation methods */
268 I_NEAREST, /* Nearest neighbor */
269 I_LINEAR, /* Linear interpolation */
271 I_1BSPLINE, /* 1st order B-Spline */
276 /* Constants for sizing PHANTOM */
278 static const double PERCENT_PHM_SIZE_INCR=0.0; /* Fractional increase in phantom limits compared to pelm size */
279 static const int N_EXTRA_DETECTORS=4; /* Number of extra detectors widths when calculating detlen */
281 static const char O_TRACE_NONE_STR[]= "none";
282 static const char O_TRACE_TEXT_STR[]= "text";
283 static const char O_TRACE_PHM_STR[]= "phm";
284 static const char O_TRACE_RAYS_STR[]= "rays";
285 static const char O_TRACE_PLOT_STR[]= "plot";
286 static const char O_TRACE_CLIPPING_STR[]= "clipping";
289 TRACE_NONE, /* No tracing */
290 TRACE_TEXT, /* Minimal status */
291 TRACE_PHM, /* Show phantom */
292 TRACE_RAYS, /* Show all rays */
293 TRACE_PLOT, /* Plot raysums */
294 TRACE_CLIPPING /* Plot clipping */
298 O_PHM_HERMAN, /* Herman head phantom */
299 O_PHM_ROWLAND, /* Rowland head phantom */
300 O_PHM_BROWLAND, /* Bordered Rowland head phantom */
301 O_PHM_UNITPULSE /* Unit pulse phantom */
304 static const char O_PHM_HERMAN_STR[]= "herman";
305 static const char O_PHM_ROWLAND_STR[]= "rowland";
306 static const char O_PHM_BROWLAND_STR[]= "browland";
307 static const char O_PHM_UNITPULSE_STR[]= "unitpulse";
309 static const char O_INTERP_NEAREST_STR[]= "nearest";
310 static const char O_INTERP_LINEAR_STR[]= "linear";
311 static const char O_INTERP_BSPLINE_STR[]= "bspline";
313 static const char O_FILTER_ABS_BANDLIMIT_STR[]= "abs_bandlimit";
314 static const char O_FILTER_ABS_SINC_STR[]= "abs_sinc";
315 static const char O_FILTER_ABS_COS_STR[]= "abs_cos";
316 static const char O_FILTER_ABS_HAMMING_STR[]= "abs_hamming";
317 static const char O_FILTER_SHEPP_STR[]= "shepp";
318 static const char O_FILTER_BANDLIMIT_STR[]= "bandlimit";
319 static const char O_FILTER_SINC_STR[]= "sinc";
320 static const char O_FILTER_COS_STR[]= "cos";
321 static const char O_FILTER_HAMMING_STR[]= "hamming";
322 static const char O_FILTER_TRIANGLE_STR[]= "triangle";
332 static const char O_BPROJ_TRIG_STR[]= "trig";
333 static const char O_BPROJ_TABLE_STR[]= "table";
334 static const char O_BPROJ_DIFF_STR[]= "diff";
335 static const char O_BPROJ_DIFF2_STR[]= "diff2";
336 static const char O_BPROJ_IDIFF2_STR[]= "idiff2";
338 const static int RAYSUM_TRACE_ROW_TITLE=1;
339 const static int RAYSUM_TRACE_ROW_TITLE2=2;
340 const static int RAYSUM_TRACE_ROW_PHANT_ID=4;
341 const static int RAYSUM_TRACE_ROW_CHROMATIC=7;
342 const static int RAYSUM_TRACE_ROW_SCATTER=8;
343 const static int RAYSUM_TRACE_ROW_PHOT_STAT=9;
344 const static int RAYSUM_TRACE_ROW_NDET=12;
345 const static int RAYSUM_TRACE_ROW_NVIEW=13;
346 const static int RAYSUM_TRACE_ROW_SAMPLES=14;
347 const static int RAYSUM_TRACE_ROW_CURR_VIEW=17;
348 const static int RAYSUM_TRACE_ROW_ATTEN=18;
351 /*************************************************************************
352 * FUNCTION DECLARATIONS
353 ************************************************************************/
355 void usage (const char *program);
357 /* From reconstr.c */
358 IMAGE *image_reconst (IMAGE *im, RAYSUM *rs, int filt_type, double filt_param, int interp_type, int interp_param, const int backproj_type, int ir_trace);
361 void backproj_init (const RAYSUM *rs, IMAGE *im, const BackprojType bproj_method);
362 int backproj_calc (const RAYSUM *rs, IMAGE *im, const double *t, const double view_angle,
363 const int interp_type, const int bproj_method);
364 void backproj_term (const RAYSUM *rs, IMAGE *im, const int bproj_method);
366 void backproj_init_trig (const RAYSUM *rs, IMAGE *im);
367 int backproj_calc_trig (const RAYSUM *rs, IMAGE *im, const double *t,
368 const double view_angle, const int interp_type);
369 void backproj_term_trig (const RAYSUM *rs, IMAGE *im);
370 void backproj_init_table (const RAYSUM *rs, IMAGE *im);
371 int backproj_calc_table (const RAYSUM *rs, IMAGE *im, const double *t,
372 const double view_angle, const int interp_type);
373 void backproj_term_table (const RAYSUM *rs, IMAGE *im);
374 void backproj_init_d (const RAYSUM *rs, IMAGE *im);
375 int backproj_calc_d (const RAYSUM *rs, IMAGE *im, const double *t,
376 const double view_angle, const int interp_type);
377 void backproj_term_d (const RAYSUM *rs, IMAGE *im);
378 void backproj_init_d2 (const RAYSUM *rs, IMAGE *im);
379 int backproj_calc_d2 (const RAYSUM *rs, IMAGE *im, const double *t,
380 const double view_angle, const int interp_type);
381 void backproj_term_d2 (const RAYSUM *rs, IMAGE *im);
382 void backproj_init_id (const RAYSUM *rs, IMAGE *im);
383 int backproj_calc_id (const RAYSUM *rs, IMAGE *im, const double *t,
384 const double view_angle, const int interp_type);
385 void backproj_term_id (const RAYSUM *rs, IMAGE *im);
386 void backproj_init_id2 (const RAYSUM *rs, IMAGE *im);
387 int backproj_calc_id2 (const RAYSUM *rs, IMAGE *im, const double *t,
388 const double view_angle, const int interp_type);
389 void backproj_term_id2 (const RAYSUM *rs, IMAGE *im);
392 int bspline(int samples, int zoom_factor, int spline_order, double input[], double output[]);
395 double convolve(const double f1[], const double f2[], const double dx, const int n, const int np, const FunctionSymmetry func_type);
396 double convolve_both(const double f1[], const double f2[], const double dx, const int n, const int np);
399 int phm_add_pelm_kb(PHANTOM *phm);
400 PHANTOM *phm_select(void);
401 int interpolation_select(void);
402 int filter_select(double *filter_param);
405 double *filter_generate(const FilterType filt_type, double bw, double xmin, double xmax, int n, double param, DomainType domain, int numint);
406 double filter_spatial_response_calc(int filt_type, double x, double bw, double param, int n);
407 double filter_spatial_response_analytic(int filt_type, double x, double bw, double param);
408 double filter_frequency_response(int filt_type, double u, double bw, double param);
409 double sinc(double x, double mult);
410 double integral_abscos(double u, double w);
413 IMAGE *image_create(const char *fname, const int nx, const int ny);
414 int image_clear(IMAGE *im);
415 int image_save(IMAGE *im);
416 IMAGE *image_load(const char *fname);
417 void image_filter_response(IMAGE *im, int domain, double bw, int filt_type, double filt_param, int opt_trace);
420 int opt_set_trace(const char *optarg, const char *program);
421 const char *name_of_phantom(const int phmid);
422 int opt_set_phantom(const char *optarg, const char *program);
423 int opt_set_interpolation(const char *optarg, const char *program);
424 const char *name_of_interpolation(int interp_type);
425 int opt_set_filter(const char *optarg, const char *program);
426 const char *name_of_filter(const int filter);
427 DomainType opt_set_filter_domain(const char *optarg, const char *program);
428 const char *name_of_filter_domain(const DomainType domain);
429 int opt_set_backproj(const char *optarg, const char *program);
430 const char *name_of_backproj(const BackprojType backproj);
433 PHANTOM *phm_create(const int phmid);
434 PHANTOM *phm_create_from_file(const char *fname);
435 PHANTOM *phm_init(void);
436 int phm_add_pelm_file(PHANTOM *phm, const char *fname);
437 void phm_add_pelm (PHANTOM *phm, const char *type, const double cx, const double cy,
438 const double u, const double v, const double rot, const double atten);
439 int pelm_make_points(PELM *obj);
440 void pelm_make_xform (PELM *obj);
441 PELM *pelm_alloc(void);
442 void calc_arc(double x[], double y[], const int pts, const double xcent, const double ycent,
443 const double r, const double start, const double stop);
444 void calc_ellipse(double x[], double y[], const int pts, const double u, const double v);
445 int circle_pts(double theta);
446 void phm_print(PHANTOM *phm);
447 #if HAVE_INTERACTIVE_GRAPHICS
448 void phm_show(const PHANTOM *phm);
449 void phm_draw(const PHANTOM *phm);
453 void phm_to_image(const PHANTOM *phm, IMAGE *im, const int col_start, const int col_count,
454 const int nsample, const int trace);
455 int pelm_is_point_inside(PELM *obj, const double x, const double y, const CoordType coord_type);
458 void phm_std_herman (PHANTOM *phm);
459 void phm_std_rowland (PHANTOM *phm);
460 void phm_std_rowland_bordered (PHANTOM *phm);
463 int raysum_collect(RAYSUM *rs, const DETECTOR *det, const PHANTOM *phm, const int start_view, const int trace, const int unit_pulse);
464 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);
465 double phm_ray_attenuation (const PHANTOM *phm, const double x1, const double y1, const double x2, const double y2);
466 double pelm_ray_attenuation (PELM *pelm, const double x1, const double y1, const double x2, const double y2);
467 int pelm_clip_line (const PELM *pelm, double *x1, double *y1, double *x2, double *y2);
468 void raysum_trace_show_param (const char *label, const char *fmt, int row, int color, ...);
471 DETECTOR *detector_create(const PHANTOM *phm, int geometry, int ndet, int nview, int nsample, const double rot_anglen);
472 void detector_free(DETECTOR *det);
475 RAYSUM *raysum_create(const char *fname, const int nview, const int ndet);
476 RAYSUM *raysum_create_from_det(const char *fname, const DETECTOR *det);
477 RAYSUM *raysum_open(const char *filename);
478 void raysum_alloc_views(RAYSUM *rs);
479 void raysum_free(RAYSUM *rs);
480 int raysum_is_open(RAYSUM *rs);
481 int raysum_close(RAYSUM *rs);
482 int raysum_read_header(RAYSUM *rs);
483 int raysum_write_header(RAYSUM *rs);
484 int raysum_read(RAYSUM *rs);
485 int raysum_write(RAYSUM *rs);
486 DETARRAY *detarray_alloc(const int n);
487 void detarray_free(DETARRAY *darray);
488 int detarray_read(RAYSUM *rs, DETARRAY *darray, const int view_num);
489 int detarray_write(RAYSUM *rs, const DETARRAY *darray, const int view_num);
490 int raysum_print(const RAYSUM *rs);
494 #endif /* __cplusplus */