行进立方体问题 [英] Marching Cube Question

查看:41
本文介绍了行进立方体问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在编写一个程序来使用 C++ 和 Opengl 实现行进立方体.

然而,我最好的参考仅来自 http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/

在网络中,提供的代码是用 C 编写的.
我的问题是我不理解 triTable 和 edgeTable
以及它们之间的关系.

谁能帮我解释或指导我将算法转换成代码?

解决方案

这些表格用于找出如何细分曲面:

第一个表为您提供了插入所需的边.第二个表为您提供了细分的方式,意思是,您必须在立方体内部制作哪些三角形.

一个小例子:

让我们假设,顶点 1 和 2 低于 iso 级别,立方体索引应该是 3.

整个交叉点应该看起来像一个楔子.

如果你考虑一下,你必须在边缘上插入值:0 和 9 以及 2 和 10.如果将其输入到位域中,则每个位对应于边缘相交吗?"你最终会得到这样的结果:

<前>10 9 8 7 6 5 4 3 2 1 边1 1 0 0 0 0 1 0 1 0 相交?

不是吗?

这正是来自 edgeTable[3] 的二进制值;) 0x30A = 1100001010

现在您可以编写一个函数,对这些边上的点进行线性插值以适合您的 isolevel.这些点将成为您在此单元格内的表面.

但是如何细分这个单元格/表面?

如果你看着triTable[3],你的脸上应该会露出微笑:)

在评论中的残留困惑声明之后添加:;-)

Marching Cubes 的作用:想象一下,你有一个黑暗的房间,里面有一个点光源.它是标量强度值的体积光强度场的中心.您可以转到点 (x,y,z) 并测量那里的强度,例如3 坎德拉.

您现在想要通过具有特定光强度的所有点来渲染表面.你可以想象这个等值面看起来像一个围绕点光源的球体.这就是我们希望 Marching 立方体为我们提供的东西.

现在遍历房间中的所有点并将每个点标记为具有大致 iso 值的顶点,这在算法上将非常复杂,并且会导致大量顶点.然后我们必须以某种方式镶嵌.

所以:First Marching 立方体将整个体积分解成大小相同的立方体.如果底层数据具有某种底层离散性,则使用其倍数.我不会讨论另一种情况,因为这种情况很少见.比如我们在一个2mx5mx5m的房间里放了一个密度为1mm的网格

我们使用 5mmx5mmx5mm 的立方体.通过它们运行应该会便宜得多.

您现在可以想象,一些立方体的边缘与等值面相交.这些是有趣的.此代码用于识别它们:

cubeindex = 0;如果 (grid.val[0] 

如果cubeindex 保持为零,则该特定立方体不会与等值面相交.如果cubeindex > 0 你现在知道等值面穿过这个立方体并且您想要渲染其中的等值面部分.

请在脑海中想象一下.看http://en.wikipedia.org/wiki/Marching_cubes有关相交立方体的示例.

您可以轻松获得的顶点是立方体边缘的顶点.只需在 2 个角点之间线性插值即可找到位置等值并在那里放置一个顶点.但是哪些边是相交的???这就是 edgeTable[cubeindex] 中的信息.那是包含所有 ifs 的大段代码,用于存储插值点作为 xyz 点数组中的顶点:vertlist[].这篇文章是这样写的:

<前>获取位域 = edgeTable[cubeindex]如果在位域中标记了边 1(位域中的位 1 设置为 1)vertlist[0] = 插值点,在边 1 的某处... 等等.

您现在有一个充满顶点的数组,但如何将它们连接到三角形?这是 tritable 提供的信息.

剩下的就和我上面解释的差不多了.

如果还有问题,请具体说明是哪一段代码给你带来了麻烦.

i currently writing a program to implement Marching Cube using C++ and Opengl.

However, my best reference is only from http://local.wasp.uwa.edu.au/~pbourke/geometry/polygonise/

in the web, the provided codes are written in C.
my problem here is that i don't understand the triTable and edgeTable
and how they are related.

can anyone help me on the explanation or guide me on converting the algorithm into codes?

解决方案

These Tables are used for finding out how to tesselate the surface:

The first table gives you the necessary edges to interpolate. The second table gives you the way you have to tesselate, meaning, which triangles you have to make inside the cube.

A little example:

let's assume, vertex one and 2 are below the iso level, the cubeindex should be 3.

The whole intersection should look like a wedge.

If you think about it, you have to interpolate values on the edges: 0 and 9 , and 2 and 10. If you enter this into a bitfield, each bit corresponding to "is edge intersected?" you would end up with something like this:

10 9 8 7 6 5 4 3 2 1  edge
 1 1 0 0 0 0 1 0 1 0  intersected?

wouldn't you?

Which is exactly the value from edgeTable[3] in binary ;) 0x30A = 1100001010

Now you can write a function that linearly interpolates the points on those edges to fit your isolevel. These points will become your surface inside this cell.

But how to tesselate this cell/surface?

if you look into triTable[3] a smile should creep over your face :)

Addit after statement of residual puzzlement in comment: ;-)

What Marching Cubes does: Imagine you have a dark room with one point light source in it. It is the center of a volumetric light intensity field of scalar intensity values. You can go to point (x,y,z) and measure the intensity there, e.g. 3 candela.

You now want to render a surface through all points that have a certain light intensity. You can Imagine that this Isosurface would look like a sphere around the point light source. That is what we hope that Marching cubes will provide us with.

Now running through all points in the room and marking every point as a vertex that has roughly the iso value, will be algorithmically very complex and would result in a hughe number of vertices. Which we would then have to tesselate somehow.

So: First Marching cubes disects the whole volume into cubes of equal size. If the underlying data has some kind of underlying discreteness, multiples of that are used. I will not go into the other case, since that is rare. For instance we put a grid with the density of 1mm into a 2mx5mx5m room

We use cubes of 5mmx5mmx5mm. Running through them should be much cheaper.

You can imagine now, that the edges of some of the cubes intersect the isosurface. These are the interesting ones. This code identifies them:

cubeindex = 0;
   if (grid.val[0] 

if cubeindex stays zero, this particular cube is not intersected by the isosurface. If cubeindex is > 0 you now know that the isosurface goes through this cube and you want to render the piece of the isosurface that is inside it.

Please picture this in your mind. See http://en.wikipedia.org/wiki/Marching_cubes for examples of intersected cubes.

The vertices that you could get easily are those on the edges of the cube. Just interpolate linearly between 2 corner points to find the position of the isovalue and put a vertex there. But which edges are intersected??? That is the information in edgeTable[cubeindex]. That is the big piece of code with all the ifs, that stores the interpolated points as vertices in an array of xyz points: vertlist[]. This piece reads as follows:

get the bitfield = edgeTable[cubeindex]
 if edge 1 is marked in bitfield (bit 1 set to 1 in bitfield)
    vertlist[0] = interpolated point, somewhere on edge 1
... and so on.

You now have an array full of vertices, but how to connect them to triangles? That's an info that tritable provides.

The rest is pretty much what I explained above.

Well should there still be problems, please be specific about the piece of code that gives you trouble.

这篇关于行进立方体问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆