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/ProjectionGeometry2D.cpp | 50 ++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 13 deletions(-) (limited to 'src/ProjectionGeometry2D.cpp') diff --git a/src/ProjectionGeometry2D.cpp b/src/ProjectionGeometry2D.cpp index 64674bf..15be1d5 100644 --- a/src/ProjectionGeometry2D.cpp +++ b/src/ProjectionGeometry2D.cpp @@ -116,22 +116,50 @@ bool CProjectionGeometry2D::initialize(const Config& _cfg) clear(); } + // Required: DetectorCount + XMLNode node = _cfg.self.getSingleNode("DetectorCount"); + ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No DetectorCount tag specified."); + try { + m_iDetectorCount = node.getContentInt(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry2D", "DetectorCount must be an integer."); + } + CC.markNodeParsed("DetectorCount"); + + if (!initializeAngles(_cfg)) + return false; + + // some checks + ASTRA_CONFIG_CHECK(m_iDetectorCount > 0, "ProjectionGeometry2D", "DetectorCount should be positive."); + + // Interface class, so don't return true + return false; +} + +bool CProjectionGeometry2D::initializeAngles(const Config& _cfg) +{ + ConfigStackCheck CC("ProjectionGeometry2D", this, _cfg); + // Required: DetectorWidth XMLNode node = _cfg.self.getSingleNode("DetectorWidth"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No DetectorWidth tag specified."); - m_fDetectorWidth = node.getContentNumerical(); + try { + m_fDetectorWidth = node.getContentNumerical(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry2D", "DetectorWidth must be numerical."); + } CC.markNodeParsed("DetectorWidth"); - // Required: DetectorCount - node = _cfg.self.getSingleNode("DetectorCount"); - ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No DetectorCount tag specified."); - m_iDetectorCount = node.getContentInt(); - CC.markNodeParsed("DetectorCount"); // Required: ProjectionAngles node = _cfg.self.getSingleNode("ProjectionAngles"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No ProjectionAngles tag specified."); - vector angles = node.getContentNumericalArray(); + vector angles; + try { + angles = node.getContentNumericalArray(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry2D", "ProjectionAngles must be a numerical vector."); + } m_iProjectionAngleCount = angles.size(); ASTRA_CONFIG_CHECK(m_iProjectionAngleCount > 0, "ProjectionGeometry2D", "Not enough ProjectionAngles specified."); m_pfProjectionAngles = new float32[m_iProjectionAngleCount]; @@ -139,14 +167,10 @@ bool CProjectionGeometry2D::initialize(const Config& _cfg) m_pfProjectionAngles[i] = angles[i]; } CC.markNodeParsed("ProjectionAngles"); - - // some checks - ASTRA_CONFIG_CHECK(m_iDetectorCount > 0, "ProjectionGeometry2D", "DetectorCount should be positive."); - ASTRA_CONFIG_CHECK(m_fDetectorWidth > 0.0f, "ProjectionGeometry2D", "DetectorWidth should be positive."); ASTRA_CONFIG_CHECK(m_pfProjectionAngles != NULL, "ProjectionGeometry2D", "ProjectionAngles not initialized"); - // Interface class, so don't return true - return false; + ASTRA_CONFIG_CHECK(m_fDetectorWidth > 0.0f, "ProjectionGeometry2D", "DetectorWidth should be positive."); + return true; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3