r7928: support 64-bit long ints
[ctsim.git] / libctsim / backprojectors.cpp
index 7551ff9a1d1e99a1e65336b4e726af20c9f26a12..b7d320d49aab76f31668b96e3efbfd178f00289a 100644 (file)
@@ -8,7 +8,7 @@
 **  This is part of the CTSim program
 **  Copyright (c) 1983-2001 Kevin Rosenberg
 **
-**  $Id: backprojectors.cpp,v 1.33 2003/03/23 18:37:42 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
@@ -35,18 +35,18 @@ const int Backprojector::BPROJ_IDIFF = 3;
 
 const char* const Backprojector::s_aszBackprojectName[] = 
 {
-  {"trig"},
-  {"table"},
-  {"diff"},
-  {"idiff"},
+  "trig",
+  "table",
+  "diff",
+  "idiff",
 };
 
 const char* const Backprojector::s_aszBackprojectTitle[] = 
 {
-  {"Direct Trigometric"},
-  {"Trigometric Table"},
-  {"Difference Iteration"},
-  {"Integer Difference Iteration"},
+  "Direct Trigometric",
+  "Trigometric Table",
+  "Difference Iteration",
+  "Integer Difference Iteration",
 };
 
 const int Backprojector::s_iBackprojectCount = sizeof(s_aszBackprojectName) / sizeof(const char*);
@@ -65,33 +65,33 @@ const int Backprojector::INTERP_3BSPLINE = 7;
 
 const char* const Backprojector::s_aszInterpName[] = 
 {
-  {"nearest"},
-  {"linear"},
-  {"cubic"},
+  "nearest",
+  "linear",
+  "cubic",
 #if HAVE_FREQ_PREINTERP
-  {"freq_preinterpolationj"},
+  "freq_preinterpolationj",
 #endif
 #if HAVE_BSPLINE_INTERP
-  {"bspline"},
-  {"1bspline"},
-  {"2bspline"},
-  {"3bspline"},
+  "bspline",
+  "1bspline",
+  "2bspline",
+  "3bspline",
 #endif
 };
 
 const char* const Backprojector::s_aszInterpTitle[] = 
 {
-  {"Nearest"},
-  {"Linear"},
-  {"Cubic"},
+  "Nearest",
+  "Linear",
+  "Cubic",
 #if HAVE_FREQ_PREINTERP
-  {"Frequency Preinterpolation"},
+  "Frequency Preinterpolation",
 #endif
 #if HAVE_BSPLINE_INTERP
-  {"B-Spline"},
-  {"B-Spline 1st Order"},
-  {"B-Spline 2nd Order"},
-  {"B-Spline 3rd Order"},
+  "B-Spline",
+  "B-Spline 1st Order",
+  "B-Spline 2nd Order",
+  "B-Spline 3rd Order",
 #endif
 };
 
@@ -572,17 +572,21 @@ void
 BackprojectIntDiff::BackprojectView (const double* const filteredProj, const double view_angle)
 {
   double theta = view_angle;  // add half PI to view angle to get perpendicular theta angle
+#if SIZEOF_LONG == 4
   static const int scaleShift = 16;
-  static const kint32 scale = (1 << scaleShift);
-  static const kint32 scaleBitmask = scale - 1;
-  static const kint32 halfScale = scale / 2;
+#elif SIZEOF_LONG == 8
+  static const int scaleShift = 32;
+#endif
+  static const long scale = (1 << scaleShift);
+  static const long scaleBitmask = scale - 1;
+  static const long halfScale = scale / 2;
   static const double dInvScale = 1. / scale;
   
-  const kint32 det_dx = nearest<kint32> (xInc * cos (theta) / detInc * scale);
-  const kint32 det_dy = nearest<kint32> (yInc * sin (theta) / detInc * scale);
+  const long det_dx = nearest<long> (xInc * cos (theta) / detInc * scale);
+  const long det_dy = nearest<long> (yInc * sin (theta) / detInc * scale);
   
   // calculate L for first point in image (0, 0) 
-  kint32 detPosColStart = nearest<kint32> ((start_r * cos (theta - start_phi) / detInc + iDetCenter) * scale);
+  long detPosColStart = nearest<long> ((start_r * cos (theta - start_phi) / detInc + iDetCenter) * scale);
   
   double* deltaFilteredProj = NULL;  
   CubicPolyInterpolator* pCubicInterp = NULL;
@@ -603,26 +607,26 @@ BackprojectIntDiff::BackprojectView (const double* const filteredProj, const dou
     
     if (interpType == Backprojector::INTERP_NEAREST) {
       for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
-        const int iDetPos = (curDetPos + halfScale) >> 16;
+        const int iDetPos = (curDetPos + halfScale) >> scaleShift;
         if (iDetPos >= 0 && iDetPos <= iLastDet)
           *pImCol++ += filteredProj[iDetPos];
       }        // end for iy
     } else if (interpType == Backprojector::INTERP_FREQ_PREINTERPOLATION) {
       for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
-        const int iDetPos = ((curDetPos + halfScale) >> 16) * m_interpFactor;
+        const int iDetPos = ((curDetPos + halfScale) >> scaleShift) * m_interpFactor;
         if (iDetPos >= 0 && iDetPos <= iLastDet)
           *pImCol++ += filteredProj[iDetPos];
       }        // end for iy
     } else if (interpType == Backprojector::INTERP_LINEAR) {
       for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
-        const kint32 iDetPos = curDetPos >> scaleShift;
-        const kint32 detRemainder = curDetPos & scaleBitmask;
+        const long iDetPos = curDetPos >> scaleShift;
+        const long detRemainder = curDetPos & scaleBitmask;
         if (iDetPos >= 0 && iDetPos <= iLastDet)
           *pImCol++ += filteredProj[iDetPos] + (detRemainder * deltaFilteredProj[iDetPos]);
       }        // end for iy
     } else if (interpType == Backprojector::INTERP_CUBIC) {
       for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
-        *pImCol++ += pCubicInterp->interpolate (static_cast<double>(curDetPos) / 65536);
+        *pImCol++ += pCubicInterp->interpolate (static_cast<double>(curDetPos) / scale);
       }
     } // end Cubic
   } // end for ix