# Computing volume from marching cubes

This topic is 2477 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey graphics-gurus, I am using the marching cubes algorithm to construct an isosurface from a 3d field of data. I have the triangular facets, etc. all done, but now I need to compute the volume enclosed in the iso-surface. I can think of one way to do this: using the triangular facets and the vertices of the cube, I create several tetrahedra and then simply calculate the volume of each tet. However, I noticed that as the number of facets in each cube increases, it can become non-trivial to automate the creation of the tets. Could someone point me to a reference that describes the algorithm to automate this process? Or has anybody created a table of vertices for all combinations of tets that are possible corresponding to each of the 256 cases of the MC tritable? Or is there a more efficient way to compute the volume using the MC information? Will greatly appreciate any help!

##### Share on other sites
I've been looking into this recently. You may want to check out:

Llamas I. Real-time voxelization of triangle meshes on the GPU. SIGGRAPH '07: ACM SIGGRAPH 2007 sketches; 2007

The presentation is found at:
http://developer.nvidia.com/object/siggraph-2007.html

##### Share on other sites
If you already have the triangles, computing the volume is easy. Just loop over all your created triangles, and sum up the quantity dot(v0, cross(v1,v2)) where v0, v1, v2 are the vertices of your triangle.

##### Share on other sites
Quote:
 Original post by PragmaIf you already have the triangles, computing the volume is easy. Just loop over all your created triangles, and sum up the quantity dot(v0, cross(v1,v2)) where v0, v1, v2 are the vertices of your triangle.

Are there any limitations to the type of mesh one can use this on? e.g.: convex hulls only?

##### Share on other sites
Quote:
 Original post by PragmaIf you already have the triangles, computing the volume is easy. Just loop over all your created triangles, and sum up the quantity dot(v0, cross(v1,v2)) where v0, v1, v2 are the vertices of your triangle.

Does your approach work even if the isosurface does not enclose the origin? I guess the expression you have suggested is for determining the volume of tets with one vertex at the origin...

In my case, I can have several closed isosurfaces in one data field (say like several spheres distributed in space - except that the geometry need not be as simple as spheres). So the origin need not necessarily be enclosed within the isosurface.

##### Share on other sites
The mesh does not need to be convex, and it doesn't need to enclose the origin. To prove to yourself that this is true, try drawing some examples in 2D on paper. You'll see that sometimes dot(v0, cross(v1,v2)) is negative, but that when all contributions are added up the negative terms cancel with even larger positive terms.

The only requirement is that your mesh has to be closed and your triangles have to be consistently oriented. This should happen automatically with data from marching cubes.

EDIT: It should actually be dot(v0, cross(v1,v2)) / 6

[Edited by - Pragma on January 14, 2009 7:57:48 AM]

##### Share on other sites
Quote:
 Original post by PragmaThe mesh does not need to be convex, and it doesn't need to enclose the origin. To prove to yourself that this is true, try drawing some examples in 2D on paper. You'll see that sometimes dot(v0, cross(v1,v2)) is negative, but that when all contributions are added up the negative terms cancel with even larger positive terms.The only requirement is that your mesh has to be closed and your triangles have to be consistently oriented. This should happen automatically with data from marching cubes.EDIT: It should actually be dot(v0, cross(v1,v2)) / 6

Well, this is great. Thank you for this. I'll do some testing today and see how it flies. I am concerned with things like quaternion Julia sets, which have all kinds of interesting surface properties. If anything fails, this will be it. Should have the results within an hour or two.

##### Share on other sites
Yeah, I'm a bonehead! Took me a second to make the link with determinants... Thanks for pointing this out.

[Edited by - taby on January 14, 2009 1:43:56 PM]

##### Share on other sites
Quote:
 Original post by PragmaThe mesh does not need to be convex, and it doesn't need to enclose the origin. To prove to yourself that this is true, try drawing some examples in 2D on paper. You'll see that sometimes dot(v0, cross(v1,v2)) is negative, but that when all contributions are added up the negative terms cancel with even larger positive terms.The only requirement is that your mesh has to be closed and your triangles have to be consistently oriented. This should happen automatically with data from marching cubes.EDIT: It should actually be dot(v0, cross(v1,v2)) / 6

Thanks for clarifying this. However, I missed a detail in my original question that could complicate matters. The way my code works is I compute the volume corresponding to each closed isosurface at the level of the individual cells and then sum up the individual volumes by cycling through all the cells (this way it is just easier to run on parallel machines; each processor computes its portion of the volume. Furthermore, a closed isosurface may be shared by several processors.). In other words, if I take a marching cube, then I really need the volume formed by the intersection of the triangular facets with the cube. Once this is done, I store the contribution of each cube to the total volume in each cell (cube).

##### Share on other sites
Do you care about the volume contained in each cell? Or do you just need to know the total volume?

If it's the former then you'll need to use a different trick. But if it's the latter, you can compute dot(v0, cross(v1,v2)) / 6 for all the triangles in each cell and store them in the cell. Then you can add this up for all the cells. You can easily do this in parallel over multiple machines.

1. 1
2. 2
3. 3
Rutin
20
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• ### Forum Statistics

• Total Topics
633655
• Total Posts
3013175
×