简体   繁体   English

C / CUDA中的3D旋转问题

[英]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). 我正在尝试使用C / CUDA为图像堆栈实现3D旋转例程(主要是为了加快计算时间)。 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. 我使用ImageJ源代码作为代码的基础,因此旋转不是围绕原点自由旋转,而是沿轴旋转。 There is an interesting problem I have come upon though. 我遇到了一个有趣的问题。 I implemented a rotation of an object about the Y-axis with little problem. 我实现了一个对象绕Y轴旋转几乎没有问题。 However, when I attempt to rotate about the X-axis, with very similar code, there are issues. 但是,当我尝试使用非常相似的代码绕X轴旋转时,会出现问题。 I noticed that in the X rotation, there was significant striping, such as this example: 我注意到在X旋转中存在明显的条纹,例如以下示例:

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

which was not occurring in the Y-rotation I was doing. 这不是我正在做的Y旋转中发生的。

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). 我提供了运行CUDA内核以绕每个轴旋转(rotationY是有效的轴,rotationX是产生条纹的轴)。 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. 编辑:我已将问题缩小到atomicMin()无法正常工作。 zbuffer is not changing correctly even though all the offsets are being set correctly. 即使正确设置了所有偏移量,zbuffer也无法正确更改。 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. rotationX的函数原型中缺少参数projectionwidth。 This is my best candidate for the error right now. 现在,这是我最适合该错误的人。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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