From 475b1746c133b0286871b7414918704557f1abcc Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 9 Mar 2015 15:53:07 +0100 Subject: Remove old Logging code (only used in fft.cu) --- src/CudaFilteredBackProjectionAlgorithm.cpp | 14 +++--- src/Logger.cpp | 77 ----------------------------- 2 files changed, 6 insertions(+), 85 deletions(-) delete mode 100644 src/Logger.cpp (limited to 'src') diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index fcdf860..77bd412 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -34,8 +34,6 @@ $Id$ #include "astra/AstraObjectManager.h" #include "../cuda/2d/astra.h" -#include - using namespace std; using namespace astra; @@ -105,7 +103,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) } CC.markNodeParsed("FilterType"); ASTRA_DELETE(node); - + // filter node = _cfg.self->getSingleNode("FilterSinogramId"); if(node != NULL) @@ -168,7 +166,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) CC.markOptionParsed("ShortScan"); } - + m_pFBP = new AstraFBP; @@ -186,7 +184,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(CFloat32ProjectionData2D * { clear(); } - + // required classes m_pSinogram = _pSinogram; m_pReconstruction = _pReconstruction; @@ -326,7 +324,7 @@ void CCudaFilteredBackProjectionAlgorithm::run(int _iNrIterations /* = 0 */) const CVolumeGeometry2D& volgeom = *m_pReconstruction->getGeometry(); ok &= m_pFBP->getReconstruction(m_pReconstruction->getData(), volgeom.getGridColCount()); - + ASTRA_ASSERT(ok); } @@ -335,7 +333,7 @@ bool CCudaFilteredBackProjectionAlgorithm::check() // check pointers ASTRA_CONFIG_CHECK(m_pSinogram, "FBP_CUDA", "Invalid Projection Data Object."); ASTRA_CONFIG_CHECK(m_pReconstruction, "FBP_CUDA", "Invalid Reconstruction Data Object."); - + if((m_eFilter == FILTER_PROJECTION) || (m_eFilter == FILTER_SINOGRAM) || (m_eFilter == FILTER_RPROJECTION) || (m_eFilter == FILTER_RSINOGRAM)) { ASTRA_CONFIG_CHECK(m_pfFilter, "FBP_CUDA", "Invalid filter pointer."); @@ -387,7 +385,7 @@ static bool stringCompareLowerCase(const char * _stringA, const char * _stringB) #else iCmpReturn = strcasecmp(_stringA, _stringB); #endif - + return (iCmpReturn == 0); } diff --git a/src/Logger.cpp b/src/Logger.cpp deleted file mode 100644 index 148e18c..0000000 --- a/src/Logger.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* ------------------------------------------------------------------------ -Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp - 2014-2015, CWI, Amsterdam - -Contact: astra@uantwerpen.be -Website: http://sf.net/projects/astra-toolbox - -This file is part of the ASTRA Toolbox. - - -The ASTRA Toolbox is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -The ASTRA Toolbox is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with the ASTRA Toolbox. If not, see . - ------------------------------------------------------------------------ -$Id$ -*/ - -#include - -using namespace astra; - -const char * g_loggerFileName = "astra_logger.txt"; - -void CLogger::_assureIsInitialized() -{ - if(!m_bInitialized) - { - m_pOutFile = fopen(g_loggerFileName, "r"); - if(m_pOutFile != NULL) - { - // file exists, users wants to log - fclose(m_pOutFile); - m_pOutFile = fopen(g_loggerFileName, "w"); - } - - m_bInitialized = true; - } -} - -void CLogger::writeLine(const char * _text) -{ - _assureIsInitialized(); - - if(m_pOutFile != NULL) - { - fprintf(m_pOutFile, "%s\n", _text); - fflush(m_pOutFile); - } -} - -void CLogger::writeTerminalCUDAError(const char * _fileName, int _iLine, const char * _errString) -{ - char buffer[256]; - - sprintf(buffer, "Cuda error in file '%s' in line %i : %s.", _fileName, _iLine, _errString); - - writeLine(buffer); -} - -CLogger::CLogger() -{ - ; -} - -FILE * CLogger::m_pOutFile = NULL; -bool CLogger::m_bInitialized = false; -- cgit v1.2.3 From a1dff91d7d8db49ecd79dfbcc6a6a663b114f9fd Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 9 Mar 2015 17:51:42 +0100 Subject: Adds new logging capabilities (based on clog.h) --- src/Logging.cpp | 175 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 175 insertions(+) create mode 100644 src/Logging.cpp (limited to 'src') diff --git a/src/Logging.cpp b/src/Logging.cpp new file mode 100644 index 0000000..9011d37 --- /dev/null +++ b/src/Logging.cpp @@ -0,0 +1,175 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2015, iMinds-Vision Lab, University of Antwerp + 2014-2015, CWI, Amsterdam + +Contact: astra@uantwerpen.be +Website: http://sf.net/projects/astra-toolbox + +This file is part of the ASTRA Toolbox. + + +The ASTRA Toolbox is free software: you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +The ASTRA Toolbox is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with the ASTRA Toolbox. If not, see . + +----------------------------------------------------------------------- +$Id$ +*/ + +#define CLOG_MAIN +#include + +#include + +#include + +using namespace astra; + +void CLogger::enableScreen() +{ + m_bEnabledScreen = true; +} + +void CLogger::enableFile() +{ + m_bEnabledFile = true; +} + +void CLogger::enable() +{ + enableScreen(); + enableFile(); +} + +void CLogger::disableScreen() +{ + m_bEnabledScreen = false; +} + +void CLogger::disableFile() +{ + m_bEnabledFile = false; +} + +void CLogger::disable() +{ + disableScreen(); + disableFile(); +} + +void CLogger::debug(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_debug(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_debug(sfile,sline,1,fmt,ap); +} + +void CLogger::info(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_info(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_info(sfile,sline,1,fmt,ap); +} + +void CLogger::warn(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_warn(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_warn(sfile,sline,1,fmt,ap); +} + +void CLogger::error(const char *sfile, int sline, const char *fmt, ...) +{ + _assureIsInitialized(); + va_list ap; + va_start(ap, fmt); + if(m_bEnabledScreen) clog_error(sfile,sline,0,fmt,ap); + if(m_bEnabledFile && m_bFileProvided) clog_error(sfile,sline,1,fmt,ap); +} + +void CLogger::_setLevel(int id, log_level m_eLevel) +{ + switch(m_eLevel){ + case LOG_DEBUG: + clog_set_level(id,CLOG_DEBUG); + break; + case LOG_INFO: + clog_set_level(id,CLOG_INFO); + break; + case LOG_WARN: + clog_set_level(id,CLOG_WARN); + break; + case LOG_ERROR: + clog_set_level(id,CLOG_ERROR); + break; + } +} + +void CLogger::setOutputScreen(int fd, log_level m_eLevel) +{ + _assureIsInitialized(); + clog_free(0); + clog_init_fd(0, fd); + _setLevel(0,m_eLevel); +} + +void CLogger::setOutputFile(const char *filename, log_level m_eLevel) +{ + if(m_bFileProvided){ + clog_free(1); + m_bFileProvided=false; + } + if(!clog_init_path(1,filename)){ + m_bFileProvided=true; + _setLevel(1,m_eLevel); + } +} + +void CLogger::_assureIsInitialized() +{ + if(!m_bInitialized) + { + clog_init_fd(0, 2); + clog_set_level(0, CLOG_INFO); + m_bInitialized = true; + } +} + +void CLogger::setFormatFile(const char *fmt) +{ + if(m_bFileProvided){ + clog_set_fmt(1,fmt); + }else{ + error(__FILE__,__LINE__,"No log file specified"); + } +} +void CLogger::setFormatScreen(const char *fmt) +{ + clog_set_fmt(0,fmt); +} + +CLogger::CLogger() +{ + ; +} + +bool CLogger::m_bEnabledScreen = true; +bool CLogger::m_bEnabledFile = true; +bool CLogger::m_bFileProvided = false; +bool CLogger::m_bInitialized = false; -- cgit v1.2.3 From 150951875c236f95a64fd132c26576bd19daca80 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Tue, 10 Mar 2015 15:11:15 +0100 Subject: Use new logging API internally instead of printf / iostream --- src/ConeProjectionGeometry3D.cpp | 4 +++- src/Config.cpp | 7 ++++++- src/CudaFilteredBackProjectionAlgorithm.cpp | 4 +++- src/CudaForwardProjectionAlgorithm.cpp | 4 +++- src/CudaForwardProjectionAlgorithm3D.cpp | 4 +++- src/CudaReconstructionAlgorithm2D.cpp | 4 +++- src/FilteredBackProjectionAlgorithm.cpp | 4 +++- 7 files changed, 24 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp index eb9adcf..13f147b 100644 --- a/src/ConeProjectionGeometry3D.cpp +++ b/src/ConeProjectionGeometry3D.cpp @@ -28,6 +28,8 @@ $Id$ #include "astra/ConeProjectionGeometry3D.h" +#include "astra/Logging.h" + #include #include @@ -257,7 +259,7 @@ void CConeProjectionGeometry3D::projectPoint(float32 fX, float32 fY, float32 fZ, // Scale fS to detector plane fU = detectorOffsetXToColIndexFloat( (fS * (m_fOriginSourceDistance + m_fOriginDetectorDistance)) / fD ); - fprintf(stderr, "alpha: %f, D: %f, V: %f, S: %f, U: %f\n", alpha, fD, fV, fS, fU); + astra::CLogger::debug(__FILE__,__LINE__,"alpha: %f, D: %f, V: %f, S: %f, U: %f", alpha, fD, fV, fS, fU); } diff --git a/src/Config.cpp b/src/Config.cpp index 653935e..0a85b3c 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -37,6 +37,9 @@ $Id$ #include "astra/Projector2D.h" #include "astra/Projector3D.h" +#include "astra/Logging.h" +#include + using namespace astra; using namespace std; @@ -144,7 +147,9 @@ bool ConfigStackCheck::stopParsing() nodes.clear(); if (!errors.empty()) { - cout << "Warning: " << name << ": unused configuration options: " << errors << std::endl; + ostringstream os; + os << "Warning: " << name << ": unused configuration options: " << errors; + astra::CLogger::warn(__FILE__,__LINE__,os.str().c_str()); return false; } diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index 77bd412..26b848e 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -34,6 +34,8 @@ $Id$ #include "astra/AstraObjectManager.h" #include "../cuda/2d/astra.h" +#include "astra/Logging.h" + using namespace std; using namespace astra; @@ -483,7 +485,7 @@ E_FBPFILTER CCudaFilteredBackProjectionAlgorithm::_convertStringToFilter(const c } else { - cerr << "Failed to convert \"" << _filterType << "\" into a filter." << endl; + astra::CLogger::error(__FILE__,__LINE__,"Failed to convert \"%s\" into a filter.",_filterType); } return output; diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index ab0d643..1ae6b83 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -42,6 +42,8 @@ $Id$ #include "astra/FanFlatVecProjectionGeometry2D.h" #include "astra/CudaProjector2D.h" +#include "astra/Logging.h" + using namespace std; namespace astra { @@ -104,7 +106,7 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - cout << "Warning: non-CUDA Projector2D passed to FP_CUDA" << std::endl; + astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed to FP_CUDA"); } delete node; } diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp index bb122e0..57e1094 100644 --- a/src/CudaForwardProjectionAlgorithm3D.cpp +++ b/src/CudaForwardProjectionAlgorithm3D.cpp @@ -40,6 +40,8 @@ $Id$ #include "astra/ParallelVecProjectionGeometry3D.h" #include "astra/ConeVecProjectionGeometry3D.h" +#include "astra/Logging.h" + #include "../cuda/3d/astra3d.h" using namespace std; @@ -265,7 +267,7 @@ void CCudaForwardProjectionAlgorithm3D::run(int) for (int k = 0; k < 2; ++k) { float fU, fV; projgeom->projectPoint(fX[i], fY[j], fZ[k], a, fU, fV); - fprintf(stderr, "%3d %c1,%c1,%c1 -> %12f %12f\n", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); + astra::CLogger::debug(__FILE__,__LINE__,"%3d %c1,%c1,%c1 -> %12f %12f", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); } } #endif diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index d3dedc5..b434e8a 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -37,6 +37,8 @@ $Id$ #include "astra/FanFlatVecProjectionGeometry2D.h" #include "astra/CudaProjector2D.h" +#include "astra/Logging.h" + #include "../cuda/2d/algo.h" #include @@ -176,7 +178,7 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - cout << "Warning: non-CUDA Projector2D passed" << std::endl; + astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed"); } delete node; } diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp index 50cf939..47315bb 100644 --- a/src/FilteredBackProjectionAlgorithm.cpp +++ b/src/FilteredBackProjectionAlgorithm.cpp @@ -39,6 +39,8 @@ $Id$ #include "astra/Fourier.h" #include "astra/DataProjector.h" +#include "astra/Logging.h" + using namespace std; namespace astra { @@ -133,7 +135,7 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) for (int i = 0; i < angleCount; i ++) { if (projectionIndex[i] > m_pProjector->getProjectionGeometry()->getProjectionAngleCount() -1 ) { - cout << "Invalid Projection Index" << endl; + astra::CLogger::error(__FILE__,__LINE__,"Invalid Projection Index"); return false; } else { int orgIndex = (int)projectionIndex[i]; -- cgit v1.2.3 From c5507b6ef2abfab169150528a374526bb348bf62 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 12:18:21 +0100 Subject: Adds ASTRA_*** defines for easier logging, and changes internal calls to these defines --- src/ConeProjectionGeometry3D.cpp | 2 +- src/Config.cpp | 2 +- src/CudaFilteredBackProjectionAlgorithm.cpp | 2 +- src/CudaForwardProjectionAlgorithm.cpp | 2 +- src/CudaForwardProjectionAlgorithm3D.cpp | 2 +- src/CudaReconstructionAlgorithm2D.cpp | 2 +- src/FilteredBackProjectionAlgorithm.cpp | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp index 13f147b..1976901 100644 --- a/src/ConeProjectionGeometry3D.cpp +++ b/src/ConeProjectionGeometry3D.cpp @@ -259,7 +259,7 @@ void CConeProjectionGeometry3D::projectPoint(float32 fX, float32 fY, float32 fZ, // Scale fS to detector plane fU = detectorOffsetXToColIndexFloat( (fS * (m_fOriginSourceDistance + m_fOriginDetectorDistance)) / fD ); - astra::CLogger::debug(__FILE__,__LINE__,"alpha: %f, D: %f, V: %f, S: %f, U: %f", alpha, fD, fV, fS, fU); + ASTRA_DEBUG("alpha: %f, D: %f, V: %f, S: %f, U: %f", alpha, fD, fV, fS, fU); } diff --git a/src/Config.cpp b/src/Config.cpp index 0a85b3c..388cfdf 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -149,7 +149,7 @@ bool ConfigStackCheck::stopParsing() if (!errors.empty()) { ostringstream os; os << "Warning: " << name << ": unused configuration options: " << errors; - astra::CLogger::warn(__FILE__,__LINE__,os.str().c_str()); + ASTRA_WARN(os.str().c_str()); return false; } diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index 26b848e..0badc20 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -485,7 +485,7 @@ E_FBPFILTER CCudaFilteredBackProjectionAlgorithm::_convertStringToFilter(const c } else { - astra::CLogger::error(__FILE__,__LINE__,"Failed to convert \"%s\" into a filter.",_filterType); + ASTRA_ERROR("Failed to convert \"%s\" into a filter.",_filterType); } return output; diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index 1ae6b83..19cadd6 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -106,7 +106,7 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed to FP_CUDA"); + ASTRA_WARN("Warning: non-CUDA Projector2D passed to FP_CUDA"); } delete node; } diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp index 57e1094..8e6bab5 100644 --- a/src/CudaForwardProjectionAlgorithm3D.cpp +++ b/src/CudaForwardProjectionAlgorithm3D.cpp @@ -267,7 +267,7 @@ void CCudaForwardProjectionAlgorithm3D::run(int) for (int k = 0; k < 2; ++k) { float fU, fV; projgeom->projectPoint(fX[i], fY[j], fZ[k], a, fU, fV); - astra::CLogger::debug(__FILE__,__LINE__,"%3d %c1,%c1,%c1 -> %12f %12f", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); + ASTRA_DEBUG("%3d %c1,%c1,%c1 -> %12f %12f", a, i ? ' ' : '-', j ? ' ' : '-', k ? ' ' : '-', fU, fV); } } #endif diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index b434e8a..929f0f1 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -178,7 +178,7 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - astra::CLogger::warn(__FILE__,__LINE__,"Warning: non-CUDA Projector2D passed"); + ASTRA_WARN("Warning: non-CUDA Projector2D passed"); } delete node; } diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp index 47315bb..4a8e5ac 100644 --- a/src/FilteredBackProjectionAlgorithm.cpp +++ b/src/FilteredBackProjectionAlgorithm.cpp @@ -135,7 +135,7 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) for (int i = 0; i < angleCount; i ++) { if (projectionIndex[i] > m_pProjector->getProjectionGeometry()->getProjectionAngleCount() -1 ) { - astra::CLogger::error(__FILE__,__LINE__,"Invalid Projection Index"); + ASTRA_ERROR("Invalid Projection Index"); return false; } else { int orgIndex = (int)projectionIndex[i]; -- cgit v1.2.3 From f21700e00e81538d5510973a51b8ae97fb4a24dd Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 17:12:42 +0100 Subject: Enable logging to Matlab window using callback function Also introduces a mex initialize function that is called at the first invocation of any mex method. --- src/Logging.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/Logging.cpp b/src/Logging.cpp index 9011d37..9d7c219 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -124,8 +124,7 @@ void CLogger::_setLevel(int id, log_level m_eLevel) void CLogger::setOutputScreen(int fd, log_level m_eLevel) { _assureIsInitialized(); - clog_free(0); - clog_init_fd(0, fd); + clog_set_fd(0, fd); _setLevel(0,m_eLevel); } @@ -169,6 +168,11 @@ CLogger::CLogger() ; } +bool CLogger::setCallbackScreen(void (*cb)(const char *msg, size_t len)){ + _assureIsInitialized(); + return clog_set_cb(0,cb)==0; +} + bool CLogger::m_bEnabledScreen = true; bool CLogger::m_bEnabledFile = true; bool CLogger::m_bFileProvided = false; -- cgit v1.2.3 From 35fadf8641b05d357a37e8098b9a801ba0e815b9 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 17:22:41 +0100 Subject: Use a less verbose default fmt for screen logging and cleaner messages --- src/Config.cpp | 2 +- src/CudaForwardProjectionAlgorithm.cpp | 2 +- src/CudaReconstructionAlgorithm2D.cpp | 2 +- src/Logging.cpp | 1 + 4 files changed, 4 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index 388cfdf..d860638 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -148,7 +148,7 @@ bool ConfigStackCheck::stopParsing() if (!errors.empty()) { ostringstream os; - os << "Warning: " << name << ": unused configuration options: " << errors; + os << name << ": unused configuration options: " << errors; ASTRA_WARN(os.str().c_str()); return false; } diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index 19cadd6..95abb62 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -106,7 +106,7 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - ASTRA_WARN("Warning: non-CUDA Projector2D passed to FP_CUDA"); + ASTRA_WARN("non-CUDA Projector2D passed to FP_CUDA"); } delete node; } diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index 929f0f1..1c6b763 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -178,7 +178,7 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) id = boost::lexical_cast(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { - ASTRA_WARN("Warning: non-CUDA Projector2D passed"); + ASTRA_WARN("non-CUDA Projector2D passed"); } delete node; } diff --git a/src/Logging.cpp b/src/Logging.cpp index 9d7c219..f95df0e 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -146,6 +146,7 @@ void CLogger::_assureIsInitialized() { clog_init_fd(0, 2); clog_set_level(0, CLOG_INFO); + clog_set_fmt(0, "%l: %m\n"); m_bInitialized = true; } } -- cgit v1.2.3 From 476fd5388da4aa6e23658460199e26e88e05dc5d Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 13 Mar 2015 17:49:55 +0100 Subject: Only allow stdout and stderr for screen logging --- src/Logging.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Logging.cpp b/src/Logging.cpp index f95df0e..8290ca0 100644 --- a/src/Logging.cpp +++ b/src/Logging.cpp @@ -124,7 +124,11 @@ void CLogger::_setLevel(int id, log_level m_eLevel) void CLogger::setOutputScreen(int fd, log_level m_eLevel) { _assureIsInitialized(); - clog_set_fd(0, fd); + if(fd==1||fd==2){ + clog_set_fd(0, fd); + }else{ + error(__FILE__,__LINE__,"Invalid file descriptor"); + } _setLevel(0,m_eLevel); } -- cgit v1.2.3 From 5968cf4b6cf6907808011e66597054106df2a00f Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 30 Mar 2015 15:34:07 +0200 Subject: Add missing error on wrong projgeom type in CProjector3D::initialize --- src/Projector3D.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/Projector3D.cpp b/src/Projector3D.cpp index b546ee9..def5237 100644 --- a/src/Projector3D.cpp +++ b/src/Projector3D.cpp @@ -108,6 +108,7 @@ bool CProjector3D::initialize(const Config& _cfg) pProjGeometry = new CConeVecProjectionGeometry3D(); } else { // Invalid geometry type + ASTRA_CONFIG_CHECK(false, "Projector3D", "Invalid projection geometry type specified."); } pProjGeometry->initialize(Config(node)); // this deletes node m_pProjectionGeometry = pProjGeometry; -- cgit v1.2.3 From b70ed00ebdf2dc952e29daf4b335bc47fd7c2ea0 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Mon, 30 Mar 2015 15:35:01 +0200 Subject: Fix typo in error message --- src/Projector3D.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/Projector3D.cpp b/src/Projector3D.cpp index def5237..14cb16a 100644 --- a/src/Projector3D.cpp +++ b/src/Projector3D.cpp @@ -120,7 +120,7 @@ bool CProjector3D::initialize(const Config& _cfg) CVolumeGeometry3D* pVolGeometry = new CVolumeGeometry3D(); pVolGeometry->initialize(Config(node)); // this deletes node m_pVolumeGeometry = pVolGeometry; - ASTRA_CONFIG_CHECK(m_pVolumeGeometry->isInitialized(), "Projector2D", "VolumeGeometry not initialized."); + ASTRA_CONFIG_CHECK(m_pVolumeGeometry->isInitialized(), "Projector3D", "VolumeGeometry not initialized."); CC.markNodeParsed("VolumeGeometry"); return true; -- cgit v1.2.3 From 1b32573046f33050b9300324e6c74e10abb6caaf Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Thu, 9 Apr 2015 15:44:01 +0200 Subject: Add 'link' feature to Python (for 2D and 3D data) --- src/Float32ProjectionData2D.cpp | 19 +++++++++++++++++++ src/Float32VolumeData2D.cpp | 20 ++++++++++++++++++++ 2 files changed, 39 insertions(+) (limited to 'src') diff --git a/src/Float32ProjectionData2D.cpp b/src/Float32ProjectionData2D.cpp index 85e0cdd..f7f83e3 100644 --- a/src/Float32ProjectionData2D.cpp +++ b/src/Float32ProjectionData2D.cpp @@ -75,6 +75,16 @@ CFloat32ProjectionData2D::CFloat32ProjectionData2D(const CFloat32ProjectionData2 m_bInitialized = true; } +//---------------------------------------------------------------------------------------- +// Create an instance of the CFloat32ProjectionData2D class with pre-allocated data +CFloat32ProjectionData2D::CFloat32ProjectionData2D(CProjectionGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory) +{ + m_bInitialized = false; + m_bInitialized = initialize(_pGeometry, _pCustomMemory); +} + + + // Assignment operator CFloat32ProjectionData2D& CFloat32ProjectionData2D::operator=(const CFloat32ProjectionData2D& _other) @@ -118,6 +128,15 @@ bool CFloat32ProjectionData2D::initialize(CProjectionGeometry2D* _pGeometry, flo return m_bInitialized; } +//---------------------------------------------------------------------------------------- +// Initialization +bool CFloat32ProjectionData2D::initialize(CProjectionGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory) +{ + m_pGeometry = _pGeometry->clone(); + m_bInitialized = _initialize(m_pGeometry->getDetectorCount(), m_pGeometry->getProjectionAngleCount(), _pCustomMemory); + return m_bInitialized; +} + //---------------------------------------------------------------------------------------- // Destructor CFloat32ProjectionData2D::~CFloat32ProjectionData2D() diff --git a/src/Float32VolumeData2D.cpp b/src/Float32VolumeData2D.cpp index e11c4e4..c903c66 100644 --- a/src/Float32VolumeData2D.cpp +++ b/src/Float32VolumeData2D.cpp @@ -72,6 +72,15 @@ CFloat32VolumeData2D::CFloat32VolumeData2D(const CFloat32VolumeData2D& _other) : m_bInitialized = true; } +//---------------------------------------------------------------------------------------- +// Create an instance of the CFloat32VolumeData2D class with pre-allocated data +CFloat32VolumeData2D::CFloat32VolumeData2D(CVolumeGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory) +{ + m_bInitialized = false; + m_bInitialized = initialize(_pGeometry, _pCustomMemory); +} + + // Assignment operator CFloat32VolumeData2D& CFloat32VolumeData2D::operator=(const CFloat32VolumeData2D& _other) @@ -122,6 +131,17 @@ bool CFloat32VolumeData2D::initialize(CVolumeGeometry2D* _pGeometry, float32 _fS m_bInitialized = _initialize(m_pGeometry->getGridColCount(), m_pGeometry->getGridRowCount(), _fScalar); return m_bInitialized; } + +//---------------------------------------------------------------------------------------- +// Initialization +bool CFloat32VolumeData2D::initialize(CVolumeGeometry2D* _pGeometry, CFloat32CustomMemory* _pCustomMemory) +{ + m_pGeometry = _pGeometry->clone(); + m_bInitialized = _initialize(m_pGeometry->getGridColCount(), m_pGeometry->getGridRowCount(), _pCustomMemory); + return m_bInitialized; +} + + //---------------------------------------------------------------------------------------- void CFloat32VolumeData2D::changeGeometry(CVolumeGeometry2D* _pGeometry) { -- cgit v1.2.3 From 7b55ee5f60c5f5865726cf48636b642cd9de111d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 10 Apr 2015 12:29:22 +0200 Subject: Add changeGeometry function to Data3D classes --- src/Float32ProjectionData3D.cpp | 9 +++++++++ src/Float32VolumeData3D.cpp | 9 +++++++++ 2 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/Float32ProjectionData3D.cpp b/src/Float32ProjectionData3D.cpp index d039c83..2bd0447 100644 --- a/src/Float32ProjectionData3D.cpp +++ b/src/Float32ProjectionData3D.cpp @@ -270,4 +270,13 @@ CFloat32ProjectionData3D& CFloat32ProjectionData3D::operator-=(const float32& _f return *this; } +void CFloat32ProjectionData3D::changeGeometry(CProjectionGeometry3D* _pGeometry) +{ + if (!m_bInitialized) return; + + delete m_pGeometry; + m_pGeometry = _pGeometry->clone(); +} + + } // end namespace astra diff --git a/src/Float32VolumeData3D.cpp b/src/Float32VolumeData3D.cpp index ce00a10..bd78001 100644 --- a/src/Float32VolumeData3D.cpp +++ b/src/Float32VolumeData3D.cpp @@ -266,4 +266,13 @@ CFloat32VolumeData3D& CFloat32VolumeData3D::operator-=(const float32& _fScalar) return *this; } +void CFloat32VolumeData3D::changeGeometry(CVolumeGeometry3D* _pGeometry) +{ + if (!m_bInitialized) return; + + delete m_pGeometry; + m_pGeometry = _pGeometry->clone(); +} + + } // end namespace astra -- cgit v1.2.3 From 68955e294ea772b5a37653b3c871f6ca6268324d Mon Sep 17 00:00:00 2001 From: Valerii Sokolov Date: Wed, 29 Apr 2015 13:46:47 +0200 Subject: Now include path is system-independent. --- src/XMLDocument.cpp | 5 ----- src/XMLNode.cpp | 5 ----- 2 files changed, 10 deletions(-) (limited to 'src') diff --git a/src/XMLDocument.cpp b/src/XMLDocument.cpp index 406564f..da843b4 100644 --- a/src/XMLDocument.cpp +++ b/src/XMLDocument.cpp @@ -32,13 +32,8 @@ $Id$ #include #include -#ifdef _MSC_VER #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_print.hpp" -#else -#include "rapidxml.hpp" -#include "rapidxml_print.hpp" -#endif using namespace rapidxml; using namespace astra; diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp index 4b2bdf4..5e9d927 100644 --- a/src/XMLNode.cpp +++ b/src/XMLNode.cpp @@ -28,13 +28,8 @@ $Id$ #include "astra/XMLNode.h" -#ifdef _MSC_VER #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_print.hpp" -#else -#include "rapidxml.hpp" -#include "rapidxml_print.hpp" -#endif #include -- cgit v1.2.3 From bf31003d74f538a9096ef5999b31b0daa58c38c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jeroen=20B=C3=A9dorf?= Date: Thu, 2 Apr 2015 12:04:31 +0200 Subject: Fix memory leak in the config --- src/Config.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/Config.cpp b/src/Config.cpp index d860638..32e5ed9 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -48,6 +48,7 @@ using namespace std; Config::Config() { self = 0; + _doc = 0; } //----------------------------------------------------------------------------- @@ -55,6 +56,7 @@ Config::Config() Config::Config(XMLNode* _self) { self = _self; + _doc = 0; } //----------------------------------------------------------------------------- @@ -62,6 +64,8 @@ Config::~Config() { delete self; self = 0; + delete _doc; + _doc = 0; } //----------------------------------------------------------------------------- @@ -70,6 +74,7 @@ void Config::initialize(std::string rootname) if (self == 0) { XMLDocument* doc = XMLDocument::createDocument(rootname); self = doc->getRootNode(); + _doc = doc; } } -- cgit v1.2.3 From 47fe3421585302f2101691a685ab99b0e1ad5cfc Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 1 May 2015 17:48:32 +0200 Subject: Change XMLNode* to XMLNode An XMLNode object is already simply a pointer, so no need to dynamically allocate XMLNodes. --- src/ArtAlgorithm.cpp | 6 +- src/ConeProjectionGeometry3D.cpp | 26 +++-- src/ConeVecProjectionGeometry3D.cpp | 25 ++--- src/Config.cpp | 19 ++-- src/CudaBackProjectionAlgorithm3D.cpp | 6 +- src/CudaCglsAlgorithm3D.cpp | 6 +- src/CudaDartMaskAlgorithm.cpp | 22 ++-- src/CudaDartMaskAlgorithm3D.cpp | 22 ++-- src/CudaDartSmoothingAlgorithm.cpp | 20 ++-- src/CudaDartSmoothingAlgorithm3D.cpp | 20 ++-- src/CudaDataOperationAlgorithm.cpp | 25 ++--- src/CudaFDKAlgorithm3D.cpp | 6 +- src/CudaFilteredBackProjectionAlgorithm.cpp | 44 ++++---- src/CudaForwardProjectionAlgorithm.cpp | 23 ++--- src/CudaForwardProjectionAlgorithm3D.cpp | 21 ++-- src/CudaProjector2D.cpp | 5 +- src/CudaProjector3D.cpp | 5 +- src/CudaReconstructionAlgorithm2D.cpp | 49 +++++---- src/CudaRoiSelectAlgorithm.cpp | 13 ++- src/CudaSartAlgorithm.cpp | 4 +- src/CudaSirtAlgorithm.cpp | 8 +- src/CudaSirtAlgorithm3D.cpp | 6 +- src/FanFlatProjectionGeometry2D.cpp | 22 ++-- src/FanFlatVecProjectionGeometry2D.cpp | 18 ++-- src/FilteredBackProjectionAlgorithm.cpp | 20 ++-- src/ForwardProjectionAlgorithm.cpp | 23 ++--- src/ParallelBeamBlobKernelProjector2D.cpp | 22 ++-- src/ParallelProjectionGeometry2D.cpp | 8 +- src/ParallelProjectionGeometry3D.cpp | 12 +-- src/ParallelVecProjectionGeometry3D.cpp | 25 ++--- src/ProjectionGeometry2D.cpp | 17 ++- src/ProjectionGeometry3D.cpp | 25 ++--- src/Projector2D.cpp | 6 +- src/Projector3D.cpp | 8 +- src/ReconstructionAlgorithm2D.cpp | 39 ++++--- src/ReconstructionAlgorithm3D.cpp | 36 +++---- src/SartAlgorithm.cpp | 4 +- src/SparseMatrixProjectionGeometry2D.cpp | 15 ++- src/VolumeGeometry2D.cpp | 30 +++--- src/VolumeGeometry3D.cpp | 45 ++++---- src/XMLDocument.cpp | 5 +- src/XMLNode.cpp | 155 ++++++++++++---------------- 42 files changed, 410 insertions(+), 506 deletions(-) (limited to 'src') diff --git a/src/ArtAlgorithm.cpp b/src/ArtAlgorithm.cpp index 8f058a3..6a699ec 100644 --- a/src/ArtAlgorithm.cpp +++ b/src/ArtAlgorithm.cpp @@ -132,7 +132,7 @@ bool CArtAlgorithm::initialize(const Config& _cfg) } // ray order - string projOrder = _cfg.self->getOption("RayOrder", "sequential"); + string projOrder = _cfg.self.getOption("RayOrder", "sequential"); CC.markOptionParsed("RayOrder"); m_iCurrentRay = 0; m_iRayCount = m_pProjector->getProjectionGeometry()->getProjectionAngleCount() * @@ -145,7 +145,7 @@ bool CArtAlgorithm::initialize(const Config& _cfg) m_piDetectorOrder[i] = i % m_pProjector->getProjectionGeometry()->getDetectorCount(); } } else if (projOrder == "custom") { - vector rayOrderList = _cfg.self->getOptionNumericalArray("RayOrderList"); + vector rayOrderList = _cfg.self.getOptionNumericalArray("RayOrderList"); m_iRayCount = rayOrderList.size() / 2; m_piProjectionOrder = new int[m_iRayCount]; m_piDetectorOrder = new int[m_iRayCount]; @@ -158,7 +158,7 @@ bool CArtAlgorithm::initialize(const Config& _cfg) return false; } - m_fLambda = _cfg.self->getOptionNumerical("Lambda", 1.0f); + m_fLambda = _cfg.self.getOptionNumerical("Lambda", 1.0f); CC.markOptionParsed("Lambda"); // success diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp index 1976901..dd22eba 100644 --- a/src/ConeProjectionGeometry3D.cpp +++ b/src/ConeProjectionGeometry3D.cpp @@ -87,17 +87,15 @@ bool CConeProjectionGeometry3D::initialize(const Config& _cfg) CProjectionGeometry3D::initialize(_cfg); // Required: DistanceOriginDetector - XMLNode* node = _cfg.self->getSingleNode("DistanceOriginDetector"); + XMLNode node = _cfg.self.getSingleNode("DistanceOriginDetector"); ASTRA_CONFIG_CHECK(node, "ConeProjectionGeometry3D", "No DistanceOriginDetector tag specified."); - m_fOriginDetectorDistance = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_fOriginDetectorDistance = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DistanceOriginDetector"); // Required: DetectorOriginSource - node = _cfg.self->getSingleNode("DistanceOriginSource"); + node = _cfg.self.getSingleNode("DistanceOriginSource"); ASTRA_CONFIG_CHECK(node, "ConeProjectionGeometry3D", "No DistanceOriginSource tag specified."); - m_fOriginSourceDistance = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_fOriginSourceDistance = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DistanceOriginSource"); // success @@ -193,14 +191,14 @@ Config* CConeProjectionGeometry3D::getConfiguration() const { Config* cfg = new Config(); cfg->initialize("ProjectionGeometry3D"); - cfg->self->addAttribute("type", "cone"); - cfg->self->addChildNode("DetectorSpacingX", m_fDetectorSpacingX); - cfg->self->addChildNode("DetectorSpacingY", m_fDetectorSpacingY); - cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); - cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); - cfg->self->addChildNode("DistanceOriginDetector", m_fOriginDetectorDistance); - cfg->self->addChildNode("DistanceOriginSource", m_fOriginSourceDistance); - cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + cfg->self.addAttribute("type", "cone"); + cfg->self.addChildNode("DetectorSpacingX", m_fDetectorSpacingX); + cfg->self.addChildNode("DetectorSpacingY", m_fDetectorSpacingY); + cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount); + cfg->self.addChildNode("DistanceOriginDetector", m_fOriginDetectorDistance); + cfg->self.addChildNode("DistanceOriginSource", m_fOriginSourceDistance); + cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); return cfg; } diff --git a/src/ConeVecProjectionGeometry3D.cpp b/src/ConeVecProjectionGeometry3D.cpp index 9dc273d..47ed630 100644 --- a/src/ConeVecProjectionGeometry3D.cpp +++ b/src/ConeVecProjectionGeometry3D.cpp @@ -73,33 +73,30 @@ bool CConeVecProjectionGeometry3D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); ConfigStackCheck CC("ConeVecProjectionGeometry3D", this, _cfg); - XMLNode* node; + XMLNode node; // TODO: Fix up class hierarchy... this class doesn't fit very well. // initialization of parent class //CProjectionGeometry3D::initialize(_cfg); // Required: DetectorRowCount - node = _cfg.self->getSingleNode("DetectorRowCount"); + node = _cfg.self.getSingleNode("DetectorRowCount"); ASTRA_CONFIG_CHECK(node, "ConeVecProjectionGeometry3D", "No DetectorRowCount tag specified."); - m_iDetectorRowCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iDetectorRowCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorRowCount"); // Required: DetectorColCount - node = _cfg.self->getSingleNode("DetectorColCount"); + node = _cfg.self.getSingleNode("DetectorColCount"); ASTRA_CONFIG_CHECK(node, "ConeVecProjectionGeometry3D", "No DetectorColCount tag specified."); - m_iDetectorColCount = boost::lexical_cast(node->getContent()); + m_iDetectorColCount = boost::lexical_cast(node.getContent()); m_iDetectorTotCount = m_iDetectorRowCount * m_iDetectorColCount; - ASTRA_DELETE(node); CC.markNodeParsed("DetectorColCount"); // Required: Vectors - node = _cfg.self->getSingleNode("Vectors"); + node = _cfg.self.getSingleNode("Vectors"); ASTRA_CONFIG_CHECK(node, "ConeVecProjectionGeometry3D", "No Vectors tag specified."); - vector data = node->getContentNumericalArrayDouble(); + vector data = node.getContentNumericalArrayDouble(); CC.markNodeParsed("Vectors"); - ASTRA_DELETE(node); ASTRA_CONFIG_CHECK(data.size() % 12 == 0, "ConeVecProjectionGeometry3D", "Vectors doesn't consist of 12-tuples."); m_iProjectionAngleCount = data.size() / 12; m_pProjectionAngles = new SConeProjection[m_iProjectionAngleCount]; @@ -208,9 +205,9 @@ Config* CConeVecProjectionGeometry3D::getConfiguration() const Config* cfg = new Config(); cfg->initialize("ProjectionGeometry3D"); - cfg->self->addAttribute("type", "cone_vec"); - cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); - cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); + cfg->self.addAttribute("type", "cone_vec"); + cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount); std::string vectors = ""; for (int i = 0; i < m_iProjectionAngleCount; ++i) { @@ -229,7 +226,7 @@ Config* CConeVecProjectionGeometry3D::getConfiguration() const vectors += boost::lexical_cast(p.fDetVZ); if (i < m_iProjectionAngleCount-1) vectors += ';'; } - cfg->self->addChildNode("Vectors", vectors); + cfg->self.addChildNode("Vectors", vectors); return cfg; } diff --git a/src/Config.cpp b/src/Config.cpp index 32e5ed9..395080b 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -45,15 +45,14 @@ using namespace std; //----------------------------------------------------------------------------- // default constructor -Config::Config() +Config::Config() : self() { - self = 0; _doc = 0; } //----------------------------------------------------------------------------- // not so default constructor -Config::Config(XMLNode* _self) +Config::Config(XMLNode _self) { self = _self; _doc = 0; @@ -62,8 +61,6 @@ Config::Config(XMLNode* _self) //----------------------------------------------------------------------------- Config::~Config() { - delete self; - self = 0; delete _doc; _doc = 0; } @@ -71,7 +68,7 @@ Config::~Config() //----------------------------------------------------------------------------- void Config::initialize(std::string rootname) { - if (self == 0) { + if (!self) { XMLDocument* doc = XMLDocument::createDocument(rootname); self = doc->getRootNode(); _doc = doc; @@ -129,13 +126,13 @@ bool ConfigStackCheck::stopParsing() std::string errors; - std::list nodes = cfg->self->getNodes(); - for (std::list::iterator i = nodes.begin(); i != nodes.end(); ++i) + std::list nodes = cfg->self.getNodes(); + for (std::list::iterator i = nodes.begin(); i != nodes.end(); ++i) { - std::string nodeName = (*i)->getName(); + std::string nodeName = i->getName(); if (nodeName == "Option") { - nodeName = (*i)->getAttribute("key", ""); + nodeName = i->getAttribute("key", ""); if (object->configCheckData->parsedOptions.find(nodeName) == object->configCheckData->parsedOptions.end()) { if (!errors.empty()) errors += ", "; errors += nodeName; @@ -147,8 +144,6 @@ bool ConfigStackCheck::stopParsing() } } } - for (std::list::iterator i = nodes.begin(); i != nodes.end(); ++i) - delete (*i); nodes.clear(); if (!errors.empty()) { diff --git a/src/CudaBackProjectionAlgorithm3D.cpp b/src/CudaBackProjectionAlgorithm3D.cpp index abcf096..fbb8f28 100644 --- a/src/CudaBackProjectionAlgorithm3D.cpp +++ b/src/CudaBackProjectionAlgorithm3D.cpp @@ -102,9 +102,9 @@ bool CCudaBackProjectionAlgorithm3D::initialize(const Config& _cfg) return false; } - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); CC.markOptionParsed("VoxelSuperSampling"); CFloat32ProjectionData3DMemory* pSinoMem = dynamic_cast(m_pSinogram); @@ -114,7 +114,7 @@ const CParallelProjectionGeometry3D* par3dgeom = dynamic_cast(projgeom); if (parvec3dgeom || par3dgeom) { // This option is only supported for Par3D currently - m_bSIRTWeighting = _cfg.self->getOptionBool("SIRTWeighting", false); + m_bSIRTWeighting = _cfg.self.getOptionBool("SIRTWeighting", false); CC.markOptionParsed("SIRTWeighting"); } diff --git a/src/CudaCglsAlgorithm3D.cpp b/src/CudaCglsAlgorithm3D.cpp index a5500d6..3457b81 100644 --- a/src/CudaCglsAlgorithm3D.cpp +++ b/src/CudaCglsAlgorithm3D.cpp @@ -106,11 +106,11 @@ bool CCudaCglsAlgorithm3D::initialize(const Config& _cfg) return false; } - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); CC.markOptionParsed("DetectorSuperSampling"); - m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); CC.markOptionParsed("VoxelSuperSampling"); m_pCgls = new AstraCGLS3d(); diff --git a/src/CudaDartMaskAlgorithm.cpp b/src/CudaDartMaskAlgorithm.cpp index dcdefcc..950b428 100644 --- a/src/CudaDartMaskAlgorithm.cpp +++ b/src/CudaDartMaskAlgorithm.cpp @@ -65,38 +65,36 @@ bool CCudaDartMaskAlgorithm::initialize(const Config& _cfg) ConfigStackCheck CC("CudaDartMaskAlgorithm", this, _cfg); // reconstruction data - XMLNode* node = _cfg.self->getSingleNode("SegmentationDataId"); + XMLNode node = _cfg.self.getSingleNode("SegmentationDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No SegmentationDataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pSegmentation = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("SegmentationDataId"); // reconstruction data - node = _cfg.self->getSingleNode("MaskDataId"); + node = _cfg.self.getSingleNode("MaskDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No MaskDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pMask = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("MaskDataId"); // Option: GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); // Option: Connectivity - m_iConn = (unsigned int)_cfg.self->getOptionNumerical("Connectivity", 8); + m_iConn = (unsigned int)_cfg.self.getOptionNumerical("Connectivity", 8); CC.markOptionParsed("Connectivity"); // Option: Threshold - m_iThreshold = (unsigned int)_cfg.self->getOptionNumerical("Threshold", 1); + m_iThreshold = (unsigned int)_cfg.self.getOptionNumerical("Threshold", 1); CC.markOptionParsed("Threshold"); // Option: Radius - m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1); + m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1); CC.markOptionParsed("Radius"); _check(); diff --git a/src/CudaDartMaskAlgorithm3D.cpp b/src/CudaDartMaskAlgorithm3D.cpp index f3500b9..b0dfc5b 100644 --- a/src/CudaDartMaskAlgorithm3D.cpp +++ b/src/CudaDartMaskAlgorithm3D.cpp @@ -65,38 +65,36 @@ bool CCudaDartMaskAlgorithm3D::initialize(const Config& _cfg) ConfigStackCheck CC("CudaDartMaskAlgorithm", this, _cfg); // reconstruction data - XMLNode* node = _cfg.self->getSingleNode("SegmentationDataId"); + XMLNode node = _cfg.self.getSingleNode("SegmentationDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No SegmentationDataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pSegmentation = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("SegmentationDataId"); // reconstruction data - node = _cfg.self->getSingleNode("MaskDataId"); + node = _cfg.self.getSingleNode("MaskDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No MaskDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pMask = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("MaskDataId"); // Option: GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); // Option: Connectivity - m_iConn = (unsigned int)_cfg.self->getOptionNumerical("Connectivity", 8); + m_iConn = (unsigned int)_cfg.self.getOptionNumerical("Connectivity", 8); CC.markOptionParsed("Connectivity"); // Option: Threshold - m_iThreshold = (unsigned int)_cfg.self->getOptionNumerical("Threshold", 1); + m_iThreshold = (unsigned int)_cfg.self.getOptionNumerical("Threshold", 1); CC.markOptionParsed("Threshold"); // Option: Radius - m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1); + m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1); CC.markOptionParsed("Radius"); _check(); diff --git a/src/CudaDartSmoothingAlgorithm.cpp b/src/CudaDartSmoothingAlgorithm.cpp index 2f2103f..7e22809 100644 --- a/src/CudaDartSmoothingAlgorithm.cpp +++ b/src/CudaDartSmoothingAlgorithm.cpp @@ -65,34 +65,32 @@ bool CCudaDartSmoothingAlgorithm::initialize(const Config& _cfg) ConfigStackCheck CC("CudaDartSmoothingAlgorithm", this, _cfg); // reconstruction data - XMLNode* node = _cfg.self->getSingleNode("InDataId"); + XMLNode node = _cfg.self.getSingleNode("InDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No InDataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pIn = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("InDataId"); // reconstruction data - node = _cfg.self->getSingleNode("OutDataId"); + node = _cfg.self.getSingleNode("OutDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No OutDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pOut = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("OutDataId"); // Option: GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); // Option: Radius - m_fB = (float)_cfg.self->getOptionNumerical("Intensity", 0.3f); + m_fB = (float)_cfg.self.getOptionNumerical("Intensity", 0.3f); CC.markOptionParsed("Intensity"); // Option: Radius - m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1); + m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1); CC.markOptionParsed("Radius"); diff --git a/src/CudaDartSmoothingAlgorithm3D.cpp b/src/CudaDartSmoothingAlgorithm3D.cpp index f3cf015..9c4437a 100644 --- a/src/CudaDartSmoothingAlgorithm3D.cpp +++ b/src/CudaDartSmoothingAlgorithm3D.cpp @@ -65,34 +65,32 @@ bool CCudaDartSmoothingAlgorithm3D::initialize(const Config& _cfg) ConfigStackCheck CC("CudaDartSmoothingAlgorithm", this, _cfg); // reconstruction data - XMLNode* node = _cfg.self->getSingleNode("InDataId"); + XMLNode node = _cfg.self.getSingleNode("InDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No InDataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pIn = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("InDataId"); // reconstruction data - node = _cfg.self->getSingleNode("OutDataId"); + node = _cfg.self.getSingleNode("OutDataId"); ASTRA_CONFIG_CHECK(node, "CudaDartMask", "No OutDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pOut = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("OutDataId"); // Option: GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); // Option: Intensity - m_fB = (float)_cfg.self->getOptionNumerical("Intensity", 0.3f); + m_fB = (float)_cfg.self.getOptionNumerical("Intensity", 0.3f); CC.markOptionParsed("Intensity"); // Option: Radius - m_iRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 1); + m_iRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 1); CC.markOptionParsed("Radius"); _check(); diff --git a/src/CudaDataOperationAlgorithm.cpp b/src/CudaDataOperationAlgorithm.cpp index 79a9d7f..ae133c2 100644 --- a/src/CudaDataOperationAlgorithm.cpp +++ b/src/CudaDataOperationAlgorithm.cpp @@ -67,40 +67,37 @@ bool CCudaDataOperationAlgorithm::initialize(const Config& _cfg) ConfigStackCheck CC("CCudaDataOperationAlgorithm", this, _cfg); // operation - XMLNode* node = _cfg.self->getSingleNode("Operation"); + XMLNode node = _cfg.self.getSingleNode("Operation"); ASTRA_CONFIG_CHECK(node, "CCudaDataOperationAlgorithm", "No Operation tag specified."); - m_sOperation = node->getContent(); + m_sOperation = node.getContent(); m_sOperation.erase(std::remove(m_sOperation.begin(), m_sOperation.end(), ' '), m_sOperation.end()); - ASTRA_DELETE(node); CC.markNodeParsed("Operation"); // data - node = _cfg.self->getSingleNode("DataId"); + node = _cfg.self.getSingleNode("DataId"); ASTRA_CONFIG_CHECK(node, "CCudaDataOperationAlgorithm", "No DataId tag specified."); - vector data = node->getContentArray(); + vector data = node.getContentArray(); for (vector::iterator it = data.begin(); it != data.end(); it++){ int id = boost::lexical_cast(*it); m_pData.push_back(dynamic_cast(CData2DManager::getSingleton().get(id))); } - ASTRA_DELETE(node); CC.markNodeParsed("DataId"); // scalar - node = _cfg.self->getSingleNode("Scalar"); + node = _cfg.self.getSingleNode("Scalar"); ASTRA_CONFIG_CHECK(node, "CCudaDataOperationAlgorithm", "No Scalar tag specified."); - m_fScalar = node->getContentNumericalArray(); - ASTRA_DELETE(node); + m_fScalar = node.getContentNumericalArray(); CC.markNodeParsed("Scalar"); // Option: GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); - if (_cfg.self->hasOption("MaskId")) { - int id = boost::lexical_cast(_cfg.self->getOption("MaskId")); + if (_cfg.self.hasOption("MaskId")) { + int id = boost::lexical_cast(_cfg.self.getOption("MaskId")); m_pMask = dynamic_cast(CData2DManager::getSingleton().get(id)); } CC.markOptionParsed("MaskId"); diff --git a/src/CudaFDKAlgorithm3D.cpp b/src/CudaFDKAlgorithm3D.cpp index 7638696..467e641 100644 --- a/src/CudaFDKAlgorithm3D.cpp +++ b/src/CudaFDKAlgorithm3D.cpp @@ -100,12 +100,12 @@ bool CCudaFDKAlgorithm3D::initialize(const Config& _cfg) return false; } - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); CC.markOptionParsed("VoxelSuperSampling"); - m_bShortScan = _cfg.self->getOptionBool("ShortScan", false); + m_bShortScan = _cfg.self.getOptionBool("ShortScan", false); CC.markOptionParsed("ShortScan"); // success diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index 0badc20..5d6c166 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -78,39 +78,36 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) } // sinogram data - XMLNode* node = _cfg.self->getSingleNode("ProjectionDataId"); + XMLNode node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "CudaFBP", "No ProjectionDataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pSinogram = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionDataId"); // reconstruction data - node = _cfg.self->getSingleNode("ReconstructionDataId"); + node = _cfg.self.getSingleNode("ReconstructionDataId"); ASTRA_CONFIG_CHECK(node, "CudaFBP", "No ReconstructionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pReconstruction = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ReconstructionDataId"); // filter type - node = _cfg.self->getSingleNode("FilterType"); - if(node != NULL) + node = _cfg.self.getSingleNode("FilterType"); + if (node) { - m_eFilter = _convertStringToFilter(node->getContent().c_str()); + m_eFilter = _convertStringToFilter(node.getContent().c_str()); } else { m_eFilter = FILTER_RAMLAK; } CC.markNodeParsed("FilterType"); - ASTRA_DELETE(node); // filter - node = _cfg.self->getSingleNode("FilterSinogramId"); - if(node != NULL) + node = _cfg.self.getSingleNode("FilterSinogramId"); + if (node) { - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); const CFloat32ProjectionData2D * pFilterData = dynamic_cast(CData2DManager::getSingleton().get(id)); m_iFilterWidth = pFilterData->getGeometry()->getDetectorCount(); int iFilterProjectionCount = pFilterData->getGeometry()->getProjectionAngleCount(); @@ -124,13 +121,12 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) m_pfFilter = NULL; } CC.markNodeParsed("FilterSinogramId"); // TODO: Only for some types! - ASTRA_DELETE(node); // filter parameter - node = _cfg.self->getSingleNode("FilterParameter"); - if(node != NULL) + node = _cfg.self.getSingleNode("FilterParameter"); + if (node) { - float fParameter = boost::lexical_cast(node->getContent()); + float fParameter = boost::lexical_cast(node.getContent()); m_fFilterParameter = fParameter; } else @@ -138,13 +134,12 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) m_fFilterParameter = -1.0f; } CC.markNodeParsed("FilterParameter"); // TODO: Only for some types! - ASTRA_DELETE(node); // D value - node = _cfg.self->getSingleNode("FilterD"); - if(node != NULL) + node = _cfg.self.getSingleNode("FilterD"); + if (node) { - float fD = boost::lexical_cast(node->getContent()); + float fD = boost::lexical_cast(node.getContent()); m_fFilterD = fD; } else @@ -152,19 +147,18 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) m_fFilterD = 1.0f; } CC.markNodeParsed("FilterD"); // TODO: Only for some types! - ASTRA_DELETE(node); // GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); // Pixel supersampling factor - m_iPixelSuperSampling = (int)_cfg.self->getOptionNumerical("PixelSuperSampling", 1); + m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", 1); CC.markOptionParsed("PixelSuperSampling"); // Fan beam short scan mode if (m_pSinogram && dynamic_cast(m_pSinogram->getGeometry())) { - m_bShortScan = (int)_cfg.self->getOptionBool("ShortScan", false); + m_bShortScan = (int)_cfg.self.getOptionBool("ShortScan", false); CC.markOptionParsed("ShortScan"); } diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index 95abb62..0f97d59 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -73,42 +73,39 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) ConfigStackCheck CC("CudaForwardProjectionAlgorithm", this, _cfg); // sinogram data - XMLNode* node = _cfg.self->getSingleNode("ProjectionDataId"); + XMLNode node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "FP_CUDA", "No ProjectionDataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pSinogram = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionDataId"); // volume data - node = _cfg.self->getSingleNode("VolumeDataId"); + node = _cfg.self.getSingleNode("VolumeDataId"); ASTRA_CONFIG_CHECK(node, "FP_CUDA", "No VolumeDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pVolume = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("VolumeDataId"); // GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); // Detector supersampling factor - m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); CC.markOptionParsed("DetectorSuperSampling"); // This isn't used yet, but passing it is not something to warn about - node = _cfg.self->getSingleNode("ProjectorId"); + node = _cfg.self.getSingleNode("ProjectorId"); if (node) { - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { ASTRA_WARN("non-CUDA Projector2D passed to FP_CUDA"); } - delete node; } CC.markNodeParsed("ProjectorId"); diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp index 8e6bab5..e29b5a9 100644 --- a/src/CudaForwardProjectionAlgorithm3D.cpp +++ b/src/CudaForwardProjectionAlgorithm3D.cpp @@ -78,40 +78,37 @@ bool CCudaForwardProjectionAlgorithm3D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); ConfigStackCheck CC("CudaForwardProjectionAlgorithm3D", this, _cfg); - XMLNode* node; + XMLNode node; int id; // sinogram data - node = _cfg.self->getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "CudaForwardProjection3D", "No ProjectionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pProjections = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionDataId"); // reconstruction data - node = _cfg.self->getSingleNode("VolumeDataId"); + node = _cfg.self.getSingleNode("VolumeDataId"); ASTRA_CONFIG_CHECK(node, "CudaForwardProjection3D", "No VolumeDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pVolume = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("VolumeDataId"); // optional: projector - node = _cfg.self->getSingleNode("ProjectorId"); + node = _cfg.self.getSingleNode("ProjectorId"); if (node) { - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pProjector = CProjector3DManager::getSingleton().get(id); - ASTRA_DELETE(node); } else { m_pProjector = 0; // TODO: or manually construct default projector? } CC.markNodeParsed("ProjectorId"); // GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); CC.markOptionParsed("DetectorSuperSampling"); // success diff --git a/src/CudaProjector2D.cpp b/src/CudaProjector2D.cpp index 056ea3b..fa024c8 100644 --- a/src/CudaProjector2D.cpp +++ b/src/CudaProjector2D.cpp @@ -104,10 +104,10 @@ bool CCudaProjector2D::initialize(const Config& _cfg) // TODO: Check the projection geometry is a supported type - XMLNode* node = _cfg.self->getSingleNode("ProjectionKernel"); + XMLNode node = _cfg.self.getSingleNode("ProjectionKernel"); m_projectionKernel = ker2d_default; if (node) { - std::string sProjKernel = node->getContent(); + std::string sProjKernel = node.getContent(); if (sProjKernel == "default") { @@ -115,7 +115,6 @@ bool CCudaProjector2D::initialize(const Config& _cfg) return false; } } - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionKernel"); m_bIsInitialized = _check(); diff --git a/src/CudaProjector3D.cpp b/src/CudaProjector3D.cpp index 2f4c799..41529a5 100644 --- a/src/CudaProjector3D.cpp +++ b/src/CudaProjector3D.cpp @@ -105,10 +105,10 @@ bool CCudaProjector3D::initialize(const Config& _cfg) return false; } - XMLNode* node = _cfg.self->getSingleNode("ProjectionKernel"); + XMLNode node = _cfg.self.getSingleNode("ProjectionKernel"); m_projectionKernel = ker3d_default; if (node) { - std::string sProjKernel = node->getContent(); + std::string sProjKernel = node.getContent(); if (sProjKernel == "default") { @@ -118,7 +118,6 @@ bool CCudaProjector3D::initialize(const Config& _cfg) return false; } } - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionKernel"); m_bIsInitialized = _check(); diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index 1c6b763..db99d42 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -96,91 +96,88 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) } // sinogram data - XMLNode* node = _cfg.self->getSingleNode("ProjectionDataId"); + XMLNode node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "CudaSirt2", "No ProjectionDataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pSinogram = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionDataId"); // reconstruction data - node = _cfg.self->getSingleNode("ReconstructionDataId"); + node = _cfg.self.getSingleNode("ReconstructionDataId"); ASTRA_CONFIG_CHECK(node, "CudaSirt2", "No ReconstructionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pReconstruction = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ReconstructionDataId"); // fixed mask - if (_cfg.self->hasOption("ReconstructionMaskId")) { + if (_cfg.self.hasOption("ReconstructionMaskId")) { m_bUseReconstructionMask = true; - id = boost::lexical_cast(_cfg.self->getOption("ReconstructionMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("ReconstructionMaskId")); m_pReconstructionMask = dynamic_cast(CData2DManager::getSingleton().get(id)); ASTRA_CONFIG_CHECK(m_pReconstructionMask, "CudaReconstruction2D", "Invalid ReconstructionMaskId."); } CC.markOptionParsed("ReconstructionMaskId"); // fixed mask - if (_cfg.self->hasOption("SinogramMaskId")) { + if (_cfg.self.hasOption("SinogramMaskId")) { m_bUseSinogramMask = true; - id = boost::lexical_cast(_cfg.self->getOption("SinogramMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("SinogramMaskId")); m_pSinogramMask = dynamic_cast(CData2DManager::getSingleton().get(id)); ASTRA_CONFIG_CHECK(m_pSinogramMask, "CudaReconstruction2D", "Invalid SinogramMaskId."); } CC.markOptionParsed("SinogramMaskId"); // Constraints - NEW - if (_cfg.self->hasOption("MinConstraint")) { + if (_cfg.self.hasOption("MinConstraint")) { m_bUseMinConstraint = true; - m_fMinValue = _cfg.self->getOptionNumerical("MinConstraint", 0.0f); + m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f); CC.markOptionParsed("MinConstraint"); } else { // Constraint - OLD - m_bUseMinConstraint = _cfg.self->getOptionBool("UseMinConstraint", false); + m_bUseMinConstraint = _cfg.self.getOptionBool("UseMinConstraint", false); CC.markOptionParsed("UseMinConstraint"); if (m_bUseMinConstraint) { - m_fMinValue = _cfg.self->getOptionNumerical("MinConstraintValue", 0.0f); + m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f); CC.markOptionParsed("MinConstraintValue"); } } - if (_cfg.self->hasOption("MaxConstraint")) { + if (_cfg.self.hasOption("MaxConstraint")) { m_bUseMaxConstraint = true; - m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraint", 255.0f); + m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f); CC.markOptionParsed("MaxConstraint"); } else { // Constraint - OLD - m_bUseMaxConstraint = _cfg.self->getOptionBool("UseMaxConstraint", false); + m_bUseMaxConstraint = _cfg.self.getOptionBool("UseMaxConstraint", false); CC.markOptionParsed("UseMaxConstraint"); if (m_bUseMaxConstraint) { - m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraintValue", 0.0f); + m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 0.0f); CC.markOptionParsed("MaxConstraintValue"); } } // GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); // Detector supersampling factor - m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); CC.markOptionParsed("DetectorSuperSampling"); // Pixel supersampling factor - m_iPixelSuperSampling = (int)_cfg.self->getOptionNumerical("PixelSuperSampling", 1); + m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", 1); CC.markOptionParsed("PixelSuperSampling"); // This isn't used yet, but passing it is not something to warn about - node = _cfg.self->getSingleNode("ProjectorId"); + node = _cfg.self.getSingleNode("ProjectorId"); if (node) { - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast(projector)) { ASTRA_WARN("non-CUDA Projector2D passed"); } - delete node; } CC.markNodeParsed("ProjectorId"); diff --git a/src/CudaRoiSelectAlgorithm.cpp b/src/CudaRoiSelectAlgorithm.cpp index bfccb3a..7635c69 100644 --- a/src/CudaRoiSelectAlgorithm.cpp +++ b/src/CudaRoiSelectAlgorithm.cpp @@ -66,22 +66,21 @@ bool CCudaRoiSelectAlgorithm::initialize(const Config& _cfg) ConfigStackCheck CC("CudaDartMaskAlgorithm", this, _cfg); // reconstruction data - XMLNode* node = _cfg.self->getSingleNode("DataId"); + XMLNode node = _cfg.self.getSingleNode("DataId"); ASTRA_CONFIG_CHECK(node, "CudaRoiSelect", "No DataId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pData = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("DataId"); // Option: GPU number - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUIndex", m_iGPUIndex); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUIndex", m_iGPUIndex); CC.markOptionParsed("GPUindex"); - if (!_cfg.self->hasOption("GPUindex")) + if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); // Option: Radius - m_fRadius = (unsigned int)_cfg.self->getOptionNumerical("Radius", 0.0f); + m_fRadius = (unsigned int)_cfg.self.getOptionNumerical("Radius", 0.0f); CC.markOptionParsed("Radius"); _check(); diff --git a/src/CudaSartAlgorithm.cpp b/src/CudaSartAlgorithm.cpp index 8e22c59..8c0c6d7 100644 --- a/src/CudaSartAlgorithm.cpp +++ b/src/CudaSartAlgorithm.cpp @@ -74,7 +74,7 @@ bool CCudaSartAlgorithm::initialize(const Config& _cfg) // projection order int projectionCount = m_pSinogram->getGeometry()->getProjectionAngleCount(); int* projectionOrder = NULL; - string projOrder = _cfg.self->getOption("ProjectionOrder", "random"); + string projOrder = _cfg.self.getOption("ProjectionOrder", "random"); CC.markOptionParsed("ProjectionOrder"); if (projOrder == "sequential") { projectionOrder = new int[projectionCount]; @@ -97,7 +97,7 @@ bool CCudaSartAlgorithm::initialize(const Config& _cfg) sart->setProjectionOrder(projectionOrder, projectionCount); delete[] projectionOrder; } else if (projOrder == "custom") { - vector projOrderList = _cfg.self->getOptionNumericalArray("ProjectionOrderList"); + vector projOrderList = _cfg.self.getOptionNumericalArray("ProjectionOrderList"); projectionOrder = new int[projOrderList.size()]; for (int i = 0; i < projOrderList.size(); i++) { projectionOrder[i] = static_cast(projOrderList[i]); diff --git a/src/CudaSirtAlgorithm.cpp b/src/CudaSirtAlgorithm.cpp index f6eb79a..d424915 100644 --- a/src/CudaSirtAlgorithm.cpp +++ b/src/CudaSirtAlgorithm.cpp @@ -76,13 +76,13 @@ bool CCudaSirtAlgorithm::initialize(const Config& _cfg) return false; // min/max masks - if (_cfg.self->hasOption("MinMaskId")) { - int id = boost::lexical_cast(_cfg.self->getOption("MinMaskId")); + if (_cfg.self.hasOption("MinMaskId")) { + int id = boost::lexical_cast(_cfg.self.getOption("MinMaskId")); m_pMinMask = dynamic_cast(CData2DManager::getSingleton().get(id)); } CC.markOptionParsed("MinMaskId"); - if (_cfg.self->hasOption("MaxMaskId")) { - int id = boost::lexical_cast(_cfg.self->getOption("MaxMaskId")); + if (_cfg.self.hasOption("MaxMaskId")) { + int id = boost::lexical_cast(_cfg.self.getOption("MaxMaskId")); m_pMaxMask = dynamic_cast(CData2DManager::getSingleton().get(id)); } CC.markOptionParsed("MaxMaskId"); diff --git a/src/CudaSirtAlgorithm3D.cpp b/src/CudaSirtAlgorithm3D.cpp index da83c7e..5ad131b 100644 --- a/src/CudaSirtAlgorithm3D.cpp +++ b/src/CudaSirtAlgorithm3D.cpp @@ -107,11 +107,11 @@ bool CCudaSirtAlgorithm3D::initialize(const Config& _cfg) return false; } - m_iGPUIndex = (int)_cfg.self->getOptionNumerical("GPUindex", -1); + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iDetectorSuperSampling = (int)_cfg.self->getOptionNumerical("DetectorSuperSampling", 1); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); CC.markOptionParsed("DetectorSuperSampling"); - m_iVoxelSuperSampling = (int)_cfg.self->getOptionNumerical("VoxelSuperSampling", 1); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); CC.markOptionParsed("VoxelSuperSampling"); m_pSirt = new AstraSIRT3d(); diff --git a/src/FanFlatProjectionGeometry2D.cpp b/src/FanFlatProjectionGeometry2D.cpp index d757f18..32a19bc 100644 --- a/src/FanFlatProjectionGeometry2D.cpp +++ b/src/FanFlatProjectionGeometry2D.cpp @@ -134,17 +134,15 @@ bool CFanFlatProjectionGeometry2D::initialize(const Config& _cfg) CProjectionGeometry2D::initialize(_cfg); // Required: DistanceOriginDetector - XMLNode* node = _cfg.self->getSingleNode("DistanceOriginDetector"); + XMLNode node = _cfg.self.getSingleNode("DistanceOriginDetector"); ASTRA_CONFIG_CHECK(node, "FanFlatProjectionGeometry2D", "No DistanceOriginDetector tag specified."); - m_fOriginDetectorDistance = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_fOriginDetectorDistance = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DistanceOriginDetector"); // Required: DetectorOriginSource - node = _cfg.self->getSingleNode("DistanceOriginSource"); + node = _cfg.self.getSingleNode("DistanceOriginSource"); ASTRA_CONFIG_CHECK(node, "FanFlatProjectionGeometry2D", "No DistanceOriginSource tag specified."); - m_fOriginSourceDistance = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_fOriginSourceDistance = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DistanceOriginSource"); // success @@ -209,12 +207,12 @@ Config* CFanFlatProjectionGeometry2D::getConfiguration() const { Config* cfg = new Config(); cfg->initialize("ProjectionGeometry2D"); - cfg->self->addAttribute("type", "fanflat"); - cfg->self->addChildNode("DetectorCount", getDetectorCount()); - cfg->self->addChildNode("DetectorWidth", getDetectorWidth()); - cfg->self->addChildNode("DistanceOriginSource", getOriginSourceDistance()); - cfg->self->addChildNode("DistanceOriginDetector", getOriginDetectorDistance()); - cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + cfg->self.addAttribute("type", "fanflat"); + cfg->self.addChildNode("DetectorCount", getDetectorCount()); + cfg->self.addChildNode("DetectorWidth", getDetectorWidth()); + cfg->self.addChildNode("DistanceOriginSource", getOriginSourceDistance()); + cfg->self.addChildNode("DistanceOriginDetector", getOriginDetectorDistance()); + cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); return cfg; } //---------------------------------------------------------------------------------------- diff --git a/src/FanFlatVecProjectionGeometry2D.cpp b/src/FanFlatVecProjectionGeometry2D.cpp index 9c7b596..4104379 100644 --- a/src/FanFlatVecProjectionGeometry2D.cpp +++ b/src/FanFlatVecProjectionGeometry2D.cpp @@ -116,25 +116,23 @@ bool CFanFlatVecProjectionGeometry2D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); ConfigStackCheck CC("FanFlatVecProjectionGeometry2D", this, _cfg); - XMLNode* node; + XMLNode node; // TODO: Fix up class hierarchy... this class doesn't fit very well. // initialization of parent class //CProjectionGeometry2D::initialize(_cfg); // Required: DetectorCount - node = _cfg.self->getSingleNode("DetectorCount"); + node = _cfg.self.getSingleNode("DetectorCount"); ASTRA_CONFIG_CHECK(node, "FanFlatVecProjectionGeometry3D", "No DetectorRowCount tag specified."); - m_iDetectorCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iDetectorCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorCount"); // Required: Vectors - node = _cfg.self->getSingleNode("Vectors"); + node = _cfg.self.getSingleNode("Vectors"); ASTRA_CONFIG_CHECK(node, "FanFlatVecProjectionGeometry3D", "No Vectors tag specified."); - vector data = node->getContentNumericalArray(); + vector data = node.getContentNumericalArray(); CC.markNodeParsed("Vectors"); - ASTRA_DELETE(node); ASTRA_CONFIG_CHECK(data.size() % 6 == 0, "FanFlatVecProjectionGeometry3D", "Vectors doesn't consist of 6-tuples."); m_iProjectionAngleCount = data.size() / 6; m_pProjectionAngles = new SFanProjection[m_iProjectionAngleCount]; @@ -232,8 +230,8 @@ Config* CFanFlatVecProjectionGeometry2D::getConfiguration() const { Config* cfg = new Config(); cfg->initialize("ProjectionGeometry2D"); - cfg->self->addAttribute("type", "fanflat_vec"); - cfg->self->addChildNode("DetectorCount", getDetectorCount()); + cfg->self.addAttribute("type", "fanflat_vec"); + cfg->self.addChildNode("DetectorCount", getDetectorCount()); std::string vectors = ""; for (int i = 0; i < m_iProjectionAngleCount; ++i) { SFanProjection& p = m_pProjectionAngles[i]; @@ -245,7 +243,7 @@ Config* CFanFlatVecProjectionGeometry2D::getConfiguration() const vectors += boost::lexical_cast(p.fDetUY); if (i < m_iProjectionAngleCount-1) vectors += ';'; } - cfg->self->addChildNode("Vectors", vectors); + cfg->self.addChildNode("Vectors", vectors); return cfg; } //---------------------------------------------------------------------------------------- diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp index 4a8e5ac..f494d22 100644 --- a/src/FilteredBackProjectionAlgorithm.cpp +++ b/src/FilteredBackProjectionAlgorithm.cpp @@ -94,30 +94,27 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); // projector - XMLNode* node = _cfg.self->getSingleNode("ProjectorId"); + XMLNode node = _cfg.self.getSingleNode("ProjectorId"); ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ProjectorId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pProjector = CProjector2DManager::getSingleton().get(id); - ASTRA_DELETE(node); // sinogram data - node = _cfg.self->getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ProjectionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pSinogram = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); // volume data - node = _cfg.self->getSingleNode("ReconstructionDataId"); + node = _cfg.self.getSingleNode("ReconstructionDataId"); ASTRA_CONFIG_CHECK(node, "FilteredBackProjection", "No ReconstructionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pReconstruction = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); - node = _cfg.self->getSingleNode("ProjectionIndex"); + node = _cfg.self.getSingleNode("ProjectionIndex"); if (node) { - vector projectionIndex = node->getContentNumericalArray(); + vector projectionIndex = node.getContentNumericalArray(); int angleCount = projectionIndex.size(); int detectorCount = m_pProjector->getProjectionGeometry()->getDetectorCount(); @@ -154,7 +151,6 @@ bool CFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) m_pProjector = new CParallelBeamLineKernelProjector2D(pg,m_pReconstruction->getGeometry()); m_pSinogram = new CFloat32ProjectionData2D(pg, sinogramData2D); } - ASTRA_DELETE(node); // TODO: check that the angles are linearly spaced between 0 and pi diff --git a/src/ForwardProjectionAlgorithm.cpp b/src/ForwardProjectionAlgorithm.cpp index b530491..f356824 100644 --- a/src/ForwardProjectionAlgorithm.cpp +++ b/src/ForwardProjectionAlgorithm.cpp @@ -126,37 +126,34 @@ bool CForwardProjectionAlgorithm::initialize(const Config& _cfg) } // projector - XMLNode* node = _cfg.self->getSingleNode("ProjectorId"); + XMLNode node = _cfg.self.getSingleNode("ProjectorId"); ASTRA_CONFIG_CHECK(node, "ForwardProjection", "No ProjectorId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pProjector = CProjector2DManager::getSingleton().get(id); - ASTRA_DELETE(node); // sinogram data - node = _cfg.self->getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "ForwardProjection", "No ProjectionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pSinogram = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); // volume data - node = _cfg.self->getSingleNode("VolumeDataId"); + node = _cfg.self.getSingleNode("VolumeDataId"); ASTRA_CONFIG_CHECK(node, "ForwardProjection", "No VolumeDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pVolume = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); // volume mask - if (_cfg.self->hasOption("VolumeMaskId")) { + if (_cfg.self.hasOption("VolumeMaskId")) { m_bUseVolumeMask = true; - id = boost::lexical_cast(_cfg.self->getOption("VolumeMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("VolumeMaskId")); m_pVolumeMask = dynamic_cast(CData2DManager::getSingleton().get(id)); } // sino mask - if (_cfg.self->hasOption("SinogramMaskId")) { + if (_cfg.self.hasOption("SinogramMaskId")) { m_bUseSinogramMask = true; - id = boost::lexical_cast(_cfg.self->getOption("SinogramMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("SinogramMaskId")); m_pSinogramMask = dynamic_cast(CData2DManager::getSingleton().get(id)); } diff --git a/src/ParallelBeamBlobKernelProjector2D.cpp b/src/ParallelBeamBlobKernelProjector2D.cpp index 3253f88..4559a48 100644 --- a/src/ParallelBeamBlobKernelProjector2D.cpp +++ b/src/ParallelBeamBlobKernelProjector2D.cpp @@ -128,28 +128,28 @@ bool CParallelBeamBlobKernelProjector2D::initialize(const Config& _cfg) } // required: Kernel - XMLNode* node = _cfg.self->getSingleNode("Kernel"); + XMLNode node = _cfg.self.getSingleNode("Kernel"); ASTRA_CONFIG_CHECK(node, "BlobProjector", "No Kernel tag specified."); { // Required: KernelSize - XMLNode* node2 = node->getSingleNode("KernelSize"); + XMLNode node2 = node.getSingleNode("KernelSize"); ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelSize tag specified."); - m_fBlobSize = boost::lexical_cast(node2->getContent()); + m_fBlobSize = boost::lexical_cast(node2.getContent()); // Required: SampleRate - node2 = node->getSingleNode("SampleRate"); + node2 = node.getSingleNode("SampleRate"); ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/SampleRate tag specified."); - m_fBlobSampleRate = boost::lexical_cast(node2->getContent()); + m_fBlobSampleRate = boost::lexical_cast(node2.getContent()); // Required: SampleCount - node2 = node->getSingleNode("SampleCount"); + node2 = node.getSingleNode("SampleCount"); ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/SampleCount tag specified."); - m_iBlobSampleCount = boost::lexical_cast(node2->getContent()); + m_iBlobSampleCount = boost::lexical_cast(node2.getContent()); // Required: KernelValues - node2 = node->getSingleNode("KernelValues"); + node2 = node.getSingleNode("KernelValues"); ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelValues tag specified."); - vector values = node2->getContentNumericalArray(); + vector values = node2.getContentNumericalArray(); ASTRA_CONFIG_CHECK(values.size() == (unsigned int)m_iBlobSampleCount, "BlobProjector", "Number of specified values doesn't match SampleCount."); m_pfBlobValues = new float32[m_iBlobSampleCount]; for (int i = 0; i < m_iBlobSampleCount; i++) { @@ -157,9 +157,9 @@ bool CParallelBeamBlobKernelProjector2D::initialize(const Config& _cfg) } // Required: KernelValues - node2 = node->getSingleNode("KernelValuesNeg"); + node2 = node.getSingleNode("KernelValuesNeg"); ASTRA_CONFIG_CHECK(node2, "BlobProjector", "No Kernel/KernelValuesNeg tag specified."); - vector values2 = node2->getContentNumericalArray(); + vector values2 = node2.getContentNumericalArray(); ASTRA_CONFIG_CHECK(values2.size() == (unsigned int)m_iBlobSampleCount, "BlobProjector", "Number of specified values doesn't match SampleCount."); m_pfBlobValuesNeg = new float32[m_iBlobSampleCount]; for (int i = 0; i < m_iBlobSampleCount; i++) { diff --git a/src/ParallelProjectionGeometry2D.cpp b/src/ParallelProjectionGeometry2D.cpp index cac8f30..699e141 100644 --- a/src/ParallelProjectionGeometry2D.cpp +++ b/src/ParallelProjectionGeometry2D.cpp @@ -176,10 +176,10 @@ Config* CParallelProjectionGeometry2D::getConfiguration() const { Config* cfg = new Config(); cfg->initialize("ProjectionGeometry2D"); - cfg->self->addAttribute("type", "parallel"); - cfg->self->addChildNode("DetectorCount", getDetectorCount()); - cfg->self->addChildNode("DetectorWidth", getDetectorWidth()); - cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + cfg->self.addAttribute("type", "parallel"); + cfg->self.addChildNode("DetectorCount", getDetectorCount()); + cfg->self.addChildNode("DetectorWidth", getDetectorWidth()); + cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); return cfg; } //---------------------------------------------------------------------------------------- diff --git a/src/ParallelProjectionGeometry3D.cpp b/src/ParallelProjectionGeometry3D.cpp index eb200f9..1c87157 100644 --- a/src/ParallelProjectionGeometry3D.cpp +++ b/src/ParallelProjectionGeometry3D.cpp @@ -164,12 +164,12 @@ Config* CParallelProjectionGeometry3D::getConfiguration() const { Config* cfg = new Config(); cfg->initialize("ProjectionGeometry3D"); - cfg->self->addAttribute("type", "parallel3d"); - cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); - cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); - cfg->self->addChildNode("DetectorSpacingX", m_fDetectorSpacingX); - cfg->self->addChildNode("DetectorSpacingY", m_fDetectorSpacingY); - cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + cfg->self.addAttribute("type", "parallel3d"); + cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount); + cfg->self.addChildNode("DetectorSpacingX", m_fDetectorSpacingX); + cfg->self.addChildNode("DetectorSpacingY", m_fDetectorSpacingY); + cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); return cfg; } //---------------------------------------------------------------------------------------- diff --git a/src/ParallelVecProjectionGeometry3D.cpp b/src/ParallelVecProjectionGeometry3D.cpp index dc325e9..ffad6d0 100644 --- a/src/ParallelVecProjectionGeometry3D.cpp +++ b/src/ParallelVecProjectionGeometry3D.cpp @@ -73,33 +73,30 @@ bool CParallelVecProjectionGeometry3D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); ConfigStackCheck CC("ParallelVecProjectionGeometry3D", this, _cfg); - XMLNode* node; + XMLNode node; // TODO: Fix up class hierarchy... this class doesn't fit very well. // initialization of parent class //CProjectionGeometry3D::initialize(_cfg); // Required: DetectorRowCount - node = _cfg.self->getSingleNode("DetectorRowCount"); + node = _cfg.self.getSingleNode("DetectorRowCount"); ASTRA_CONFIG_CHECK(node, "ParallelVecProjectionGeometry3D", "No DetectorRowCount tag specified."); - m_iDetectorRowCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iDetectorRowCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorRowCount"); // Required: DetectorCount - node = _cfg.self->getSingleNode("DetectorColCount"); + node = _cfg.self.getSingleNode("DetectorColCount"); ASTRA_CONFIG_CHECK(node, "", "No DetectorColCount tag specified."); - m_iDetectorColCount = boost::lexical_cast(node->getContent()); + m_iDetectorColCount = boost::lexical_cast(node.getContent()); m_iDetectorTotCount = m_iDetectorRowCount * m_iDetectorColCount; - ASTRA_DELETE(node); CC.markNodeParsed("DetectorColCount"); // Required: Vectors - node = _cfg.self->getSingleNode("Vectors"); + node = _cfg.self.getSingleNode("Vectors"); ASTRA_CONFIG_CHECK(node, "ParallelVecProjectionGeometry3D", "No Vectors tag specified."); - vector data = node->getContentNumericalArrayDouble(); + vector data = node.getContentNumericalArrayDouble(); CC.markNodeParsed("Vectors"); - ASTRA_DELETE(node); ASTRA_CONFIG_CHECK(data.size() % 12 == 0, "ParallelVecProjectionGeometry3D", "Vectors doesn't consist of 12-tuples."); m_iProjectionAngleCount = data.size() / 12; m_pProjectionAngles = new SPar3DProjection[m_iProjectionAngleCount]; @@ -208,9 +205,9 @@ Config* CParallelVecProjectionGeometry3D::getConfiguration() const Config* cfg = new Config(); cfg->initialize("ProjectionGeometry3D"); - cfg->self->addAttribute("type", "parallel3d_vec"); - cfg->self->addChildNode("DetectorRowCount", m_iDetectorRowCount); - cfg->self->addChildNode("DetectorColCount", m_iDetectorColCount); + cfg->self.addAttribute("type", "parallel3d_vec"); + cfg->self.addChildNode("DetectorRowCount", m_iDetectorRowCount); + cfg->self.addChildNode("DetectorColCount", m_iDetectorColCount); std::string vectors = ""; for (int i = 0; i < m_iProjectionAngleCount; ++i) { @@ -229,7 +226,7 @@ Config* CParallelVecProjectionGeometry3D::getConfiguration() const vectors += boost::lexical_cast(p.fDetVZ); if (i < m_iProjectionAngleCount-1) vectors += ';'; } - cfg->self->addChildNode("Vectors", vectors); + cfg->self.addChildNode("Vectors", vectors); return cfg; } diff --git a/src/ProjectionGeometry2D.cpp b/src/ProjectionGeometry2D.cpp index 89b5fe0..b89605b 100644 --- a/src/ProjectionGeometry2D.cpp +++ b/src/ProjectionGeometry2D.cpp @@ -124,24 +124,21 @@ bool CProjectionGeometry2D::initialize(const Config& _cfg) } // Required: DetectorWidth - XMLNode* node = _cfg.self->getSingleNode("DetectorWidth"); + XMLNode node = _cfg.self.getSingleNode("DetectorWidth"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No DetectorWidth tag specified."); - m_fDetectorWidth = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_fDetectorWidth = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorWidth"); // Required: DetectorCount - node = _cfg.self->getSingleNode("DetectorCount"); + node = _cfg.self.getSingleNode("DetectorCount"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No DetectorCount tag specified."); - m_iDetectorCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iDetectorCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorCount"); // Required: ProjectionAngles - node = _cfg.self->getSingleNode("ProjectionAngles"); + node = _cfg.self.getSingleNode("ProjectionAngles"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry2D", "No ProjectionAngles tag specified."); - vector angles = node->getContentNumericalArray(); - delete node; + vector angles = node.getContentNumericalArray(); m_iProjectionAngleCount = angles.size(); ASTRA_CONFIG_CHECK(m_iProjectionAngleCount > 0, "ProjectionGeometry2D", "Not enough ProjectionAngles specified."); m_pfProjectionAngles = new float32[m_iProjectionAngleCount]; @@ -150,7 +147,7 @@ bool CProjectionGeometry2D::initialize(const Config& _cfg) } CC.markNodeParsed("ProjectionAngles"); - vector offset = _cfg.self->getOptionNumericalArray("ExtraDetectorOffset"); + vector offset = _cfg.self.getOptionNumericalArray("ExtraDetectorOffset"); m_pfExtraDetectorOffset = new float32[m_iProjectionAngleCount]; if (offset.size() == (size_t)m_iProjectionAngleCount) { for (int i = 0; i < m_iProjectionAngleCount; i++) { diff --git a/src/ProjectionGeometry3D.cpp b/src/ProjectionGeometry3D.cpp index 5b77767..ef0246c 100644 --- a/src/ProjectionGeometry3D.cpp +++ b/src/ProjectionGeometry3D.cpp @@ -149,38 +149,34 @@ bool CProjectionGeometry3D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); // Required: DetectorWidth - XMLNode* node = _cfg.self->getSingleNode("DetectorSpacingX"); + XMLNode node = _cfg.self.getSingleNode("DetectorSpacingX"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingX tag specified."); - m_fDetectorSpacingX = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_fDetectorSpacingX = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorSpacingX"); // Required: DetectorHeight - node = _cfg.self->getSingleNode("DetectorSpacingY"); + node = _cfg.self.getSingleNode("DetectorSpacingY"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorSpacingY tag specified."); - m_fDetectorSpacingY = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_fDetectorSpacingY = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorSpacingY"); // Required: DetectorRowCount - node = _cfg.self->getSingleNode("DetectorRowCount"); + node = _cfg.self.getSingleNode("DetectorRowCount"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorRowCount tag specified."); - m_iDetectorRowCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iDetectorRowCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("DetectorRowCount"); // Required: DetectorCount - node = _cfg.self->getSingleNode("DetectorColCount"); + node = _cfg.self.getSingleNode("DetectorColCount"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No DetectorColCount tag specified."); - m_iDetectorColCount = boost::lexical_cast(node->getContent()); + m_iDetectorColCount = boost::lexical_cast(node.getContent()); m_iDetectorTotCount = m_iDetectorRowCount * m_iDetectorColCount; - ASTRA_DELETE(node); CC.markNodeParsed("DetectorColCount"); // Required: ProjectionAngles - node = _cfg.self->getSingleNode("ProjectionAngles"); + node = _cfg.self.getSingleNode("ProjectionAngles"); ASTRA_CONFIG_CHECK(node, "ProjectionGeometry3D", "No ProjectionAngles tag specified."); - vector angles = node->getContentNumericalArray(); + vector angles = node.getContentNumericalArray(); m_iProjectionAngleCount = angles.size(); ASTRA_CONFIG_CHECK(m_iProjectionAngleCount > 0, "ProjectionGeometry3D", "Not enough ProjectionAngles specified."); m_pfProjectionAngles = new float32[m_iProjectionAngleCount]; @@ -188,7 +184,6 @@ bool CProjectionGeometry3D::initialize(const Config& _cfg) m_pfProjectionAngles[i] = angles[i]; } CC.markNodeParsed("ProjectionAngles"); - ASTRA_DELETE(node); // Interface class, so don't return true return false; diff --git a/src/Projector2D.cpp b/src/Projector2D.cpp index 32a2956..cf233a0 100644 --- a/src/Projector2D.cpp +++ b/src/Projector2D.cpp @@ -114,12 +114,12 @@ bool CProjector2D::initialize(const Config& _cfg) } // required: ProjectionGeometry - XMLNode* node = _cfg.self->getSingleNode("ProjectionGeometry"); + XMLNode node = _cfg.self.getSingleNode("ProjectionGeometry"); ASTRA_CONFIG_CHECK(node, "Projector2D", "No ProjectionGeometry tag specified."); // FIXME: Change how the base class is created. (This is duplicated // in astra_mex_data2d.cpp.) - std::string type = node->getAttribute("type"); + std::string type = node.getAttribute("type"); if (type == "sparse_matrix") { m_pProjectionGeometry = new CSparseMatrixProjectionGeometry2D(); m_pProjectionGeometry->initialize(Config(node)); @@ -141,7 +141,7 @@ bool CProjector2D::initialize(const Config& _cfg) // required: VolumeGeometry - node = _cfg.self->getSingleNode("VolumeGeometry"); + node = _cfg.self.getSingleNode("VolumeGeometry"); ASTRA_CONFIG_CHECK(node, "Projector2D", "No VolumeGeometry tag specified."); m_pVolumeGeometry = new CVolumeGeometry2D(); m_pVolumeGeometry->initialize(Config(node)); diff --git a/src/Projector3D.cpp b/src/Projector3D.cpp index 14cb16a..5e22105 100644 --- a/src/Projector3D.cpp +++ b/src/Projector3D.cpp @@ -92,11 +92,11 @@ bool CProjector3D::initialize(const Config& _cfg) assert(_cfg.self); ConfigStackCheck CC("Projector3D", this, _cfg); - XMLNode* node; + XMLNode node; - node = _cfg.self->getSingleNode("ProjectionGeometry"); + node = _cfg.self.getSingleNode("ProjectionGeometry"); ASTRA_CONFIG_CHECK(node, "Projector3D", "No ProjectionGeometry tag specified."); - std::string type = node->getAttribute("type"); + std::string type = node.getAttribute("type"); CProjectionGeometry3D* pProjGeometry = 0; if (type == "parallel3d") { pProjGeometry = new CParallelProjectionGeometry3D(); @@ -115,7 +115,7 @@ bool CProjector3D::initialize(const Config& _cfg) ASTRA_CONFIG_CHECK(m_pProjectionGeometry->isInitialized(), "Projector3D", "ProjectionGeometry not initialized."); CC.markNodeParsed("ProjectionGeometry"); - node = _cfg.self->getSingleNode("VolumeGeometry"); + node = _cfg.self.getSingleNode("VolumeGeometry"); ASTRA_CONFIG_CHECK(node, "Projector3D", "No VolumeGeometry tag specified."); CVolumeGeometry3D* pVolGeometry = new CVolumeGeometry3D(); pVolGeometry->initialize(Config(node)); // this deletes node diff --git a/src/ReconstructionAlgorithm2D.cpp b/src/ReconstructionAlgorithm2D.cpp index e089fac..767efe6 100644 --- a/src/ReconstructionAlgorithm2D.cpp +++ b/src/ReconstructionAlgorithm2D.cpp @@ -84,71 +84,68 @@ bool CReconstructionAlgorithm2D::initialize(const Config& _cfg) ConfigStackCheck CC("ReconstructionAlgorithm2D", this, _cfg); // projector - XMLNode* node = _cfg.self->getSingleNode("ProjectorId"); + XMLNode node = _cfg.self.getSingleNode("ProjectorId"); ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ProjectorId tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pProjector = CProjector2DManager::getSingleton().get(id); - ASTRA_DELETE(node); CC.markNodeParsed("ProjectorId"); // sinogram data - node = _cfg.self->getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ProjectionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pSinogram = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionDataId"); // reconstruction data - node = _cfg.self->getSingleNode("ReconstructionDataId"); + node = _cfg.self.getSingleNode("ReconstructionDataId"); ASTRA_CONFIG_CHECK(node, "Reconstruction2D", "No ReconstructionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pReconstruction = dynamic_cast(CData2DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ReconstructionDataId"); // fixed mask - if (_cfg.self->hasOption("ReconstructionMaskId")) { + if (_cfg.self.hasOption("ReconstructionMaskId")) { m_bUseReconstructionMask = true; - id = boost::lexical_cast(_cfg.self->getOption("ReconstructionMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("ReconstructionMaskId")); m_pReconstructionMask = dynamic_cast(CData2DManager::getSingleton().get(id)); ASTRA_CONFIG_CHECK(m_pReconstructionMask, "Reconstruction2D", "Invalid ReconstructionMaskId."); } CC.markOptionParsed("ReconstructionMaskId"); // fixed mask - if (_cfg.self->hasOption("SinogramMaskId")) { + if (_cfg.self.hasOption("SinogramMaskId")) { m_bUseSinogramMask = true; - id = boost::lexical_cast(_cfg.self->getOption("SinogramMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("SinogramMaskId")); m_pSinogramMask = dynamic_cast(CData2DManager::getSingleton().get(id)); ASTRA_CONFIG_CHECK(m_pSinogramMask, "Reconstruction2D", "Invalid SinogramMaskId."); } CC.markOptionParsed("SinogramMaskId"); // Constraints - NEW - if (_cfg.self->hasOption("MinConstraint")) { + if (_cfg.self.hasOption("MinConstraint")) { m_bUseMinConstraint = true; - m_fMinValue = _cfg.self->getOptionNumerical("MinConstraint", 0.0f); + m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f); CC.markOptionParsed("MinConstraint"); } else { // Constraint - OLD - m_bUseMinConstraint = _cfg.self->getOptionBool("UseMinConstraint", false); + m_bUseMinConstraint = _cfg.self.getOptionBool("UseMinConstraint", false); CC.markOptionParsed("UseMinConstraint"); if (m_bUseMinConstraint) { - m_fMinValue = _cfg.self->getOptionNumerical("MinConstraintValue", 0.0f); + m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f); CC.markOptionParsed("MinConstraintValue"); } } - if (_cfg.self->hasOption("MaxConstraint")) { + if (_cfg.self.hasOption("MaxConstraint")) { m_bUseMaxConstraint = true; - m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraint", 255.0f); + m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f); CC.markOptionParsed("MaxConstraint"); } else { // Constraint - OLD - m_bUseMaxConstraint = _cfg.self->getOptionBool("UseMaxConstraint", false); + m_bUseMaxConstraint = _cfg.self.getOptionBool("UseMaxConstraint", false); CC.markOptionParsed("UseMaxConstraint"); if (m_bUseMaxConstraint) { - m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraintValue", 0.0f); + m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 0.0f); CC.markOptionParsed("MaxConstraintValue"); } } diff --git a/src/ReconstructionAlgorithm3D.cpp b/src/ReconstructionAlgorithm3D.cpp index 13d069d..86b8ab2 100644 --- a/src/ReconstructionAlgorithm3D.cpp +++ b/src/ReconstructionAlgorithm3D.cpp @@ -104,7 +104,7 @@ bool CReconstructionAlgorithm3D::initialize(const Config& _cfg) ASTRA_ASSERT(_cfg.self); ConfigStackCheck CC("ReconstructionAlgorithm3D", this, _cfg); - XMLNode* node; + XMLNode node; int id; #if 0 // projector @@ -116,60 +116,58 @@ bool CReconstructionAlgorithm3D::initialize(const Config& _cfg) #endif // sinogram data - node = _cfg.self->getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "Reconstruction3D", "No ProjectionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pSinogram = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ProjectionDataId"); // reconstruction data - node = _cfg.self->getSingleNode("ReconstructionDataId"); + node = _cfg.self.getSingleNode("ReconstructionDataId"); ASTRA_CONFIG_CHECK(node, "Reconstruction3D", "No ReconstructionDataId tag specified."); - id = boost::lexical_cast(node->getContent()); + id = boost::lexical_cast(node.getContent()); m_pReconstruction = dynamic_cast(CData3DManager::getSingleton().get(id)); - ASTRA_DELETE(node); CC.markNodeParsed("ReconstructionDataId"); // fixed mask - if (_cfg.self->hasOption("ReconstructionMaskId")) { + if (_cfg.self.hasOption("ReconstructionMaskId")) { m_bUseReconstructionMask = true; - id = boost::lexical_cast(_cfg.self->getOption("ReconstructionMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("ReconstructionMaskId")); m_pReconstructionMask = dynamic_cast(CData3DManager::getSingleton().get(id)); } CC.markOptionParsed("ReconstructionMaskId"); // fixed mask - if (_cfg.self->hasOption("SinogramMaskId")) { + if (_cfg.self.hasOption("SinogramMaskId")) { m_bUseSinogramMask = true; - id = boost::lexical_cast(_cfg.self->getOption("SinogramMaskId")); + id = boost::lexical_cast(_cfg.self.getOption("SinogramMaskId")); m_pSinogramMask = dynamic_cast(CData3DManager::getSingleton().get(id)); } // Constraints - NEW - if (_cfg.self->hasOption("MinConstraint")) { + if (_cfg.self.hasOption("MinConstraint")) { m_bUseMinConstraint = true; - m_fMinValue = _cfg.self->getOptionNumerical("MinConstraint", 0.0f); + m_fMinValue = _cfg.self.getOptionNumerical("MinConstraint", 0.0f); CC.markOptionParsed("MinConstraint"); } else { // Constraint - OLD - m_bUseMinConstraint = _cfg.self->getOptionBool("UseMinConstraint", false); + m_bUseMinConstraint = _cfg.self.getOptionBool("UseMinConstraint", false); CC.markOptionParsed("UseMinConstraint"); if (m_bUseMinConstraint) { - m_fMinValue = _cfg.self->getOptionNumerical("MinConstraintValue", 0.0f); + m_fMinValue = _cfg.self.getOptionNumerical("MinConstraintValue", 0.0f); CC.markOptionParsed("MinConstraintValue"); } } - if (_cfg.self->hasOption("MaxConstraint")) { + if (_cfg.self.hasOption("MaxConstraint")) { m_bUseMaxConstraint = true; - m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraint", 255.0f); + m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraint", 255.0f); CC.markOptionParsed("MaxConstraint"); } else { // Constraint - OLD - m_bUseMaxConstraint = _cfg.self->getOptionBool("UseMaxConstraint", false); + m_bUseMaxConstraint = _cfg.self.getOptionBool("UseMaxConstraint", false); CC.markOptionParsed("UseMaxConstraint"); if (m_bUseMaxConstraint) { - m_fMaxValue = _cfg.self->getOptionNumerical("MaxConstraintValue", 0.0f); + m_fMaxValue = _cfg.self.getOptionNumerical("MaxConstraintValue", 0.0f); CC.markOptionParsed("MaxConstraintValue"); } } diff --git a/src/SartAlgorithm.cpp b/src/SartAlgorithm.cpp index f7a1677..e4dc5c7 100644 --- a/src/SartAlgorithm.cpp +++ b/src/SartAlgorithm.cpp @@ -126,7 +126,7 @@ bool CSartAlgorithm::initialize(const Config& _cfg) // projection order m_iCurrentProjection = 0; m_iProjectionCount = m_pProjector->getProjectionGeometry()->getProjectionAngleCount(); - string projOrder = _cfg.self->getOption("ProjectionOrder", "sequential"); + string projOrder = _cfg.self.getOption("ProjectionOrder", "sequential"); CC.markOptionParsed("ProjectionOrder"); if (projOrder == "sequential") { m_piProjectionOrder = new int[m_iProjectionCount]; @@ -145,7 +145,7 @@ bool CSartAlgorithm::initialize(const Config& _cfg) m_piProjectionOrder[i + k] = t; } } else if (projOrder == "custom") { - vector projOrderList = _cfg.self->getOptionNumericalArray("ProjectionOrderList"); + vector projOrderList = _cfg.self.getOptionNumericalArray("ProjectionOrderList"); m_piProjectionOrder = new int[projOrderList.size()]; for (int i = 0; i < m_iProjectionCount; i++) { m_piProjectionOrder[i] = static_cast(projOrderList[i]); diff --git a/src/SparseMatrixProjectionGeometry2D.cpp b/src/SparseMatrixProjectionGeometry2D.cpp index 86357d2..073720f 100644 --- a/src/SparseMatrixProjectionGeometry2D.cpp +++ b/src/SparseMatrixProjectionGeometry2D.cpp @@ -98,11 +98,10 @@ bool CSparseMatrixProjectionGeometry2D::initialize(const Config& _cfg) CProjectionGeometry2D::initialize(_cfg); // get matrix - XMLNode* node = _cfg.self->getSingleNode("MatrixID"); + XMLNode node = _cfg.self.getSingleNode("MatrixID"); ASTRA_CONFIG_CHECK(node, "SparseMatrixProjectionGeometry2D", "No MatrixID tag specified."); - int id = boost::lexical_cast(node->getContent()); + int id = boost::lexical_cast(node.getContent()); m_pMatrix = CMatrixManager::getSingleton().get(id); - ASTRA_DELETE(node); CC.markNodeParsed("MatrixID"); // success @@ -194,11 +193,11 @@ Config* CSparseMatrixProjectionGeometry2D::getConfiguration() const { Config* cfg = new Config(); cfg->initialize("ProjectionGeometry2D"); - cfg->self->addAttribute("type", "sparse matrix"); - cfg->self->addChildNode("DetectorCount", getDetectorCount()); - cfg->self->addChildNode("DetectorWidth", getDetectorWidth()); - cfg->self->addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); - cfg->self->addChildNode("MatrixID", CMatrixManager::getSingleton().getIndex(m_pMatrix)); + cfg->self.addAttribute("type", "sparse matrix"); + cfg->self.addChildNode("DetectorCount", getDetectorCount()); + cfg->self.addChildNode("DetectorWidth", getDetectorWidth()); + cfg->self.addChildNode("ProjectionAngles", m_pfProjectionAngles, m_iProjectionAngleCount); + cfg->self.addChildNode("MatrixID", CMatrixManager::getSingleton().getIndex(m_pMatrix)); return cfg; } diff --git a/src/VolumeGeometry2D.cpp b/src/VolumeGeometry2D.cpp index d412914..6eea1b2 100644 --- a/src/VolumeGeometry2D.cpp +++ b/src/VolumeGeometry2D.cpp @@ -164,24 +164,22 @@ bool CVolumeGeometry2D::initialize(const Config& _cfg) } // Required: GridColCount - XMLNode* node = _cfg.self->getSingleNode("GridColCount"); + XMLNode node = _cfg.self.getSingleNode("GridColCount"); ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridColCount tag specified."); - m_iGridColCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iGridColCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("GridColCount"); // Required: GridRowCount - node = _cfg.self->getSingleNode("GridRowCount"); + node = _cfg.self.getSingleNode("GridRowCount"); ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridRowCount tag specified."); - m_iGridRowCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iGridRowCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("GridRowCount"); // Optional: Window minima and maxima - m_fWindowMinX = _cfg.self->getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f); - m_fWindowMaxX = _cfg.self->getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f); - m_fWindowMinY = _cfg.self->getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f); - m_fWindowMaxY = _cfg.self->getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f); + m_fWindowMinX = _cfg.self.getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f); + m_fWindowMaxX = _cfg.self.getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f); + m_fWindowMinY = _cfg.self.getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f); + m_fWindowMaxY = _cfg.self.getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f); CC.markOptionParsed("WindowMinX"); CC.markOptionParsed("WindowMaxX"); CC.markOptionParsed("WindowMinY"); @@ -285,13 +283,13 @@ Config* CVolumeGeometry2D::getConfiguration() const Config* cfg = new Config(); cfg->initialize("VolumeGeometry2D"); - cfg->self->addChildNode("GridColCount", m_iGridColCount); - cfg->self->addChildNode("GridRowCount", m_iGridRowCount); + cfg->self.addChildNode("GridColCount", m_iGridColCount); + cfg->self.addChildNode("GridRowCount", m_iGridRowCount); - cfg->self->addOption("WindowMinX", m_fWindowMinX); - cfg->self->addOption("WindowMaxX", m_fWindowMaxX); - cfg->self->addOption("WindowMinY", m_fWindowMinY); - cfg->self->addOption("WindowMaxY", m_fWindowMaxY); + cfg->self.addOption("WindowMinX", m_fWindowMinX); + cfg->self.addOption("WindowMaxX", m_fWindowMaxX); + cfg->self.addOption("WindowMinY", m_fWindowMinY); + cfg->self.addOption("WindowMaxY", m_fWindowMaxY); return cfg; } diff --git a/src/VolumeGeometry3D.cpp b/src/VolumeGeometry3D.cpp index 66e6f0c..a1cf424 100644 --- a/src/VolumeGeometry3D.cpp +++ b/src/VolumeGeometry3D.cpp @@ -192,33 +192,30 @@ bool CVolumeGeometry3D::initialize(const Config& _cfg) } // Required: GridColCount - XMLNode* node = _cfg.self->getSingleNode("GridColCount"); + XMLNode node = _cfg.self.getSingleNode("GridColCount"); ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridColCount tag specified."); - m_iGridColCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iGridColCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("GridColCount"); // Required: GridRowCount - node = _cfg.self->getSingleNode("GridRowCount"); + node = _cfg.self.getSingleNode("GridRowCount"); ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridRowCount tag specified."); - m_iGridRowCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iGridRowCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("GridRowCount"); // Required: GridRowCount - node = _cfg.self->getSingleNode("GridSliceCount"); + node = _cfg.self.getSingleNode("GridSliceCount"); ASTRA_CONFIG_CHECK(node, "ReconstructionGeometry2D", "No GridSliceCount tag specified."); - m_iGridSliceCount = boost::lexical_cast(node->getContent()); - ASTRA_DELETE(node); + m_iGridSliceCount = boost::lexical_cast(node.getContent()); CC.markNodeParsed("GridSliceCount"); // Optional: Window minima and maxima - m_fWindowMinX = _cfg.self->getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f); - m_fWindowMaxX = _cfg.self->getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f); - m_fWindowMinY = _cfg.self->getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f); - m_fWindowMaxY = _cfg.self->getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f); - m_fWindowMinZ = _cfg.self->getOptionNumerical("WindowMinZ", -m_iGridSliceCount/2.0f); - m_fWindowMaxZ = _cfg.self->getOptionNumerical("WindowMaxZ", m_iGridSliceCount/2.0f); + m_fWindowMinX = _cfg.self.getOptionNumerical("WindowMinX", -m_iGridColCount/2.0f); + m_fWindowMaxX = _cfg.self.getOptionNumerical("WindowMaxX", m_iGridColCount/2.0f); + m_fWindowMinY = _cfg.self.getOptionNumerical("WindowMinY", -m_iGridRowCount/2.0f); + m_fWindowMaxY = _cfg.self.getOptionNumerical("WindowMaxY", m_iGridRowCount/2.0f); + m_fWindowMinZ = _cfg.self.getOptionNumerical("WindowMinZ", -m_iGridSliceCount/2.0f); + m_fWindowMaxZ = _cfg.self.getOptionNumerical("WindowMaxZ", m_iGridSliceCount/2.0f); CC.markOptionParsed("WindowMinX"); CC.markOptionParsed("WindowMaxX"); CC.markOptionParsed("WindowMinY"); @@ -386,16 +383,16 @@ Config* CVolumeGeometry3D::getConfiguration() const Config* cfg = new Config(); cfg->initialize("VolumeGeometry3D"); - cfg->self->addChildNode("GridColCount", m_iGridColCount); - cfg->self->addChildNode("GridRowCount", m_iGridRowCount); - cfg->self->addChildNode("GridSliceCount", m_iGridSliceCount); + cfg->self.addChildNode("GridColCount", m_iGridColCount); + cfg->self.addChildNode("GridRowCount", m_iGridRowCount); + cfg->self.addChildNode("GridSliceCount", m_iGridSliceCount); - cfg->self->addOption("WindowMinX", m_fWindowMinX); - cfg->self->addOption("WindowMaxX", m_fWindowMaxX); - cfg->self->addOption("WindowMinY", m_fWindowMinY); - cfg->self->addOption("WindowMaxY", m_fWindowMaxY); - cfg->self->addOption("WindowMinZ", m_fWindowMinZ); - cfg->self->addOption("WindowMaxZ", m_fWindowMaxZ); + cfg->self.addOption("WindowMinX", m_fWindowMinX); + cfg->self.addOption("WindowMaxX", m_fWindowMaxX); + cfg->self.addOption("WindowMinY", m_fWindowMinY); + cfg->self.addOption("WindowMaxY", m_fWindowMaxY); + cfg->self.addOption("WindowMinZ", m_fWindowMinZ); + cfg->self.addOption("WindowMaxZ", m_fWindowMaxZ); return cfg; } diff --git a/src/XMLDocument.cpp b/src/XMLDocument.cpp index da843b4..716ed9e 100644 --- a/src/XMLDocument.cpp +++ b/src/XMLDocument.cpp @@ -89,10 +89,9 @@ XMLDocument* XMLDocument::createDocument(string sRootName) } //----------------------------------------------------------------------------- -XMLNode* XMLDocument::getRootNode() +XMLNode XMLDocument::getRootNode() { - // TODO: clean up: this 'new' requires callers to do memory management - return new XMLNode(fDOMDocument->first_node()); + return XMLNode(fDOMDocument->first_node()); } //----------------------------------------------------------------------------- diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp index 5e9d927..75985cc 100644 --- a/src/XMLNode.cpp +++ b/src/XMLNode.cpp @@ -38,22 +38,11 @@ using namespace astra; using namespace std; -//----------------------------------------------------------------------------- -// Utility function to delete a list of nodes -static void deleteNodes(list& nodes) -{ - for (list::iterator i = nodes.begin(); i != nodes.end(); ++i) - delete (*i); - - nodes.clear(); -} - - //----------------------------------------------------------------------------- // default constructor XMLNode::XMLNode() { - + fDOMElement = 0; } //----------------------------------------------------------------------------- @@ -79,14 +68,14 @@ void XMLNode::setDOMNode(xml_node<>* n) //----------------------------------------------------------------------------- // print XML Node -void XMLNode::print() +void XMLNode::print() const { std::cout << fDOMElement; } //----------------------------------------------------------------------------- // print XML Node -std::string XMLNode::toString() +std::string XMLNode::toString() const { std::string s; ::print(std::back_inserter(s), *fDOMElement, 0); @@ -95,64 +84,61 @@ std::string XMLNode::toString() //----------------------------------------------------------------------------- // Get single node -XMLNode* XMLNode::getSingleNode(string name) +XMLNode XMLNode::getSingleNode(string name) const { xml_node<> *node = fDOMElement->first_node(name.c_str()); - if (node) - return new XMLNode(node); - else - return 0; + return XMLNode(node); } //----------------------------------------------------------------------------- // Get list of nodes -list XMLNode::getNodes(string name) +list XMLNode::getNodes(string name) const { - list result; + list result; xml_node<> *iter; for (iter = fDOMElement->first_node(name.c_str()); iter; iter = iter->next_sibling(name.c_str())) { - result.push_back(new XMLNode(iter)); + result.push_back(XMLNode(iter)); } return result; } //----------------------------------------------------------------------------- // Get list of nodes -list XMLNode::getNodes() +list XMLNode::getNodes() const { - list result; + list result; xml_node<> *iter; for (iter = fDOMElement->first_node(); iter; iter = iter->next_sibling()) { - result.push_back(new XMLNode(iter)); + result.push_back(XMLNode(iter)); } return result; } //----------------------------------------------------------------------------- // Get name of this node -std::string XMLNode::getName() +std::string XMLNode::getName() const { return fDOMElement->name(); } //----------------------------------------------------------------------------- // Get node content - STRING -string XMLNode::getContent() +string XMLNode::getContent() const { return fDOMElement->value(); } //----------------------------------------------------------------------------- // Get node content - NUMERICAL -float32 XMLNode::getContentNumerical() +float32 XMLNode::getContentNumerical() const { return boost::lexical_cast(getContent()); } //----------------------------------------------------------------------------- // Get node content - BOOLEAN -bool XMLNode::getContentBool() +bool XMLNode::getContentBool() const { string res = getContent(); return ((res == "1") || (res == "yes") || (res == "true") || (res == "on")); @@ -160,21 +146,20 @@ bool XMLNode::getContentBool() //----------------------------------------------------------------------------- // Get node content - STRING LIST -vector XMLNode::getContentArray() +vector XMLNode::getContentArray() const { // get listsize int iSize = boost::lexical_cast(getAttribute("listsize")); // create result array vector res(iSize); // loop all list item nodes - list nodes = getNodes("ListItem"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - int iIndex = (*it)->getAttributeNumerical("index"); - string sValue = (*it)->getAttribute("value"); + list nodes = getNodes("ListItem"); + for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { + int iIndex = it->getAttributeNumerical("index"); + string sValue = it->getAttribute("value"); ASTRA_ASSERT(iIndex < iSize); res[iIndex] = sValue; } - deleteNodes(nodes); // return return res; @@ -182,7 +167,7 @@ vector XMLNode::getContentArray() //----------------------------------------------------------------------------- // Get node content - NUMERICAL LIST -vector XMLNode::getContentNumericalArray() +vector XMLNode::getContentNumericalArray() const { // is scalar if (!hasAttribute("listsize")) { @@ -195,19 +180,18 @@ vector XMLNode::getContentNumericalArray() // create result array vector res(iSize); // loop all list item nodes - list nodes = getNodes("ListItem"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - int iIndex = (*it)->getAttributeNumerical("index"); - float32 fValue = (*it)->getAttributeNumerical("value"); + list nodes = getNodes("ListItem"); + for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { + int iIndex = it->getAttributeNumerical("index"); + float32 fValue = it->getAttributeNumerical("value"); ASTRA_ASSERT(iIndex < iSize); res[iIndex] = fValue; } - deleteNodes(nodes); // return return res; } -vector XMLNode::getContentNumericalArrayDouble() +vector XMLNode::getContentNumericalArrayDouble() const { // is scalar if (!hasAttribute("listsize")) { @@ -220,21 +204,20 @@ vector XMLNode::getContentNumericalArrayDouble() // create result array vector res(iSize); // loop all list item nodes - list nodes = getNodes("ListItem"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - int iIndex = (*it)->getAttributeNumerical("index"); - double fValue = (*it)->getAttributeNumericalDouble("value"); + list nodes = getNodes("ListItem"); + for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { + int iIndex = it->getAttributeNumerical("index"); + double fValue = it->getAttributeNumericalDouble("value"); ASTRA_ASSERT(iIndex < iSize); res[iIndex] = fValue; } - deleteNodes(nodes); // return return res; } //----------------------------------------------------------------------------- // Get node content - NUMERICAL LIST 2 -void XMLNode::getContentNumericalArray(float32*& _pfData, int& _iSize) +void XMLNode::getContentNumericalArray(float32*& _pfData, int& _iSize) const { // is scalar if (!hasAttribute("listsize")) { @@ -248,19 +231,18 @@ void XMLNode::getContentNumericalArray(float32*& _pfData, int& _iSize) // create result array _pfData = new float32[_iSize]; // loop all list item nodes - list nodes = getNodes("ListItem"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - int iIndex = (*it)->getAttributeNumerical("index"); - float32 fValue = (*it)->getAttributeNumerical("value"); + list nodes = getNodes("ListItem"); + for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { + int iIndex = it->getAttributeNumerical("index"); + float32 fValue = it->getAttributeNumerical("value"); ASTRA_ASSERT(iIndex < _iSize); _pfData[iIndex] = fValue; } - deleteNodes(nodes); } //----------------------------------------------------------------------------- // Is attribute? -bool XMLNode::hasAttribute(string _sName) +bool XMLNode::hasAttribute(string _sName) const { xml_attribute<> *attr = fDOMElement->first_attribute(_sName.c_str()); return (attr != 0); @@ -268,7 +250,7 @@ bool XMLNode::hasAttribute(string _sName) //----------------------------------------------------------------------------- // Get attribute - STRING -string XMLNode::getAttribute(string _sName, string _sDefaultValue) +string XMLNode::getAttribute(string _sName, string _sDefaultValue) const { xml_attribute<> *attr = fDOMElement->first_attribute(_sName.c_str()); @@ -279,12 +261,12 @@ string XMLNode::getAttribute(string _sName, string _sDefaultValue) //----------------------------------------------------------------------------- // Get attribute - NUMERICAL -float32 XMLNode::getAttributeNumerical(string _sName, float32 _fDefaultValue) +float32 XMLNode::getAttributeNumerical(string _sName, float32 _fDefaultValue) const { if (!hasAttribute(_sName)) return _fDefaultValue; return boost::lexical_cast(getAttribute(_sName)); } -double XMLNode::getAttributeNumericalDouble(string _sName, double _fDefaultValue) +double XMLNode::getAttributeNumericalDouble(string _sName, double _fDefaultValue) const { if (!hasAttribute(_sName)) return _fDefaultValue; return boost::lexical_cast(getAttribute(_sName)); @@ -292,7 +274,7 @@ double XMLNode::getAttributeNumericalDouble(string _sName, double _fDefaultValue //----------------------------------------------------------------------------- // Get attribute - BOOLEAN -bool XMLNode::getAttributeBool(string _sName, bool _bDefaultValue) +bool XMLNode::getAttributeBool(string _sName, bool _bDefaultValue) const { if (!hasAttribute(_sName)) return _bDefaultValue; string res = getAttribute(_sName); @@ -301,7 +283,7 @@ bool XMLNode::getAttributeBool(string _sName, bool _bDefaultValue) //----------------------------------------------------------------------------- // Has option? -bool XMLNode::hasOption(string _sKey) +bool XMLNode::hasOption(string _sKey) const { xml_node<> *iter; for (iter = fDOMElement->first_node("Option"); iter; iter = iter->next_sibling("Option")) { @@ -314,7 +296,7 @@ bool XMLNode::hasOption(string _sKey) //----------------------------------------------------------------------------- // Get option - STRING -string XMLNode::getOption(string _sKey, string _sDefaultValue) +string XMLNode::getOption(string _sKey, string _sDefaultValue) const { xml_node<> *iter; for (iter = fDOMElement->first_node("Option"); iter; iter = iter->next_sibling("Option")) { @@ -331,7 +313,7 @@ string XMLNode::getOption(string _sKey, string _sDefaultValue) //----------------------------------------------------------------------------- // Get option - NUMERICAL -float32 XMLNode::getOptionNumerical(string _sKey, float32 _fDefaultValue) +float32 XMLNode::getOptionNumerical(string _sKey, float32 _fDefaultValue) const { if (!hasOption(_sKey)) return _fDefaultValue; return boost::lexical_cast(getOption(_sKey)); @@ -339,7 +321,7 @@ float32 XMLNode::getOptionNumerical(string _sKey, float32 _fDefaultValue) //----------------------------------------------------------------------------- // Get option - BOOL -bool XMLNode::getOptionBool(string _sKey, bool _bDefaultValue) +bool XMLNode::getOptionBool(string _sKey, bool _bDefaultValue) const { bool bHasOption = hasOption(_sKey); if (!bHasOption) return _bDefaultValue; @@ -349,20 +331,18 @@ bool XMLNode::getOptionBool(string _sKey, bool _bDefaultValue) //----------------------------------------------------------------------------- // Get option - NUMERICAL ARRAY -vector XMLNode::getOptionNumericalArray(string _sKey) +vector XMLNode::getOptionNumericalArray(string _sKey) const { if (!hasOption(_sKey)) return vector(); - list nodes = getNodes("Option"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - if ((*it)->getAttribute("key") == _sKey) { - vector vals = (*it)->getContentNumericalArray(); - deleteNodes(nodes); + list nodes = getNodes("Option"); + for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { + if (it->getAttribute("key") == _sKey) { + vector vals = it->getContentNumericalArray(); return vals; } } - deleteNodes(nodes); return vector(); } @@ -385,41 +365,40 @@ vector XMLNode::getOptionNumericalArray(string _sKey) //----------------------------------------------------------------------------- // Add child node - EMPTY -XMLNode* XMLNode::addChildNode(string _sNodeName) +XMLNode XMLNode::addChildNode(string _sNodeName) { xml_document<> *doc = fDOMElement->document(); char *node_name = doc->allocate_string(_sNodeName.c_str()); xml_node<> *node = doc->allocate_node(node_element, node_name); fDOMElement->append_node(node); - // TODO: clean up: this 'new' requires callers to do memory management - return new XMLNode(node); + return XMLNode(node); } //----------------------------------------------------------------------------- // Add child node - STRING -XMLNode* XMLNode::addChildNode(string _sNodeName, string _sText) +XMLNode XMLNode::addChildNode(string _sNodeName, string _sText) { - XMLNode* res = addChildNode(_sNodeName); - res->setContent(_sText); + XMLNode res = addChildNode(_sNodeName); + res.setContent(_sText); return res; } //----------------------------------------------------------------------------- // Add child node - FLOAT -XMLNode* XMLNode::addChildNode(string _sNodeName, float32 _fValue) +XMLNode XMLNode::addChildNode(string _sNodeName, float32 _fValue) { - XMLNode* res = addChildNode(_sNodeName); - res->setContent(_fValue); + XMLNode res = addChildNode(_sNodeName); + res.setContent(_fValue); return res; } //----------------------------------------------------------------------------- // Add child node - LIST -XMLNode* XMLNode::addChildNode(string _sNodeName, float32* _pfList, int _iSize) +XMLNode XMLNode::addChildNode(string _sNodeName, float32* _pfList, int _iSize) { - XMLNode* res = addChildNode(_sNodeName); - res->setContent(_pfList, _iSize); + XMLNode res = addChildNode(_sNodeName); + res.setContent(_pfList, _iSize); return res; } @@ -472,20 +451,18 @@ void XMLNode::addAttribute(string _sName, float32 _fValue) // Add option - STRING void XMLNode::addOption(string _sName, string _sText) { - XMLNode* node = addChildNode("Option"); - node->addAttribute("key", _sName); - node->addAttribute("value", _sText); - delete node; + XMLNode node = addChildNode("Option"); + node.addAttribute("key", _sName); + node.addAttribute("value", _sText); } //----------------------------------------------------------------------------- // Add option - FLOAT void XMLNode::addOption(string _sName, float32 _sText) { - XMLNode* node = addChildNode("Option"); - node->addAttribute("key", _sName); - node->addAttribute("value", _sText); - delete node; + XMLNode node = addChildNode("Option"); + node.addAttribute("key", _sName); + node.addAttribute("value", _sText); } //----------------------------------------------------------------------------- -- cgit v1.2.3 From fff7470f1d74b0085355130350fa834ea8d37069 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 6 May 2015 13:50:11 +0200 Subject: Make XML array handling consistent setContent and getContent were using different XML formats previously. --- src/XMLNode.cpp | 150 ++++++++++++++++++++++++++++++++------------------------ 1 file changed, 87 insertions(+), 63 deletions(-) (limited to 'src') diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp index 75985cc..0ec701f 100644 --- a/src/XMLNode.cpp +++ b/src/XMLNode.cpp @@ -32,6 +32,11 @@ $Id$ #include "rapidxml/rapidxml_print.hpp" #include +#include +#include +#include + + using namespace rapidxml; using namespace astra; @@ -167,77 +172,43 @@ vector XMLNode::getContentArray() const //----------------------------------------------------------------------------- // Get node content - NUMERICAL LIST +// NB: A 2D matrix is returned as a linear list vector XMLNode::getContentNumericalArray() const { - // is scalar - if (!hasAttribute("listsize")) { - vector res(1); - res[0] = getContentNumerical(); - return res; - } + string input = getContent(); - int iSize = boost::lexical_cast(getAttribute("listsize")); - // create result array - vector res(iSize); - // loop all list item nodes - list nodes = getNodes("ListItem"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - int iIndex = it->getAttributeNumerical("index"); - float32 fValue = it->getAttributeNumerical("value"); - ASTRA_ASSERT(iIndex < iSize); - res[iIndex] = fValue; + // split + std::vector items; + boost::split(items, input, boost::is_any_of(",;")); + + // init list + vector out; + out.resize(items.size()); + + // loop elements + for (unsigned int i = 0; i < items.size(); i++) { + out[i] = boost::lexical_cast(items[i]); } - // return - return res; + return out; } vector XMLNode::getContentNumericalArrayDouble() const { - // is scalar - if (!hasAttribute("listsize")) { - vector res(1); - res[0] = getContentNumerical(); - return res; - } + string input = getContent(); - int iSize = boost::lexical_cast(getAttribute("listsize")); - // create result array - vector res(iSize); - // loop all list item nodes - list nodes = getNodes("ListItem"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - int iIndex = it->getAttributeNumerical("index"); - double fValue = it->getAttributeNumericalDouble("value"); - ASTRA_ASSERT(iIndex < iSize); - res[iIndex] = fValue; - } - // return - return res; -} + // split + std::vector items; + boost::split(items, input, boost::is_any_of(",;")); -//----------------------------------------------------------------------------- -// Get node content - NUMERICAL LIST 2 -void XMLNode::getContentNumericalArray(float32*& _pfData, int& _iSize) const -{ - // is scalar - if (!hasAttribute("listsize")) { - _iSize = 1; - _pfData = new float32[_iSize]; - _pfData[0] = getContentNumerical(); - return; - } - // get listsize - _iSize = boost::lexical_cast(getAttribute("listsize")); - // create result array - _pfData = new float32[_iSize]; - // loop all list item nodes - list nodes = getNodes("ListItem"); - for (list::iterator it = nodes.begin(); it != nodes.end(); it++) { - int iIndex = it->getAttributeNumerical("index"); - float32 fValue = it->getAttributeNumerical("value"); - ASTRA_ASSERT(iIndex < _iSize); - _pfData[iIndex] = fValue; + // init list + vector out; + out.resize(items.size()); + + // loop elements + for (unsigned int i = 0; i < items.size(); i++) { + out[i] = boost::lexical_cast(items[i]); } + return out; } //----------------------------------------------------------------------------- @@ -420,15 +391,68 @@ void XMLNode::setContent(float32 _fValue) //----------------------------------------------------------------------------- // Set content - LIST -void XMLNode::setContent(float32* pfList, int _iSize) -{ + +template +static std::string setContentList_internal(T* pfList, int _iSize) { std::string str = (_iSize > 0) ? boost::lexical_cast(pfList[0]) : ""; for (int i = 1; i < _iSize; i++) { str += "," + boost::lexical_cast(pfList[i]); } - setContent(str); + return str; +} + +void XMLNode::setContent(float32* pfList, int _iSize) +{ + setContent(setContentList_internal(pfList, _iSize)); +} + +void XMLNode::setContent(double* pfList, int _iSize) +{ + setContent(setContentList_internal(pfList, _iSize)); } +//----------------------------------------------------------------------------- +// Set content - MATRIX + +template +static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHeight, bool transposed) +{ + std::string str = ""; + + int s1,s2; + + if (!transposed) { + s1 = 1; + s2 = _iWidth; + } else { + s1 = _iHeight; + s2 = 1; + } + + for (int y = 0; y < _iHeight; ++y) { + if (_iWidth > 0) + str += boost::lexical_cast(_pfMatrix[0*s1 + y*s2]); + for (int x = 1; x < _iWidth; x++) + str += "," + boost::lexical_cast(_pfMatrix[x*s1 + y*s2]); + + if (y != _iHeight-1) + str += ";"; + } + + return str; +} + +void XMLNode::setContent(float32* _pfMatrix, int _iWidth, int _iHeight, bool transposed) +{ + setContent(setContentMatrix_internal(_pfMatrix, _iWidth, _iHeight, transposed)); +} + +void XMLNode::setContent(double* _pfMatrix, int _iWidth, int _iHeight, bool transposed) +{ + setContent(setContentMatrix_internal(_pfMatrix, _iWidth, _iHeight, transposed)); +} + + //----------------------------------------------------------------------------- // Add attribute - STRING void XMLNode::addAttribute(string _sName, string _sText) -- cgit v1.2.3