summaryrefslogtreecommitdiffstats
path: root/cuda/3d/fdk.cu
diff options
context:
space:
mode:
authorWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2019-09-27 15:16:26 +0200
committerWillem Jan Palenstijn <Willem.Jan.Palenstijn@cwi.nl>2019-09-27 15:16:26 +0200
commit54af7e8e22a3f1c9d90b13291b28d39778c05564 (patch)
tree260310b16d624261bb80f82979af27750022259b /cuda/3d/fdk.cu
parent1fec36f7ccadd5f7dcf2bb59b0654dc53653b0f3 (diff)
parentb629db207bb263495bfff2e61ce189ccac27b4b9 (diff)
downloadastra-54af7e8e22a3f1c9d90b13291b28d39778c05564.tar.gz
astra-54af7e8e22a3f1c9d90b13291b28d39778c05564.tar.bz2
astra-54af7e8e22a3f1c9d90b13291b28d39778c05564.tar.xz
astra-54af7e8e22a3f1c9d90b13291b28d39778c05564.zip
Merge branch 'consistent_scaling'
Diffstat (limited to 'cuda/3d/fdk.cu')
-rw-r--r--cuda/3d/fdk.cu242
1 files changed, 9 insertions, 233 deletions
diff --git a/cuda/3d/fdk.cu b/cuda/3d/fdk.cu
index 1294721..456694f 100644
--- a/cuda/3d/fdk.cu
+++ b/cuda/3d/fdk.cu
@@ -32,11 +32,6 @@ along with the ASTRA Toolbox. If not, see <http://www.gnu.org/licenses/>.
#include "astra/cuda/2d/fft.h"
-#ifdef STANDALONE
-#include "astra/cuda/3d/cone_fp.h"
-#include "testutil.h"
-#endif
-
#include "astra/Logging.h"
#include <cstdio>
@@ -57,10 +52,13 @@ static const unsigned g_MaxAngles = 12000;
__constant__ float gC_angle[g_MaxAngles];
-// per-detector u/v shifts?
+// TODO: To support non-cube voxels, preweighting needs per-view
+// parameters. NB: Need to properly take into account the
+// anisotropic volume normalization done for that too.
-__global__ void devFDK_preweight(void* D_projData, unsigned int projPitch, unsigned int startAngle, unsigned int endAngle, float fSrcOrigin, float fDetOrigin, float fZShift, float fDetUSize, float fDetVSize, float fVoxSize, const SDimensions3D dims)
+
+__global__ void devFDK_preweight(void* D_projData, unsigned int projPitch, unsigned int startAngle, unsigned int endAngle, float fSrcOrigin, float fDetOrigin, float fZShift, float fDetUSize, float fDetVSize, const SDimensions3D dims)
{
float* projData = (float*)D_projData;
int angle = startAngle + blockIdx.y * g_anglesPerWeightBlock + threadIdx.y;
@@ -88,14 +86,10 @@ __global__ void devFDK_preweight(void* D_projData, unsigned int projPitch, unsig
// fCentralRayLength / fRayLength : the main FDK preweighting factor
// fSrcOrigin / (fDetUSize * fCentralRayLength)
// : to adjust the filter to the det width
- // || u v s || ^ 2 : see cone_bp.cu, FDKWEIGHT
// pi / (2 * iProjAngles) : scaling of the integral over angles
- // fVoxSize ^ 2 : ...
- const float fW1 = fSrcOrigin * fDetUSize * fDetVSize;
const float fW2 = fCentralRayLength / (fDetUSize * fSrcOrigin);
- const float fW3 = fVoxSize * fVoxSize;
- const float fW = fCentralRayLength * fW1 * fW1 * fW2 * fW3 * (M_PI / 2.0f) / (float)dims.iProjAngles;
+ const float fW = fCentralRayLength * fW2 * (M_PI / 2.0f) / (float)dims.iProjAngles;
for (int detectorV = startDetectorV; detectorV < endDetectorV; ++detectorV)
{
@@ -167,7 +161,7 @@ __global__ void devFDK_ParkerWeight(void* D_projData, unsigned int projPitch, un
bool FDK_PreWeight(cudaPitchedPtr D_projData,
float fSrcOrigin, float fDetOrigin,
float fZShift,
- float fDetUSize, float fDetVSize, float fVoxSize,
+ float fDetUSize, float fDetVSize,
bool bShortScan,
const SDimensions3D& dims, const float* angles)
{
@@ -180,7 +174,7 @@ bool FDK_PreWeight(cudaPitchedPtr D_projData,
int projPitch = D_projData.pitch/sizeof(float);
- devFDK_preweight<<<dimGrid, dimBlock>>>(D_projData.ptr, projPitch, 0, dims.iProjAngles, fSrcOrigin, fDetOrigin, fZShift, fDetUSize, fDetVSize, fVoxSize, dims);
+ devFDK_preweight<<<dimGrid, dimBlock>>>(D_projData.ptr, projPitch, 0, dims.iProjAngles, fSrcOrigin, fDetOrigin, fZShift, fDetUSize, fDetVSize, dims);
cudaTextForceKernelsCompletion();
@@ -344,9 +338,8 @@ bool FDK(cudaPitchedPtr D_volumeData,
#if 1
- // NB: assuming cube voxels (params.fVolScaleX)
ok = FDK_PreWeight(D_projData, fSrcOrigin, fDetOrigin,
- fZShift, fDetUSize, fDetVSize, params.fVolScaleX,
+ fZShift, fDetUSize, fDetVSize,
bShortScan, dims, pfAngles);
#else
ok = true;
@@ -379,220 +372,3 @@ bool FDK(cudaPitchedPtr D_volumeData,
}
-
-#ifdef STANDALONE
-void dumpVolume(const char* filespec, const cudaPitchedPtr& data, const SDimensions3D& dims, float fMin, float fMax)
-{
- float* buf = new float[dims.iVolX*dims.iVolY];
- unsigned int pitch = data.pitch / sizeof(float);
-
- for (int i = 0; i < dims.iVolZ; ++i) {
- cudaMemcpy2D(buf, dims.iVolX*sizeof(float), ((float*)data.ptr)+pitch*dims.iVolY*i, data.pitch, dims.iVolX*sizeof(float), dims.iVolY, cudaMemcpyDeviceToHost);
-
- char fname[512];
- sprintf(fname, filespec, dims.iVolZ-i-1);
- saveImage(fname, dims.iVolY, dims.iVolX, buf, fMin, fMax);
- }
-}
-
-void dumpSinograms(const char* filespec, const cudaPitchedPtr& data, const SDimensions3D& dims, float fMin, float fMax)
-{
- float* bufs = new float[dims.iProjAngles*dims.iProjU];
- unsigned int pitch = data.pitch / sizeof(float);
-
- for (int i = 0; i < dims.iProjV; ++i) {
- cudaMemcpy2D(bufs, dims.iProjU*sizeof(float), ((float*)data.ptr)+pitch*dims.iProjAngles*i, data.pitch, dims.iProjU*sizeof(float), dims.iProjAngles, cudaMemcpyDeviceToHost);
-
- char fname[512];
- sprintf(fname, filespec, i);
- saveImage(fname, dims.iProjAngles, dims.iProjU, bufs, fMin, fMax);
- }
-}
-
-void dumpProjections(const char* filespec, const cudaPitchedPtr& data, const SDimensions3D& dims, float fMin, float fMax)
-{
- float* bufp = new float[dims.iProjV*dims.iProjU];
- unsigned int pitch = data.pitch / sizeof(float);
-
- for (int i = 0; i < dims.iProjAngles; ++i) {
- for (int j = 0; j < dims.iProjV; ++j) {
- cudaMemcpy(bufp+dims.iProjU*j, ((float*)data.ptr)+pitch*dims.iProjAngles*j+pitch*i, dims.iProjU*sizeof(float), cudaMemcpyDeviceToHost);
- }
-
- char fname[512];
- sprintf(fname, filespec, i);
- saveImage(fname, dims.iProjV, dims.iProjU, bufp, fMin, fMax);
- }
-}
-
-
-
-
-int main()
-{
-#if 0
- SDimensions3D dims;
- dims.iVolX = 512;
- dims.iVolY = 512;
- dims.iVolZ = 512;
- dims.iProjAngles = 180;
- dims.iProjU = 1024;
- dims.iProjV = 1024;
- dims.iRaysPerDet = 1;
-
- cudaExtent extentV;
- extentV.width = dims.iVolX*sizeof(float);
- extentV.height = dims.iVolY;
- extentV.depth = dims.iVolZ;
-
- cudaPitchedPtr volData; // pitch, ptr, xsize, ysize
-
- cudaMalloc3D(&volData, extentV);
-
- cudaExtent extentP;
- extentP.width = dims.iProjU*sizeof(float);
- extentP.height = dims.iProjAngles;
- extentP.depth = dims.iProjV;
-
- cudaPitchedPtr projData; // pitch, ptr, xsize, ysize
-
- cudaMalloc3D(&projData, extentP);
- cudaMemset3D(projData, 0, extentP);
-
-#if 0
- float* slice = new float[256*256];
- cudaPitchedPtr ptr;
- ptr.ptr = slice;
- ptr.pitch = 256*sizeof(float);
- ptr.xsize = 256*sizeof(float);
- ptr.ysize = 256;
-
- for (unsigned int i = 0; i < 256*256; ++i)
- slice[i] = 1.0f;
- for (unsigned int i = 0; i < 256; ++i) {
- cudaExtent extentS;
- extentS.width = dims.iVolX*sizeof(float);
- extentS.height = dims.iVolY;
- extentS.depth = 1;
- cudaPos sp = { 0, 0, 0 };
- cudaPos dp = { 0, 0, i };
- cudaMemcpy3DParms p;
- p.srcArray = 0;
- p.srcPos = sp;
- p.srcPtr = ptr;
- p.dstArray = 0;
- p.dstPos = dp;
- p.dstPtr = volData;
- p.extent = extentS;
- p.kind = cudaMemcpyHostToDevice;
- cudaMemcpy3D(&p);
-#if 0
- if (i == 128) {
- for (unsigned int j = 0; j < 256*256; ++j)
- slice[j] = 0.0f;
- }
-#endif
- }
-#endif
-
- SConeProjection angle[180];
- angle[0].fSrcX = -1536;
- angle[0].fSrcY = 0;
- angle[0].fSrcZ = 0;
-
- angle[0].fDetSX = 1024;
- angle[0].fDetSY = -512;
- angle[0].fDetSZ = 512;
-
- angle[0].fDetUX = 0;
- angle[0].fDetUY = 1;
- angle[0].fDetUZ = 0;
-
- angle[0].fDetVX = 0;
- angle[0].fDetVY = 0;
- angle[0].fDetVZ = -1;
-
-#define ROTATE0(name,i,alpha) do { angle[i].f##name##X = angle[0].f##name##X * cos(alpha) - angle[0].f##name##Y * sin(alpha); angle[i].f##name##Y = angle[0].f##name##X * sin(alpha) + angle[0].f##name##Y * cos(alpha); } while(0)
- for (int i = 1; i < 180; ++i) {
- angle[i] = angle[0];
- ROTATE0(Src, i, i*2*M_PI/180);
- ROTATE0(DetS, i, i*2*M_PI/180);
- ROTATE0(DetU, i, i*2*M_PI/180);
- ROTATE0(DetV, i, i*2*M_PI/180);
- }
-#undef ROTATE0
-
- astraCUDA3d::ConeFP(volData, projData, dims, angle, 1.0f);
-
- //dumpSinograms("sino%03d.png", projData, dims, 0, 512);
- //dumpProjections("proj%03d.png", projData, dims, 0, 512);
-
- astraCUDA3d::zeroVolumeData(volData, dims);
-
- float* angles = new float[dims.iProjAngles];
- for (int i = 0; i < 180; ++i)
- angles[i] = i*2*M_PI/180;
-
- astraCUDA3d::FDK(volData, projData, 1536, 512, 0, 0, dims, angles);
-
- dumpVolume("vol%03d.png", volData, dims, -20, 100);
-
-
-#else
-
- SDimensions3D dims;
- dims.iVolX = 1000;
- dims.iVolY = 999;
- dims.iVolZ = 500;
- dims.iProjAngles = 376;
- dims.iProjU = 1024;
- dims.iProjV = 524;
- dims.iRaysPerDet = 1;
-
- float* angles = new float[dims.iProjAngles];
- for (int i = 0; i < dims.iProjAngles; ++i)
- angles[i] = -i*(M_PI)/360;
-
- cudaPitchedPtr volData = astraCUDA3d::allocateVolumeData(dims);
- cudaPitchedPtr projData = astraCUDA3d::allocateProjectionData(dims);
- astraCUDA3d::zeroProjectionData(projData, dims);
- astraCUDA3d::zeroVolumeData(volData, dims);
-
- timeval t;
- tic(t);
-
- for (int i = 0; i < dims.iProjAngles; ++i) {
- char fname[256];
- sprintf(fname, "/home/wpalenst/tmp/Elke/proj%04d.png", i);
- unsigned int w,h;
- float* bufp = loadImage(fname, w,h);
-
- int pitch = projData.pitch / sizeof(float);
- for (int j = 0; j < dims.iProjV; ++j) {
- cudaMemcpy(((float*)projData.ptr)+dims.iProjAngles*pitch*j+pitch*i, bufp+dims.iProjU*j, dims.iProjU*sizeof(float), cudaMemcpyHostToDevice);
- }
-
- delete[] bufp;
- }
- printf("Load time: %f\n", toc(t));
-
- //dumpSinograms("sino%03d.png", projData, dims, -8.0f, 256.0f);
- //astraCUDA3d::FDK(volData, projData, 7350, 62355, 0, 10, dims, angles);
- //astraCUDA3d::FDK(volData, projData, 7350, -380, 0, 10, dims, angles);
-
- tic(t);
-
- astraCUDA3d::FDK(volData, projData, 7383.29867, 0, 0, 10, dims, angles);
-
- printf("FDK time: %f\n", toc(t));
- tic(t);
-
- dumpVolume("vol%03d.png", volData, dims, -65.9f, 200.0f);
- //dumpVolume("vol%03d.png", volData, dims, 0.0f, 256.0f);
- printf("Save time: %f\n", toc(t));
-
-#endif
-
-
-}
-#endif