r11859: Canonicalize whitespace
[ctsim.git] / tools / pjrec.cpp
index 7426f47125117b48c16a152b6262403808e7fbeb..427c5a82fc9acd9f65319432467d85089ed4edec 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: pjrec.cpp,v 1.20 2000/12/17 22:30:34 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
@@ -48,9 +48,9 @@ static struct option my_options[] =
   {0, 0, 0, 0}
 };
 
-static const char* g_szIdStr = "$Id: pjrec.cpp,v 1.20 2000/12/17 22:30:34 kevin Exp $";
+static const char* g_szIdStr = "$Id$";
 
-void 
+void
 pjrec_usage (const char *program)
 {
   std::cout << "usage: " << fileBasename(program) << " raysum-file image-file nx-image ny-image [OPTIONS]" << std::endl;
@@ -61,24 +61,27 @@ pjrec_usage (const char *program)
   std::cout << "  nx-image        Number of columns in output image" << std::endl;
   std::cout << "  ny-image        Number of rows in output image" << std::endl;
   std::cout << "  --interp        Interpolation method during backprojection" << std::endl;
-  std::cout << "    nearest     Nearest neighbor interpolation" << std::endl;
-  std::cout << "    linear      Linear interpolation" << std::endl;
+  std::cout << "    nearest         Nearest neighbor interpolation" << std::endl;
+  std::cout << "    linear          Linear interpolation (default)" << std::endl;
+  std::cout << "    cubic           Cubic interpolation\n";
 #if HAVE_BSPLINE_INTERP
-  std::cout << "    bspline     B-spline interpolation" << std::endl;
+  std::cout << "    bspline         B-spline interpolation" << std::endl;
 #endif
   std::cout << "  --preinterpolate  Preinterpolation factor (default = 1)\n";
   std::cout << "                    Used only with frequency-based filtering\n";
   std::cout << "  --filter       Filter name" << std::endl;
-  std::cout << "    abs_bandlimit Abs * Bandlimiting (default)" << std::endl;
-  std::cout << "    abs_sinc      Abs * Sinc" << std::endl;
-  std::cout << "    abs_cosine    Abs * Cosine" << std::endl;
-  std::cout << "    abs_hamming   Abs * Hamming" << std::endl;
-  std::cout << "    shepp         Shepp-Logan" << std::endl;
-  std::cout << "    bandlimit     Bandlimiting" << std::endl;
-  std::cout << "    sinc          Sinc" << std::endl;
-  std::cout << "    cosine        Cosine" << std::endl;
-  std::cout << "    triangle      Triangle" << std::endl;
-  std::cout << "    hamming       Hamming" << std::endl;
+  std::cout << "    abs_bandlimit  Abs * Bandlimiting (default)" << std::endl;
+  std::cout << "    abs_sinc       Abs * Sinc" << std::endl;
+  std::cout << "    abs_cosine     Abs * Cosine" << std::endl;
+  std::cout << "    abs_hamming    Abs * Hamming" << std::endl;
+  std::cout << "    abs_hanning    Abs * Hanning" << std::endl;
+  std::cout << "    shepp          Shepp-Logan" << std::endl;
+  std::cout << "    bandlimit      Bandlimiting" << std::endl;
+  std::cout << "    sinc           Sinc" << std::endl;
+  std::cout << "    cosine         Cosine" << std::endl;
+  std::cout << "    triangle       Triangle" << std::endl;
+  std::cout << "    hamming        Hamming" << std::endl;
+  std::cout << "    hanning        Hanning" << std::endl;
   std::cout << "  --filter-method  Filter method before backprojections\n";;
   std::cout << "    convolution      Spatial filtering (default)\n";
   std::cout << "    fourier          Frequency filtering with discete fourier\n";
@@ -97,17 +100,11 @@ pjrec_usage (const char *program)
   std::cout << "    trig        Trigometric functions at every point" << std::endl;
   std::cout << "    table       Trigometric functions with precalculated table" << std::endl;
   std::cout << "    diff        Difference method" << std::endl;
-  std::cout << "    diff2       Optimized difference method (default)" << std::endl;
-  std::cout << "    idiff2      Optimized difference method with integer math" << std::endl;
-  std::cout << "    idiff3      Highly-optimized difference method with integer math" << std::endl;
+  std::cout << "    idiff       Difference method with integer math [default]" << std::endl;
   std::cout << "  --filter-param Alpha level for Hamming filter" << std::endl;
   std::cout << "  --trace        Set tracing to level" << std::endl;
   std::cout << "     none        No tracing (default)" << std::endl;
   std::cout << "     console     Text level tracing" << std::endl;
-  std::cout << "     phantom     Trace phantom" << std::endl;
-  std::cout << "     proj        Trace allrays" << std::endl;
-  std::cout << "     plot        Trace plotting" << std::endl;
-  std::cout << "     clipping    Trace clipping" << std::endl;
   std::cout << "  --verbose      Turn on verbose mode" << std::endl;
   std::cout << "  --debug        Turn on debug mode" << std::endl;
   std::cout << "  --version      Print version" << std::endl;
@@ -121,8 +118,8 @@ static void ReduceImageMPI (MPIWorld& mpiWorld, ImageFile* imLocal, ImageFile* i
 #endif
 
 
-int 
-pjrec_main (int argc, char * argv[])
+int
+pjrec_main (int argc, char * const argv[])
 {
   Projections projGlobal;
   ImageFile* imGlobal = NULL;
@@ -138,7 +135,7 @@ pjrec_main (int argc, char * argv[])
   std::string sOptFilterMethodName (ProcessSignal::convertFilterMethodIDToName (ProcessSignal::FILTER_METHOD_CONVOLUTION));
   std::string sOptFilterGenerationName (ProcessSignal::convertFilterGenerationIDToName (ProcessSignal::FILTER_GENERATION_DIRECT));
   std::string sOptInterpName (Backprojector::convertInterpIDToName (Backprojector::INTERP_LINEAR));
-  std::string sOptBackprojectName (Backprojector::convertBackprojectIDToName (Backprojector::BPROJ_IDIFF3));
+  std::string sOptBackprojectName (Backprojector::convertBackprojectIDToName (Backprojector::BPROJ_IDIFF));
   int iOptPreinterpolationFactor = 1;
   int nx, ny;
   char *endptr;
@@ -157,99 +154,99 @@ pjrec_main (int argc, char * argv[])
     while (1) {
       int c = getopt_long(argc, argv, "", my_options, NULL);
       char *endptr = NULL;
-      
+
       if (c == -1)
-       break;
-      
+        break;
+
       switch (c)
-       {
-       case O_INTERP:
-         sOptInterpName = optarg;
-         break;
-       case O_PREINTERPOLATION_FACTOR:
-         iOptPreinterpolationFactor = strtol(optarg, &endptr, 10);
-         if (endptr != optarg + strlen(optarg)) {
-           pjrec_usage(argv[0]);
-           return(1);
-         }
-         break;
-       case O_FILTER:
-         sOptFilterName = optarg;
-         break;
+        {
+        case O_INTERP:
+          sOptInterpName = optarg;
+          break;
+        case O_PREINTERPOLATION_FACTOR:
+          iOptPreinterpolationFactor = strtol(optarg, &endptr, 10);
+          if (endptr != optarg + strlen(optarg)) {
+            pjrec_usage(argv[0]);
+            return(1);
+          }
+          break;
+        case O_FILTER:
+          sOptFilterName = optarg;
+          break;
         case O_FILTER_METHOD:
-         sOptFilterMethodName = optarg;
+          sOptFilterMethodName = optarg;
+          break;
+        case O_FILTER_GENERATION:
+          sOptFilterGenerationName = optarg;
+          break;
+        case O_FILTER_PARAM:
+          dOptFilterParam = strtod(optarg, &endptr);
+          if (endptr != optarg + strlen(optarg)) {
+            pjrec_usage(argv[0]);
+            return(1);
+          }
+          break;
+        case O_ZEROPAD:
+          iOptZeropad = strtol(optarg, &endptr, 10);
+          if (endptr != optarg + strlen(optarg)) {
+            pjrec_usage(argv[0]);
+            return(1);
+          }
+          break;
+        case O_BACKPROJ:
+          sOptBackprojectName = optarg;
+          break;
+        case O_VERBOSE:
+          bOptVerbose = true;
+          break;
+        case O_DEBUG:
+          bOptDebug = true;
+          break;
+        case O_TRACE:
+          if ((optTrace = Trace::convertTraceNameToID(optarg)) == Trace::TRACE_INVALID) {
+            pjrec_usage(argv[0]);
+            return (1);
+          }
           break;
-       case O_FILTER_GENERATION:
-         sOptFilterGenerationName = optarg;
-         break;
-       case O_FILTER_PARAM:
-         dOptFilterParam = strtod(optarg, &endptr);
-         if (endptr != optarg + strlen(optarg)) {
-           pjrec_usage(argv[0]);
-           return(1);
-         }
-         break;
-       case O_ZEROPAD:
-         iOptZeropad = strtol(optarg, &endptr, 10);
-         if (endptr != optarg + strlen(optarg)) {
-           pjrec_usage(argv[0]);
-           return(1);
-         }
-         break;
-       case O_BACKPROJ:
-         sOptBackprojectName = optarg;
-         break;
-       case O_VERBOSE:
-         bOptVerbose = true;
-         break;
-       case O_DEBUG:
-         bOptDebug = true;
-         break;
-       case O_TRACE:
-         if ((optTrace = Trace::convertTraceNameToID(optarg)) == Trace::TRACE_INVALID) {
-           pjrec_usage(argv[0]);
-           return (1);
-         }
-         break;
         case O_VERSION:
 #ifdef VERSION
-         std::cout <<  "Version " <<  VERSION << std::endl << g_szIdStr << std::endl;
+          std::cout <<  "Version " <<  VERSION << std::endl << g_szIdStr << std::endl;
 #else
           std::cout << "Unknown version number" << std::endl;
 #endif
-         return (0);
-       case O_HELP:
-       case '?':
-         pjrec_usage(argv[0]);
-         return (0);
-       default:
-         pjrec_usage(argv[0]);
-         return (1);
-       }
+          return (0);
+        case O_HELP:
+        case '?':
+          pjrec_usage(argv[0]);
+          return (0);
+        default:
+          pjrec_usage(argv[0]);
+          return (1);
+        }
     }
-  
+
     if (optind + 4 != argc) {
       pjrec_usage(argv[0]);
       return (1);
     }
 
     pszFilenameProj = argv[optind];
-  
+
     pszFilenameImage = argv[optind + 1];
-  
+
     nx = strtol(argv[optind + 2], &endptr, 10);
     ny = strtol(argv[optind + 3], &endptr, 10);
-  
+
     std::ostringstream filterDesc;
     if (dOptFilterParam >= 0)
-      filterDesc << sOptFilterName << ": alpha=" << dOptFilterParam; 
+      filterDesc << sOptFilterName << ": alpha=" << dOptFilterParam;
     else
       filterDesc << sOptFilterName;
 
     std::ostringstream label;
     label << "pjrec: " << nx << "x" << ny << ", " << filterDesc.str() << ", " << sOptInterpName << ", preinterpolationFactor=" << iOptPreinterpolationFactor << ", " << sOptBackprojectName;
     sRemark = label.str();
-  
+
     if (bOptVerbose)
       std::cout << "SRemark: " << sRemark << std::endl;
 #ifdef HAVE_MPI
@@ -311,7 +308,12 @@ pjrec_main (int argc, char * argv[])
 
   imLocal = new ImageFile (nx, ny);
 #else
-  projGlobal.read (pszFilenameProj);
+
+  if (! projGlobal.read (pszFilenameProj)) {
+    fprintf(stderr, "Unable to read projectfile file %s\n", pszFilenameProj);
+    exit(1);
+  }
+
   if (bOptVerbose) {
     std::ostringstream os;
     projGlobal.printScanInfo(os);
@@ -356,7 +358,7 @@ pjrec_main (int argc, char * argv[])
       imGlobal->labelAdd (Array2dFileLabel::L_HISTORY, sRemark.c_str(), dCalcTime);
       imGlobal->fileWrite (pszFilenameImage);
       if (bOptVerbose)
-       std::cout << "Run time: " << dCalcTime << " seconds" << std::endl;
+        std::cout << "Run time: " << dCalcTime << " seconds" << std::endl;
     }
 #ifdef HAVE_MPI
   MPI::Finalize();
@@ -377,14 +379,14 @@ static void ScatterProjectionsMPI (MPIWorld& mpiWorld, Projections& projGlobal,
   if (mpiWorld.getRank() == 0) {
     for (int iProc = 0; iProc < mpiWorld.getNumProcessors(); iProc++) {
       for (int iw = mpiWorld.getStartWorkUnit(iProc); iw <= mpiWorld.getEndWorkUnit(iProc); iw++) {
-       DetectorArray& detarray = projGlobal.getDetectorArray( iw );
-       int nDet = detarray.nDet();
-       DetectorValue* detval = detarray.detValues();
-
-       double viewAngle = detarray.viewAngle();
-       mpiWorld.getComm().Send(&nDet, 1, MPI::INT, iProc, 0);
-       mpiWorld.getComm().Send(&viewAngle, 1, MPI::DOUBLE, iProc, 0);
-       mpiWorld.getComm().Send(detval, nDet, MPI::FLOAT, iProc, 0);
+        DetectorArray& detarray = projGlobal.getDetectorArray( iw );
+        int nDet = detarray.nDet();
+        DetectorValue* detval = detarray.detValues();
+
+        double viewAngle = detarray.viewAngle();
+        mpiWorld.getComm().Send(&nDet, 1, MPI::INT, iProc, 0);
+        mpiWorld.getComm().Send(&viewAngle, 1, MPI::DOUBLE, iProc, 0);
+        mpiWorld.getComm().Send(detval, nDet, MPI::FLOAT, iProc, 0);
       }
     }
   }
@@ -421,7 +423,7 @@ ReduceImageMPI (MPIWorld& mpiWorld, ImageFile* imLocal, ImageFile* imGlobal)
 
 
 #ifndef NO_MAIN
-int 
+int
 main (int argc, char* argv[])
 {
   int retval = 1;
@@ -429,9 +431,9 @@ main (int argc, char* argv[])
   try {
     retval = pjrec_main(argc, argv);
   } catch (exception e) {
-         std::cerr << "Exception: " << e.what() << std::endl;
+          std::cerr << "Exception: " << e.what() << std::endl;
   } catch (...) {
-         std::cerr << "Unknown exception" << std::endl;
+          std::cerr << "Unknown exception" << std::endl;
   }
 
   return (retval);