diff options
author | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2015-04-15 14:27:52 +0200 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2015-04-15 14:27:52 +0200 |
commit | 66968b3886b3800afcecf8f089962f87243cf4b1 (patch) | |
tree | 7b162a87427c18eb37446d7f98a1e376ef5da73d /src | |
parent | 9458268a8b9192af98fc1b88bf0a5fbbc7696a77 (diff) | |
parent | 40475404d83d74d7b5db3f71ea1488a6de10ccc5 (diff) | |
download | astra-66968b3886b3800afcecf8f089962f87243cf4b1.tar.gz astra-66968b3886b3800afcecf8f089962f87243cf4b1.tar.bz2 astra-66968b3886b3800afcecf8f089962f87243cf4b1.tar.xz astra-66968b3886b3800afcecf8f089962f87243cf4b1.zip |
Merge branch 'master' into volgeom3d
Diffstat (limited to 'src')
-rw-r--r-- | src/ConeProjectionGeometry3D.cpp | 4 | ||||
-rw-r--r-- | src/Config.cpp | 7 | ||||
-rw-r--r-- | src/CudaFilteredBackProjectionAlgorithm.cpp | 16 | ||||
-rw-r--r-- | src/CudaForwardProjectionAlgorithm.cpp | 4 | ||||
-rw-r--r-- | src/CudaForwardProjectionAlgorithm3D.cpp | 4 | ||||
-rw-r--r-- | src/CudaReconstructionAlgorithm2D.cpp | 4 | ||||
-rw-r--r-- | src/FilteredBackProjectionAlgorithm.cpp | 4 | ||||
-rw-r--r-- | src/Float32ProjectionData2D.cpp | 19 | ||||
-rw-r--r-- | src/Float32ProjectionData3D.cpp | 9 | ||||
-rw-r--r-- | src/Float32VolumeData2D.cpp | 20 | ||||
-rw-r--r-- | src/Float32VolumeData3D.cpp | 9 | ||||
-rw-r--r-- | src/Logger.cpp | 77 | ||||
-rw-r--r-- | src/Logging.cpp | 184 | ||||
-rw-r--r-- | src/Projector3D.cpp | 3 |
14 files changed, 272 insertions, 92 deletions
diff --git a/src/ConeProjectionGeometry3D.cpp b/src/ConeProjectionGeometry3D.cpp index eb9adcf..1976901 100644 --- a/src/ConeProjectionGeometry3D.cpp +++ b/src/ConeProjectionGeometry3D.cpp @@ -28,6 +28,8 @@ $Id$ #include "astra/ConeProjectionGeometry3D.h" +#include "astra/Logging.h" + #include <boost/lexical_cast.hpp> #include <cstring> @@ -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_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 653935e..d860638 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 <sstream> + using namespace astra; using namespace std; @@ -144,7 +147,9 @@ bool ConfigStackCheck<T>::stopParsing() nodes.clear(); if (!errors.empty()) { - cout << "Warning: " << name << ": unused configuration options: " << errors << std::endl; + ostringstream os; + os << name << ": unused configuration options: " << errors; + ASTRA_WARN(os.str().c_str()); return false; } diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index fcdf860..0badc20 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -34,7 +34,7 @@ $Id$ #include "astra/AstraObjectManager.h" #include "../cuda/2d/astra.h" -#include <astra/Logger.h> +#include "astra/Logging.h" using namespace std; using namespace astra; @@ -105,7 +105,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) } CC.markNodeParsed("FilterType"); ASTRA_DELETE(node); - + // filter node = _cfg.self->getSingleNode("FilterSinogramId"); if(node != NULL) @@ -168,7 +168,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) CC.markOptionParsed("ShortScan"); } - + m_pFBP = new AstraFBP; @@ -186,7 +186,7 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(CFloat32ProjectionData2D * { clear(); } - + // required classes m_pSinogram = _pSinogram; m_pReconstruction = _pReconstruction; @@ -326,7 +326,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 +335,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 +387,7 @@ static bool stringCompareLowerCase(const char * _stringA, const char * _stringB) #else iCmpReturn = strcasecmp(_stringA, _stringB); #endif - + return (iCmpReturn == 0); } @@ -485,7 +485,7 @@ E_FBPFILTER CCudaFilteredBackProjectionAlgorithm::_convertStringToFilter(const c } else { - cerr << "Failed to convert \"" << _filterType << "\" into a filter." << endl; + ASTRA_ERROR("Failed to convert \"%s\" into a filter.",_filterType); } return output; diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index ab0d643..95abb62 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<int>(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast<CCudaProjector2D*>(projector)) { - cout << "Warning: non-CUDA Projector2D passed to FP_CUDA" << std::endl; + ASTRA_WARN("non-CUDA Projector2D passed to FP_CUDA"); } delete node; } diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp index 914ee2f..aa36715 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; @@ -261,7 +263,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_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 d3dedc5..1c6b763 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 <ctime> @@ -176,7 +178,7 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) id = boost::lexical_cast<int>(node->getContent()); CProjector2D *projector = CProjector2DManager::getSingleton().get(id); if (!dynamic_cast<CCudaProjector2D*>(projector)) { - cout << "Warning: non-CUDA Projector2D passed" << std::endl; + ASTRA_WARN("non-CUDA Projector2D passed"); } delete node; } diff --git a/src/FilteredBackProjectionAlgorithm.cpp b/src/FilteredBackProjectionAlgorithm.cpp index 50cf939..4a8e5ac 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_ERROR("Invalid Projection Index"); return false; } else { int orgIndex = (int)projectionIndex[i]; 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) @@ -119,6 +129,15 @@ bool CFloat32ProjectionData2D::initialize(CProjectionGeometry2D* _pGeometry, flo } //---------------------------------------------------------------------------------------- +// 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/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/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) { 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 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 <http://www.gnu.org/licenses/>. - ------------------------------------------------------------------------ -$Id$ -*/ - -#include <astra/Logger.h> - -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; diff --git a/src/Logging.cpp b/src/Logging.cpp new file mode 100644 index 0000000..8290ca0 --- /dev/null +++ b/src/Logging.cpp @@ -0,0 +1,184 @@ +/* +----------------------------------------------------------------------- +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 <http://www.gnu.org/licenses/>. + +----------------------------------------------------------------------- +$Id$ +*/ + +#define CLOG_MAIN +#include <astra/clog.h> + +#include <astra/Logging.h> + +#include <cstdio> + +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(); + if(fd==1||fd==2){ + clog_set_fd(0, fd); + }else{ + error(__FILE__,__LINE__,"Invalid file descriptor"); + } + _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); + clog_set_fmt(0, "%l: %m\n"); + 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::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; +bool CLogger::m_bInitialized = false; diff --git a/src/Projector3D.cpp b/src/Projector3D.cpp index b546ee9..14cb16a 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; @@ -119,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; |