From 7b25c857ded357c0cb0b481dac6404c27ed0293d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 5 Jul 2017 15:15:42 +0200 Subject: Reduce stringstream creation/imbue overhead --- src/Utilities.cpp | 19 ++++++++++++++++++- src/XMLNode.cpp | 17 +++++++++++------ 2 files changed, 29 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/Utilities.cpp b/src/Utilities.cpp index eb06d8b..eb34092 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -73,7 +73,24 @@ std::vector stringToFloatVector(const std::string &s) std::vector stringToDoubleVector(const std::string &s) { - return stringToVector(s); + std::vector out; + out.reserve(100); + std::istringstream iss; + iss.imbue(std::locale::classic()); + size_t current = 0; + size_t next; + do { + next = s.find_first_of(",;", current); + std::string t = s.substr(current, next - current); + iss.str(t); + iss.clear(); + double f; + iss >> f; + out.push_back(f); + current = next + 1; + } while (next != std::string::npos); + + return out; } template diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp index 3b7237f..0ddc511 100644 --- a/src/XMLNode.cpp +++ b/src/XMLNode.cpp @@ -30,6 +30,9 @@ along with the ASTRA Toolbox. If not, see . #include "rapidxml/rapidxml.hpp" #include "rapidxml/rapidxml_print.hpp" +#include +#include + using namespace rapidxml; using namespace astra; @@ -399,8 +402,6 @@ void XMLNode::setContent(double* pfList, int _iSize) template static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHeight, bool transposed) { - std::string str = ""; - int s1,s2; if (!transposed) { @@ -411,17 +412,21 @@ static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHe s2 = 1; } + std::ostringstream s; + s.imbue(std::locale::classic()); + s << std::setprecision(17); + for (int y = 0; y < _iHeight; ++y) { if (_iWidth > 0) - str += StringUtil::toString(_pfMatrix[0*s1 + y*s2]); + s << _pfMatrix[0*s1 + y*s2]; for (int x = 1; x < _iWidth; x++) - str += "," + StringUtil::toString(_pfMatrix[x*s1 + y*s2]); + s << "," << _pfMatrix[x*s1 + y*s2]; if (y != _iHeight-1) - str += ";"; + s << ";"; } - return str; + return s.str(); } void XMLNode::setContent(float32* _pfMatrix, int _iWidth, int _iHeight, bool transposed) -- cgit v1.2.3 From 8d8a3d26372d9c0a784e181121fc2b360f6fee51 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 31 Aug 2017 16:47:29 +0200 Subject: Add trailing ,/; to string repr of float vector/matrix This makes it possible to differentiate between a scalar and a one-element vector, and fixes #111. --- src/Utilities.cpp | 9 ++++++--- src/XMLNode.cpp | 9 ++++----- 2 files changed, 10 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Utilities.cpp b/src/Utilities.cpp index eb34092..c90e67b 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -77,6 +77,7 @@ std::vector stringToDoubleVector(const std::string &s) out.reserve(100); std::istringstream iss; iss.imbue(std::locale::classic()); + size_t length = s.size(); size_t current = 0; size_t next; do { @@ -88,7 +89,7 @@ std::vector stringToDoubleVector(const std::string &s) iss >> f; out.push_back(f); current = next + 1; - } while (next != std::string::npos); + } while (next != std::string::npos && current != length); return out; } @@ -97,6 +98,7 @@ template std::vector stringToVector(const std::string& s) { std::vector out; + size_t length = s.size(); size_t current = 0; size_t next; do { @@ -104,7 +106,7 @@ std::vector stringToVector(const std::string& s) std::string t = s.substr(current, next - current); out.push_back(stringTo(t)); current = next + 1; - } while (next != std::string::npos); + } while (next != std::string::npos && current != length); return out; } @@ -134,13 +136,14 @@ void splitString(std::vector &items, const std::string& s, const char *delim) { items.clear(); + size_t length = s.size(); size_t current = 0; size_t next; do { next = s.find_first_of(delim, current); items.push_back(s.substr(current, next - current)); current = next + 1; - } while (next != std::string::npos); + } while (next != std::string::npos && current != length); } } diff --git a/src/XMLNode.cpp b/src/XMLNode.cpp index 0ddc511..2bf1330 100644 --- a/src/XMLNode.cpp +++ b/src/XMLNode.cpp @@ -379,9 +379,9 @@ void XMLNode::setContent(float32 _fValue) template static std::string setContentList_internal(T* pfList, int _iSize) { - std::string str = (_iSize > 0) ? StringUtil::toString(pfList[0]) : ""; - for (int i = 1; i < _iSize; i++) { - str += "," + StringUtil::toString(pfList[i]); + std::string str; + for (int i = 0; i < _iSize; i++) { + str += StringUtil::toString(pfList[i]) + ","; } return str; } @@ -422,8 +422,7 @@ static std::string setContentMatrix_internal(T* _pfMatrix, int _iWidth, int _iHe for (int x = 1; x < _iWidth; x++) s << "," << _pfMatrix[x*s1 + y*s2]; - if (y != _iHeight-1) - s << ";"; + s << ";"; } return s.str(); -- cgit v1.2.3 From d1e2b4f904266c94f4ebf9fc5c95d495c95b0d5c Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 17 Oct 2017 22:06:13 +0200 Subject: Improve stringToFloatVector to match stringToDoubleVector --- src/Utilities.cpp | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/Utilities.cpp b/src/Utilities.cpp index c90e67b..2ae1b66 100644 --- a/src/Utilities.cpp +++ b/src/Utilities.cpp @@ -66,14 +66,10 @@ double stringToDouble(const std::string& s) template<> float stringTo(const std::string& s) { return stringToFloat(s); } template<> double stringTo(const std::string& s) { return stringToDouble(s); } -std::vector stringToFloatVector(const std::string &s) -{ - return stringToVector(s); -} - -std::vector stringToDoubleVector(const std::string &s) +template +std::vector stringToNumericVector(const std::string &s) { - std::vector out; + std::vector out; out.reserve(100); std::istringstream iss; iss.imbue(std::locale::classic()); @@ -85,7 +81,7 @@ std::vector stringToDoubleVector(const std::string &s) std::string t = s.substr(current, next - current); iss.str(t); iss.clear(); - double f; + T f; iss >> f; out.push_back(f); current = next + 1; @@ -94,6 +90,15 @@ std::vector stringToDoubleVector(const std::string &s) return out; } +std::vector stringToFloatVector(const std::string &s) +{ + return stringToNumericVector(s); +} +std::vector stringToDoubleVector(const std::string &s) +{ + return stringToNumericVector(s); +} + template std::vector stringToVector(const std::string& s) { -- cgit v1.2.3 From 521825da92af4d3a08609241353517b8ec7e780c Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 18 Oct 2017 23:00:25 +0200 Subject: Fix output initialization for MODE_ADD CGM jobs --- src/CompositeGeometryManager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src') diff --git a/src/CompositeGeometryManager.cpp b/src/CompositeGeometryManager.cpp index a4dace2..184144c 100644 --- a/src/CompositeGeometryManager.cpp +++ b/src/CompositeGeometryManager.cpp @@ -1386,6 +1386,12 @@ static bool doJob(const CCompositeGeometryManager::TJobSet::const_iterator& iter bool ok = dstMem->allocateGPUMemory(outx, outy, outz, zero ? astraCUDA3d::INIT_ZERO : astraCUDA3d::INIT_NO); if (!ok) ASTRA_ERROR("Error allocating GPU memory"); + if (!zero) { + // instead of zeroing output memory, copy from host + ok = dstMem->copyToGPUMemory(dstdims); + if (!ok) ASTRA_ERROR("Error copying output data to GPU"); + } + for (CCompositeGeometryManager::TJobList::const_iterator i = L.begin(); i != L.end(); ++i) { const CCompositeGeometryManager::SJob &j = *i; -- cgit v1.2.3 From d753de051893698bfd1e107a2d03b1a38b55dd91 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 31 Oct 2017 17:10:56 +0100 Subject: Remove some unnecessary includes --- src/CudaFilteredBackProjectionAlgorithm.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src') diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index 7e2df79..a5d7b93 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -517,12 +517,3 @@ E_FBPFILTER CCudaFilteredBackProjectionAlgorithm::_convertStringToFilter(const c return output; } -void CCudaFilteredBackProjectionAlgorithm::testGenFilter(E_FBPFILTER _eFilter, float _fD, int _iProjectionCount, cufftComplex * _pFilter, int _iFFTRealDetectorCount, int _iFFTFourierDetectorCount) -{ - genFilter(_eFilter, _fD, _iProjectionCount, _pFilter, _iFFTRealDetectorCount, _iFFTFourierDetectorCount); -} - -int CCudaFilteredBackProjectionAlgorithm::getGPUCount() -{ - return 0; -} -- cgit v1.2.3 From adda34cf902c246a75eb46800949dc15d5e84f37 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 1 Nov 2017 12:27:18 +0100 Subject: Remove unused code --- src/swrap.cpp | 46 ---------------------------------------------- 1 file changed, 46 deletions(-) delete mode 100644 src/swrap.cpp (limited to 'src') diff --git a/src/swrap.cpp b/src/swrap.cpp deleted file mode 100644 index c970ab5..0000000 --- a/src/swrap.cpp +++ /dev/null @@ -1,46 +0,0 @@ -/* ------------------------------------------------------------------------ -Copyright: 2010-2016, iMinds-Vision Lab, University of Antwerp - 2014-2016, CWI, Amsterdam - -Contact: astra@uantwerpen.be -Website: http://www.astra-toolbox.com/ - -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 . - ------------------------------------------------------------------------ -*/ - -#ifndef _MSC_VER - -#include "astra/swrap.h" -#include - -errno_t fopen_s(FILE** pFile, const char* filename, const char* mode) -{ - if (!pFile) - return EINVAL; - - FILE* x = fopen(filename, mode); - if (!x) - return errno; - - *pFile = x; - return 0; -} - -#endif -- cgit v1.2.3 From f70f68fcd465f421b566b199e23e66c1f186b01d Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 1 Nov 2017 15:05:13 +0100 Subject: Separate cuda from astra headers further --- src/CudaDartMaskAlgorithm.cpp | 1 + src/CudaDartSmoothingAlgorithm.cpp | 1 + src/CudaDataOperationAlgorithm.cpp | 1 + src/CudaRoiSelectAlgorithm.cpp | 1 + 4 files changed, 4 insertions(+) (limited to 'src') diff --git a/src/CudaDartMaskAlgorithm.cpp b/src/CudaDartMaskAlgorithm.cpp index 375d565..a2e1ee6 100644 --- a/src/CudaDartMaskAlgorithm.cpp +++ b/src/CudaDartMaskAlgorithm.cpp @@ -29,6 +29,7 @@ along with the ASTRA Toolbox. If not, see . #include "astra/CudaDartMaskAlgorithm.h" +#include "../cuda/2d/astra.h" #include "../cuda/2d/darthelper.h" #include "../cuda/2d/algo.h" diff --git a/src/CudaDartSmoothingAlgorithm.cpp b/src/CudaDartSmoothingAlgorithm.cpp index 0759ea0..9e586c0 100644 --- a/src/CudaDartSmoothingAlgorithm.cpp +++ b/src/CudaDartSmoothingAlgorithm.cpp @@ -29,6 +29,7 @@ along with the ASTRA Toolbox. If not, see . #include "astra/CudaDartSmoothingAlgorithm.h" +#include "../cuda/2d/astra.h" #include "../cuda/2d/darthelper.h" #include "../cuda/2d/algo.h" diff --git a/src/CudaDataOperationAlgorithm.cpp b/src/CudaDataOperationAlgorithm.cpp index f9466e2..6c6b27c 100644 --- a/src/CudaDataOperationAlgorithm.cpp +++ b/src/CudaDataOperationAlgorithm.cpp @@ -31,6 +31,7 @@ along with the ASTRA Toolbox. If not, see . #include "../cuda/2d/algo.h" #include "../cuda/2d/darthelper.h" +#include "../cuda/2d/astra.h" #include "../cuda/2d/arith.h" #include "astra/AstraObjectManager.h" diff --git a/src/CudaRoiSelectAlgorithm.cpp b/src/CudaRoiSelectAlgorithm.cpp index baf8a6f..2b0ba15 100644 --- a/src/CudaRoiSelectAlgorithm.cpp +++ b/src/CudaRoiSelectAlgorithm.cpp @@ -29,6 +29,7 @@ along with the ASTRA Toolbox. If not, see . #include "astra/CudaRoiSelectAlgorithm.h" +#include "../cuda/2d/astra.h" #include "../cuda/2d/darthelper.h" #include "../cuda/2d/algo.h" -- cgit v1.2.3 From bd2798bed2fddfe00dac006013a9fb1363417f20 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Tue, 14 Nov 2017 14:56:02 +0100 Subject: Remove unused code --- src/Float32Data3DMemory.cpp | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'src') diff --git a/src/Float32Data3DMemory.cpp b/src/Float32Data3DMemory.cpp index 5c5c310..017625b 100644 --- a/src/Float32Data3DMemory.cpp +++ b/src/Float32Data3DMemory.cpp @@ -71,8 +71,6 @@ bool CFloat32Data3DMemory::_initialize(int _iWidth, int _iHeight, int _iDepth) // allocate memory for the data, but do not fill it m_pfData = NULL; - m_ppfDataRowInd = NULL; - m_pppfDataSliceInd = NULL; m_pCustomMemory = 0; _allocateData(); @@ -103,8 +101,6 @@ bool CFloat32Data3DMemory::_initialize(int _iWidth, int _iHeight, int _iDepth, c // allocate memory for the data, but do not fill it m_pfData = NULL; - m_ppfDataRowInd = NULL; - m_pppfDataSliceInd = NULL; m_pCustomMemory = 0; _allocateData(); @@ -140,8 +136,6 @@ bool CFloat32Data3DMemory::_initialize(int _iWidth, int _iHeight, int _iDepth, f // allocate memory for the data, but do not fill it m_pfData = NULL; - m_ppfDataRowInd = NULL; - m_pppfDataSliceInd = NULL; m_pCustomMemory = 0; _allocateData(); @@ -178,8 +172,6 @@ bool CFloat32Data3DMemory::_initialize(int _iWidth, int _iHeight, int _iDepth, C // allocate memory for the data, but do not fill it m_pCustomMemory = _pCustomMemory; m_pfData = NULL; - m_ppfDataRowInd = NULL; - m_pppfDataSliceInd = NULL; _allocateData(); // initialization complete @@ -198,8 +190,6 @@ void CFloat32Data3DMemory::_allocateData() ASTRA_ASSERT(m_iSize > 0); ASTRA_ASSERT(m_iSize == (size_t)m_iWidth * m_iHeight * m_iDepth); ASTRA_ASSERT(m_pfData == NULL); - ASTRA_ASSERT(m_ppfDataRowInd == NULL); - ASTRA_ASSERT(m_pppfDataSliceInd == NULL); if (!m_pCustomMemory) { // allocate contiguous block @@ -213,20 +203,6 @@ void CFloat32Data3DMemory::_allocateData() } else { m_pfData = m_pCustomMemory->m_fPtr; } - - // create array of pointers to each row of the data block - m_ppfDataRowInd = new float32*[m_iHeight*m_iDepth]; - for (int iy = 0; iy < m_iHeight*m_iDepth; iy++) - { - m_ppfDataRowInd[iy] = &(m_pfData[iy * m_iWidth]); - } - - // create array of pointers to each row of the data block - m_pppfDataSliceInd = new float32**[m_iDepth]; - for (int iy = 0; iy < m_iDepth; iy++) - { - m_pppfDataSliceInd[iy] = &(m_ppfDataRowInd[iy * m_iHeight]); - } } //---------------------------------------------------------------------------------------- @@ -235,13 +211,6 @@ void CFloat32Data3DMemory::_freeData() { // basic checks ASTRA_ASSERT(m_pfData != NULL); - ASTRA_ASSERT(m_ppfDataRowInd != NULL); - ASTRA_ASSERT(m_pppfDataSliceInd != NULL); - - // free memory for index table - delete[] m_pppfDataSliceInd; - // free memory for index table - delete[] m_ppfDataRowInd; if (!m_pCustomMemory) { // free memory for data block @@ -266,8 +235,6 @@ void CFloat32Data3DMemory::_clear() m_iSize = 0; m_pfData = NULL; - m_ppfDataRowInd = NULL; - m_pppfDataSliceInd = NULL; m_pCustomMemory = NULL; } -- cgit v1.2.3