Daniel
Daniel

Reputation: 6842

Marching Cubes (C++ to C#)

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.

Upvotes: 0

Views: 760

Answers (2)

Felice Pollano
Felice Pollano

Reputation: 33252

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>()

Upvotes: 2

Chefire
Chefire

Reputation: 139

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.

Upvotes: 1

Related Questions