I am currently working on understanding and implementing the Marching Cubes algorithm using C ++, creating a sample of data in OpenGL.
I ran into a problem when the grid I create skips triangles. I see almost half of the missing triangles, which can be seen below.
Will filling triangles and creating squares be the right approach to solving the problem, or will I miss something obvious?
The edge intersection table I used has the following link:
http://paulbourke.net/geometry/polygonise/
Instead of using an array of boundary flag from 12-bit entries, I have 12 if statements (2 of which are shown). I use an index in a 3D array to determine x, y, z values ββbased on edge values ββ(0-11)
if ((edge.point1 == 0 && edge.point2 == 1) ||
(edge.point1 == 1 && edge.point2 == 0))
{
p1.x = x; p1.y = y; p1.z = z;
p2.x = x+1; p2.y = y; p2.z = z;
}
else if ((edge.point1 == 1 && edge.point2 == 2) ||
(edge.point1 == 2 && edge.point2 == 1))
{
p1.x = x+1; p1.y = y; p1.z = z;
p2.x = x+1; p2.y = y+1; p2.z = z;
}
In addition, the interpolation function is below.
point interpolate(point p1, point p2, unsigned char isovalue)
{
point p;
unsigned char d1 = getDataValue(p1.x, p1.y, p1.z);
unsigned char d2 = getDataValue(p2.x, p2.y, p2.z);
if (abs(double(isovalue)-double(d1)) == 0)
return(p1);
if (abs(double(isovalue)-double(d2)) == 0)
return(p2);
if (abs(double(d1)-double(d2)) == 0)
return(p1);
double val = double(isovalue - d1) / double(d2 - d1);
p.x = p1.x + val * (p2.x - p1.x);
p.y = p1.y + val * (p2.y - p1.y);
p.z = p1.z + val * (p2.z - p1.z);
return p;
}


UPDATE:
After searching for an example, I changed my code and was able to display all the triangles. Now I see a problem when, when the object is rotated, the object begins to invert the z axis and displays the object inside out.
Why does the object begin to invert z values ββduring rotation?
