r158: *** empty log message ***
[ctsim.git] / libctsim / backprojectors.cpp
index ae31cf866967d5f5b1ebab1910e722100e5eb8c9..4983256ffd0e57846690d9bf7bb5ef9c8a1f544a 100644 (file)
@@ -8,7 +8,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: backprojectors.cpp,v 1.9 2000/07/20 11:17:31 kevin Exp $
+**  $Id: backprojectors.cpp,v 1.10 2000/07/22 15:45:33 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
 
 #include "ct.h"
 
-const char Backprojector::BPROJ_TRIG_STR[]=     "trig";
-const char Backprojector::BPROJ_TABLE_STR[]=    "table";
-const char Backprojector::BPROJ_DIFF_STR[]=     "diff";
-const char Backprojector::BPROJ_DIFF2_STR[]=    "diff2";
-const char Backprojector::BPROJ_IDIFF2_STR[]=   "idiff2";
-const char Backprojector::BPROJ_IDIFF3_STR[]=   "idiff3";
-
-const char Backprojector::BPROJ_TRIG_TITLE_STR[]=     "Direc Trigometric";
-const char Backprojector::BPROJ_TABLE_TITLE_STR[]=    "Trig Table";
-const char Backprojector::BPROJ_DIFF_TITLE_STR[]=     "Diff";
-const char Backprojector::BPROJ_DIFF2_TITLE_STR[]=    "Diff2";
-const char Backprojector::BPROJ_IDIFF2_TITLE_STR[]=   "Integer Diff2";
-const char Backprojector::BPROJ_IDIFF3_TITLE_STR[]=   "Integer Diff3";
-const char Backprojector::INTERP_NEAREST_STR[]=  "nearest";
-const char Backprojector::INTERP_LINEAR_STR[]=   "linear";
-const char Backprojector::INTERP_BSPLINE_STR[]=  "bspline";
-const char Backprojector::INTERP_FREQ_PREINTERPOLATION_STR[]= "freq_preinterpolation";
-
-const char Backprojector::INTERP_NEAREST_TITLE_STR[]=  "Nearest";
-const char Backprojector::INTERP_LINEAR_TITLE_STR[]=   "Linear";
-const char Backprojector::INTERP_BSPLINE_TITLE_STR[]=  "B-Spline";
-const char Backprojector::INTERP_FREQ_PREINTERPOLATION_TITLE_STR[]= "Frequency Preinterpolation";
+const int Backprojector::BPROJ_INVALID = -1;
+const int Backprojector::BPROJ_TRIG = 0;
+const int Backprojector::BPROJ_TABLE = 1;
+const int Backprojector::BPROJ_DIFF = 2;
+const int Backprojector::BPROJ_DIFF2 = 3;
+const int Backprojector::BPROJ_IDIFF2 = 4;
+const int Backprojector::BPROJ_IDIFF3 = 5;
+
+const char* Backprojector::s_aszBackprojectName[] = 
+{
+  {"trig"},
+  {"table"},
+  {"diff"},
+  {"diff2"},
+  {"idiff2"},
+  {"idiff3"},
+};
+
+const char* Backprojector::s_aszBackprojectTitle[] = 
+{
+  {"Direct Trigometric"},
+  {"Trigometric Table"},
+  {"Difference Iteration"},
+  {"Difference Iteration Optimized"},
+  {"Integer Difference Iteration Optimized"},
+  {"Integer Difference Iteration Highly-Optimized"},
+};
+
+const int Backprojector::s_iBackprojectCount = sizeof(s_aszBackprojectName) / sizeof(const char*);
+
+const int Backprojector::INTERP_INVALID = -1;
+const int Backprojector::INTERP_NEAREST = 0;
+const int Backprojector::INTERP_LINEAR = 1;
+const int Backprojector::INTERP_FREQ_PREINTERPOLATION = 2;
+#if HAVE_BSPLINE_INTERP
+const int Backprojector::INTERP_BSPLINE = 3;
+const int Backprojector::INTERP_1BSPLINE = 4;
+const int Backprojector::INTERP_2BSPLINE = 5;
+const int Backprojector::INTERP_3BSPLINE = 6;
+#endif
+
+const char* Backprojector::s_aszInterpName[] = 
+{
+  {"nearest"},
+  {"linear"},
+  {"freq_preinterpolationj"},
+#if HAVE_BSPLINE_INTERP
+  {"bspline"},
+  {"1bspline"},
+  {"2bspline"},
+  {"3bspline"},
+#endif
+};
+
+const char* Backprojector::s_aszInterpTitle[] = 
+{
+  {"Nearest"},
+  {"Linear"},
+  {"Frequency Preinterpolationj"},
+#if HAVE_BSPLINE_INTERP
+  {"B-Spline"},
+  {"B-Spline 1st Order"},
+  {"B-Spline 2nd Order"},
+  {"B-Spline 3rd Order"},
+#endif
+};
+
+const int Backprojector::s_iInterpCount = sizeof(s_aszInterpName) / sizeof(const char*);
+
 
 
 Backprojector::Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor)
@@ -66,7 +112,7 @@ Backprojector::BackprojectView (const double* const viewData, const double viewA
     m_pBackprojectImplem->BackprojectView (viewData, viewAngle);
 }
 
-Backprojector::~Backprojector (void)
+Backprojector::~Backprojector ()
 {
   delete m_pBackprojectImplem;
 }
@@ -90,7 +136,7 @@ Backprojector::initBackprojector (const Projections& proj, ImageFile& im, const
     m_failMessage = "Invalid backprojection name ";
     m_failMessage += backprojName;
   }
-  m_idInterpolation = convertInterpolationNameToID (interpName);
+  m_idInterpolation = convertInterpNameToID (interpName);
   if (m_idInterpolation == INTERP_INVALID) {
     m_fail = true;
     m_failMessage = "Invalid interpolation name ";
@@ -124,107 +170,88 @@ Backprojector::initBackprojector (const Projections& proj, ImageFile& im, const
 }
 
 
-const Backprojector::BackprojectID
+int
 Backprojector::convertBackprojectNameToID (const char* const backprojName)
 {
-  BackprojectID backprojID = BPROJ_INVALID;
-
-  if (strcasecmp (backprojName, BPROJ_TRIG_STR) == 0)
-    backprojID = BPROJ_TRIG;
-  else if (strcasecmp (backprojName, BPROJ_TABLE_STR) == 0)
-    backprojID = BPROJ_TABLE;
-  else if (strcasecmp (backprojName, BPROJ_DIFF_STR) == 0)
-    backprojID = BPROJ_DIFF;
-  else if (strcasecmp (backprojName, BPROJ_DIFF2_STR) == 0)
-    backprojID = BPROJ_DIFF2;
-  else if (strcasecmp (backprojName, BPROJ_IDIFF2_STR) == 0)
-    backprojID = BPROJ_IDIFF2;
-  else if (strcasecmp (backprojName, BPROJ_IDIFF3_STR) == 0)
-    backprojID = BPROJ_IDIFF3;
+  int backprojID = BPROJ_INVALID;
+
+  for (int i = 0; i < s_iBackprojectCount; i++)
+      if (strcasecmp (backprojName, s_aszBackprojectName[i]) == 0) {
+         backprojID = i;
+         break;
+      }
 
   return (backprojID);
 }
 
 const char*
-Backprojector::convertBackprojectIDToName (const BackprojectID bprojID)
+Backprojector::convertBackprojectIDToName (int bprojID)
 {
-  const char *bprojName = "";
-
-  if (bprojID == BPROJ_TRIG)
-    bprojName = BPROJ_TRIG_STR;
-  else if (bprojID == BPROJ_TABLE)
-    bprojName = BPROJ_TABLE_STR;
-  else if (bprojID == BPROJ_DIFF)
-    bprojName = BPROJ_DIFF_STR;
-  else if (bprojID == BPROJ_DIFF2)
-    bprojName = BPROJ_DIFF2_STR;
-  else if (bprojID == BPROJ_IDIFF2)
-    bprojName = BPROJ_IDIFF2_STR;
-  else if (bprojID == BPROJ_IDIFF3)
-    bprojName = BPROJ_IDIFF3_STR;
+  static const char *bprojName = "";
+
+  if (bprojID >= 0 && bprojID < s_iBackprojectCount)
+      return (s_aszBackprojectName[bprojID]);
 
   return (bprojName);
 }
 
+const char*
+Backprojector::convertBackprojectIDToTitle (const int bprojID)
+{
+  static const char *bprojTitle = "";
+
+  if (bprojID >= 0 && bprojID < s_iBackprojectCount)
+      return (s_aszBackprojectTitle[bprojID]);
+
+  return (bprojTitle);
+}
 
 
-const Backprojector::InterpolationID
-Backprojector::convertInterpolationNameToID (const char* const interpName)
+int
+Backprojector::convertInterpNameToID (const char* const interpName)
 {
-  InterpolationID interpID = INTERP_INVALID;
-
-  if (strcasecmp (interpName, INTERP_NEAREST_STR) == 0)
-    interpID = INTERP_NEAREST;
-  else if (strcasecmp (interpName, INTERP_LINEAR_STR) == 0)
-    interpID = INTERP_LINEAR;
-  else if (strcasecmp (interpName, INTERP_FREQ_PREINTERPOLATION_STR) == 0)
-    interpID = INTERP_FREQ_PREINTERPOLATION;
-#if HAVE_BSPLINE_INTERP
-  else if (strcasecmp (interpName, INTERP_BSPLINE_STR) == 0)
-    interpID = INTERP_BSPLINE;
-#endif
+  int interpID = INTERP_INVALID;
+
+  for (int i = 0; i < s_iInterpCount; i++)
+      if (strcasecmp (interpName, s_aszInterpName[i]) == 0) {
+         interpID = i;
+         break;
+      }
 
   return (interpID);
 }
 
+const char*
+Backprojector::convertInterpIDToName (const int interpID)
+{
+  static const char *interpName = "";
 
-/* NAME
- *     name_of_interp                  Return name of interpolation method
- *
- * SYNOPSIS
- *     name = name_of_interp (interp_type)
- *     char *name                      Name of interpolation method
- *     int interp_type                 Method of interpolation
- *
- * NOTES
- *     Returns NULL if interp_type is invalid
- */
+  if (interpID >= 0 && interpID < s_iInterpCount)
+      return (s_aszInterpName[interpID]);
+
+  return (interpName);
+}
 
 const char*
-Backprojector::convertInterpolationIDToName (const InterpolationID interpID)
+Backprojector::convertInterpIDToTitle (const int interpID)
 {
-  if (interpID == INTERP_NEAREST)
-    return (INTERP_NEAREST_STR);
-  else if (interpID == INTERP_LINEAR)
-    return (INTERP_LINEAR_STR);
-  else if (interpID == INTERP_FREQ_PREINTERPOLATION)
-    return (INTERP_FREQ_PREINTERPOLATION_STR);
-#if HAVE_BSPLINE_INTERP
-  else if (interpID == INTERP_BSPLINE)
-    return (INTERP_BSPLINE_STR);
-#endif
-  else
-    return ("");
+  static const char *interpTitle = "";
+
+  if (interpID >= 0 && interpID < s_iInterpCount)
+      return (s_aszInterpTitle[interpID]);
+
+  return (interpTitle);
 }
 
 
+
 // CLASS IDENTICATION
 //   Backproject
 //
 // PURPOSE
 //   Pure virtual base class for all backprojectors.
 
-Backproject::Backproject (const Projections& proj, ImageFile& im, const Backprojector::InterpolationID interpType, const int interpFactor)
+Backproject::Backproject (const Projections& proj, ImageFile& im, const int interpType, const int interpFactor)
     : proj(proj), im(im), interpType(interpType), m_interpFactor(interpFactor)
 {
   detInc = proj.detInc();
@@ -246,11 +273,11 @@ Backproject::Backproject (const Projections& proj, ImageFile& im, const Backproj
   yInc = (yMax - yMin) / ny;
 }
 
-Backproject::~Backproject (void)
+Backproject::~Backproject ()
 {}
 
 void
-Backproject::ScaleImageByRotIncrement (void)
+Backproject::ScaleImageByRotIncrement ()
 {
   for (int ix = 0; ix < nx; ix++)
     for (int iy = 0; iy < ny; iy++)
@@ -320,7 +347,7 @@ BackprojectTrig::BackprojectView (const double* const filteredProj, const double
 // PURPOSE
 //   Precalculates trigometric function value for each point in image for backprojection.
 
-BackprojectTable::BackprojectTable (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor)
+BackprojectTable::BackprojectTable (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
   : Backproject::Backproject (proj, im, interpType, interpFactor)
 {
   arrayR.initSetSize (nx, ny);
@@ -337,7 +364,7 @@ BackprojectTable::BackprojectTable (const Projections& proj, ImageFile& im, Back
     }
 }
 
-BackprojectTable::~BackprojectTable (void)
+BackprojectTable::~BackprojectTable ()
 {
   ScaleImageByRotIncrement();
 }
@@ -382,7 +409,7 @@ BackprojectTable::BackprojectView (const double* const filteredProj, const doubl
 //   Backprojects by precalculating the change in L position for each x & y step in the image.
 //   Iterates in x & y direction by adding difference in L position
 
-BackprojectDiff::BackprojectDiff (const Projections& proj, ImageFile& im, Backprojector::InterpolationID interpType, const int interpFactor)
+BackprojectDiff::BackprojectDiff (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
   :  Backproject::Backproject (proj, im, interpType, interpFactor)
 {
   // calculate center of first pixel v[0][0]