** Date Started: 1984
**
** This is part of the CTSim program
-** Copyright (C) 1983-2000 Kevin Rosenberg
-**
-** $Id: phm2pj.cpp,v 1.30 2001/04/02 03:49:52 kevin Exp $
+** Copyright (C) 1983-2009 Kevin Rosenberg
**
** 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
#include "timer.h"
-enum { O_PHANTOM, O_DESC, O_NRAY, O_ROTANGLE, O_PHMFILE, O_GEOMETRY, O_FOCAL_LENGTH, O_CENTER_DETECTOR_LENGTH,
-O_VIEW_RATIO, O_SCAN_RATIO, O_TRACE, O_VERBOSE, O_HELP, O_DEBUG, O_VERSION };
+enum { O_PHANTOM, O_DESC, O_NRAY, O_ROTANGLE, O_PHMFILE, O_IMAGEFILE, O_GEOMETRY, O_FOCAL_LENGTH, O_CENTER_DETECTOR_LENGTH,
+O_VIEW_RATIO, O_SCAN_RATIO, O_OFFSETVIEW, O_TRACE, O_VERBOSE, O_HELP, O_DEBUG, O_VERSION };
-static struct option phm2pj_options[] =
+static struct option phm2pj_options[] =
{
{"phantom", 1, 0, O_PHANTOM},
{"phmfile", 1, 0, O_PHMFILE},
+ {"imagefile", 1, 0, O_IMAGEFILE},
{"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},
{"center-detector-length", 1, 0, O_CENTER_DETECTOR_LENGTH},
+ {"offsetview", 1, 0, O_OFFSETVIEW},
{"view-ratio", 1, 0, O_VIEW_RATIO},
{"scan-ratio", 1, 0, O_SCAN_RATIO},
{"trace", 1, 0, O_TRACE},
{0, 0, 0, 0}
};
-static const char* g_szIdStr = "$Id: phm2pj.cpp,v 1.30 2001/04/02 03:49:52 kevin Exp $";
+static const char* g_szIdStr = "$Id$";
-void
+void
phm2pj_usage (const char *program)
{
std::cout << "usage: " << fileBasename(program) << " outfile ndet nview [--phantom phantom-name] [--phmfile filename] [OPTIONS]\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 << " SELECT PHANTOM Use either --phantom, --phmfile, or --imagefile\n";
std::cout << " --phantom Phantom to use for projection\n";
std::cout << " herman Herman head phantom\n";
std::cout << " shepp-logan Shepp-Logan head phantom\n";
std::cout << " unit-pulse Unit pulse phantom\n";
std::cout << " --phmfile Get Phantom from phantom file\n";
- std::cout << " --desc Description of raysum\n";
+ std::cout << " --imagefile Get Phantom from imagefile\n";
+ std::cout << " --desc Add description for projection file\n";
std::cout << " --nray Number of rays per detector (default = 1)\n";
std::cout << " --rotangle Angle to rotate view through (fraction of a circle)\n";
std::cout << " (default = select appropriate for geometry)\n";
std::cout << " (default = 1)\n";
std::cout << " --scan-ratio Length to scan (scan diameter to view diameter)\n";
std::cout << " (default = 1)\n";
+ std::cout << " --offsetview Initial gantry offset in 'views' (default = 0)\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";
void GatherProjectionsMPI (MPIWorld& mpiWorld, Projections& pjGlobal, Projections& pjLocal, const int opt_debug);
#endif
-int
+int
phm2pj_main (int argc, char* const argv[])
{
Phantom phm;
std::string opt_desc;
std::string optPhmName;
std::string optPhmFileName;
+ std::string optImageFileName;
int opt_ndet;
int opt_nview;
+ int opt_offsetview = 0;
int opt_nray = 1;
double dOptFocalLength = 2.;
double dOptCenterDetectorLength = 2.;
double opt_rotangle = -1;
char* endptr = NULL;
char* endstr;
-
+ UNUSED(opt_debug);
+
#ifdef HAVE_MPI
MPIWorld mpiWorld (argc, argv);
#endif
-
+
Timer timerProgram;
-
+
#ifdef HAVE_MPI
if (mpiWorld.getRank() == 0) {
#endif
while (1) {
int c = getopt_long(argc, argv, "", phm2pj_options, NULL);
-
+
if (c == -1)
break;
-
+
switch (c) {
case O_PHANTOM:
optPhmName = optarg;
case O_PHMFILE:
optPhmFileName = optarg;
break;
+ case O_IMAGEFILE:
+ optImageFileName = optarg;
+ break;
case O_VERBOSE:
opt_verbose = 1;
break;
return (1);
}
break;
+ case O_OFFSETVIEW:
+ opt_offsetview = strtol(optarg, &endptr, 10);
+ endstr = optarg + strlen(optarg);
+ if (endptr != endstr) {
+ std::cerr << "Error setting --offsetview to %s" << optarg << std::endl;
+ phm2pj_usage(argv[0]);
+ return (1);
+ }
+ break;
+
case O_VERSION:
#ifdef VERSION
std::cout << "Version: " << VERSION << std::endl << g_szIdStr << std::endl;
return (1);
}
}
-
- if (optPhmName == "" && optPhmFileName == "") {
+
+ if (optPhmName.empty() && optPhmFileName.empty() && optImageFileName.empty()) {
std::cerr << "No phantom defined\n" << std::endl;
phm2pj_usage(argv[0]);
return (1);
}
+ if ((! optPhmName.empty() && !optPhmFileName.empty()) ||
+ (! optPhmName.empty() && !optImageFileName.empty()) ||
+ (! optPhmFileName.empty() && !optImageFileName.empty())) {
+ std::cerr << "Multiple phantoms define. Use only --phantom, --phmfile, or --imagefile\n" << std::endl;
+ phm2pj_usage(argv[0]);
+ return (1);
+ }
+
if (optind + 3 != argc) {
phm2pj_usage(argv[0]);
return (1);
}
-
+
opt_outfile = argv[optind];
opt_ndet = strtol(argv[optind+1], &endptr, 10);
endstr = argv[optind+1] + strlen(argv[optind+1]);
phm2pj_usage(argv[0]);
return (1);
}
-
+
if (opt_rotangle < 0) {
if (optGeometryName.compare ("parallel") == 0)
opt_rotangle = 0.5;
else
opt_rotangle = 1.0;
}
-
+
std::ostringstream desc;
- desc << "phm2pj: NDet=" << opt_ndet << ", Nview=" << opt_nview << ", NRay=" << opt_nray << ", RotAngle=" << opt_rotangle << ", Geometry=" << optGeometryName << ", ";
- if (optPhmFileName.length()) {
+ desc << "phm2pj: NDet=" << opt_ndet << ", Nview=" << opt_nview << ", NRay=" << opt_nray << ", RotAngle=" << opt_rotangle << ", OffsetView =" << opt_offsetview << ", Geometry=" << optGeometryName << ", ";
+
+ if (!optPhmFileName.empty()) {
desc << "PhantomFile=" << optPhmFileName;
- } else if (optPhmName != "") {
+ } else if (!optPhmName.empty()) {
desc << "Phantom=" << optPhmName;
+ } else if (!optImageFileName.empty()) {
+ desc << "Imagefile=" << optImageFileName;
}
if (opt_desc.length()) {
desc << ": " << opt_desc;
}
opt_desc = desc.str();
-
- if (optPhmName != "") {
+
+ if (!optPhmName.empty()) {
phm.createFromPhantom (optPhmName.c_str());
if (phm.fail()) {
std::cout << phm.failMessage() << std::endl << std::endl;
phm2pj_usage(argv[0]);
return (1);
}
- }
-
- if (optPhmFileName != "") {
+ } else if (!optPhmFileName.empty()) {
#ifdef HAVE_MPI
std::cerr << "Can not read phantom from file in MPI mode\n";
return (1);
#endif
- phm.createFromFile (optPhmFileName.c_str());
+ phm.createFromPhmFile (optPhmFileName.c_str());
+ } else if (!optImageFileName.empty()) {
+#ifdef HAVE_MPI
+ std::cerr << "Can not read image from file in MPI mode\n";
+ return (1);
+#endif
+ phm.createFromImageFile (optImageFileName.c_str());
}
-
+
#ifdef HAVE_MPI
}
#endif
-
+
#ifdef HAVE_MPI
TimerCollectiveMPI timerBcast(mpiWorld.getComm());
mpiWorld.BcastString (optPhmName);
mpiWorld.getComm().Bcast (&opt_trace, 1, MPI::INT, 0);
if (opt_verbose)
timerBcast.timerEndAndReport ("Time to broadcast variables");
-
+
if (mpiWorld.getRank() > 0 && optPhmName != "")
phm.createFromPhantom (optPhmName.c_str());
#endif
-
+
opt_rotangle *= TWOPI;
- Scanner scanner (phm, optGeometryName.c_str(), opt_ndet, opt_nview, opt_nray, opt_rotangle, dOptFocalLength,
- dOptCenterDetectorLength, dOptViewRatio, dOptScanRatio);
+ Scanner scanner (phm, optGeometryName.c_str(), opt_ndet, opt_nview, opt_offsetview, opt_nray,
+ opt_rotangle, dOptFocalLength, dOptCenterDetectorLength, dOptViewRatio, dOptScanRatio);
if (scanner.fail()) {
std::cout << "Scanner Creation Error: " << scanner.failMessage() << std::endl;
return (1);
}
#ifdef HAVE_MPI
mpiWorld.setTotalWorkUnits (opt_nview);
-
+
Projections pjGlobal;
if (mpiWorld.getRank() == 0)
pjGlobal.initFromScanner (scanner);
-
+
if (opt_verbose) {
std::ostringstream os;
pjGlobal.printScanInfo(os);
std::cout << os.str();
}
-
+
Projections pjLocal (scanner);
pjLocal.setNView (mpiWorld.getMyLocalWorkUnits());
-
+
if (opt_debug)
std::cout << "pjLocal->nview = " << pjLocal.nView() << " (process " << mpiWorld.getRank() << ")\n";;
-
+
TimerCollectiveMPI timerProject (mpiWorld.getComm());
scanner.collectProjections (pjLocal, phm, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits(), false, opt_trace);
if (opt_verbose)
timerProject.timerEndAndReport ("Time to collect projections");
-
+
TimerCollectiveMPI timerGather (mpiWorld.getComm());
GatherProjectionsMPI (mpiWorld, pjGlobal, pjLocal, opt_debug);
- if (opt_verbose)
+ if (opt_verbose)
timerGather.timerEndAndReport ("Time to gather projections");
-
+
#else
Projections pjGlobal (scanner);
- scanner.collectProjections (pjGlobal, phm, opt_trace);
+ scanner.collectProjections (pjGlobal, phm, 0, opt_nview, opt_offsetview, true, opt_trace);
#endif
-
+
#ifdef HAVE_MPI
- if (mpiWorld.getRank() == 0)
+ if (mpiWorld.getRank() == 0)
#endif
{
pjGlobal.setCalcTime (timerProgram.timerEnd());
std::cout << "Run time: " << pjGlobal.calcTime() << " seconds\n";
}
}
-
+
return (0);
}
double viewAngle = detArray.viewAngle();
int nDet = detArray.nDet();
DetectorValue* detval = detArray.detValues();
-
+
mpiWorld.getComm().Send(&viewAngle, 1, MPI::DOUBLE, 0, 0);
mpiWorld.getComm().Send(&nDet, 1, MPI::INT, 0, 0);
mpiWorld.getComm().Send(detval, nDet, MPI::FLOAT, 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++) {
int nDet;
DetectorArray& detArray = pjGlobal.getDetectorArray(iw);
DetectorValue* detval = detArray.detValues();
-
+
mpiWorld.getComm().Recv(&viewAngle, 1, MPI::DOUBLE, iProc, 0, status);
mpiWorld.getComm().Recv(&nDet, 1, MPI::INT, iProc, 0, status);
mpiWorld.getComm().Recv(detval, nDet, MPI::FLOAT, iProc, 0, status);
#ifndef NO_MAIN
-int
+int
main (int argc, char* argv[])
{
int retval = 1;
-
+
try {
retval = phm2pj_main(argc, argv);
#if HAVE_DMALLOC
} catch (...) {
std::cerr << "Unknown exception\n";
}
-
+
return (retval);
}
#endif