how does getdepth function work in MarchingCube algorithm?

南楼画角 提交于 2019-12-12 05:48:09

问题


I am trying to understand Marching Cube Algorithm, so for I think I have understood how triangles are formed and how normals are calculated in each grid. I can see there is a linked list kind of structure that links each grid to another. But when I come across GetDepth(t[m]) which passes each triangles (those triangles of each grid) (t[0],..,..)individually, it returns depth of the node.

The function,

float GetDepth(TRIANGLE t) {

    float z;
    z = t.p[0].z;
    z = t.p[1].z > z? t.p[1].z: z;
    z = t.p[2].z > z? t.p[2].z: z;
    return z;
}

It looks like its trying to find max z(is it true). I can see that it compares " > " and then I lost it. Can any one please explain what is happening here.


回答1:


It would seem that you are unfamiliar with ? as a ternary operator. The code you posted is equivalent to the following:

float GetDepth(TRIANGLE t) {

float z;
z = t.p[0].z;
if (t.p[1].z > z) {z = t.p[1].z;} else {z = z;}
if (t.p[2].z > z) {z = t.p[2].z;} else {z = z;}
return z;
}

And yes, this does find the maximum z in the p array.



来源:https://stackoverflow.com/questions/15996097/how-does-getdepth-function-work-in-marchingcube-algorithm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!