X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fctrec.c;h=01874dd82b8aecaa2c71896645102221af8b121b;hb=8f6d22c1d18c183cfcb95ca97cea85cbae0ab6c3;hp=56297d2af3dd494c7ba419ce48e0fc85e9b70cda;hpb=13838bda88b63a2535b5baaf7197006767de4b8e;p=ctsim.git diff --git a/src/ctrec.c b/src/ctrec.c index 56297d2..01874dd 100644 --- a/src/ctrec.c +++ b/src/ctrec.c @@ -2,10 +2,45 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctrec.c,v 1.1 2000/04/28 13:02:44 kevin Exp $ +** $Id: ctrec.c,v 1.12 2000/05/24 22:50:04 kevin Exp $ ** $Log: ctrec.c,v $ -** Revision 1.1 2000/04/28 13:02:44 kevin -** Initial revision +** Revision 1.12 2000/05/24 22:50:04 kevin +** Added support for new SGP library +** +** Revision 1.11 2000/05/16 04:33:59 kevin +** Improved option processing +** +** Revision 1.10 2000/05/11 01:06:30 kevin +** Changed sprintf to snprintf +** +** Revision 1.9 2000/05/08 20:02:32 kevin +** ANSI C changes +** +** Revision 1.8 2000/05/04 18:16:34 kevin +** renamed filter definitions +** +** Revision 1.7 2000/05/03 08:49:50 kevin +** Code cleanup +** +** Revision 1.6 2000/05/02 15:31:47 kevin +** code cleaning +** +** Revision 1.5 2000/04/30 11:41:06 kevin +** Cleaned up debugging code +** +** Revision 1.4 2000/04/30 10:13:27 kevin +** Fixed MPI bugs +** +** Revision 1.3 2000/04/30 04:06:13 kevin +** Update Raysum i/o routines +** Fix MPI bug in ctrec (scatter_raysum) that referenced rs_global +** +** Revision 1.2 2000/04/29 23:24:56 kevin +** *** empty log message *** +** +** Revision 1.1.1.1 2000/04/28 13:02:44 kevin +** Initial CVS import for first public release +** ** ** ** This program is free software; you can redistribute it and/or modify @@ -21,6 +56,7 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ + /* FILE * ctrec.c Reconstruct an image from raysums * @@ -32,15 +68,7 @@ #include "ct.h" -#define O_INTERP 1 -#define O_FILTER 2 -#define O_FILTER_PARAM 3 -#define O_BACKPROJ 4 -#define O_VERBOSE 5 -#define O_TRACE 6 -#define O_HELP 7 -#define O_DEBUG 8 -#define O_VERSION 9 +enum {O_INTERP, O_FILTER, O_FILTER_PARAM, O_BACKPROJ, O_VERBOSE, O_TRACE, O_HELP, O_DEBUG, O_VERSION}; static struct option my_options[] = { @@ -57,7 +85,7 @@ static struct option my_options[] = }; void -usage (const char *program) +ctrec_usage (const char *program) { fprintf(stdout,"usage: %s raysum-file image-file nx-image ny-image [OPTIONS]\n", kbasename(program)); fprintf(stdout,"Image reconstruction from raysum projections\n"); @@ -90,8 +118,8 @@ usage (const char *program) fprintf(stdout," --filter-param Alpha level for Hamming filter\n"); fprintf(stdout," --trace Set tracing to level\n"); fprintf(stdout," none No tracing (default)\n"); - fprintf(stdout," status Status tracing\n"); - fprintf(stdout," pic Trace picture\n"); + fprintf(stdout," text Text level tracing\n"); + fprintf(stdout," phm Trace phantom\n"); fprintf(stdout," rays Trace allrays\n"); fprintf(stdout," plot Trace plotting\n"); fprintf(stdout," clipping Trace clipping\n"); @@ -99,41 +127,41 @@ usage (const char *program) fprintf(stdout," --debug Turn on debug mode\n"); fprintf(stdout," --version Print version\n"); fprintf(stdout," --help Print this help message\n"); - exit(1); } #ifdef MPI_CT -void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int debug); +static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int debug); #endif -void print_raysum_info(const RAYSUM *rs); + +static void print_raysum_info(const RAYSUM *rs); int -main (const int argc, char *const argv[]) +ctrec_main (const int argc, char *const argv[]) { - IMAGE *im_global; - RAYSUM *rs_global; - char *rs_name, *im_filename; + IMAGE *im_global = NULL; + RAYSUM *rs_global = NULL; + char *rs_name, *im_filename = NULL; char remark[MAXREMARK]; char filt_name[80]; int nx, ny; - double time_start, time_end; + double time_start = 0, time_end = 0; char *endptr; int opt_verbose = 0; int opt_debug = 0; int opt_trace = TRACE_NONE; - double opt_filter_param; - int opt_filter = W_A_BANDLIMIT; + double opt_filter_param = 1; + int opt_filter = FILTER_ABS_BANDLIMIT; int opt_interp = I_LINEAR; int opt_interp_param = 1; - int opt_backproj = O_BPROJ_DIFF2; + BackprojType opt_backproj = O_BPROJ_DIFF2; #ifdef MPI_CT IMAGE *im_local; RAYSUM *rs_local; int mpi_argc = argc; char **mpi_argv = (char **) argv; int mpi_nview, mpi_ndet; - double mpi_detinc, mpi_rotinc, mpi_piclen; + double mpi_detinc, mpi_rotinc, mpi_phmlen; double mpi_t1, mpi_t2, mpi_t, mpi_t_g; int ix; @@ -168,19 +196,27 @@ main (const int argc, char *const argv[]) switch (c) { case O_INTERP: - opt_interp = opt_set_interpolation(optarg, argv[0]); + if ((opt_interp = opt_set_interpolation(optarg)) < 0) { + ctrec_usage(argv[0]); + return (1); + } break; case O_FILTER: - opt_filter = opt_set_filter(optarg, argv[0]); + if ((opt_filter = opt_set_filter(optarg)) < 0) { + ctrec_usage(argv[0]); + return (1); + } break; case O_BACKPROJ: - opt_backproj = opt_set_backproj(optarg, argv[0]); + if ((opt_backproj = opt_set_backproj(optarg)) < 0) { + ctrec_usage(argv[0]); + return (1); + } break; case O_FILTER_PARAM: opt_filter_param = strtod(optarg, &endptr); if (endptr != optarg + strlen(optarg)) { - usage(argv[0]); - exit(1); + ctrec_usage(argv[0]); } break; case O_VERBOSE: @@ -190,7 +226,10 @@ main (const int argc, char *const argv[]) opt_debug = 1; break; case O_TRACE: - opt_trace = opt_set_trace(optarg, argv[0]); + if ((opt_trace = opt_set_trace(optarg)) < 0) { + ctrec_usage(argv[0]); + return (1); + } break; case O_VERSION: #ifdef VERSION @@ -201,17 +240,17 @@ main (const int argc, char *const argv[]) exit(0); case O_HELP: case '?': - usage(argv[0]); - exit(0); + ctrec_usage(argv[0]); + return (0); default: - usage(argv[0]); - exit(1); + ctrec_usage(argv[0]); + return (1); } } if (optind + 4 != argc) { - usage(argv[0]); - exit(1); + ctrec_usage(argv[0]); + return (1); } rs_name = argv[optind]; @@ -221,15 +260,14 @@ main (const int argc, char *const argv[]) nx = strtol(argv[optind + 2], &endptr, 10); ny = strtol(argv[optind + 3], &endptr, 10); - if (opt_filter == W_G_HAMMING || opt_filter == W_AG_HAMMING) - sprintf (filt_name, "%s: alpha = %.2f", - filter_name_of (opt_filter), opt_filter_param); + if (opt_filter == FILTER_G_HAMMING || opt_filter == FILTER_ABS_G_HAMMING) + snprintf (filt_name, sizeof(filt_name), "%s: alpha = %.2f", + name_of_filter (opt_filter), opt_filter_param); else - sprintf (filt_name, "%s", filter_name_of (opt_filter)); + snprintf (filt_name, sizeof(filt_name), "%s", name_of_filter (opt_filter)); - sprintf (remark, - "Reconstruct: %dx%d, %s, %s, %s", - nx, ny, filt_name, interp_name_of (opt_interp), name_of_backproj(opt_backproj)); + snprintf (remark, sizeof(remark), "Reconstruct: %dx%d, %s, %s, %s", + nx, ny, filt_name, name_of_interpolation (opt_interp), name_of_backproj(opt_backproj)); if (opt_verbose) fprintf (stdout, "%s\n", remark); @@ -239,27 +277,18 @@ main (const int argc, char *const argv[]) #ifdef MPI_CT if (mpi_ct.my_rank == 0) { - if (file_exists(rs_name) == FALSE) { - fprintf (stderr, "File %s does not exist\n", rs_name); - exit(1); - } rs_global = raysum_open (rs_name); raysum_read (rs_global); - print_raysum_info(rs_global); - if (opt_verbose) { - printf ("Number of detectors: %d\n", rs_global->ndet); - printf (" Number of views: %d\n", rs_global->nview); - printf (" Remark: %s\n", rs_global->remark); - } - + if (opt_verbose) + print_raysum_info(rs_global); + mpi_ndet = rs_global->ndet; mpi_nview = rs_global->nview; mpi_detinc = rs_global->det_inc; - mpi_piclen = rs_global->piclen; + mpi_phmlen = rs_global->phmlen; mpi_rotinc = rs_global->rot_inc; } - mpi_t1 = MPI_Wtime(); MPI_Bcast(&opt_verbose, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&opt_debug, 1, MPI_INT, 0, mpi_ct.comm); @@ -272,7 +301,7 @@ main (const int argc, char *const argv[]) MPI_Bcast(&mpi_ndet, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&mpi_nview, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&mpi_detinc, 1, MPI_DOUBLE, 0, mpi_ct.comm); - MPI_Bcast(&mpi_piclen, 1, MPI_DOUBLE, 0, mpi_ct.comm); + MPI_Bcast(&mpi_phmlen, 1, MPI_DOUBLE, 0, mpi_ct.comm); MPI_Bcast(&mpi_rotinc, 1, MPI_DOUBLE, 0, mpi_ct.comm); MPI_Bcast(&nx, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&ny, 1, MPI_INT, 0, mpi_ct.comm); @@ -286,17 +315,14 @@ main (const int argc, char *const argv[]) mpi_ct_calc_work_units(mpi_nview); - rs_local = raysum_create (NULL, mpi_ct.local_work_units[mpi_ct.my_rank], mpi_ndet, TRUE); - // rs_local->ndet = mpi_ndet; - // rs_local->nview = mpi_nview; + rs_local = raysum_create (NULL, mpi_ct.local_work_units[mpi_ct.my_rank], mpi_ndet); + + rs_local->ndet = mpi_ndet; + rs_local->nview = mpi_nview; rs_local->det_inc = mpi_detinc; - rs_local->piclen = mpi_piclen; + rs_local->phmlen = mpi_phmlen; rs_local->rot_inc = mpi_rotinc; - if (opt_debug) - fprintf(stderr, "Bcast'd rs vars, my nview=%d, local_work_units=%d, start_work_units=%d (process %d)\n", - mpi_nview, mpi_ct.local_work_units[mpi_ct.my_rank], mpi_ct.start_work_unit[mpi_ct.my_rank], mpi_ct.my_rank); - if (opt_verbose) mpi_t1 = MPI_Wtime(); mpi_scatter_rs(rs_global, rs_local, opt_debug); @@ -318,7 +344,7 @@ main (const int argc, char *const argv[]) #else rs_global = raysum_open (rs_name); raysum_read (rs_global); - if (opt_debug) + if (opt_verbose) print_raysum_info(rs_global); im_global = image_create (im_filename, nx, ny); @@ -333,25 +359,25 @@ main (const int argc, char *const argv[]) mpi_t2 = MPI_Wtime(); mpi_t = mpi_t2 - mpi_t1; MPI_Reduce(&mpi_t, &mpi_t_g, 1, MPI_DOUBLE, MPI_MAX, 0, mpi_ct.comm); - if (mpi_ct.my_rank == 0) { + if (mpi_ct.my_rank == 0 && opt_verbose) printf("Time to reconstruct = %f, Max time = %f\n", mpi_t, mpi_t_g); - } #else image_reconst (im_global, rs_global, opt_filter, opt_filter_param, opt_interp, opt_interp_param, opt_backproj, opt_trace); #endif #ifdef MPI_CT - if (mpi_ct.my_rank == 0) { - raysum_close (rs_global); - } - if (opt_verbose) mpi_t1 = MPI_Wtime(); + for (ix = 0; ix < im_local->nx; ix++) { - MPI_Reduce(im_local->v[ix], im_global->v[ix], - im_local->ny, MPI_FLOAT, MPI_SUM, 0, mpi_ct.comm); + void *recvbuf = NULL; + if (mpi_ct.my_rank == 0) + recvbuf = im_global->v[ix]; + + MPI_Reduce(im_local->v[ix], recvbuf, im_local->ny, MPI_FLOAT, MPI_SUM, 0, mpi_ct.comm); } + if (opt_verbose) { mpi_t2 = MPI_Wtime(); mpi_t = mpi_t2 - mpi_t1; @@ -359,25 +385,26 @@ main (const int argc, char *const argv[]) if (mpi_ct.my_rank == 0) printf("Time to reduce image = %f secs, max time = %f\n", mpi_t, mpi_t_g); } - if (mpi_ct.my_rank == 0) { - strncpy (im_global->remark, remark, MAXREMARK); - image_save (im_global); - time_end = MPI_Wtime(); - im_global->calctime = time_end - time_start; - if (opt_verbose) - fprintf (stdout, "Time active = %.2f\n", im_global->calctime); - } -#else - raysum_close (rs_global); - strncpy (im_global->remark, remark, MAXREMARK); - image_save (im_global); + if (mpi_ct.my_rank == 0) + time_end = MPI_Wtime(); +#else time_end = td_current_sec(); - im_global->calctime = time_end - time_start; - if (opt_verbose) - fprintf (stdout, "Time active = %.2f secs\n", im_global->calctime); #endif + +#ifdef MPI_CT + if (mpi_ct.my_rank == 0) +#endif + { + raysum_close (rs_global); + strncpy (im_global->remark, remark, sizeof(im_global->remark)); + im_global->calctime = time_end - time_start; + image_save (im_global); + if (opt_verbose) + fprintf (stdout, "Time active = %.2f\n", im_global->calctime); + } + #ifdef MPI_CT MPI_Finalize(); #endif @@ -387,50 +414,61 @@ main (const int argc, char *const argv[]) #ifdef MPI_CT -void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug) +static void mpi_scatter_rs (RAYSUM *rs_global, RAYSUM *rs_local, const int opt_debug) { int iproc; int end_work_unit; - int iw; + int iw = 0; if (mpi_ct.my_rank == 0) { for (iproc = 0; iproc < mpi_ct.nproc; iproc++) { - end_work_unit = mpi_ct.start_work_unit[iproc] - + mpi_ct.local_work_units[iproc] - - 1; - - if (opt_debug) - fprintf(stdout, "Sending rs data to process %d\n", iproc); + end_work_unit = mpi_ct.start_work_unit[iproc] + mpi_ct.local_work_units[iproc] - 1; for (iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) { - MPI_Send(&rs_global->view[iw]->view_angle, 1, MPI_DOUBLE, iproc, 0, mpi_ct.comm); MPI_Send(&rs_global->view[iw]->ndet, 1, MPI_INT, iproc, 0, mpi_ct.comm); + MPI_Send(&rs_global->view[iw]->view_angle, 1, MPI_DOUBLE, iproc, 0, mpi_ct.comm); MPI_Send(rs_global->view[iw]->detval, rs_global->ndet, MPI_FLOAT, iproc, 0, mpi_ct.comm); } } } + if (opt_debug) + fprintf(stdout, "Receiving rs data in process %d\n", mpi_ct.my_rank); + end_work_unit = mpi_ct.local_work_units[mpi_ct.my_rank] - 1; for (iw = 0; iw <= end_work_unit; iw++) { MPI_Status status; - MPI_Recv(&rs_local->view[iw]->view_angle, 1, MPI_DOUBLE, 0, 0, mpi_ct.comm, &status); MPI_Recv(&rs_local->view[iw]->ndet, 1, MPI_INT, 0, 0, mpi_ct.comm, &status); - MPI_Recv(rs_local->view[iw]->detval, rs_global->ndet, MPI_FLOAT, 0, 0, mpi_ct.comm, &status); + MPI_Recv(&rs_local->view[iw]->view_angle, 1, MPI_DOUBLE, 0, 0, mpi_ct.comm, &status); + MPI_Recv(rs_local->view[iw]->detval, rs_local->ndet, MPI_FLOAT, 0, 0, mpi_ct.comm, &status); } rs_local->nview = mpi_ct.local_work_units[mpi_ct.my_rank]; + if (opt_debug) { + MPI_Barrier(MPI_COMM_WORLD); + fprintf(stdout, "Done with mpi_scatter_rs in process %2d\n", mpi_ct.my_rank); + } } #endif -void print_raysum_info(const RAYSUM *rs) +static void print_raysum_info(const RAYSUM *rs) { printf ("Number of detectors: %d\n", rs->ndet); printf (" Number of views: %d\n", rs->nview); printf (" Remark: %s\n", rs->remark); - printf ("Piclen: %f\n", rs->piclen); - printf ("det_start: %f\n", rs->det_start); - printf ("det_inc: %f\n", rs->det_inc); - printf ("rot_start: %f\n", rs->rot_start); - printf ("rot_inc: %f\n", rs->rot_inc); + printf (" phmlen: %f\n", rs->phmlen); + printf (" det_start: %f\n", rs->det_start); + printf (" det_inc: %f\n", rs->det_inc); + printf (" rot_start: %f\n", rs->rot_start); + printf (" rot_inc: %f\n", rs->rot_inc); +} + +#ifndef NO_MAIN +int +main (const int argc, char *const argv[]) +{ + return (ctrec_main(argc, argv)); } +#endif +