projects
/
ctsim.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
better cleaning
[ctsim.git]
/
tools
/
phm2if.cpp
diff --git
a/tools/phm2if.cpp
b/tools/phm2if.cpp
index f7f9551d62505bc5f7447df0b8f69cc5492a5d7d..ab3115107b8998ec4b235a91886bc9ff3291d233 100644
(file)
--- a/
tools/phm2if.cpp
+++ b/
tools/phm2if.cpp
@@
-9,7
+9,7
@@
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id
: phm2if.cpp,v 1.19 2001/01/02 13:57:52 kevin Exp
$
+** $Id$
**
** 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
**
** 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,10
+29,10
@@
#include "timer.h"
#include "timer.h"
-enum { O_PHANTOM, O_DESC, O_NSAMPLE, O_FILTER, O_
TRACE, O_VERBOSE, O_HELP,
+enum { O_PHANTOM, O_DESC, O_NSAMPLE, O_FILTER, O_
VIEW_RATIO, O_TRACE, O_VERBOSE, O_HELP,
O_PHMFILE, O_FILTER_DOMAIN, O_FILTER_BW, O_FILTER_PARAM, O_DEBUG, O_VERSION };
O_PHMFILE, O_FILTER_DOMAIN, O_FILTER_BW, O_FILTER_PARAM, O_DEBUG, O_VERSION };
-static struct option my_options[] =
+static struct option my_options[] =
{
{"phantom", 1, 0, O_PHANTOM},
{"phmfile", 1, 0, O_PHMFILE},
{
{"phantom", 1, 0, O_PHANTOM},
{"phmfile", 1, 0, O_PHMFILE},
@@
-43,6
+43,7
@@
static struct option my_options[] =
{"filter-bw", 1, 0, O_FILTER_BW},
{"filter-param", 1, 0, O_FILTER_PARAM},
{"trace", 1, 0, O_TRACE},
{"filter-bw", 1, 0, O_FILTER_BW},
{"filter-param", 1, 0, O_FILTER_PARAM},
{"trace", 1, 0, O_TRACE},
+ {"view-ratio", 1, 0, O_VIEW_RATIO},
{"verbose", 0, 0, O_VERBOSE},
{"debug", 0, 0, O_DEBUG},
{"help", 0, 0, O_HELP},
{"verbose", 0, 0, O_VERBOSE},
{"debug", 0, 0, O_DEBUG},
{"help", 0, 0, O_HELP},
@@
-50,9
+51,9
@@
static struct option my_options[] =
{0, 0, 0, 0}
};
{0, 0, 0, 0}
};
-static const char* g_szIdStr = "$Id
: phm2if.cpp,v 1.19 2001/01/02 13:57:52 kevin Exp
$";
+static const char* g_szIdStr = "$Id$";
-void
+void
phm2if_usage (const char *program)
{
std::cout << "phm2if_usage: " << fileBasename(program) << " outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]\n";
phm2if_usage (const char *program)
{
std::cout << "phm2if_usage: " << fileBasename(program) << " outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]\n";
@@
-61,12
+62,11
@@
phm2if_usage (const char *program)
std::cout << " outfile Name of output file for image\n";
std::cout << " nx Number of pixels X-axis\n";
std::cout << " ny Number of pixels Y-axis\n";
std::cout << " outfile Name of output file for image\n";
std::cout << " nx Number of pixels X-axis\n";
std::cout << " ny Number of pixels Y-axis\n";
+ std::cout << " --view-ratio View diameter to phantom diameter ratio (default = 1)\n";
std::cout << " --phantom Phantom to use for projection\n";
std::cout << " herman Herman head phantom\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 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 << " unit-pulse Unit pulse phantom\n";
std::cout << " --phmfile Generate Phantom from phantom file\n";
std::cout << " --filter Generate Phantom from a filter function\n";
std::cout << " abs_bandlimit Abs * Bandlimiting\n";
std::cout << " --phmfile Generate Phantom from phantom file\n";
std::cout << " --filter Generate Phantom from a filter function\n";
std::cout << " abs_bandlimit Abs * Bandlimiting\n";
@@
-89,10
+89,6
@@
phm2if_usage (const char *program)
std::cout << " --trace Trace level to use\n";
std::cout << " none No tracing (default)\n";
std::cout << " console Trace text level\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\n";
- std::cout << " proj Trace projections\n";
- std::cout << " plot Trace plot\n";
- std::cout << " clipping Trace clipping\n";
std::cout << " --debug Debug mode\n";
std::cout << " --verbose Verbose mode\n";
std::cout << " --version Print version\n";
std::cout << " --debug Debug mode\n";
std::cout << " --verbose Verbose mode\n";
std::cout << " --version Print version\n";
@@
-103,8
+99,8
@@
phm2if_usage (const char *program)
void mpi_gather_image (MPIWorld& mpiWorld, ImageFile* pImGlobal, ImageFile* pImLocal, const int optDebug);
#endif
void mpi_gather_image (MPIWorld& mpiWorld, ImageFile* pImGlobal, ImageFile* pImLocal, const int optDebug);
#endif
-int
-phm2if_main (int argc, char* argv[])
+int
+phm2if_main (int argc, char*
const
argv[])
{
ImageFile* pImGlobal = NULL;
Phantom phm;
{
ImageFile* pImGlobal = NULL;
Phantom phm;
@@
-117,6
+113,7
@@
phm2if_main (int argc, char* argv[])
int opt_nx = 0;
int opt_ny = 0;
int opt_nsample = 1;
int opt_nx = 0;
int opt_ny = 0;
int opt_nsample = 1;
+ double optViewRatio = 1.;
double optFilterParam = 1.;
double optFilterBW = 1.;
int optTrace = Trace::TRACE_NONE;
double optFilterParam = 1.;
double optFilterBW = 1.;
int optTrace = Trace::TRACE_NONE;
@@
-125,7
+122,7
@@
phm2if_main (int argc, char* argv[])
char *endptr = NULL;
char *endstr;
Timer timerProgram;
char *endptr = NULL;
char *endstr;
Timer timerProgram;
-
+
#ifdef HAVE_MPI
ImageFile* pImLocal = NULL;
MPIWorld mpiWorld (argc, argv);
#ifdef HAVE_MPI
ImageFile* pImLocal = NULL;
MPIWorld mpiWorld (argc, argv);
@@
-135,7
+132,7
@@
phm2if_main (int argc, char* argv[])
int c = getopt_long(argc, argv, "", my_options, NULL);
if (c == -1)
break;
int c = getopt_long(argc, argv, "", my_options, NULL);
if (c == -1)
break;
-
+
switch (c) {
case O_PHANTOM:
optPhmName = optarg;
switch (c) {
case O_PHANTOM:
optPhmName = optarg;
@@
-173,6
+170,15
@@
phm2if_main (int argc, char* argv[])
return (1);
}
break;
return (1);
}
break;
+ case O_VIEW_RATIO:
+ optViewRatio = strtod(optarg, &endptr);
+ endstr = optarg + strlen(optarg);
+ if (endptr != endstr) {
+ sys_error(ERR_SEVERE,"Error setting --view-ratio to %s\n", optarg);
+ phm2if_usage(argv[0]);
+ return (1);
+ }
+ break;
case O_FILTER_PARAM:
optFilterParam = strtod(optarg, &endptr);
endstr = optarg + strlen(optarg);
case O_FILTER_PARAM:
optFilterParam = strtod(optarg, &endptr);
endstr = optarg + strlen(optarg);
@@
-206,13
+212,13
@@
phm2if_main (int argc, char* argv[])
return (1);
}
}
return (1);
}
}
-
+
if (optPhmName == "" && optFilterName == "" && optPhmFilename == "") {
std::cerr << "No phantom defined\n" << std::endl;
phm2if_usage(argv[0]);
return (1);
}
if (optPhmName == "" && optFilterName == "" && optPhmFilename == "") {
std::cerr << "No phantom defined\n" << std::endl;
phm2if_usage(argv[0]);
return (1);
}
-
+
if (optind + 3 != argc) {
phm2if_usage(argv[0]);
return (1);
if (optind + 3 != argc) {
phm2if_usage(argv[0]);
return (1);
@@
-232,9
+238,9
@@
phm2if_main (int argc, char* argv[])
phm2if_usage(argv[0]);
return (1);
}
phm2if_usage(argv[0]);
return (1);
}
-
+
std::ostringstream oss;
std::ostringstream oss;
- oss << "phm2if: nx=" << opt_nx << ", ny=" << opt_ny << ", nsample=" << opt_nsample << ", ";
+ oss << "phm2if: nx=" << opt_nx << ", ny=" << opt_ny << ",
viewRatio=" << optViewRatio << ",
nsample=" << opt_nsample << ", ";
if (optPhmFilename != "")
oss << "phantomFile=" << optPhmFilename;
else if (optPhmName != "")
if (optPhmFilename != "")
oss << "phantomFile=" << optPhmFilename;
else if (optPhmName != "")
@@
-245,7
+251,7
@@
phm2if_main (int argc, char* argv[])
if (optDesc != "")
oss << ": " << optDesc;
optDesc = oss.str();
if (optDesc != "")
oss << ": " << optDesc;
optDesc = oss.str();
-
+
if (optPhmName != "") {
phm.createFromPhantom (optPhmName.c_str());
if (phm.fail()) {
if (optPhmName != "") {
phm.createFromPhantom (optPhmName.c_str());
if (phm.fail()) {
@@
-254,22
+260,22
@@
phm2if_main (int argc, char* argv[])
return (1);
}
}
return (1);
}
}
-
+
if (optPhmFilename != "") {
phm.createFromFile(optPhmFilename.c_str());
#ifdef HAVE_MPI
if (optPhmFilename != "") {
phm.createFromFile(optPhmFilename.c_str());
#ifdef HAVE_MPI
- if (mpiWorld.getRank() == 0)
+ if (mpiWorld.getRank() == 0)
std::cerr << "Can't use phantom from file in MPI mode\n";
return (1);
#endif
}
std::cerr << "Can't use phantom from file in MPI mode\n";
return (1);
#endif
}
-
+
if (optVerbose)
std::cout << "Rasterize Phantom to Image\n" << std::endl;
#ifdef HAVE_MPI
}
#endif
if (optVerbose)
std::cout << "Rasterize Phantom to Image\n" << std::endl;
#ifdef HAVE_MPI
}
#endif
-
+
#ifdef HAVE_MPI
TimerCollectiveMPI timerBcast (mpiWorld.getComm());
mpiWorld.BcastString (optPhmName);
#ifdef HAVE_MPI
TimerCollectiveMPI timerBcast (mpiWorld.getComm());
mpiWorld.BcastString (optPhmName);
@@
-279,20
+285,21
@@
phm2if_main (int argc, char* argv[])
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_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 (&optViewRatio, 1, MPI::DOUBLE, 0);
mpiWorld.getComm().Bcast (&optFilterParam, 1, MPI::DOUBLE, 0);
mpiWorld.getComm().Bcast (&optFilterBW, 1, MPI::DOUBLE, 0);
mpiWorld.getComm().Bcast (&optFilterParam, 1, MPI::DOUBLE, 0);
mpiWorld.getComm().Bcast (&optFilterBW, 1, MPI::DOUBLE, 0);
-
+
mpiWorld.BcastString (optFilterName);
mpiWorld.BcastString (optDomainName);
mpiWorld.BcastString (optFilterName);
mpiWorld.BcastString (optDomainName);
-
+
if (optVerbose)
timerBcast.timerEndAndReport ("Time to broadcast variables");
if (optVerbose)
timerBcast.timerEndAndReport ("Time to broadcast variables");
-
+
mpiWorld.setTotalWorkUnits (opt_nx);
mpiWorld.setTotalWorkUnits (opt_nx);
-
+
if (mpiWorld.getRank() > 0 && optPhmName != "")
phm.createFromPhantom (optPhmName.c_str());
if (mpiWorld.getRank() > 0 && optPhmName != "")
phm.createFromPhantom (optPhmName.c_str());
-
+
if (mpiWorld.getRank() == 0) {
pImGlobal = new ImageFile (opt_nx, opt_ny);
}
if (mpiWorld.getRank() == 0) {
pImGlobal = new ImageFile (opt_nx, opt_ny);
}
@@
-300,12
+307,12
@@
phm2if_main (int argc, char* argv[])
#else
pImGlobal = new ImageFile (opt_nx, opt_ny);
#endif
#else
pImGlobal = new ImageFile (opt_nx, opt_ny);
#endif
-
+
ImageFileArray v = NULL;
#ifdef HAVE_MPI
if (mpiWorld.getRank() == 0)
v = pImGlobal->getArray ();
ImageFileArray v = NULL;
#ifdef HAVE_MPI
if (mpiWorld.getRank() == 0)
v = pImGlobal->getArray ();
-
+
if (phm.getComposition() == P_UNIT_PULSE) {
if (mpiWorld.getRank() == 0) {
v[opt_nx/2][opt_ny/2] = 1.;
if (phm.getComposition() == P_UNIT_PULSE) {
if (mpiWorld.getRank() == 0) {
v[opt_nx/2][opt_ny/2] = 1.;
@@
-316,10
+323,10
@@
phm2if_main (int argc, char* argv[])
}
} else {
TimerCollectiveMPI timerRasterize (mpiWorld.getComm());
}
} else {
TimerCollectiveMPI timerRasterize (mpiWorld.getComm());
- phm.convertToImagefile (*pImLocal, opt_nsample, optTrace, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits(), false);
+ phm.convertToImagefile (*pImLocal, opt
ViewRatio, opt
_nsample, optTrace, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits(), false);
if (optVerbose)
timerRasterize.timerEndAndReport ("Time to rasterize phantom");
if (optVerbose)
timerRasterize.timerEndAndReport ("Time to rasterize phantom");
-
+
TimerCollectiveMPI timerGather (mpiWorld.getComm());
mpi_gather_image (mpiWorld, pImGlobal, pImLocal, optDebug);
if (optVerbose)
TimerCollectiveMPI timerGather (mpiWorld.getComm());
mpi_gather_image (mpiWorld, pImGlobal, pImLocal, optDebug);
if (optVerbose)
@@
-332,16
+339,12
@@
phm2if_main (int argc, char* argv[])
} else if (optFilterName != "") {
pImGlobal->filterResponse (optDomainName.c_str(), optFilterBW, optFilterName.c_str(), optFilterParam);
} else {
} else if (optFilterName != "") {
pImGlobal->filterResponse (optDomainName.c_str(), optFilterBW, optFilterName.c_str(), optFilterParam);
} else {
-#if HAVE_SGP
- if (optTrace >= Trace::TRACE_PHANTOM)
- phm.show();
-#endif
- phm.convertToImagefile (*pImGlobal, opt_nsample, optTrace);
+ phm.convertToImagefile (*pImGlobal, optViewRatio, opt_nsample, optTrace);
}
#endif
}
#endif
-
+
#ifdef HAVE_MPI
#ifdef HAVE_MPI
- if (mpiWorld.getRank() == 0)
+ if (mpiWorld.getRank() == 0)
#endif
{
double calctime = timerProgram.timerEnd ();
#endif
{
double calctime = timerProgram.timerEnd ();
@@
-349,26
+352,13
@@
phm2if_main (int argc, char* argv[])
pImGlobal->fileWrite (optOutFilename.c_str());
if (optVerbose)
std::cout << "Time to rasterize phantom: " << calctime << " seconds\n";
pImGlobal->fileWrite (optOutFilename.c_str());
if (optVerbose)
std::cout << "Time to rasterize phantom: " << calctime << " seconds\n";
-
- if (optTrace >= Trace::TRACE_PHANTOM) {
- double dmin, dmax;
- int nscale;
-
- std::cout << "Enter display size scale (nominal = 1): ";
- std::cin >> nscale;
- std::cout << "Enter minimum and maximum densities (min, max): ";
- std::cin >> dmin;
-
- std::cin >> dmax;
- pImGlobal->displayScaling (nscale, dmin, dmax);
- }
}
}
-
+
delete pImGlobal;
#ifdef HAVE_MPI
delete pImLocal;
#endif
delete pImGlobal;
#ifdef HAVE_MPI
delete pImLocal;
#endif
-
+
return (0);
}
return (0);
}
@@
-380,13
+370,13
@@
void mpi_gather_image (MPIWorld& mpiWorld, ImageFile* pImGlobal, ImageFile* pImL
ImageFileArray vLocal = pImLocal->getArray();
ImageFileArray vGlobal = NULL;
int nyLocal = pImLocal->ny();
ImageFileArray vLocal = pImLocal->getArray();
ImageFileArray vGlobal = NULL;
int nyLocal = pImLocal->ny();
-
+
if (mpiWorld.getRank() == 0)
vGlobal = pImGlobal->getArray();
if (mpiWorld.getRank() == 0)
vGlobal = pImGlobal->getArray();
-
+
for (int iw = 0; iw < mpiWorld.getMyLocalWorkUnits(); iw++)
mpiWorld.getComm().Send(vLocal[iw], nyLocal, pImLocal->getMPIDataType(), 0, 0);
for (int iw = 0; iw < mpiWorld.getMyLocalWorkUnits(); iw++)
mpiWorld.getComm().Send(vLocal[iw], nyLocal, pImLocal->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++) {
if (mpiWorld.getRank() == 0) {
for (int iProc = 0; iProc < mpiWorld.getNumProcessors(); iProc++) {
for (int iw = mpiWorld.getStartWorkUnit(iProc); iw <= mpiWorld.getEndWorkUnit(iProc); iw++) {
@@
-395,16
+385,16
@@
void mpi_gather_image (MPIWorld& mpiWorld, ImageFile* pImGlobal, ImageFile* pImL
}
}
}
}
}
}
-
+
}
#endif
#ifndef NO_MAIN
}
#endif
#ifndef NO_MAIN
-int
+int
main (int argc, char* argv[])
{
int retval = 1;
main (int argc, char* argv[])
{
int retval = 1;
-
+
try {
retval = phm2if_main(argc, argv);
} catch (exception e) {
try {
retval = phm2if_main(argc, argv);
} catch (exception e) {
@@
-412,7
+402,7
@@
main (int argc, char* argv[])
} catch (...) {
std::cerr << "Unknown exception\n";
}
} catch (...) {
std::cerr << "Unknown exception\n";
}
-
+
return (retval);
}
#endif
return (retval);
}
#endif