C++ Marching Cubes Algorithm Explanation
I am trying to implement the marching cubes algorithm in C++ based on this description:
http://paulbourke.net/geometry/polygonise/
But i don't understand how do you calculate the "GRIDCELL" values. To be exact the
double val[8];
part is not clear for me what it does. I looked at some examples but they are too complex and it's hard to understand how these values are computed.
typedef struct {
XYZ p[8];
double val[8];
} GRIDCELL;
As i understand XYZ p[8]; are the vertex coordinates for the cube. But what val[8]; is? Also can you please explain how to calculate them?
Thanks!
The marching cubes algorithm is -- as explained in the linked description -- an algorithm to build a polygonal representation from sampled data. The
double val[8];
are the samples for the 8 vertices of the cube. So they are not computed they are measurements from eg MRI scans. So the algorithm is the other way around: take a set of measured numbers and construct a surface representation for visualization from it.
I did small research and now i fully understand the algorithm.
First off all:
I wasn't aware of this, but now i am.
This value simply represents the isosurface. Or in other words the density.
double val[8];
To simplify: from -1.0 to 0.0 the voxel maybe solid or not solid.
For iso values ah perlin/simplex noise can be used for example.
Te val is the level of "charge" for each vertex of the cell, it depends of the tipe of shape that you want to creae. fe: if you want to made a ball you can sample the values with the formula:
for (int l = 0; l < 8; ++l){
float distance = sqrtf(pow(cell.p[l].x - chargepos.x, 2.0) + pow(cell.p[l].y - chargepos.y, 2.0) + pow(cell.p[l].z - chargepos.z, 2.0));
cell.val[l] = chargevalue /pow(distance, 2.0);}
链接地址: http://www.djcxy.com/p/6350.html
上一篇: 行进多维数据集问题