r117: *** empty log message ***
[ctsim.git] / src / phm2pj.cpp
index fe831548437ad183353f8882e7d3f3479df79443..a4510c40bb3b09312325570cae510776cf0ab143 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: phm2pj.cpp,v 1.1 2000/06/17 20:12:15 kevin Exp $
+**  $Id: phm2pj.cpp,v 1.3 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
@@ -59,6 +59,7 @@ phm2pj_usage (const char *program)
   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;
@@ -91,10 +92,11 @@ phm2pj_main (int argc, char* argv[])
   char *opt_outfile = NULL;
   string opt_desc;
   string opt_phmfilename;
-  int opt_ndet, opt_nview;
+  int opt_ndet;
+  int opt_nview;
   int opt_nray = 1;
   int opt_trace = 0;
-  int opt_phmnum = -1;
+  string optPhmName;
   int opt_verbose = 0;
   int opt_debug = 0;
   double opt_rotangle = 1;
@@ -118,11 +120,12 @@ phm2pj_main (int argc, char* argv[])
       
       switch (c) {
       case O_PHANTOM:
-       if ((opt_phmnum = opt_set_phantom (optarg)) < 0) {
+       optPhmName = optarg;
+       if (! phm.createFromPhantom (optPhmName.c_str())) {
+         cout << "ERROR: Invalid phantom name " << optPhmName << endl << endl;
          phm2pj_usage(argv[0]);
          return (1);
        }
-       phm.create (opt_phmnum);
        break;
       case O_PHMFILE:
 #ifdef HAVE_MPI
@@ -169,11 +172,11 @@ phm2pj_main (int argc, char* argv[])
        break;
         case O_VERSION:
 #ifdef VERSION
-       cout << "Version: " << VERSION << endl;
+         cout << "Version: " << VERSION << endl;
 #else
-        cout << "Unknown version number" << endl;
+          cout << "Unknown version number" << endl;
 #endif
-         exit(0);
+         return (0);
       case O_HELP:
       case '?':
        phm2pj_usage(argv[0]);
@@ -214,8 +217,8 @@ phm2pj_main (int argc, char* argv[])
     desc << "Raysum_Collect: NDet=" << opt_ndet << ", Nview=" << opt_nview << ", NRay=" << opt_nray << ", RotAngle=" << opt_rotangle << ", ";
     if (opt_phmfilename.length()) {
       desc << "PhantomFile=" << opt_phmfilename;
-    } else if (opt_phmnum != -1) {
-      desc << "Phantom=" << name_of_phantom(opt_phmnum);
+    } else if (optPhmName != "") {
+      desc << "Phantom=" << optPhmName;
     }
     if (opt_desc.length()) {
       desc << ": " << opt_desc;
@@ -226,17 +229,19 @@ phm2pj_main (int argc, char* argv[])
 #endif
 
 #ifdef HAVE_MPI
+  TimerCollectiveMPI timerBcast(mpiWorld.getComm());
+  mpiWorld.BcastString (optPhmName);
   mpiWorld.getComm().Bcast (&opt_rotangle, 1, MPI::DOUBLE, 0);
   mpiWorld.getComm().Bcast (&opt_nview, 1, MPI::INT, 0);
   mpiWorld.getComm().Bcast (&opt_ndet, 1, MPI::INT, 0);
   mpiWorld.getComm().Bcast (&opt_nray, 1, MPI::INT, 0);
-  mpiWorld.getComm().Bcast (&opt_phmnum, 1, MPI::INT, 0);
   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);
+  timerBcast.timerEndAndReport ("Time to broadcast variables");
 
-  if (mpiWorld.getRank() > 0 && opt_phmnum >= 0)
-    phm.create (opt_phmnum);
+  if (mpiWorld.getRank() > 0 && optPhmName != "")
+    phm.createFromPhantom (optPhmName.c_str());
 #endif
 
   opt_rotangle *= PI;
@@ -246,24 +251,28 @@ phm2pj_main (int argc, char* argv[])
   mpiWorld.setTotalWorkUnits (opt_nview);
 
   Projections pjGlobal;
-  if (mpiWorld.getRank() == 0) {
-    pjGlobal = Projections (scanner);
-  }
+  if (mpiWorld.getRank() == 0)
+    pjGlobal.initFromScanner (scanner);
   
-  Scanner localScanner (phm, opt_geometry, opt_ndet, mpiWorld.getMyLocalWorkUnits(), opt_nray, opt_rotangle);
-  Projections pjLocal (localScanner);
+  if (opt_verbose)
+    pjGlobal.printScanInfo();
+
+  Projections pjLocal (scanner);
+  pjLocal.setNView (mpiWorld.getMyLocalWorkUnits());
+
   if (opt_debug)
     cout << "pjLocal->nview = " << pjLocal.nView() << " (process " << mpiWorld.getRank() << ")" << endl;;
 
-  TimerMPI timerProject (mpiWorld.getComm());
-  localScanner.collectProjections (pjLocal, phm, mpiWorld.getMyStartWorkUnit(), opt_trace);
+  TimerCollectiveMPI timerProject (mpiWorld.getComm());
+  scanner.collectProjections (pjLocal, phm, mpiWorld.getMyStartWorkUnit(), opt_trace);
   if (opt_verbose)
     timerProject.timerEndAndReport ("Time to collect projections");
 
-  TimerMPI timerGather (mpiWorld.getComm());
+  TimerCollectiveMPI timerGather (mpiWorld.getComm());
   GatherProjectionsMPI (mpiWorld, pjGlobal, pjLocal, opt_debug);
-  if (opt_verbose)
-    timerGather.timerEndAndReport ("Time to gather projections");
+  if (opt_verbose) 
+     timerGather.timerEndAndReport ("Time to gather projections");
+
 #else
   Projections pjGlobal (scanner);
   scanner.collectProjections (pjGlobal, phm, 0, opt_trace);
@@ -281,7 +290,7 @@ phm2pj_main (int argc, char* argv[])
        cout << endl;
        pjGlobal.printScanInfo();
        cout << endl;
-       cout << "Remark: " << pjGlobal.remark() << endl;
+       cout << "  Remark: " << pjGlobal.remark() << endl;
        cout << "Run time: " << pjGlobal.calcTime() << " seconds" << endl;
       }
     }
@@ -317,7 +326,7 @@ void GatherProjectionsMPI (MPIWorld& mpiWorld, Projections& pjGlobal, Projection
        MPI::Status status;
        double viewAngle;
        int nDet;
-       DetectorArray detArray = pjGlobal.getDetectorArray(iw);
+       DetectorArray& detArray = pjGlobal.getDetectorArray(iw);
        DetectorValue* detval = detArray.detValues();
 
        mpiWorld.getComm().Recv(&viewAngle, 1, MPI::DOUBLE, iProc, 0, status);
@@ -327,7 +336,6 @@ void GatherProjectionsMPI (MPIWorld& mpiWorld, Projections& pjGlobal, Projection
       }
     }
   }
-
 }
 #endif
 
@@ -336,7 +344,17 @@ void GatherProjectionsMPI (MPIWorld& mpiWorld, Projections& pjGlobal, Projection
 int 
 main (int argc, char* argv[])
 {
-  return (phm2pj_main(argc, argv));
+  int retval = 1;
+
+  try {
+    retval = phm2pj_main(argc, argv);
+  } catch (exception e) {
+    cerr << "Exception: " << e.what() << endl;
+  } catch (...) {
+    cerr << "Unknown exception" << endl;
+  }
+
+  return (retval);
 }
 #endif