X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=tools%2Fphm2pj.cpp;h=cf4a24f4a098ffe468882fda1342ea747c076038;hp=a2b30216b7645624143b23b93ae662ace4f44b3c;hb=855f0990a75750c61badd376ff35ffb39fab1c36;hpb=980bef9b95bef1ab728634181a5672088fd47066 diff --git a/tools/phm2pj.cpp b/tools/phm2pj.cpp index a2b3021..cf4a24f 100644 --- a/tools/phm2pj.cpp +++ b/tools/phm2pj.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: phm2pj.cpp,v 1.6 2000/07/31 14:48:35 kevin Exp $ +** $Id: phm2pj.cpp,v 1.18 2000/12/17 23:30:48 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 @@ -29,7 +29,7 @@ #include "timer.h" -enum { O_PHANTOM, O_DESC, O_NRAY, O_ROTANGLE, O_PHMFILE, +enum { O_PHANTOM, O_DESC, O_NRAY, O_ROTANGLE, O_PHMFILE, O_GEOMETRY, O_FOCAL_LENGTH, O_FIELD_OF_VIEW, O_TRACE, O_VERBOSE, O_HELP, O_DEBUG, O_VERSION }; static struct option phm2pj_options[] = @@ -39,6 +39,9 @@ static struct option phm2pj_options[] = {"desc", 1, 0, O_DESC}, {"nray", 1, 0, O_NRAY}, {"rotangle", 1, 0, O_ROTANGLE}, + {"geometry", 1, 0, O_GEOMETRY}, + {"focal-length", 1, 0, O_FOCAL_LENGTH}, + {"field-of-view", 1, 0, O_FIELD_OF_VIEW}, {"trace", 1, 0, O_TRACE}, {"verbose", 0, 0, O_VERBOSE}, {"help", 0, 0, O_HELP}, @@ -47,37 +50,47 @@ static struct option phm2pj_options[] = {0, 0, 0, 0} }; +static const char* g_szIdStr = "$Id: phm2pj.cpp,v 1.18 2000/12/17 23:30:48 kevin Exp $"; + void phm2pj_usage (const char *program) { - cout << "usage: " << fileBasename(program) << " outfile ndet nview [--phantom phantom-name] [--phmfile filename] [OPTIONS]" << endl; - cout << "Calculate (projections) through phantom object, either a predefined --phantom or a --phmfile" << endl; - cout << "" << endl; - cout << " outfile Name of output file for raysums" << endl; - cout << " ndet Number of detectors" << endl; - cout << " nview Number of rotated views" << 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 Get Phantom from phantom file" << endl; - cout << " --desc Description of raysum" << endl; - cout << " --nray Number of rays per detector (default = 1)" << endl; - cout << " --rotangle Degrees to rotate view through, multiple of PI (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 image" << endl; - cout << " rays Trace rays" << endl; - cout << " plot Trace plot" << endl; - cout << " clipping Trace clipping" << endl; - cout << " --verbose Verbose mode" << endl; - cout << " --debug Debug mode" << endl; - cout << " --version Print version" << endl; - cout << " --help Print this help message" << endl; + std::cout << "usage: " << fileBasename(program) << " outfile ndet nview [--phantom phantom-name] [--phmfile filename] [OPTIONS]\n"; + std::cout << "Calculate (projections) through phantom object, either a predefined --phantom or a --phmfile\n\n"; + std::cout << " outfile Name of output file for projections\n"; + std::cout << " ndet Number of detectors\n"; + std::cout << " nview Number of rotated views\n"; + std::cout << " --phantom Phantom to use for projection\n"; + std::cout << " herman Herman head phantom\n"; + std::cout << " herman-b Herman head phantom (Bordered)\n"; + std::cout << " shepp-logan Shepp-Logan head phantom\n"; + std::cout << " shepp-logan-b Shepp-Logan head phantom (Bordered)\n"; + std::cout << " unitpulse Unit pulse phantom\n"; + std::cout << " --phmfile Get Phantom from phantom file\n"; + std::cout << " --desc Description of raysum\n"; + std::cout << " --nray Number of rays per detector (default = 1)\n"; + std::cout << " --rotangle Degrees to rotate view through (multiple of PI)\n"; + std::cout << " (default = 1)\n"; + std::cout << " --geometry Geometry of scanning\n"; + std::cout << " parallel Parallel scan beams (default)\n"; + std::cout << " equilinear Equilinear divergent scan beams\n"; + std::cout << " equiangular Equiangular divergent scan beams\n"; + std::cout << " --focal-length Focal length ratio (ratio to radius of phantom)\n"; + std::cout << " (default = 1)\n"; + std::cout << " --field-of-view Field of view (ratio to diameter of phantom square)\n"; + std::cout << " (default = 1)\n"; + std::cout << " --trace Trace level to use\n"; + std::cout << " none No tracing (default)\n"; + std::cout << " console Trace text level\n"; + std::cout << " phantom Trace phantom image\n"; + std::cout << " proj Trace projections\n"; + std::cout << " plot Trace plot\n"; + std::cout << " clipping Trace clipping\n"; + std::cout << " --verbose Verbose mode\n"; + std::cout << " --debug Debug mode\n"; + std::cout << " --version Print version\n"; + std::cout << " --help Print this help message\n"; } #ifdef HAVE_MPI @@ -88,15 +101,17 @@ int phm2pj_main (int argc, char* argv[]) { Phantom phm; - string optGeometryName = Scanner::convertGeometryIDToName(Scanner::GEOMETRY_PARALLEL); + std::string optGeometryName = Scanner::convertGeometryIDToName(Scanner::GEOMETRY_PARALLEL); char *opt_outfile = NULL; - string opt_desc; - string optPhmFileName; + std::string opt_desc; + std::string optPhmName; + std::string optPhmFileName; int opt_ndet; int opt_nview; int opt_nray = 1; - int opt_trace = 0; - string optPhmName (Phantom::convertPhantomIDToName(Phantom::PHM_HERMAN)); + double dOptFocalLength = 1.; + double dOptFieldOfView = 1.; + int opt_trace = Trace::TRACE_NONE; int opt_verbose = 0; int opt_debug = 0; double opt_rotangle = 1; @@ -133,7 +148,7 @@ phm2pj_main (int argc, char* argv[]) break; break; case O_TRACE: - if ((opt_trace = TraceLevel::convertTraceNameToID(optarg)) == TRACE_INVALID) { + if ((opt_trace = Trace::convertTraceNameToID(optarg)) == Trace::TRACE_INVALID) { phm2pj_usage(argv[0]); return (1); } @@ -145,7 +160,28 @@ phm2pj_main (int argc, char* argv[]) opt_rotangle = strtod(optarg, &endptr); endstr = optarg + strlen(optarg); if (endptr != endstr) { - cerr << "Error setting --rotangle to " << optarg << endl; + std::cerr << "Error setting --rotangle to " << optarg << endl; + phm2pj_usage(argv[0]); + return (1); + } + break; + case O_GEOMETRY: + optGeometryName = optarg; + break; + case O_FOCAL_LENGTH: + dOptFocalLength = strtod(optarg, &endptr); + endstr = optarg + strlen(optarg); + if (endptr != endstr) { + std::cerr << "Error setting --focal-length to " << optarg << endl; + phm2pj_usage(argv[0]); + return (1); + } + break; + case O_FIELD_OF_VIEW: + dOptFieldOfView = strtod(optarg, &endptr); + endstr = optarg + strlen(optarg); + if (endptr != endstr) { + std::cerr << "Error setting --field-of-view to " << optarg << endl; phm2pj_usage(argv[0]); return (1); } @@ -154,16 +190,16 @@ phm2pj_main (int argc, char* argv[]) opt_nray = strtol(optarg, &endptr, 10); endstr = optarg + strlen(optarg); if (endptr != endstr) { - cerr << "Error setting --nray to %s" << optarg << endl; + std::cerr << "Error setting --nray to %s" << optarg << endl; phm2pj_usage(argv[0]); return (1); } break; case O_VERSION: #ifdef VERSION - cout << "Version: " << VERSION << endl; + std::cout << "Version: " << VERSION << endl << g_szIdStr << endl; #else - cout << "Unknown version number" << endl; + std::cout << "Unknown version number\n"; #endif return (0); case O_HELP: @@ -177,7 +213,7 @@ phm2pj_main (int argc, char* argv[]) } if (optPhmName == "" && optPhmFileName == "") { - cerr << "No phantom defined" << endl << endl; + std::cerr << "No phantom defined\n" << endl; phm2pj_usage(argv[0]); return (1); } @@ -190,20 +226,20 @@ phm2pj_main (int argc, char* argv[]) opt_ndet = strtol(argv[optind+1], &endptr, 10); endstr = argv[optind+1] + strlen(argv[optind+1]); if (endptr != endstr) { - cerr << "Error setting --ndet to " << argv[optind+1] << endl; + std::cerr << "Error setting --ndet to " << argv[optind+1] << endl; phm2pj_usage(argv[0]); return (1); } opt_nview = strtol(argv[optind+2], &endptr, 10); endstr = argv[optind+2] + strlen(argv[optind+2]); if (endptr != endstr) { - cerr << "Error setting --nview to " << argv[optind+2] << endl; + std::cerr << "Error setting --nview to " << argv[optind+2] << endl; phm2pj_usage(argv[0]); return (1); } - ostringstream desc; - desc << "phm2pj: NDet=" << opt_ndet << ", Nview=" << opt_nview << ", NRay=" << opt_nray << ", RotAngle=" << opt_rotangle << ", "; + std::ostringstream desc; + desc << "phm2pj: NDet=" << opt_ndet << ", Nview=" << opt_nview << ", NRay=" << opt_nray << ", RotAngle=" << opt_rotangle << ", Geometry=" << optGeometryName << ", "; if (optPhmFileName.length()) { desc << "PhantomFile=" << optPhmFileName; } else if (optPhmName != "") { @@ -217,7 +253,7 @@ phm2pj_main (int argc, char* argv[]) if (optPhmName != "") { phm.createFromPhantom (optPhmName.c_str()); if (phm.fail()) { - cout << phm.failMessage() << endl << endl; + std::cout << phm.failMessage() << endl << endl; phm2pj_usage(argv[0]); return (1); } @@ -225,7 +261,7 @@ phm2pj_main (int argc, char* argv[]) if (optPhmFileName != "") { #ifdef HAVE_MPI - cerr << "Can not read phantom from file in MPI mode" << endl; + std::cerr << "Can not read phantom from file in MPI mode\n"; return (1); #endif phm.createFromFile (optPhmFileName.c_str()); @@ -252,9 +288,9 @@ phm2pj_main (int argc, char* argv[]) #endif opt_rotangle *= PI; - Scanner scanner (phm, optGeometryName.c_str(), opt_ndet, opt_nview, opt_nray, opt_rotangle); + Scanner scanner (phm, optGeometryName.c_str(), opt_ndet, opt_nview, opt_nray, opt_rotangle, dOptFocalLength, dOptFieldOfView); if (scanner.fail()) { - cout << "Scanner Creation Error: " << scanner.failMessage() << endl; + std::cout << "Scanner Creation Error: " << scanner.failMessage() << endl; return (1); } #ifdef HAVE_MPI @@ -264,17 +300,20 @@ phm2pj_main (int argc, char* argv[]) if (mpiWorld.getRank() == 0) pjGlobal.initFromScanner (scanner); - if (opt_verbose) - pjGlobal.printScanInfo(); + if (opt_verbose) { + std::ostringstream os; + pjGlobal.printScanInfo(os); + std::cout << os.str(); + } Projections pjLocal (scanner); pjLocal.setNView (mpiWorld.getMyLocalWorkUnits()); if (opt_debug) - cout << "pjLocal->nview = " << pjLocal.nView() << " (process " << mpiWorld.getRank() << ")" << endl;; + std::cout << "pjLocal->nview = " << pjLocal.nView() << " (process " << mpiWorld.getRank() << ")\n";; TimerCollectiveMPI timerProject (mpiWorld.getComm()); - scanner.collectProjections (pjLocal, phm, mpiWorld.getMyStartWorkUnit(), opt_trace); + scanner.collectProjections (pjLocal, phm, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits(), false, opt_trace); if (opt_verbose) timerProject.timerEndAndReport ("Time to collect projections"); @@ -285,24 +324,25 @@ phm2pj_main (int argc, char* argv[]) #else Projections pjGlobal (scanner); - +#if HAVE_SGP SGPDriver* pSGPDriver = NULL; SGP* pSGP = NULL; - - if (opt_trace >= TRACE_PHM) { + if (opt_trace >= Trace::TRACE_PHANTOM) { pSGPDriver = new SGPDriver ("phm2pj", 600, 600); pSGP = new SGP (*pSGPDriver); } - - scanner.collectProjections (pjGlobal, phm, 0, opt_trace, pSGP); - - if (opt_trace >= TRACE_PHM) { - cout << "Press enter to continue\n"; + scanner.collectProjections (pjGlobal, phm, opt_trace, pSGP); + if (opt_trace >= Trace::TRACE_PHANTOM) { + std::cout << "Press enter to continue\n"; cio_kb_getc(); delete pSGP; pSGP = NULL; delete pSGPDriver; pSGPDriver = NULL; } +#else + scanner.collectProjections (pjGlobal, phm, opt_trace); +#endif + #endif #ifdef HAVE_MPI @@ -314,11 +354,12 @@ phm2pj_main (int argc, char* argv[]) pjGlobal.write (opt_outfile); if (opt_verbose) { phm.print(); - cout << endl; - pjGlobal.printScanInfo(); - cout << endl; - cout << " Remark: " << pjGlobal.remark() << endl; - cout << "Run time: " << pjGlobal.calcTime() << " seconds" << endl; + std::cout << endl; + ostringstream os; + pjGlobal.printScanInfo (os); + std::cout << os.str() << endl; + std::cout << " Remark: " << pjGlobal.remark() << endl; + std::cout << "Run time: " << pjGlobal.calcTime() << " seconds\n"; } } @@ -379,9 +420,9 @@ main (int argc, char* argv[]) // dmalloc_shutdown(); #endif } catch (exception e) { - cerr << "Exception: " << e.what() << endl; + std::cerr << "Exception: " << e.what() << endl; } catch (...) { - cerr << "Unknown exception" << endl; + std::cerr << "Unknown exception\n"; } return (retval);