From 248639b4fee8659a4106dcc44d721149a1885018 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 5 Mar 2015 17:01:47 +0100 Subject: Add 3d geometry normalization functions --- include/astra/GeometryUtil3D.h | 53 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'include/astra') diff --git a/include/astra/GeometryUtil3D.h b/include/astra/GeometryUtil3D.h index 698372e..6ceac63 100644 --- a/include/astra/GeometryUtil3D.h +++ b/include/astra/GeometryUtil3D.h @@ -43,6 +43,33 @@ struct SConeProjection { // the V-edge of a detector pixel double fDetVX, fDetVY, fDetVZ; + + + + + void translate(double dx, double dy, double dz) { + fSrcX += dx; + fSrcY += dy; + fSrcZ += dz; + fDetSX += dx; + fDetSY += dy; + fDetSZ += dz; + + } + void scale(double factor) { + fSrcX *= factor; + fSrcY *= factor; + fSrcZ *= factor; + fDetSX *= factor; + fDetSY *= factor; + fDetSZ *= factor; + fDetUX *= factor; + fDetUY *= factor; + fDetUZ *= factor; + fDetVX *= factor; + fDetVY *= factor; + fDetVZ *= factor; + } }; struct SPar3DProjection { @@ -57,6 +84,29 @@ struct SPar3DProjection { // the V-edge of a detector pixel double fDetVX, fDetVY, fDetVZ; + + + + + void translate(double dx, double dy, double dz) { + fDetSX += dx; + fDetSY += dy; + fDetSZ += dz; + } + void scale(double factor) { + fRayX *= factor; + fRayY *= factor; + fRayZ *= factor; + fDetSX *= factor; + fDetSY *= factor; + fDetSZ *= factor; + fDetUX *= factor; + fDetUY *= factor; + fDetUZ *= factor; + fDetVX *= factor; + fDetVY *= factor; + fDetVZ *= factor; + } }; void computeBP_UV_Coeffs(const SPar3DProjection& proj, @@ -68,6 +118,9 @@ void computeBP_UV_Coeffs(const SConeProjection& proj, double &fVX, double &fVY, double &fVZ, double &fVC, double &fDX, double &fDY, double &fDZ, double &fDC); + + + } #endif -- cgit v1.2.3 From 8f37932efdbf7585c85ba1e7653e7080e17d7714 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 23 Jul 2015 11:39:28 +0200 Subject: Reduce code duplication --- include/astra/AstraObjectFactory.h | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'include/astra') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index 1ed4955..efe997d 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -109,14 +109,11 @@ T* CAstraObjectFactory::create(std::string _sType) template T* CAstraObjectFactory::create(const Config& _cfg) { - functor_find finder = functor_find(); - finder.tofind = _cfg.self.getAttribute("type"); - CreateObject::find(finder); - if (finder.res == NULL) return NULL; - if (finder.res->initialize(_cfg)) - return finder.res; - - delete finder.res; + T* object = create(_cfg.self.getAttribute("type")); + if (object == NULL) return NULL; + if (object->initialize(_cfg)) + return object; + delete object; return NULL; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3 From 2f800d5c1a305a23906783ecaa075e3d5274ef26 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 23 Jul 2015 11:49:39 +0200 Subject: Fix comments --- include/astra/AstraObjectFactory.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'include/astra') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index efe997d..c935a7c 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -59,16 +59,16 @@ public: */ ~CAstraObjectFactory(); - /** Create, but don't initialize, a new projector object. + /** Create, but don't initialize, a new object. * - * @param _sType Type of the new projector. - * @return Pointer to a new, unitialized projector. + * @param _sType Type of the new object. + * @return Pointer to a new, uninitialized object. */ T* create(std::string _sType); - /** Create and initialize a new projector object. + /** Create and initialize a new object. * - * @param _cfg Configuration object to create and initialize a new projector. + * @param _cfg Configuration object to create and initialize a new object. * @return Pointer to a new, initialized projector. */ T* create(const Config& _cfg); -- cgit v1.2.3 From 9e077994b382b2df63e4b79dd2afebc50366d419 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 23 Jul 2015 11:43:47 +0200 Subject: Add hooks for plugin support to AstraObjectFactory To use these hooks, add a specialization of findPlugin for the desired type of object (e.g., Algorithms). --- include/astra/AstraObjectFactory.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'include/astra') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index c935a7c..356acf9 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -73,6 +73,13 @@ public: */ T* create(const Config& _cfg); + /** Find a plugin. + * + * @param _sType Name of plugin to find. + * @return Pointer to a new, uninitialized object, or NULL if not found. + */ + T* findPlugin(std::string _sType); + }; @@ -93,6 +100,15 @@ CAstraObjectFactory::~CAstraObjectFactory() } + +//---------------------------------------------------------------------------------------- +// Hook for finding plugin in registered plugins. +template +T* CAstraObjectFactory::findPlugin(std::string _sType) +{ + return NULL; +} + //---------------------------------------------------------------------------------------- // Create template @@ -101,6 +117,9 @@ T* CAstraObjectFactory::create(std::string _sType) functor_find finder = functor_find(); finder.tofind = _sType; CreateObject::find(finder); + if (finder.res == NULL) { + finder.res = findPlugin(_sType); + } return finder.res; } -- cgit v1.2.3 From 18b6d25f7e4f0943b3592f3bb4f6ca5ed9c285d3 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 19 Jun 2015 22:28:06 +0200 Subject: Add support for Python algorithm plugins --- include/astra/AstraObjectFactory.h | 13 ++++++ include/astra/PluginAlgorithm.h | 85 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 include/astra/PluginAlgorithm.h (limited to 'include/astra') diff --git a/include/astra/AstraObjectFactory.h b/include/astra/AstraObjectFactory.h index 356acf9..325989e 100644 --- a/include/astra/AstraObjectFactory.h +++ b/include/astra/AstraObjectFactory.h @@ -40,6 +40,10 @@ $Id$ #include "AlgorithmTypelist.h" +#ifdef ASTRA_PYTHON +#include "PluginAlgorithm.h" +#endif + namespace astra { @@ -147,6 +151,15 @@ T* CAstraObjectFactory::create(const Config& _cfg) */ class _AstraExport CAlgorithmFactory : public CAstraObjectFactory {}; +#ifdef ASTRA_PYTHON +template <> +inline CAlgorithm* CAstraObjectFactory::findPlugin(std::string _sType) + { + CPluginAlgorithmFactory *fac = CPluginAlgorithmFactory::getSingletonPtr(); + return fac->getPlugin(_sType); + } +#endif + /** * Class used to create 2D projectors from a string or a config object */ diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h new file mode 100644 index 0000000..7d6c64a --- /dev/null +++ b/include/astra/PluginAlgorithm.h @@ -0,0 +1,85 @@ +/* +----------------------------------------------------------------------- +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$ +*/ + +#ifndef _INC_ASTRA_PLUGINALGORITHM +#define _INC_ASTRA_PLUGINALGORITHM + +#ifdef ASTRA_PYTHON + +#include +#include "bytesobject.h" +#include "astra/Algorithm.h" +#include "astra/Singleton.h" +#include "astra/XMLDocument.h" +#include "astra/XMLNode.h" + +namespace astra { +class _AstraExport CPluginAlgorithm : public CAlgorithm { + +public: + + CPluginAlgorithm(PyObject* pyclass); + ~CPluginAlgorithm(); + + bool initialize(const Config& _cfg); + void run(int _iNrIterations); + +private: + PyObject * instance; + +}; + +class _AstraExport CPluginAlgorithmFactory : public Singleton { + +public: + + CPluginAlgorithmFactory(); + ~CPluginAlgorithmFactory(); + + CPluginAlgorithm * getPlugin(std::string name); + + bool registerPlugin(std::string name, std::string className); + bool registerPluginClass(std::string name, PyObject * className); + + PyObject * getRegistered(); + + std::string getHelp(std::string name); + +private: + PyObject * pluginDict; + PyObject *ospath, *inspect, *six, *astra; + std::vector getPluginPathList(); +}; + +PyObject* XMLNode2dict(XMLNode node); + +} + +#endif + +#endif \ No newline at end of file -- cgit v1.2.3 From 2f871bc7068d6c87a7d950ae044ba66b0b8dcd3f Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 17 Jul 2015 12:05:46 +0200 Subject: Remove config text file loading for plugins --- include/astra/PluginAlgorithm.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'include/astra') diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h index 7d6c64a..a82c579 100644 --- a/include/astra/PluginAlgorithm.h +++ b/include/astra/PluginAlgorithm.h @@ -72,8 +72,7 @@ public: private: PyObject * pluginDict; - PyObject *ospath, *inspect, *six, *astra; - std::vector getPluginPathList(); + PyObject *inspect, *six; }; PyObject* XMLNode2dict(XMLNode node); -- cgit v1.2.3 From 3d136b7c819b0b142ad056bf01c8c1191eea9ba0 Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Fri, 17 Jul 2015 16:22:05 +0200 Subject: Fix numpy lapack loading when running in Matlab --- include/astra/Globals.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/astra') diff --git a/include/astra/Globals.h b/include/astra/Globals.h index 4de07d1..dc2d7e6 100644 --- a/include/astra/Globals.h +++ b/include/astra/Globals.h @@ -146,6 +146,8 @@ namespace astra { const float32 PIdiv2 = PI / 2; const float32 PIdiv4 = PI / 4; const float32 eps = 1e-7f; + + extern bool running_in_matlab; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3 From d91b51f6d58003de84a9d6dd8189fceba0e81a5a Mon Sep 17 00:00:00 2001 From: "Daniel M. Pelt" Date: Mon, 20 Jul 2015 14:07:21 +0200 Subject: Allow registering plugins without explicit name, and fix exception handling when running in Matlab --- include/astra/PluginAlgorithm.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'include/astra') diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h index a82c579..b56228e 100644 --- a/include/astra/PluginAlgorithm.h +++ b/include/astra/PluginAlgorithm.h @@ -64,9 +64,12 @@ public: CPluginAlgorithm * getPlugin(std::string name); bool registerPlugin(std::string name, std::string className); + bool registerPlugin(std::string className); bool registerPluginClass(std::string name, PyObject * className); + bool registerPluginClass(PyObject * className); PyObject * getRegistered(); + std::map getRegisteredMap(); std::string getHelp(std::string name); -- cgit v1.2.3 From 43a38c117405f99e3a1b498f899de4ba6d01a044 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 7 Oct 2015 18:14:39 +0200 Subject: Improve option passing through CudaProjector3D Not all constructors were reading options from the projector. Also allow passing GPUIndex via CudaProjector3D. Thanks to Nicola Vigano for part of the patch. --- include/astra/CudaBackProjectionAlgorithm3D.h | 2 ++ include/astra/CudaCglsAlgorithm3D.h | 2 ++ include/astra/CudaFDKAlgorithm3D.h | 2 ++ include/astra/CudaForwardProjectionAlgorithm3D.h | 1 + include/astra/CudaProjector3D.h | 2 ++ include/astra/CudaSirtAlgorithm3D.h | 2 ++ 6 files changed, 11 insertions(+) (limited to 'include/astra') diff --git a/include/astra/CudaBackProjectionAlgorithm3D.h b/include/astra/CudaBackProjectionAlgorithm3D.h index 2d98218..74aeec8 100644 --- a/include/astra/CudaBackProjectionAlgorithm3D.h +++ b/include/astra/CudaBackProjectionAlgorithm3D.h @@ -147,6 +147,8 @@ protected: */ bool m_bSIRTWeighting; + + void initializeFromProjector(); }; // inline functions diff --git a/include/astra/CudaCglsAlgorithm3D.h b/include/astra/CudaCglsAlgorithm3D.h index 77c41c1..3e4084b 100644 --- a/include/astra/CudaCglsAlgorithm3D.h +++ b/include/astra/CudaCglsAlgorithm3D.h @@ -161,6 +161,8 @@ protected: bool m_bAstraCGLSInit; int m_iDetectorSuperSampling; int m_iVoxelSuperSampling; + + void initializeFromProjector(); }; // inline functions diff --git a/include/astra/CudaFDKAlgorithm3D.h b/include/astra/CudaFDKAlgorithm3D.h index 1b025f1..63f07fd 100644 --- a/include/astra/CudaFDKAlgorithm3D.h +++ b/include/astra/CudaFDKAlgorithm3D.h @@ -152,6 +152,8 @@ protected: int m_iGPUIndex; int m_iVoxelSuperSampling; bool m_bShortScan; + + void initializeFromProjector(); }; // inline functions diff --git a/include/astra/CudaForwardProjectionAlgorithm3D.h b/include/astra/CudaForwardProjectionAlgorithm3D.h index bdd1356..4198d56 100644 --- a/include/astra/CudaForwardProjectionAlgorithm3D.h +++ b/include/astra/CudaForwardProjectionAlgorithm3D.h @@ -122,6 +122,7 @@ protected: int m_iGPUIndex; int m_iDetectorSuperSampling; + void initializeFromProjector(); }; // inline functions diff --git a/include/astra/CudaProjector3D.h b/include/astra/CudaProjector3D.h index 1d570fe..da88d6d 100644 --- a/include/astra/CudaProjector3D.h +++ b/include/astra/CudaProjector3D.h @@ -117,12 +117,14 @@ public: Cuda3DProjectionKernel getProjectionKernel() const { return m_projectionKernel; } int getVoxelSuperSampling() const { return m_iVoxelSuperSampling; } int getDetectorSuperSampling() const { return m_iDetectorSuperSampling; } + int getGPUIndex() const { return m_iGPUIndex; } protected: Cuda3DProjectionKernel m_projectionKernel; int m_iVoxelSuperSampling; int m_iDetectorSuperSampling; + int m_iGPUIndex; }; diff --git a/include/astra/CudaSirtAlgorithm3D.h b/include/astra/CudaSirtAlgorithm3D.h index fda4635..379720e 100644 --- a/include/astra/CudaSirtAlgorithm3D.h +++ b/include/astra/CudaSirtAlgorithm3D.h @@ -175,6 +175,8 @@ protected: bool m_bAstraSIRTInit; int m_iDetectorSuperSampling; int m_iVoxelSuperSampling; + + void initializeFromProjector(); }; // inline functions -- cgit v1.2.3 From 003663649a191fc5bc011d6e5424496576b5e793 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Thu, 8 Oct 2015 11:24:49 +0200 Subject: Improve option passing through CudaProjector2D Not all constructors were reading options from the projector. Also allow passing GPUIndex via CudaProjector2D. Also refactor CudaReconstructionAlgorithm::initialize/check to avoid code duplication with ReconstructionAlgorithm. --- include/astra/CudaBackProjectionAlgorithm.h | 5 +--- include/astra/CudaCglsAlgorithm.h | 9 ++------ include/astra/CudaEMAlgorithm.h | 8 ++----- .../astra/CudaFilteredBackProjectionAlgorithm.h | 3 +++ include/astra/CudaForwardProjectionAlgorithm.h | 27 +++++++++++----------- include/astra/CudaProjector2D.h | 2 ++ include/astra/CudaReconstructionAlgorithm2D.h | 22 ++++-------------- include/astra/CudaSartAlgorithm.h | 7 ++---- include/astra/CudaSirtAlgorithm.h | 9 ++------ include/astra/ReconstructionAlgorithm2D.h | 3 +++ 10 files changed, 35 insertions(+), 60 deletions(-) (limited to 'include/astra') diff --git a/include/astra/CudaBackProjectionAlgorithm.h b/include/astra/CudaBackProjectionAlgorithm.h index 84899b0..2450376 100644 --- a/include/astra/CudaBackProjectionAlgorithm.h +++ b/include/astra/CudaBackProjectionAlgorithm.h @@ -85,13 +85,10 @@ public: * @param _pProjector Projector Object. (Ignored) * @param _pSinogram ProjectionData2D object containing the sinogram data. * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. - * @param _iGPUindex GPU to use. - * @param _iPixelSuperSampling Square root of number of samples per voxel, used to compute the backprojection */ bool initialize(CProjector2D* _pProjector, CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction, - int _iGPUindex = -1, int _iPixelSuperSampling = 1); + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * diff --git a/include/astra/CudaCglsAlgorithm.h b/include/astra/CudaCglsAlgorithm.h index c51093c..6aa0343 100644 --- a/include/astra/CudaCglsAlgorithm.h +++ b/include/astra/CudaCglsAlgorithm.h @@ -91,18 +91,13 @@ public: /** Initialize class, use sequential order. * - * @param _pProjector Projector Object. (Ignored) + * @param _pProjector Projector Object. (Optional) * @param _pSinogram ProjectionData2D object containing the sinogram * @param _pReconstruction VolumeData2D for storing the reconstruction - * @param _iGPUindex Index of GPU to use. (Starting at 0.) - * @param _iDetectorSuperSampling Supersampling factor for the FP. - * @param _iPixelSuperSampling Square root of number of samples per voxel, used to compute the backprojection */ bool initialize(CProjector2D* _pProjector, CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction, - int _iGPUindex = -1, int _iDetectorSuperSampling = 1, - int _iPixelSuperSampling = 1); + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * diff --git a/include/astra/CudaEMAlgorithm.h b/include/astra/CudaEMAlgorithm.h index 97eb7ca..d313f7c 100644 --- a/include/astra/CudaEMAlgorithm.h +++ b/include/astra/CudaEMAlgorithm.h @@ -63,17 +63,13 @@ public: /** Initialize class. * - * @param _pProjector Projector Object. (Ignored) + * @param _pProjector Projector Object. (Optional) * @param _pSinogram ProjectionData2D object containing the sinogram data. * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. - * @param _iGPUindex GPU to use. - * @param _iDetectorSuperSampling Supersampling factor for the FP. */ bool initialize(CProjector2D* _pProjector, CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction, - int _iGPUindex = -1, int _iDetectorSuperSampling = 1, - int _iPixelSuperSampling = 1); + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * diff --git a/include/astra/CudaFilteredBackProjectionAlgorithm.h b/include/astra/CudaFilteredBackProjectionAlgorithm.h index 33445b6..cf1f19f 100644 --- a/include/astra/CudaFilteredBackProjectionAlgorithm.h +++ b/include/astra/CudaFilteredBackProjectionAlgorithm.h @@ -85,6 +85,9 @@ protected: AstraFBP* m_pFBP; bool m_bAstraFBPInit; + + void initializeFromProjector(); + virtual bool requiresProjector() const { return false; } }; // inline functions diff --git a/include/astra/CudaForwardProjectionAlgorithm.h b/include/astra/CudaForwardProjectionAlgorithm.h index d172a7a..097d499 100644 --- a/include/astra/CudaForwardProjectionAlgorithm.h +++ b/include/astra/CudaForwardProjectionAlgorithm.h @@ -33,16 +33,15 @@ $Id$ #include "Algorithm.h" -#include "ParallelProjectionGeometry2D.h" -#include "VolumeGeometry2D.h" - -#include "Float32ProjectionData2D.h" -#include "Float32VolumeData2D.h" - #ifdef ASTRA_CUDA namespace astra { +class CProjector2D; +class CProjectionGeometry2D; +class CFloat32ProjectionData2D; +class CFloat32VolumeData2D; + /** * \brief * This class contains a GPU implementation of an algorithm that creates a forward projection @@ -91,19 +90,15 @@ public: /** Initialize class. * - * @param _pVolumeGeometry Geometry of the volume. - * @param _pProjectionGeometry Geometry of the projection. + * @param _pProjector Projector2D object. (Optional) * @param _pVolume VolumeData2D object containing the phantom to compute sinogram from * @param _pSinogram ProjectionData2D object to store sinogram data in. - * @param _iGPUindex Index of GPU to use. (Starting at 0.) - * @param _iDetectorSuperSampling Number of samples per detector element, used to compute the forward projection * @return success */ - bool initialize(CProjectionGeometry2D* _pProjectionGeometry, - CVolumeGeometry2D* _pVolumeGeometry, + bool initialize(CProjector2D* _pProjector, CFloat32VolumeData2D* _pVolume, - CFloat32ProjectionData2D* _pSinogram, - int _iGPUindex = -1, int _iDetectorSuperSampling = 1); + CFloat32ProjectionData2D* _pSinogram); + /** Get all information parameters * @@ -147,6 +142,9 @@ public: void setGPUIndex(int _iGPUIndex); protected: + //< Optional Projector2D object + CProjector2D* m_pProjector; + //< ProjectionData2D object containing the sinogram. CFloat32ProjectionData2D* m_pSinogram; //< VolumeData2D object containing the phantom. @@ -157,6 +155,7 @@ protected: //< Number of rays per detector element int m_iDetectorSuperSampling; + void initializeFromProjector(); }; // inline functions diff --git a/include/astra/CudaProjector2D.h b/include/astra/CudaProjector2D.h index ecfca41..2b4bacb 100644 --- a/include/astra/CudaProjector2D.h +++ b/include/astra/CudaProjector2D.h @@ -124,12 +124,14 @@ public: Cuda2DProjectionKernel getProjectionKernel() const { return m_projectionKernel; } int getVoxelSuperSampling() const { return m_iVoxelSuperSampling; } int getDetectorSuperSampling() const { return m_iDetectorSuperSampling; } + int getGPUIndex() const { return m_iGPUIndex; } protected: Cuda2DProjectionKernel m_projectionKernel; int m_iVoxelSuperSampling; int m_iDetectorSuperSampling; + int m_iGPUIndex; }; //---------------------------------------------------------------------------------------- diff --git a/include/astra/CudaReconstructionAlgorithm2D.h b/include/astra/CudaReconstructionAlgorithm2D.h index e19bb8f..dc93a1a 100644 --- a/include/astra/CudaReconstructionAlgorithm2D.h +++ b/include/astra/CudaReconstructionAlgorithm2D.h @@ -70,28 +70,13 @@ public: /** Initialize class. * - * @param _pProjector Projector Object. (Ignored) + * @param _pProjector Projector Object. (Optional) * @param _pSinogram ProjectionData2D object containing the sinogram data. * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. */ - bool initialize(CProjector2D* _pProjector, - CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction); - - /** Initialize class. - * - * @param _pProjector Projector Object. (Ignored) - * @param _pSinogram ProjectionData2D object containing the sinogram data. - * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. - * @param _iGPUindex GPU to use. - * @param _iDetectorSuperSampling Supersampling factor for the FP. - * @param _iPixelSuperSampling Square root of number of samples per voxel, used to compute the backprojection - */ virtual bool initialize(CProjector2D* _pProjector, CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction, - int _iGPUindex = -1, int _iDetectorSuperSampling = 1, - int _iPixelSuperSampling = 1); + CFloat32VolumeData2D* _pReconstruction); /** Clear this class. @@ -166,6 +151,9 @@ protected: int m_iGPUIndex; bool m_bAlgoInit; + + void initializeFromProjector(); + virtual bool requiresProjector() const { return false; } }; // inline functions diff --git a/include/astra/CudaSartAlgorithm.h b/include/astra/CudaSartAlgorithm.h index b370bd0..53d1e7b 100644 --- a/include/astra/CudaSartAlgorithm.h +++ b/include/astra/CudaSartAlgorithm.h @@ -84,16 +84,13 @@ public: /** Initialize class. * - * @param _pProjector Projector Object. (Ignored) + * @param _pProjector Projector Object. (Optional) * @param _pSinogram ProjectionData2D object containing the sinogram data. * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. - * @param _iGPUindex GPU to use. - * @param _iDetectorSuperSampling Supersampling factor for the FP. */ bool initialize(CProjector2D* _pProjector, CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction, - int _iGPUindex = -1, int _iDetectorSuperSampling = 1); + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * diff --git a/include/astra/CudaSirtAlgorithm.h b/include/astra/CudaSirtAlgorithm.h index 607889a..751d612 100644 --- a/include/astra/CudaSirtAlgorithm.h +++ b/include/astra/CudaSirtAlgorithm.h @@ -97,18 +97,13 @@ public: /** Initialize class. * - * @param _pProjector Projector Object. (Ignored) + * @param _pProjector Projector Object. (Optional) * @param _pSinogram ProjectionData2D object containing the sinogram data. * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. - * @param _iGPUindex GPU to use. - * @param _iDetectorSuperSampling Supersampling factor for the FP. - * @param _iPixelSuperSampling Square root of number of samples per voxel, used to compute the backprojection */ bool initialize(CProjector2D* _pProjector, CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction, - int _iGPUindex = -1, int _iDetectorSuperSampling = 1, - int _iPixelSuperSampling = 1); + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * diff --git a/include/astra/ReconstructionAlgorithm2D.h b/include/astra/ReconstructionAlgorithm2D.h index 60584e0..ac87c4f 100644 --- a/include/astra/ReconstructionAlgorithm2D.h +++ b/include/astra/ReconstructionAlgorithm2D.h @@ -208,6 +208,9 @@ protected: //< Use the fixed reconstruction mask? bool m_bUseSinogramMask; + + //< Specify if initialize/check should check for a valid Projector + virtual bool requiresProjector() const { return true; } }; // inline functions -- cgit v1.2.3 From 33668f347d7fdcd700fc5e4e34153cbba7889c01 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 9 Oct 2015 11:46:05 +0200 Subject: Fix whitespace --- include/astra/CudaEMAlgorithm.h | 4 ++-- include/astra/CudaForwardProjectionAlgorithm.h | 4 ++-- include/astra/CudaSartAlgorithm.h | 4 ++-- include/astra/CudaSirtAlgorithm.h | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'include/astra') diff --git a/include/astra/CudaEMAlgorithm.h b/include/astra/CudaEMAlgorithm.h index d313f7c..a9d2711 100644 --- a/include/astra/CudaEMAlgorithm.h +++ b/include/astra/CudaEMAlgorithm.h @@ -68,8 +68,8 @@ public: * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. */ bool initialize(CProjector2D* _pProjector, - CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction); + CFloat32ProjectionData2D* _pSinogram, + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * diff --git a/include/astra/CudaForwardProjectionAlgorithm.h b/include/astra/CudaForwardProjectionAlgorithm.h index 097d499..449a610 100644 --- a/include/astra/CudaForwardProjectionAlgorithm.h +++ b/include/astra/CudaForwardProjectionAlgorithm.h @@ -96,8 +96,8 @@ public: * @return success */ bool initialize(CProjector2D* _pProjector, - CFloat32VolumeData2D* _pVolume, - CFloat32ProjectionData2D* _pSinogram); + CFloat32VolumeData2D* _pVolume, + CFloat32ProjectionData2D* _pSinogram); /** Get all information parameters diff --git a/include/astra/CudaSartAlgorithm.h b/include/astra/CudaSartAlgorithm.h index 53d1e7b..c22dc4f 100644 --- a/include/astra/CudaSartAlgorithm.h +++ b/include/astra/CudaSartAlgorithm.h @@ -89,8 +89,8 @@ public: * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. */ bool initialize(CProjector2D* _pProjector, - CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction); + CFloat32ProjectionData2D* _pSinogram, + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * diff --git a/include/astra/CudaSirtAlgorithm.h b/include/astra/CudaSirtAlgorithm.h index 751d612..929ac30 100644 --- a/include/astra/CudaSirtAlgorithm.h +++ b/include/astra/CudaSirtAlgorithm.h @@ -102,8 +102,8 @@ public: * @param _pReconstruction VolumeData2D object for storing the reconstructed volume. */ bool initialize(CProjector2D* _pProjector, - CFloat32ProjectionData2D* _pSinogram, - CFloat32VolumeData2D* _pReconstruction); + CFloat32ProjectionData2D* _pSinogram, + CFloat32VolumeData2D* _pReconstruction); /** Get a description of the class. * -- cgit v1.2.3 From 07c31b932078544205d61551edd4a66f69be30ae Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 2 Dec 2015 11:25:59 +0100 Subject: Avoid unnecessary include in header --- include/astra/PluginAlgorithm.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'include/astra') diff --git a/include/astra/PluginAlgorithm.h b/include/astra/PluginAlgorithm.h index b56228e..667e813 100644 --- a/include/astra/PluginAlgorithm.h +++ b/include/astra/PluginAlgorithm.h @@ -31,13 +31,16 @@ $Id$ #ifdef ASTRA_PYTHON -#include -#include "bytesobject.h" #include "astra/Algorithm.h" #include "astra/Singleton.h" #include "astra/XMLDocument.h" #include "astra/XMLNode.h" +// Slightly hackish forward declaration of PyObject +struct _object; +typedef _object PyObject; + + namespace astra { class _AstraExport CPluginAlgorithm : public CAlgorithm { @@ -84,4 +87,4 @@ PyObject* XMLNode2dict(XMLNode node); #endif -#endif \ No newline at end of file +#endif -- cgit v1.2.3 From 5df8492fcca44965f87884509668c1b75509e584 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 2 Dec 2015 14:56:42 +0100 Subject: Fix Windows build --- include/astra/Globals.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'include/astra') diff --git a/include/astra/Globals.h b/include/astra/Globals.h index dc2d7e6..f70c3a9 100644 --- a/include/astra/Globals.h +++ b/include/astra/Globals.h @@ -147,7 +147,7 @@ namespace astra { const float32 PIdiv4 = PI / 4; const float32 eps = 1e-7f; - extern bool running_in_matlab; + extern _AstraExport bool running_in_matlab; } //---------------------------------------------------------------------------------------- -- cgit v1.2.3 From b14fb531ad9ae3d565f2cf28f5506408ab10dbed Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Wed, 18 Nov 2015 11:26:15 +0100 Subject: Add CompositeGeometryManager This handles FP and BP operations on multiple data objects at once, splitting them to fit in GPU memory where necessary. --- include/astra/CompositeGeometryManager.h | 150 ++++++++++++++++++++++++ include/astra/ConeProjectionGeometry3D.h | 10 +- include/astra/ConeVecProjectionGeometry3D.h | 11 +- include/astra/GeometryUtil3D.h | 17 +++ include/astra/ParallelProjectionGeometry3D.h | 11 +- include/astra/ParallelVecProjectionGeometry3D.h | 10 +- include/astra/ProjectionGeometry3D.h | 19 ++- 7 files changed, 218 insertions(+), 10 deletions(-) create mode 100644 include/astra/CompositeGeometryManager.h (limited to 'include/astra') diff --git a/include/astra/CompositeGeometryManager.h b/include/astra/CompositeGeometryManager.h new file mode 100644 index 0000000..a6e57f1 --- /dev/null +++ b/include/astra/CompositeGeometryManager.h @@ -0,0 +1,150 @@ +/* +----------------------------------------------------------------------- +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 . + +----------------------------------------------------------------------- +*/ + +#ifndef _INC_ASTRA_COMPOSITEGEOMETRYMANAGER +#define _INC_ASTRA_COMPOSITEGEOMETRYMANAGER + +#include "Globals.h" + +#ifdef ASTRA_CUDA + +#include +#include +#include +#include + + +namespace astra { + +class CCompositeVolume; +class CCompositeProjections; +class CFloat32Data3DMemory; +class CFloat32ProjectionData3DMemory; +class CFloat32VolumeData3DMemory; +class CVolumeGeometry3D; +class CProjectionGeometry3D; +class CProjector3D; + + + +class _AstraExport CCompositeGeometryManager { +public: + class CPart; + typedef std::list > TPartList; + class CPart { + public: + CPart() { } + CPart(const CPart& other); + virtual ~CPart() { } + + enum { + PART_VOL, PART_PROJ + } eType; + + CFloat32Data3DMemory* pData; + unsigned int subX; + unsigned int subY; + unsigned int subZ; + + bool uploadToGPU(); + bool downloadFromGPU(/*mode?*/); + virtual TPartList split(size_t maxSize, int div) = 0; + virtual CPart* reduce(const CPart *other) = 0; + virtual void getDims(size_t &x, size_t &y, size_t &z) = 0; + size_t getSize(); + }; + + class CVolumePart : public CPart { + public: + CVolumePart() { eType = PART_VOL; } + CVolumePart(const CVolumePart& other); + virtual ~CVolumePart(); + + CVolumeGeometry3D* pGeom; + + virtual TPartList split(size_t maxSize, int div); + virtual CPart* reduce(const CPart *other); + virtual void getDims(size_t &x, size_t &y, size_t &z); + + CVolumePart* clone() const; + }; + class CProjectionPart : public CPart { + public: + CProjectionPart() { eType = PART_PROJ; } + CProjectionPart(const CProjectionPart& other); + virtual ~CProjectionPart(); + + CProjectionGeometry3D* pGeom; + + virtual TPartList split(size_t maxSize, int div); + virtual CPart* reduce(const CPart *other); + virtual void getDims(size_t &x, size_t &y, size_t &z); + + CProjectionPart* clone() const; + }; + + struct SJob { + public: + boost::shared_ptr pInput; + boost::shared_ptr pOutput; + CProjector3D *pProjector; // For a `global' geometry. It will not match + // the geometries of the input and output. + + + enum { + JOB_FP, JOB_BP, JOB_NOP + } eType; + enum { + MODE_ADD, MODE_SET + } eMode; + + }; + + typedef std::list TJobList; + // output part -> list of jobs for that output + typedef std::map TJobSet; + + bool doJobs(TJobList &jobs); + + // Convenience functions for creating and running a single FP or BP job + bool doFP(CProjector3D *pProjector, CFloat32VolumeData3DMemory *pVolData, + CFloat32ProjectionData3DMemory *pProjData); + bool doBP(CProjector3D *pProjector, CFloat32VolumeData3DMemory *pVolData, + CFloat32ProjectionData3DMemory *pProjData); + + +protected: + + bool splitJobs(TJobSet &jobs, size_t maxSize, int div, TJobSet &split); + +}; + +} + +#endif + +#endif diff --git a/include/astra/ConeProjectionGeometry3D.h b/include/astra/ConeProjectionGeometry3D.h index 00e72ce..dede6e1 100644 --- a/include/astra/ConeProjectionGeometry3D.h +++ b/include/astra/ConeProjectionGeometry3D.h @@ -186,9 +186,15 @@ public: */ virtual CVector3D getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const; - virtual void projectPoint(float32 fX, float32 fY, float32 fZ, + virtual void projectPoint(double fX, double fY, double fZ, int iAngleIndex, - float32 &fU, float32 &fV) const; + double &fU, double &fV) const; + virtual void backprojectPointX(int iAngleIndex, double fU, double fV, + double fX, double &fY, double &fZ) const; + virtual void backprojectPointY(int iAngleIndex, double fU, double fV, + double fY, double &fX, double &fZ) const; + virtual void backprojectPointZ(int iAngleIndex, double fU, double fV, + double fZ, double &fX, double &fY) const; }; diff --git a/include/astra/ConeVecProjectionGeometry3D.h b/include/astra/ConeVecProjectionGeometry3D.h index 71e8010..f76f9dd 100644 --- a/include/astra/ConeVecProjectionGeometry3D.h +++ b/include/astra/ConeVecProjectionGeometry3D.h @@ -148,9 +148,16 @@ public: const SConeProjection* getProjectionVectors() const { return m_pProjectionAngles; } - virtual void projectPoint(float32 fX, float32 fY, float32 fZ, + virtual void projectPoint(double fX, double fY, double fZ, int iAngleIndex, - float32 &fU, float32 &fV) const; + double &fU, double &fV) const; + virtual void backprojectPointX(int iAngleIndex, double fU, double fV, + double fX, double &fY, double &fZ) const; + virtual void backprojectPointY(int iAngleIndex, double fU, double fV, + double fY, double &fX, double &fZ) const; + virtual void backprojectPointZ(int iAngleIndex, double fU, double fV, + double fZ, double &fX, double &fY) const; + }; } // namespace astra diff --git a/include/astra/GeometryUtil3D.h b/include/astra/GeometryUtil3D.h index 6ceac63..e4d73e4 100644 --- a/include/astra/GeometryUtil3D.h +++ b/include/astra/GeometryUtil3D.h @@ -119,6 +119,23 @@ void computeBP_UV_Coeffs(const SConeProjection& proj, double &fDX, double &fDY, double &fDZ, double &fDC); +SConeProjection* genConeProjections(unsigned int iProjAngles, + unsigned int iProjU, + unsigned int iProjV, + double fOriginSourceDistance, + double fOriginDetectorDistance, + double fDetUSize, + double fDetVSize, + const float *pfAngles); + +SPar3DProjection* genPar3DProjections(unsigned int iProjAngles, + unsigned int iProjU, + unsigned int iProjV, + double fDetUSize, + double fDetVSize, + const float *pfAngles); + + } diff --git a/include/astra/ParallelProjectionGeometry3D.h b/include/astra/ParallelProjectionGeometry3D.h index 72401e5..d95c050 100644 --- a/include/astra/ParallelProjectionGeometry3D.h +++ b/include/astra/ParallelProjectionGeometry3D.h @@ -147,9 +147,16 @@ public: */ virtual CVector3D getProjectionDirection(int _iProjectionIndex, int _iDetectorIndex) const; - virtual void projectPoint(float32 fX, float32 fY, float32 fZ, + virtual void projectPoint(double fX, double fY, double fZ, int iAngleIndex, - float32 &fU, float32 &fV) const; + double &fU, double &fV) const; + virtual void backprojectPointX(int iAngleIndex, double fU, double fV, + double fX, double &fY, double &fZ) const; + virtual void backprojectPointY(int iAngleIndex, double fU, double fV, + double fY, double &fX, double &fZ) const; + virtual void backprojectPointZ(int iAngleIndex, double fU, double fV, + double fZ, double &fX, double &fY) const; + /** * Creates (= allocates) a 2D projection geometry used when projecting one slice using a 2D projector diff --git a/include/astra/ParallelVecProjectionGeometry3D.h b/include/astra/ParallelVecProjectionGeometry3D.h index 59238c8..ec91086 100644 --- a/include/astra/ParallelVecProjectionGeometry3D.h +++ b/include/astra/ParallelVecProjectionGeometry3D.h @@ -149,9 +149,15 @@ public: const SPar3DProjection* getProjectionVectors() const { return m_pProjectionAngles; } - virtual void projectPoint(float32 fX, float32 fY, float32 fZ, + virtual void projectPoint(double fX, double fY, double fZ, int iAngleIndex, - float32 &fU, float32 &fV) const; + double &fU, double &fV) const; + virtual void backprojectPointX(int iAngleIndex, double fU, double fV, + double fX, double &fY, double &fZ) const; + virtual void backprojectPointY(int iAngleIndex, double fU, double fV, + double fY, double &fX, double &fZ) const; + virtual void backprojectPointZ(int iAngleIndex, double fU, double fV, + double fZ, double &fX, double &fY) const; }; } // namespace astra diff --git a/include/astra/ProjectionGeometry3D.h b/include/astra/ProjectionGeometry3D.h index 19ac3ab..0b60287 100644 --- a/include/astra/ProjectionGeometry3D.h +++ b/include/astra/ProjectionGeometry3D.h @@ -317,9 +317,24 @@ public: * @param iAngleIndex the index of the angle to use * @param fU,fV the projected point. */ - virtual void projectPoint(float32 fX, float32 fY, float32 fZ, + virtual void projectPoint(double fX, double fY, double fZ, int iAngleIndex, - float32 &fU, float32 &fV) const = 0; + double &fU, double &fV) const = 0; + + /* Backproject a point onto a plane parallel to a coordinate plane. + * The 2D point coordinates are the (unrounded) indices of the detector + * column and row. The output is in 3D coordinates in units. + * are in units. The output fU,fV are the (unrounded) indices of the + * detector column and row. + * This may fall outside of the actual detector. + */ + virtual void backprojectPointX(int iAngleIndex, double fU, double fV, + double fX, double &fY, double &fZ) const = 0; + virtual void backprojectPointY(int iAngleIndex, double fU, double fV, + double fY, double &fX, double &fZ) const = 0; + virtual void backprojectPointZ(int iAngleIndex, double fU, double fV, + double fZ, double &fX, double &fY) const = 0; + /** Returns true if the type of geometry defined in this class is the one specified in _sType. * -- cgit v1.2.3 From 81e7385c110a6210d0f9bc402df522301ec162f6 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 4 Dec 2015 15:14:19 +0100 Subject: Add utility functions for creating FP/BP JobLists --- include/astra/CompositeGeometryManager.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include/astra') diff --git a/include/astra/CompositeGeometryManager.h b/include/astra/CompositeGeometryManager.h index a6e57f1..6610151 100644 --- a/include/astra/CompositeGeometryManager.h +++ b/include/astra/CompositeGeometryManager.h @@ -136,6 +136,8 @@ public: bool doBP(CProjector3D *pProjector, CFloat32VolumeData3DMemory *pVolData, CFloat32ProjectionData3DMemory *pProjData); + bool doFP(CProjector3D *pProjector, const std::vector& volData, const std::vector& projData); + bool doBP(CProjector3D *pProjector, const std::vector& volData, const std::vector& projData); protected: -- cgit v1.2.3 From 8603f9a768c99b18eb74aff13a015fc60fa57ea6 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 4 Dec 2015 16:20:35 +0100 Subject: Update version to 1.7 --- include/astra/Globals.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'include/astra') diff --git a/include/astra/Globals.h b/include/astra/Globals.h index f70c3a9..31f1371 100644 --- a/include/astra/Globals.h +++ b/include/astra/Globals.h @@ -61,9 +61,9 @@ $Id$ // macro's #define ASTRA_TOOLBOXVERSION_MAJOR 1 -#define ASTRA_TOOLBOXVERSION_MINOR 6 +#define ASTRA_TOOLBOXVERSION_MINOR 7 #define ASTRA_TOOLBOXVERSION ((ASTRA_TOOLBOXVERSION_MAJOR)*100 + (ASTRA_TOOLBOXVERSION_MINOR)) -#define ASTRA_TOOLBOXVERSION_STRING "1.6" +#define ASTRA_TOOLBOXVERSION_STRING "1.7" #define ASTRA_ASSERT(a) assert(a) -- cgit v1.2.3