** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: backprojectors.cpp,v 1.5 2000/07/07 15:30:59 kevin Exp $
+** $Id: backprojectors.cpp,v 1.6 2000/07/09 08:16:17 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
interpID = INTERP_NEAREST;
else if (strcasecmp (interpName, INTERP_LINEAR_STR) == 0)
interpID = INTERP_LINEAR;
+ else if (strcasecmp (interpName, INTERP_FREQ_PREINTERPOLATE_STR) == 0)
+ interpID = INTERP_FREQ_PREINTERPOLATE;
#if HAVE_BSPLINE_INTERP
else if (strcasecmp (interpName, INTERP_BSPLINE_STR) == 0)
interpID = INTERP_BSPLINE;
return (INTERP_NEAREST_STR);
else if (interpID == INTERP_LINEAR)
return (INTERP_LINEAR_STR);
+ else if (interpID == INTERP_FREQ_PREINTERPOLATE)
+ return (INTERP_FREQ_PREINTERPOLATE_STR);
#if HAVE_BSPLINE_INTERP
else if (interpID == INTERP_BSPLINE)
return (INTERP_BSPLINE_STR);
{
double theta = - view_angle; // add half PI to view angle to get perpendicular theta angle
- kint32 scale = 1 << 16;
- double dScale = scale;
- kint32 halfScale = scale / 2;
+ static const kint32 scale = 1 << 16;
+ static const double dScale = scale;
+ static const kint32 halfScale = scale / 2;
- kint32 det_dx = nearest<kint32> (xInc * sin (theta) / detInc * scale);
- kint32 det_dy = nearest<kint32> (yInc * cos (theta) / detInc * scale);
+ const kint32 det_dx = nearest<kint32> (xInc * sin (theta) / detInc * scale);
+ const kint32 det_dy = nearest<kint32> (yInc * cos (theta) / detInc * scale);
// calculate L for first point in image (0, 0)
kint32 detPosColStart = nearest<kint32> (start_r * cos (theta - start_phi) / detInc * scale);
double theta = - view_angle; // add half PI to view angle to get perpendicular theta angle
static const int scaleShift = 16;
static const kint32 scale = (1 << scaleShift);
+ static const kint32 scaleBitmask = scale - 1;
static const double dScale = scale;
static const kint32 halfScale = scale / 2;
+ static const double dInvScale = 1. / scale;
const kint32 det_dx = nearest<kint32> (xInc * sin (theta) / detInc * scale);
const kint32 det_dy = nearest<kint32> (yInc * cos (theta) / detInc * scale);
kint32 curDetPos = detPosColStart;
ImageFileColumn pImCol = v[ix];
- for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
- if (interpType == Backprojector::INTERP_NEAREST) {
- int iDetPos = (curDetPos + halfScale) >> scaleShift;
-
- if (iDetPos < 0 || iDetPos >= nDet) // check for impossible: index outside of raysum pos
- errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
- else
- *pImCol++ += filteredProj[iDetPos];
- } else if (interpType == Backprojector::INTERP_LINEAR) {
- kint32 detPosFloor = curDetPos / scale;
- kint32 detPosRemainder = curDetPos % scale;
- if (detPosRemainder < 0) {
- detPosFloor--;
- detPosRemainder += scale;
- }
- int iDetPos = iDetCenter + detPosFloor;
- double frac = detPosRemainder / dScale;
- if (iDetPos < 0 || iDetPos >= nDet - 1)
- errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
- else
- *pImCol++ += ((1.-frac) * filteredProj[iDetPos] + frac * filteredProj[iDetPos+1]);
- }
- } // end for y
- } // end for x
+ if (interpType == Backprojector::INTERP_NEAREST) {
+ for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
+ int iDetPos = (curDetPos + halfScale) >> 16;
+ assert(iDetPos >= 0 && iDetPos < nDet);
+ *pImCol++ += filteredProj[iDetPos];
+ } // end for iy
+ } else if (interpType == Backprojector::INTERP_LINEAR) {
+ for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
+ kint32 iDetPos = curDetPos >> scaleShift;
+ kint32 detRemainder = curDetPos & scaleBitmask;
+#if 0
+ double frac = detRemainder * (1. / 65536.);
+ assert(iDetPos >= 0 && iDetPos < nDet - 1);
+ *pImCol++ += ((1.-frac) * filteredProj[iDetPos]) + (frac * filteredProj[iDetPos+1]);
+#else
+ assert(iDetPos >= 0 && iDetPos < nDet - 1);
+ const double* const detPointer = &filteredProj[iDetPos];
+ *pImCol++ += (((scale-detRemainder) * *detPointer) + (detRemainder * *(detPointer+1))) * dInvScale;
+#endif
+ } // end for iy
+ } //end linear
+ } // end for ix
}