summaryrefslogtreecommitdiffstats
path: root/src/ReconstructionAlgorithm2D.cpp
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2018-12-12 11:25:33 +0100
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2018-12-23 16:58:03 +0100
commit74feef4718770d20273aa97f9176484149f178ae (patch)
treed7c52cb57a60cc85d6326901cc71ff09986f11a4 /src/ReconstructionAlgorithm2D.cpp
parent8220a50be6bcbddf179bb855b2f7d36436fcca6b (diff)
downloadastra-74feef4718770d20273aa97f9176484149f178ae.tar.gz
astra-74feef4718770d20273aa97f9176484149f178ae.tar.bz2
astra-74feef4718770d20273aa97f9176484149f178ae.tar.xz
astra-74feef4718770d20273aa97f9176484149f178ae.zip
Improve config error handling
Diffstat (limited to 'src/ReconstructionAlgorithm2D.cpp')
-rw-r--r--src/ReconstructionAlgorithm2D.cpp50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/ReconstructionAlgorithm2D.cpp b/src/ReconstructionAlgorithm2D.cpp
index 9d1aa1d..781b391 100644
--- a/src/ReconstructionAlgorithm2D.cpp
+++ b/src/ReconstructionAlgorithm2D.cpp
@@ -28,6 +28,7 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
#include "astra/ReconstructionAlgorithm2D.h"
#include "astra/AstraObjectManager.h"
+#include "astra/Logging.h"
using namespace std;
@@ -85,33 +86,36 @@ bool CReconstructionAlgorithm2D::initialize(const Config& _cfg)
if (requiresProjector()) {
ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ProjectorId tag specified.");
}
- int id;
+ m_pProjector = 0;
+ int id = -1;
if (node) {
- id = node.getContentInt();
+ id = StringUtil::stringToInt(node.getContent(), -1);
m_pProjector = CProjector2DManager::getSingleton().get(id);
- } else {
- m_pProjector = 0;
+ if (!m_pProjector) {
+ // Report this explicitly since projector is optional
+ ASTRA_ERROR("ProjectorId is not a valid id");
+ }
}
CC.markNodeParsed("ProjectorId");
// sinogram data
node = _cfg.self.getSingleNode("ProjectionDataId");
ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ProjectionDataId tag specified.");
- id = node.getContentInt();
+ id = StringUtil::stringToInt(node.getContent(), -1);
m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
CC.markNodeParsed("ProjectionDataId");
// reconstruction data
node = _cfg.self.getSingleNode("ReconstructionDataId");
ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ReconstructionDataId tag specified.");
- id = node.getContentInt();
+ id = StringUtil::stringToInt(node.getContent(), -1);
m_pReconstruction = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
CC.markNodeParsed("ReconstructionDataId");
// fixed mask
if (_cfg.self.hasOption("ReconstructionMaskId")) {
m_bUseReconstructionMask = true;
- id = _cfg.self.getOptionInt("ReconstructionMaskId");
+ id = StringUtil::stringToInt(_cfg.self.getOption("ReconstructionMaskId"), -1);
m_pReconstructionMask = dynamic_cast<CFloat32VolumeData2D*>(CData2DManager::getSingleton().get(id));
ASTRA_CONFIG_CHECK(m_pReconstructionMask, "Reconstruction2D", "Invalid ReconstructionMaskId.");
}
@@ -120,36 +124,56 @@ bool CReconstructionAlgorithm2D::initialize(const Config& _cfg)
// fixed mask
if (_cfg.self.hasOption("SinogramMaskId")) {
m_bUseSinogramMask = true;
- id = _cfg.self.getOptionInt("SinogramMaskId");
+ id = StringUtil::stringToInt(_cfg.self.getOption("SinogramMaskId"), -1);
m_pSinogramMask = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id));
- ASTRA_CONFIG_CHECK(m_pSinogramMask, "Reconstruction2D", "Invalid SinogramMaskId.");
+ ASTRA_CONFIG_CHECK(m_pSinogramMask, "ReconstructionAlgorithm2D", "Invalid SinogramMaskId.");
}
CC.markOptionParsed("SinogramMaskId");
// Constraints - NEW
if (_cfg.self.hasOption("MinConstraint")) {
m_bUseMinConstraint = true;
- m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f);
+ try {
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f);
+ } catch (const astra::StringUtil::bad_cast &e) {
+ m_fMinValue = 0.0f;
+ ASTRA_ERROR("MinConstraint must be numerical");
+ }
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);
+ try {
+ m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f);
+ } catch (const astra::StringUtil::bad_cast &e) {
+ m_fMinValue = 0.0f;
+ ASTRA_ERROR("MinConstraintValue must be numerical");
+ }
CC.markOptionParsed("MinConstraintValue");
}
}
if (_cfg.self.hasOption("MaxConstraint")) {
m_bUseMaxConstraint = true;
- m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f);
+ try {
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f);
+ } catch (const astra::StringUtil::bad_cast &e) {
+ m_fMinValue = 255.0f;
+ ASTRA_ERROR("MaxConstraint must be numerical");
+ }
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);
+ try {
+ m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 255.0f);
+ } catch (const astra::StringUtil::bad_cast &e) {
+ m_fMaxValue = 255.0f;
+ ASTRA_ERROR("MaxConstraintValue must be numerical");
+ }
CC.markOptionParsed("MaxConstraintValue");
}
}