X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fphm2sdf.c;h=fb72ab3288cc0a0eae1dd81eedd6bfe1d494a841;hb=07b93dbf2b66fa23c5378ab0fa42f9a7f0083380;hp=aafb9b27fda012a662e778b08dda17133de9c0e8;hpb=2a0006ec846e8da055fe002cb1611853dd01270c;p=ctsim.git diff --git a/src/phm2sdf.c b/src/phm2sdf.c index aafb9b2..fb72ab3 100644 --- a/src/phm2sdf.c +++ b/src/phm2sdf.c @@ -2,8 +2,33 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2sdf.c,v 1.2 2000/04/28 13:50:45 kevin Exp $ +** $Id: phm2sdf.c,v 1.10 2000/05/24 22:50:04 kevin Exp $ ** $Log: phm2sdf.c,v $ +** Revision 1.10 2000/05/24 22:50:04 kevin +** Added support for new SGP library +** +** Revision 1.9 2000/05/16 04:33:59 kevin +** Improved option processing +** +** Revision 1.8 2000/05/11 01:06:30 kevin +** Changed sprintf to snprintf +** +** Revision 1.7 2000/05/08 20:02:32 kevin +** ANSI C changes +** +** Revision 1.6 2000/05/03 08:49:50 kevin +** Code cleanup +** +** Revision 1.5 2000/04/30 19:17:54 kevin +** *** empty log message *** +** +** Revision 1.4 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.3 2000/04/28 18:19:01 kevin +** removed unused files +** ** Revision 1.2 2000/04/28 13:50:45 kevin ** Removed Makefile Makefile.in that are automatically generated by autoconf ** @@ -25,6 +50,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 * phm2sdf.c Generate a SDF image from a phantom * @@ -35,24 +61,13 @@ #include "ct.h" -#define O_PHANTOM 1 -#define O_DESC 2 -#define O_NSAMPLE 3 -#define O_FILTER 4 -#define O_TRACE 5 -#define O_VERBOSE 6 -#define O_HELP 7 -#define O_PICFILE 8 -#define O_FILTER_DOMAIN 9 -#define O_FILTER_BW 10 -#define O_FILTER_PARAM 11 -#define O_DEBUG 12 -#define O_VERSION 13 +enum { O_PHANTOM, O_DESC, O_NSAMPLE, O_FILTER, O_TRACE, O_VERBOSE, O_HELP, + O_PHMFILE, O_FILTER_DOMAIN, O_FILTER_BW, O_FILTER_PARAM, O_DEBUG, O_VERSION }; static struct option my_options[] = { {"phantom", 1, 0, O_PHANTOM}, - {"picfile", 1, 0, O_PICFILE}, + {"phmfile", 1, 0, O_PHMFILE}, {"desc", 1, 0, O_DESC}, {"nsample", 1, 0, O_NSAMPLE}, {"filter", 1, 0, O_FILTER}, @@ -68,10 +83,10 @@ static struct option my_options[] = }; void -usage (const char *program) +phm2sdf_usage (const char *program) { - fprintf(stdout,"usage: %s outfile nx ny [--phantom phantom-name] [--picfile filename] [--filter filter-name] [OPTIONS]\n",kbasename(program)); - fprintf(stdout,"Generate phantom image from a predefined --phantom or a --picfile\n"); + fprintf(stdout,"phm2sdf_usage: %s outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]\n",kbasename(program)); + fprintf(stdout,"Generate phantom image from a predefined --phantom or a --phmfile\n"); fprintf(stdout,"\n"); fprintf(stdout," outfile Name of output file for image\n"); fprintf(stdout," nx Number of pixels X-axis\n"); @@ -81,7 +96,7 @@ usage (const char *program) fprintf(stdout," rowland Rowland head phantom\n"); fprintf(stdout," browland Bordered Rowland head phantom\n"); fprintf(stdout," unitpulse Unit pulse phantom\n"); - fprintf(stdout," --picfile Generate Phantom from picture file\n"); + fprintf(stdout," --phmfile Generate Phantom from phantom file\n"); fprintf(stdout," --filter Generate Phantom from a filter function\n"); fprintf(stdout," abs_bandlimit Abs * Bandlimiting\n"); fprintf(stdout," abs_sinc Abs * Sinc\n"); @@ -103,7 +118,7 @@ usage (const char *program) fprintf(stdout," --trace Trace level to use\n"); fprintf(stdout," none No tracing (default)\n"); fprintf(stdout," text Trace text level\n"); - fprintf(stdout," pic Trace picture\n"); + fprintf(stdout," phm Trace phantom\n"); fprintf(stdout," rays Trace rays\n"); fprintf(stdout," plot Trace plot\n"); fprintf(stdout," clipping Trace clipping\n"); @@ -111,7 +126,6 @@ usage (const char *program) fprintf(stdout," --verbose Verbose mode\n"); fprintf(stdout," --version Print version\n"); fprintf(stdout," --help Print this help message\n"); - exit(1); } #ifdef MPI_CT @@ -119,25 +133,25 @@ void mpi_gather_image (IMAGE *im_global, IMAGE *im_local, const int opt_debug); #endif int -main (const int argc, char *const argv[]) +phm2sdf_main (const int argc, char *const argv[]) { IMAGE *im_global = NULL; - PICTURE *pic = NULL; + PHANTOM *phm = NULL; int opt_nx = 0, opt_ny = 0; int opt_nsample = 1; - int opt_picnum = -1; + int opt_phmnum = -1; int opt_filter = -1; int opt_filter_domain = D_SPATIAL; - char *opt_outfile; + char *opt_outfile = NULL; int opt_debug = 0; char str[256]; - char opt_desc[256], opt_picfilename[256]; + char opt_desc[256], opt_phmfilename[256]; char *endstr, *endptr; - double opt_filter_param; + double opt_filter_param = 1; double opt_filter_bw = 1.; int opt_trace = TRACE_NONE; int opt_verbose = 0; - double time_start, time_end; + double time_start=0, time_end=0; #ifdef MPI_CT IMAGE *im_local = NULL; int mpi_argc = argc; @@ -152,7 +166,6 @@ main (const int argc, char *const argv[]) if (mpi_ct.nproc > MPI_MAX_PROCESS) { sys_error(ERR_FATAL, "Number of mpi processes (%d) exceeds max processes (%d)", mpi_ct.nproc, MPI_MAX_PROCESS); - exit(1); } #endif @@ -167,7 +180,7 @@ main (const int argc, char *const argv[]) #endif strcpy(opt_desc, ""); - strcpy(opt_picfilename, ""); + strcpy(opt_phmfilename, ""); while (1) { int c = getopt_long(argc, argv, "", my_options, NULL); char *endptr = NULL; @@ -178,15 +191,18 @@ main (const int argc, char *const argv[]) switch (c) { case O_PHANTOM: - opt_picnum = opt_set_picture(optarg, argv[0]); + if ((opt_phmnum = opt_set_phantom(optarg)) < 0) { + phm2sdf_usage(argv[0]); + return (1); + } break; - case O_PICFILE: - strncpy(opt_picfilename, optarg, sizeof(opt_picfilename)); - pic = create_pic_from_file(opt_picfilename); + case O_PHMFILE: + strncpy(opt_phmfilename, optarg, sizeof(opt_phmfilename)); + phm = phm_create_from_file(opt_phmfilename); #ifdef MPI_CT if (mpi_ct.my_rank == 0) - fprintf(stderr, "Can't use picture from file in MPI mode\n"); - exit(1); + fprintf(stderr, "Can't use phantom from file in MPI mode\n"); + return (1); #endif break; case O_VERBOSE: @@ -196,13 +212,22 @@ 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) { + phm2sdf_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) { + phm2sdf_usage (argv[0]); + return (1); + } break; case O_FILTER_DOMAIN: - opt_filter_domain = opt_set_filter_domain(optarg, argv[0]); + if ((opt_filter_domain = opt_set_filter_domain(optarg)) < 0) { + phm2sdf_usage (argv[0]); + return (1); + } break; case O_DESC: strncpy(opt_desc, optarg, sizeof(opt_desc)); @@ -212,8 +237,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --filter-bw to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } break; case O_FILTER_PARAM: @@ -221,8 +246,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --filter-param to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } break; case O_NSAMPLE: @@ -230,8 +255,8 @@ main (const int argc, char *const argv[]) endstr = optarg + strlen(optarg); if (endptr != endstr) { fprintf(stderr,"Error setting --nsample to %s\n", optarg); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } break; case O_VERSION: @@ -242,51 +267,48 @@ main (const int argc, char *const argv[]) #endif case O_HELP: case '?': - usage(argv[0]); - exit(0); + phm2sdf_usage(argv[0]); + return (0); default: - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } } - if (pic == NULL && opt_picnum == -1 && opt_filter == -1) { + if (phm == NULL && opt_phmnum == -1 && opt_filter == -1) { fprintf(stderr, "No phantom defined\n"); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } - if (opt_trace >= TRACE_PIC) - show_pic(pic); - if (optind + 3 != argc) { - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } opt_outfile = argv[optind]; opt_nx = strtol(argv[optind+1], &endptr, 10); endstr = argv[optind+1] + strlen(argv[optind+1]); if (endptr != endstr) { fprintf(stderr,"Error setting nx to %s\n", argv[optind+1]); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } opt_ny = strtol(argv[optind+2], &endptr, 10); endstr = argv[optind+2] + strlen(argv[optind+2]); if (endptr != endstr) { fprintf(stderr,"Error setting ny to %s\n", argv[optind+2]); - usage(argv[0]); - exit(1); + phm2sdf_usage(argv[0]); + return (1); } snprintf(str, sizeof(str), "nx=%d, ny=%d, nsample=%d, ", opt_nx, opt_ny, opt_nsample); - if (opt_picfilename[0]) { + if (opt_phmfilename[0]) { strncat(str, "phantom=", sizeof(str)); - strncat(str, opt_picfilename, sizeof(str)); + strncat(str, opt_phmfilename, sizeof(str)); } - else if (opt_picnum != -1) { + else if (opt_phmnum != -1) { strncat(str, "phantom=", sizeof(str)); - strncat(str, name_of_picture(opt_picnum), sizeof(str)); + strncat(str, name_of_phantom(opt_phmnum), sizeof(str)); } else if (opt_filter != -1) { strncat(str, "filter=", sizeof(str)); @@ -314,7 +336,7 @@ main (const int argc, char *const argv[]) MPI_Bcast(&opt_nx, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&opt_ny, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&opt_nsample, 1, MPI_INT, 0, mpi_ct.comm); - MPI_Bcast(&opt_picnum, 1, MPI_INT, 0, mpi_ct.comm); + MPI_Bcast(&opt_phmnum, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&opt_filter, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&opt_filter_domain, 1, MPI_INT, 0, mpi_ct.comm); MPI_Bcast(&opt_filter_param, 1, MPI_DOUBLE, 0, mpi_ct.comm); @@ -337,98 +359,90 @@ main (const int argc, char *const argv[]) #else im_global = image_create (opt_outfile, opt_nx, opt_ny); #endif - - if (opt_picnum > 0) - pic = create_pic(opt_picnum); + + if (opt_phmnum >= 0) + phm = phm_create (opt_phmnum); + #ifdef MPI_CT else { if (mpi_ct.my_rank == 0) - fprintf(stderr, "picnum < 0\n"); + fprintf(stderr, "phmnum < 0\n"); exit(1); } #endif #ifdef MPI_CT - if (pic->type == P_UNIT_PULSE) { + if (phm->type == P_UNIT_PULSE) { if (mpi_ct.my_rank == 0) { im_global->v[opt_nx/2][opt_ny/2] = 1.; im_global->calctime = 0; } } else if (opt_filter != -1) { if (mpi_ct.my_rank == 0) { - image_filter_init (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); + image_filter_response (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); im_global->calctime = 0; } } else { if (opt_verbose) mpi_t1 = MPI_Wtime(); - pic_to_image (pic, im_local, mpi_ct.start_work_unit[mpi_ct.my_rank], + phm_to_image (phm, im_local, mpi_ct.start_work_unit[mpi_ct.my_rank], mpi_ct.local_work_units[mpi_ct.my_rank], opt_nsample, opt_trace); if (opt_verbose) { 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) - printf("Time to compile pic = %f secs, Max time = %f\n", mpi_t, mpi_t_g); + printf("Time to compile phm = %f secs, Max time = %f\n", mpi_t, mpi_t_g); } mpi_gather_image(im_global, im_local, opt_debug); } #else - if (pic->type == P_UNIT_PULSE) { + if (phm->type == P_UNIT_PULSE) { im_global->v[opt_nx/2][opt_ny/2] = 1.; im_global->calctime = 0; } else if (opt_filter != -1) { - image_filter_init (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); + image_filter_response (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); im_global->calctime = 0; } else { - pic_to_image (pic, im_global, 0, opt_nx, opt_nsample, opt_trace); +#if HAVE_SGP + if (opt_trace >= TRACE_PHM) + phm_show(phm); +#endif + phm_to_image (phm, im_global, 0, opt_nx, opt_nsample, opt_trace); } #endif #ifdef MPI_CT time_end = MPI_Wtime(); - if (mpi_ct.my_rank == 0) { +#else + time_end = td_current_sec(); +#endif + +#ifdef MPI_CT + if (mpi_ct.my_rank == 0) +#endif + { im_global->calctime = time_end - time_start; strncpy (im_global->remark, opt_desc, sizeof(im_global->remark)); - } - - if (mpi_ct.my_rank == 0) { image_save (im_global); if (opt_verbose) fprintf (stdout, "Time to compile image = %.2f sec\n\n", im_global->calctime); } -#else - time_end = td_current_sec(); - im_global->calctime = time_end - time_start; - strncpy (im_global->remark, opt_desc, sizeof(im_global->remark)); - image_save (im_global); - - if (opt_trace >= TRACE_PIC) - { - crt_set_cpos (1, 1); - } - - if (opt_verbose) - fprintf (stdout, "Time to compile image = %.2f sec\n\n", im_global->calctime); -#endif - if (opt_trace >= TRACE_PIC) + if (opt_trace >= TRACE_PHM) { double dmin, dmax; - int nx, ny; + int nscale; - printf ("Enter size of cell (nx, ny): "); - scanf ("%d %d", &nx, &ny); + printf ("Enter display size scale (nominal = 1): "); + scanf ("%d", &nscale); printf ("Enter minimum and maximum densities (min, max): "); scanf ("%lf %lf", &dmin, &dmax); - // image_paint (CRTDEV, im_global, 0, 0, nx, ny, dmin, dmax, 0); - WAITKEY(); - - crt_set_palette (0, crt_calc_color (0., 0., 2.)); - crt_put_stra ("Finished", 8 + C_WHITE); - crt_set_cpos (1, 2); + image_display_scale (im_global, nscale, dmin, dmax); } + phm_free (phm); + return (0); } @@ -469,3 +483,11 @@ void mpi_gather_image (IMAGE *im_global, IMAGE *im_local, const int opt_debug) } #endif + +#ifndef NO_MAIN +int +main (const int argc, char *const argv[]) +{ + return (phm2sdf_main(argc, argv)); +} +#endif