Question

I am trying to implement marching cubes in C#, but I've come to a part where I don't understand the algorithm and I don't how to implement it.

int Polygonise(GRIDCELL grid, double isolevel, TRIANGLE *triangles)

The third argument I don't really understand. I know it's a pointer, but later on in the algo, when you set the triangles it appears as though the triangles variable is an array of the TRIANGLE struct:

int ntriang = 0;

for (int i=0; triTable[cubeindex,i]!=-1; i+=3) {
    triangles[ntriang].p[i  ] = vertlist[triTable[cubeindex,i  ]];
    triangles[ntriang].p[i+1] = vertlist[triTable[cubeindex,i+1]];
    triangles[ntriang].p[i+2] = vertlist[triTable[cubeindex,i+2]];
    ntriang++;
}

Notice the triangles[ntriang]. That doesn't make sense because before we set triangles to TRIANGLE *triangles. I also don't understand why It's a pointer.

Was it helpful?

Solution

The caller of Polygonize expects *triangles point to an allocated array long enough to contain all the triangles. The equivalent in c# can be a TRIANGLE[] or a List<TRIANGLE>()

OTHER TIPS

It looks like this function takes the GRID of voxels/cells and outputs the triangles. It is a pointer since you will get a list of triangles.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top