X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=libctsim%2Fbackprojectors.cpp;h=d3cb2035dc125af3415006a2d204cc61b5cc7907;hb=6850134e4711a842cc7c0a306a9e4243df06b952;hp=0684c16c5c638e95e01eec79a8d5988968b5ed04;hpb=dfa390de2efc04d85b03718a6480f735516df0e8;p=ctsim.git diff --git a/libctsim/backprojectors.cpp b/libctsim/backprojectors.cpp index 0684c16..d3cb203 100644 --- a/libctsim/backprojectors.cpp +++ b/libctsim/backprojectors.cpp @@ -8,7 +8,7 @@ ** 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 @@ -152,6 +152,8 @@ Backprojector::convertInterpolationNameToID (const char* const interpName) 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; @@ -180,6 +182,8 @@ Backprojector::convertInterpolationIDToName (const InterpolationID interpID) 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); @@ -471,12 +475,12 @@ BackprojectIntDiff2::BackprojectView (const double* const filteredProj, const do { 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 (xInc * sin (theta) / detInc * scale); - kint32 det_dy = nearest (yInc * cos (theta) / detInc * scale); + const kint32 det_dx = nearest (xInc * sin (theta) / detInc * scale); + const kint32 det_dy = nearest (yInc * cos (theta) / detInc * scale); // calculate L for first point in image (0, 0) kint32 detPosColStart = nearest (start_r * cos (theta - start_phi) / detInc * scale); @@ -524,8 +528,10 @@ BackprojectIntDiff3::BackprojectView (const double* const filteredProj, const do 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 (xInc * sin (theta) / detInc * scale); const kint32 det_dy = nearest (yInc * cos (theta) / detInc * scale); @@ -537,28 +543,26 @@ BackprojectIntDiff3::BackprojectView (const double* const filteredProj, const do 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 }