X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=src%2Fphm2if.cpp;h=75119c9642b2fab18ffe01fdb1f50c1cff78f4e1;hp=9d32f1ea069d6d55faad56a955ca130526d1ce4b;hb=2d39e823ba389fc68e5317c422b55be006094252;hpb=f173363bba9997045e5ec825e64d6253ec4da235 diff --git a/src/phm2if.cpp b/src/phm2if.cpp index 9d32f1e..75119c9 100644 --- a/src/phm2if.cpp +++ b/src/phm2if.cpp @@ -1,44 +1,15 @@ /***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: phm2if.cpp,v 1.1 2000/06/07 02:29:05 kevin Exp $ -** $Log: phm2if.cpp,v $ -** Revision 1.1 2000/06/07 02:29:05 kevin -** Initial C++ versions -** -** 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 +** FILE IDENTIFICATION ** -** 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 -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release +** Name: phm2if.cpp +** Purpose: Convert an phantom object to an image file +** Programmer: Kevin Rosenberg +** Date Started: 1984 ** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg ** +** $Id: phm2if.cpp,v 1.13 2000/06/22 10:17:28 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -54,15 +25,9 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -/* FILE - * phm2sdf.c Generate a SDF image from a phantom - * - * HISTORY - * 1984 - Final DOS verion - * 1999 - First UNIX version - */ - #include "ct.h" +#include "timer.h" + 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 }; @@ -86,104 +51,85 @@ static struct option my_options[] = }; void -phm2sdf_usage (const char *program) +phm2if_usage (const char *program) { - 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"); - fprintf(stdout," ny Number of pixels Y-axis\n"); - fprintf(stdout," --phantom Phantom to use for projection\n"); - fprintf(stdout," herman Herman head phantom\n"); - fprintf(stdout," rowland Rowland head phantom\n"); - fprintf(stdout," browland Bordered Rowland head phantom\n"); - fprintf(stdout," unitpulse Unit pulse phantom\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"); - fprintf(stdout," abs_cos Abs * Cosine\n"); - fprintf(stdout," abs_hamming Abs * Hamming\n"); - fprintf(stdout," shepp Shepp-Logan\n"); - fprintf(stdout," bandlimit Bandlimiting\n"); - fprintf(stdout," sinc Sinc\n"); - fprintf(stdout," cos Cosine\n"); - fprintf(stdout," triangle Triangle\n"); - fprintf(stdout," hamming Hamming\n"); - fprintf(stdout," --filter-param Alpha level for Hamming filter\n"); - fprintf(stdout," --filter-domain Set domain of filter\n"); - fprintf(stdout," spatial Spatial domain (default)\n"); - fprintf(stdout," freq Frequency domain\n"); - fprintf(stdout," --filter-bw Filter bandwidth (default = 1)\n"); - fprintf(stdout," --desc Description of raysum\n"); - fprintf(stdout," --nsample Number of samples per axis per pixel (default = 1)\n"); - fprintf(stdout," --trace Trace level to use\n"); - fprintf(stdout," none No tracing (default)\n"); - fprintf(stdout," text Trace text level\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"); - fprintf(stdout," --debug Debug mode\n"); - fprintf(stdout," --verbose Verbose mode\n"); - fprintf(stdout," --version Print version\n"); - fprintf(stdout," --help Print this help message\n"); + cout << "phm2if_usage: " << fileBasename(program) << " outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]" << endl; + cout << "Generate phantom image from a predefined --phantom or a --phmfile" << endl; + cout << endl; + cout << " outfile Name of output file for image" << endl; + cout << " nx Number of pixels X-axis" << endl; + cout << " ny Number of pixels Y-axis" << endl; + cout << " --phantom Phantom to use for projection" << endl; + cout << " herman Herman head phantom" << endl; + cout << " bherman Bordered Herman head phantom" << endl; + cout << " rowland Rowland head phantom" << endl; + cout << " browland Bordered Rowland head phantom" << endl; + cout << " unitpulse Unit pulse phantom" << endl; + cout << " --phmfile Generate Phantom from phantom file" << endl; + cout << " --filter Generate Phantom from a filter function" << endl; + cout << " abs_bandlimit Abs * Bandlimiting" << endl; + cout << " abs_sinc Abs * Sinc" << endl; + cout << " abs_cos Abs * Cosine" << endl; + cout << " abs_hamming Abs * Hamming" << endl; + cout << " shepp Shepp-Logan" << endl; + cout << " bandlimit Bandlimiting" << endl; + cout << " sinc Sinc" << endl; + cout << " cos Cosine" << endl; + cout << " triangle Triangle" << endl; + cout << " hamming Hamming" << endl; + cout << " --filter-param Alpha level for Hamming filter" << endl; + cout << " --filter-domain Set domain of filter" << endl; + cout << " spatial Spatial domain (default)" << endl; + cout << " freq Frequency domain" << endl; + cout << " --filter-bw Filter bandwidth (default = 1)" << endl; + cout << " --desc Description of raysum" << endl; + cout << " --nsample Number of samples per axis per pixel (default = 1)" << endl; + cout << " --trace Trace level to use" << endl; + cout << " none No tracing (default)" << endl; + cout << " text Trace text level" << endl; + cout << " phm Trace phantom" << endl; + cout << " rays Trace rays" << endl; + cout << " plot Trace plot" << endl; + cout << " clipping Trace clipping" << endl; + cout << " --debug Debug mode" << endl; + cout << " --verbose Verbose mode" << endl; + cout << " --version Print version" << endl; + cout << " --help Print this help message" << endl; } -#ifdef MPI_CT -void mpi_gather_image (ImageFile *im_global, ImageFile *im_local, const int opt_debug); +#ifdef HAVE_MPI +void mpi_gather_image (MPIWorld& mpiWorld, ImageFile* imGlobal, ImageFile* imLocal, const int opt_debug); #endif int -phm2sdf_main (const int argc, char *const argv[]) +phm2if_main (int argc, char* argv[]) { - ImageFile *im_global = NULL; - PHANTOM *phm = NULL; + ImageFile* imGlobal = NULL; + Phantom phm; int opt_nx = 0, opt_ny = 0; int opt_nsample = 1; - int opt_phmnum = -1; - FilterType opt_filter = static_cast(-1); - DomainType opt_filter_domain = D_SPATIAL; + string optPhmName; + string optFilterName; + string optDomainName = "spatial"; char *opt_outfile = NULL; int opt_debug = 0; - char str[256]; - char opt_desc[256], opt_phmfilename[256]; + string opt_desc; + string opt_phmfilename; char *endstr, *endptr; double opt_filter_param = 1; double opt_filter_bw = 1.; int opt_trace = TRACE_NONE; - int opt_verbose = 0; - double time_start=0, time_end=0; -#ifdef MPI_CT - ImageFile *im_local = NULL; - int mpi_argc = argc; - char **mpi_argv = (char **) argv; - double mpi_t1, mpi_t2, mpi_t, mpi_t_g; - - MPI_Init(&mpi_argc, &mpi_argv); - MPI_Comm_dup (MPI_COMM_WORLD, &mpi_ct.comm); - MPI_Comm_size(mpi_ct.comm, &mpi_ct.nproc); - MPI_Comm_rank(mpi_ct.comm, &mpi_ct.my_rank); - - 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); - } + bool opt_verbose = false; +#ifdef HAVE_MPI + ImageFile* imLocal = NULL; + MPIWorld mpiWorld (argc, argv); #endif -#ifdef MPI_CT - time_start = MPI_Wtime(); -#else - time_start = td_current_sec(); -#endif + Timer timerProgram; -#ifdef MPI_CT - if (mpi_ct.my_rank == 0) { +#ifdef HAVE_MPI + if (mpiWorld.getRank() == 0) { #endif - - strcpy(opt_desc, ""); - strcpy(opt_phmfilename, ""); while (1) { int c = getopt_long(argc, argv, "", my_options, NULL); char *endptr = NULL; @@ -194,53 +140,49 @@ phm2sdf_main (const int argc, char *const argv[]) switch (c) { case O_PHANTOM: - if ((opt_phmnum = opt_set_phantom(optarg)) < 0) { - phm2sdf_usage(argv[0]); + optPhmName = optarg; + if (! phm.createFromPhantom (optPhmName.c_str())) { + cout << "Invalid phantom name " << optPhmName << endl << endl; + phm2if_usage(argv[0]); return (1); } break; 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 phantom from file in MPI mode\n"); + opt_phmfilename = optarg; + phm.createFromFile(opt_phmfilename.c_str()); +#ifdef HAVE_MPI + if (mpiWorld.getRank() == 0) + cerr << "Can't use phantom from file in MPI mode" << endl; return (1); #endif break; case O_VERBOSE: - opt_verbose = 1; + opt_verbose = true; break; case O_DEBUG: opt_debug = 1; break; case O_TRACE: if ((opt_trace = opt_set_trace(optarg)) < 0) { - phm2sdf_usage(argv[0]); + phm2if_usage(argv[0]); return (1); } break; case O_FILTER: - if ((opt_filter = opt_set_filter(optarg)) < 0) { - phm2sdf_usage (argv[0]); - return (1); - } + optFilterName = optarg; break; case O_FILTER_DOMAIN: - if ((opt_filter_domain = opt_set_filter_domain(optarg)) < 0) { - phm2sdf_usage (argv[0]); - return (1); - } + optDomainName = optarg; break; case O_DESC: - strncpy(opt_desc, optarg, sizeof(opt_desc)); + opt_desc = optarg; break; case O_FILTER_BW: opt_filter_bw = strtod(optarg, &endptr); endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr,"Error setting --filter-bw to %s\n", optarg); - phm2sdf_usage(argv[0]); + sys_error(ERR_SEVERE,"Error setting --filter-bw to %s\n", optarg); + phm2if_usage(argv[0]); return (1); } break; @@ -248,8 +190,8 @@ phm2sdf_main (const int argc, char *const argv[]) opt_filter_param = strtod(optarg, &endptr); endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr,"Error setting --filter-param to %s\n", optarg); - phm2sdf_usage(argv[0]); + sys_error(ERR_SEVERE,"Error setting --filter-param to %s\n", optarg); + phm2if_usage(argv[0]); return (1); } break; @@ -257,236 +199,190 @@ phm2sdf_main (const int argc, char *const argv[]) opt_nsample = strtol(optarg, &endptr, 10); endstr = optarg + strlen(optarg); if (endptr != endstr) { - fprintf(stderr,"Error setting --nsample to %s\n", optarg); - phm2sdf_usage(argv[0]); + sys_error(ERR_SEVERE,"Error setting --nsample to %s\n", optarg); + phm2if_usage(argv[0]); return (1); } break; case O_VERSION: #ifdef VERSION - fprintf(stdout, "Version %s\n", VERSION); + cout << "Version " << VERSION << endl; #else - fprintf(stderr, "Unknown version number"); + cerr << "Unknown version number" << endl; #endif case O_HELP: case '?': - phm2sdf_usage(argv[0]); + phm2if_usage(argv[0]); return (0); default: - phm2sdf_usage(argv[0]); + phm2if_usage(argv[0]); return (1); } } - if (phm == NULL && opt_phmnum == -1 && opt_filter == -1) { - fprintf(stderr, "No phantom defined\n"); - phm2sdf_usage(argv[0]); + if (phm.nPElem() == 0 && optPhmName == "" && optFilterName == "") { + cerr << "No phantom defined" << endl; + phm2if_usage(argv[0]); return (1); } if (optind + 3 != argc) { - phm2sdf_usage(argv[0]); + phm2if_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]); - phm2sdf_usage(argv[0]); + sys_error(ERR_SEVERE,"Error setting nx to %s\n", argv[optind+1]); + phm2if_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]); - phm2sdf_usage(argv[0]); + sys_error(ERR_SEVERE,"Error setting ny to %s\n", argv[optind+2]); + phm2if_usage(argv[0]); return (1); } - snprintf(str, sizeof(str), "nx=%d, ny=%d, nsample=%d, ", opt_nx, opt_ny, opt_nsample); - if (opt_phmfilename[0]) { - strncat(str, "phantom=", sizeof(str)); - strncat(str, opt_phmfilename, sizeof(str)); - } - else if (opt_phmnum != -1) { - strncat(str, "phantom=", sizeof(str)); - strncat(str, name_of_phantom(opt_phmnum), sizeof(str)); - } - else if (opt_filter != -1) { - strncat(str, "filter=", sizeof(str)); - strncat(str, name_of_filter(opt_filter), sizeof(str)); - strncat(str, " - ", sizeof(str)); - strncat(str, name_of_filter_domain(opt_filter_domain), sizeof(str)); + ostringstream oss; + oss << "nx=" << opt_nx << ", ny=" << opt_ny << ", nsample=" << opt_nsample << ", "; + if (opt_phmfilename.length()) + oss << "phantom=" << opt_phmfilename; + else if (optPhmName != "") + oss << "phantom=" << optPhmName; + else if (optFilterName != "") { + oss << "filter=" << optFilterName << " - " << optDomainName; } - if (opt_desc[0]) { - strncat(str, ": ", sizeof(str)); - strncat(str, opt_desc, sizeof(str)); - } - strncpy(opt_desc, str, sizeof(opt_desc)); + if (opt_desc.length()) + oss << ": " << opt_desc; + opt_desc = oss.str(); if (opt_verbose) - printf("Rasterize Phantom to Image\n\n"); -#ifdef MPI_CT + cout << "Rasterize Phantom to Image" << endl << endl; +#ifdef HAVE_MPI } #endif -#ifdef MPI_CT - 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); - MPI_Bcast(&opt_trace, 1, MPI_INT, 0, mpi_ct.comm); - 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_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); - MPI_Bcast(&opt_filter_bw, 1, MPI_DOUBLE, 0, mpi_ct.comm); +#ifdef HAVE_MPI + TimerCollectiveMPI timerBcast (mpiWorld.getComm()); + mpiWorld.BcastString (optPhmName); + mpiWorld.getComm().Bcast (&opt_verbose, 1, MPI::INT, 0); + mpiWorld.getComm().Bcast (&opt_debug, 1, MPI::INT, 0); + mpiWorld.getComm().Bcast (&opt_trace, 1, MPI::INT, 0); + mpiWorld.getComm().Bcast (&opt_nx, 1, MPI::INT, 0); + mpiWorld.getComm().Bcast (&opt_ny, 1, MPI::INT, 0); + mpiWorld.getComm().Bcast (&opt_nsample, 1, MPI::INT, 0); + mpiWorld.getComm().Bcast (&opt_filter_param, 1, MPI::DOUBLE, 0); + mpiWorld.getComm().Bcast (&opt_filter_bw, 1, MPI::DOUBLE, 0); - 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 Bcast vars = %f secs, Max time = %f\n", mpi_t, mpi_t_g); - } + mpiWorld.BcastString (optFilterName); + mpiWorld.BcastString (optDomainName); - mpi_ct_calc_work_units(opt_nx); + if (opt_verbose) + timerBcast.timerEndAndReport ("Time to broadcast variables"); - if (mpi_ct.my_rank == 0) { - im_global = new ImageFile (opt_outfile, opt_nx, opt_ny); - im_global->adf.fileCreate(); - } + mpiWorld.setTotalWorkUnits (opt_nx); - im_local = new ImageFile (opt_nx, opt_ny); -#else - im_global = new ImageFile (opt_outfile, opt_nx, opt_ny); - im_global->adf.fileCreate (); -#endif - - if (opt_phmnum >= 0) - phm = phm_create (opt_phmnum); + if (mpiWorld.getRank() > 0 && optPhmName != "") + phm.createFromPhantom (optPhmName.c_str()); -#ifdef MPI_CT - else { - if (mpi_ct.my_rank == 0) - fprintf(stderr, "phmnum < 0\n"); - exit(1); + if (mpiWorld.getRank() == 0) { + imGlobal = new ImageFile (opt_outfile, opt_nx, opt_ny); + imGlobal->fileCreate(); } + imLocal = new ImageFile (opt_nx, opt_ny); +#else + imGlobal = new ImageFile (opt_outfile, opt_nx, opt_ny); + imGlobal->fileCreate (); #endif - ImageFileArray v = im_global->adf.getArray (); - double calctime = 0; + ImageFileArray v; +#ifdef HAVE_MPI + if (mpiWorld.getRank() == 0) + v = imGlobal->getArray (); -#ifdef MPI_CT - if (phm->type == P_UNIT_PULSE) { - if (mpi_ct.my_rank == 0) { + if (phm.getComposition() == P_UNIT_PULSE) { + if (mpiWorld.getRank() == 0) { v[opt_nx/2][opt_ny/2] = 1.; - calctime = 0; } - } else if (opt_filter != -1) { - if (mpi_ct.my_rank == 0) { - image_filter_response (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); - calctime = 0; + } else if (optFilterName != "") { + if (mpiWorld.getRank() == 0) { + image_filter_response (*imGlobal, optDomainName.c_str(), opt_filter_bw, optFilterName.c_str(), opt_filter_param, opt_trace); } } else { + TimerCollectiveMPI timerRasterize (mpiWorld.getComm()); + phm.convertToImagefile (*imLocal, opt_nsample, opt_trace, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits()); if (opt_verbose) - mpi_t1 = MPI_Wtime(); - 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 phm = %f secs, Max time = %f\n", mpi_t, mpi_t_g); - } - mpi_gather_image(im_global, im_local, opt_debug); + timerRasterize.timerEndAndReport ("Time to rasterize phantom"); + + TimerCollectiveMPI timerGather (mpiWorld.getComm()); + mpi_gather_image (mpiWorld, imGlobal, imLocal, opt_debug); + if (opt_verbose) + timerGather.timerEndAndReport ("Time to gather image"); } #else - if (phm->type == P_UNIT_PULSE) { + v = imGlobal->getArray (); + if (phm.getComposition() == P_UNIT_PULSE) { v[opt_nx/2][opt_ny/2] = 1.; - calctime = 0; - } else if (opt_filter != -1) { - // image_filter_response (im_global, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); - calctime = 0; + } else if (optFilterName != "") { + image_filter_response (*imGlobal, optDomainName.c_str(), opt_filter_bw, optFilterName.c_str(), opt_filter_param, opt_trace); } else { #if HAVE_SGP if (opt_trace >= TRACE_PHM) - phm_show(phm); + phm.show(); #endif - // phm_to_image (phm, im_global, 0, opt_nx, opt_nsample, opt_trace); + phm.convertToImagefile (*imGlobal, opt_nsample, opt_trace); } #endif -#ifdef MPI_CT - time_end = MPI_Wtime(); -#else - time_end = td_current_sec(); -#endif - -#ifdef MPI_CT - if (mpi_ct.my_rank == 0) +#ifdef HAVE_MPI + if (mpiWorld.getRank() == 0) #endif { - im_global->adf.arrayDataWrite (); - calctime = time_end - time_start; - im_global->adf.labelAdd (Array2dFileLabel::L_HISTORY, opt_desc, calctime); - im_global->adf.fileClose (); + imGlobal->arrayDataWrite (); + double calctime = timerProgram.timerEnd (); + imGlobal->labelAdd (Array2dFileLabel::L_HISTORY, opt_desc.c_str(), calctime); + imGlobal->fileClose (); if (opt_verbose) - fprintf (stdout, "Time to compile image = %.2f sec\n\n", calctime); - } + cout << "Time to rasterized phantom: " << calctime << " seconds" << endl; - if (opt_trace >= TRACE_PHM) - { + if (opt_trace >= TRACE_PHM) { double dmin, dmax; int nscale; - + printf ("Enter display size scale (nominal = 1): "); scanf ("%d", &nscale); printf ("Enter minimum and maximum densities (min, max): "); scanf ("%lf %lf", &dmin, &dmax); - // image_display_scale (im_global, nscale, dmin, dmax); + image_display_scale (*imGlobal, nscale, dmin, dmax); } - - phm_free (phm); + } return (0); } -#ifdef MPI_CT -void mpi_gather_image (ImageFile *im_global, ImageFile *im_local, const int opt_debug) +#ifdef HAVE_MPI +void mpi_gather_image (MPIWorld& mpiWorld, ImageFile* imGlobal, ImageFile* imLocal, const int opt_debug) { - int iproc; - int end_work_unit; - int iw; - - end_work_unit = mpi_ct.local_work_units[mpi_ct.my_rank] - 1; - for (iw = 0; iw <= end_work_unit; iw++) { - MPI_Send(im_local->v[iw], im_local->ny, im_local->getMPIDataType(), 0, 0, mpi_ct.comm); - } - - 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; + ImageFileArray vLocal = imLocal->getArray(); + ImageFileArray vGlobal = NULL; + int nyLocal = imLocal->ny(); - if (opt_debug) { - fprintf(stdout, "Recv rs data from process %d (%d-%d)\n", iproc, - mpi_ct.start_work_unit[iproc], end_work_unit); - fflush(stdout); - } - - - for (iw = mpi_ct.start_work_unit[iproc]; iw <= end_work_unit; iw++) { - MPI_Status status; - - MPI_Recv(im_global->v[iw], im_global->ny, MPI_FLOAT, iproc, 0, mpi_ct.comm, &status); + if (mpiWorld.getRank() == 0) + vGlobal = imGlobal->getArray(); + + for (int iw = 0; iw < mpiWorld.getMyLocalWorkUnits(); iw++) + mpiWorld.getComm().Send(vLocal[iw], nyLocal, imLocal->getMPIDataType(), 0, 0); + + if (mpiWorld.getRank() == 0) { + for (int iProc = 0; iProc < mpiWorld.getNumProcessors(); iProc++) { + for (int iw = mpiWorld.getStartWorkUnit(iProc); iw <= mpiWorld.getEndWorkUnit(iProc); iw++) { + MPI::Status status; + mpiWorld.getComm().Recv(vGlobal[iw], nyLocal, imLocal->getMPIDataType(), iProc, 0, status); } } } @@ -496,8 +392,18 @@ void mpi_gather_image (ImageFile *im_global, ImageFile *im_local, const int opt_ #ifndef NO_MAIN int -main (const int argc, char *const argv[]) +main (int argc, char* argv[]) { - return (phm2sdf_main(argc, argv)); + int retval = 1; + + try { + retval = phm2if_main(argc, argv); + } catch (exception e) { + cerr << "Exception: " << e.what() << endl; + } catch (...) { + cerr << "Unknown exception" << endl; + } + + return (retval); } #endif