1 /*****************************************************************************
4 ** Name: backprojectors.cpp Classes for backprojection
5 ** Programmer: Kevin Rosenberg
6 ** Date Started: June 2000
8 ** This is part of the CTSim program
9 ** Copyright (C) 1983-2000 Kevin Rosenberg
11 ** $Id: backprojectors.cpp,v 1.18 2000/12/06 15:17:51 kevin Exp $
13 ** This program is free software; you can redistribute it and/or modify
14 ** it under the terms of the GNU General Public License (version 2) as
15 ** published by the Free Software Foundation.
17 ** This program is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
22 ** You should have received a copy of the GNU General Public License
23 ** along with this program; if not, write to the Free Software
24 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 ******************************************************************************/
29 const int Backprojector::BPROJ_INVALID = -1;
30 const int Backprojector::BPROJ_TRIG = 0;
31 const int Backprojector::BPROJ_TABLE = 1;
32 const int Backprojector::BPROJ_DIFF = 2;
33 const int Backprojector::BPROJ_DIFF2 = 3;
34 const int Backprojector::BPROJ_IDIFF2 = 4;
35 const int Backprojector::BPROJ_IDIFF3 = 5;
37 const char* Backprojector::s_aszBackprojectName[] =
47 const char* Backprojector::s_aszBackprojectTitle[] =
49 {"Direct Trigometric"},
50 {"Trigometric Table"},
51 {"Difference Iteration"},
52 {"Difference Iteration Optimized"},
53 {"Integer Difference Iteration Optimized"},
54 {"Integer Difference Iteration Highly-Optimized"},
57 const int Backprojector::s_iBackprojectCount = sizeof(s_aszBackprojectName) / sizeof(const char*);
59 const int Backprojector::INTERP_INVALID = -1;
60 const int Backprojector::INTERP_NEAREST = 0;
61 const int Backprojector::INTERP_LINEAR = 1;
62 const int Backprojector::INTERP_FREQ_PREINTERPOLATION = 2;
63 #if HAVE_BSPLINE_INTERP
64 const int Backprojector::INTERP_BSPLINE = 3;
65 const int Backprojector::INTERP_1BSPLINE = 4;
66 const int Backprojector::INTERP_2BSPLINE = 5;
67 const int Backprojector::INTERP_3BSPLINE = 6;
70 const char* Backprojector::s_aszInterpName[] =
74 {"freq_preinterpolationj"},
75 #if HAVE_BSPLINE_INTERP
83 const char* Backprojector::s_aszInterpTitle[] =
87 {"Frequency Preinterpolationj"},
88 #if HAVE_BSPLINE_INTERP
90 {"B-Spline 1st Order"},
91 {"B-Spline 2nd Order"},
92 {"B-Spline 3rd Order"},
96 const int Backprojector::s_iInterpCount = sizeof(s_aszInterpName) / sizeof(const char*);
100 Backprojector::Backprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor)
103 m_pBackprojectImplem = NULL;
105 initBackprojector (proj, im, backprojName, interpName, interpFactor);
109 Backprojector::BackprojectView (const double* const viewData, const double viewAngle)
111 if (m_pBackprojectImplem != NULL)
112 m_pBackprojectImplem->BackprojectView (viewData, viewAngle);
115 Backprojector::~Backprojector ()
117 delete m_pBackprojectImplem;
120 // FUNCTION IDENTIFICATION
121 // Backproject* projector = selectBackprojector (...)
124 // Selects a backprojector based on BackprojType
125 // and initializes the backprojector
128 Backprojector::initBackprojector (const Projections& proj, ImageFile& im, const char* const backprojName, const char* const interpName, const int interpFactor)
130 m_nameBackproject = backprojName;
131 m_nameInterpolation = interpName;
132 m_pBackprojectImplem = NULL;
133 m_idBackproject = convertBackprojectNameToID (backprojName);
134 if (m_idBackproject == BPROJ_INVALID) {
136 m_failMessage = "Invalid backprojection name ";
137 m_failMessage += backprojName;
139 m_idInterpolation = convertInterpNameToID (interpName);
140 if (m_idInterpolation == INTERP_INVALID) {
142 m_failMessage = "Invalid interpolation name ";
143 m_failMessage += interpName;
146 if (m_fail || m_idBackproject == BPROJ_INVALID || m_idInterpolation == INTERP_INVALID) {
151 if (proj.geometry() == Scanner::GEOMETRY_EQUILINEAR)
152 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectEquilinear(proj, im, m_idInterpolation, interpFactor));
153 else if (proj.geometry() == Scanner::GEOMETRY_EQUIANGULAR)
154 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectEquiangular(proj, im, m_idInterpolation, interpFactor));
155 else if (proj.geometry() == Scanner::GEOMETRY_PARALLEL) {
156 if (m_idBackproject == BPROJ_TRIG)
157 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectTrig (proj, im, m_idInterpolation, interpFactor));
158 else if (m_idBackproject == BPROJ_TABLE)
159 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectTable (proj, im, m_idInterpolation, interpFactor));
160 else if (m_idBackproject == BPROJ_DIFF)
161 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectDiff (proj, im, m_idInterpolation, interpFactor));
162 else if (m_idBackproject == BPROJ_DIFF2)
163 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectDiff2 (proj, im, m_idInterpolation, interpFactor));
164 else if (m_idBackproject == BPROJ_IDIFF2)
165 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectIntDiff2 (proj, im, m_idInterpolation, interpFactor));
166 else if (m_idBackproject == BPROJ_IDIFF3)
167 m_pBackprojectImplem = static_cast<Backproject*>(new BackprojectIntDiff3 (proj, im, m_idInterpolation, interpFactor));
170 m_failMessage = "Unable to select a backprojection method [Backprojector::initBackprojector]";
179 Backprojector::convertBackprojectNameToID (const char* const backprojName)
181 int backprojID = BPROJ_INVALID;
183 for (int i = 0; i < s_iBackprojectCount; i++)
184 if (strcasecmp (backprojName, s_aszBackprojectName[i]) == 0) {
193 Backprojector::convertBackprojectIDToName (int bprojID)
195 static const char *bprojName = "";
197 if (bprojID >= 0 && bprojID < s_iBackprojectCount)
198 return (s_aszBackprojectName[bprojID]);
204 Backprojector::convertBackprojectIDToTitle (const int bprojID)
206 static const char *bprojTitle = "";
208 if (bprojID >= 0 && bprojID < s_iBackprojectCount)
209 return (s_aszBackprojectTitle[bprojID]);
216 Backprojector::convertInterpNameToID (const char* const interpName)
218 int interpID = INTERP_INVALID;
220 for (int i = 0; i < s_iInterpCount; i++)
221 if (strcasecmp (interpName, s_aszInterpName[i]) == 0) {
230 Backprojector::convertInterpIDToName (const int interpID)
232 static const char *interpName = "";
234 if (interpID >= 0 && interpID < s_iInterpCount)
235 return (s_aszInterpName[interpID]);
241 Backprojector::convertInterpIDToTitle (const int interpID)
243 static const char *interpTitle = "";
245 if (interpID >= 0 && interpID < s_iInterpCount)
246 return (s_aszInterpTitle[interpID]);
248 return (interpTitle);
253 // CLASS IDENTICATION
257 // Pure virtual base class for all backprojectors.
259 Backproject::Backproject (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
260 : proj(proj), im(im), interpType(interpType), m_interpFactor(interpFactor)
262 detInc = proj.detInc();
264 iDetCenter = (nDet - 1) / 2; // index refering to L=0 projection
265 rotScale = proj.rotInc();
266 rotScale /= (proj.nView() * proj.rotInc() / PI); // scale by number of PI rotations
273 xMin = -proj.phmLen() / 2; // Retangular coords of phantom
274 xMax = xMin + proj.phmLen();
275 yMin = -proj.phmLen() / 2;
276 yMax = yMin + proj.phmLen();
278 xInc = (xMax - xMin) / nx; // size of cells
279 yInc = (yMax - yMin) / ny;
281 m_dFocalLength = proj.focalLength();
284 Backproject::~Backproject ()
288 Backproject::ScaleImageByRotIncrement ()
290 for (int ix = 0; ix < nx; ix++)
291 for (int iy = 0; iy < ny; iy++)
292 v[ix][iy] *= rotScale;
295 void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double r, double phi, double L, int iDetPos)
297 sys_error (ERR_WARNING, "r=%f, phi=%f", r, phi);
298 errorIndexOutsideDetector (ix, iy, theta, L, iDetPos);
301 void Backproject::errorIndexOutsideDetector (int ix, int iy, double theta, double L, int iDetPos)
305 os << "ix=" << ix << ", iy=" << iy << ", theta=" << theta << ", L=" << L << ", detinc=" << detInc << "\n";
306 os << "ndet=" << nDet << ", detInc=" << detInc << ", iDetCenter=" << iDetCenter << "\n";
307 os << "xMin=" << xMin << ", xMax=" << xMax << ", xInc=" << xInc << "\n";
308 os << "yMin=" << yMin << ", yMax=" << yMax << ", yInc=" << yInc << "\n";
309 os << "iDetPos index outside bounds: " << iDetPos << " [backprojector]";;
311 sys_error (ERR_WARNING, os.str().c_str());
\r
316 // CLASS IDENTICATION
320 // Uses trigometric functions at each point in image for backprojection.
323 BackprojectTrig::BackprojectView (const double* const filteredProj, const double view_angle)
325 double theta = view_angle;
327 double x = xMin + xInc / 2; // Rectang coords of center of pixel
328 for (int ix = 0; ix < nx; x += xInc, ix++) {
329 double y = yMin + yInc / 2;
330 for (int iy = 0; iy < ny; y += yInc, iy++) {
331 double r = sqrt (x * x + y * y); // distance of cell from center
332 double phi = atan2 (y, x); // angle of cell from center
333 double L = r * cos (theta - phi); // position on detector
335 if (interpType == Backprojector::INTERP_NEAREST) {
336 int iDetPos = iDetCenter + nearest<int> (L / detInc); // calc'd index in the filter raysum array
338 if (iDetPos < 0 || iDetPos >= nDet) // check for impossible: index outside of raysum pos
339 errorIndexOutsideDetector (ix, iy, theta, r, phi, L, iDetPos);
341 v[ix][iy] += rotScale * filteredProj[iDetPos];
342 } else if (interpType == Backprojector::INTERP_LINEAR) {
343 double p = L / detInc; // position along detector
344 double pFloor = floor (p);
345 int iDetPos = iDetCenter + static_cast<int>(pFloor);
346 double frac = p - pFloor; // fraction distance from det
347 if (iDetPos < 0 || iDetPos >= nDet - 1) // check for impossible: index outside of raysum pos
348 errorIndexOutsideDetector (ix, iy, theta, r, phi, L, iDetPos);
350 v[ix][iy] += rotScale * ((1-frac) * filteredProj[iDetPos] + frac * filteredProj[iDetPos+1]);
357 // CLASS IDENTICATION
361 // Precalculates trigometric function value for each point in image for backprojection.
363 BackprojectTable::BackprojectTable (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
364 : Backproject (proj, im, interpType, interpFactor)
366 arrayR.initSetSize (im.nx(), im.ny());
367 arrayPhi.initSetSize (im.nx(), im.ny());
368 r = arrayR.getArray();
369 phi = arrayPhi.getArray();
371 double x, y; // Rectang coords of center of pixel
373 for (x = xMin + xInc / 2, ix = 0; ix < nx; x += xInc, ix++)
374 for (y = yMin + yInc / 2, iy = 0; iy < ny; y += yInc, iy++) {
375 r[ix][iy] = sqrt (x * x + y * y);
376 phi[ix][iy] = atan2 (y, x);
380 BackprojectTable::~BackprojectTable ()
382 ScaleImageByRotIncrement();
386 BackprojectTable::BackprojectView (const double* const filteredProj, const double view_angle)
388 double theta = view_angle;
390 for (int ix = 0; ix < nx; ix++) {
391 ImageFileColumn pImCol = v[ix];
393 for (int iy = 0; iy < ny; iy++) {
394 double L = r[ix][iy] * cos (theta - phi[ix][iy]);
396 if (interpType == Backprojector::INTERP_NEAREST) {
397 int iDetPos = iDetCenter + nearest<int>(L / detInc); // calc index in the filtered raysum vector
399 if (iDetPos < 0 || iDetPos >= nDet) // check for impossible: index outside of raysum pos
400 errorIndexOutsideDetector (ix, iy, theta, r[ix][iy], phi[ix][iy], L, iDetPos);
402 pImCol[iy] += filteredProj[iDetPos];
403 } else if (interpType == Backprojector::INTERP_LINEAR) {
404 double dPos = L / detInc; // position along detector
405 double dPosFloor = floor (dPos);
406 int iDetPos = iDetCenter + static_cast<int>(dPosFloor);
407 double frac = dPos - dPosFloor; // fraction distance from det
408 if (iDetPos < 0 || iDetPos >= nDet - 1)
409 errorIndexOutsideDetector (ix, iy, theta, r[ix][iy], phi[ix][iy], L, iDetPos);
411 pImCol[iy] += ((1-frac) * filteredProj[iDetPos] + frac * filteredProj[iDetPos+1]);
418 // CLASS IDENTICATION
422 // Backprojects by precalculating the change in L position for each x & y step in the image.
423 // Iterates in x & y direction by adding difference in L position
425 BackprojectDiff::BackprojectDiff (const Projections& proj, ImageFile& im, int interpType, const int interpFactor)
426 : Backproject (proj, im, interpType, interpFactor)
428 // calculate center of first pixel v[0][0]
429 double x = xMin + xInc / 2;
430 double y = yMin + yInc / 2;
431 start_r = sqrt (x * x + y * y);
432 start_phi = atan2 (y, x);
437 BackprojectDiff::~BackprojectDiff()
439 ScaleImageByRotIncrement();
443 BackprojectDiff::BackprojectView (const double* const filteredProj, const double view_angle)
445 double theta = view_angle; // add half PI to view angle to get perpendicular theta angle
446 double det_dx = xInc * cos (theta);
447 double det_dy = yInc * sin (theta);
448 double lColStart = start_r * cos (theta - start_phi); // calculate L for first point in image
450 for (int ix = 0; ix < nx; ix++, lColStart += det_dx) {
451 double curDetPos = lColStart;
452 ImageFileColumn pImCol = v[ix];
454 for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
456 printf ("[%2d,%2d]: %8.5f ", ix, iy, curDetPos);
458 if (interpType == Backprojector::INTERP_NEAREST) {
459 int iDetPos = iDetCenter + nearest<int>(curDetPos / detInc); // calc index in the filtered raysum vector
461 if (iDetPos < 0 || iDetPos >= nDet) // check for impossible: index outside of raysum pos
462 errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
464 pImCol[iy] += filteredProj[iDetPos];
465 } else if (interpType == Backprojector::INTERP_LINEAR) {
466 double detPos = curDetPos / detInc; // position along detector
467 double detPosFloor = floor (detPos);
468 int iDetPos = iDetCenter + static_cast<int>(detPosFloor);
469 double frac = detPos - detPosFloor; // fraction distance from det
470 if (iDetPos < 0 || iDetPos >= nDet - 1)
471 errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
473 pImCol[iy] += ((1-frac) * filteredProj[iDetPos] + frac * filteredProj[iDetPos+1]);
480 // CLASS IDENTICATION
484 // Optimized version of BackprojectDiff
487 BackprojectDiff2::BackprojectView (const double* const filteredProj, const double view_angle)
489 double theta = view_angle;
491 // Distance betw. detectors for an angle given in units of detectors
492 double det_dx = xInc * cos (theta) / detInc;
493 double det_dy = yInc * sin (theta) / detInc;
495 // calculate detPosition for first point in image (ix=0, iy=0)
496 double detPosColStart = start_r * cos (theta - start_phi) / detInc;
499 printf ("start_r=%8.5f, start_phi=%8.5f, rotScale=%8.5f\n", start_r, start_phi, rotScale);
501 for (int ix = 0; ix < nx; ix++, detPosColStart += det_dx) {
502 double curDetPos = detPosColStart;
503 ImageFileColumn pImCol = v[ix];
505 for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
507 printf ("[%2d,%2d]: %8.5f %8.5f\n", ix, iy, curDetPos, filteredProj[iDetCenter + nearest<int>(curDetPos)]);
509 if (interpType == Backprojector::INTERP_NEAREST) {
510 int iDetPos = iDetCenter + nearest<int> (curDetPos); // calc index in the filtered raysum vector
512 if (iDetPos < 0 || iDetPos >= nDet) // check for impossible: index outside of raysum pos
513 errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
515 *pImCol++ += filteredProj[iDetPos];
516 } else if (interpType == Backprojector::INTERP_LINEAR) {
517 double detPosFloor = floor (curDetPos);
518 int iDetPos = iDetCenter + static_cast<int>(detPosFloor);
519 double frac = curDetPos - detPosFloor; // fraction distance from det
520 if (iDetPos < 0 || iDetPos >= nDet - 1)
521 errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
523 *pImCol++ += filteredProj[iDetPos] + (frac * (filteredProj[iDetPos+1] - filteredProj[iDetPos]));
529 // CLASS IDENTICATION
530 // BackprojectIntDiff2
533 // Integer version of BackprojectDiff2
536 BackprojectIntDiff2::BackprojectView (const double* const filteredProj, const double view_angle)
538 double theta = view_angle;
540 static const kint32 scale = 1 << 16;
541 static const double dScale = scale;
542 static const kint32 halfScale = scale / 2;
544 const kint32 det_dx = nearest<kint32> (xInc * cos (theta) / detInc * scale);
545 const kint32 det_dy = nearest<kint32> (yInc * sin (theta) / detInc * scale);
547 // calculate L for first point in image (0, 0)
548 kint32 detPosColStart = nearest<kint32> (start_r * cos (theta - start_phi) / detInc * scale);
550 for (int ix = 0; ix < nx; ix++, detPosColStart += det_dx) {
551 kint32 curDetPos = detPosColStart;
552 ImageFileColumn pImCol = v[ix];
554 for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
555 if (interpType == Backprojector::INTERP_NEAREST) {
556 int detPosNearest = (curDetPos >= 0 ? ((curDetPos + halfScale) / scale) : ((curDetPos - halfScale) / scale));
557 int iDetPos = iDetCenter + detPosNearest; // calc index in the filtered raysum vector
559 if (iDetPos < 0 || iDetPos >= nDet) // check for index outside of raysum pos
560 errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
562 *pImCol++ += filteredProj[iDetPos];
563 } else if (interpType == Backprojector::INTERP_LINEAR) {
564 kint32 detPosFloor = curDetPos / scale;
565 kint32 detPosRemainder = curDetPos % scale;
566 if (detPosRemainder < 0) {
568 detPosRemainder += scale;
570 int iDetPos = iDetCenter + detPosFloor;
571 double frac = detPosRemainder / dScale;
572 if (iDetPos < 0 || iDetPos >= nDet - 1)
573 errorIndexOutsideDetector (ix, iy, theta, curDetPos, iDetPos);
575 *pImCol++ += ((1.-frac) * filteredProj[iDetPos] + frac * filteredProj[iDetPos+1]);
581 // CLASS IDENTICATION
582 // BackprojectIntDiff3
585 // Highly optimized version of BackprojectIntDiff2
588 BackprojectIntDiff3::BackprojectView (const double* const filteredProj, const double view_angle)
590 double theta = view_angle; // add half PI to view angle to get perpendicular theta angle
591 static const int scaleShift = 16;
592 static const kint32 scale = (1 << scaleShift);
593 static const kint32 scaleBitmask = scale - 1;
594 static const kint32 halfScale = scale / 2;
595 static const double dInvScale = 1. / scale;
597 const kint32 det_dx = nearest<kint32> (xInc * cos (theta) / detInc * scale);
598 const kint32 det_dy = nearest<kint32> (yInc * sin (theta) / detInc * scale);
600 // calculate L for first point in image (0, 0)
601 kint32 detPosColStart = nearest<kint32> ((start_r * cos (theta - start_phi) / detInc + iDetCenter) * scale);
603 // precalculate scaled difference for linear interpolation
604 double* deltaFilteredProj = new double [nDet];
605 if (interpType == Backprojector::INTERP_LINEAR) {
606 for (int i = 0; i < nDet - 1; i++)
607 deltaFilteredProj[i] = (filteredProj[i+1] - filteredProj[i]) * dInvScale;
609 deltaFilteredProj[nDet - 1] = 0; // last detector
611 int iLastDet = nDet - 1;
612 for (int ix = 0; ix < nx; ix++, detPosColStart += det_dx) {
613 kint32 curDetPos = detPosColStart;
614 ImageFileColumn pImCol = v[ix];
616 if (interpType == Backprojector::INTERP_NEAREST) {
617 for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
618 const int iDetPos = (curDetPos + halfScale) >> 16;
619 if (iDetPos >= 0 && iDetPos <= iLastDet)
620 *pImCol++ += filteredProj[iDetPos];
622 } else if (interpType == Backprojector::INTERP_FREQ_PREINTERPOLATION) {
623 for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
624 const int iDetPos = ((curDetPos + halfScale) >> 16) * m_interpFactor;
625 if (iDetPos >= 0 && iDetPos <= iLastDet)
626 *pImCol++ += filteredProj[iDetPos];
628 } else if (interpType == Backprojector::INTERP_LINEAR) {
629 for (int iy = 0; iy < ny; iy++, curDetPos += det_dy) {
630 const kint32 iDetPos = curDetPos >> scaleShift;
631 const kint32 detRemainder = curDetPos & scaleBitmask;
632 if (iDetPos >= 0 && iDetPos <= iLastDet)
633 *pImCol++ += filteredProj[iDetPos] + (detRemainder * deltaFilteredProj[iDetPos]);
638 delete deltaFilteredProj;
643 BackprojectEquiangular::BackprojectView (const double* const filteredProj, const double view_angle)
645 double beta = view_angle;
647 for (int ix = 0; ix < nx; ix++) {
648 ImageFileColumn pImCol = v[ix];
650 for (int iy = 0; iy < ny; iy++) {
651 double dAngleDiff = beta - phi[ix][iy];
652 double rcos_t = r[ix][iy] * cos (dAngleDiff);
653 double rsin_t = r[ix][iy] * sin (dAngleDiff);
654 double dFLPlusSin = m_dFocalLength + rsin_t;
655 double gamma = atan (rcos_t / dFLPlusSin);
656 double dL2 = dFLPlusSin * dFLPlusSin + (rcos_t * rcos_t);
658 if (interpType == Backprojector::INTERP_NEAREST) {
659 int iDetPos =iDetCenter + nearest<int>(gamma / detInc); // calc index in the filtered raysum vector
661 if (iDetPos < 0 || iDetPos >= nDet) { // check for impossible: index outside of raysum pos
662 ; // errorIndexOutsideDetector (ix, iy, beta, r[ix][iy], phi[ix][iy], gamma, iDetPos);
664 pImCol[iy] += filteredProj[iDetPos] / dL2;
665 } else if (interpType == Backprojector::INTERP_LINEAR) {
666 double dPos = gamma / detInc; // position along detector
667 double dPosFloor = floor (dPos);
668 int iDetPos = iDetCenter + static_cast<int>(dPosFloor);
669 double frac = dPos - dPosFloor; // fraction distance from det
670 if (iDetPos < 0 || iDetPos >= nDet - 1) {
671 ; // errorIndexOutsideDetector (ix, iy, beta, r[ix][iy], phi[ix][iy], gamma, iDetPos);
673 pImCol[iy] += (filteredProj[iDetPos] + frac * (filteredProj[iDetPos+1] - filteredProj[iDetPos])) / dL2;
680 BackprojectEquilinear::BackprojectView (const double* const filteredProj, const double view_angle)
682 double beta = view_angle;
684 for (int ix = 0; ix < nx; ix++) {
685 ImageFileColumn pImCol = v[ix];
687 for (int iy = 0; iy < ny; iy++) {
688 double dAngleDiff = beta - phi[ix][iy];
689 double rcos_t = r[ix][iy] * cos (dAngleDiff);
690 double rsin_t = r[ix][iy] * sin (dAngleDiff);
692 double dU = (m_dFocalLength + rsin_t) / m_dFocalLength;
693 double dDetPos = rcos_t / dU;
694 // double to scale for imaginary detector that passes through origin
695 // of phantom, see Kak-Slaney Figure 3.22
698 if (interpType == Backprojector::INTERP_NEAREST) {
699 int iDetPos = iDetCenter + nearest<int>(dDetPos / detInc); // calc index in the filtered raysum vector
701 if (iDetPos < 0 || iDetPos >= nDet) // check for impossible: index outside of raysum pos
702 ; /// errorIndexOutsideDetector (ix, iy, beta, r[ix][iy], phi[ix][iy], dDetPos, iDetPos);
704 pImCol[iy] += (filteredProj[iDetPos] / (dU * dU));
705 } else if (interpType == Backprojector::INTERP_LINEAR) {
706 double dPos = dDetPos / detInc; // position along detector
707 double dPosFloor = floor (dPos);
708 int iDetPos = iDetCenter + static_cast<int>(dPosFloor);
709 double frac = dPos - dPosFloor; // fraction distance from det
710 if (iDetPos < 0 || iDetPos >= nDet - 1)
711 ; // errorIndexOutsideDetector (ix, iy, beta, r[ix][iy], phi[ix][iy], dDetPos, iDetPos);
713 pImCol[iy] += (filteredProj[iDetPos] + frac * (filteredProj[iDetPos+1] - filteredProj[iDetPos])) / (dU * dU);