From 8220a50be6bcbddf179bb855b2f7d36436fcca6b Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 7 Dec 2018 16:41:40 +0100 Subject: More gracefully handle config errors in geometries --- src/ParallelVecProjectionGeometry2D.cpp | 44 +++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 19 deletions(-) (limited to 'src/ParallelVecProjectionGeometry2D.cpp') diff --git a/src/ParallelVecProjectionGeometry2D.cpp b/src/ParallelVecProjectionGeometry2D.cpp index 8905a26..30682c5 100644 --- a/src/ParallelVecProjectionGeometry2D.cpp +++ b/src/ParallelVecProjectionGeometry2D.cpp @@ -29,7 +29,6 @@ along with the ASTRA Toolbox. If not, see . #include #include -#include using namespace std; @@ -100,20 +99,29 @@ bool CParallelVecProjectionGeometry2D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); ConfigStackCheck CC("ParallelVecProjectionGeometry2D", this, _cfg); - // TODO: Fix up class hierarchy... this class doesn't fit very well. // initialization of parent class - //CProjectionGeometry2D::initialize(_cfg); + CProjectionGeometry2D::initialize(_cfg); - // Required: DetectorCount - XMLNode node = _cfg.self.getSingleNode("DetectorCount"); - ASTRA_CONFIG_CHECK(node, "ParallelVecProjectionGeometry2D", "No DetectorRowCount tag specified."); - m_iDetectorCount = boost::lexical_cast(node.getContent()); - CC.markNodeParsed("DetectorCount"); + + // success + m_bInitialized = _check(); + return m_bInitialized; +} + +bool CParallelVecProjectionGeometry2D::initializeAngles(const Config& _cfg) +{ + ConfigStackCheck CC("ParallelVecProjectionGeometry2D", this, _cfg); // Required: Vectors - node = _cfg.self.getSingleNode("Vectors"); + XMLNode node = _cfg.self.getSingleNode("Vectors"); ASTRA_CONFIG_CHECK(node, "ParallelVecProjectionGeometry2D", "No Vectors tag specified."); - vector data = node.getContentNumericalArray(); + vector data; + try { + data = node.getContentNumericalArray(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ParallelVecProjectionGeometry2D", "Vectors must be a numerical matrix."); + } + CC.markNodeParsed("Vectors"); ASTRA_CONFIG_CHECK(data.size() % 6 == 0, "ParallelVecProjectionGeometry2D", "Vectors doesn't consist of 6-tuples."); m_iProjectionAngleCount = data.size() / 6; @@ -132,9 +140,7 @@ bool CParallelVecProjectionGeometry2D::initialize(const Config& _cfg) p.fDetSY = data[6*i + 3] - 0.5f * m_iDetectorCount * p.fDetUY; } - // success - m_bInitialized = _check(); - return m_bInitialized; + return true; } //---------------------------------------------------------------------------------------- @@ -215,12 +221,12 @@ Config* CParallelVecProjectionGeometry2D::getConfiguration() const std::string vectors = ""; for (int i = 0; i < m_iProjectionAngleCount; ++i) { SParProjection& p = m_pProjectionAngles[i]; - vectors += boost::lexical_cast(p.fRayX) + ","; - vectors += boost::lexical_cast(p.fRayY) + ","; - vectors += boost::lexical_cast(p.fDetSX + 0.5f * m_iDetectorCount * p.fDetUX) + ","; - vectors += boost::lexical_cast(p.fDetSY + 0.5f * m_iDetectorCount * p.fDetUY) + ","; - vectors += boost::lexical_cast(p.fDetUX) + ","; - vectors += boost::lexical_cast(p.fDetUY); + vectors += StringUtil::toString(p.fRayX) + ","; + vectors += StringUtil::toString(p.fRayY) + ","; + vectors += StringUtil::toString(p.fDetSX + 0.5f * m_iDetectorCount * p.fDetUX) + ","; + vectors += StringUtil::toString(p.fDetSY + 0.5f * m_iDetectorCount * p.fDetUY) + ","; + vectors += StringUtil::toString(p.fDetUX) + ","; + vectors += StringUtil::toString(p.fDetUY); if (i < m_iProjectionAngleCount-1) vectors += ';'; } cfg->self.addChildNode("Vectors", vectors); -- cgit v1.2.3