Marching cubes是做什么的?
是一种重建算法。
Marching cubes uses a divide-and-conquer approach to locate the surface in a logical cube created from eight pixels; four each from two adjacent slices.
具体步骤?
将一个3D几何体划分为若干个小正方体的组成(体素化)。
判断每一个体素的顶点是否在3D几何体内。
通过体素顶点可以进行重建。
2D版本叫Marching Squares.
下面以marching squares为例进行描述。
将上述2D图形分成grid(与三位cube相对应)
可以得到每一个grid四个顶点的状态,红色是在体内,蓝色是在几何体外。
通过连接中线近似即可重建出图形。
在存储方面,可以按照栅格顶点的状态进行分类。
所以上面图形的第一行可以存储为:00231000
3D版本叫Marching cubes
算法步骤:
1. Read four slices into memory.
2. Scan two slices and create a cube from four neighbors on one slice and four neighbors on the next slice.
3. Calculate an index for the cube by comparing the eight density values at the cube vertices with the surface constant.
4. Using the index, look up the list of edges from a precalculated table.
5. Using the densities at each edge vertex, find the surface-edge intersection via linear interpolation.
6. Calculate a unit normal at each cube vertex using central differences. Interpolate the normal to each triangle vertex.
7. Output the triangle vertices and vertex normal.
顶点值高于等值在表面的内部,等于等值在表面上,低于等值在表面外。
每个顶点有两种状态,总共有256种,可以制作一个查找表(look up table)
但由于反转状态不变,所以可以减少一半,为128种。
再根据旋转不变形,又可以减少到14种情况。
可以认为这14中类似于基,经过旋转,反转可以得到256种状态对应的结果。