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/ProjectionGeometry3D.cpp | 71 +++++++++++++++++++++++++++++++++----------- 1 file changed, 53 insertions(+), 18 deletions(-) (limited to 'src/ProjectionGeometry3D.cpp') diff --git a/src/ProjectionGeometry3D.cpp b/src/ProjectionGeometry3D.cpp index bea88ab..92de247 100644 --- a/src/ProjectionGeometry3D.cpp +++ b/src/ProjectionGeometry3D.cpp @@ -133,7 +133,7 @@ void CProjectionGeometry3D::clear() } //---------------------------------------------------------------------------------------- -// Initialization witha Config object +// Initialization with a Config object bool CProjectionGeometry3D::initialize(const Config& _cfg) { ASTRA_ASSERT(_cfg.self); @@ -145,35 +145,70 @@ bool CProjectionGeometry3D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); - // Required: DetectorWidth - XMLNode node = _cfg.self.getSingleNode("DetectorSpacingX"); - ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingX tag specified."); - m_fDetectorSpacingX = node.getContentNumerical(); - CC.markNodeParsed("DetectorSpacingX"); - - // Required: DetectorHeight - node = _cfg.self.getSingleNode("DetectorSpacingY"); - ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingY tag specified."); - m_fDetectorSpacingY = node.getContentNumerical(); - CC.markNodeParsed("DetectorSpacingY"); // Required: DetectorRowCount - node = _cfg.self.getSingleNode("DetectorRowCount"); + XMLNode node = _cfg.self.getSingleNode("DetectorRowCount"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorRowCount tag specified."); - m_iDetectorRowCount = node.getContentInt(); + try { + m_iDetectorRowCount = node.getContentInt(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry3D", "DetectorRowCount must be an integer."); + } CC.markNodeParsed("DetectorRowCount"); // Required: DetectorCount node = _cfg.self.getSingleNode("DetectorColCount"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorColCount tag specified."); - m_iDetectorColCount = node.getContentInt(); + try { + m_iDetectorColCount = node.getContentInt(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry3D", "DetectorColCount must be an integer."); + } m_iDetectorTotCount = m_iDetectorRowCount * m_iDetectorColCount; CC.markNodeParsed("DetectorColCount"); + + if (!initializeAngles(_cfg)) + return false; + + + // Interface class, so don't return true + return false; +} + +bool CProjectionGeometry3D::initializeAngles(const Config& _cfg) +{ + ConfigStackCheck CC("ProjectionGeometry3D", this, _cfg); + + // Required: DetectorWidth + XMLNode node = _cfg.self.getSingleNode("DetectorSpacingX"); + ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingX tag specified."); + try { + m_fDetectorSpacingX = node.getContentNumerical(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry3D", "DetectorSpacingX must be numerical."); + } + CC.markNodeParsed("DetectorSpacingX"); + + // Required: DetectorHeight + node = _cfg.self.getSingleNode("DetectorSpacingY"); + ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingY tag specified."); + try { + m_fDetectorSpacingY = node.getContentNumerical(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry3D", "DetectorSpacingY must be numerical."); + } + CC.markNodeParsed("DetectorSpacingY"); + // Required: ProjectionAngles node = _cfg.self.getSingleNode("ProjectionAngles"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No ProjectionAngles tag specified."); - vector angles = node.getContentNumericalArray(); + vector angles; + try { + angles = node.getContentNumericalArray(); + } catch (const StringUtil::bad_cast &e) { + ASTRA_CONFIG_CHECK(false, "ProjectionGeometry3D", "ProjectionAngles must be a numerical vector."); + } m_iProjectionAngleCount = angles.size(); ASTRA_CONFIG_CHECK(m_iProjectionAngleCount > 0, "ProjectionGeometry3D", "Not enough ProjectionAngles specified."); m_pfProjectionAngles = new float32[m_iProjectionAngleCount]; @@ -182,8 +217,8 @@ bool CProjectionGeometry3D::initialize(const Config& _cfg) } CC.markNodeParsed("ProjectionAngles"); - // Interface class, so don't return true - return false; + + return true; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3