summaryrefslogtreecommitdiffstats
path: root/include/astra
diff options
context:
space:
mode:
Diffstat (limited to 'include/astra')
-rw-r--r--include/astra/FanFlatBeamLineKernelProjector2D.inl156
-rw-r--r--include/astra/ParallelBeamBlobKernelProjector2D.inl119
-rw-r--r--include/astra/ParallelBeamLineKernelProjector2D.inl209
-rw-r--r--include/astra/ParallelBeamLinearKernelProjector2D.inl153
-rw-r--r--include/astra/ParallelBeamStripKernelProjector2D.inl166
5 files changed, 509 insertions, 294 deletions
diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl
index 1676cb1..23438fb 100644
--- a/include/astra/FanFlatBeamLineKernelProjector2D.inl
+++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl
@@ -25,9 +25,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
-----------------------------------------------------------------------
$Id$
*/
-
-
-using namespace astra;
+#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); }
template <typename Policy>
void CFanFlatBeamLineKernelProjector2D::project(Policy& p)
@@ -55,12 +53,6 @@ void CFanFlatBeamLineKernelProjector2D::projectSingleRay(int _iProjection, int _
template <typename Policy>
void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p)
{
- // variables
- float32 detX, detY, S, T, I, x, y, c, r, update_c, update_r, offset;
- float32 lengthPerRow, lengthPerCol, inv_pixelLengthX, inv_pixelLengthY, invTminSTimesLengthPerRow, invTminSTimesLengthPerCol;
- int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector, colCount, rowCount, detCount;
- const SFanProjection * proj = 0;
-
// get vector geometry
const CFanFlatVecProjectionGeometry2D* pVecProjectionGeometry;
if (dynamic_cast<CFanFlatProjectionGeometry2D*>(m_pProjectionGeometry)) {
@@ -70,16 +62,26 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in
}
// precomputations
- inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX();
- inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY();
- colCount = m_pVolumeGeometry->getGridColCount();
- rowCount = m_pVolumeGeometry->getGridRowCount();
- detCount = pVecProjectionGeometry->getDetectorCount();
+ 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();
+ const float32 Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f;
+ const float32 Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f;
// loop angles
- for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) {
+ #pragma omp parallel for
+ for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) {
+
+ // variables
+ float32 Dx, Dy, Rx, Ry, S, T, weight, c, r, deltac, deltar, offset, RxOverRy, RyOverRx;
+ float32 lengthPerRow, lengthPerCol, invTminSTimesLengthPerRow, invTminSTimesLengthPerCol;
+ int iVolumeIndex, iRayIndex, row, col, iDetector;
- proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle];
+ const SFanProjection * proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle];
// loop detectors
for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) {
@@ -89,156 +91,116 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in
// 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;
- float32 fRayX = proj->fSrcX - detX;
- float32 fRayY = proj->fSrcY - detY;
+ Rx = proj->fSrcX - Dx;
+ Ry = proj->fSrcY - Dy;
- bool vertical = fabs(fRayX) < fabs(fRayY);
+ bool vertical = fabs(Rx) < fabs(Ry);
if (vertical) {
- lengthPerRow = m_pVolumeGeometry->getPixelLengthX() * sqrt(fRayY*fRayY + fRayX*fRayX) / abs(fRayY);
- update_c = -m_pVolumeGeometry->getPixelLengthY() * (fRayX/fRayY) * inv_pixelLengthX;
- S = 0.5f - 0.5f*fabs(fRayX/fRayY);
- T = 0.5f + 0.5f*fabs(fRayX/fRayY);
+ RxOverRy = Rx/Ry;
+ lengthPerRow = pixelLengthX * sqrt(Rx*Rx + Ry*Ry) / abs(Ry);
+ 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(fRayY*fRayY + fRayX*fRayX) / abs(fRayX);
- update_r = -m_pVolumeGeometry->getPixelLengthX() * (fRayY/fRayX) * inv_pixelLengthY;
- S = 0.5f - 0.5f*fabs(fRayY/fRayX);
- T = 0.5f + 0.5f*fabs(fRayY/fRayX);
+ RyOverRx = Ry/Rx;
+ lengthPerCol = pixelLengthY * sqrt(Rx*Rx + Ry*Ry) / abs(Rx);
+ deltar = -pixelLengthX * RyOverRx * inv_pixelLengthY;
+ S = 0.5f - 0.5f*fabs(RyOverRx);
+ T = 0.5f + 0.5f*fabs(RyOverRx);
invTminSTimesLengthPerCol = lengthPerCol / (T - S);
}
+ bool isin = false;
+
// vertically
if (vertical) {
- // calculate x for row 0
- x = detX + (fRayX/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) {
+ 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.pixelPosterior(iVolumeIndex);
- }
+ policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight)
iVolumeIndex++;
- // POLICY: PIXEL PRIOR + ADD + POSTERIOR
- if (p.pixelPrior(iVolumeIndex)) {
- p.addWeight(iRayIndex, iVolumeIndex, I);
- p.pixelPosterior(iVolumeIndex);
- }
+ policy_weight(p, iRayIndex, iVolumeIndex, weight)
}
// 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.pixelPosterior(iVolumeIndex);
- }
+ policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight)
iVolumeIndex++;
- // 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, lengthPerRow);
- p.pixelPosterior(iVolumeIndex);
- }
+ policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow)
}
-
+ isin = true;
}
}
// horizontally
else {
- // calculate y for col 0
- y = detY + (fRayY/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) {
+ for (col = 0; col < colCount; ++col, r += deltar) {
int 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;
}
}
diff --git a/include/astra/ParallelBeamBlobKernelProjector2D.inl b/include/astra/ParallelBeamBlobKernelProjector2D.inl
index 1945cdd..c2aa193 100644
--- a/include/astra/ParallelBeamBlobKernelProjector2D.inl
+++ b/include/astra/ParallelBeamBlobKernelProjector2D.inl
@@ -50,6 +50,63 @@ void CParallelBeamBlobKernelProjector2D::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 pixel directly on its left (col), and the distance (offset) to it, can be found:
+// col = floor(c)
+// offset = c - col
+//
+// The index of this pixel is
+// volumeIndex = row * colCount + col
+//
+//
+// 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
+//
template <typename Policy>
void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p)
{
@@ -62,6 +119,8 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i
}
// precomputations
+ const float32 pixelLengthX = m_pVolumeGeometry->getPixelLengthX();
+ const float32 pixelLengthY = m_pVolumeGeometry->getPixelLengthY();
const float32 inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX();
const float32 inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY();
const int colCount = m_pVolumeGeometry->getGridColCount();
@@ -73,7 +132,7 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i
for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) {
// variables
- float32 detX, detY, x, y, c, r, update_c, update_r, offset, invBlobExtent, weight, d;
+ float32 Dx, Dy, Ex, Ey, c, r, deltac, deltar, offset, invBlobExtent, RxOverRy, RyOverRx;
int iVolumeIndex, iRayIndex, row, col, iDetector;
int col_left, col_right, row_top, row_bottom, index;
@@ -81,15 +140,18 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i
bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY);
if (vertical) {
- update_c = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX;
- float32 normR = sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX);
- invBlobExtent = m_pVolumeGeometry->getPixelLengthY() / abs(m_fBlobSize * normR / proj->fRayY);
+ RxOverRy = proj->fRayX/proj->fRayY;
+ deltac = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX;
+ invBlobExtent = m_pVolumeGeometry->getPixelLengthY() / abs(m_fBlobSize * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / proj->fRayY);
} else {
- update_r = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY;
- float32 normR = sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX);
- invBlobExtent = m_pVolumeGeometry->getPixelLengthX() / abs(m_fBlobSize * normR / proj->fRayX);
+ RyOverRx = proj->fRayY/proj->fRayX;
+ deltar = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY;
+ invBlobExtent = m_pVolumeGeometry->getPixelLengthX() / abs(m_fBlobSize * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / proj->fRayX);
}
+ Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f;
+ Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f;
+
// loop detectors
for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) {
@@ -98,18 +160,17 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i
// 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;
// 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_left = int(c - 0.5f - m_fBlobSize);
col_right = int(c + 0.5f + m_fBlobSize);
@@ -117,17 +178,15 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i
if (col_left < 0) col_left = 0;
if (col_right > colCount-1) col_right = colCount-1;
- // for each column
+ // loop columns
for (col = col_left; col <= col_right; ++col) {
- offset = abs(c - float32(col)) * invBlobExtent;
- index = (int)(offset*m_iBlobSampleCount+0.5f);
- weight = m_pfBlobValues[min(index,m_iBlobSampleCount-1)];
-
iVolumeIndex = row * colCount + col;
// POLICY: PIXEL PRIOR + ADD + POSTERIOR
if (p.pixelPrior(iVolumeIndex)) {
- p.addWeight(iRayIndex, iVolumeIndex, weight);
+ offset = abs(c - float32(col)) * invBlobExtent;
+ index = (int)(offset*m_iBlobSampleCount+0.5f);
+ p.addWeight(iRayIndex, iVolumeIndex, m_pfBlobValues[min(index,m_iBlobSampleCount-1)]);
p.pixelPosterior(iVolumeIndex);
}
}
@@ -137,12 +196,11 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i
// 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) {
row_top = int(r - 0.5f - m_fBlobSize);
row_bottom = int(r + 0.5f + m_fBlobSize);
@@ -150,21 +208,18 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i
if (row_top < 0) row_top = 0;
if (row_bottom > rowCount-1) row_bottom = rowCount-1;
- // for each column
+ // loop rows
for (row = row_top; row <= row_bottom; ++row) {
- offset = abs(r - float32(row)) * invBlobExtent;
- index = (int)(offset*m_iBlobSampleCount+0.5f);
- weight = m_pfBlobValues[min(index,m_iBlobSampleCount-1)];
-
iVolumeIndex = row * colCount + col;
// POLICY: PIXEL PRIOR + ADD + POSTERIOR
if (p.pixelPrior(iVolumeIndex)) {
- p.addWeight(iRayIndex, iVolumeIndex, weight);
+ offset = abs(r - float32(row)) * invBlobExtent;
+ index = (int)(offset*m_iBlobSampleCount+0.5f);
+ p.addWeight(iRayIndex, iVolumeIndex, m_pfBlobValues[min(index,m_iBlobSampleCount-1)]);
p.pixelPosterior(iVolumeIndex);
}
}
-
}
}
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;
}
}
diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl
index 79b82d4..ecbdeb3 100644
--- a/include/astra/ParallelBeamLinearKernelProjector2D.inl
+++ b/include/astra/ParallelBeamLinearKernelProjector2D.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 CParallelBeamLinearKernelProjector2D::project(Policy& p)
@@ -51,6 +52,79 @@ void CParallelBeamLinearKernelProjector2D::projectSingleRay(int _iProjection, in
//----------------------------------------------------------------------------------------
// 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 pixel directly on its left (col), and the distance (offset) to it, can be found:
+// col = floor(c)
+// offset = c - col
+//
+// The index of this pixel is
+// volumeIndex = row * colCount + col
+//
+// The projection kernel is defined by
+//
+// LengthPerRow
+// /|\
+// / | \
+// __/ | \__ 0
+// p0 p1 p2
+//
+// And thus
+// W_(rayIndex,volIndex) = (1 - offset) * lengthPerRow
+// W_(rayIndex,volIndex+1) = offset * 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
+// LengthPerCol = pixelLengthY * sqrt(Rx^2+Ry^2) / |Rx|
+//
+// W_(rayIndex,volIndex) = (1 - offset) * lengthPerCol
+// W_(rayIndex,volIndex+colcount) = offset * lengthPerCol
+//
template <typename Policy>
void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p)
{
@@ -63,8 +137,10 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom,
}
// 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();
@@ -74,21 +150,26 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom,
for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) {
// variables
- float32 detX, detY, x, y, c, r, update_c, update_r, offset;
- float32 lengthPerRow, lengthPerCol;
+ float32 Dx, Dy, Ex, Ey, x, y, c, r, deltac, deltar, offset;
+ float32 RxOverRy, RyOverRx, lengthPerRow, lengthPerCol;
int iVolumeIndex, iRayIndex, row, col, iDetector;
const SParProjection * proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle];
bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY);
if (vertical) {
+ RxOverRy = proj->fRayX/proj->fRayY;
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;
+ deltac = -pixelLengthY * RxOverRy * inv_pixelLengthX;
} else {
+ RyOverRx = proj->fRayY/proj->fRayX;
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;
+ deltar = -pixelLengthX * RyOverRx * inv_pixelLengthY;
}
+ Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f;
+ Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f;
+
// loop detectors
for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) {
@@ -97,70 +178,54 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom,
// 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);
+ if (col <= 0 || col >= colCount-1) { if (!isin) continue; else break; }
offset = c - float32(col);
- if (col <= 0 || col >= colCount-1) continue;
-
iVolumeIndex = row * colCount + col;
- // POLICY: PIXEL PRIOR + ADD + POSTERIOR
- if (p.pixelPrior(iVolumeIndex)) {
- p.addWeight(iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerRow);
- p.pixelPosterior(iVolumeIndex);
- }
+ policy_weight(p, iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerRow)
iVolumeIndex++;
- // POLICY: PIXEL PRIOR + ADD + POSTERIOR
- if (p.pixelPrior(iVolumeIndex)) {
- p.addWeight(iRayIndex, iVolumeIndex, offset * lengthPerRow);
- p.pixelPosterior(iVolumeIndex);
- }
+ policy_weight(p, iRayIndex, iVolumeIndex, offset * lengthPerRow)
+ 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);
+ row = int(r);
+ if (row <= 0 || row >= rowCount-1) { if (!isin) continue; else break; }
offset = r - float32(row);
- if (row <= 0 || row >= rowCount-1) continue;
-
iVolumeIndex = row * colCount + col;
- // POLICY: PIXEL PRIOR + ADD + POSTERIOR
- if (p.pixelPrior(iVolumeIndex)) {
- p.addWeight(iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerCol);
- p.pixelPosterior(iVolumeIndex);
- }
+ policy_weight(p, iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerCol)
iVolumeIndex += colCount;
- // POLICY: PIXEL PRIOR + ADD + POSTERIOR
- if (p.pixelPrior(iVolumeIndex)) {
- p.addWeight(iRayIndex, iVolumeIndex, offset * lengthPerCol);
- p.pixelPosterior(iVolumeIndex);
- }
-
+ policy_weight(p, iRayIndex, iVolumeIndex, offset * lengthPerCol)
+
+ isin = true;
}
}
diff --git a/include/astra/ParallelBeamStripKernelProjector2D.inl b/include/astra/ParallelBeamStripKernelProjector2D.inl
index 85faaa3..f0203f2 100644
--- a/include/astra/ParallelBeamStripKernelProjector2D.inl
+++ b/include/astra/ParallelBeamStripKernelProjector2D.inl
@@ -49,6 +49,68 @@ void CParallelBeamStripKernelProjector2D::projectSingleRay(int _iProjection, int
//----------------------------------------------------------------------------------------
// PROJECT BLOCK
+//
+// Kernel limitations: isotropic pixels (PixelLengthX == PixelLengthY)
+//
+// For each angle/detector pair:
+//
+// Let DL=(DLx,DLy) denote the left of the detector (point) in volume coordinates, and
+// Let DR=(DRx,DRy) denote the right 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 left edge of the strip (DL+aR) with the centre line of the upper row of pixels (E+bF) is
+// { DLx + a*Rx = Ex + b*Fx
+// { DLy + a*Ry = Ey + b*Fy
+// Solving for (a,b) results in:
+// a = (Ey + b*Fy - DLy)/Ry
+// = (Ey - DLy)/Ry
+// b = (DLx + a*Rx - Ex)/Fx
+// = (DLx + (Ey - DLy)*Rx/Ry - Ex)/Fx
+//
+// Define cL as the x-value of the intersection of the left edge of the strip with the upper row in pixel coordinates.
+// cL = b
+//
+// cR, the x-value of the intersection of the right edge of the strip with the upper row in pixel coordinates can be found similarly.
+//
+// The intersection of the ray (DL+aR) with the left 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
+// cL' = (DLx + (Ey' - DLy)*Rx/Ry - Ex)/Fx.
+// And thus:
+// deltac = cL' - cL = (DLx + (Ey' - DLy)*Rx/Ry - Ex)/Fx - (DLx + (Ey - DLy)*Rx/Ry - Ex)/Fx
+// = [(Ey' - DLy)*Rx/Ry - (Ey - DLy)*Rx/Ry]/Fx
+// = [Ey' - Ey]*(Rx/Ry)/Fx
+// = [Ey' - Ey]*(Rx/Ry)/Fx
+// = -PixelLengthY*(Rx/Ry)/Fx.
+//
+// The projection weight for a certain pixel is defined by the area between two points of
+//
+// _____ 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|
+//
+// For a certain row, all columns that are 'hit' by this kernel lie in the interval
+// (col_left, col_right) = (floor(cL-1/2+S), floor(cR+3/2-S))
+//
+// The offsets for both is
+// (offsetL, offsetR) = (cL - floor(col_left), cR - floor(col_left))
+//
+// The projection weight is found by the difference between the integrated values of the kernel
+// offset <= -T Kernel = 0
+// -T < offset <= -S Kernel = PixelArea/2*(T+offset)^2/(T-S)
+// -S < offset <= S Kernel = PixelArea/2 + offset
+// S < offset <= T Kernel = PixelArea - PixelArea/2*(T-offset)^2/(T-S)
+// T <= offset: Kernel = PixelArea
+//
template <typename Policy>
void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p)
{
@@ -61,9 +123,11 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
}
// precomputations
- const float32 inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX();
- const float32 inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY();
- const float32 pixelArea = m_pVolumeGeometry->getPixelLengthX() * m_pVolumeGeometry->getPixelLengthY();
+ const float32 pixelLengthX = m_pVolumeGeometry->getPixelLengthX();
+ const float32 pixelLengthY = m_pVolumeGeometry->getPixelLengthY();
+ const float32 pixelArea = pixelLengthX * pixelLengthY;
+ 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();
@@ -73,8 +137,8 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) {
// variables
- float32 detLX, detLY, detRX, detRY, S, T, update_c, update_r, offsetL, offsetR, invTminS;
- float32 res, fRxOverRy, fRyOverRx;
+ float32 DLx, DLy, DRx, DRy, Ex, Ey, S, T, deltac, deltar, offsetL, offsetR, invTminS;
+ float32 res, RxOverRy, RyOverRx, cL, cR, rL, rR;
int iVolumeIndex, iRayIndex, iDetector;
int row, row_top, row_bottom, col, col_left, col_right;
@@ -82,19 +146,22 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY);
if (vertical) {
- fRxOverRy = proj->fRayX/proj->fRayY;
- update_c = -m_pVolumeGeometry->getPixelLengthY() * fRxOverRy * inv_pixelLengthX;
- S = 0.5f - 0.5f*fabs(fRxOverRy);
- T = 0.5f + 0.5f*fabs(fRxOverRy);
+ RxOverRy = proj->fRayX/proj->fRayY;
+ deltac = -m_pVolumeGeometry->getPixelLengthY() * RxOverRy * inv_pixelLengthX;
+ S = 0.5f - 0.5f*fabs(RxOverRy);
+ T = 0.5f + 0.5f*fabs(RxOverRy);
invTminS = 1.0f / (T-S);
} else {
- fRyOverRx = proj->fRayY/proj->fRayX;
- update_r = -m_pVolumeGeometry->getPixelLengthX() * fRyOverRx * inv_pixelLengthY;
- S = 0.5f - 0.5f*fabs(fRyOverRx);
- T = 0.5f + 0.5f*fabs(fRyOverRx);
+ RyOverRx = proj->fRayY/proj->fRayX;
+ deltar = -m_pVolumeGeometry->getPixelLengthX() * RyOverRx * inv_pixelLengthY;
+ S = 0.5f - 0.5f*fabs(RyOverRx);
+ T = 0.5f + 0.5f*fabs(RyOverRx);
invTminS = 1.0f / (T-S);
}
+ Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f;
+ Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f;
+
// loop detectors
for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) {
@@ -103,19 +170,17 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
// POLICY: RAY PRIOR
if (!p.rayPrior(iRayIndex)) continue;
- detLX = proj->fDetSX + iDetector * proj->fDetUX;
- detLY = proj->fDetSY + iDetector * proj->fDetUY;
- detRX = detLX + proj->fDetUX;
- detRY = detLY + proj->fDetUY;
+ DLx = proj->fDetSX + iDetector * proj->fDetUX;
+ DLy = proj->fDetSY + iDetector * proj->fDetUY;
+ DRx = DLx + proj->fDetUX;
+ DRy = DLy + proj->fDetUY;
// vertically
if (vertical) {
// calculate cL and cR for row 0
- float32 xL = detLX + fRxOverRy*(m_pVolumeGeometry->pixelRowToCenterY(0)-detLY);
- float32 cL = (xL - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f;
- float32 xR = detRX + fRxOverRy*(m_pVolumeGeometry->pixelRowToCenterY(0)-detRY);
- float32 cR = (xR - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f;
+ cL = (DLx + (Ey - DLy)*RxOverRy - Ex) * inv_pixelLengthX;
+ cR = (DRx + (Ey - DRy)*RxOverRy - Ex) * inv_pixelLengthX;
if (cR < cL) {
float32 tmp = cL;
@@ -123,8 +188,8 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
cR = tmp;
}
- // for each row
- for (row = 0; row < rowCount; ++row, cL += update_c, cR += update_c) {
+ // loop rows
+ for (row = 0; row < rowCount; ++row, cL += deltac, cR += deltac) {
col_left = int(cL-0.5f+S);
col_right = int(cR+1.5-S);
@@ -132,27 +197,27 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
if (col_left < 0) col_left = 0;
if (col_right > colCount-1) col_right = colCount-1;
- offsetL = cL - float32(col_left);
- offsetR = cR - float32(col_left);
+ float32 tmp = float32(col_left);
+ offsetL = cL - tmp;
+ offsetR = cR - tmp;
- // for each column
+ // loop columns
for (col = col_left; col <= col_right; ++col, offsetL -= 1.0f, offsetR -= 1.0f) {
iVolumeIndex = row * colCount + col;
-
// POLICY: PIXEL PRIOR + ADD + POSTERIOR
if (p.pixelPrior(iVolumeIndex)) {
// right ray edge
- if (T <= offsetR) res = 1.0f;
- else if (S < offsetR) res = 1.0f - 0.5f*(T-offsetR)*(T-offsetR)*invTminS;
- else if (-S < offsetR) res = 0.5f + offsetR;
- else if (-T < offsetR) res = 0.5f*(offsetR+T)*(offsetR+T)*invTminS;
- else res = 0.0f;
+ if (T <= offsetR) res = 1.0f;
+ else if (S < offsetR) res = 1.0f - 0.5f*(T-offsetR)*(T-offsetR)*invTminS;
+ else if (-S < offsetR) res = 0.5f + offsetR;
+ else if (-T < offsetR) res = 0.5f*(offsetR+T)*(offsetR+T)*invTminS;
+ else res = 0.0f;
// left ray edge
- if (T <= offsetL) res -= 1.0f;
- else if (S < offsetL) res -= 1.0f - 0.5f*(T-offsetL)*(T-offsetL)*invTminS;
+ if (T <= offsetL) res -= 1.0f;
+ else if (S < offsetL) res -= 1.0f - 0.5f*(T-offsetL)*(T-offsetL)*invTminS;
else if (-S < offsetL) res -= 0.5f + offsetL;
else if (-T < offsetL) res -= 0.5f*(offsetL+T)*(offsetL+T)*invTminS;
@@ -167,10 +232,8 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
else {
// calculate rL and rR for row 0
- float32 yL = detLY + fRyOverRx*(m_pVolumeGeometry->pixelColToCenterX(0)-detLX);
- float32 rL = (m_pVolumeGeometry->getWindowMaxY() - yL) * inv_pixelLengthY - 0.5f;
- float32 yR = detRY + fRyOverRx*(m_pVolumeGeometry->pixelColToCenterX(0)-detRX);
- float32 rR = (m_pVolumeGeometry->getWindowMaxY() - yR) * inv_pixelLengthY - 0.5f;
+ rL = -(DLy + (Ex - DLx)*RyOverRx - Ey) * inv_pixelLengthY;
+ rR = -(DRy + (Ex - DRx)*RyOverRx - Ey) * inv_pixelLengthY;
if (rR < rL) {
float32 tmp = rL;
@@ -178,8 +241,8 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
rR = tmp;
}
- // for each column
- for (col = 0; col < colCount; ++col, rL += update_r, rR += update_r) {
+ // loop columns
+ for (col = 0; col < colCount; ++col, rL += deltar, rR += deltar) {
row_top = int(rL-0.5f+S);
row_bottom = int(rR+1.5-S);
@@ -187,31 +250,30 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom,
if (row_top < 0) row_top = 0;
if (row_bottom > rowCount-1) row_bottom = rowCount-1;
- offsetL = rL - float32(row_top);
- offsetR = rR - float32(row_top);
+ float32 tmp = float32(row_top);
+ offsetL = rL - tmp;
+ offsetR = rR - tmp;
- // for each row
+ // loop rows
for (row = row_top; row <= row_bottom; ++row, offsetL -= 1.0f, offsetR -= 1.0f) {
iVolumeIndex = row * colCount + col;
-
// POLICY: PIXEL PRIOR + ADD + POSTERIOR
if (p.pixelPrior(iVolumeIndex)) {
// right ray edge
- if (T <= offsetR) res = 1.0f;
- else if (S < offsetR) res = 1.0f - 0.5f*(T-offsetR)*(T-offsetR)*invTminS;
- else if (-S < offsetR) res = 0.5f + offsetR;
- else if (-T < offsetR) res = 0.5f*(offsetR+T)*(offsetR+T)*invTminS;
- else res = 0.0f;
+ if (T <= offsetR) res = 1.0f;
+ else if (S < offsetR) res = 1.0f - 0.5f*(T-offsetR)*(T-offsetR)*invTminS;
+ else if (-S < offsetR) res = 0.5f + offsetR;
+ else if (-T < offsetR) res = 0.5f*(offsetR+T)*(offsetR+T)*invTminS;
+ else res = 0.0f;
// left ray edge
- if (T <= offsetL) res -= 1.0f;
- else if (S < offsetL) res -= 1.0f - 0.5f*(T-offsetL)*(T-offsetL)*invTminS;
+ if (T <= offsetL) res -= 1.0f;
+ else if (S < offsetL) res -= 1.0f - 0.5f*(T-offsetL)*(T-offsetL)*invTminS;
else if (-S < offsetL) res -= 0.5f + offsetL;
else if (-T < offsetL) res -= 0.5f*(offsetL+T)*(offsetL+T)*invTminS;
-
p.addWeight(iRayIndex, iVolumeIndex, pixelArea*res);
p.pixelPosterior(iVolumeIndex);
}