C++ – Implementing Marching Cube Algorithm

3dcopenglrendering

From My last question: Marching Cube Question

However, i am still unclear as in:

  1. how to create imaginary cube/voxel to check if a vertex is below the isosurface?
  2. how do i know which vertex is below the isosurface?
  3. how does each cube/voxel determines which cubeindex/surface to use?
  4. how draw surface using the data in triTable?

Let's say i have a point cloud data of an apple.
how do i proceed?

can anybody that are familiar with Marching Cube help me?
i only know C++ and opengl.(c is a little bit out of my hand)

Best Answer

First of all, the isosurface can be represented in two ways. One way is to have the isovalue and per-point scalars as a dataset from an external source. That's how MRI scans work. The second approach is to make an implicit function F() which takes a point/vertex as its parameter and returns a new scalar. Consider this function:

float computeScalar(const Vector3<float>& v)
{
    return std::sqrt(v.x*v.x + v.y*v.y + v.z*v.z);
}

Which would compute the distance from the point and to the origin for every point in your scalar field. If the isovalue is the radius, you just figured a way to represent a sphere. This is because |v| <= R is true for all points inside a sphere, or which lives on its interior. Just figure out which vertices are inside the sphere and which ones are on the outside. You want to use the less or greater-than operators because a volume divides the space in two. When you know which points in your cube are classified as inside and outside, you also know which edges the isosurface intersects. You can end up with everything from no triangles to five triangles. The position of the mesh vertices can be computed by interpolating across the intersected edges to find the actual intersection point.


If you want to represent say an apple with scalar fields, you would either need to get the source data set to plug in to your application, or use a pretty complex implicit function. I recommend getting simple geometric primitives like spheres and tori to work first, and then expand from there.

Related Topic