簡體   English   中英

C / CUDA中的3D旋轉問題

[英]Trouble with 3D rotation in C/CUDA

我正在嘗試使用C / CUDA為圖像堆棧實現3D旋轉例程(主要是為了加快計算時間)。 我使用ImageJ源代碼作為代碼的基礎,因此旋轉不是圍繞原點自由旋轉,而是沿軸旋轉。 我遇到了一個有趣的問題。 我實現了一個對象繞Y軸旋轉幾乎沒有問題。 但是,當我嘗試使用非常相似的代碼繞X軸旋轉時,會出現問題。 我注意到在X旋轉中存在明顯的條紋,例如以下示例:

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

這不是我正在做的Y旋轉中發生的。

我提供了運行CUDA內核以繞每個軸旋轉(rotationY是有效的軸,rotationX是產生條紋的軸)。 我想知道是否有人可以提供建議,說明為什么我會遇到一個而不是另一個的問題,只要它們的實現非常相似。

編輯:我已將問題縮小到atomicMin()無法正常工作。 即使正確設置了所有偏移量,zbuffer也無法正確更改。 如果有人知道為什么這可能行不通,那很好。

__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;
    }
}
}

rotationX的函數原型中缺少參數projectionwidth。 現在,這是我最適合該錯誤的人。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM