From a452bc6f1c450a7174ec257d052dfe3ce25b1623 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Tue, 3 Mar 2015 18:22:23 +0100 Subject: created parallel_vec geometry class --- include/astra/GeometryUtil2D.h | 12 ++ include/astra/ParallelVecProjectionGeometry2D.h | 163 ++++++++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 include/astra/ParallelVecProjectionGeometry2D.h (limited to 'include/astra') diff --git a/include/astra/GeometryUtil2D.h b/include/astra/GeometryUtil2D.h index d4ee92e..680cecd 100644 --- a/include/astra/GeometryUtil2D.h +++ b/include/astra/GeometryUtil2D.h @@ -31,6 +31,18 @@ $Id$ namespace astra { +struct SParProjection { + // the ray direction + float fRayX, fRayY; + + // the start of the (linear) detector + float fDetSX, fDetSY; + + // the length of a single detector pixel + float fDetUX, fDetUY; +}; + + struct SFanProjection { // the source float fSrcX, fSrcY; diff --git a/include/astra/ParallelVecProjectionGeometry2D.h b/include/astra/ParallelVecProjectionGeometry2D.h new file mode 100644 index 0000000..96f8a54 --- /dev/null +++ b/include/astra/ParallelVecProjectionGeometry2D.h @@ -0,0 +1,163 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp + 2014-2015, CWI, Amsterdam + +Contact: astra@uantwerpen.be +Website: http://sf.net/projects/astra-toolbox + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +$Id$ +*/ + +#ifndef _INC_ASTRA_PARALLELVECPROJECTIONGEOMETRY2D +#define _INC_ASTRA_PARALLELVECPROJECTIONGEOMETRY2D + +#include "ProjectionGeometry2D.h" +#include "GeometryUtil2D.h" + +namespace astra +{ + +/** + * This class defines a 2D parallel beam projection geometry. + * + * \par XML Configuration + * \astra_xml_item{DetectorCount, int, Number of detectors for each projection.} + * + * \par MATLAB example + * \astra_code{ + * proj_geom = astra_struct('parallel_vec');\n + * proj_geom.DetectorCount = 512;\n + * proj_geom.Vectors = V;\n + * } + * + * \par Vectors + * Vectors is a matrix containing the actual geometry. Each row corresponds + * to a single projection, and consists of: + * ( rayX, rayY, dX, dY, uX, uY) + * ray: the ray direction + * d : the centre of the detector line + * u : the vector from detector pixel (0) to (1) + */ +class _AstraExport CParallelVecProjectionGeometry2D : public CProjectionGeometry2D +{ +protected: + + SParProjection *m_pProjectionAngles; + +public: + + /** Default constructor. Sets all variables to zero. Note that this constructor leaves the object in an unusable state and must + * be followed by a call to init(). + */ + CParallelVecProjectionGeometry2D(); + + /** Constructor. + * + * @param _iProjectionAngleCount Number of projection angles. + * @param _iDetectorCount Number of detectors, i.e., the number of detector measurements for each projection angle. + * @param _pfProjectionAngles Pointer to an array of projection angles. The angles will be copied from this array. + */ + CParallelVecProjectionGeometry2D(int _iProjectionAngleCount, + int _iDetectorCount, + const SParProjection* _pfProjectionAngles); + + /** Copy constructor. + */ + CParallelVecProjectionGeometry2D(const CParallelVecProjectionGeometry2D& _projGeom); + + /** Assignment operator. + */ + CParallelVecProjectionGeometry2D& operator=(const CParallelVecProjectionGeometry2D& _other); + + /** Destructor. + */ + virtual ~CParallelVecProjectionGeometry2D(); + + /** Initialize the geometry with a config object. + * + * @param _cfg Configuration Object + * @return initialization successful? + */ + virtual bool initialize(const Config& _cfg); + + /** Initialization. This function MUST be called after using the default constructor and MAY be called to + * reset a previously initialized object. + * + * @param _iProjectionAngleCount Number of projection angles. + * @param _iDetectorCount Number of detectors, i.e., the number of detector measurements for each projection angle. + * @param _pfProjectionAngles Pointer to an array of projection angles. The angles will be copied from this array. + */ + bool initialize(int _iProjectionAngleCount, + int _iDetectorCount, + const SParProjection* _pfProjectionAngles); + + virtual bool _check(); + + /** Create a hard copy. + */ + virtual CProjectionGeometry2D* clone(); + + /** Returns true if the type of geometry defined in this class is the one specified in _sType. + * + * @param _sType geometry type to compare to. + * @return true if _sType == "fanflat_vec". + */ + virtual bool isOfType(const std::string& _sType); + + /** Return true if this geometry instance is the same as the one specified. + * + * @return true if this geometry instance is the same as the one specified. + */ + virtual bool isEqual(CProjectionGeometry2D*) const; + + /** Get all settings in a Config object. + * + * @return Configuration Object. + */ + virtual Config* getConfiguration() const; + + + /** Get the value for t and theta, based upon the row and column index. + * + * @param _iRow row index + * @param _iColumn column index + * @param _fT output: value of t + * @param _fTheta output: value of theta, always lies within the [0,pi[ interval. + */ + virtual void getRayParams(int _iRow, int _iColumn, float32& _fT, float32& _fTheta) const; + + /** + * Returns a vector describing the direction of a ray belonging to a certain detector + * + * @param _iProjectionIndex index of projection + * @param _iProjectionIndex index of detector + * + * @return a unit vector describing the direction + */ + virtual CVector3D getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex); + + const SParProjection* getProjectionVectors() const { return m_pProjectionAngles; } + +}; + +} // namespace astra + +#endif /* _INC_ASTRA_PARALLELVECPROJECTIONGEOMETRY2D */ -- cgit v1.2.3 From a215ef4fb4ce341885aa74db65a5873c16637e69 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Thu, 5 Mar 2015 16:29:07 +0100 Subject: updated 'line' kernel projector --- include/astra/ParallelBeamLineKernelProjector2D.h | 7 + .../astra/ParallelBeamLineKernelProjector2D.inl | 202 ++++++++++++++++++++- 2 files changed, 206 insertions(+), 3 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLineKernelProjector2D.h b/include/astra/ParallelBeamLineKernelProjector2D.h index 24f43d5..dd5eab2 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.h +++ b/include/astra/ParallelBeamLineKernelProjector2D.h @@ -30,6 +30,7 @@ $Id$ #define _INC_ASTRA_PARALLELBEAMLINEKERNELPROJECTOR #include "ParallelProjectionGeometry2D.h" +#include "ParallelVecProjectionGeometry2D.h" #include "Float32Data2D.h" #include "Projector2D.h" @@ -180,6 +181,12 @@ protected: template void projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& _policy); + + /** Internal policy-based projection of a range of angles and range. + * (_i*From is inclusive, _i*To exclusive) */ + template + void projectBlock_internal_vector(int _iProjFrom, int _iProjTo, + int _iDetFrom, int _iDetTo, Policy& _policy); }; inline std::string CParallelBeamLineKernelProjector2D::getType() diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 199d69e..31aa138 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -29,8 +29,13 @@ $Id$ template void CParallelBeamLineKernelProjector2D::project(Policy& p) { - projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); + } } template @@ -49,7 +54,7 @@ void CParallelBeamLineKernelProjector2D::projectSingleRay(int _iProjection, int //---------------------------------------------------------------------------------------- -// PROJECT BLOCK +// PROJECT BLOCK - default projection geometry template void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { @@ -59,6 +64,11 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector, x1; bool switch_t; + float32 old_theta; + const SParProjection * proj = 0; + + const CParallelProjectionGeometry2D* pProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + // loop angles for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { @@ -287,3 +297,189 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i } +//---------------------------------------------------------------------------------------- +// PROJECT BLOCK - vector projection geometry +template +void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(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; + + const SParProjection * proj = 0; + const CParallelVecProjectionGeometry2D* pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + + inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); + inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); + + // loop angles + for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { + + proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; + + bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY); + if (vertical) { + S = abs(0.5f * (1.0f - proj->fRayY/proj->fRayX)); + T = abs(0.5f * (1.0f + proj->fRayY/proj->fRayX)); + lengthPerRow = m_pVolumeGeometry->getPixelLengthX() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayY); + invTminSTimesLengthPerRow = lengthPerRow / (T - S); + } else { + S = abs(0.5f * (1.0f - proj->fRayX/proj->fRayY)); + T = abs(0.5f * (1.0f + proj->fRayX/proj->fRayY)); + lengthPerCol = m_pVolumeGeometry->getPixelLengthY() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayX); + invTminSTimesLengthPerCol = lengthPerCol / (T - S); + } + + // loop detectors + for (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; + + // vertically + if (vertical) { + + // calculate x for row 0 + float32 x = detX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detY); + float32 c = (x - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; + float32 update_c = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX; + + // for each row + for (row = 0; row < m_pVolumeGeometry->getGridRowCount(); ++row, c += update_c) { + + col = int(c+0.5f); + offset = c - float32(col); + + if (col <= 0 || col >= m_pVolumeGeometry->getGridColCount()-1) continue; + + // left + if (offset < -S) { + I = (offset + T) * invTminSTimesLengthPerRow; + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col-1); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); + p.pixelPosterior(iVolumeIndex); + } + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); + } + } + + // right + else if (S < offset) { + I = (offset - S) * invTminSTimesLengthPerRow; + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); + p.pixelPosterior(iVolumeIndex); + } + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col+1); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); + } + } + + // centre + else { + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow); + p.pixelPosterior(iVolumeIndex); + } + } + + } + } + + // horizontally + else { + + // calculate y for col 0 + float32 y = detY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detX); + float32 r = (m_pVolumeGeometry->getWindowMaxY() - y) * inv_pixelLengthY - 0.5f; + float32 update_r = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY; + + // for each col + for (col = 0; col < m_pVolumeGeometry->getGridColCount(); ++col, r += update_r) { + + int row = int(r+0.5f); + float32 offset = r - float32(row); + + if (row <= 0 || row >= m_pVolumeGeometry->getGridRowCount()-1) continue; + + // up + if (offset < -S) { + I = (offset + T) * invTminSTimesLengthPerCol; + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row-1, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); + p.pixelPosterior(iVolumeIndex); + } + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); + } + } + + // down + else if (S < offset) { + I = (offset - S) * invTminSTimesLengthPerCol; + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); + p.pixelPosterior(iVolumeIndex); + } + + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row+1, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); + } + } + + // centre + else { + iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol); + p.pixelPosterior(iVolumeIndex); + } + } + + } + } // end loop col + + // POLICY: RAY POSTERIOR + p.rayPosterior(iRayIndex); + + } // end loop detector + } // end loop angles + +} \ No newline at end of file -- cgit v1.2.3 From 1af118ebea7bffe4eba070dca35127234d39b426 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Fri, 6 Mar 2015 17:19:44 +0100 Subject: 'line' kernel optimizations --- .../astra/ParallelBeamLineKernelProjector2D.inl | 73 +++++++++++++--------- 1 file changed, 43 insertions(+), 30 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 31aa138..69978b0 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -34,22 +34,32 @@ void CParallelBeamLineKernelProjector2D::project(Policy& p) 0, m_pProjectionGeometry->getDetectorCount(), p); } else if (dynamic_cast(m_pProjectionGeometry)) { projectBlock_internal_vector(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); + 0, m_pProjectionGeometry->getDetectorCount(), p); } } template void CParallelBeamLineKernelProjector2D::projectSingleProjection(int _iProjection, Policy& p) { - projectBlock_internal(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); + } } template void CParallelBeamLineKernelProjector2D::projectSingleRay(int _iProjection, int _iDetector, Policy& p) { - projectBlock_internal(_iProjection, _iProjection + 1, + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(_iProjection, _iProjection + 1, + _iDetector, _iDetector + 1, p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(_iProjection, _iProjection + 1, _iDetector, _iDetector + 1, p); + } } @@ -313,6 +323,9 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); + int colCount = m_pVolumeGeometry->getGridColCount(); + int rowCount = m_pVolumeGeometry->getGridRowCount(); + // loop angles for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { @@ -320,15 +333,17 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY); if (vertical) { - S = abs(0.5f * (1.0f - proj->fRayY/proj->fRayX)); - T = abs(0.5f * (1.0f + proj->fRayY/proj->fRayX)); + S = fabs(0.5f * (1.0f - proj->fRayY/proj->fRayX)); + T = fabs(0.5f * (1.0f + proj->fRayY/proj->fRayX)); lengthPerRow = m_pVolumeGeometry->getPixelLengthX() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayY); invTminSTimesLengthPerRow = lengthPerRow / (T - S); + update_c = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX; } else { - S = abs(0.5f * (1.0f - proj->fRayX/proj->fRayY)); - T = abs(0.5f * (1.0f + proj->fRayX/proj->fRayY)); + S = fabs(0.5f * (1.0f - proj->fRayX/proj->fRayY)); + T = fabs(0.5f * (1.0f + proj->fRayX/proj->fRayY)); lengthPerCol = m_pVolumeGeometry->getPixelLengthY() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayX); invTminSTimesLengthPerCol = lengthPerCol / (T - S); + update_r = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY; } // loop detectors @@ -346,30 +361,29 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj if (vertical) { // calculate x for row 0 - float32 x = detX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detY); - float32 c = (x - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; - float32 update_c = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX; + x = detX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detY); + c = (x - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; // for each row - for (row = 0; row < m_pVolumeGeometry->getGridRowCount(); ++row, c += update_c) { + for (row = 0; row < rowCount; ++row, c += update_c) { col = int(c+0.5f); offset = c - float32(col); - if (col <= 0 || col >= m_pVolumeGeometry->getGridColCount()-1) continue; + if (col <= 0 || col >= colCount-1) continue; // left if (offset < -S) { I = (offset + T) * invTminSTimesLengthPerRow; - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col-1); + iVolumeIndex = row * colCount + col - 1; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); p.pixelPosterior(iVolumeIndex); } - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + iVolumeIndex++; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, I); @@ -381,14 +395,14 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj else if (S < offset) { I = (offset - S) * invTminSTimesLengthPerRow; - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + iVolumeIndex = row * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); p.pixelPosterior(iVolumeIndex); } - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col+1); + iVolumeIndex++; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, I); @@ -398,7 +412,7 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj // centre else { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + iVolumeIndex = row * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow); @@ -413,30 +427,29 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj else { // calculate y for col 0 - float32 y = detY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detX); - float32 r = (m_pVolumeGeometry->getWindowMaxY() - y) * inv_pixelLengthY - 0.5f; - float32 update_r = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY; + y = detY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detX); + r = (m_pVolumeGeometry->getWindowMaxY() - y) * inv_pixelLengthY - 0.5f; // for each col - for (col = 0; col < m_pVolumeGeometry->getGridColCount(); ++col, r += update_r) { + for (col = 0; col < colCount; ++col, r += update_r) { int row = int(r+0.5f); - float32 offset = r - float32(row); + offset = r - float32(row); - if (row <= 0 || row >= m_pVolumeGeometry->getGridRowCount()-1) continue; + if (row <= 0 || row >= rowCount-1) continue; // up if (offset < -S) { I = (offset + T) * invTminSTimesLengthPerCol; - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row-1, col); + iVolumeIndex = (row-1) * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); p.pixelPosterior(iVolumeIndex); } - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + iVolumeIndex += colCount; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, I); @@ -448,14 +461,14 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj else if (S < offset) { I = (offset - S) * invTminSTimesLengthPerCol; - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + iVolumeIndex = row * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); p.pixelPosterior(iVolumeIndex); } - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row+1, col); + iVolumeIndex += colCount; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, I); @@ -465,7 +478,7 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj // centre else { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); + iVolumeIndex = row * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol); @@ -474,7 +487,7 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj } } - } // end loop col + } // POLICY: RAY POSTERIOR p.rayPosterior(iRayIndex); -- cgit v1.2.3 From 6f3217fc80380c02e69b363338941a91d721d47c Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Fri, 6 Mar 2015 17:20:02 +0100 Subject: updated 'linear' kernal projector --- .../astra/ParallelBeamLinearKernelProjector2D.h | 4 + .../astra/ParallelBeamLinearKernelProjector2D.inl | 139 ++++++++++++++++++++- 2 files changed, 138 insertions(+), 5 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.h b/include/astra/ParallelBeamLinearKernelProjector2D.h index 855093a..3b84380 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.h +++ b/include/astra/ParallelBeamLinearKernelProjector2D.h @@ -30,6 +30,7 @@ $Id$ #define _INC_ASTRA_PARALLELLINEARKERNELPROJECTOR #include "ParallelProjectionGeometry2D.h" +#include "ParallelVecProjectionGeometry2D.h" #include "Float32Data2D.h" #include "Projector2D.h" @@ -185,6 +186,9 @@ protected: void projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& _policy); + template + void projectBlock_internal_vector(int _iProjFrom, int _iProjTo, + int _iDetFrom, int _iDetTo, Policy& _policy); }; diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index 67e0d58..04577de 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -30,22 +30,37 @@ $Id$ template void CParallelBeamLinearKernelProjector2D::project(Policy& p) { - projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); + } } template void CParallelBeamLinearKernelProjector2D::projectSingleProjection(int _iProjection, Policy& p) { - projectBlock_internal(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); + } } template void CParallelBeamLinearKernelProjector2D::projectSingleRay(int _iProjection, int _iDetector, Policy& p) { - projectBlock_internal(_iProjection, _iProjection + 1, + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(_iProjection, _iProjection + 1, _iDetector, _iDetector + 1, p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(_iProjection, _iProjection + 1, + _iDetector, _iDetector + 1, p); + } } //---------------------------------------------------------------------------------------- @@ -182,3 +197,117 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, } +//---------------------------------------------------------------------------------------- +// PROJECT BLOCK - vector projection geometry +template +void CParallelBeamLinearKernelProjector2D::projectBlock_internal_vector(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) +{ + // variables + float32 detX, detY, x, y, c, r, update_c, update_r, offset; + float32 lengthPerRow, lengthPerCol, inv_pixelLengthX, inv_pixelLengthY; + int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector; + + const SParProjection * proj = 0; + const CParallelVecProjectionGeometry2D* pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + + inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); + inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); + + int colCount = m_pVolumeGeometry->getGridColCount(); + int rowCount = m_pVolumeGeometry->getGridRowCount(); + + // loop angles + for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { + + 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; + } 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; + } + + // loop detectors + for (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; + + // 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; + + // for each row + for (row = 0; row < rowCount; ++row, c += update_c) { + + col = int(c); + 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); + } + + iVolumeIndex++; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, offset * lengthPerRow); + p.pixelPosterior(iVolumeIndex); + } + + } + } + + // 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; + + // for each col + for (col = 0; col < colCount; ++col, r += update_r) { + + int row = int(r); + 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); + } + + iVolumeIndex += colCount; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, offset * lengthPerCol); + p.pixelPosterior(iVolumeIndex); + } + + } + } + + // POLICY: RAY POSTERIOR + p.rayPosterior(iRayIndex); + + } // end loop detector + } // end loop angles +} \ No newline at end of file -- cgit v1.2.3 From 043005e280194ab529bae7863ba50d33f34daa42 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Wed, 11 Mar 2015 14:12:39 +0100 Subject: updated 'strip' kernel projector --- include/astra/ParallelBeamStripKernelProjector2D.h | 7 + .../astra/ParallelBeamStripKernelProjector2D.inl | 197 ++++++++++++++++++++- 2 files changed, 197 insertions(+), 7 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamStripKernelProjector2D.h b/include/astra/ParallelBeamStripKernelProjector2D.h index 624bd3c..c2bb0ed 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.h +++ b/include/astra/ParallelBeamStripKernelProjector2D.h @@ -30,6 +30,7 @@ $Id$ #define _INC_ASTRA_PARALLELBEAMSTROKEKERNELPROJECTOR #include "ParallelProjectionGeometry2D.h" +#include "ParallelVecProjectionGeometry2D.h" #include "Float32Data2D.h" #include "Projector2D.h" @@ -183,6 +184,12 @@ protected: void projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& _policy); + /** Internal policy-based projection of a range of angles and range. + * (_i*From is inclusive, _i*To exclusive) */ + template + void projectBlock_internal_vector(int _iProjFrom, int _iProjTo, + int _iDetFrom, int _iDetTo, Policy& _policy); + }; //---------------------------------------------------------------------------------------- diff --git a/include/astra/ParallelBeamStripKernelProjector2D.inl b/include/astra/ParallelBeamStripKernelProjector2D.inl index 7d73888..684408b 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.inl +++ b/include/astra/ParallelBeamStripKernelProjector2D.inl @@ -29,24 +29,38 @@ $Id$ template void CParallelBeamStripKernelProjector2D::project(Policy& p) { - projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); + } } template void CParallelBeamStripKernelProjector2D::projectSingleProjection(int _iProjection, Policy& p) { - projectBlock_internal(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); + } } template void CParallelBeamStripKernelProjector2D::projectSingleRay(int _iProjection, int _iDetector, Policy& p) { - projectBlock_internal(_iProjection, _iProjection + 1, + if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal(_iProjection, _iProjection + 1, _iDetector, _iDetector + 1, p); + } else if (dynamic_cast(m_pProjectionGeometry)) { + projectBlock_internal_vector(_iProjection, _iProjection + 1, + _iDetector, _iDetector + 1, p); + } } - //---------------------------------------------------------------------------------------- // PROJECT BLOCK template @@ -277,7 +291,7 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, // POLICY: PIXEL POSTERIOR p.pixelPosterior(iVolumeIndex); - x2L -= 1.0f; + x2L -= 1.0f; x2R -= 1.0f; } // end row loop @@ -295,4 +309,173 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, } // end angle loop } +//---------------------------------------------------------------------------------------- +// PROJECT BLOCK - vector projection geometry +template +void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) +{ + // variables + float32 detX, detY, detLX, detLY, detRX, detRY, S, T, update_c, update_r, offsetL, offsetR, invTminS; + float32 lengthPerRow, lengthPerCol, inv_pixelLengthX, inv_pixelLengthY, pixelArea; + int iVolumeIndex, iRayIndex, iRayIndexL, iRayIndexR, row, row_top, row_bottom, col, col_left, col_right, iAngle, iDetector, colCount, rowCount; + + const SParProjection * proj = 0; + const CParallelVecProjectionGeometry2D* pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + + inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); + inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); + pixelArea = m_pVolumeGeometry->getPixelLengthX() * m_pVolumeGeometry->getPixelLengthY(); + + colCount = m_pVolumeGeometry->getGridColCount(); + rowCount = m_pVolumeGeometry->getGridRowCount(); + + // loop angles + for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { + + proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; + + bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY); + if (vertical) { + S = 0.5f - 0.5f*fabs(proj->fRayX/proj->fRayY); + T = 0.5f + 0.5f*fabs(proj->fRayX/proj->fRayY); + update_c = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX; + invTminS = 1.0f / (T-S); + } else { + S = 0.5f - 0.5f*fabs(proj->fRayY/proj->fRayX); + T = 0.5f + 0.5f*fabs(proj->fRayY/proj->fRayX); + update_r = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY; + invTminS = 1.0f / (T-S); + } + + // loop detectors + for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { + + iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; + + // POLICY: RAY PRIOR + if (!p.rayPrior(iRayIndex)) continue; + + detLX = proj->fDetSX + (iDetector+0.0f) * proj->fDetUX; + detLY = proj->fDetSY + (iDetector+0.0f) * proj->fDetUY; + detRX = detLX + proj->fDetUX; + detRY = detLY + proj->fDetUY; + + // vertically + if (vertical) { + + // calculate cL and cR for row 0 + float32 xL = detLX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detLY); + float32 cL = (xL - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; + float32 xR = detRX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detRY); + float32 cR = (xR - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; + + if (cR < cL) { + float32 tmp = cL; + cL = cR; + cR = tmp; + } + + // for each row + for (row = 0; row < rowCount; ++row, cL += update_c, cR += update_c) { + + col_left = int(cL-0.5f+S); + col_right = int(cR+1.5-S); + + if (col_left < 0) col_left = 0; + if (col_right > colCount-1) col_right = colCount-1; + + // for each column + for (col = col_left; col <= col_right; ++col) { + iVolumeIndex = row * colCount + col; + + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + + offsetL = cL - float32(col); + offsetR = cR - float32(col); + + // right ray edge + float32 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; + + // left ray edge + 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); + } + } + } + } + + // horizontally + else { + + // calculate rL and rR for row 0 + float32 yL = detLY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detLX); + float32 rL = (m_pVolumeGeometry->getWindowMaxY() - yL) * inv_pixelLengthY - 0.5f; + float32 yR = detRY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detRX); + float32 rR = (m_pVolumeGeometry->getWindowMaxY() - yR) * inv_pixelLengthY - 0.5f; + + if (rR < rL) { + float32 tmp = rL; + rL = rR; + rR = tmp; + } + + // for each column + for (col = 0; col < colCount; ++col, rL += update_r, rR += update_r) { + + row_top = int(rL-0.5f+S); + row_bottom = int(rR+1.5-S); + + if (row_top < 0) row_top = 0; + if (row_bottom > rowCount-1) row_bottom = rowCount-1; + + // for each row + for (row = row_top; row <= row_bottom; ++row) { + + iVolumeIndex = row * colCount + col; + + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + + offsetL = rL - float32(row); + offsetR = rR - float32(row); + + // right ray edge + float32 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; + + // left ray edge + 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); + } + } + } + } + + // POLICY: RAY POSTERIOR + p.rayPosterior(iRayIndex); + + } // end loop detector + } // end loop angles + +} -- cgit v1.2.3 From 2c1999b1bbfb7ef2ca1ae22b43e2a0ab8108073f Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Thu, 12 Mar 2015 11:40:56 +0100 Subject: parallel projectors now always use vector geometries internally --- include/astra/ParallelBeamLineKernelProjector2D.h | 5 - .../astra/ParallelBeamLineKernelProjector2D.inl | 302 ++---------------- .../astra/ParallelBeamLinearKernelProjector2D.h | 4 - .../astra/ParallelBeamLinearKernelProjector2D.inl | 181 ++--------- include/astra/ParallelBeamStripKernelProjector2D.h | 6 - .../astra/ParallelBeamStripKernelProjector2D.inl | 343 +++------------------ include/astra/ParallelProjectionGeometry2D.h | 10 +- 7 files changed, 99 insertions(+), 752 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLineKernelProjector2D.h b/include/astra/ParallelBeamLineKernelProjector2D.h index dd5eab2..5a10021 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.h +++ b/include/astra/ParallelBeamLineKernelProjector2D.h @@ -182,11 +182,6 @@ protected: void projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& _policy); - /** Internal policy-based projection of a range of angles and range. - * (_i*From is inclusive, _i*To exclusive) */ - template - void projectBlock_internal_vector(int _iProjFrom, int _iProjTo, - int _iDetFrom, int _iDetTo, Policy& _policy); }; inline std::string CParallelBeamLineKernelProjector2D::getType() diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 69978b0..dc3153d 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -29,302 +29,52 @@ $Id$ template void CParallelBeamLineKernelProjector2D::project(Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); - } + projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); } template void CParallelBeamLineKernelProjector2D::projectSingleProjection(int _iProjection, Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); - } + projectBlock_internal(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); } template void CParallelBeamLineKernelProjector2D::projectSingleRay(int _iProjection, int _iDetector, Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(_iProjection, _iProjection + 1, - _iDetector, _iDetector + 1, p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(_iProjection, _iProjection + 1, + projectBlock_internal(_iProjection, _iProjection + 1, _iDetector, _iDetector + 1, p); - } } -//---------------------------------------------------------------------------------------- -// PROJECT BLOCK - default projection geometry -template -void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) -{ - // variables - float32 theta, sin_theta, cos_theta, inv_sin_theta, inv_cos_theta, S, T, t, I, P, x, x2; - float32 lengthPerRow, updatePerRow, inv_pixelLengthX, lengthPerCol, updatePerCol, inv_pixelLengthY; - int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector, x1; - bool switch_t; - - float32 old_theta; - const SParProjection * proj = 0; - - const CParallelProjectionGeometry2D* pProjectionGeometry = dynamic_cast(m_pProjectionGeometry); - - // loop angles - for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { - - // get theta - theta = m_pProjectionGeometry->getProjectionAngle(iAngle); - switch_t = false; - if (theta >= 7*PIdiv4) theta -= 2*PI; - if (theta >= 3*PIdiv4) { - theta -= PI; - switch_t = true; - } - - // precalculate sin, cos, 1/cos - sin_theta = sin(theta); - cos_theta = cos(theta); - inv_sin_theta = 1.0f / sin_theta; - inv_cos_theta = 1.0f / cos_theta; - - // precalculate kernel limits - lengthPerRow = m_pVolumeGeometry->getPixelLengthY() * inv_cos_theta; - updatePerRow = sin_theta * inv_cos_theta; - inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); - - // precalculate kernel limits - lengthPerCol = m_pVolumeGeometry->getPixelLengthX() * inv_sin_theta; - updatePerCol = cos_theta * inv_sin_theta; - inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); - - // precalculate S and T - S = 0.5f - 0.5f * ((updatePerRow < 0) ? -updatePerRow : updatePerRow); - T = 0.5f - 0.5f * ((updatePerCol < 0) ? -updatePerCol : updatePerCol); - - // loop detectors - for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - - iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; - - // POLICY: RAY PRIOR - if (!p.rayPrior(iRayIndex)) continue; - - // get t - t = m_pProjectionGeometry->indexToDetectorOffset(iDetector); - if (switch_t) t = -t; - - // vertically - if (theta <= PIdiv4) { - - // calculate x for row 0 - P = (t - sin_theta * m_pVolumeGeometry->pixelRowToCenterY(0)) * inv_cos_theta; - x = (P - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX; - - // get coords - int nextx1 = int((x > 0.0f) ? x : x-1.0f); - float nextx2 = x - nextx1; - - // for each row - for (row = 0; row < m_pVolumeGeometry->getGridRowCount(); ++row) { - - x1 = nextx1; - x2 = nextx2; - nextx2 += updatePerRow; - while (nextx2 >= 1.0f) { - nextx2 -= 1.0f; - nextx1++; - } - while (nextx2 < 0.0f) { - nextx2 += 1.0f; - nextx1--; - } - - if (x1 < -1 || x1 > m_pVolumeGeometry->getGridColCount()) continue; - - // left - if (x2 < 0.5f-S) { - I = (0.5f - S + x2) / (1.0f - 2.0f*S) * lengthPerRow; - - if (x1-1 >= 0 && x1-1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1-1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); - p.pixelPosterior(iVolumeIndex); - } - } - - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } - } - } - - // center - else if (x2 <= 0.5f+S) { - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow); - p.pixelPosterior(iVolumeIndex); - } - } - } - - // right - else { - I = (1.5f - S - x2) / (1.0f - 2.0f*S) * lengthPerRow; - - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } - } - if (x1+1 >= 0 && x1+1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1+1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); - p.pixelPosterior(iVolumeIndex); - } - } - } - } - } - - // horizontally - else if (PIdiv4 <= theta && theta <= 3*PIdiv4) { - - // calculate point P - P = (t - cos_theta * m_pVolumeGeometry->pixelColToCenterX(0)) * inv_sin_theta; - x = (m_pVolumeGeometry->getWindowMaxY() - P) * inv_pixelLengthY; - - // get coords - int nextx1 = int((x > 0.0f) ? x : x-1.0f); - float nextx2 = x - nextx1; - - // for each col - for (col = 0; col < m_pVolumeGeometry->getGridColCount(); ++col) { - - x1 = nextx1; - x2 = nextx2; - - nextx2 += updatePerCol; - while (nextx2 >= 1.0f) { - nextx2 -= 1.0f; - nextx1++; - } - while (nextx2 < 0.0f) { - nextx2 += 1.0f; - nextx1--; - } - - if (x1 < -1 || x1 > m_pVolumeGeometry->getGridRowCount()) continue; - - // up - if (x2 < 0.5f-T) { - I = (0.5f - T + x2) / (1.0f - 2.0f*T) * lengthPerCol; - - if (x1-1 >= 0 && x1-1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1-1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); - p.pixelPosterior(iVolumeIndex); - } - } - - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } - } - } - - // center - else if (x2 <= 0.5f+T) { - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol); - p.pixelPosterior(iVolumeIndex); - } - } - } - - // down - else { - I = (1.5f - T - x2) / (1.0f - 2.0f*T) * lengthPerCol; - - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } - } - if (x1+1 >= 0 && x1+1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1+1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); - p.pixelPosterior(iVolumeIndex); - } - } - } - } - } // end loop col - - // POLICY: RAY POSTERIOR - p.rayPosterior(iRayIndex); - - } // end loop detector - } // end loop angles - -} //---------------------------------------------------------------------------------------- // PROJECT BLOCK - vector projection geometry template -void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) +void CParallelBeamLineKernelProjector2D::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; - + int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector, colCount, rowCount, detCount; const SParProjection * proj = 0; - const CParallelVecProjectionGeometry2D* pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + // get vector geometry + const CParallelVecProjectionGeometry2D* pVecProjectionGeometry; + if (dynamic_cast(m_pProjectionGeometry)) { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry)->toVectorGeometry(); + } else { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + } + + // precomputations inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); - - int colCount = m_pVolumeGeometry->getGridColCount(); - int rowCount = m_pVolumeGeometry->getGridRowCount(); + colCount = m_pVolumeGeometry->getGridColCount(); + rowCount = m_pVolumeGeometry->getGridRowCount(); + detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { @@ -333,17 +83,17 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY); if (vertical) { - S = fabs(0.5f * (1.0f - proj->fRayY/proj->fRayX)); - T = fabs(0.5f * (1.0f + proj->fRayY/proj->fRayX)); lengthPerRow = m_pVolumeGeometry->getPixelLengthX() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayY); - invTminSTimesLengthPerRow = lengthPerRow / (T - S); 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); + invTminSTimesLengthPerRow = lengthPerRow / (T - S); } else { - S = fabs(0.5f * (1.0f - proj->fRayX/proj->fRayY)); - T = fabs(0.5f * (1.0f + proj->fRayX/proj->fRayY)); lengthPerCol = m_pVolumeGeometry->getPixelLengthY() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayX); - invTminSTimesLengthPerCol = lengthPerCol / (T - S); 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); + invTminSTimesLengthPerCol = lengthPerCol / (T - S); } // loop detectors @@ -495,4 +245,4 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal_vector(int _iProj } // end loop detector } // end loop angles -} \ No newline at end of file +} diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.h b/include/astra/ParallelBeamLinearKernelProjector2D.h index 3b84380..8e25c38 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.h +++ b/include/astra/ParallelBeamLinearKernelProjector2D.h @@ -186,10 +186,6 @@ protected: void projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& _policy); - template - void projectBlock_internal_vector(int _iProjFrom, int _iProjTo, - int _iDetFrom, int _iDetTo, Policy& _policy); - }; //---------------------------------------------------------------------------------------- diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index 04577de..9f898ce 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -26,195 +26,54 @@ along with the ASTRA Toolbox. If not, see . $Id$ */ - template void CParallelBeamLinearKernelProjector2D::project(Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); - } + projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); } template void CParallelBeamLinearKernelProjector2D::projectSingleProjection(int _iProjection, Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); - } + projectBlock_internal(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); } template void CParallelBeamLinearKernelProjector2D::projectSingleRay(int _iProjection, int _iDetector, Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(_iProjection, _iProjection + 1, - _iDetector, _iDetector + 1, p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(_iProjection, _iProjection + 1, + projectBlock_internal(_iProjection, _iProjection + 1, _iDetector, _iDetector + 1, p); - } } -//---------------------------------------------------------------------------------------- -// PROJECT BLOCK -template -void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) -{ - // variables - float32 theta, sin_theta, cos_theta, inv_sin_theta, inv_cos_theta, t; - float32 lengthPerRow, updatePerRow, inv_pixelLengthX; - float32 lengthPerCol, updatePerCol, inv_pixelLengthY; - bool switch_t; - int iAngle, iDetector, iVolumeIndex, iRayIndex; - int row, col, x1; - float32 P,x,x2; - // loop angles - for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { - - // get theta - theta = m_pProjectionGeometry->getProjectionAngle(iAngle); - switch_t = false; - if (theta >= 7*PIdiv4) theta -= 2*PI; - if (theta >= 3*PIdiv4) { - theta -= PI; - switch_t = true; - } - - // precalculate sin, cos, 1/cos - sin_theta = sin(theta); - cos_theta = cos(theta); - inv_cos_theta = 1.0f / cos_theta; - inv_sin_theta = 1.0f / sin_theta; - - // precalculate kernel limits - lengthPerRow = m_pVolumeGeometry->getPixelLengthY() * inv_cos_theta; - updatePerRow = sin_theta * inv_cos_theta; - inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); - - // precalculate kernel limits - lengthPerCol = m_pVolumeGeometry->getPixelLengthX() * inv_sin_theta; - updatePerCol = cos_theta * inv_sin_theta; - inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); - - // loop detectors - for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - - iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; - - // POLICY: RAY PRIOR - if (!p.rayPrior(iRayIndex)) continue; - - // get t - t = m_pProjectionGeometry->indexToDetectorOffset(iDetector); - if (switch_t) { - t = -t; - } - - // vertically - if (theta <= PIdiv4) { - - // calculate x for row 0 - P = (t - sin_theta * m_pVolumeGeometry->pixelRowToCenterY(0)) * inv_cos_theta; - x = m_pVolumeGeometry->coordXToColF(P) - 0.5f; - - // for each row - for (row = 0; row < m_pVolumeGeometry->getGridRowCount(); ++row) { - - // get coords - x1 = int((x > 0.0f) ? x : x-1.0f); - x2 = x - x1; - x += updatePerRow; - - // add weights - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, (1.0f - x2) * lengthPerRow); - p.pixelPosterior(iVolumeIndex); - } - } - if (x1+1 >= 0 && x1+1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1+1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, (x2) * lengthPerRow); - p.pixelPosterior(iVolumeIndex); - } - } - } - } - - // horizontally - else if (PIdiv4 <= theta && theta <= 3*PIdiv4) { - - // calculate point P - P = (t - cos_theta * m_pVolumeGeometry->pixelColToCenterX(0)) * inv_sin_theta; - x = m_pVolumeGeometry->coordYToRowF(P) - 0.5f; - - // for each row - for (col = 0; col < m_pVolumeGeometry->getGridColCount(); ++col) { - - // get coords - x1 = int((x > 0.0f) ? x : x-1.0f); - x2 = x - x1; - x += updatePerCol; - - // add weights - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, (1.0f - x2) * lengthPerCol); - p.pixelPosterior(iVolumeIndex); - } - } - if (x1+1 >= 0 && x1+1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1+1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, x2 * lengthPerCol); - p.pixelPosterior(iVolumeIndex); - } - } - } - } - - // POLICY: RAY POSTERIOR - p.rayPosterior(iRayIndex); - - } // end loop detector - } // end loop angles - -} //---------------------------------------------------------------------------------------- // PROJECT BLOCK - vector projection geometry template -void CParallelBeamLinearKernelProjector2D::projectBlock_internal_vector(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) +void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { // variables float32 detX, detY, x, y, c, r, update_c, update_r, offset; float32 lengthPerRow, lengthPerCol, inv_pixelLengthX, inv_pixelLengthY; - int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector; - + int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector, colCount, rowCount, detCount; const SParProjection * proj = 0; - const CParallelVecProjectionGeometry2D* pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + // get vector geometry + const CParallelVecProjectionGeometry2D* pVecProjectionGeometry; + if (dynamic_cast(m_pProjectionGeometry)) { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry)->toVectorGeometry(); + } else { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + } + + // precomputations inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); - - int colCount = m_pVolumeGeometry->getGridColCount(); - int rowCount = m_pVolumeGeometry->getGridRowCount(); + colCount = m_pVolumeGeometry->getGridColCount(); + rowCount = m_pVolumeGeometry->getGridRowCount(); + detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { @@ -310,4 +169,4 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal_vector(int _iPr } // end loop detector } // end loop angles -} \ No newline at end of file +} diff --git a/include/astra/ParallelBeamStripKernelProjector2D.h b/include/astra/ParallelBeamStripKernelProjector2D.h index c2bb0ed..8fb665f 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.h +++ b/include/astra/ParallelBeamStripKernelProjector2D.h @@ -184,12 +184,6 @@ protected: void projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& _policy); - /** Internal policy-based projection of a range of angles and range. - * (_i*From is inclusive, _i*To exclusive) */ - template - void projectBlock_internal_vector(int _iProjFrom, int _iProjTo, - int _iDetFrom, int _iDetTo, Policy& _policy); - }; //---------------------------------------------------------------------------------------- diff --git a/include/astra/ParallelBeamStripKernelProjector2D.inl b/include/astra/ParallelBeamStripKernelProjector2D.inl index 684408b..31d222a 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.inl +++ b/include/astra/ParallelBeamStripKernelProjector2D.inl @@ -29,305 +29,51 @@ $Id$ template void CParallelBeamStripKernelProjector2D::project(Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(0, m_pProjectionGeometry->getProjectionAngleCount(), - 0, m_pProjectionGeometry->getDetectorCount(), p); - } + projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); } template void CParallelBeamStripKernelProjector2D::projectSingleProjection(int _iProjection, Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(_iProjection, _iProjection + 1, - 0, m_pProjectionGeometry->getDetectorCount(), p); - } + projectBlock_internal(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); } template void CParallelBeamStripKernelProjector2D::projectSingleRay(int _iProjection, int _iDetector, Policy& p) { - if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal(_iProjection, _iProjection + 1, - _iDetector, _iDetector + 1, p); - } else if (dynamic_cast(m_pProjectionGeometry)) { - projectBlock_internal_vector(_iProjection, _iProjection + 1, + projectBlock_internal(_iProjection, _iProjection + 1, _iDetector, _iDetector + 1, p); - } } + //---------------------------------------------------------------------------------------- // PROJECT BLOCK template void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) -{ - ASTRA_ASSERT(m_bIsInitialized); - - // Some variables - float32 theta, t; - int row, col; - int iAngle; - int iDetector; - float32 res; - float32 PL, PLimitL, PLimitR; - float32 xL, xR, XLimitL, XLimitR; - int x1L,x1R; - float32 x2L, x2R, updateX; - int iVolumeIndex, iRayIndex; - - float32 sin_theta, cos_theta, inv_sin_theta, inv_cos_theta; - float32 fabs_sin_theta, fabs_cos_theta, fabs_inv_sin_theta, fabs_inv_cos_theta; - float32 PW, PH, DW, inv_PW, inv_PH; - float32 S, T, U, V, inv_4T; - - // loop angles - for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { - - // get values - theta = m_pProjectionGeometry->getProjectionAngle(iAngle); - bool switch_t = false; - if (theta >= 7*PIdiv4) theta -= 2*PI; - if (theta >= 3*PIdiv4) { - theta -= PI; - switch_t = true; - } - - // Precalculate sin, cos, 1/cos - sin_theta = sin(theta); - cos_theta = cos(theta); - inv_cos_theta = 1.0f / cos_theta; - inv_sin_theta = 1.0f / sin_theta; - - fabs_sin_theta = (sin_theta < 0.0f) ? -sin_theta : sin_theta; - fabs_cos_theta = (cos_theta < 0.0f) ? -cos_theta : cos_theta; - fabs_inv_cos_theta = (inv_cos_theta < 0.0f) ? -inv_cos_theta : inv_cos_theta; - fabs_inv_sin_theta = (inv_sin_theta < 0.0f) ? -inv_sin_theta : inv_sin_theta; - - // Other precalculations - PW = m_pVolumeGeometry->getPixelLengthX(); - PH = m_pVolumeGeometry->getPixelLengthY(); - DW = m_pProjectionGeometry->getDetectorWidth(); - inv_PW = 1.0f / PW; - inv_PH = 1.0f / PH; - - // [-45?,45?] and [135?,225?] - if (theta < PIdiv4) { - - // Precalculate kernel limits - S = -0.5f * fabs_sin_theta * fabs_inv_cos_theta; - T = -S; - U = 1.0f + S; - V = 1.0f - S; - inv_4T = 0.25f / T; - - updateX = sin_theta * inv_cos_theta; - - // loop detectors - for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - - iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; - - // POLICY: RAY PRIOR - if (!p.rayPrior(iRayIndex)) continue; - - // get t - t = m_pProjectionGeometry->indexToDetectorOffset(iDetector); - if (switch_t) t = -t; - - // calculate left strip extremes (volume coordinates) - PL = (t - sin_theta * m_pVolumeGeometry->pixelRowToCenterY(0) - DW*0.5f) * inv_cos_theta; - PLimitL = PL - 0.5f * fabs_sin_theta * fabs_inv_cos_theta * PH; - PLimitR = PLimitL + DW * inv_cos_theta + PH * fabs_sin_theta * fabs_inv_cos_theta; - - // calculate strip extremes (pixel coordinates) - XLimitL = (PLimitL - m_pVolumeGeometry->getWindowMinX()) * inv_PW; - XLimitR = (PLimitR - m_pVolumeGeometry->getWindowMinX()) * inv_PW; - xL = (PL - m_pVolumeGeometry->getWindowMinX()) * inv_PW; - xR = xL + (DW * inv_cos_theta) * inv_PW; - - // for each row - for (row = 0; row < m_pVolumeGeometry->getGridRowCount(); ++row) { - - // get strip extremes in column indices - x1L = int((XLimitL > 0.0f) ? XLimitL : XLimitL-1.0f); - x1R = int((XLimitR > 0.0f) ? XLimitR : XLimitR-1.0f); - - // get coords w.r.t leftmost column hit by strip - x2L = xL - x1L; - x2R = xR - x1L; - - // update strip extremes for the next row - XLimitL += updateX; - XLimitR += updateX; - xL += updateX; - xR += updateX; - - // for each affected col - for (col = x1L; col <= x1R; ++col) { - - if (col < 0 || col >= m_pVolumeGeometry->getGridColCount()) { x2L -= 1.0f; x2R -= 1.0f; continue; } - - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); - // POLICY: PIXEL PRIOR - if (!p.pixelPrior(iVolumeIndex)) { x2L -= 1.0f; x2R -= 1.0f; continue; } - - // right - if (x2R >= V) res = 1.0f; - else if (x2R > U) res = x2R - (x2R-U)*(x2R-U)*inv_4T; - else if (x2R >= T) res = x2R; - else if (x2R > S) res = (x2R-S)*(x2R-S) * inv_4T; - else { x2L -= 1.0f; x2R -= 1.0f; continue; } - - // left - if (x2L <= S) {} // - 0.0f - else if (x2L < T) res -= (x2L-S)*(x2L-S) * inv_4T; - else if (x2L <= U) res -= x2L; - else if (x2L < V) res -= x2L - (x2L-U)*(x2L-U)*inv_4T; - else { x2L -= 1.0f; x2R -= 1.0f; continue; } - - // POLICY: ADD - p.addWeight(iRayIndex, iVolumeIndex, PW*PH * res); - - // POLICY: PIXEL POSTERIOR - p.pixelPosterior(iVolumeIndex); - - x2L -= 1.0f; - x2R -= 1.0f; - - } // end col loop - - } // end row loop - - // POLICY: RAY POSTERIOR - p.rayPosterior(iRayIndex); - - } // end detector loop - - // [45?,135?] and [225?,315?] - // horizontaly - } else { - - // Precalculate kernel limits - S = -0.5f * fabs_cos_theta * fabs_inv_sin_theta; - T = -S; - U = 1.0f + S; - V = 1.0f - S; - inv_4T = 0.25f / T; - - updateX = cos_theta * inv_sin_theta; - - // loop detectors - for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - - iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; - - // POLICY: RAY PRIOR - if (!p.rayPrior(iRayIndex)) continue; - - // get t - t = m_pProjectionGeometry->indexToDetectorOffset(iDetector); - if (switch_t) t = -t; - - // calculate left strip extremes (volume coordinates) - PL = (t - cos_theta * m_pVolumeGeometry->pixelColToCenterX(0) + DW*0.5f) * inv_sin_theta; - PLimitL = PL + 0.5f * fabs_cos_theta * fabs_inv_sin_theta * PW; - PLimitR = PLimitL - DW * inv_sin_theta - PH * fabs_cos_theta * fabs_inv_sin_theta; - - // calculate strip extremes (pixel coordinates) - XLimitL = (m_pVolumeGeometry->getWindowMaxY() - PLimitL) * inv_PH; - XLimitR = (m_pVolumeGeometry->getWindowMaxY() - PLimitR) * inv_PH; - xL = (m_pVolumeGeometry->getWindowMaxY() - PL) * inv_PH; - xR = xL + (DW * fabs_inv_sin_theta) * inv_PH; - - // for each col - for (col = 0; col < m_pVolumeGeometry->getGridColCount(); ++col) { - - // get strip extremes in column indices - x1L = int((XLimitL > 0.0f) ? XLimitL : XLimitL-1.0f); - x1R = int((XLimitR > 0.0f) ? XLimitR : XLimitR-1.0f); - - // get coords w.r.t leftmost column hit by strip - x2L = xL - x1L; - x2R = xR - x1L; - - // update strip extremes for the next row - XLimitL += updateX; - XLimitR += updateX; - xL += updateX; - xR += updateX; - - // for each affected col - for (row = x1L; row <= x1R; ++row) { - - if (row < 0 || row >= m_pVolumeGeometry->getGridRowCount()) { x2L -= 1.0f; x2R -= 1.0f; continue; } - - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); - - // POLICY: PIXEL PRIOR - if (!p.pixelPrior(iVolumeIndex)) { x2L -= 1.0f; x2R -= 1.0f; continue; } - - // right - if (x2R >= V) res = 1.0f; - else if (x2R > U) res = x2R - (x2R-U)*(x2R-U)*inv_4T; - else if (x2R >= T) res = x2R; - else if (x2R > S) res = (x2R-S)*(x2R-S) * inv_4T; - else { x2L -= 1.0f; x2R -= 1.0f; continue; } - - // left - if (x2L <= S) {} // - 0.0f - else if (x2L < T) res -= (x2L-S)*(x2L-S) * inv_4T; - else if (x2L <= U) res -= x2L; - else if (x2L < V) res -= x2L - (x2L-U)*(x2L-U)*inv_4T; - else { x2L -= 1.0f; x2R -= 1.0f; continue; } - - // POLICY: ADD - p.addWeight(iRayIndex, iVolumeIndex, PW*PH * res); - - // POLICY: PIXEL POSTERIOR - p.pixelPosterior(iVolumeIndex); - - x2L -= 1.0f; - x2R -= 1.0f; - - } // end row loop - - } // end col loop - - // POLICY: RAY POSTERIOR - p.rayPosterior(iRayIndex); - - } // end detector loop - - - } // end theta switch - - } // end angle loop -} - -//---------------------------------------------------------------------------------------- -// PROJECT BLOCK - vector projection geometry -template -void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { // variables - float32 detX, detY, detLX, detLY, detRX, detRY, S, T, update_c, update_r, offsetL, offsetR, invTminS; - float32 lengthPerRow, lengthPerCol, inv_pixelLengthX, inv_pixelLengthY, pixelArea; - int iVolumeIndex, iRayIndex, iRayIndexL, iRayIndexR, row, row_top, row_bottom, col, col_left, col_right, iAngle, iDetector, colCount, rowCount; - + float32 detLX, detLY, detRX, detRY, S, T, update_c, update_r, offsetL, offsetR, invTminS; + float32 inv_pixelLengthX, inv_pixelLengthY, pixelArea, res, fRxOverRy, fRyOverRx; + int iVolumeIndex, iRayIndex, iAngle, iDetector; + int row, row_top, row_bottom, col, col_left, col_right, colCount, rowCount, detCount; const SParProjection * proj = 0; - const CParallelVecProjectionGeometry2D* pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + + // get vector geometry + const CParallelVecProjectionGeometry2D* pVecProjectionGeometry; + if (dynamic_cast(m_pProjectionGeometry)) { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry)->toVectorGeometry(); + } else { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + } + // precomputations inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); pixelArea = m_pVolumeGeometry->getPixelLengthX() * m_pVolumeGeometry->getPixelLengthY(); - colCount = m_pVolumeGeometry->getGridColCount(); rowCount = m_pVolumeGeometry->getGridRowCount(); + detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { @@ -336,27 +82,29 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iPro bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY); if (vertical) { - S = 0.5f - 0.5f*fabs(proj->fRayX/proj->fRayY); - T = 0.5f + 0.5f*fabs(proj->fRayX/proj->fRayY); - update_c = -m_pVolumeGeometry->getPixelLengthY() * (proj->fRayX/proj->fRayY) * inv_pixelLengthX; + 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); invTminS = 1.0f / (T-S); } else { - S = 0.5f - 0.5f*fabs(proj->fRayY/proj->fRayX); - T = 0.5f + 0.5f*fabs(proj->fRayY/proj->fRayX); - update_r = -m_pVolumeGeometry->getPixelLengthX() * (proj->fRayY/proj->fRayX) * inv_pixelLengthY; + 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); invTminS = 1.0f / (T-S); } // loop detectors for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; + iRayIndex = iAngle * detCount + iDetector; // POLICY: RAY PRIOR if (!p.rayPrior(iRayIndex)) continue; - detLX = proj->fDetSX + (iDetector+0.0f) * proj->fDetUX; - detLY = proj->fDetSY + (iDetector+0.0f) * proj->fDetUY; + detLX = proj->fDetSX + iDetector * proj->fDetUX; + detLY = proj->fDetSY + iDetector * proj->fDetUY; detRX = detLX + proj->fDetUX; detRY = detLY + proj->fDetUY; @@ -364,9 +112,9 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iPro if (vertical) { // calculate cL and cR for row 0 - float32 xL = detLX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detLY); + float32 xL = detLX + fRxOverRy*(m_pVolumeGeometry->pixelRowToCenterY(0)-detLY); float32 cL = (xL - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; - float32 xR = detRX + (proj->fRayX/proj->fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detRY); + float32 xR = detRX + fRxOverRy*(m_pVolumeGeometry->pixelRowToCenterY(0)-detRY); float32 cR = (xR - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; if (cR < cL) { @@ -384,23 +132,23 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iPro 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); + // for each column - for (col = col_left; col <= col_right; ++col) { + 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)) { - offsetL = cL - float32(col); - offsetR = cR - float32(col); - // right ray edge - float32 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; @@ -408,7 +156,6 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iPro 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); } @@ -420,9 +167,9 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iPro else { // calculate rL and rR for row 0 - float32 yL = detLY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detLX); + float32 yL = detLY + fRyOverRx*(m_pVolumeGeometry->pixelColToCenterX(0)-detLX); float32 rL = (m_pVolumeGeometry->getWindowMaxY() - yL) * inv_pixelLengthY - 0.5f; - float32 yR = detRY + (proj->fRayY/proj->fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detRX); + float32 yR = detRY + fRyOverRx*(m_pVolumeGeometry->pixelColToCenterX(0)-detRX); float32 rR = (m_pVolumeGeometry->getWindowMaxY() - yR) * inv_pixelLengthY - 0.5f; if (rR < rL) { @@ -440,23 +187,23 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal_vector(int _iPro 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); + // for each row - for (row = row_top; row <= row_bottom; ++row) { + 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)) { - offsetL = rL - float32(row); - offsetR = rR - float32(row); - // right ray edge - float32 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; diff --git a/include/astra/ParallelProjectionGeometry2D.h b/include/astra/ParallelProjectionGeometry2D.h index 2f7d36f..36b4b6f 100644 --- a/include/astra/ParallelProjectionGeometry2D.h +++ b/include/astra/ParallelProjectionGeometry2D.h @@ -30,6 +30,7 @@ $Id$ #define _INC_ASTRA_PARALLELPROJECTIONGEOMETRY2D #include "ProjectionGeometry2D.h" +#include "ParallelVecProjectionGeometry2D.h" namespace astra { @@ -134,7 +135,7 @@ public: * @param _sType geometry type to compare to. * @return true if _sType == "parallel". */ - virtual bool isOfType(const std::string& _sType); + virtual bool isOfType(const std::string& _sType); /** Get all settings in a Config object. * @@ -151,7 +152,12 @@ public: * * @return a unit vector describing the direction */ - virtual CVector3D getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex = 0); + virtual CVector3D getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex = 0); + + /** Create a vector geom + */ + CParallelVecProjectionGeometry2D* toVectorGeometry(); + }; } // namespace astra -- cgit v1.2.3 From 424c97dcdcf4604ffcf6dd0d3a5cda93e332c7e4 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Thu, 12 Mar 2015 11:41:11 +0100 Subject: updated 'blob' kernel projector --- include/astra/ParallelBeamBlobKernelProjector2D.h | 7 +- .../astra/ParallelBeamBlobKernelProjector2D.inl | 267 +++++++++------------ 2 files changed, 122 insertions(+), 152 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamBlobKernelProjector2D.h b/include/astra/ParallelBeamBlobKernelProjector2D.h index ecf71ef..a718f56 100644 --- a/include/astra/ParallelBeamBlobKernelProjector2D.h +++ b/include/astra/ParallelBeamBlobKernelProjector2D.h @@ -215,7 +215,12 @@ protected: float32 m_fBlobSampleRate; //< At which interval are the inserted blob values evaluated? int m_iBlobSampleCount; //< Number of evaluated blob samples float32* m_pfBlobValues; //< Evaluated blob values - float32* m_pfBlobValuesNeg; //< Evaluated blob values + + /** Internal policy-based projection of a range of angles and range. + * (_i*From is inclusive, _i*To exclusive) */ + template + void projectBlock_internal(int _iProjFrom, int _iProjTo, + int _iDetFrom, int _iDetTo, Policy& _policy); }; diff --git a/include/astra/ParallelBeamBlobKernelProjector2D.inl b/include/astra/ParallelBeamBlobKernelProjector2D.inl index 467e066..203eb51 100644 --- a/include/astra/ParallelBeamBlobKernelProjector2D.inl +++ b/include/astra/ParallelBeamBlobKernelProjector2D.inl @@ -27,186 +27,151 @@ $Id$ */ - -//---------------------------------------------------------------------------------------- -// PROJECT ALL template void CParallelBeamBlobKernelProjector2D::project(Policy& p) { - for (int iAngle = 0; iAngle < m_pProjectionGeometry->getProjectionAngleCount(); ++iAngle) { - for (int iDetector = 0; iDetector < m_pProjectionGeometry->getDetectorCount(); ++iDetector) { - projectSingleRay(iAngle, iDetector, p); - } - } + projectBlock_internal(0, m_pProjectionGeometry->getProjectionAngleCount(), + 0, m_pProjectionGeometry->getDetectorCount(), p); } - -//---------------------------------------------------------------------------------------- -// PROJECT SINGLE PROJECTION template void CParallelBeamBlobKernelProjector2D::projectSingleProjection(int _iProjection, Policy& p) { - for (int iDetector = 0; iDetector < m_pProjectionGeometry->getDetectorCount(); ++iDetector) { - projectSingleRay(_iProjection, iDetector, p); - } + projectBlock_internal(_iProjection, _iProjection + 1, + 0, m_pProjectionGeometry->getDetectorCount(), p); } - - -//---------------------------------------------------------------------------------------- -// PROJECT SINGLE RAY template void CParallelBeamBlobKernelProjector2D::projectSingleRay(int _iProjection, int _iDetector, Policy& p) { - ASTRA_ASSERT(m_bIsInitialized); - - int iRayIndex = _iProjection * m_pProjectionGeometry->getDetectorCount() + _iDetector; - - // POLICY: RAY PRIOR - if (!p.rayPrior(iRayIndex)) return; - - // get values - float32 t = m_pProjectionGeometry->indexToDetectorOffset(_iDetector); - float32 theta = m_pProjectionGeometry->getProjectionAngle(_iProjection); - if (theta >= 7*PIdiv4) theta -= 2*PI; - - bool flip = false; + projectBlock_internal(_iProjection, _iProjection + 1, + _iDetector, _iDetector + 1, p); +} - if (theta >= 3*PIdiv4) { - theta -= PI; - t = -t; - flip = true; +//---------------------------------------------------------------------------------------- +// PROJECT BLOCK - vector projection geometry +template +void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) +{ + // variables + float32 detX, detY, x, y, c, r, update_c, update_r, offset, invBlobExtent, inv_pixelLengthX, inv_pixelLengthY, weight, d; + int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector, colCount, rowCount, detCount; + int col_left, col_right, row_top, row_bottom, index; + const SParProjection * proj = 0; + + // get vector geometry + const CParallelVecProjectionGeometry2D* pVecProjectionGeometry; + if (dynamic_cast(m_pProjectionGeometry)) { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry)->toVectorGeometry(); + } else { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); } + // 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(); + + // loop angles + for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { + + proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; + + 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); + } 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); + } - if (theta <= PIdiv4) { // -pi/4 <= theta <= pi/4 - - // precalculate sin, cos, 1/cos - float32 sin_theta = sin(theta); - float32 cos_theta = cos(theta); - float32 inv_cos_theta = 1.0f / cos_theta; - - // precalculate other stuff - float32 lengthPerRow = m_pVolumeGeometry->getPixelLengthY() * inv_cos_theta; - float32 updatePerRow = sin_theta * lengthPerRow; - float32 inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); - float32 pixelLengthX_over_blobSize = m_pVolumeGeometry->getPixelLengthX() / m_fBlobSize; - - // some variables - int row, col, xmin, xmax; - float32 P, x, d; - - // calculate P and x for row 0 - P = (t - sin_theta * m_pVolumeGeometry->pixelRowToCenterY(0)) * inv_cos_theta; - x = (P - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; - - // for each row - for (row = 0; row < m_pVolumeGeometry->getGridRowCount(); ++row) { + // loop detectors + for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - // calculate extent - xmin = (int)ceil((P - m_fBlobSize - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f); - xmax = (int)floor((P + m_fBlobSize - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f); - - // add pixels - for (col = xmin; col <= xmax; col++) { - if (col >= 0 && col < m_pVolumeGeometry->getGridColCount()) { - //d = abs(x - col) * pixelLengthX_over_blobSize; - //index = (int)(d*m_iBlobSampleCount+0.5f); - //float32 fWeight = m_pfBlobValues[min(index,m_iBlobSampleCount-1)] * lengthPerRow; - - float32 fWeight; - int index; - if ((x >= col) ^ flip) { - d = abs(x - col) * pixelLengthX_over_blobSize * cos_theta; - index = (int)(d*m_iBlobSampleCount+0.5f); - fWeight = m_pfBlobValues[min(index,m_iBlobSampleCount-1)]; - } else { - d = abs(x - col) * pixelLengthX_over_blobSize * cos_theta; - index = (int)(d*m_iBlobSampleCount+0.5f); - fWeight = m_pfBlobValuesNeg[min(index,m_iBlobSampleCount-1)]; - } + iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; - int iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, fWeight); - p.pixelPosterior(iVolumeIndex); + // POLICY: RAY PRIOR + if (!p.rayPrior(iRayIndex)) continue; + + detX = proj->fDetSX + (iDetector+0.5f) * proj->fDetUX; + detY = 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; + + // for each row + for (row = 0; row < rowCount; ++row, c += update_c) { + + col_left = int(c - 0.5f - m_fBlobSize); + col_right = int(c + 0.5f + m_fBlobSize); + + if (col_left < 0) col_left = 0; + if (col_right > colCount-1) col_right = colCount-1; + + // for each column + 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); + p.pixelPosterior(iVolumeIndex); + } } } } - // update P and x - P += updatePerRow; - x += updatePerRow * inv_pixelLengthX; - } + // horizontally + else { - } else { // pi/4 < theta < 3pi/4 - - // precalculate sin cos - float32 sin_90_theta = sin(PIdiv2-theta); - float32 cos_90_theta = cos(PIdiv2-theta); - float32 inv_cos_90_theta = 1.0f / cos_90_theta; - - // precalculate other stuff - float32 lengthPerCol = m_pVolumeGeometry->getPixelLengthX() * inv_cos_90_theta; - float32 updatePerCol = sin_90_theta * lengthPerCol; - float32 inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); - float32 pixelLengthY_over_blobSize = m_pVolumeGeometry->getPixelLengthY() / m_fBlobSize; - - // some variables - int row, col, xmin, xmax; - float32 P,x, d; - - // calculate P and x for col 0 - P = (sin_90_theta * m_pVolumeGeometry->pixelColToCenterX(0) - t) * inv_cos_90_theta; - x = (P - m_pVolumeGeometry->getWindowMinY()) * inv_pixelLengthY - 0.5f; - - // for each col - for (col = 0; col < m_pVolumeGeometry->getGridColCount(); ++col) { - - // calculate extent - xmin = (int)ceil((P - m_fBlobSize - m_pVolumeGeometry->getWindowMinY()) * inv_pixelLengthY - 0.5f); - xmax = (int)floor((P + m_fBlobSize - m_pVolumeGeometry->getWindowMinY()) * inv_pixelLengthY - 0.5f); - - // add pixels - for (row = xmin; row <= xmax; row++) { - if (row >= 0 && row < m_pVolumeGeometry->getGridRowCount()) { - //d = abs(x - row) * pixelLengthY_over_blobSize; - //int index = (int)(d*m_iBlobSampleCount+0.5f); - //float32 fWeight = m_pfBlobValues[min(index,m_iBlobSampleCount-1)] * lengthPerCol; - - float32 fWeight; - int index; - if ((x <= row) ^ flip) { - d = abs(x - row) * pixelLengthY_over_blobSize * cos_90_theta; - index = (int)(d*m_iBlobSampleCount+0.5f); - fWeight = m_pfBlobValues[min(index,m_iBlobSampleCount-1)]; - } else { - d = abs(x - row) * pixelLengthY_over_blobSize * cos_90_theta; - index = (int)(d*m_iBlobSampleCount+0.5f); - fWeight = m_pfBlobValuesNeg[min(index,m_iBlobSampleCount-1)]; - } + // 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; + // for each col + for (col = 0; col < colCount; ++col, r += update_r) { - int iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, fWeight); - p.pixelPosterior(iVolumeIndex); - } - } - } + row_top = int(r - 0.5f - m_fBlobSize); + row_bottom = int(r + 0.5f + m_fBlobSize); - // update P and x - P += updatePerCol; - x += updatePerCol * inv_pixelLengthY; - } + if (row_top < 0) row_top = 0; + if (row_bottom > rowCount-1) row_bottom = rowCount-1; - } - - // POLICY: RAY POSTERIOR - p.rayPosterior(iRayIndex); + // for each column + 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); + p.pixelPosterior(iVolumeIndex); + } + } + } + } + + // POLICY: RAY POSTERIOR + p.rayPosterior(iRayIndex); + + } // end loop detector + } // end loop angles } -- cgit v1.2.3 From c0b6862d75edcde6beacf811ce97200776d13b62 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Thu, 12 Mar 2015 15:16:10 +0100 Subject: updated 'line_fanflat' projector --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 315 +++++++++------------ include/astra/FanFlatProjectionGeometry2D.h | 5 + 2 files changed, 140 insertions(+), 180 deletions(-) (limited to 'include/astra') diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl index 2f87659..1676cb1 100644 --- a/include/astra/FanFlatBeamLineKernelProjector2D.inl +++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl @@ -51,246 +51,201 @@ void CFanFlatBeamLineKernelProjector2D::projectSingleRay(int _iProjection, int _ } //---------------------------------------------------------------------------------------- -// PROJECT BLOCK +// PROJECT BLOCK - vector projection geometry template void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { // variables - float32 sin_theta, cos_theta, inv_sin_theta, inv_cos_theta, S, T, t, I, P, x, x2; - float32 lengthPerRow, updatePerRow, inv_pixelLengthX, lengthPerCol, updatePerCol, inv_pixelLengthY; - int iVolumeIndex, iRayIndex, row, col, iAngle, iDetector, x1; - bool switch_t; - - const CFanFlatProjectionGeometry2D* pProjectionGeometry = dynamic_cast(m_pProjectionGeometry); - const CFanFlatVecProjectionGeometry2D* pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); - - float32 old_theta, theta, alpha; + 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(m_pProjectionGeometry)) { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry)->toVectorGeometry(); + } else { + pVecProjectionGeometry = dynamic_cast(m_pProjectionGeometry); + } + + // 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(); + // loop angles for (iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { - // get theta - if (pProjectionGeometry) { - old_theta = pProjectionGeometry->getProjectionAngle(iAngle); - } - else if (pVecProjectionGeometry) { - proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; - old_theta = atan2(-proj->fSrcX, proj->fSrcY); - if (old_theta < 0) old_theta += 2*PI; - } else { - assert(false); - } - - switch_t = false; - if (old_theta >= 7*PIdiv4) old_theta -= 2*PI; - if (old_theta >= 3*PIdiv4) { - old_theta -= PI; - switch_t = true; - } + proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; // loop detectors for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { - iRayIndex = iAngle * m_pProjectionGeometry->getDetectorCount() + iDetector; + iRayIndex = iAngle * detCount + iDetector; // POLICY: RAY PRIOR if (!p.rayPrior(iRayIndex)) continue; - - // get values - if (pProjectionGeometry) { - t = -pProjectionGeometry->indexToDetectorOffset(iDetector); - alpha = atan(t / pProjectionGeometry->getSourceDetectorDistance()); - t = sin(alpha) * pProjectionGeometry->getOriginSourceDistance(); - } - else if (pVecProjectionGeometry) { - float32 detX = proj->fDetSX + proj->fDetUX*(0.5f + iDetector); - float32 detY = proj->fDetSY + proj->fDetUY*(0.5f + iDetector); - alpha = angleBetweenVectors(-proj->fSrcX, -proj->fSrcY, detX - proj->fSrcX, detY - proj->fSrcY); - t = sin(alpha) * sqrt(proj->fSrcX*proj->fSrcX + proj->fSrcY*proj->fSrcY); + + detX = proj->fDetSX + (iDetector+0.5f) * proj->fDetUX; + detY = proj->fDetSY + (iDetector+0.5f) * proj->fDetUY; + + float32 fRayX = proj->fSrcX - detX; + float32 fRayY = proj->fSrcY - detY; + + bool vertical = fabs(fRayX) < fabs(fRayY); + 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); + invTminSTimesLengthPerRow = lengthPerRow / (T - S); } else { - assert(false); + 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); + invTminSTimesLengthPerCol = lengthPerCol / (T - S); } - if (switch_t) t = -t; - theta = old_theta + alpha; - - // precalculate sin, cos, 1/cos - sin_theta = sin(theta); - cos_theta = cos(theta); - inv_sin_theta = 1.0f / sin_theta; - inv_cos_theta = 1.0f / cos_theta; - - // precalculate kernel limits - lengthPerRow = m_pVolumeGeometry->getPixelLengthY() * inv_cos_theta; - updatePerRow = sin_theta * inv_cos_theta; - inv_pixelLengthX = 1.0f / m_pVolumeGeometry->getPixelLengthX(); - - // precalculate kernel limits - lengthPerCol = m_pVolumeGeometry->getPixelLengthX() * inv_sin_theta; - updatePerCol = cos_theta * inv_sin_theta; - inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); - - // precalculate S and T - S = 0.5f - 0.5f * ((updatePerRow < 0) ? -updatePerRow : updatePerRow); - T = 0.5f - 0.5f * ((updatePerCol < 0) ? -updatePerCol : updatePerCol); - // vertically - if (old_theta <= PIdiv4) { - + if (vertical) { + // calculate x for row 0 - P = (t - sin_theta * m_pVolumeGeometry->pixelRowToCenterY(0)) * inv_cos_theta; - x = (P - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX; + x = detX + (fRayX/fRayY)*(m_pVolumeGeometry->pixelRowToCenterY(0)-detY); + c = (x - m_pVolumeGeometry->getWindowMinX()) * inv_pixelLengthX - 0.5f; // for each row - for (row = 0; row < m_pVolumeGeometry->getGridRowCount(); ++row) { - - // get coords - x1 = int((x > 0.0f) ? x : x-1.0f); - x2 = x - x1; - x += updatePerRow; + for (row = 0; row < rowCount; ++row, c += update_c) { + + col = int(c+0.5f); + offset = c - float32(col); - if (x1 < -1 || x1 > m_pVolumeGeometry->getGridColCount()) continue; + if (col <= 0 || col >= colCount-1) continue; // left - if (x2 < 0.5f-S) { - I = (0.5f - S + x2) / (1.0f - 2.0f*S) * lengthPerRow; - - if (x1-1 >= 0 /*&& x1-1 < m_pVolumeGeometry->getGridColCount()*/) {//x1 is always less than or equal to gridColCount because of the "continue" in the beginning of the for-loop - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1-1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); - p.pixelPosterior(iVolumeIndex); - } + if (offset < -S) { + I = (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); } - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } + iVolumeIndex++; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); } } - // center - else if (x2 <= 0.5f+S) { - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow); - p.pixelPosterior(iVolumeIndex); - } - } - } - // right - else if (x2 <= 1.0f) { - I = (1.5f - S - x2) / (1.0f - 2.0f*S) * lengthPerRow; - - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridColCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } + else if (S < offset) { + I = (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); + } + + iVolumeIndex++; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); } - if (/*x1+1 >= 0 &&*/ x1+1 < m_pVolumeGeometry->getGridColCount()) {//x1 is always greater than or equal to -1 because of the "continue" in the beginning of the for-loop - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(row, x1+1); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-I); - p.pixelPosterior(iVolumeIndex); - } + } + + // centre + else { + iVolumeIndex = row * colCount + col; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow); + p.pixelPosterior(iVolumeIndex); } } + } } // horizontally - //else if (PIdiv4 <= old_theta && old_theta <= 3*PIdiv4) { else { - // calculate point P - P = (t - cos_theta * m_pVolumeGeometry->pixelColToCenterX(0)) * inv_sin_theta; - x = (m_pVolumeGeometry->getWindowMaxY() - P) * inv_pixelLengthY; + // calculate y for col 0 + y = detY + (fRayY/fRayX)*(m_pVolumeGeometry->pixelColToCenterX(0)-detX); + r = (m_pVolumeGeometry->getWindowMaxY() - y) * inv_pixelLengthY - 0.5f; // for each col - for (col = 0; col < m_pVolumeGeometry->getGridColCount(); ++col) { - - // get coords - x1 = int((x > 0.0f) ? x : x-1.0f); - x2 = x - x1; - x += updatePerCol; + for (col = 0; col < colCount; ++col, r += update_r) { + + int row = int(r+0.5f); + offset = r - float32(row); - if (x1 < -1 || x1 > m_pVolumeGeometry->getGridRowCount()) continue; + if (row <= 0 || row >= rowCount-1) continue; // up - if (x2 < 0.5f-T) { - I = (0.5f - T + x2) / (1.0f - 2.0f*T) * lengthPerCol; - - if (x1-1 >= 0 /*&& x1-1 < m_pVolumeGeometry->getGridRowCount()*/) {//x1 is always less than or equal to gridRowCount because of the "continue" in the beginning of the for-loop - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1-1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); - p.pixelPosterior(iVolumeIndex); - } + if (offset < -S) { + I = (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); } - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } + iVolumeIndex += colCount; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); } } - // center - else if (x2 <= 0.5f+T) { - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol); - p.pixelPosterior(iVolumeIndex); - } - } - } - // down - else if (x2 <= 1.0f) { - I = (1.5f - T - x2) / (1.0f - 2.0f*T) * lengthPerCol; - - if (x1 >= 0 && x1 < m_pVolumeGeometry->getGridRowCount()) { - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, I); - p.pixelPosterior(iVolumeIndex); - } + else if (S < offset) { + I = (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); } - if (/*x1+1 >= 0 &&*/ x1+1 < m_pVolumeGeometry->getGridRowCount()) {//x1 is always greater than or equal to -1 because of the "continue" in the beginning of the for-loop - iVolumeIndex = m_pVolumeGeometry->pixelRowColToIndex(x1+1, col); - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol-I); - p.pixelPosterior(iVolumeIndex); - } + + iVolumeIndex += colCount; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, I); + p.pixelPosterior(iVolumeIndex); + } + } + + // centre + else { + iVolumeIndex = row * colCount + col; + // POLICY: PIXEL PRIOR + ADD + POSTERIOR + if (p.pixelPrior(iVolumeIndex)) { + p.addWeight(iRayIndex, iVolumeIndex, lengthPerCol); + p.pixelPosterior(iVolumeIndex); } } + } - } // end loop col + } // POLICY: RAY POSTERIOR p.rayPosterior(iRayIndex); } // end loop detector } // end loop angles + } diff --git a/include/astra/FanFlatProjectionGeometry2D.h b/include/astra/FanFlatProjectionGeometry2D.h index 180fe68..8750232 100644 --- a/include/astra/FanFlatProjectionGeometry2D.h +++ b/include/astra/FanFlatProjectionGeometry2D.h @@ -30,6 +30,7 @@ $Id$ #define _INC_ASTRA_FANFLATPROJECTIONGEOMETRY2D #include "ProjectionGeometry2D.h" +#include "FanFlatVecProjectionGeometry2D.h" #include @@ -190,6 +191,10 @@ public: * @return a unit vector describing the direction */ virtual CVector3D getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex); + + /** Create a vector geom + */ + CFanFlatVecProjectionGeometry2D* toVectorGeometry(); }; -- cgit v1.2.3 From d53185395827980e101629c633653cb4284edb06 Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Fri, 13 Mar 2015 10:22:22 +0100 Subject: removed extraDetectorOffset --- include/astra/ProjectionGeometry2D.h | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ProjectionGeometry2D.h b/include/astra/ProjectionGeometry2D.h index b8324e2..d26e6a7 100644 --- a/include/astra/ProjectionGeometry2D.h +++ b/include/astra/ProjectionGeometry2D.h @@ -65,10 +65,6 @@ protected: */ float32 m_fDetectorWidth; - /** An array of m_iProjectionAngleCount elements containing an extra detector offset for each projection. - */ - float32* m_pfExtraDetectorOffset; - /** Dynamically allocated array of projection angles. All angles are represented in radians and lie in * the [0,2pi[ interval. */ @@ -202,9 +198,6 @@ public: */ float32 getProjectionAngleDegrees(int _iProjectionIndex) const; - float32 getExtraDetectorOffset(int iAngle) const; - const float32* getExtraDetectorOffset() const { return m_pfExtraDetectorOffset; } - /** Get the index coordinate of a point on a detector array. * * @param _fOffset distance between the center of the detector array and a certain point @@ -273,12 +266,6 @@ public: //---------------------------------------------------------------------------------------- -inline float32 CProjectionGeometry2D::getExtraDetectorOffset(int _iAngle) const -{ - return m_pfExtraDetectorOffset ? m_pfExtraDetectorOffset[_iAngle] : 0.0f; -} - - // Get the initialization state. inline bool CProjectionGeometry2D::isInitialized() const { -- cgit v1.2.3 From 1ff4a270a7df1edb54dd91fe653d6a936b959b3a Mon Sep 17 00:00:00 2001 From: Wim van Aarle Date: Wed, 27 May 2015 15:48:48 +0200 Subject: some marginal gains + added documentation --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 156 ++++++--------- .../astra/ParallelBeamBlobKernelProjector2D.inl | 119 ++++++++---- .../astra/ParallelBeamLineKernelProjector2D.inl | 209 ++++++++++++++------- .../astra/ParallelBeamLinearKernelProjector2D.inl | 153 ++++++++++----- .../astra/ParallelBeamStripKernelProjector2D.inl | 166 +++++++++++----- 5 files changed, 509 insertions(+), 294 deletions(-) (limited to 'include/astra') 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 . ----------------------------------------------------------------------- $Id$ */ - - -using namespace astra; +#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } template void CFanFlatBeamLineKernelProjector2D::project(Policy& p) @@ -55,12 +53,6 @@ void CFanFlatBeamLineKernelProjector2D::projectSingleRay(int _iProjection, int _ template 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(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 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 . ----------------------------------------------------------------------- $Id$ */ +#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } template 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 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 . ----------------------------------------------------------------------- $Id$ */ +#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } template 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 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 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); } -- cgit v1.2.3 From b1ffc11d930c19bd73af9837a08bc8dde9fe8e72 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 29 Jul 2016 12:03:38 +0200 Subject: Add CUDA parvec support --- .../astra/CudaFilteredBackProjectionAlgorithm.h | 30 ++------- include/astra/GeometryUtil2D.h | 73 +++++++++++++++++----- include/astra/ParallelProjectionGeometry2D.h | 6 +- include/astra/ProjectionGeometry2D.h | 6 +- 4 files changed, 69 insertions(+), 46 deletions(-) (limited to 'include/astra') diff --git a/include/astra/CudaFilteredBackProjectionAlgorithm.h b/include/astra/CudaFilteredBackProjectionAlgorithm.h index cf1f19f..180e001 100644 --- a/include/astra/CudaFilteredBackProjectionAlgorithm.h +++ b/include/astra/CudaFilteredBackProjectionAlgorithm.h @@ -26,28 +26,24 @@ along with the ASTRA Toolbox. If not, see . $Id$ */ -#ifndef CUDAFILTEREDBACKPROJECTIONALGORITHM2_H -#define CUDAFILTEREDBACKPROJECTIONALGORITHM2_H +#ifndef CUDAFILTEREDBACKPROJECTIONALGORITHM_H +#define CUDAFILTEREDBACKPROJECTIONALGORITHM_H #include #include -#include +#include #include "../../cuda/2d/astra.h" namespace astra { -class _AstraExport CCudaFilteredBackProjectionAlgorithm : public CReconstructionAlgorithm2D +class _AstraExport CCudaFilteredBackProjectionAlgorithm : public CCudaReconstructionAlgorithm2D { public: static std::string type; private: - CFloat32ProjectionData2D * m_pSinogram; - CFloat32VolumeData2D * m_pReconstruction; - int m_iGPUIndex; - int m_iPixelSuperSampling; E_FBPFILTER m_eFilter; float * m_pfFilter; int m_iFilterWidth; // number of elements per projection direction in filter @@ -64,15 +60,6 @@ public: virtual bool initialize(const Config& _cfg); bool initialize(CFloat32ProjectionData2D * _pSinogram, CFloat32VolumeData2D * _pReconstruction, E_FBPFILTER _eFilter, const float * _pfFilter = NULL, int _iFilterWidth = 0, int _iGPUIndex = -1, float _fFilterParameter = -1.0f); - virtual void run(int _iNrIterations = 0); - - static int calcIdealRealFilterWidth(int _iDetectorCount); - static int calcIdealFourierFilterWidth(int _iDetectorCount); - - //debug - static void testGenFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, cufftComplex * _pFilter, int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount); - static int getGPUCount(); - /** Get a description of the class. * * @return description string @@ -82,12 +69,7 @@ public: protected: bool check(); - AstraFBP* m_pFBP; - - bool m_bAstraFBPInit; - - void initializeFromProjector(); - virtual bool requiresProjector() const { return false; } + virtual void initCUDAAlgorithm(); }; // inline functions @@ -95,4 +77,4 @@ inline std::string CCudaFilteredBackProjectionAlgorithm::description() const { r } -#endif /* CUDAFILTEREDBACKPROJECTIONALGORITHM2_H */ +#endif /* CUDAFILTEREDBACKPROJECTIONALGORITHM_H */ diff --git a/include/astra/GeometryUtil2D.h b/include/astra/GeometryUtil2D.h index 680cecd..2f03062 100644 --- a/include/astra/GeometryUtil2D.h +++ b/include/astra/GeometryUtil2D.h @@ -32,27 +32,72 @@ $Id$ namespace astra { struct SParProjection { - // the ray direction - float fRayX, fRayY; + // the ray direction + float fRayX, fRayY; + + // the start of the (linear) detector + float fDetSX, fDetSY; + + // the length of a single detector pixel + float fDetUX, fDetUY; + + + void translate(double dx, double dy) { + fDetSX += dx; + fDetSY += dy; + } + void scale(double factor) { + fRayX *= factor; + fRayY *= factor; + fDetSX *= factor; + fDetSY *= factor; + fDetUX *= factor; + fDetUY *= factor; + } +}; - // the start of the (linear) detector - float fDetSX, fDetSY; - // the length of a single detector pixel - float fDetUX, fDetUY; +struct SFanProjection { + // the source + float fSrcX, fSrcY; + + // the start of the (linear) detector + float fDetSX, fDetSY; + + // the length of a single detector pixel + float fDetUX, fDetUY; + + void translate(double dx, double dy) { + fSrcX += dx; + fSrcY += dy; + fDetSX += dx; + fDetSY += dy; + } + void scale(double factor) { + fSrcX *= factor; + fSrcY *= factor; + fDetSX *= factor; + fDetSY *= factor; + fDetUX *= factor; + fDetUY *= factor; + } }; -struct SFanProjection { - // the source - float fSrcX, fSrcY; - // the start of the (linear) detector - float fDetSX, fDetSY; +SParProjection* genParProjections(unsigned int iProjAngles, + unsigned int iProjDets, + double fDetSize, + const float *pfAngles, + const float *pfExtraOffsets); - // the length of a single detector pixel - float fDetUX, fDetUY; -}; +SFanProjection* genFanProjections(unsigned int iProjAngles, + unsigned int iProjDets, + double fOriginSource, double fOriginDetector, + double fDetSize, + const float *pfAngles); + +bool getFanParameters(const SFanProjection &proj, unsigned int iProjDets, float &fAngle, float &fOriginSource, float &fOriginDetector, float &fDetSize, float &fOffset); } diff --git a/include/astra/ParallelProjectionGeometry2D.h b/include/astra/ParallelProjectionGeometry2D.h index 36b4b6f..ca67ba7 100644 --- a/include/astra/ParallelProjectionGeometry2D.h +++ b/include/astra/ParallelProjectionGeometry2D.h @@ -84,8 +84,7 @@ public: CParallelProjectionGeometry2D(int _iProjectionAngleCount, int _iDetectorCount, float32 _fDetectorWidth, - const float32* _pfProjectionAngles, - const float32* _pfExtraDetectorOffsets = 0); + const float32* _pfProjectionAngles); /** Copy constructor. */ @@ -117,8 +116,7 @@ public: bool initialize(int _iProjectionAngleCount, int _iDetectorCount, float32 _fDetectorWidth, - const float32* _pfProjectionAngles, - const float32* _pfExtraDetectorOffsets = 0); + const float32* _pfProjectionAngles); /** Create a hard copy. */ diff --git a/include/astra/ProjectionGeometry2D.h b/include/astra/ProjectionGeometry2D.h index d26e6a7..b656d97 100644 --- a/include/astra/ProjectionGeometry2D.h +++ b/include/astra/ProjectionGeometry2D.h @@ -90,8 +90,7 @@ protected: CProjectionGeometry2D(int _iProjectionAngleCount, int _iDetectorCount, float32 _fDetectorWidth, - const float32* _pfProjectionAngles, - const float32* _pfExtraDetectorOffsets = 0); + const float32* _pfProjectionAngles); /** Copy constructor. */ @@ -117,8 +116,7 @@ protected: bool _initialize(int _iProjectionAngleCount, int _iDetectorCount, float32 _fDetectorWidth, - const float32* _pfProjectionAngles, - const float32* _pfExtraDetectorOffsets = 0); + const float32* _pfProjectionAngles); public: -- cgit v1.2.3 From 741675b458bf23cf437a6c56f95483c5c66af774 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 29 Jul 2016 14:08:51 +0200 Subject: Fix memory leak in CPU projectors --- include/astra/ParallelBeamLineKernelProjector2D.inl | 3 +++ include/astra/ParallelBeamLinearKernelProjector2D.inl | 3 +++ include/astra/ParallelBeamStripKernelProjector2D.inl | 2 ++ 3 files changed, 8 insertions(+) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 199cfd7..b3e54f9 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -316,4 +316,7 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i } // end loop detector } // end loop angles + if (dynamic_cast(m_pProjectionGeometry)) + delete pVecProjectionGeometry; + } diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index ecbdeb3..9b2c7b1 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -234,4 +234,7 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, } // end loop detector } // end loop angles + + if (dynamic_cast(m_pProjectionGeometry)) + delete pVecProjectionGeometry; } diff --git a/include/astra/ParallelBeamStripKernelProjector2D.inl b/include/astra/ParallelBeamStripKernelProjector2D.inl index f0203f2..e457316 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.inl +++ b/include/astra/ParallelBeamStripKernelProjector2D.inl @@ -287,4 +287,6 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, } // end loop detector } // end loop angles + if (dynamic_cast(m_pProjectionGeometry)) + delete pVecProjectionGeometry; } -- cgit v1.2.3 From 514f3610e61fd14f237fdd1981b45c6cf3037b21 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 15 Sep 2017 17:37:37 +0200 Subject: Fix boundary issues in par_line --- .../astra/ParallelBeamLineKernelProjector2D.inl | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 83c16d7..6976cfd 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -210,8 +210,8 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i // 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; } + col = int(floor(c+0.5f)); + if (col < -1 || col > colCount) { if (!isin) continue; else break; } offset = c - float32(col); // left @@ -220,14 +220,14 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i iVolumeIndex = row * colCount + col - 1; // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { + if (col > 0 && p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-weight); p.pixelPosterior(iVolumeIndex); } iVolumeIndex++; // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { + if (col >= 0 && col < colCount && p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, weight); p.pixelPosterior(iVolumeIndex); } @@ -239,21 +239,21 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i iVolumeIndex = row * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { + if (col >= 0 && col < colCount && p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-weight); p.pixelPosterior(iVolumeIndex); } iVolumeIndex++; // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (p.pixelPrior(iVolumeIndex)) { + if (col + 1 < colCount && p.pixelPrior(iVolumeIndex)) { p.addWeight(iRayIndex, iVolumeIndex, weight); p.pixelPosterior(iVolumeIndex); } } // centre - else { + else if (col >= 0 && col < colCount) { iVolumeIndex = row * colCount + col; // POLICY: PIXEL PRIOR + ADD + POSTERIOR if (p.pixelPrior(iVolumeIndex)) { @@ -274,8 +274,8 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i // loop columns for (col = 0; col < colCount; ++col, r += deltar) { - row = int(r+0.5f); - if (row <= 0 || row >= rowCount-1) { if (!isin) continue; else break; } + row = int(floor(r+0.5f)); + if (row < -1 || row > rowCount) { if (!isin) continue; else break; } offset = r - float32(row); // up @@ -283,10 +283,10 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i weight = (offset + T) * invTminSTimesLengthPerCol; iVolumeIndex = (row-1) * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) + if (row > 0) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) } iVolumeIndex += colCount; - policy_weight(p, iRayIndex, iVolumeIndex, weight) + if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight) } } // down @@ -294,14 +294,14 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i weight = (offset - S) * invTminSTimesLengthPerCol; iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) + if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) } iVolumeIndex += colCount; - policy_weight(p, iRayIndex, iVolumeIndex, weight) + if (row + 1 < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight) } } // centre - else { + else if (row >= 0 && row < rowCount) { iVolumeIndex = row * colCount + col; policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol) } -- cgit v1.2.3 From 55b2cd9192ecd36d33155161023c6d55b8811408 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 15 Sep 2017 18:33:22 +0200 Subject: Homogenize style --- .../astra/ParallelBeamLineKernelProjector2D.inl | 42 ++++++---------------- 1 file changed, 11 insertions(+), 31 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 6976cfd..3236469 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -24,7 +24,7 @@ along with the ASTRA Toolbox. If not, see . ----------------------------------------------------------------------- */ -#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } +#define policy_weight(p,rayindex,volindex,weight) do { if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } } while (false) template void CParallelBeamLineKernelProjector2D::project(Policy& p) @@ -219,18 +219,10 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i weight = (offset + T) * invTminSTimesLengthPerRow; iVolumeIndex = row * colCount + col - 1; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (col > 0 && p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-weight); - p.pixelPosterior(iVolumeIndex); - } + if (col > 0) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight); } iVolumeIndex++; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (col >= 0 && col < colCount && p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, weight); - p.pixelPosterior(iVolumeIndex); - } + if (col >= 0 && col < colCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // right @@ -238,28 +230,16 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i weight = (offset - S) * invTminSTimesLengthPerRow; iVolumeIndex = row * colCount + col; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (col >= 0 && col < colCount && p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, lengthPerRow-weight); - p.pixelPosterior(iVolumeIndex); - } + if (col >= 0 && col < colCount) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight); } iVolumeIndex++; - // POLICY: PIXEL PRIOR + ADD + POSTERIOR - if (col + 1 < colCount && p.pixelPrior(iVolumeIndex)) { - p.addWeight(iRayIndex, iVolumeIndex, weight); - p.pixelPosterior(iVolumeIndex); - } + if (col + 1 < colCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // centre else if (col >= 0 && col < colCount) { 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; } @@ -283,10 +263,10 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i weight = (offset + T) * invTminSTimesLengthPerCol; iVolumeIndex = (row-1) * colCount + col; - if (row > 0) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) } + if (row > 0) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight); } iVolumeIndex += colCount; - if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight) } + if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // down @@ -294,16 +274,16 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i weight = (offset - S) * invTminSTimesLengthPerCol; iVolumeIndex = row * colCount + col; - if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) } + if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight); } iVolumeIndex += colCount; - if (row + 1 < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight) } + if (row + 1 < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // centre else if (row >= 0 && row < rowCount) { iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol) + policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol); } isin = true; } -- cgit v1.2.3 From d5b31702671ec2f22e43beb9dac3613fe145cf4a Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 18 Sep 2017 11:12:38 +0200 Subject: Fix boundary issues in fan_line --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 34 +++++++++++----------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'include/astra') diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl index 51dc878..5c8eddf 100644 --- a/include/astra/FanFlatBeamLineKernelProjector2D.inl +++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl @@ -25,7 +25,7 @@ along with the ASTRA Toolbox. If not, see . ----------------------------------------------------------------------- */ -#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } +#define policy_weight(p,rayindex,volindex,weight) do { if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } } while (false) template void CFanFlatBeamLineKernelProjector2D::project(Policy& p) @@ -125,8 +125,8 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in // for each row for (row = 0; row < rowCount; ++row, c += deltac) { - col = int(c+0.5f); - if (col <= 0 || col >= colCount-1) { if (!isin) continue; else break; } + col = int(floor(c+0.5f)); + if (col < -1 || col > colCount) { if (!isin) continue; else break; } offset = c - float32(col); // left @@ -134,10 +134,10 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in weight = (offset + T) * invTminSTimesLengthPerRow; iVolumeIndex = row * colCount + col - 1; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight) + if (col > 0) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight); } iVolumeIndex++; - policy_weight(p, iRayIndex, iVolumeIndex, weight) + if (col >= 0 && col < colCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // right @@ -145,16 +145,16 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in weight = (offset - S) * invTminSTimesLengthPerRow; iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight) + if (col >= 0 && col < colCount) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow-weight); } iVolumeIndex++; - policy_weight(p, iRayIndex, iVolumeIndex, weight) + if (col + 1 < colCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // centre - else { + else if (col >= 0 && col < colCount) { iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow) + policy_weight(p, iRayIndex, iVolumeIndex, lengthPerRow); } isin = true; } @@ -169,8 +169,8 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in // for each col 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; } + row = int(floor(r+0.5f)); + if (row < -1 || row > rowCount) { if (!isin) continue; else break; } offset = r - float32(row); // up @@ -178,10 +178,10 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in weight = (offset + T) * invTminSTimesLengthPerCol; iVolumeIndex = (row-1) * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) + if (row > 0) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight); } iVolumeIndex += colCount; - policy_weight(p, iRayIndex, iVolumeIndex, weight) + if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // down @@ -189,16 +189,16 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in weight = (offset - S) * invTminSTimesLengthPerCol; iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight) + if (row >= 0 && row < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol-weight); } iVolumeIndex += colCount; - policy_weight(p, iRayIndex, iVolumeIndex, weight) + if (row + 1 < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, weight); } } // centre - else { + else if (row >= 0 && row < rowCount) { iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol) + policy_weight(p, iRayIndex, iVolumeIndex, lengthPerCol); } isin = true; } -- cgit v1.2.3 From a40b6c9948cfc461f25f8f4878fb4ca671ca5107 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 18 Sep 2017 15:49:38 +0200 Subject: Fix boundary issues in par_linear --- include/astra/ParallelBeamLinearKernelProjector2D.inl | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'include/astra') diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index 2619a12..fc5935a 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -25,7 +25,7 @@ along with the ASTRA Toolbox. If not, see . ----------------------------------------------------------------------- */ -#define policy_weight(p,rayindex,volindex,weight) if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } +#define policy_weight(p,rayindex,volindex,weight) do { if (p.pixelPrior(volindex)) { p.addWeight(rayindex, volindex, weight); p.pixelPosterior(volindex); } } while (false) template void CParallelBeamLinearKernelProjector2D::project(Policy& p) @@ -192,15 +192,15 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, // loop rows for (row = 0; row < rowCount; ++row, c += deltac) { - col = int(c); - if (col <= 0 || col >= colCount-1) { if (!isin) continue; else break; } + col = int(floor(c)); + if (col < -1 || col >= colCount) { if (!isin) continue; else break; } offset = c - float32(col); iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerRow) + if (col >= 0) { policy_weight(p, iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerRow); } iVolumeIndex++; - policy_weight(p, iRayIndex, iVolumeIndex, offset * lengthPerRow) + if (col + 1 < colCount) { policy_weight(p, iRayIndex, iVolumeIndex, offset * lengthPerRow); } isin = true; } @@ -215,15 +215,15 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, // loop columns for (col = 0; col < colCount; ++col, r += deltar) { - row = int(r); - if (row <= 0 || row >= rowCount-1) { if (!isin) continue; else break; } + row = int(floor(r)); + if (row < -1 || row >= rowCount) { if (!isin) continue; else break; } offset = r - float32(row); iVolumeIndex = row * colCount + col; - policy_weight(p, iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerCol) + if (row >= 0) { policy_weight(p, iRayIndex, iVolumeIndex, (1.0f - offset) * lengthPerCol); } iVolumeIndex += colCount; - policy_weight(p, iRayIndex, iVolumeIndex, offset * lengthPerCol) + if (row + 1 < rowCount) { policy_weight(p, iRayIndex, iVolumeIndex, offset * lengthPerCol); } isin = true; } -- cgit v1.2.3 From 5fba1c8c07a8dc99351edc7c3d3784e01ddf583f Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 20 Sep 2017 14:43:21 +0200 Subject: Remove broken openmp support from CPU kernels The writes to the volume in the (ray-driven) backprojection are not done in a thread-safe way. --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 1 - include/astra/ParallelBeamBlobKernelProjector2D.inl | 1 - include/astra/ParallelBeamLineKernelProjector2D.inl | 1 - include/astra/ParallelBeamLinearKernelProjector2D.inl | 1 - include/astra/ParallelBeamStripKernelProjector2D.inl | 1 - 5 files changed, 5 deletions(-) (limited to 'include/astra') diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl index 5c8eddf..07d61b5 100644 --- a/include/astra/FanFlatBeamLineKernelProjector2D.inl +++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl @@ -73,7 +73,6 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in const float32 Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f; // loop angles - #pragma omp parallel for for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { // variables diff --git a/include/astra/ParallelBeamBlobKernelProjector2D.inl b/include/astra/ParallelBeamBlobKernelProjector2D.inl index e11c4d4..a4045dc 100644 --- a/include/astra/ParallelBeamBlobKernelProjector2D.inl +++ b/include/astra/ParallelBeamBlobKernelProjector2D.inl @@ -127,7 +127,6 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i const int detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles - #pragma omp parallel for for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { // variables diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 3236469..773077d 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -158,7 +158,6 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i const int detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles - #pragma omp parallel for for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { // variables diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index fc5935a..6206d80 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -146,7 +146,6 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, const int detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles - #pragma omp parallel for for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { // variables diff --git a/include/astra/ParallelBeamStripKernelProjector2D.inl b/include/astra/ParallelBeamStripKernelProjector2D.inl index 3a21ed6..040ea11 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.inl +++ b/include/astra/ParallelBeamStripKernelProjector2D.inl @@ -132,7 +132,6 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, const int detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles - #pragma omp parallel for for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { // variables -- cgit v1.2.3 From e1a3f0ba1fe7455d0c9183ad07f106aebc1c821f Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 20 Sep 2017 16:45:41 +0200 Subject: Fix non-square window for CPU projectors --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 2 +- include/astra/ParallelBeamBlobKernelProjector2D.inl | 2 +- include/astra/ParallelBeamLineKernelProjector2D.inl | 2 +- include/astra/ParallelBeamLinearKernelProjector2D.inl | 2 +- include/astra/ParallelBeamStripKernelProjector2D.inl | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'include/astra') diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl index 07d61b5..01f031c 100644 --- a/include/astra/FanFlatBeamLineKernelProjector2D.inl +++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl @@ -69,7 +69,7 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in 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 Ex = m_pVolumeGeometry->getWindowMinX() + pixelLengthX*0.5f; const float32 Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f; // loop angles diff --git a/include/astra/ParallelBeamBlobKernelProjector2D.inl b/include/astra/ParallelBeamBlobKernelProjector2D.inl index a4045dc..67662ad 100644 --- a/include/astra/ParallelBeamBlobKernelProjector2D.inl +++ b/include/astra/ParallelBeamBlobKernelProjector2D.inl @@ -147,7 +147,7 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i 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; + Ex = m_pVolumeGeometry->getWindowMinX() + pixelLengthX*0.5f; Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f; // loop detectors diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 773077d..d88d1cb 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -184,7 +184,7 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i invTminSTimesLengthPerCol = lengthPerCol / (T - S); } - Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f; + Ex = m_pVolumeGeometry->getWindowMinX() + pixelLengthX*0.5f; Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f; // loop detectors diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index 6206d80..ccb8cda 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -166,7 +166,7 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, deltar = -pixelLengthX * RyOverRx * inv_pixelLengthY; } - Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f; + Ex = m_pVolumeGeometry->getWindowMinX() + pixelLengthX*0.5f; Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f; // loop detectors diff --git a/include/astra/ParallelBeamStripKernelProjector2D.inl b/include/astra/ParallelBeamStripKernelProjector2D.inl index 040ea11..4f828f0 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.inl +++ b/include/astra/ParallelBeamStripKernelProjector2D.inl @@ -157,7 +157,7 @@ void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, invTminS = 1.0f / (T-S); } - Ex = m_pVolumeGeometry->getWindowMinY() + pixelLengthX*0.5f; + Ex = m_pVolumeGeometry->getWindowMinX() + pixelLengthX*0.5f; Ey = m_pVolumeGeometry->getWindowMaxY() - pixelLengthY*0.5f; // loop detectors -- cgit v1.2.3 From 1a8243ed0311c3074a79b97e1730bf3409774b8d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 27 Sep 2017 13:57:04 +0200 Subject: Unify some parallel_vec parameter computations --- include/astra/GeometryUtil2D.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/astra') diff --git a/include/astra/GeometryUtil2D.h b/include/astra/GeometryUtil2D.h index 4d79353..914e40d 100644 --- a/include/astra/GeometryUtil2D.h +++ b/include/astra/GeometryUtil2D.h @@ -96,8 +96,11 @@ SFanProjection* genFanProjections(unsigned int iProjAngles, double fDetSize, const float *pfAngles); +bool getParParameters(const SParProjection &proj, unsigned int iProjDets, float &fAngle, float &fDetSize, float &fOffset); + bool getFanParameters(const SFanProjection &proj, unsigned int iProjDets, float &fAngle, float &fOriginSource, float &fOriginDetector, float &fDetSize, float &fOffset); + } #endif -- cgit v1.2.3 From 90ef1f69d79a0c40414c5932dfa9bd69f363ae80 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 10 Oct 2017 13:15:53 +0200 Subject: Scale 2D projection results by detector pixel width The strip and cuda projectors already did this scaling, so this makes the other behave consistently. --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 6 ++++-- include/astra/ParallelBeamLineKernelProjector2D.inl | 6 ++++-- include/astra/ParallelBeamLinearKernelProjector2D.inl | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) (limited to 'include/astra') diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl index 01f031c..c1e1e94 100644 --- a/include/astra/FanFlatBeamLineKernelProjector2D.inl +++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl @@ -82,6 +82,8 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in const SFanProjection * proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; + float32 detSize = sqrt(proj->fDetUX * proj->fDetUX + proj->fDetUY * proj->fDetUY); + // loop detectors for (iDetector = _iDetFrom; iDetector < _iDetTo; ++iDetector) { @@ -99,14 +101,14 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in bool vertical = fabs(Rx) < fabs(Ry); if (vertical) { RxOverRy = Rx/Ry; - lengthPerRow = pixelLengthX * sqrt(Rx*Rx + Ry*Ry) / abs(Ry); + lengthPerRow = detSize * 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 { RyOverRx = Ry/Rx; - lengthPerCol = pixelLengthY * sqrt(Rx*Rx + Ry*Ry) / abs(Rx); + lengthPerCol = detSize * 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); diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index d88d1cb..e516fe1 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -167,17 +167,19 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i const SParProjection * proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; + float32 detSize = sqrt(proj->fDetUX * proj->fDetUX + proj->fDetUY * proj->fDetUY); + bool vertical = fabs(proj->fRayX) < fabs(proj->fRayY); if (vertical) { RxOverRy = proj->fRayX/proj->fRayY; - lengthPerRow = pixelLengthX * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayY); + lengthPerRow = detSize * 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 { RyOverRx = proj->fRayY/proj->fRayX; - lengthPerCol = pixelLengthY * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayX); + lengthPerCol = detSize * 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); diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index ccb8cda..d2c529f 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -155,14 +155,16 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, const SParProjection * proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; + float32 detSize = sqrt(proj->fDetUX * proj->fDetUX + proj->fDetUY * proj->fDetUY); + 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); + lengthPerRow = detSize * m_pVolumeGeometry->getPixelLengthX() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayY); 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); + lengthPerCol = detSize * m_pVolumeGeometry->getPixelLengthY() * sqrt(proj->fRayY*proj->fRayY + proj->fRayX*proj->fRayX) / abs(proj->fRayX); deltar = -pixelLengthX * RyOverRx * inv_pixelLengthY; } -- cgit v1.2.3 From f87ca86a994cdc3205a294e9bbbeddde312ea53b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 11 Oct 2017 11:32:28 +0200 Subject: Make geometry config checks slightly less numerically strict --- include/astra/Globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/astra') diff --git a/include/astra/Globals.h b/include/astra/Globals.h index 8375726..0adc3e5 100644 --- a/include/astra/Globals.h +++ b/include/astra/Globals.h @@ -142,7 +142,7 @@ namespace astra { const float32 PI32 = 3.14159265358979323846264338328f; const float32 PIdiv2 = PI / 2; const float32 PIdiv4 = PI / 4; - const float32 eps = 1e-7f; + const float32 eps = 1e-6f; extern _AstraExport bool running_in_matlab; } -- cgit v1.2.3 From 08df6c4167118e0a3b5f128078f9c13f206a171a Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 12 Oct 2017 15:17:10 +0200 Subject: Fix some warnings --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 22 ++- .../astra/ParallelBeamBlobKernelProjector2D.inl | 1 - .../astra/ParallelBeamLineKernelProjector2D.inl | 179 ++++++++++----------- .../astra/ParallelBeamLinearKernelProjector2D.inl | 151 +++++++++-------- .../astra/ParallelBeamStripKernelProjector2D.inl | 126 +++++++-------- 5 files changed, 236 insertions(+), 243 deletions(-) (limited to 'include/astra') diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl index c1e1e94..927aa09 100644 --- a/include/astra/FanFlatBeamLineKernelProjector2D.inl +++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl @@ -99,6 +99,9 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in Ry = proj->fSrcY - Dy; bool vertical = fabs(Rx) < fabs(Ry); + bool isin = false; + + // vertically if (vertical) { RxOverRy = Rx/Ry; lengthPerRow = detSize * pixelLengthX * sqrt(Rx*Rx + Ry*Ry) / abs(Ry); @@ -106,19 +109,6 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in S = 0.5f - 0.5f*fabs(RxOverRy); T = 0.5f + 0.5f*fabs(RxOverRy); invTminSTimesLengthPerRow = lengthPerRow / (T - S); - } else { - RyOverRx = Ry/Rx; - lengthPerCol = detSize * 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 c for row 0 c = (Dx + (Ey - Dy)*RxOverRy - Ex) * inv_pixelLengthX; @@ -163,6 +153,12 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in // horizontally else { + RyOverRx = Ry/Rx; + lengthPerCol = detSize * 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); // calculate r for col 0 r = -(Dy + (Ex - Dx)*RyOverRx - Ey) * inv_pixelLengthY; diff --git a/include/astra/ParallelBeamBlobKernelProjector2D.inl b/include/astra/ParallelBeamBlobKernelProjector2D.inl index 67662ad..ccd2166 100644 --- a/include/astra/ParallelBeamBlobKernelProjector2D.inl +++ b/include/astra/ParallelBeamBlobKernelProjector2D.inl @@ -124,7 +124,6 @@ void CParallelBeamBlobKernelProjector2D::projectBlock_internal(int _iProjFrom, i const float32 inv_pixelLengthY = 1.0f / m_pVolumeGeometry->getPixelLengthY(); const int colCount = m_pVolumeGeometry->getGridColCount(); const int rowCount = m_pVolumeGeometry->getGridRowCount(); - const int detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index e516fe1..7db0a34 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -49,94 +49,94 @@ 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 -// +/* 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 void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { @@ -155,7 +155,6 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i const float32 inv_pixelLengthY = 1.0f / pixelLengthY; const int colCount = m_pVolumeGeometry->getGridColCount(); const int rowCount = m_pVolumeGeometry->getGridRowCount(); - const int detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { @@ -163,7 +162,7 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i // variables 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; + int iVolumeIndex, iRayIndex, row, col; const SParProjection * proj = &pVecProjectionGeometry->getProjectionVectors()[iAngle]; diff --git a/include/astra/ParallelBeamLinearKernelProjector2D.inl b/include/astra/ParallelBeamLinearKernelProjector2D.inl index d2c529f..61e4973 100644 --- a/include/astra/ParallelBeamLinearKernelProjector2D.inl +++ b/include/astra/ParallelBeamLinearKernelProjector2D.inl @@ -51,80 +51,80 @@ 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 -// +/* 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 void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { @@ -143,13 +143,12 @@ void CParallelBeamLinearKernelProjector2D::projectBlock_internal(int _iProjFrom, const float32 inv_pixelLengthY = 1.0f / pixelLengthY; const int colCount = m_pVolumeGeometry->getGridColCount(); const int rowCount = m_pVolumeGeometry->getGridRowCount(); - const int detCount = pVecProjectionGeometry->getDetectorCount(); // loop angles for (int iAngle = _iProjFrom; iAngle < _iProjTo; ++iAngle) { // variables - float32 Dx, Dy, Ex, Ey, x, y, c, r, deltac, deltar, offset; + float32 Dx, Dy, Ex, Ey, c, r, deltac, deltar, offset; float32 RxOverRy, RyOverRx, lengthPerRow, lengthPerCol; int iVolumeIndex, iRayIndex, row, col, iDetector; diff --git a/include/astra/ParallelBeamStripKernelProjector2D.inl b/include/astra/ParallelBeamStripKernelProjector2D.inl index 4f828f0..fdfcd90 100644 --- a/include/astra/ParallelBeamStripKernelProjector2D.inl +++ b/include/astra/ParallelBeamStripKernelProjector2D.inl @@ -47,69 +47,69 @@ 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 -// +/* 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 void CParallelBeamStripKernelProjector2D::projectBlock_internal(int _iProjFrom, int _iProjTo, int _iDetFrom, int _iDetTo, Policy& p) { -- cgit v1.2.3 From 6ccba6087654fbbd16644e7f0fd93daed479f9d3 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 28 Nov 2017 14:01:16 +0100 Subject: Fix FanFlatBeamLineKernelProjector memleak --- include/astra/FanFlatBeamLineKernelProjector2D.inl | 4 ++++ include/astra/ParallelBeamLineKernelProjector2D.inl | 1 + 2 files changed, 5 insertions(+) (limited to 'include/astra') diff --git a/include/astra/FanFlatBeamLineKernelProjector2D.inl b/include/astra/FanFlatBeamLineKernelProjector2D.inl index 927aa09..eb73de8 100644 --- a/include/astra/FanFlatBeamLineKernelProjector2D.inl +++ b/include/astra/FanFlatBeamLineKernelProjector2D.inl @@ -207,4 +207,8 @@ void CFanFlatBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, in } // end loop detector } // end loop angles + // Delete created vec geometry if required + if (dynamic_cast(m_pProjectionGeometry)) + delete pVecProjectionGeometry; + } diff --git a/include/astra/ParallelBeamLineKernelProjector2D.inl b/include/astra/ParallelBeamLineKernelProjector2D.inl index 7db0a34..d07f989 100644 --- a/include/astra/ParallelBeamLineKernelProjector2D.inl +++ b/include/astra/ParallelBeamLineKernelProjector2D.inl @@ -295,6 +295,7 @@ void CParallelBeamLineKernelProjector2D::projectBlock_internal(int _iProjFrom, i } // end loop detector } // end loop angles + // Delete created vec geometry if required if (dynamic_cast(m_pProjectionGeometry)) delete pVecProjectionGeometry; -- cgit v1.2.3