简体   繁体   中英

Trouble with 3D rotation in C/CUDA

I am trying to implement a 3D rotation routine for an image stack using C/CUDA (mostly to speed up calculation times). I used the ImageJ source code as a basis for the code, so the rotation isn't freely about the origin, but rather along axes. There is an interesting problem I have come upon though. I implemented a rotation of an object about the Y-axis with little problem. However, when I attempt to rotate about the X-axis, with very similar code, there are issues. I noticed that in the X rotation, there was significant striping, such as this example:

http://i.imgur.com/dkecs.png

which was not occurring in the Y-rotation I was doing.

I have provided the CUDA kernels that are run to do the rotation about each axes (rotationY is the one that works, rotationX is the one that gives the striping). I was wondering if anybody could provide any suggestions as to why I would be getting problems with one and not the other, provided they are very similar in implementation.

EDIT: I have narrowed the problem down to atomicMin() not working correctly. zbuffer is not changing correctly even though all the offsets are being set correctly. If anybody knows why this might not be working it would be good to know.

__global__ void rotationY(int *input, int *projArray, int costheta, int sintheta, int width, int height, int depth, int xcenter, int zcenter,
int projectionwidth, int projectionsize, int *zbuffer, int adjCue, int depthCueSurf, int zmax, int zdiff){
int i=threadIdx.x + blockDim.x*blockIdx.x;
int zcostheta;
int zsintheta;
int offset;
int k, z, point, xnew, znew;
int y=i/width;
int x=i-y*width-xcenter;
int xcostheta = x*costheta;
int xsintheta = x*sintheta;
int offsetinit = y*projectionwidth;
zbuffer[i]=32767;
__syncthreads();
for(k=1; k<=depth; k++){
    z = (int)(k-1+.5) - zcenter;
    zcostheta = z*costheta;
    zsintheta = z*sintheta;
    point = i + (k-1)*width*height;
    if(input[point]>0){
        xnew = (xcostheta + zsintheta)/8192 + xcenter;
        znew = (zcostheta - xsintheta)/8192 + zcenter;
        offset = offsetinit + xnew;
        if (offset<0 || offset>=projectionsize) offset = 0;
        atomicMin(&zbuffer[offset],znew);
    }
    __syncthreads();
    if(input[point]>0){
        if(znew<=zbuffer[offset]) projArray[offset] = adjCue*input[point]/100+depthCueSurf*input[point]*(zmax-znew)/zdiff;
    }

}
}

__global__ void rotationX(int *input, int *projArray, int costheta, int sintheta, int width, int height, int depth, int ycenter, int zcenter,
int projectionsize, int *zbuffer, int adjCue, int depthCueSurf, int zmax, int zdiff)    {

int i=threadIdx.x + blockDim.x*blockIdx.x;
int zcostheta;
int zsintheta;
int offset;
int k, z, point, ynew, znew;
int y=i/width;
int x=i-y*width;
y=y-ycenter;
int ycostheta = y*costheta;
int ysintheta = y*sintheta;
zbuffer[i]=32767;
__syncthreads();
for(k=1; k<=depth; k++){
    z = (int)(k-1+.5) - zcenter;
    zcostheta = z*costheta;
    zsintheta = z*sintheta;
    point = i + (k-1)*width*height;
    if(input[point]>0){
        ynew = (ycostheta - zsintheta)/8192 + ycenter;
        znew = (ysintheta + zcostheta)/8192 + zcenter;
        offset = x + ynew*width;
        if (offset<0 || offset>=projectionsize) offset = 0;
        atomicMin(&zbuffer[offset], znew);
    }
    __syncthreads();
    if(input[point]>0){
        if(znew<=zbuffer[offset]) projArray[offset] = adjCue*input[point]/100+depthCueSurf*input[point]*(zmax-znew)/zdiff;
    }
}
}

The parameter projectionwidth is missing in the function prototype of rotationX. This is my best candidate for the error right now.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM