X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=src%2Fphm2if.cpp;h=afac8162d2ebe0fa0e4eaae64b52b67c8a3e150a;hb=52107baf438f31ce8930b062e7fdebf95d3fd9ee;hp=0eb5c9e1ebc544c765b6788db92e2cccf4b5ce5e;hpb=207332eec9416d299766abb697312cfd27eb890e;p=ctsim.git diff --git a/src/phm2if.cpp b/src/phm2if.cpp index 0eb5c9e..afac816 100644 --- a/src/phm2if.cpp +++ b/src/phm2if.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2if.cpp,v 1.11 2000/06/19 17:58:13 kevin Exp $ +** $Id: phm2if.cpp,v 1.16 2000/07/04 22:21:01 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 @@ -61,6 +61,7 @@ phm2if_usage (const char *program) 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; @@ -107,13 +108,13 @@ phm2if_main (int argc, char* argv[]) 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 = Phantom::PHM_HERMAN_STR; + string optFilterName; + string optDomainName = SignalFilter::DOMAIN_SPATIAL_STR; char *opt_outfile = NULL; int opt_debug = 0; string opt_desc; - string opt_phmfilename; + string opt_phmFileName; char *endstr, *endptr; double opt_filter_param = 1; double opt_filter_bw = 1.; @@ -139,19 +140,10 @@ phm2if_main (int argc, char* argv[]) switch (c) { case O_PHANTOM: - if ((opt_phmnum = opt_set_phantom(optarg)) < 0) { - phm2if_usage(argv[0]); - return (1); - } + optPhmName = optarg; break; case O_PHMFILE: - 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 + opt_phmFileName = optarg; break; case O_VERBOSE: opt_verbose = true; @@ -160,22 +152,16 @@ phm2if_main (int argc, char* argv[]) opt_debug = 1; break; case O_TRACE: - if ((opt_trace = opt_set_trace(optarg)) < 0) { + if ((opt_trace = convertTraceNameToID(optarg)) == TRACE_INVALID) { phm2if_usage(argv[0]); return (1); } break; case O_FILTER: - if ((opt_filter = opt_set_filter(optarg)) < 0) { - phm2if_usage (argv[0]); - return (1); - } + optFilterName = optarg; break; case O_FILTER_DOMAIN: - if ((opt_filter_domain = opt_set_filter_domain(optarg)) < 0) { - phm2if_usage (argv[0]); - return (1); - } + optDomainName = optarg; break; case O_DESC: opt_desc = optarg; @@ -223,8 +209,8 @@ phm2if_main (int argc, char* argv[]) } } - if (phm.nPElem() == 0 && opt_phmnum == -1 && opt_filter == -1) { - cerr << "No phantom defined" << endl; + if (optPhmName == "" && optFilterName == "" && opt_phmFileName == "") { + cerr << "No phantom defined" << endl << endl; phm2if_usage(argv[0]); return (1); } @@ -250,19 +236,36 @@ phm2if_main (int argc, char* argv[]) } ostringstream oss; - oss << "nx=" << opt_nx << ", ny=" << opt_ny << ", nsample=" << opt_nsample << ", "; - if (opt_phmfilename.length()) - oss << "phantom=" << opt_phmfilename; - else if (opt_phmnum != -1) - oss << "phantom=" << name_of_phantom(opt_phmnum); - else if (opt_filter != -1) { - oss << "filter=" << name_of_filter(opt_filter); - oss << " - " << name_of_filter_domain(opt_filter_domain); + oss << "phm2if: nx=" << opt_nx << ", ny=" << opt_ny << ", nsample=" << opt_nsample << ", "; + if (opt_phmFileName != "") + oss << "phantom=" << opt_phmFileName; + else if (optPhmName != "") + oss << "phantom=" << optPhmName; + else if (optFilterName != "") { + oss << "filter=" << optFilterName << " - " << optDomainName; } - if (opt_desc.length()) + if (opt_desc != "") oss << ": " << opt_desc; opt_desc = oss.str(); + if (optPhmName != "") { + phm.createFromPhantom (optPhmName.c_str()); + if (phm.fail()) { + cout << phm.failMessage() << endl << endl; + phm2if_usage(argv[0]); + return (1); + } + } + + if (opt_phmFileName != "") { + 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 + } + if (opt_verbose) cout << "Rasterize Phantom to Image" << endl << endl; #ifdef HAVE_MPI @@ -271,42 +274,33 @@ phm2if_main (int argc, char* argv[]) #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_phmnum, 1, MPI::INT, 0); - mpiWorld.getComm().Bcast (&opt_filter, 1, MPI::INT, 0); - mpiWorld.getComm().Bcast (&opt_filter_domain, 1, MPI::INT, 0); mpiWorld.getComm().Bcast (&opt_filter_param, 1, MPI::DOUBLE, 0); mpiWorld.getComm().Bcast (&opt_filter_bw, 1, MPI::DOUBLE, 0); + mpiWorld.BcastString (optFilterName); + mpiWorld.BcastString (optDomainName); + if (opt_verbose) timerBcast.timerEndAndReport ("Time to broadcast variables"); mpiWorld.setTotalWorkUnits (opt_nx); + if (mpiWorld.getRank() > 0 && optPhmName != "") + phm.createFromPhantom (optPhmName.c_str()); + if (mpiWorld.getRank() == 0) { - imGlobal = new ImageFile (opt_outfile, opt_nx, opt_ny); - imGlobal->fileCreate(); + imGlobal = new ImageFile (opt_nx, opt_ny); } imLocal = new ImageFile (opt_nx, opt_ny); #else - imGlobal = new ImageFile (opt_outfile, opt_nx, opt_ny); - imGlobal->fileCreate (); -#endif - - if (opt_phmnum >= 0) - phm.create (opt_phmnum); - -#ifdef HAVE_MPI - else { - if (mpiWorld.getRank() == 0) - cerr << "phmnum < 0" << endl; - return (1); - } + imGlobal = new ImageFile (opt_nx, opt_ny); #endif ImageFileArray v; @@ -318,13 +312,13 @@ phm2if_main (int argc, char* argv[]) if (mpiWorld.getRank() == 0) { v[opt_nx/2][opt_ny/2] = 1.; } - } else if (opt_filter != -1) { + } else if (optFilterName != "") { if (mpiWorld.getRank() == 0) { - image_filter_response (*imGlobal, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); + imGlobal->filterResponse (optDomainName.c_str(), opt_filter_bw, optFilterName.c_str(), opt_filter_param); } } else { TimerCollectiveMPI timerRasterize (mpiWorld.getComm()); - phm_to_imagefile (phm, *imLocal, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits(), opt_nsample, opt_trace); + phm.convertToImagefile (*imLocal, opt_nsample, opt_trace, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits()); if (opt_verbose) timerRasterize.timerEndAndReport ("Time to rasterize phantom"); @@ -337,14 +331,14 @@ phm2if_main (int argc, char* argv[]) v = imGlobal->getArray (); if (phm.getComposition() == P_UNIT_PULSE) { v[opt_nx/2][opt_ny/2] = 1.; - } else if (opt_filter != -1) { - image_filter_response (*imGlobal, opt_filter_domain, opt_filter_bw, opt_filter, opt_filter_param, opt_trace); + } else if (optFilterName != "") { + imGlobal->filterResponse (optDomainName.c_str(), opt_filter_bw, optFilterName.c_str(), opt_filter_param); } else { #if HAVE_SGP if (opt_trace >= TRACE_PHM) phm.show(); #endif - phm_to_imagefile (phm, *imGlobal, 0, opt_nx, opt_nsample, opt_trace); + phm.convertToImagefile (*imGlobal, opt_nsample, opt_trace); } #endif @@ -352,10 +346,9 @@ phm2if_main (int argc, char* argv[]) if (mpiWorld.getRank() == 0) #endif { - imGlobal->arrayDataWrite (); double calctime = timerProgram.timerEnd (); imGlobal->labelAdd (Array2dFileLabel::L_HISTORY, opt_desc.c_str(), calctime); - imGlobal->fileClose (); + imGlobal->fileWrite (opt_outfile); if (opt_verbose) cout << "Time to rasterized phantom: " << calctime << " seconds" << endl; @@ -367,7 +360,7 @@ phm2if_main (int argc, char* argv[]) scanf ("%d", &nscale); printf ("Enter minimum and maximum densities (min, max): "); scanf ("%lf %lf", &dmin, &dmax); - image_display_scale (*imGlobal, nscale, dmin, dmax); + imGlobal->displayScaling (nscale, dmin, dmax); } }