diff options
author | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2015-09-16 15:52:30 +0200 |
---|---|---|
committer | Willem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl> | 2015-09-16 15:52:40 +0200 |
commit | 8144bf0397ee1913b830d82058ccd40df741f1b3 (patch) | |
tree | 7f707615c104621226fd8bdd868f86aee8e5bd73 | |
parent | 47b520d51fc4fc49db992b9117f6c0abfa8152b5 (diff) | |
parent | c1713c00c4aeae594913667d868106e8591dd1d1 (diff) | |
download | astra-8144bf0397ee1913b830d82058ccd40df741f1b3.tar.gz astra-8144bf0397ee1913b830d82058ccd40df741f1b3.tar.bz2 astra-8144bf0397ee1913b830d82058ccd40df741f1b3.tar.xz astra-8144bf0397ee1913b830d82058ccd40df741f1b3.zip |
Merge branch 'master'
-rw-r--r-- | include/astra/CudaProjector2D.h | 6 | ||||
-rw-r--r-- | include/astra/CudaProjector3D.h | 5 | ||||
-rw-r--r-- | matlab/mex/astra_mex_log_c.cpp | 8 | ||||
-rw-r--r-- | matlab/mex/mexInitFunctions.cpp | 2 | ||||
-rw-r--r-- | matlab/tools/astra_create_fbp_reconstruction.m | 1 | ||||
-rw-r--r-- | matlab/tools/opTomo.m | 2 | ||||
-rw-r--r-- | python/astra/PyIncludes.pxd | 2 | ||||
-rw-r--r-- | python/astra/algorithm_c.pyx | 4 | ||||
-rw-r--r-- | python/astra/log_c.pyx | 8 | ||||
-rw-r--r-- | python/astra/optomo.py | 18 | ||||
-rw-r--r-- | samples/matlab/s010_supersampling.m | 28 | ||||
-rw-r--r-- | src/CudaBackProjectionAlgorithm3D.cpp | 14 | ||||
-rw-r--r-- | src/CudaCglsAlgorithm3D.cpp | 22 | ||||
-rw-r--r-- | src/CudaFDKAlgorithm3D.cpp | 13 | ||||
-rw-r--r-- | src/CudaFilteredBackProjectionAlgorithm.cpp | 27 | ||||
-rw-r--r-- | src/CudaForwardProjectionAlgorithm.cpp | 38 | ||||
-rw-r--r-- | src/CudaForwardProjectionAlgorithm3D.cpp | 16 | ||||
-rw-r--r-- | src/CudaProjector2D.cpp | 8 | ||||
-rw-r--r-- | src/CudaProjector3D.cpp | 8 | ||||
-rw-r--r-- | src/CudaReconstructionAlgorithm2D.cpp | 44 | ||||
-rw-r--r-- | src/CudaSirtAlgorithm3D.cpp | 23 | ||||
-rw-r--r-- | src/ReconstructionAlgorithm3D.cpp | 19 |
22 files changed, 231 insertions, 85 deletions
diff --git a/include/astra/CudaProjector2D.h b/include/astra/CudaProjector2D.h index a571851..ecfca41 100644 --- a/include/astra/CudaProjector2D.h +++ b/include/astra/CudaProjector2D.h @@ -121,9 +121,15 @@ public: virtual std::string description() const; + Cuda2DProjectionKernel getProjectionKernel() const { return m_projectionKernel; } + int getVoxelSuperSampling() const { return m_iVoxelSuperSampling; } + int getDetectorSuperSampling() const { return m_iDetectorSuperSampling; } + protected: Cuda2DProjectionKernel m_projectionKernel; + int m_iVoxelSuperSampling; + int m_iDetectorSuperSampling; }; //---------------------------------------------------------------------------------------- diff --git a/include/astra/CudaProjector3D.h b/include/astra/CudaProjector3D.h index a181531..1d570fe 100644 --- a/include/astra/CudaProjector3D.h +++ b/include/astra/CudaProjector3D.h @@ -115,11 +115,14 @@ public: Cuda3DProjectionKernel getProjectionKernel() const { return m_projectionKernel; } + int getVoxelSuperSampling() const { return m_iVoxelSuperSampling; } + int getDetectorSuperSampling() const { return m_iDetectorSuperSampling; } protected: Cuda3DProjectionKernel m_projectionKernel; - + int m_iVoxelSuperSampling; + int m_iDetectorSuperSampling; }; diff --git a/matlab/mex/astra_mex_log_c.cpp b/matlab/mex/astra_mex_log_c.cpp index ea4621e..905612c 100644 --- a/matlab/mex/astra_mex_log_c.cpp +++ b/matlab/mex/astra_mex_log_c.cpp @@ -55,7 +55,7 @@ void astra_mex_log_debug(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::debug(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::debug(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- @@ -75,7 +75,7 @@ void astra_mex_log_info(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::info(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::info(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- @@ -95,7 +95,7 @@ void astra_mex_log_warn(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::warn(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::warn(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- @@ -115,7 +115,7 @@ void astra_mex_log_error(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prh string filename = mexToString(prhs[1]); int linenumber = (int)mxGetScalar(prhs[2]); string message = mexToString(prhs[3]); - astra::CLogger::error(filename.c_str(),linenumber,message.c_str()); + astra::CLogger::error(filename.c_str(),linenumber,"%s",message.c_str()); } //----------------------------------------------------------------------------------------- diff --git a/matlab/mex/mexInitFunctions.cpp b/matlab/mex/mexInitFunctions.cpp index d8a50d7..89a31a1 100644 --- a/matlab/mex/mexInitFunctions.cpp +++ b/matlab/mex/mexInitFunctions.cpp @@ -8,7 +8,7 @@ bool mexIsInitialized=false; * */ void logCallBack(const char *msg, size_t len){ - mexPrintf(msg); + mexPrintf("%s",msg); } /** diff --git a/matlab/tools/astra_create_fbp_reconstruction.m b/matlab/tools/astra_create_fbp_reconstruction.m index 5540f27..a2561b7 100644 --- a/matlab/tools/astra_create_fbp_reconstruction.m +++ b/matlab/tools/astra_create_fbp_reconstruction.m @@ -19,6 +19,7 @@ cfg.ProjectorId = proj_id; cfg.Options.GPUindex = 0; alg_id = astra_mex_algorithm('create', cfg); astra_mex_algorithm('run', alg_id); +astra_mex_algorithm('delete', alg_id); if numel(sinogram) ~= 1 astra_mex_data2d('delete', sinogram_id); diff --git a/matlab/tools/opTomo.m b/matlab/tools/opTomo.m index 14128d2..71dfb1e 100644 --- a/matlab/tools/opTomo.m +++ b/matlab/tools/opTomo.m @@ -248,6 +248,7 @@ classdef opTomo < opSpot % cleanup astra_mex_data3d('delete', vol_id); astra_mex_data3d('delete', sino_id); + astra_mex_algorithm('delete', alg_id); else % X is passed as a vector, reshape it into projection data x = reshape(x, op.proj_size); @@ -272,6 +273,7 @@ classdef opTomo < opSpot % cleanup astra_mex_data3d('delete', vol_id); astra_mex_data3d('delete', sino_id); + astra_mex_algorithm('delete', alg_id); end end % opTomo_intrnl3D diff --git a/python/astra/PyIncludes.pxd b/python/astra/PyIncludes.pxd index 909f58f..35dea5f 100644 --- a/python/astra/PyIncludes.pxd +++ b/python/astra/PyIncludes.pxd @@ -143,7 +143,7 @@ cdef extern from "astra/Float32ProjectionData2D.h" namespace "astra": cdef extern from "astra/Algorithm.h" namespace "astra": cdef cppclass CAlgorithm: bool initialize(Config) - void run(int) + void run(int) nogil bool isInitialized() cdef extern from "astra/ReconstructionAlgorithm2D.h" namespace "astra": diff --git a/python/astra/algorithm_c.pyx b/python/astra/algorithm_c.pyx index 966d3d7..3231c1f 100644 --- a/python/astra/algorithm_c.pyx +++ b/python/astra/algorithm_c.pyx @@ -73,7 +73,9 @@ cdef CAlgorithm * getAlg(i) except NULL: def run(i, iterations=0): cdef CAlgorithm * alg = getAlg(i) - alg.run(iterations) + cdef int its = iterations + with nogil: + alg.run(its) def get_res_norm(i): diff --git a/python/astra/log_c.pyx b/python/astra/log_c.pyx index f16329f..55c63e6 100644 --- a/python/astra/log_c.pyx +++ b/python/astra/log_c.pyx @@ -53,19 +53,19 @@ cdef extern from "astra/Logging.h" namespace "astra::CLogger": def log_debug(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - debug(cstr[0],sline,cstr[1]) + debug(cstr[0],sline,"%s",<char*>cstr[1]) def log_info(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - info(cstr[0],sline,cstr[1]) + info(cstr[0],sline,"%s",<char*>cstr[1]) def log_warn(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - warn(cstr[0],sline,cstr[1]) + warn(cstr[0],sline,"%s",<char*>cstr[1]) def log_error(sfile, sline, message): cstr = list(map(six.b,(sfile,message))) - error(cstr[0],sline,cstr[1]) + error(cstr[0],sline,"%s",<char*>cstr[1]) def log_enable(): enable() diff --git a/python/astra/optomo.py b/python/astra/optomo.py index 0108674..4a64150 100644 --- a/python/astra/optomo.py +++ b/python/astra/optomo.py @@ -86,7 +86,15 @@ class OpTomo(scipy.sparse.linalg.LinearOperator): self.proj_id = proj_id - self.T = OpTomoTranspose(self) + self.transposeOpTomo = OpTomoTranspose(self) + try: + self.T = self.transposeOpTomo + except AttributeError: + # Scipy >= 0.16 defines self.T using self._transpose() + pass + + def _transpose(self): + return self.transposeOpTomo def __checkArray(self, arr, shp): if len(arr.shape)==1: @@ -189,6 +197,11 @@ class OpTomoTranspose(scipy.sparse.linalg.LinearOperator): self.parent = parent self.dtype = np.float32 self.shape = (parent.shape[1], parent.shape[0]) + try: + self.T = self.parent + except AttributeError: + # Scipy >= 0.16 defines self.T using self._transpose() + pass def _matvec(self, s): return self.parent.rmatvec(s) @@ -196,6 +209,9 @@ class OpTomoTranspose(scipy.sparse.linalg.LinearOperator): def rmatvec(self, v): return self.parent.matvec(v) + def _transpose(self): + return self.parent + def __mul__(self,s): # Catch the case of a backprojection of 2D/3D data if isinstance(s, np.ndarray) and s.shape==self.parent.sshape: diff --git a/samples/matlab/s010_supersampling.m b/samples/matlab/s010_supersampling.m index 80f6f56..148f6ad 100644 --- a/samples/matlab/s010_supersampling.m +++ b/samples/matlab/s010_supersampling.m @@ -12,23 +12,15 @@ vol_geom = astra_create_vol_geom(256, 256); proj_geom = astra_create_proj_geom('parallel', 3.0, 128, linspace2(0,pi,180)); P = phantom(256); -% Because the astra_create_sino_gpu wrapper does not have support for -% all possible algorithm options, we manually create a sinogram -phantom_id = astra_mex_data2d('create', '-vol', vol_geom, P); -sinogram_id = astra_mex_data2d('create', '-sino', proj_geom); -cfg = astra_struct('FP_CUDA'); -cfg.VolumeDataId = phantom_id; -cfg.ProjectionDataId = sinogram_id; +% We create a projector set up to use 3 rays per detector element +cfg_proj = astra_struct('cuda'); +cfg_proj.option.DetectorSuperSampling = 3; +cfg_proj.ProjectionGeometry = proj_geom; +cfg_proj.VolumeGeometry = vol_geom; +proj_id = astra_mex_projector('create', cfg_proj); -% Set up 3 rays per detector element -cfg.option.DetectorSuperSampling = 3; -alg_id = astra_mex_algorithm('create', cfg); -astra_mex_algorithm('run', alg_id); -astra_mex_algorithm('delete', alg_id); -astra_mex_data2d('delete', phantom_id); - -sinogram3 = astra_mex_data2d('get', sinogram_id); +[sinogram3 sinogram_id] = astra_create_sino(P, proj_id); figure(1); imshow(P, []); figure(2); imshow(sinogram3, []); @@ -39,14 +31,14 @@ rec_id = astra_mex_data2d('create', '-vol', vol_geom); cfg = astra_struct('SIRT_CUDA'); cfg.ReconstructionDataId = rec_id; cfg.ProjectionDataId = sinogram_id; -% Set up 3 rays per detector element -cfg.option.DetectorSuperSampling = 3; +cfg.ProjectorId = proj_id; + % There is also an option for supersampling during the backprojection step. % This should be used if your detector pixels are smaller than the voxels. % Set up 2 rays per image pixel dimension, for 4 rays total per image pixel. -% cfg.option.PixelSuperSampling = 2; +% cfg_proj.option.PixelSuperSampling = 2; alg_id = astra_mex_algorithm('create', cfg); diff --git a/src/CudaBackProjectionAlgorithm3D.cpp b/src/CudaBackProjectionAlgorithm3D.cpp index fbb8f28..e8e0433 100644 --- a/src/CudaBackProjectionAlgorithm3D.cpp +++ b/src/CudaBackProjectionAlgorithm3D.cpp @@ -32,6 +32,7 @@ $Id$ #include "astra/AstraObjectManager.h" +#include "astra/CudaProjector3D.h" #include "astra/ConeProjectionGeometry3D.h" #include "astra/ParallelProjectionGeometry3D.h" #include "astra/ParallelVecProjectionGeometry3D.h" @@ -102,9 +103,20 @@ bool CCudaBackProjectionAlgorithm3D::initialize(const Config& _cfg) return false; } + CCudaProjector3D* pCudaProjector = 0; + pCudaProjector = dynamic_cast<CCudaProjector3D*>(m_pProjector); + if (!pCudaProjector) { + // TODO: Report + } + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); + + + m_iVoxelSuperSampling = 1; + if (pCudaProjector) + m_iVoxelSuperSampling = pCudaProjector->getVoxelSuperSampling(); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", m_iVoxelSuperSampling); CC.markOptionParsed("VoxelSuperSampling"); CFloat32ProjectionData3DMemory* pSinoMem = dynamic_cast<CFloat32ProjectionData3DMemory*>(m_pSinogram); diff --git a/src/CudaCglsAlgorithm3D.cpp b/src/CudaCglsAlgorithm3D.cpp index 3457b81..f527dc5 100644 --- a/src/CudaCglsAlgorithm3D.cpp +++ b/src/CudaCglsAlgorithm3D.cpp @@ -32,6 +32,7 @@ $Id$ #include "astra/AstraObjectManager.h" +#include "astra/CudaProjector3D.h" #include "astra/ConeProjectionGeometry3D.h" #include "astra/ParallelVecProjectionGeometry3D.h" #include "astra/ConeVecProjectionGeometry3D.h" @@ -106,12 +107,27 @@ bool CCudaCglsAlgorithm3D::initialize(const Config& _cfg) return false; } + CCudaProjector3D* pCudaProjector = 0; + pCudaProjector = dynamic_cast<CCudaProjector3D*>(m_pProjector); + if (!pCudaProjector) { + // TODO: Report + } + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); - CC.markOptionParsed("DetectorSuperSampling"); - m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); + + m_iVoxelSuperSampling = 1; + m_iDetectorSuperSampling = 1; + if (pCudaProjector) { + // New interface + m_iVoxelSuperSampling = pCudaProjector->getVoxelSuperSampling(); + m_iDetectorSuperSampling = pCudaProjector->getDetectorSuperSampling(); + } + // Deprecated options + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", m_iVoxelSuperSampling); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", m_iDetectorSuperSampling); CC.markOptionParsed("VoxelSuperSampling"); + CC.markOptionParsed("DetectorSuperSampling"); m_pCgls = new AstraCGLS3d(); diff --git a/src/CudaFDKAlgorithm3D.cpp b/src/CudaFDKAlgorithm3D.cpp index 467e641..667d926 100644 --- a/src/CudaFDKAlgorithm3D.cpp +++ b/src/CudaFDKAlgorithm3D.cpp @@ -32,6 +32,7 @@ $Id$ #include "astra/AstraObjectManager.h" +#include "astra/CudaProjector3D.h" #include "astra/ConeProjectionGeometry3D.h" #include "../cuda/3d/astra3d.h" @@ -100,9 +101,19 @@ bool CCudaFDKAlgorithm3D::initialize(const Config& _cfg) return false; } + CCudaProjector3D* pCudaProjector = 0; + pCudaProjector = dynamic_cast<CCudaProjector3D*>(m_pProjector); + if (!pCudaProjector) { + // TODO: Report + } + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); + + m_iVoxelSuperSampling = 1; + if (pCudaProjector) + m_iVoxelSuperSampling = pCudaProjector->getVoxelSuperSampling(); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", m_iVoxelSuperSampling); CC.markOptionParsed("VoxelSuperSampling"); m_bShortScan = _cfg.self.getOptionBool("ShortScan", false); diff --git a/src/CudaFilteredBackProjectionAlgorithm.cpp b/src/CudaFilteredBackProjectionAlgorithm.cpp index 5d6c166..aac96d6 100644 --- a/src/CudaFilteredBackProjectionAlgorithm.cpp +++ b/src/CudaFilteredBackProjectionAlgorithm.cpp @@ -32,6 +32,7 @@ $Id$ #include <cstring> #include "astra/AstraObjectManager.h" +#include "astra/CudaProjector2D.h" #include "../cuda/2d/astra.h" #include "astra/Logging.h" @@ -77,8 +78,22 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) clear(); } + // Projector + XMLNode node = _cfg.self.getSingleNode("ProjectorId"); + CCudaProjector2D* pCudaProjector = 0; + if (node) { + int id = boost::lexical_cast<int>(node.getContent()); + CProjector2D *projector = CProjector2DManager::getSingleton().get(id); + pCudaProjector = dynamic_cast<CCudaProjector2D*>(projector); + if (!pCudaProjector) { + ASTRA_WARN("non-CUDA Projector2D passed"); + } + } + CC.markNodeParsed("ProjectorId"); + + // sinogram data - XMLNode node = _cfg.self.getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "CudaFBP", "No ProjectionDataId tag specified."); int id = boost::lexical_cast<int>(node.getContent()); m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id)); @@ -152,10 +167,16 @@ bool CCudaFilteredBackProjectionAlgorithm::initialize(const Config& _cfg) m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - // Pixel supersampling factor - m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", 1); + m_iPixelSuperSampling = 1; + if (pCudaProjector) { + // New interface + m_iPixelSuperSampling = pCudaProjector->getVoxelSuperSampling(); + } + // Deprecated options + m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", m_iPixelSuperSampling); CC.markOptionParsed("PixelSuperSampling"); + // Fan beam short scan mode if (m_pSinogram && dynamic_cast<CFanFlatProjectionGeometry2D*>(m_pSinogram->getGeometry())) { m_bShortScan = (int)_cfg.self.getOptionBool("ShortScan", false); diff --git a/src/CudaForwardProjectionAlgorithm.cpp b/src/CudaForwardProjectionAlgorithm.cpp index 0f97d59..b382f2e 100644 --- a/src/CudaForwardProjectionAlgorithm.cpp +++ b/src/CudaForwardProjectionAlgorithm.cpp @@ -71,9 +71,24 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) { ASTRA_ASSERT(_cfg.self); ConfigStackCheck<CAlgorithm> CC("CudaForwardProjectionAlgorithm", this, _cfg); + + // Projector + XMLNode node = _cfg.self.getSingleNode("ProjectorId"); + CCudaProjector2D* pCudaProjector = 0; + if (node) { + int id = boost::lexical_cast<int>(node.getContent()); + CProjector2D *projector = CProjector2DManager::getSingleton().get(id); + pCudaProjector = dynamic_cast<CCudaProjector2D*>(projector); + if (!pCudaProjector) { + ASTRA_WARN("non-CUDA Projector2D passed to FP_CUDA"); + } + } + CC.markNodeParsed("ProjectorId"); + + // sinogram data - XMLNode node = _cfg.self.getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "FP_CUDA", "No ProjectionDataId tag specified."); int id = boost::lexical_cast<int>(node.getContent()); m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id)); @@ -94,21 +109,14 @@ bool CCudaForwardProjectionAlgorithm::initialize(const Config& _cfg) CC.markOptionParsed("GPUIndex"); // Detector supersampling factor - 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"); - if (node) { - id = boost::lexical_cast<int>(node.getContent()); - CProjector2D *projector = CProjector2DManager::getSingleton().get(id); - if (!dynamic_cast<CCudaProjector2D*>(projector)) { - ASTRA_WARN("non-CUDA Projector2D passed to FP_CUDA"); - } + m_iDetectorSuperSampling = 1; + if (pCudaProjector) { + // New interface + m_iDetectorSuperSampling = pCudaProjector->getDetectorSuperSampling(); } - CC.markNodeParsed("ProjectorId"); - + // Deprecated option + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", m_iDetectorSuperSampling); + CC.markOptionParsed("DetectorSuperSampling"); // return success diff --git a/src/CudaForwardProjectionAlgorithm3D.cpp b/src/CudaForwardProjectionAlgorithm3D.cpp index e29b5a9..46dab12 100644 --- a/src/CudaForwardProjectionAlgorithm3D.cpp +++ b/src/CudaForwardProjectionAlgorithm3D.cpp @@ -97,18 +97,28 @@ bool CCudaForwardProjectionAlgorithm3D::initialize(const Config& _cfg) // optional: projector node = _cfg.self.getSingleNode("ProjectorId"); + CCudaProjector3D* pCudaProjector = 0; + m_pProjector = 0; if (node) { id = boost::lexical_cast<int>(node.getContent()); m_pProjector = CProjector3DManager::getSingleton().get(id); - } else { - m_pProjector = 0; // TODO: or manually construct default projector? + pCudaProjector = dynamic_cast<CCudaProjector3D*>(CProjector3DManager::getSingleton().get(id)); + m_pProjector = pCudaProjector; + if (!pCudaProjector) { + // TODO: Report + } } CC.markNodeParsed("ProjectorId"); // GPU number m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); + + + m_iDetectorSuperSampling = 1; + if (pCudaProjector) + m_iDetectorSuperSampling = pCudaProjector->getDetectorSuperSampling(); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", m_iDetectorSuperSampling); CC.markOptionParsed("DetectorSuperSampling"); // success diff --git a/src/CudaProjector2D.cpp b/src/CudaProjector2D.cpp index fa024c8..a26e32d 100644 --- a/src/CudaProjector2D.cpp +++ b/src/CudaProjector2D.cpp @@ -59,6 +59,8 @@ void CCudaProjector2D::_clear() m_bIsInitialized = false; m_projectionKernel = ker2d_default; + m_iVoxelSuperSampling = 1; + m_iDetectorSuperSampling = 1; } //---------------------------------------------------------------------------------------- @@ -117,6 +119,12 @@ bool CCudaProjector2D::initialize(const Config& _cfg) } CC.markNodeParsed("ProjectionKernel"); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); + CC.markOptionParsed("VoxelSuperSampling"); + + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); + CC.markOptionParsed("DetectorSuperSampling"); + m_bIsInitialized = _check(); return m_bIsInitialized; } diff --git a/src/CudaProjector3D.cpp b/src/CudaProjector3D.cpp index 41529a5..d2fd74c 100644 --- a/src/CudaProjector3D.cpp +++ b/src/CudaProjector3D.cpp @@ -62,6 +62,8 @@ void CCudaProjector3D::_clear() m_bIsInitialized = false; m_projectionKernel = ker3d_default; + m_iVoxelSuperSampling = 1; + m_iDetectorSuperSampling = 1; } //---------------------------------------------------------------------------------------- @@ -120,6 +122,12 @@ bool CCudaProjector3D::initialize(const Config& _cfg) } CC.markNodeParsed("ProjectionKernel"); + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); + CC.markOptionParsed("VoxelSuperSampling"); + + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); + CC.markOptionParsed("DetectorSuperSampling"); + m_bIsInitialized = _check(); return m_bIsInitialized; } diff --git a/src/CudaReconstructionAlgorithm2D.cpp b/src/CudaReconstructionAlgorithm2D.cpp index db99d42..71b6637 100644 --- a/src/CudaReconstructionAlgorithm2D.cpp +++ b/src/CudaReconstructionAlgorithm2D.cpp @@ -95,8 +95,22 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) clear(); } + // Projector + XMLNode node = _cfg.self.getSingleNode("ProjectorId"); + CCudaProjector2D* pCudaProjector = 0; + if (node) { + int id = boost::lexical_cast<int>(node.getContent()); + CProjector2D *projector = CProjector2DManager::getSingleton().get(id); + pCudaProjector = dynamic_cast<CCudaProjector2D*>(projector); + if (!pCudaProjector) { + ASTRA_WARN("non-CUDA Projector2D passed"); + } + } + CC.markNodeParsed("ProjectorId"); + + // sinogram data - XMLNode node = _cfg.self.getSingleNode("ProjectionDataId"); + node = _cfg.self.getSingleNode("ProjectionDataId"); ASTRA_CONFIG_CHECK(node, "CudaSirt2", "No ProjectionDataId tag specified."); int id = boost::lexical_cast<int>(node.getContent()); m_pSinogram = dynamic_cast<CFloat32ProjectionData2D*>(CData2DManager::getSingleton().get(id)); @@ -161,27 +175,21 @@ bool CCudaReconstructionAlgorithm2D::initialize(const Config& _cfg) if (!_cfg.self.hasOption("GPUindex")) CC.markOptionParsed("GPUIndex"); - // Detector supersampling factor - m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); + // Supersampling factors + m_iDetectorSuperSampling = 1; + m_iPixelSuperSampling = 1; + if (pCudaProjector) { + // New interface + m_iDetectorSuperSampling = pCudaProjector->getDetectorSuperSampling(); + m_iPixelSuperSampling = pCudaProjector->getVoxelSuperSampling(); + } + // Deprecated options + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", m_iDetectorSuperSampling); + m_iPixelSuperSampling = (int)_cfg.self.getOptionNumerical("PixelSuperSampling", m_iPixelSuperSampling); CC.markOptionParsed("DetectorSuperSampling"); - - // Pixel supersampling factor - 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"); - if (node) { - id = boost::lexical_cast<int>(node.getContent()); - CProjector2D *projector = CProjector2DManager::getSingleton().get(id); - if (!dynamic_cast<CCudaProjector2D*>(projector)) { - ASTRA_WARN("non-CUDA Projector2D passed"); - } - } - CC.markNodeParsed("ProjectorId"); - - return _check(); } diff --git a/src/CudaSirtAlgorithm3D.cpp b/src/CudaSirtAlgorithm3D.cpp index 5ad131b..abbb9fd 100644 --- a/src/CudaSirtAlgorithm3D.cpp +++ b/src/CudaSirtAlgorithm3D.cpp @@ -36,6 +36,7 @@ $Id$ #include "astra/ParallelProjectionGeometry3D.h" #include "astra/ParallelVecProjectionGeometry3D.h" #include "astra/ConeVecProjectionGeometry3D.h" +#include "astra/CudaProjector3D.h" #include "../cuda/3d/astra3d.h" @@ -107,12 +108,28 @@ bool CCudaSirtAlgorithm3D::initialize(const Config& _cfg) return false; } + CCudaProjector3D* pCudaProjector = 0; + pCudaProjector = dynamic_cast<CCudaProjector3D*>(m_pProjector); + if (!pCudaProjector) { + // TODO: Report + } + m_iGPUIndex = (int)_cfg.self.getOptionNumerical("GPUindex", -1); CC.markOptionParsed("GPUindex"); - m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", 1); - CC.markOptionParsed("DetectorSuperSampling"); - m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", 1); + + + m_iVoxelSuperSampling = 1; + m_iDetectorSuperSampling = 1; + if (pCudaProjector) { + // New interface + m_iVoxelSuperSampling = pCudaProjector->getVoxelSuperSampling(); + m_iDetectorSuperSampling = pCudaProjector->getDetectorSuperSampling(); + } + // Deprecated options + m_iVoxelSuperSampling = (int)_cfg.self.getOptionNumerical("VoxelSuperSampling", m_iVoxelSuperSampling); + m_iDetectorSuperSampling = (int)_cfg.self.getOptionNumerical("DetectorSuperSampling", m_iDetectorSuperSampling); CC.markOptionParsed("VoxelSuperSampling"); + CC.markOptionParsed("DetectorSuperSampling"); m_pSirt = new AstraSIRT3d(); diff --git a/src/ReconstructionAlgorithm3D.cpp b/src/ReconstructionAlgorithm3D.cpp index 86b8ab2..13d4b07 100644 --- a/src/ReconstructionAlgorithm3D.cpp +++ b/src/ReconstructionAlgorithm3D.cpp @@ -106,14 +106,18 @@ bool CReconstructionAlgorithm3D::initialize(const Config& _cfg) XMLNode node; int id; -#if 0 + // projector - node = _cfg.self->getSingleNode("ProjectorId"); - ASTRA_CONFIG_CHECK(node, "Reconstruction3D", "No ProjectorId tag specified."); - id = boost::lexical_cast<int>(node->getContent()); - m_pProjector = CProjector3DManager::getSingleton().get(id); - ASTRA_DELETE(node); -#endif + node = _cfg.self.getSingleNode("ProjectorId"); + m_pProjector = 0; + if (node) { + id = boost::lexical_cast<int>(node.getContent()); + m_pProjector = CProjector3DManager::getSingleton().get(id); + if (!m_pProjector) { + // TODO: Report + } + } + CC.markNodeParsed("ProjectorId"); // sinogram data node = _cfg.self.getSingleNode("ProjectionDataId"); @@ -143,6 +147,7 @@ bool CReconstructionAlgorithm3D::initialize(const Config& _cfg) id = boost::lexical_cast<int>(_cfg.self.getOption("SinogramMaskId")); m_pSinogramMask = dynamic_cast<CFloat32ProjectionData3D*>(CData3DManager::getSingleton().get(id)); } + CC.markOptionParsed("SinogramMaskId"); // Constraints - NEW if (_cfg.self.hasOption("MinConstraint")) { |