diff options
author | Wim van Aarle <wimvanaarle@gmail.com> | 2015-05-27 15:48:48 +0200 |
---|---|---|
committer | Wim van Aarle <wimvanaarle@gmail.com> | 2015-05-27 15:48:48 +0200 |
commit | 1ff4a270a7df1edb54dd91fe653d6a936b959b3a (patch) | |
tree | 1a12275687b032072dcda345d6d99fbc3f1536ce /include/astra/ParallelBeamLineKernelProjector2D.inl | |
parent | fe9bba178fdae86ab47fa0428ed38dc04f6ac0a2 (diff) | |
download | astra-1ff4a270a7df1edb54dd91fe653d6a936b959b3a.tar.gz astra-1ff4a270a7df1edb54dd91fe653d6a936b959b3a.tar.bz2 astra-1ff4a270a7df1edb54dd91fe653d6a936b959b3a.tar.xz astra-1ff4a270a7df1edb54dd91fe653d6a936b959b3a.zip |
some marginal gains + added documentation
Diffstat (limited to 'include/astra/ParallelBeamLineKernelProjector2D.inl')
-rw-r--r-- | include/astra/ParallelBeamLineKernelProjector2D.inl | 209 |
1 files changed, 140 insertions, 69 deletions
diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 9c58d60..199cfd7 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -25,6 +25,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>. ----------------------------------------------------------------------- $Id$ */ +#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } template <typename Policy> void CParallelBeamLineKernelProjector2D::project(Policy& p) @@ -48,10 +49,95 @@ void CParallelBeamLineKernelProjector2D::projectSingleRay(int _iProjection, int } - - //---------------------------------------------------------------------------------------- // PROJECT BLOCK - vector projection geometry +// +// Kernel limitations: isotropic pixels (PixelLengthX == PixelLengthY) +// +// For each angle/detector pair: +// +// Let D=(Dx,Dy) denote the centre of the detector (point) in volume coordinates, and +// let R=(Rx,Ry) denote the direction of the ray (vector). +// +// For mainly vertical rays (|Rx|<=|Ry|), +// let E=(Ex,Ey) denote the centre of the most upper left pixel: +// E = (WindowMinX + PixelLengthX/2, WindowMaxY - PixelLengthY/2), +// and let F=(Fx,Fy) denote a vector to the next pixel +// F = (PixelLengthX, 0) +// +// The intersection of the ray (D+aR) with the centre line of the upper row of pixels (E+bF) is +// { Dx + a*Rx = Ex + b*Fx +// { Dy + a*Ry = Ey + b*Fy +// Solving for (a,b) results in: +// a = (Ey + b*Fy - Dy)/Ry +// = (Ey - Dy)/Ry +// b = (Dx + a*Rx - Ex)/Fx +// = (Dx + (Ey - Dy)*Rx/Ry - Ex)/Fx +// +// Define c as the x-value of the intersection of the ray with the upper row in pixel coordinates. +// c = b +// +// The intersection of the ray (D+aR) with the centre line of the second row of pixels (E'+bF) with +// E'=(WindowMinX + PixelLengthX/2, WindowMaxY - 3*PixelLengthY/2) +// expressed in x-value pixel coordinates is +// c' = (Dx + (Ey' - Dy)*Rx/Ry - Ex)/Fx. +// And thus: +// deltac = c' - c = (Dx + (Ey' - Dy)*Rx/Ry - Ex)/Fx - (Dx + (Ey - Dy)*Rx/Ry - Ex)/Fx +// = [(Ey' - Dy)*Rx/Ry - (Ey - Dy)*Rx/Ry]/Fx +// = [Ey' - Ey]*(Rx/Ry)/Fx +// = [Ey' - Ey]*(Rx/Ry)/Fx +// = -PixelLengthY*(Rx/Ry)/Fx. +// +// Given c on a certain row, its closest pixel (col), and the distance (offset) to it, can be found: +// col = floor(c+1/2) +// offset = c - col +// +// The index of this pixel is +// volumeIndex = row * colCount + col +// +// The projection kernel is defined by +// +// _____ LengthPerRow +// /| | |\ +// / | | | \ +// __/ | | | \__ 0 +// -T -S 0 S T +// +// with S = 1/2 - 1/2*|Rx/Ry|, T = 1/2 + 1/2*|Rx/Ry|, and LengthPerRow = pixelLengthX * sqrt(Rx^2+Ry^2) / |Ry| +// +// And thus +// { (offset+T)/(T-S) * LengthPerRow if -T <= offset < S +// W_(rayIndex,volIndex) = { LengthPerRow if -S <= offset <= S +// { (offset-S)/(T-S) * LengthPerRow if S < offset <= T +// +// If -T <= offset < S, the weight for the pixel directly to the left is +// W_(rayIndex,volIndex-1) = LengthPerRow - (offset+T)/(T-S) * LengthPerRow, +// and if S < offset <= T, the weight for the pixel directly to the right is +// W_(rayIndex,volIndex+1) = LengthPerRow - (offset-S)/(T-S) * LengthPerRow. +// +// +// Mainly horizontal rays (|Rx|<=|Ry|) are handled in a similar fashion: +// +// E = (WindowMinX + PixelLengthX/2, WindowMaxY - PixelLengthY/2), +// F = (0, -PixelLengthX) +// +// a = (Ex + b*Fx - Dx)/Rx = (Ex - Dx)/Rx +// b = (Dy + a*Ry - Ey)/Fy = (Dy + (Ex - Dx)*Ry/Rx - Ey)/Fy +// r = b +// deltar = PixelLengthX*(Ry/Rx)/Fy. +// row = floor(r+1/2) +// offset = r - row +// S = 1/2 - 1/2*|Ry/Rx| +// T = 1/2 + 1/2*|Ry/Rx| +// LengthPerCol = pixelLengthY * sqrt(Rx^2+Ry^2) / |Rx| +// +// { (offset+T)/(T-S) * LengthPerCol if -T <= offset < S +// W_(rayIndex,volIndex) = { LengthPerCol if -S <= offset <= S +// { (offset-S)/(T-S) * LengthPerCol if S < offset <= T +// +// W_(rayIndex,volIndex-colcount) = LengthPerCol - (offset+T)/(T-S) * LengthPerCol +// W_(rayIndex,volIndex+colcount) = LengthPerCol - (offset-S)/(T-S) * LengthPerCol +// template <typename Policy> void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { @@ -64,8 +150,10 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i } // precomputations - const float32 inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); - const float32 inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); + const float32 pixelLengthX = m_pVolumeGeometry->getPixelLengthX(); + const float32 pixelLengthY = m_pVolumeGeometry->getPixelLengthY(); + const float32 inv_pixelLengthX = 1.0f / pixelLengthX; + const float32 inv_pixelLengthY = 1.0f / pixelLengthY; const int colCount = m_pVolumeGeometry->getGridColCount(); const int rowCount = m_pVolumeGeometry->getGridRowCount(); const int detCount = pVecProjectionGeometry->getDetectorCount(); @@ -75,87 +163,92 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { // variables - float32 detX, detY, S, T, I, x, y, c, r, update_c, update_r, offset; - float32 lengthPerRow, lengthPerCol, invTminSTimesLengthPerRow, invTminSTimesLengthPerCol; + float32 Dx, Dy, Ex, Ey, S, T, weight, c, r, deltac, deltar, offset; + float32 RxOverRy, RyOverRx, lengthPerRow, lengthPerCol, invTminSTimesLengthPerRow, invTminSTimesLengthPerCol; int iVolumeIndex, iRayIndex, row, col, iDetector; const SParProjection * proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY); if (vertical) { - lengthPerRow = m_pVolumeGeometry->getPixelLengthX() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayY); - update_c = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX; - S = 0.5f - 0.5f*fabs(proj->fRayX/proj->fRayY); - T = 0.5f + 0.5f*fabs(proj->fRayX/proj->fRayY); + RxOverRy = proj->fRayX/proj->fRayY; + lengthPerRow = pixelLengthX * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayY); + deltac = -pixelLengthY * RxOverRy * inv_pixelLengthX; + S = 0.5f - 0.5f*fabs(RxOverRy); + T = 0.5f + 0.5f*fabs(RxOverRy); invTminSTimesLengthPerRow = lengthPerRow / (T - S); } else { - lengthPerCol = m_pVolumeGeometry->getPixelLengthY() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayX); - update_r = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY; - S = 0.5f - 0.5f*fabs(proj->fRayY/proj->fRayX); - T = 0.5f + 0.5f*fabs(proj->fRayY/proj->fRayX); + RyOverRx = proj->fRayY/proj->fRayX; + lengthPerCol = pixelLengthY * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayX); + deltar = -pixelLengthX * RyOverRx * inv_pixelLengthY; + S = 0.5f - 0.5f*fabs(RyOverRx); + T = 0.5f + 0.5f*fabs(RyOverRx); invTminSTimesLengthPerCol = lengthPerCol / (T - S); } + Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f; + Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f; + // loop detectors - for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - + for (int iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { + iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; // POLICY: RAY PRIOR if (!p.rayPrior(iRayIndex)) continue; - - detX = proj->fDetSX + (iDetector+0.5f) * proj->fDetUX; - detY = proj->fDetSY + (iDetector+0.5f) * proj->fDetUY; + Dx = proj->fDetSX + (iDetector+0.5f) * proj->fDetUX; + Dy = proj->fDetSY + (iDetector+0.5f) * proj->fDetUY; + + bool isin = false; + // vertically if (vertical) { - // calculate x for row 0 - x = detX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detY); - c = (x - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; + // calculate c for row 0 + c = (Dx + (Ey - Dy)*RxOverRy - Ex) * inv_pixelLengthX; - // for each row - for (row = 0; row < rowCount; ++row, c += update_c) { + // loop rows + for (row = 0; row < rowCount; ++row, c += deltac) { col = int(c+0.5f); + if (col <= 0 || col >= colCount-1) { if (!isin) continue; else break; } offset = c - float32(col); - if (col <= 0 || col >= colCount-1) continue; - // left if (offset < -S) { - I = (offset + T) * invTminSTimesLengthPerRow; + weight = (offset + T) * invTminSTimesLengthPerRow; iVolumeIndex = row * colCount + col - 1; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); + p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-weight); p.pixelPosterior(iVolumeIndex); } iVolumeIndex++; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); + p.addWeight(iRayIndex, iVolumeIndex, weight); p.pixelPosterior(iVolumeIndex); } } // right else if (S < offset) { - I = (offset - S) * invTminSTimesLengthPerRow; + weight = (offset - S) * invTminSTimesLengthPerRow; iVolumeIndex = row * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); + p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-weight); p.pixelPosterior(iVolumeIndex); } iVolumeIndex++; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); + p.addWeight(iRayIndex, iVolumeIndex, weight); p.pixelPosterior(iVolumeIndex); } } @@ -169,73 +262,51 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i p.pixelPosterior(iVolumeIndex); } } - + isin = true; } } // horizontally else { - // calculate y for col 0 - y = detY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detX); - r = (m_pVolumeGeometry->getWindowMaxY() - y) * inv_pixelLengthY - 0.5f; + // calculate r for col 0 + r = -(Dy + (Ex - Dx)*RyOverRx - Ey) * inv_pixelLengthY; - // for each col - for (col = 0; col < colCount; ++col, r += update_r) { + // loop columns + for (col = 0; col < colCount; ++col, r += deltar) { - int row = int(r+0.5f); + row = int(r+0.5f); + if (row <= 0 || row >= rowCount-1) { if (!isin) continue; else break; } offset = r - float32(row); - if (row <= 0 || row >= rowCount-1) continue; - // up if (offset < -S) { - I = (offset + T) * invTminSTimesLengthPerCol; + weight = (offset + T) * invTminSTimesLengthPerCol; iVolumeIndex = (row-1) * colCount + col; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); - p.pixelPosterior(iVolumeIndex); - } + policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) iVolumeIndex += colCount; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } + policy_weight(p, iRayIndex, iVolumeIndex, weight) } // down else if (S < offset) { - I = (offset - S) * invTminSTimesLengthPerCol; + weight = (offset - S) * invTminSTimesLengthPerCol; iVolumeIndex = row * colCount + col; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); - p.pixelPosterior(iVolumeIndex); - } + policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) iVolumeIndex += colCount; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } + policy_weight(p, iRayIndex, iVolumeIndex, weight) } // centre else { iVolumeIndex = row * colCount + col; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol); - p.pixelPosterior(iVolumeIndex); - } + policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol) } - + isin = true; } } |