From e5b70e8b53e4ecc81b1aacc3af7893faf49ddc24 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Fri, 22 Jun 2018 15:46:11 +0200 Subject: Move CUDA include files --- include/astra/cuda/3d/algo3d.h | 71 ++++++++ include/astra/cuda/3d/arith3d.h | 79 +++++++++ include/astra/cuda/3d/astra3d.h | 314 +++++++++++++++++++++++++++++++++++ include/astra/cuda/3d/cgls3d.h | 112 +++++++++++++ include/astra/cuda/3d/cone_bp.h | 45 +++++ include/astra/cuda/3d/cone_fp.h | 45 +++++ include/astra/cuda/3d/darthelper3d.h | 42 +++++ include/astra/cuda/3d/dims3d.h | 77 +++++++++ include/astra/cuda/3d/fdk.h | 50 ++++++ include/astra/cuda/3d/mem3d.h | 105 ++++++++++++ include/astra/cuda/3d/par3d_bp.h | 46 +++++ include/astra/cuda/3d/par3d_fp.h | 50 ++++++ include/astra/cuda/3d/sirt3d.h | 121 ++++++++++++++ include/astra/cuda/3d/util3d.h | 68 ++++++++ 14 files changed, 1225 insertions(+) create mode 100644 include/astra/cuda/3d/algo3d.h create mode 100644 include/astra/cuda/3d/arith3d.h create mode 100644 include/astra/cuda/3d/astra3d.h create mode 100644 include/astra/cuda/3d/cgls3d.h create mode 100644 include/astra/cuda/3d/cone_bp.h create mode 100644 include/astra/cuda/3d/cone_fp.h create mode 100644 include/astra/cuda/3d/darthelper3d.h create mode 100644 include/astra/cuda/3d/dims3d.h create mode 100644 include/astra/cuda/3d/fdk.h create mode 100644 include/astra/cuda/3d/mem3d.h create mode 100644 include/astra/cuda/3d/par3d_bp.h create mode 100644 include/astra/cuda/3d/par3d_fp.h create mode 100644 include/astra/cuda/3d/sirt3d.h create mode 100644 include/astra/cuda/3d/util3d.h (limited to 'include/astra/cuda/3d') diff --git a/include/astra/cuda/3d/algo3d.h b/include/astra/cuda/3d/algo3d.h new file mode 100644 index 0000000..f5fd207 --- /dev/null +++ b/include/astra/cuda/3d/algo3d.h @@ -0,0 +1,71 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_ALGO_H +#define _CUDA_ALGO_H + +#include "dims3d.h" +#include "util3d.h" + +namespace astraCUDA3d { + +class _AstraExport ReconAlgo3D { +public: + ReconAlgo3D(); + ~ReconAlgo3D(); + + bool setConeGeometry(const SDimensions3D& dims, const SConeProjection* projs, const SProjectorParams3D& params); + bool setPar3DGeometry(const SDimensions3D& dims, const SPar3DProjection* projs, const SProjectorParams3D& params); + + void signalAbort() { shouldAbort = true; } + +protected: + void reset(); + + bool callFP(cudaPitchedPtr& D_volumeData, + cudaPitchedPtr& D_projData, + float outputScale); + bool callBP(cudaPitchedPtr& D_volumeData, + cudaPitchedPtr& D_projData, + float outputScale); + + SDimensions3D dims; + SProjectorParams3D params; + SConeProjection* coneProjs; + SPar3DProjection* par3DProjs; + + float fOutputScale; + + volatile bool shouldAbort; + +}; + + +} + +#endif + diff --git a/include/astra/cuda/3d/arith3d.h b/include/astra/cuda/3d/arith3d.h new file mode 100644 index 0000000..fa9f3a1 --- /dev/null +++ b/include/astra/cuda/3d/arith3d.h @@ -0,0 +1,79 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_ARITH3D_H +#define _CUDA_ARITH3D_H + +#include + +namespace astraCUDA3d { + +struct opAddScaled; +struct opScaleAndAdd; +struct opAddMulScaled; +struct opAddMul; +struct opAdd; +struct opMul; +struct opMul2; +struct opDividedBy; +struct opInvert; +struct opSet; +struct opClampMin; +struct opClampMax; + +enum VolType { + SINO = 0, + VOL = 1 +}; + + +template void processVol(CUdeviceptr* out, unsigned int pitch, unsigned int width, unsigned int height); +template void processVol(CUdeviceptr* out, float fParam, unsigned int pitch, unsigned int width, unsigned int height); +template void processVol(CUdeviceptr* out, const CUdeviceptr* in, unsigned int pitch, unsigned int width, unsigned int height); +template void processVol(CUdeviceptr* out, const CUdeviceptr* in, float fParam, unsigned int pitch, unsigned int width, unsigned int height); +template void processVol(CUdeviceptr* out, const CUdeviceptr* in1, const CUdeviceptr* in2, float fParam, unsigned int pitch, unsigned int width, unsigned int height); +template void processVol(CUdeviceptr* out, const CUdeviceptr* in1, const CUdeviceptr* in2, unsigned int pitch, unsigned int width, unsigned int height); + +template void processVol3D(cudaPitchedPtr& out, const SDimensions3D& dims); +template void processVol3D(cudaPitchedPtr& out, float fParam, const SDimensions3D& dims); +template void processVol3D(cudaPitchedPtr& out, const cudaPitchedPtr& in, const SDimensions3D& dims); +template void processVol3D(cudaPitchedPtr& out, const cudaPitchedPtr& in, float fParam, const SDimensions3D& dims); +template void processVol3D(cudaPitchedPtr& out, const cudaPitchedPtr& in1, const cudaPitchedPtr& in2, float fParam, const SDimensions3D& dims); +template void processVol3D(cudaPitchedPtr& out, const cudaPitchedPtr& in1, const cudaPitchedPtr& in2, const SDimensions3D& dims); + +template void processSino3D(cudaPitchedPtr& out, const SDimensions3D& dims); +template void processSino3D(cudaPitchedPtr& out, float fParam, const SDimensions3D& dims); +template void processSino3D(cudaPitchedPtr& out, const cudaPitchedPtr& in, const SDimensions3D& dims); +template void processSino3D(cudaPitchedPtr& out, const cudaPitchedPtr& in, float fParam, const SDimensions3D& dims); +template void processSino3D(cudaPitchedPtr& out, const cudaPitchedPtr& in1, const cudaPitchedPtr& in2, float fParam, const SDimensions3D& dims); +template void processSino3D(cudaPitchedPtr& out, const cudaPitchedPtr& in1, const cudaPitchedPtr& in2, const SDimensions3D& dims); + + + +} + +#endif diff --git a/include/astra/cuda/3d/astra3d.h b/include/astra/cuda/3d/astra3d.h new file mode 100644 index 0000000..0ea752d --- /dev/null +++ b/include/astra/cuda/3d/astra3d.h @@ -0,0 +1,314 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_ASTRA3D_H +#define _CUDA_ASTRA3D_H + +#include "dims3d.h" + +namespace astra { + + +// TODO: Switch to a class hierarchy as with the 2D algorithms + + +class CProjectionGeometry3D; +class CParallelProjectionGeometry3D; +class CParallelVecProjectionGeometry3D; +class CConeProjectionGeometry3D; +class CConeVecProjectionGeometry3D; +class CVolumeGeometry3D; +class AstraSIRT3d_internal; + +using astraCUDA3d::Cuda3DProjectionKernel; +using astraCUDA3d::ker3d_default; +using astraCUDA3d::ker3d_sum_square_weights; + + +class _AstraExport AstraSIRT3d { +public: + + AstraSIRT3d(); + ~AstraSIRT3d(); + + // Set the volume and projection geometry + bool setGeometry(const CVolumeGeometry3D* pVolGeom, + const CProjectionGeometry3D* pProjGeom); + + // Enable supersampling. + // + // The number of rays used in FP is the square of iDetectorSuperSampling. + // The number of rays used in BP is the cube of iVoxelSuperSampling. + bool enableSuperSampling(unsigned int iVoxelSuperSampling, + unsigned int iDetectorSuperSampling); + + void setRelaxation(float r); + + // Enable volume/sinogram masks + // + // This may optionally be called before init(). + // If it is called, setVolumeMask()/setSinogramMask() must be called between + // setSinogram() and iterate(). + bool enableVolumeMask(); + bool enableSinogramMask(); + + // Set GPU index + // + // This should be called before init(). Note that setting the GPU index + // in a thread which has already used the GPU may not work. + bool setGPUIndex(int index); + + // Allocate GPU buffers and + // precompute geometry-specific data. + // + // This must be called after calling setReconstructionGeometry() and + // setProjectionGeometry() or setFanProjectionGeometry(). + bool init(); + + // Setup input sinogram for a slice. + // pfSinogram must be a float array of size XXX + // NB: iSinogramPitch is measured in floats, not in bytes. + // + // This must be called after init(), and before iterate(). It may be + // called again after iterate()/getReconstruction() to start a new slice. + // + // pfSinogram will only be read from during this call. + bool setSinogram(const float* pfSinogram, unsigned int iSinogramPitch); + + // Setup volume mask for a slice. + // pfMask must be a float array of size XXX + // NB: iMaskPitch is measured in floats, not in bytes. + // + // It may only contain the exact values 0.0f and 1.0f. Only volume pixels + // for which pfMask[z] is 1.0f are processed. + bool setVolumeMask(const float* pfMask, unsigned int iMaskPitch); + + // Setup sinogram mask for a slice. + // pfMask must be a float array of size XXX + // NB: iMaskPitch is measured in floats, not in bytes. + // + // It may only contain the exact values 0.0f and 1.0f. Only sinogram pixels + // for which pfMask[z] is 1.0f are processed. + bool setSinogramMask(const float* pfMask, unsigned int iMaskPitch); + + // Set the starting reconstruction for SIRT. + // pfReconstruction must be a float array of size XXX + // NB: iReconstructionPitch is measured in floats, not in bytes. + // + // This may be called between setSinogram() and iterate(). + // If this function is not called before iterate(), SIRT will start + // from a zero reconstruction. + // + // pfReconstruction will only be read from during this call. + bool setStartReconstruction(const float* pfReconstruction, + unsigned int iReconstructionPitch); + + // Enable min/max constraint. + // + // These may optionally be called between init() and iterate() + bool setMinConstraint(float fMin); + bool setMaxConstraint(float fMax); + + // Perform a number of (additive) SIRT iterations. + // This must be called after setSinogram(). + // + // If called multiple times, without calls to setSinogram() or + // setStartReconstruction() in between, iterate() will continue from + // the result of the previous call. + // Calls to getReconstruction() are allowed between calls to iterate() and + // do not change the state. + bool iterate(unsigned int iIterations); + + // Get the reconstructed slice. + // pfReconstruction must be a float array of size XXX + // NB: iReconstructionPitch is measured in floats, not in bytes. + // + // This may be called after iterate(). + bool getReconstruction(float* pfReconstruction, + unsigned int iReconstructionPitch) const; + + // Compute the norm of the difference of the FP of the current + // reconstruction and the sinogram. (This performs one FP.) + // It can be called after iterate(). + float computeDiffNorm(); + + // Signal the algorithm that it should abort after the current iteration. + // This is intended to be called from another thread. + void signalAbort(); + +protected: + AstraSIRT3d_internal *pData; +}; + + +class AstraCGLS3d_internal; + + +class _AstraExport AstraCGLS3d { +public: + + AstraCGLS3d(); + ~AstraCGLS3d(); + + // Set the volume and projection geometry + bool setGeometry(const CVolumeGeometry3D* pVolGeom, + const CProjectionGeometry3D* pProjGeom); + + // Enable supersampling. + // + // The number of rays used in FP is the square of iDetectorSuperSampling. + // The number of rays used in BP is the cube of iVoxelSuperSampling. + bool enableSuperSampling(unsigned int iVoxelSuperSampling, + unsigned int iDetectorSuperSampling); + + // Enable volume/sinogram masks + // + // This may optionally be called before init(). + // If it is called, setVolumeMask()/setSinogramMask() must be called between + // setSinogram() and iterate(). + bool enableVolumeMask(); + //bool enableSinogramMask(); + + // Set GPU index + // + // This should be called before init(). Note that setting the GPU index + // in a thread which has already used the GPU may not work. + bool setGPUIndex(int index); + + // Allocate GPU buffers and + // precompute geometry-specific data. + // + // This must be called after calling setReconstructionGeometry() and + // setProjectionGeometry() or setFanProjectionGeometry(). + bool init(); + + // Setup input sinogram for a slice. + // pfSinogram must be a float array of size XXX + // NB: iSinogramPitch is measured in floats, not in bytes. + // + // This must be called after init(), and before iterate(). It may be + // called again after iterate()/getReconstruction() to start a new slice. + // + // pfSinogram will only be read from during this call. + bool setSinogram(const float* pfSinogram, unsigned int iSinogramPitch); + + // Setup volume mask for a slice. + // pfMask must be a float array of size XXX + // NB: iMaskPitch is measured in floats, not in bytes. + // + // It may only contain the exact values 0.0f and 1.0f. Only volume pixels + // for which pfMask[z] is 1.0f are processed. + bool setVolumeMask(const float* pfMask, unsigned int iMaskPitch); + + // Setup sinogram mask for a slice. + // pfMask must be a float array of size XXX + // NB: iMaskPitch is measured in floats, not in bytes. + // + // It may only contain the exact values 0.0f and 1.0f. Only sinogram pixels + // for which pfMask[z] is 1.0f are processed. + //bool setSinogramMask(const float* pfMask, unsigned int iMaskPitch); + + // Set the starting reconstruction for SIRT. + // pfReconstruction must be a float array of size XXX + // NB: iReconstructionPitch is measured in floats, not in bytes. + // + // This may be called between setSinogram() and iterate(). + // If this function is not called before iterate(), SIRT will start + // from a zero reconstruction. + // + // pfReconstruction will only be read from during this call. + bool setStartReconstruction(const float* pfReconstruction, + unsigned int iReconstructionPitch); + + // Enable min/max constraint. + // + // These may optionally be called between init() and iterate() + //bool setMinConstraint(float fMin); + //bool setMaxConstraint(float fMax); + + // Perform a number of (additive) SIRT iterations. + // This must be called after setSinogram(). + // + // If called multiple times, without calls to setSinogram() or + // setStartReconstruction() in between, iterate() will continue from + // the result of the previous call. + // Calls to getReconstruction() are allowed between calls to iterate() and + // do not change the state. + bool iterate(unsigned int iIterations); + + // Get the reconstructed slice. + // pfReconstruction must be a float array of size XXX + // NB: iReconstructionPitch is measured in floats, not in bytes. + // + // This may be called after iterate(). + bool getReconstruction(float* pfReconstruction, + unsigned int iReconstructionPitch) const; + + // Compute the norm of the difference of the FP of the current + // reconstruction and the sinogram. (This performs one FP.) + // It can be called after iterate(). + float computeDiffNorm(); + + // Signal the algorithm that it should abort after the current iteration. + // This is intended to be called from another thread. + void signalAbort(); + +protected: + AstraCGLS3d_internal *pData; +}; + +bool convertAstraGeometry_dims(const CVolumeGeometry3D* pVolGeom, + const CProjectionGeometry3D* pProjGeom, + astraCUDA3d::SDimensions3D& dims); + +bool convertAstraGeometry(const CVolumeGeometry3D* pVolGeom, + const CProjectionGeometry3D* pProjGeom, + SPar3DProjection*& pParProjs, + SConeProjection*& pConeProjs, + astraCUDA3d::SProjectorParams3D& params); + +_AstraExport bool astraCudaFP(const float* pfVolume, float* pfProjections, + const CVolumeGeometry3D* pVolGeom, + const CProjectionGeometry3D* pProjGeom, + int iGPUIndex, int iDetectorSuperSampling, + Cuda3DProjectionKernel projKernel); + + +_AstraExport bool astraCudaBP(float* pfVolume, const float* pfProjections, + const CVolumeGeometry3D* pVolGeom, + const CProjectionGeometry3D* pProjGeom, + int iGPUIndex, int iVoxelSuperSampling); + +_AstraExport bool astraCudaBP_SIRTWeighted(float* pfVolume, const float* pfProjections, + const CVolumeGeometry3D* pVolGeom, + const CProjectionGeometry3D* pProjGeom, + int iGPUIndex, int iVoxelSuperSampling); + +} + + +#endif diff --git a/include/astra/cuda/3d/cgls3d.h b/include/astra/cuda/3d/cgls3d.h new file mode 100644 index 0000000..b9b9e3a --- /dev/null +++ b/include/astra/cuda/3d/cgls3d.h @@ -0,0 +1,112 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_CGLS3D_H +#define _CUDA_CGLS3D_H + +#include "algo3d.h" + +namespace astraCUDA3d { + +class _AstraExport CGLS : public ReconAlgo3D { +public: + CGLS(); + ~CGLS(); + +// bool setConeGeometry(const SDimensions3D& dims, const SConeProjection* projs); + + + bool enableVolumeMask(); + bool enableSinogramMask(); + + // init should be called after setting all geometry + bool init(); + + // setVolumeMask should be called after init and before iterate, + // but only if enableVolumeMask was called before init. + // It may be called again after iterate. + bool setVolumeMask(cudaPitchedPtr& D_maskData); + + // setSinogramMask should be called after init and before iterate, + // but only if enableSinogramMask was called before init. + // It may be called again after iterate. + bool setSinogramMask(cudaPitchedPtr& D_smaskData); + + + // setBuffers should be called after init and before iterate. + // It may be called again after iterate. + bool setBuffers(cudaPitchedPtr& D_volumeData, + cudaPitchedPtr& D_projData); + + + // set Min/Max constraints. They may be called at any time, and will affect + // any iterate() calls afterwards. + bool setMinConstraint(float fMin) { return false; } + bool setMaxConstraint(float fMax) { return false; } + + // iterate should be called after init and setBuffers. + // It may be called multiple times. + bool iterate(unsigned int iterations); + + // Compute the norm of the difference of the FP of the current reconstruction + // and the sinogram. (This performs one FP.) + // It can be called after iterate. + float computeDiffNorm(); + +protected: + void reset(); + + bool useVolumeMask; + bool useSinogramMask; + + cudaPitchedPtr D_maskData; + cudaPitchedPtr D_smaskData; + + // Input/output + cudaPitchedPtr D_sinoData; + cudaPitchedPtr D_volumeData; + + // Temporary buffers + cudaPitchedPtr D_r; + cudaPitchedPtr D_w; + cudaPitchedPtr D_z; + cudaPitchedPtr D_p; + + float gamma; + + bool sliceInitialized; +}; + +_AstraExport bool doCGLS(cudaPitchedPtr D_volumeData, unsigned int volumePitch, + cudaPitchedPtr D_projData, unsigned int projPitch, + cudaPitchedPtr D_maskData, unsigned int maskPitch, + const SDimensions3D& dims, const SConeProjection* projs, + unsigned int iterations); + +} + +#endif diff --git a/include/astra/cuda/3d/cone_bp.h b/include/astra/cuda/3d/cone_bp.h new file mode 100644 index 0000000..6dcadb1 --- /dev/null +++ b/include/astra/cuda/3d/cone_bp.h @@ -0,0 +1,45 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_CONE_BP_H +#define _CUDA_CONE_BP_H + +namespace astraCUDA3d { + +_AstraExport bool ConeBP_Array(cudaPitchedPtr D_volumeData, + cudaArray *D_projArray, + const SDimensions3D& dims, const SConeProjection* angles, + const SProjectorParams3D& params); + +_AstraExport bool ConeBP(cudaPitchedPtr D_volumeData, + cudaPitchedPtr D_projData, + const SDimensions3D& dims, const SConeProjection* angles, + const SProjectorParams3D& params); + +} + +#endif diff --git a/include/astra/cuda/3d/cone_fp.h b/include/astra/cuda/3d/cone_fp.h new file mode 100644 index 0000000..4da72d4 --- /dev/null +++ b/include/astra/cuda/3d/cone_fp.h @@ -0,0 +1,45 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_CONE_FP_H +#define _CUDA_CONE_FP_H + +namespace astraCUDA3d { + +_AstraExport bool ConeFP_Array(cudaArray *D_volArray, + cudaPitchedPtr D_projData, + const SDimensions3D& dims, const SConeProjection* angles, + const SProjectorParams3D& params); + +_AstraExport bool ConeFP(cudaPitchedPtr D_volumeData, + cudaPitchedPtr D_projData, + const SDimensions3D& dims, const SConeProjection* angles, + const SProjectorParams3D& params); + +} + +#endif diff --git a/include/astra/cuda/3d/darthelper3d.h b/include/astra/cuda/3d/darthelper3d.h new file mode 100644 index 0000000..385e48e --- /dev/null +++ b/include/astra/cuda/3d/darthelper3d.h @@ -0,0 +1,42 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_DARTHELPER3_H +#define _CUDA_DARTHELPER3_H + +#include "dims3d.h" + +namespace astraCUDA3d { + + void dartSmoothing(float* out, const float* in, float b, unsigned int radius, SDimensions3D dims); + void dartMasking(float* out, const float* in, unsigned int conn, unsigned int radius, unsigned int threshold, SDimensions3D dims); + + bool setGPUIndex(int index); + +} + +#endif diff --git a/include/astra/cuda/3d/dims3d.h b/include/astra/cuda/3d/dims3d.h new file mode 100644 index 0000000..ef4ea78 --- /dev/null +++ b/include/astra/cuda/3d/dims3d.h @@ -0,0 +1,77 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_CONE_DIMS_H +#define _CUDA_CONE_DIMS_H + +#include "astra/GeometryUtil3D.h" + + +namespace astraCUDA3d { + +using astra::SConeProjection; +using astra::SPar3DProjection; + + +enum Cuda3DProjectionKernel { + ker3d_default = 0, + ker3d_sum_square_weights +}; + + +struct SDimensions3D { + unsigned int iVolX; + unsigned int iVolY; + unsigned int iVolZ; + unsigned int iProjAngles; + unsigned int iProjU; // number of detectors in the U direction + unsigned int iProjV; // number of detectors in the V direction +}; + +struct SProjectorParams3D { + SProjectorParams3D() : + iRaysPerDetDim(1), iRaysPerVoxelDim(1), + fOutputScale(1.0f), + fVolScaleX(1.0f), fVolScaleY(1.0f), fVolScaleZ(1.0f), + ker(ker3d_default), + bFDKWeighting(false) + { } + + unsigned int iRaysPerDetDim; + unsigned int iRaysPerVoxelDim; + float fOutputScale; + float fVolScaleX; + float fVolScaleY; + float fVolScaleZ; + Cuda3DProjectionKernel ker; + bool bFDKWeighting; +}; + +} + +#endif + diff --git a/include/astra/cuda/3d/fdk.h b/include/astra/cuda/3d/fdk.h new file mode 100644 index 0000000..6f6e73b --- /dev/null +++ b/include/astra/cuda/3d/fdk.h @@ -0,0 +1,50 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_FDK_H +#define _CUDA_FDK_H + +#include "dims3d.h" + +namespace astraCUDA3d { + +bool FDK_PreWeight(cudaPitchedPtr D_projData, + float fSrcOrigin, float fDetOrigin, + float fZShift, + float fDetUSize, float fDetVSize, float fVoxSize, + bool bShortScan, + const SDimensions3D& dims, const float* angles); + +bool FDK(cudaPitchedPtr D_volumeData, + cudaPitchedPtr D_projData, + const SConeProjection* angles, + const SDimensions3D& dims, SProjectorParams3D params, bool bShortScan, + const float* filter); + +} + +#endif diff --git a/include/astra/cuda/3d/mem3d.h b/include/astra/cuda/3d/mem3d.h new file mode 100644 index 0000000..78e1294 --- /dev/null +++ b/include/astra/cuda/3d/mem3d.h @@ -0,0 +1,105 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_MEM3D_H +#define _CUDA_MEM3D_H + +#include + +#include "astra3d.h" + +namespace astra { +class CVolumeGeometry3D; +class CProjectionGeometry3D; +} + +namespace astraCUDA3d { + +// TODO: Make it possible to delete these handles when they're no longer +// necessary inside the FP/BP +// +// TODO: Add functions for querying capacity + +struct SMemHandle3D_internal; + +struct MemHandle3D { + boost::shared_ptr d; + operator bool() const { return (bool)d; } +}; + +struct SSubDimensions3D { + unsigned int nx; + unsigned int ny; + unsigned int nz; + unsigned int pitch; + unsigned int subnx; + unsigned int subny; + unsigned int subnz; + unsigned int subx; + unsigned int suby; + unsigned int subz; +}; + +/* +// Useful or not? +enum Mem3DCopyMode { + MODE_SET, + MODE_ADD +}; +*/ + +enum Mem3DZeroMode { + INIT_NO, + INIT_ZERO +}; + +int maxBlockDimension(); + +_AstraExport MemHandle3D wrapHandle(float *D_ptr, unsigned int x, unsigned int y, unsigned int z, unsigned int pitch); + +MemHandle3D allocateGPUMemory(unsigned int x, unsigned int y, unsigned int z, Mem3DZeroMode zero); + +bool copyToGPUMemory(const float *src, MemHandle3D dst, const SSubDimensions3D &pos); + +bool copyFromGPUMemory(float *dst, MemHandle3D src, const SSubDimensions3D &pos); + +bool freeGPUMemory(MemHandle3D handle); + +bool zeroGPUMemory(MemHandle3D handle, unsigned int x, unsigned int y, unsigned int z); + +bool setGPUIndex(int index); + + +bool FP(const astra::CProjectionGeometry3D* pProjGeom, MemHandle3D projData, const astra::CVolumeGeometry3D* pVolGeom, MemHandle3D volData, int iDetectorSuperSampling, astra::Cuda3DProjectionKernel projKernel); + +bool BP(const astra::CProjectionGeometry3D* pProjGeom, MemHandle3D projData, const astra::CVolumeGeometry3D* pVolGeom, MemHandle3D volData, int iVoxelSuperSampling, bool bFDKWeighting); + +bool FDK(const astra::CProjectionGeometry3D* pProjGeom, MemHandle3D projData, const astra::CVolumeGeometry3D* pVolGeom, MemHandle3D volData, bool bShortScan, const float *pfFilter = 0); + +} + +#endif diff --git a/include/astra/cuda/3d/par3d_bp.h b/include/astra/cuda/3d/par3d_bp.h new file mode 100644 index 0000000..b4ec6a3 --- /dev/null +++ b/include/astra/cuda/3d/par3d_bp.h @@ -0,0 +1,46 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_PAR3D_BP_H +#define _CUDA_PAR3D_BP_H + +namespace astraCUDA3d { + +_AstraExport bool Par3DBP_Array(cudaPitchedPtr D_volumeData, + cudaArray *D_projArray, + const SDimensions3D& dims, const SPar3DProjection* angles, + const SProjectorParams3D& params); + +_AstraExport bool Par3DBP(cudaPitchedPtr D_volumeData, + cudaPitchedPtr D_projData, + const SDimensions3D& dims, const SPar3DProjection* angles, + const SProjectorParams3D& params); + + +} + +#endif diff --git a/include/astra/cuda/3d/par3d_fp.h b/include/astra/cuda/3d/par3d_fp.h new file mode 100644 index 0000000..18f5f2e --- /dev/null +++ b/include/astra/cuda/3d/par3d_fp.h @@ -0,0 +1,50 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_PAR3D_FP_H +#define _CUDA_PAR3D_FP_H + +namespace astraCUDA3d { + +_AstraExport bool Par3DFP_Array(cudaArray *D_volArray, + cudaPitchedPtr D_projData, + const SDimensions3D& dims, const SPar3DProjection* angles, + const SProjectorParams3D& params); + +_AstraExport bool Par3DFP(cudaPitchedPtr D_volumeData, + cudaPitchedPtr D_projData, + const SDimensions3D& dims, const SPar3DProjection* angles, + const SProjectorParams3D& params); + +_AstraExport bool Par3DFP_SumSqW(cudaPitchedPtr D_volumeData, + cudaPitchedPtr D_projData, + const SDimensions3D& dims, const SPar3DProjection* angles, + const SProjectorParams3D& params); + +} + +#endif diff --git a/include/astra/cuda/3d/sirt3d.h b/include/astra/cuda/3d/sirt3d.h new file mode 100644 index 0000000..7c9a7c0 --- /dev/null +++ b/include/astra/cuda/3d/sirt3d.h @@ -0,0 +1,121 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_SIRT3D_H +#define _CUDA_SIRT3D_H + +#include "algo3d.h" + +namespace astraCUDA3d { + +class _AstraExport SIRT : public ReconAlgo3D { +public: + SIRT(); + ~SIRT(); + +// bool setConeGeometry(const SDimensions3D& dims, const SConeProjection* projs); + + + bool enableVolumeMask(); + bool enableSinogramMask(); + + // init should be called after setting all geometry + bool init(); + + // Set relaxation factor. This may be called after init and before iterate. + void setRelaxation(float r) { fRelaxation = r; } + + // setVolumeMask should be called after init and before iterate, + // but only if enableVolumeMask was called before init. + // It may be called again after iterate. + bool setVolumeMask(cudaPitchedPtr& D_maskData); + + // setSinogramMask should be called after init and before iterate, + // but only if enableSinogramMask was called before init. + // It may be called again after iterate. + bool setSinogramMask(cudaPitchedPtr& D_smaskData); + + + // setBuffers should be called after init and before iterate. + // It may be called again after iterate. + bool setBuffers(cudaPitchedPtr& D_volumeData, + cudaPitchedPtr& D_projData); + + + // set Min/Max constraints. They may be called at any time, and will affect + // any iterate() calls afterwards. + bool setMinConstraint(float fMin); + bool setMaxConstraint(float fMax); + + // iterate should be called after init and setBuffers. + // It may be called multiple times. + bool iterate(unsigned int iterations); + + // Compute the norm of the difference of the FP of the current reconstruction + // and the sinogram. (This performs one FP.) + // It can be called after iterate. + float computeDiffNorm(); + +protected: + void reset(); + bool precomputeWeights(); + + bool useVolumeMask; + bool useSinogramMask; + + bool useMinConstraint; + bool useMaxConstraint; + float fMinConstraint; + float fMaxConstraint; + + float fRelaxation; + + cudaPitchedPtr D_maskData; + cudaPitchedPtr D_smaskData; + + // Input/output + cudaPitchedPtr D_sinoData; + cudaPitchedPtr D_volumeData; + + // Temporary buffers + cudaPitchedPtr D_projData; + cudaPitchedPtr D_tmpData; + + // Geometry-specific precomputed data + cudaPitchedPtr D_lineWeight; + cudaPitchedPtr D_pixelWeight; +}; + +bool doSIRT(cudaPitchedPtr D_volumeData, unsigned int volumePitch, + cudaPitchedPtr D_projData, unsigned int projPitch, + cudaPitchedPtr D_maskData, unsigned int maskPitch, + const SDimensions3D& dims, const SConeProjection* projs, + unsigned int iterations); + +} + +#endif diff --git a/include/astra/cuda/3d/util3d.h b/include/astra/cuda/3d/util3d.h new file mode 100644 index 0000000..17eb31e --- /dev/null +++ b/include/astra/cuda/3d/util3d.h @@ -0,0 +1,68 @@ +/* +----------------------------------------------------------------------- +Copyright: 2010-2018, imec Vision Lab, University of Antwerp + 2014-2018, CWI, Amsterdam + +Contact: astra@astra-toolbox.com +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 _CUDA_UTIL3D_H +#define _CUDA_UTIL3D_H + +#include +#include "dims3d.h" + +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif +#include "../2d/util.h" + +namespace astraCUDA3d { + +cudaPitchedPtr allocateVolumeData(const SDimensions3D& dims); +cudaPitchedPtr allocateProjectionData(const SDimensions3D& dims); +bool zeroVolumeData(cudaPitchedPtr& D_data, const SDimensions3D& dims); +bool zeroProjectionData(cudaPitchedPtr& D_data, const SDimensions3D& dims); +bool copyVolumeToDevice(const float* data, cudaPitchedPtr& D_data, const SDimensions3D& dims, unsigned int pitch = 0); +bool copyProjectionsToDevice(const float* data, cudaPitchedPtr& D_data, const SDimensions3D& dims, unsigned int pitch = 0); +bool copyVolumeFromDevice(float* data, const cudaPitchedPtr& D_data, const SDimensions3D& dims, unsigned int pitch = 0); +bool copyProjectionsFromDevice(float* data, const cudaPitchedPtr& D_data, const SDimensions3D& dims, unsigned int pitch = 0); +bool duplicateVolumeData(cudaPitchedPtr& D_dest, const cudaPitchedPtr& D_src, const SDimensions3D& dims); +bool duplicateProjectionData(cudaPitchedPtr& D_dest, const cudaPitchedPtr& D_src, const SDimensions3D& dims); + + +bool transferProjectionsToArray(cudaPitchedPtr D_projData, cudaArray* array, const SDimensions3D& dims); +bool transferVolumeToArray(cudaPitchedPtr D_volumeData, cudaArray* array, const SDimensions3D& dims); +bool zeroProjectionArray(cudaArray* array, const SDimensions3D& dims); +bool zeroVolumeArray(cudaArray* array, const SDimensions3D& dims); +cudaArray* allocateProjectionArray(const SDimensions3D& dims); +cudaArray* allocateVolumeArray(const SDimensions3D& dims); + +bool cudaTextForceKernelsCompletion(); + +float dotProduct3D(cudaPitchedPtr data, unsigned int x, unsigned int y, unsigned int z); + +int calcNextPowerOfTwo(int _iValue); + +} + +#endif -- cgit v1.2.3