r328: *** empty log message ***
[ctsim.git] / tools / phm2if.cpp
index 53abeab5e0c1c46517988f9c4d83690dd3eb2e51..e0ca9c81238e97137226410af2f2ed05bff77ab5 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: phm2if.cpp,v 1.11 2000/08/27 20:32:55 kevin Exp $
+**  $Id: phm2if.cpp,v 1.17 2001/01/02 05:34:57 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
@@ -50,53 +50,53 @@ static struct option my_options[] =
   {0, 0, 0, 0}
 };
 
-static const char* g_szIdStr = "$Id: phm2if.cpp,v 1.11 2000/08/27 20:32:55 kevin Exp $";
+static const char* g_szIdStr = "$Id: phm2if.cpp,v 1.17 2001/01/02 05:34:57 kevin Exp $";
 
 void 
 phm2if_usage (const char *program)
 {
-  cout << "phm2if_usage: " << fileBasename(program) << " outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]" << endl;
-  cout << "Generate phantom image from a predefined --phantom or a --phmfile" << endl;
-  cout << endl;
-  cout << "     outfile         Name of output file for image" << endl;
-  cout << "     nx              Number of pixels X-axis" << endl;
-  cout << "     ny              Number of pixels Y-axis" << endl;
-  cout << "     --phantom       Phantom to use for projection" << endl;
-  cout << "        herman       Herman head phantom" << endl;
-  cout << "        herman-b     Herman head phantom (Bordered)" << endl;
-  cout << "        shepp-logan  Shepp-Logan head phantom" << endl;
-  cout << "        shepp-logan-b Shepp-Logan head phantom (Bordered)" << endl;
-  cout << "        unitpulse    Unit pulse phantom" << endl;
-  cout << "     --phmfile       Generate Phantom from phantom file" << endl;
-  cout << "     --filter        Generate Phantom from a filter function" << endl;
-  cout << "       abs_bandlimit Abs * Bandlimiting" << endl;
-  cout << "       abs_sinc      Abs * Sinc" << endl;
-  cout << "       abs_cos       Abs * Cosine" << endl;
-  cout << "       abs_hamming   Abs * Hamming" << endl;
-  cout << "       shepp         Shepp-Logan" << endl;
-  cout << "       bandlimit     Bandlimiting" << endl;
-  cout << "       sinc          Sinc" << endl;
-  cout << "       cos           Cosine" << endl;
-  cout << "       triangle      Triangle" << endl;
-  cout << "       hamming       Hamming" << endl;
-  cout << "     --filter-param  Alpha level for Hamming filter" << endl;
-  cout << "     --filter-domain Set domain of filter" << endl;
-  cout << "         spatial     Spatial domain (default)" << endl;
-  cout << "         freq        Frequency domain" << endl;
-  cout << "     --filter-bw     Filter bandwidth (default = 1)" << endl;
-  cout << "     --desc          Description of raysum" << endl;
-  cout << "     --nsample       Number of samples per axis per pixel (default = 1)" << endl;
-  cout << "     --trace         Trace level to use" << endl;
-  cout << "        none         No tracing (default)" << endl;
-  cout << "        console      Trace text level" << endl;
-  cout << "        phantom      Trace phantom" << endl;
-  cout << "        proj         Trace projections" << endl;
-  cout << "        plot         Trace plot" << endl;
-  cout << "        clipping     Trace clipping" << endl;
-  cout << "     --debug         Debug mode" << endl;
-  cout << "     --verbose       Verbose mode" << endl;
-  cout << "     --version       Print version" << endl;
-  cout << "     --help          Print this help message" << endl;
+  std::cout << "phm2if_usage: " << fileBasename(program) << " outfile nx ny [--phantom phantom-name] [--phmfile filename] [--filter filter-name] [OPTIONS]\n";
+  std::cout << "Generate phantom image from a predefined --phantom or a --phmfile\n";
+  std::cout << std::endl;
+  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 << "     --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       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 << "       abs_sinc      Abs * Sinc\n";
+  std::cout << "       abs_cos       Abs * Cosine\n";
+  std::cout << "       abs_hamming   Abs * Hamming\n";
+  std::cout << "       shepp         Shepp-Logan\n";
+  std::cout << "       bandlimit     Bandlimiting\n";
+  std::cout << "       sinc          Sinc\n";
+  std::cout << "       cos           Cosine\n";
+  std::cout << "       triangle      Triangle\n";
+  std::cout << "       hamming       Hamming\n";
+  std::cout << "     --filter-param  Alpha level for Hamming filter\n";
+  std::cout << "     --filter-domain Set domain of filter\n";
+  std::cout << "         spatial     Spatial domain (default)\n";
+  std::cout << "         freq        Frequency domain\n";
+  std::cout << "     --filter-bw     Filter bandwidth (default = 1)\n";
+  std::cout << "     --desc          Description of raysum\n";
+  std::cout << "     --nsample       Number of samples per axis per pixel (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\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 << "     --help          Print this help message\n";
 }
 
 #ifdef HAVE_MPI
@@ -108,12 +108,12 @@ phm2if_main (int argc, char* argv[])
 {
   ImageFile* pImGlobal = NULL;
   Phantom phm;
-  string optPhmName (Phantom::convertPhantomIDToName(Phantom::PHM_HERMAN));
-  string optFilterName;
-  string optDomainName (SignalFilter::convertDomainIDToName (SignalFilter::DOMAIN_SPATIAL));
-  string optOutFilename;
-  string optDesc;
-  string optPhmFilename;
+  std::string optPhmName;
+  std::string optFilterName;
+  std::string optDomainName (SignalFilter::convertDomainIDToName (SignalFilter::DOMAIN_SPATIAL));
+  std::string optOutFilename;
+  std::string optDesc;
+  std::string optPhmFilename;
   int opt_nx = 0;
   int opt_ny = 0;
   int opt_nsample = 1;
@@ -193,9 +193,9 @@ phm2if_main (int argc, char* argv[])
        break;
         case O_VERSION:
 #ifdef VERSION
-         cout << "Version " << VERSION << endl << g_szIdStr << endl;
+         std::cout << "Version " << VERSION << std::endl << g_szIdStr << std::endl;
 #else
-          cerr << "Unknown version number" << endl;
+          std::cerr << "Unknown version number\n";
 #endif
       case O_HELP:
       case '?':
@@ -208,7 +208,7 @@ phm2if_main (int argc, char* argv[])
     }
     
     if (optPhmName == "" && optFilterName == "" && optPhmFilename == "") {
-      cerr << "No phantom defined" << endl << endl;
+      std::cerr << "No phantom defined\n" << std::endl;
       phm2if_usage(argv[0]);
       return (1);
     }
@@ -233,7 +233,7 @@ phm2if_main (int argc, char* argv[])
       return (1);
     }
     
-    ostringstream oss;
+    std::ostringstream oss;
     oss << "phm2if: nx=" << opt_nx << ", ny=" << opt_ny << ", nsample=" << opt_nsample << ", ";
     if (optPhmFilename != "")
       oss << "phantomFile=" << optPhmFilename;
@@ -249,7 +249,7 @@ phm2if_main (int argc, char* argv[])
     if (optPhmName != "") {
       phm.createFromPhantom (optPhmName.c_str());
       if (phm.fail()) {
-       cout << phm.failMessage() << endl << endl;
+       std::cout << phm.failMessage() << std::endl << std::endl;
        phm2if_usage(argv[0]);
        return (1);
       }
@@ -259,13 +259,13 @@ phm2if_main (int argc, char* argv[])
       phm.createFromFile(optPhmFilename.c_str());
 #ifdef HAVE_MPI
       if (mpiWorld.getRank() == 0) 
-       cerr << "Can't use phantom from file in MPI mode" << endl;
+       std::cerr << "Can't use phantom from file in MPI mode\n";
       return (1);
 #endif
     }
 
     if (optVerbose)
-      cout << "Rasterize Phantom to Image" << endl << endl;
+      std::cout << "Rasterize Phantom to Image\n" << std::endl;
 #ifdef HAVE_MPI
   }
 #endif
@@ -301,7 +301,7 @@ phm2if_main (int argc, char* argv[])
   pImGlobal = new ImageFile (opt_nx, opt_ny);
 #endif
 
-  ImageFileArray v;
+  ImageFileArray v = NULL;
 #ifdef HAVE_MPI
   if (mpiWorld.getRank() == 0)
     v = pImGlobal->getArray ();
@@ -316,7 +316,7 @@ phm2if_main (int argc, char* argv[])
     }
   } else {
     TimerCollectiveMPI timerRasterize (mpiWorld.getComm());
-    phm.convertToImagefile (*pImLocal, opt_nsample, optTrace, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits());
+    phm.convertToImagefile (*pImLocal, opt_nsample, optTrace, mpiWorld.getMyStartWorkUnit(), mpiWorld.getMyLocalWorkUnits(), false);
     if (optVerbose)
       timerRasterize.timerEndAndReport ("Time to rasterize phantom");
 
@@ -348,16 +348,17 @@ phm2if_main (int argc, char* argv[])
     pImGlobal->labelAdd (Array2dFileLabel::L_HISTORY, optDesc.c_str(), calctime);
     pImGlobal->fileWrite (optOutFilename.c_str());
     if (optVerbose)
-      cout << "Time to rasterized phantom: " << calctime << " seconds" << endl;
+      std::cout << "Time to rasterized phantom: " << calctime << " seconds\n";
 
     if (optTrace >= Trace::TRACE_PHANTOM) {
       double dmin, dmax;
       int nscale;
       
-      printf ("Enter display size scale (nominal = 1): ");
-      scanf ("%d", &nscale);
-      printf ("Enter minimum and maximum densities (min, max): ");
-      scanf ("%lf %lf", &dmin, &dmax);
+      std::cout << "Enter display size scale (nominal = 1): ";
+      std::cin >> nscale;
+      std::cout ("Enter minimum and maximum densities (min, max): ";
+      std::cin >> dmin;\r
+      std::cin >> dmax;
       pImGlobal->displayScaling (nscale, dmin, dmax);
     }
   }
@@ -406,9 +407,9 @@ main (int argc, char* argv[])
   try {
     retval = phm2if_main(argc, argv);
   } catch (exception e) {
-    cerr << "Exception: " << e.what() << endl;
+    std::cerr << "Exception: " << e.what() << std::endl;
   } catch (...) {
-    cerr << "Unknown exception" << endl;
+    std::cerr << "Unknown exception\n";
   }
 
   return (retval);