From 7bfc5b3713f750efe21992fcd8d02e840d5d4867 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 5 Dec 2018 12:03:14 +0100 Subject: Read filter config for FBP from cfg.options Since these settings are optional, they should have been in cfg.options instead of directly in cfg. The old syntax remains a fallback. This has the side-effect that the tomopy/astra interface can also supply them. --- src/Filters.cpp | 74 +++++++++++++++++++++++++++++++++------------------------ 1 file changed, 43 insertions(+), 31 deletions(-) (limited to 'src') diff --git a/src/Filters.cpp b/src/Filters.cpp index e756052..d5601e6 100644 --- a/src/Filters.cpp +++ b/src/Filters.cpp @@ -443,7 +443,7 @@ struct FilterNameMapEntry { E_FBPFILTER m_type; }; -E_FBPFILTER convertStringToFilter(const char * _filterType) +E_FBPFILTER convertStringToFilter(const std::string &_filterType) { static const FilterNameMapEntry map[] = { @@ -474,10 +474,10 @@ E_FBPFILTER convertStringToFilter(const char * _filterType) const FilterNameMapEntry *i; for (i = &map[0]; i->m_name; ++i) - if (stringCompareLowerCase(_filterType, i->m_name)) + if (stringCompareLowerCase(_filterType.c_str(), i->m_name)) return i->m_type; - ASTRA_ERROR("Failed to convert \"%s\" into a filter.",_filterType); + ASTRA_ERROR("Failed to convert \"%s\" into a filter.",_filterType.c_str()); return FILTER_ERROR; } @@ -489,59 +489,71 @@ SFilterConfig getFilterConfigForAlgorithm(const Config& _cfg, CAlgorithm *_alg) SFilterConfig c; + XMLNode node; + // filter type - XMLNode node = _cfg.self.getSingleNode("FilterType"); - if (node) - c.m_eType = convertStringToFilter(node.getContent().c_str()); - else + node = _cfg.self.getSingleNode("FilterType"); + if (_cfg.self.hasOption("FilterType")) { + c.m_eType = convertStringToFilter(_cfg.self.getOption("FilterType")); + CC.markOptionParsed("FilterType"); + } else if (node) { + // Fallback: check cfg.FilterType (instead of cfg.option.FilterType) + c.m_eType = convertStringToFilter(node.getContent()); + CC.markNodeParsed("FilterType"); + } else { c.m_eType = FILTER_RAMLAK; - CC.markNodeParsed("FilterType"); + } // filter + // TODO: Only for some values of FilterType node = _cfg.self.getSingleNode("FilterSinogramId"); - if (node) - { - int id = node.getContentInt(); + int id = -1; + if (_cfg.self.hasOption("FilterSinogramId")) { + id = _cfg.self.getOptionInt("FilterSinogramId"); + CC.markOptionParsed("FilterSinogramId"); + } else if (node) { + id = node.getContentInt(); + CC.markNodeParsed("FilterSinogramId"); + } + + if (id != -1) { const CFloat32ProjectionData2D * pFilterData = dynamic_cast(CData2DManager::getSingleton().get(id)); c.m_iCustomFilterWidth = pFilterData->getGeometry()->getDetectorCount(); c.m_iCustomFilterHeight = pFilterData->getGeometry()->getProjectionAngleCount(); c.m_pfCustomFilter = new float[c.m_iCustomFilterWidth * c.m_iCustomFilterHeight]; memcpy(c.m_pfCustomFilter, pFilterData->getDataConst(), sizeof(float) * c.m_iCustomFilterWidth * c.m_iCustomFilterHeight); - } - else - { + } else { c.m_iCustomFilterWidth = 0; c.m_iCustomFilterHeight = 0; c.m_pfCustomFilter = NULL; } - CC.markNodeParsed("FilterSinogramId"); // TODO: Only for some types! // filter parameter + // TODO: Only for some values of FilterType node = _cfg.self.getSingleNode("FilterParameter"); - if (node) - { - float fParameter = node.getContentNumerical(); - c.m_fParameter = fParameter; - } - else - { + if (_cfg.self.hasOption("FilterParameter")) { + c.m_fParameter = _cfg.self.getOptionNumerical("FilterParameter"); + CC.markOptionParsed("FilterParameter"); + } else if (node) { + c.m_fParameter = node.getContentNumerical(); + CC.markNodeParsed("FilterParameter"); + } else { c.m_fParameter = -1.0f; } - CC.markNodeParsed("FilterParameter"); // TODO: Only for some types! // D value + // TODO: Only for some values of FilterType node = _cfg.self.getSingleNode("FilterD"); - if (node) - { - float fD = node.getContentNumerical(); - c.m_fD = fD; - } - else - { + if (_cfg.self.hasOption("FilterD")) { + c.m_fD = _cfg.self.getOptionNumerical("FilterD"); + CC.markOptionParsed("FilterD"); + } else if (node) { + c.m_fD = node.getContentNumerical(); + CC.markNodeParsed("FilterD"); + } else { c.m_fD = 1.0f; } - CC.markNodeParsed("FilterD"); // TODO: Only for some types! return c; } -- cgit v1.2.3 From 662dfcfc37bd7658e61a3b2f6bbc815472a16786 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 5 Dec 2018 12:05:11 +0100 Subject: Improve detection of unused config options for filters The FilterSinogramId, FilterParameter and FilterD options now only get marked used if they are actually used, based on the value of FilterType. --- src/FilteredBackProjectionAlgorithm.cpp | 5 ++ src/Filters.cpp | 96 +++++++++++++++++++++------------ 2 files changed, 67 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp index 67a12a2..ea606f7 100644 --- a/src/FilteredBackProjectionAlgorithm.cpp +++ b/src/FilteredBackProjectionAlgorithm.cpp @@ -92,24 +92,28 @@ void CFilteredBackProjectionAlgorithm::clear() bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) { ASTRA_ASSERT(_cfg.self); + ConfigStackCheck CC("FilteredBackProjectionAlgorithm", this, _cfg); // projector XMLNode node = _cfg.self.getSingleNode("ProjectorId"); ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ProjectorId tag specified."); int id = node.getContentInt(); m_pProjector = CProjector2DManager::getSingleton().get(id); + CC.markNodeParsed("ProjectorId"); // sinogram data node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ProjectionDataId tag specified."); id = node.getContentInt(); m_pSinogram = dynamic_cast(CData2DManager::getSingleton().get(id)); + CC.markNodeParsed("ProjectionDataId"); // volume data node = _cfg.self.getSingleNode("ReconstructionDataId"); ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ReconstructionDataId tag specified."); id = node.getContentInt(); m_pReconstruction = dynamic_cast(CData2DManager::getSingleton().get(id)); + CC.markNodeParsed("ReconstructionDataId"); node = _cfg.self.getSingleNode("ProjectionIndex"); if (node) @@ -153,6 +157,7 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) delete[] sinogramData2D; delete[] projectionAngles; } + CC.markNodeParsed("ProjectionIndex"); m_filterConfig = getFilterConfigForAlgorithm(_cfg, this); diff --git a/src/Filters.cpp b/src/Filters.cpp index d5601e6..8f68202 100644 --- a/src/Filters.cpp +++ b/src/Filters.cpp @@ -492,28 +492,38 @@ SFilterConfig getFilterConfigForAlgorithm(const Config& _cfg, CAlgorithm *_alg) XMLNode node; // filter type - node = _cfg.self.getSingleNode("FilterType"); - if (_cfg.self.hasOption("FilterType")) { - c.m_eType = convertStringToFilter(_cfg.self.getOption("FilterType")); - CC.markOptionParsed("FilterType"); + const char *nodeName = "FilterType"; + node = _cfg.self.getSingleNode(nodeName); + if (_cfg.self.hasOption(nodeName)) { + c.m_eType = convertStringToFilter(_cfg.self.getOption(nodeName)); + CC.markOptionParsed(nodeName); } else if (node) { // Fallback: check cfg.FilterType (instead of cfg.option.FilterType) c.m_eType = convertStringToFilter(node.getContent()); - CC.markNodeParsed("FilterType"); + CC.markNodeParsed(nodeName); } else { c.m_eType = FILTER_RAMLAK; } // filter - // TODO: Only for some values of FilterType - node = _cfg.self.getSingleNode("FilterSinogramId"); + nodeName = "FilterSinogramId"; int id = -1; - if (_cfg.self.hasOption("FilterSinogramId")) { - id = _cfg.self.getOptionInt("FilterSinogramId"); - CC.markOptionParsed("FilterSinogramId"); - } else if (node) { - id = node.getContentInt(); - CC.markNodeParsed("FilterSinogramId"); + switch (c.m_eType) { + case FILTER_PROJECTION: + case FILTER_SINOGRAM: + case FILTER_RPROJECTION: + case FILTER_RSINOGRAM: + node = _cfg.self.getSingleNode(nodeName); + if (_cfg.self.hasOption(nodeName)) { + id = _cfg.self.getOptionInt(nodeName); + CC.markOptionParsed(nodeName); + } else if (node) { + id = node.getContentInt(); + CC.markNodeParsed(nodeName); + } + break; + default: + break; } if (id != -1) { @@ -530,31 +540,49 @@ SFilterConfig getFilterConfigForAlgorithm(const Config& _cfg, CAlgorithm *_alg) } // filter parameter - // TODO: Only for some values of FilterType - node = _cfg.self.getSingleNode("FilterParameter"); - if (_cfg.self.hasOption("FilterParameter")) { - c.m_fParameter = _cfg.self.getOptionNumerical("FilterParameter"); - CC.markOptionParsed("FilterParameter"); - } else if (node) { - c.m_fParameter = node.getContentNumerical(); - CC.markNodeParsed("FilterParameter"); - } else { - c.m_fParameter = -1.0f; + nodeName = "FilterParameter"; + c.m_fParameter = -1.0f; + switch (c.m_eType) { + case FILTER_TUKEY: + case FILTER_GAUSSIAN: + case FILTER_BLACKMAN: + case FILTER_KAISER: + node = _cfg.self.getSingleNode(nodeName); + if (_cfg.self.hasOption(nodeName)) { + c.m_fParameter = _cfg.self.getOptionNumerical(nodeName); + CC.markOptionParsed(nodeName); + } else if (node) { + c.m_fParameter = node.getContentNumerical(); + CC.markNodeParsed(nodeName); + } + break; + default: + break; } // D value - // TODO: Only for some values of FilterType - node = _cfg.self.getSingleNode("FilterD"); - if (_cfg.self.hasOption("FilterD")) { - c.m_fD = _cfg.self.getOptionNumerical("FilterD"); - CC.markOptionParsed("FilterD"); - } else if (node) { - c.m_fD = node.getContentNumerical(); - CC.markNodeParsed("FilterD"); - } else { - c.m_fD = 1.0f; + nodeName = "FilterD"; + c.m_fD = 1.0f; + switch (c.m_eType) { + case FILTER_PROJECTION: + case FILTER_SINOGRAM: + case FILTER_RPROJECTION: + case FILTER_RSINOGRAM: + break; + case FILTER_NONE: + case FILTER_ERROR: + break; + default: + node = _cfg.self.getSingleNode(nodeName); + if (_cfg.self.hasOption(nodeName)) { + c.m_fD = _cfg.self.getOptionNumerical(nodeName); + CC.markOptionParsed(nodeName); + } else if (node) { + c.m_fD = node.getContentNumerical(); + CC.markNodeParsed(nodeName); + } + break; } - return c; } -- cgit v1.2.3