Reputation: 3
I'm using HelixToolkit's ModelImporter class(Helix 3D Toolkit is a collection of custom controls and helper classes for WPF.) for loading 3D objects from STL files (STereoLithography is a file format native to the stereolithography CAD software created by 3D Systems). The 3D models contain ModelGroup3D object with one or several GeometryModel3D objects inside depending on how many parts the model is comprised from. I would like to calculate the volume of the whole 3D model. I searched for similar questions and the only one answered was this one Calculate volume of 3D mesh which I'm not sure how to reform for my solution. Since I'm a newbie any help is greatly appreciated.
Additionally the models I'm loading are all closed meshes.
Thanks
Upvotes: 0
Views: 2398
Reputation: 726
The easyest way is computing the Gaussian flux of all triangles. for the "theory" if your surface is closed then imagine that a vector filed is running through it, then what comes in is equal to what comes out and is also equal to the volume inclosed. for the calculus details check "Gauss theorem" and Green-ostrogradsky integrals.
to compute it:
Vertex v1 ;
Vertex v2 ;
Vertex v3 ;
for (int i = 0;i< triangles.Count; i++)
{
v1 = triangles[i].P0;
v2 = triangles[i].P1;
v3 = triangles[i].P2;
Mesh.volume += (((v2.Y - v1.Y) * (v3.Z - v1.Z) - (v2.Z - v1.Z) * (v3.Y - v1.Y)) * (v1.X + v2.X + v3.X)) / 6;
}
If you have any question don't hesitate, i can develop how you get to that function. Have fun.
Upvotes: 0
Reputation: 78538
First convert the surface mesh into a volume mesh. For example, you can convert the triangulated surface mesh into a tetrahedral mesh. One way to do this by constructing the constrained Delaunay triangulation of the surface triangles.
Next, you can get a good estimate of the volume enclosed by the surface mesh, by summing the volumes of all the elements in the volume mesh. For example, by summing the volumes of all the tetrahedrons in the mesh.
Upvotes: 2