summaryrefslogtreecommitdiffstats
path: root/src/CudaReconstructionAlgorithm2D.cpp
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2016-07-28 17:05:24 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2016-07-28 17:05:24 +0200
commitb2611a03577c285ddf48edab0d05dafa09ab362c (patch)
treec1d2f1b5166ba23f55e68e8faf0832f7c540f787 /src/CudaReconstructionAlgorithm2D.cpp
parent1ff4a270a7df1edb54dd91fe653d6a936b959b3a (diff)
parent53249b3ad63f0d08b9862a75602acf263d230d77 (diff)
downloadastra-b2611a03577c285ddf48edab0d05dafa09ab362c.tar.gz
astra-b2611a03577c285ddf48edab0d05dafa09ab362c.tar.bz2
astra-b2611a03577c285ddf48edab0d05dafa09ab362c.tar.xz
astra-b2611a03577c285ddf48edab0d05dafa09ab362c.zip
Merge branch 'master' into parvec
Diffstat (limited to 'src/CudaReconstructionAlgorithm2D.cpp')
-rw-r--r--src/CudaReconstructionAlgorithm2D.cpp213
1 files changed, 67 insertions, 146 deletions
diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp
index db99d42..2798434 100644
--- a/src/CudaReconstructionAlgorithm2D.cpp
+++ b/src/CudaReconstructionAlgorithm2D.cpp
@@ -30,8 +30,6 @@ $Id$
#include "astra/CudaReconstructionAlgorithm2D.h"
-#include <boost/lexical_cast.hpp>
-
#include "astra/AstraObjectManager.h"
#include "astra/FanFlatProjectionGeometry2D.h"
#include "astra/FanFlatVecProjectionGeometry2D.h"
@@ -84,103 +82,51 @@ void CCudaReconstructionAlgorithm2D::_clear()
}
//---------------------------------------------------------------------------------------
+void CCudaReconstructionAlgorithm2D::initializeFromProjector()
+{
+ m_iPixelSuperSampling = 1;
+ m_iDetectorSuperSampling = 1;
+ m_iGPUIndex = -1;
+
+ // Projector
+ CCudaProjector2D* pCudaProjector = dynamic_cast<CCudaProjector2D*>(m_pProjector);
+ if (!pCudaProjector) {
+ if (m_pProjector) {
+ ASTRA_WARN("non-CUDA Projector2D passed");
+ }
+ } else {
+ m_iDetectorSuperSampling = pCudaProjector->getDetectorSuperSampling();
+ m_iPixelSuperSampling = pCudaProjector->getVoxelSuperSampling();
+ m_iGPUIndex = pCudaProjector->getGPUIndex();
+ }
+}
+
+//---------------------------------------------------------------------------------------
// Initialize - Config
bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg)
{
ASTRA_ASSERT(_cfg.self);
ConfigStackCheck<CAlgorithm> CC("CudaReconstructionAlgorithm2D", this, _cfg);
- // if already initialized, clear first
- if (m_bIsInitialized) {
- clear();
- }
-
- // sinogram data
- XMLNode node = _cfg.self.getSingleNode("ProjectionDataId");
- ASTRA_CONFIG_CHECK(node, "CudaSirt2", "No ProjectionDataId tag specified.");
- int id = boost::lexical_cast<int>(node.getContent());
- m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- CC.markNodeParsed("ProjectionDataId");
-
- // reconstruction data
- node = _cfg.self.getSingleNode("ReconstructionDataId");
- ASTRA_CONFIG_CHECK(node, "CudaSirt2", "No ReconstructionDataId tag specified.");
- id = boost::lexical_cast<int>(node.getContent());
- m_pReconstruction = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- CC.markNodeParsed("ReconstructionDataId");
-
- // fixed mask
- if (_cfg.self.hasOption("ReconstructionMaskId")) {
- m_bUseReconstructionMask = true;
- id = boost::lexical_cast<int>(_cfg.self.getOption("ReconstructionMaskId"));
- m_pReconstructionMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_CONFIG_CHECK(m_pReconstructionMask, "CudaReconstruction2D", "Invalid ReconstructionMaskId.");
- }
- CC.markOptionParsed("ReconstructionMaskId");
- // fixed mask
- if (_cfg.self.hasOption("SinogramMaskId")) {
- m_bUseSinogramMask = true;
- id = boost::lexical_cast<int>(_cfg.self.getOption("SinogramMaskId"));
- m_pSinogramMask = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_CONFIG_CHECK(m_pSinogramMask, "CudaReconstruction2D", "Invalid SinogramMaskId.");
- }
- CC.markOptionParsed("SinogramMaskId");
+ m_bIsInitialized = CReconstructionAlgorithm2D::initialize(_cfg);
- // Constraints - NEW
- if (_cfg.self.hasOption("MinConstraint")) {
- m_bUseMinConstraint = true;
- m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f);
- CC.markOptionParsed("MinConstraint");
- } else {
- // Constraint - OLD
- m_bUseMinConstraint = _cfg.self.getOptionBool("UseMinConstraint", false);
- CC.markOptionParsed("UseMinConstraint");
- if (m_bUseMinConstraint) {
- m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f);
- CC.markOptionParsed("MinConstraintValue");
- }
- }
- if (_cfg.self.hasOption("MaxConstraint")) {
- m_bUseMaxConstraint = true;
- m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f);
- CC.markOptionParsed("MaxConstraint");
- } else {
- // Constraint - OLD
- m_bUseMaxConstraint = _cfg.self.getOptionBool("UseMaxConstraint", false);
- CC.markOptionParsed("UseMaxConstraint");
- if (m_bUseMaxConstraint) {
- m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 0.0f);
- CC.markOptionParsed("MaxConstraintValue");
- }
- }
+ if (!m_bIsInitialized)
+ return false;
- // GPU number
- m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
- m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
- CC.markOptionParsed("GPUindex");
- if (!_cfg.self.hasOption("GPUindex"))
- CC.markOptionParsed("GPUIndex");
+ initializeFromProjector();
- // Detector supersampling factor
- m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1);
+ // Deprecated options
+ m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", m_iDetectorSuperSampling);
+ m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", m_iPixelSuperSampling);
CC.markOptionParsed("DetectorSuperSampling");
-
- // Pixel supersampling factor
- m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", 1);
CC.markOptionParsed("PixelSuperSampling");
-
- // This isn't used yet, but passing it is not something to warn about
- node = _cfg.self.getSingleNode("ProjectorId");
- if (node) {
- id = boost::lexical_cast<int>(node.getContent());
- CProjector2D *projector = CProjector2DManager::getSingleton().get(id);
- if (!dynamic_cast<CCudaProjector2D*>(projector)) {
- ASTRA_WARN("non-CUDA Projector2D passed");
- }
- }
- CC.markNodeParsed("ProjectorId");
-
+ // GPU number
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1);
+ m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex);
+ CC.markOptionParsed("GPUIndex");
+ if (!_cfg.self.hasOption("GPUIndex"))
+ CC.markOptionParsed("GPUindex");
return _check();
}
@@ -191,32 +137,18 @@ bool CCudaReconstructionAlgorithm2D::initialize(CProjector2D* _pProjector,
CFloat32ProjectionData2D* _pSinogram,
CFloat32VolumeData2D* _pReconstruction)
{
- return initialize(_pProjector, _pSinogram, _pReconstruction, 0, 1);
-}
-
-//---------------------------------------------------------------------------------------
-// Initialize - C++
-bool CCudaReconstructionAlgorithm2D::initialize(CProjector2D* _pProjector,
- CFloat32ProjectionData2D* _pSinogram,
- CFloat32VolumeData2D* _pReconstruction,
- int _iGPUindex,
- int _iDetectorSuperSampling,
- int _iPixelSuperSampling)
-{
// if already initialized, clear first
if (m_bIsInitialized) {
clear();
}
- m_pProjector = 0;
+ m_pProjector = _pProjector;
// required classes
m_pSinogram = _pSinogram;
m_pReconstruction = _pReconstruction;
- m_iDetectorSuperSampling = _iDetectorSuperSampling;
- m_iPixelSuperSampling = _iPixelSuperSampling;
- m_iGPUIndex = _iGPUindex;
+ initializeFromProjector();
return _check();
}
@@ -226,40 +158,13 @@ bool CCudaReconstructionAlgorithm2D::initialize(CProjector2D* _pProjector,
// Check
bool CCudaReconstructionAlgorithm2D::_check()
{
- // TODO: CLEAN UP
-
-
- // check pointers
- //ASTRA_CONFIG_CHECK(m_pProjector, "Reconstruction2D", "Invalid Projector Object.");
- ASTRA_CONFIG_CHECK(m_pSinogram, "SIRT_CUDA", "Invalid Projection Data Object.");
- ASTRA_CONFIG_CHECK(m_pReconstruction, "SIRT_CUDA", "Invalid Reconstruction Data Object.");
-
- // check initializations
- //ASTRA_CONFIG_CHECK(m_pProjector->isInitialized(), "Reconstruction2D", "Projector Object Not Initialized.");
- ASTRA_CONFIG_CHECK(m_pSinogram->isInitialized(), "SIRT_CUDA", "Projection Data Object Not Initialized.");
- ASTRA_CONFIG_CHECK(m_pReconstruction->isInitialized(), "SIRT_CUDA", "Reconstruction Data Object Not Initialized.");
-
- ASTRA_CONFIG_CHECK(m_iDetectorSuperSampling >= 1, "SIRT_CUDA", "DetectorSuperSampling must be a positive integer.");
- ASTRA_CONFIG_CHECK(m_iPixelSuperSampling >= 1, "SIRT_CUDA", "PixelSuperSampling must be a positive integer.");
- ASTRA_CONFIG_CHECK(m_iGPUIndex >= -1, "SIRT_CUDA", "GPUIndex must be a non-negative integer.");
-
- // check compatibility between projector and data classes
-// ASTRA_CONFIG_CHECK(m_pSinogram->getGeometry()->isEqual(m_pProjector->getProjectionGeometry()), "SIRT_CUDA", "Projection Data not compatible with the specified Projector.");
-// ASTRA_CONFIG_CHECK(m_pReconstruction->getGeometry()->isEqual(m_pProjector->getVolumeGeometry()), "SIRT_CUDA", "Reconstruction Data not compatible with the specified Projector.");
-
- // todo: turn some of these back on
+ if (!CReconstructionAlgorithm2D::_check())
+ return false;
-// ASTRA_CONFIG_CHECK(m_pProjectionGeometry, "SIRT_CUDA", "ProjectionGeometry not specified.");
-// ASTRA_CONFIG_CHECK(m_pProjectionGeometry->isInitialized(), "SIRT_CUDA", "ProjectionGeometry not initialized.");
-// ASTRA_CONFIG_CHECK(m_pReconstructionGeometry, "SIRT_CUDA", "ReconstructionGeometry not specified.");
-// ASTRA_CONFIG_CHECK(m_pReconstructionGeometry->isInitialized(), "SIRT_CUDA", "ReconstructionGeometry not initialized.");
+ ASTRA_CONFIG_CHECK(m_iDetectorSuperSampling >= 1, "CudaReconstructionAlgorithm2D", "DetectorSuperSampling must be a positive integer.");
+ ASTRA_CONFIG_CHECK(m_iPixelSuperSampling >= 1, "CudaReconstructionAlgorithm2D", "PixelSuperSampling must be a positive integer.");
+ ASTRA_CONFIG_CHECK(m_iGPUIndex >= -1, "CudaReconstructionAlgorithm2D", "GPUIndex must be a non-negative integer or -1.");
- // check dimensions
- //ASTRA_CONFIG_CHECK(m_pSinogram->getAngleCount() == m_pProjectionGeometry->getProjectionAngleCount(), "SIRT_CUDA", "Sinogram data object size mismatch.");
- //ASTRA_CONFIG_CHECK(m_pSinogram->getDetectorCount() == m_pProjectionGeometry->getDetectorCount(), "SIRT_CUDA", "Sinogram data object size mismatch.");
- //ASTRA_CONFIG_CHECK(m_pReconstruction->getWidth() == m_pReconstructionGeometry->getGridColCount(), "SIRT_CUDA", "Reconstruction data object size mismatch.");
- //ASTRA_CONFIG_CHECK(m_pReconstruction->getHeight() == m_pReconstructionGeometry->getGridRowCount(), "SIRT_CUDA", "Reconstruction data object size mismatch.");
-
// check restrictions
// TODO: check restrictions built into cuda code
@@ -424,6 +329,20 @@ bool CCudaReconstructionAlgorithm2D::setupGeometry()
}
//----------------------------------------------------------------------------------------
+
+void CCudaReconstructionAlgorithm2D::initCUDAAlgorithm()
+{
+ bool ok;
+
+ ok = setupGeometry();
+ ASTRA_ASSERT(ok);
+
+ ok = m_pAlgo->allocateBuffers();
+ ASTRA_ASSERT(ok);
+}
+
+
+//----------------------------------------------------------------------------------------
// Iterate
void CCudaReconstructionAlgorithm2D::run(int _iNrIterations)
{
@@ -434,13 +353,7 @@ void CCudaReconstructionAlgorithm2D::run(int _iNrIterations)
const CVolumeGeometry2D& volgeom = *m_pReconstruction->getGeometry();
if (!m_bAlgoInit) {
-
- ok = setupGeometry();
- ASTRA_ASSERT(ok);
-
- ok = m_pAlgo->allocateBuffers();
- ASTRA_ASSERT(ok);
-
+ initCUDAAlgorithm();
m_bAlgoInit = true;
}
@@ -454,10 +367,18 @@ void CCudaReconstructionAlgorithm2D::run(int _iNrIterations)
ASTRA_ASSERT(ok);
- if (m_bUseMinConstraint)
- ok &= m_pAlgo->setMinConstraint(m_fMinValue);
- if (m_bUseMaxConstraint)
- ok &= m_pAlgo->setMaxConstraint(m_fMaxValue);
+ if (m_bUseMinConstraint) {
+ bool ret = m_pAlgo->setMinConstraint(m_fMinValue);
+ if (!ret) {
+ ASTRA_WARN("This algorithm ignores MinConstraint");
+ }
+ }
+ if (m_bUseMaxConstraint) {
+ bool ret= m_pAlgo->setMaxConstraint(m_fMaxValue);
+ if (!ret) {
+ ASTRA_WARN("This algorithm ignores MaxConstraint");
+ }
+ }
ok &= m_pAlgo->iterate(_iNrIterations);
ASTRA_ASSERT(ok);