1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ir.h,v 1.10 2000/05/04 18:16:34 kevin Exp $
7 ** Revision 1.10 2000/05/04 18:16:34 kevin
8 ** renamed filter definitions
10 ** Revision 1.9 2000/05/04 04:29:18 kevin
11 ** *** empty log message ***
13 ** Revision 1.8 2000/05/04 04:25:55 kevin
14 ** Renamed phantom and phantom-element functions/variables
16 ** Revision 1.7 2000/05/03 19:51:41 kevin
17 ** function renaming for phantoms and phantom elements
19 ** Revision 1.6 2000/05/03 08:49:49 kevin
22 ** Revision 1.5 2000/05/02 20:00:25 kevin
23 ** *** empty log message ***
25 ** Revision 1.4 2000/05/02 15:31:39 kevin
28 ** Revision 1.3 2000/04/29 23:24:29 kevin
29 ** *** empty log message ***
31 ** Revision 1.2 2000/04/28 14:14:16 kevin
32 ** *** empty log message ***
34 ** Revision 1.1.1.1 2000/04/28 13:02:43 kevin
35 ** Initial CVS import for first public release
39 ** This program is free software; you can redistribute it and/or modify
40 ** it under the terms of the GNU General Public License (version 2) as
41 ** published by the Free Software Foundation.
43 ** This program is distributed in the hope that it will be useful,
44 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 ** GNU General Public License for more details.
48 ** You should have received a copy of the GNU General Public License
49 ** along with this program; if not, write to the Free Software
50 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
51 ******************************************************************************/
52 /* FILE IDENTIFICATION
54 * Name: ir.h Header File for Image Reconstruction System
55 * Programmer: Kevin Rosenberg
56 * Date Started: 7-1-84
57 * Last Change: 1-20-85
64 #define MPI_MAX_PROCESS 128
69 int base_local_work_units;
70 int remainder_work_units;
71 int local_work_units[MPI_MAX_PROCESS];
72 int start_work_unit[MPI_MAX_PROCESS];
76 extern struct mpi_ct_st mpi_ct;
77 void mpi_ct_calc_work_units(const unsigned int global_work_units);
82 int *b; /* Histogram array (# of elements in each bin) */
83 int nbin; /* Number of histogram bins */
84 double xmin, xmax, xinc; /* Limits of histogram boundaries */
87 typedef struct histo_st HISTOGRAM;
89 /*---------------------------------------------------------------------------*/
91 #define POINTS_PER_CIRCLE 36
94 #define LENREMARK (MAXREMARK+1)
95 #define IMAGE_VAL FMTX_2D /* use 2d floating point matrix */
96 #define IMAGE_ELEM_TYPE DT_FLOAT /* use floats for images */
97 typedef float IMAGE_ELEM_VAL; /* use floats for image storing */
100 IMAGE_VAL v; /* values of voxels in matrix form */
101 SDF_2D *dfp_2d; /* Pointer to disk image file */
102 int nx, ny; /* size of voxel matrix */
103 double xmin, xmax, ymin, ymax; /* extent of voxel matrix in phm coord */
104 char remark[LENREMARK]; /* description of voxel data */
105 float calctime; /* time to calculate voxels in seconds */
109 int type; /* phmelm type (box, ellipse, etc) */
110 double atten; /* X-ray attenuation coefficient */
111 double cx,cy; /* center of phmelm */
112 double u,v; /* size of phmelm */
113 double rot; /* phmelm rotation angle (in radians) */
114 double *x, *y; /* ptr to array of points in obj world coord */
115 int pts; /* number of points in outline arrays */
116 double xmin, xmax, ymin, ymax; /* phmelm limits */
117 double radius; /* " */
118 struct { /* transform matrices */
119 GRFMTX_2D p_to_o; /* map from phantom to standard phmelm coords */
120 GRFMTX_2D o_to_p; /* map from std phmelm coords to phantom coords */
122 struct phmelm_st *next; /* pointer to next phmelm in phantom */
125 typedef struct phmelm_st PHMELM;
127 struct phm_st { /* Phantom structure */
128 PHMELM *phmelm_list; /* phmelm linked-list */
130 int n_pelm; /* number of phmelms in phantom */
131 double xmin, xmax, ymin, ymax; /* extent of phmelms in phmelm coordinates */
132 double radius; /* " " */
135 typedef struct image_st IMAGE;
136 typedef struct phm_st PHANTOM;
138 #define P_PHMELMS 0 /* Phantom made of phmelms */
139 #define P_UNIT_PULSE 1 /* Special PHANTOM, not made of phmelms */
140 #define P_FILTER 9 /* defined only by a type */
142 /*----------------------------------------------------------------------*/
144 /*----------------------------------------------------------------------*/
146 /* Ray sums are collected along an array of ndet detectors. The data
147 * for these detectors is stored in the structure DETECTARRAY
150 #define DETECT_TYPE float
153 DETECT_TYPE *detval; /* Pointer to array of values recorded by detector */
154 int ndet; /* Number of detectors in array */
155 double view_angle; /* View angle in radians */
158 #define DETECTOR_PARALLEL 1
159 #define DETECTOR_EQUIANGLE 2
160 #define DETECTOR_EQUILINEAR 3
163 int geometry; /* Geometry of detectory */
164 int ndet; /* Number of detectors in array */
165 int nview; /* Number of rotated views */
166 int nsample; /* Number of rays per detector */
167 double detlen; /* Total length of detector array */
168 double rotlen; /* Rotation angle length in radians (norm 2PI) */
169 double det_inc; /* Increment between centers of detectors */
170 double rot_inc; /* Increment in rotation angle between views */
171 double radius; /* Radius of rotation. Distance from */
172 /* center of phm to center of det */
173 double phmlen; /* Maximum Length of PHANTOM or area of interest */
175 double xd1,yd1,xd2,yd2; /* Coordinates of detector endpoints */
176 double xs1,ys1,xs2,ys2; /* Coordinates of source endpoints */
177 double angle; /* Starting angle */
186 struct detarray_st **view; /* Pointer to array of detarray_st pointers */
188 char remark[LENREMARK]; /* description of raysum data */
189 double calctime; /* time required to calculate raysums */
191 int ndet; /* number of detectors in array */
192 int nview; /* number of rotated views */
193 double rot_start; /* starting view rotation */
194 double rot_inc; /* angle between rotations */
195 double det_start; /* distance of beginning detector to center */
197 double det_inc; /* increment between detectors */
198 double phmlen; /* Length of PHANTOM edge (phm is square) */
201 typedef struct detarray_st DETARRAY;
202 typedef struct detector_st DETECTOR;
203 typedef struct raysum_st RAYSUM;
205 /*----------------------------------------------------------------------*/
207 /*----------------------------------------------------------------------*/
209 /* codes for phmelm types, passed to add_obj() */
211 #define O_RECTANGLE 1
217 /* Codes for Coordinate Types */
218 /* Defines coords for pelm_is_point_inside() */
220 #define PELM_COORD -1 /* Normalized Phmelm Coordinates */
221 #define PHM_COORD -2 /* User's PHANTOM Coordinates */
223 /* Codes for Filter types */
225 #define FILTER_BANDLIMIT 1 /* filter types for genfilter() */
226 #define FILTER_SINC 2
227 #define FILTER_G_HAMMING 3
228 #define FILTER_COSINE 4
229 #define FILTER_TRIANGLE 5
230 #define FILTER_ABS_BANDLIMIT 11 /* filters times abs() of function */
231 #define FILTER_ABS_SINC 12
232 #define FILTER_ABS_G_HAMMING 13
233 #define FILTER_ABS_COSINE 14
234 #define FILTER_SHEPP 21
236 /* function domains */
238 #define O_FREQ_STR "freq"
239 #define O_SPATIAL_STR "spatial"
241 #define D_FREQ 1 /* Domain names */
244 /* function symmetry */
246 #define FUNC_EVEN 1 /* function types, f[-n] = f[n] */
247 #define FUNC_ODD 2 /* f[-n] = -f[n] */
248 #define FUNC_BOTH 3 /* function has both odd & even components */
250 /* interpolation methods */
252 #define I_NEAREST 1 /* Interpolation methods */
253 #define I_LINEAR 2 /* Linear interpolation */
255 #define I_1BSPLINE 3 /* 1st order B-Spline */
259 /* Constants for sizing PHANTOM */
261 #define PERCENT_PHM_SIZE_INCR 0.0 /* Fractional increase in PHANTOM */
262 /* limits compared to phmelm size */
263 #define N_EXTRA_DETECTORS 4 /* Number of extra detectors */
264 /* widths when calculating detlen */
266 #define O_TRACE_NONE_STR "none"
267 #define O_TRACE_TEXT_STR "text"
268 #define O_TRACE_PHM_STR "phm"
269 #define O_TRACE_RAYS_STR "rays"
270 #define O_TRACE_PLOT_STR "plot"
271 #define O_TRACE_CLIPPING_STR "clipping"
274 #define TRACE_NONE 0 /* No tracing */
275 #define TRACE_TEXT 1 /* Minimal status */
276 #define TRACE_PHM 2 /* Show PHANTOM */
277 #define TRACE_RAYS 3 /* Show all rays */
278 #define TRACE_PLOT 4 /* Plot raysums */
279 #define TRACE_CLIPPING 5 /* Plot clipping */
281 #define O_PHM_HERMAN 1 /* Herman head phantom */
282 #define O_PHM_ROWLAND 2 /* Rowland head phantom */
283 #define O_PHM_BROWLAND 3 /* Bordered Rowland head phantom */
284 #define O_PHM_UNITPULSE 4 /* Unit pulse phantom */
286 #define O_PHM_HERMAN_STR "herman"
287 #define O_PHM_ROWLAND_STR "rowland"
288 #define O_PHM_BROWLAND_STR "browland"
289 #define O_PHM_UNITPULSE_STR "unitpulse"
291 #define O_INTERP_NEAREST_STR "nearest"
292 #define O_INTERP_LINEAR_STR "linear"
293 #define O_INTERP_BSPLINE_STR "bspline"
295 #define O_FILTER_ABS_BANDLIMIT_STR "abs_bandlimit"
296 #define O_FILTER_ABS_SINC_STR "abs_sinc"
297 #define O_FILTER_ABS_COS_STR "abs_cos"
298 #define O_FILTER_ABS_HAMMING_STR "abs_hamming"
299 #define O_FILTER_SHEPP_STR "shepp"
300 #define O_FILTER_BANDLIMIT_STR "bandlimit"
301 #define O_FILTER_SINC_STR "sinc"
302 #define O_FILTER_COS_STR "cos"
303 #define O_FILTER_HAMMING_STR "hamming"
304 #define O_FILTER_TRIANGLE_STR "triangle"
306 #define O_BPROJ_TRIG 1
307 #define O_BPROJ_TABLE 2
308 #define O_BPROJ_DIFF 3
309 #define O_BPROJ_DIFF2 4
310 #define O_BPROJ_IDIFF2 5
312 #define O_BPROJ_TRIG_STR "trig"
313 #define O_BPROJ_TABLE_STR "table"
314 #define O_BPROJ_DIFF_STR "diff"
315 #define O_BPROJ_DIFF2_STR "diff2"
316 #define O_BPROJ_IDIFF2_STR "idiff2"
318 #define RAYSUM_TRACE_ROW_TITLE 1
319 #define RAYSUM_TRACE_ROW_TITLE2 2
320 #define RAYSUM_TRACE_ROW_PHANT_ID 4
321 #define RAYSUM_TRACE_ROW_CHROMATIC 7
322 #define RAYSUM_TRACE_ROW_SCATTER 8
323 #define RAYSUM_TRACE_ROW_PHOT_STAT 9
324 #define RAYSUM_TRACE_ROW_NDET 12
325 #define RAYSUM_TRACE_ROW_NVIEW 13
326 #define RAYSUM_TRACE_ROW_SAMPLES 14
327 #define RAYSUM_TRACE_ROW_CURR_VIEW 17
328 #define RAYSUM_TRACE_ROW_ATTEN 18
331 /*----------------------------------------------------------------------*/
332 /* GRAY SCALE STRUCTURES */
333 /*----------------------------------------------------------------------*/
335 #define GS_MAX_CELL_SIZE 4
337 typedef int GS_BITMASK[4][4];
339 struct greyscale_st {
340 int dev; /* Device to output to */
341 int (*dotfunc)(int x, int y, int color); /* Pointer to dot function for device */
342 int cur_x, cur_y; /* Current cell location */
343 int nxcell, nycell; /* size of cell in pixels */
344 int xmin, ymin; /* starting position of grey scale */
345 int num_color; /* Number of primary colors available */
346 int num_intens; /* Number of intensities available */
347 int max_level; /* gs levels range from 0 to max_level */
348 char *fg_color_tbl; /* Hold foreground color for each level */
349 char *bg_color_tbl; /* Holds background color */
350 char *level_sub_tbl; /* Holds value to subtract for level */
351 /* before accessing bit mask */
352 GS_BITMASK *bm; /* Holds grey-scale bit mask */
353 struct greyscale_st *next_dev; /* Pointer to next open device */
354 /* == NULL when no more devices */
357 typedef struct greyscale_st GREYSCALE;
360 /* From reconstr.c */
361 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);
364 void backproj_init (const RAYSUM *rs, IMAGE *im, const int bproj_method);
365 int backproj_calc (const RAYSUM *rs, IMAGE *im, const double *t, const double view_angle,
366 const int interp_type, const int bproj_method);
367 void backproj_term (const RAYSUM *rs, IMAGE *im, const int bproj_method);
369 void backproj_init_trig (const RAYSUM *rs, IMAGE *im);
370 int backproj_calc_trig (const RAYSUM *rs, IMAGE *im, const double *t,
371 const double view_angle, const int interp_type);
372 void backproj_term_trig (const RAYSUM *rs, IMAGE *im);
373 void backproj_init_table (const RAYSUM *rs, IMAGE *im);
374 int backproj_calc_table (const RAYSUM *rs, IMAGE *im, const double *t,
375 const double view_angle, const int interp_type);
376 void backproj_term_table (const RAYSUM *rs, IMAGE *im);
377 void backproj_init_d (const RAYSUM *rs, IMAGE *im);
378 int backproj_calc_d (const RAYSUM *rs, IMAGE *im, const double *t,
379 const double view_angle, const int interp_type);
380 void backproj_term_d (const RAYSUM *rs, IMAGE *im);
381 void backproj_init_d2 (const RAYSUM *rs, IMAGE *im);
382 int backproj_calc_d2 (const RAYSUM *rs, IMAGE *im, const double *t,
383 const double view_angle, const int interp_type);
384 void backproj_term_d2 (const RAYSUM *rs, IMAGE *im);
385 void backproj_init_id (const RAYSUM *rs, IMAGE *im);
386 int backproj_calc_id (const RAYSUM *rs, IMAGE *im, const double *t,
387 const double view_angle, const int interp_type);
388 void backproj_term_id (const RAYSUM *rs, IMAGE *im);
389 void backproj_init_id2 (const RAYSUM *rs, IMAGE *im);
390 int backproj_calc_id2 (const RAYSUM *rs, IMAGE *im, const double *t,
391 const double view_angle, const int interp_type);
392 void backproj_term_id2 (const RAYSUM *rs, IMAGE *im);
394 void usage (const char *program);
395 int main(const int argc, char * const argv[]);
400 int bspline(int samples, int zoom_factor, int spline_order, double input[], double output[]);
403 double convolve(const double f1[], const double f2[], const double dx, const int n, const int np, const int func_type);
404 double convolve_both(const double f1[], const double f2[], const double dx, const int n, const int np);
407 int phm_add_pelm_kb(PHANTOM *phm);
408 PHANTOM *phm_select(void);
409 int interpolation_select(void);
410 int filter_select(double *filter_param);
413 double *filter_generate(int filt_type, double bw, double xmin, double xmax, int n, double param, int domain, int numint);
414 double filter_spatial_response_calc(int filt_type, double x, double bw, double param, int n);
415 double filter_spatial_response_analytic(int filt_type, double x, double bw, double param);
416 double filter_frequency_response(int filt_type, double u, double bw, double param);
417 double sinc(double x, double mult);
418 double integral_abscos(double u, double w);
421 IMAGE *image_create(const char *fname, const int nx, const int ny);
422 int image_clear(IMAGE *im);
423 int image_save(IMAGE *im);
424 IMAGE *image_load(const char *fname);
425 void image_filter_response(IMAGE *im, int domain, double bw, int filt_type, double filt_param, int opt_trace);
428 int opt_set_trace(const char *optarg, const char *program);
429 const char *name_of_phantom(const int phmid);
430 int opt_set_phantom(const char *optarg, const char *program);
431 int opt_set_interpolation(const char *optarg, const char *program);
432 const char *name_of_interpolation(int interp_type);
433 int opt_set_filter(const char *optarg, const char *program);
434 const char *name_of_filter(const int filter);
435 int opt_set_filter_domain(const char *optarg, const char *program);
436 const char *name_of_filter_domain(const int domain);
437 int opt_set_backproj(const char *optarg, const char *program);
438 const char *name_of_backproj(const int backproj);
441 PHANTOM *phm_create(const int phmid);
442 PHANTOM *phm_create_from_file(const char *fname);
443 PHANTOM *phm_init(void);
444 int phm_add_pelm_file(PHANTOM *phm, const char *fname);
445 void phm_add_pelm (PHANTOM *phm, const int type, const double cx, const double cy,
446 const double u, const double v, const double rot, const double atten);
447 int pelm_make_points(PHMELM *obj);
448 void pelm_make_xform (PHMELM *obj);
449 PHMELM *pelm_alloc(void);
450 void calc_arc(double x[], double y[], const int pts, const double xcent, const double ycent,
451 const double r, const double start, const double stop);
452 void calc_ellipse(double x[], double y[], const int pts, const double u, const double v);
453 int circle_pts(double theta);
454 void phm_print(PHANTOM *phm);
455 #if HAVE_INTERACTIVE_GRAPHICS
456 void phm_show(const PHANTOM *phm);
457 void phm_draw(const PHANTOM *phm);
461 void phm_to_image(const PHANTOM *phm, IMAGE *im, const int col_start, const int col_count,
462 const int nsample, const int trace);
463 int pelm_is_point_inside(const PHMELM *obj, double x, double y, const int coord_type);
466 void phm_std_herman (PHANTOM *phm);
467 void phm_std_rowland (PHANTOM *phm);
468 void phm_std_rowland_bordered (PHANTOM *phm);
471 int raysum_collect(RAYSUM *rs, const DETECTOR *det, const PHANTOM *phm, const int start_view, const int trace, const int unit_pulse);
472 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);
473 double phm_ray_attenuation (const PHANTOM *phm, const double x1, const double y1, const double x2, const double y2);
474 double pelm_ray_attenuation (const PHMELM *obj, const double x1, const double y1, const double x2, const double y2);
475 int pelm_clip_line (const PHMELM *obj, double *x1, double *y1, double *x2, double *y2);
476 void raysum_trace_show_param (const char *label, const char *fmt, int row, int color, ...);
479 DETECTOR *detector_create(const PHANTOM *phm, int geometry, int ndet, int nview, int nsample, const double rot_anglen);
480 void detector_free(DETECTOR *det);
483 RAYSUM *raysum_create(const char *fname, const int nview, const int ndet);
484 RAYSUM *raysum_create_from_det(const char *fname, const DETECTOR *det);
485 RAYSUM *raysum_open(const char *filename);
486 void raysum_alloc_views(RAYSUM *rs);
487 void raysum_free(RAYSUM *rs);
488 int raysum_is_open(RAYSUM *rs);
489 int raysum_close(RAYSUM *rs);
490 int raysum_read_header(RAYSUM *rs);
491 int raysum_write_header(RAYSUM *rs);
492 int raysum_read(RAYSUM *rs);
493 int raysum_write(RAYSUM *rs);
494 DETARRAY *detarray_alloc(const int n);
495 void detarray_free(DETARRAY *darray);
496 int detarray_read(RAYSUM *rs, DETARRAY *darray, const int view_num);
497 int detarray_write(RAYSUM *rs, const DETARRAY *darray, const int view_num);
498 int raysum_print(const RAYSUM *rs);