summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <wjp@usecode.org>2015-03-20 15:32:25 +0100
committerWillem Jan Palenstijn <wjp@usecode.org>2015-03-20 15:32:25 +0100
commit8d9ddc51076ce0da3d0a4216b1bc495783f3733c (patch)
tree200d43d0356f052fe23da463330e43b37138386e /src
parent2d55fd38b4a8ef5076c0591ae4147f81c1107ee3 (diff)
parent9ba78fcfa3dec88928df33be26821e3fd5a10727 (diff)
downloadastra-8d9ddc51076ce0da3d0a4216b1bc495783f3733c.tar.gz
astra-8d9ddc51076ce0da3d0a4216b1bc495783f3733c.tar.bz2
astra-8d9ddc51076ce0da3d0a4216b1bc495783f3733c.tar.xz
astra-8d9ddc51076ce0da3d0a4216b1bc495783f3733c.zip
Merge pull request #30 from dmpelt/logging
New logging API
Diffstat (limited to 'src')
-rw-r--r--src/ConeProjectionGeometry3D.cpp4
-rw-r--r--src/Config.cpp7
-rw-r--r--src/CudaFilteredBackProjectionAlgorithm.cpp16
-rw-r--r--src/CudaForwardProjectionAlgorithm.cpp4
-rw-r--r--src/CudaForwardProjectionAlgorithm3D.cpp4
-rw-r--r--src/CudaReconstructionAlgorithm2D.cpp4
-rw-r--r--src/FilteredBackProjectionAlgorithm.cpp4
-rw-r--r--src/Logger.cpp77
-rw-r--r--src/Logging.cpp184
9 files changed, 213 insertions, 91 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 bb122e0..8e6bab5 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_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/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;