Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ MeshEditor changes/improvements


DMesh3 changes
- invalid/degenerate tris no longer assert in InsertTriangle/AppendTriangle
- invalid/degenerate tris no longer assert in InsertTriangle/AppendTriangle

MeshMeasurements changes
- added Volume and Area for simple requests
64 changes: 64 additions & 0 deletions mesh/MeshMeasurements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,70 @@ public static Vector2d VolumeArea( DMesh3 mesh, IEnumerable<int> triangles,



/// <summary>
/// Compute volume and surface area of triangles of mesh.
/// Return value is (volume,area)
/// Note that if triangles don't define closed region, volume is probably nonsense...
/// </summary>
public static Vector2d VolumeArea(DMesh3 mesh)
{
double mass_integral = 0.0;
double area_sum = 0;
foreach (int tid in mesh.TriangleIndices())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triangle3d tri;
foreach(int tid in mesh.TriangleIndices())
{
    mesh.GetTriVerticies(tid, out tri);
....

{
mesh.GetTriVertices(tid, out Triangle3d tri);
Vector3d N = (tri.V1 - tri.V0).Cross(tri.V2 - tri.V0);

area_sum += 0.5 * N.Length;
mass_integral += N.x * (tri.V0.x + tri.V1.x + tri.V2.x);
}

return new Vector2d(mass_integral * (1.0 / 6.0), area_sum);
}



/// <summary>
/// Compute entire volume of mesh.
/// Return value is volume
/// Note that if triangles don't define closed region, volume is probably nonsense...
/// </summary>
public static double Volume(DMesh3 mesh)
{
double mass_integral = 0.0;

foreach (int tid in mesh.TriangleIndices())
{
mesh.GetTriVertices(tid, out Triangle3d tri);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triangle3d tri;
foreach(int tid in mesh.TriangleIndices())
{
    mesh.GetTriVerticies(tid, out tri);
....

Vector3d N = (tri.V1 - tri.V0).Cross(tri.V2 - tri.V0);
mass_integral += N.x * (tri.V0.x + tri.V1.x + tri.V2.x);
}

return mass_integral * (1.0 / 6.0);
}



/// <summary>
/// Compute surface area of triangles of mesh.
/// Return value is area
/// Note that if triangles don't define closed region, volume is probably nonsense...
/// </summary>
public static double Area(DMesh3 mesh)
{
double area_sum = 0;
foreach (int tid in mesh.TriangleIndices())
{
mesh.GetTriVertices(tid, out Triangle3d tri);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be more efficient to have the out reference Triangle3d tri declared before the for loop so it's not created in each loop?

Triangle3d tri;
foreach(int tid in mesh.TriangleIndices())
{
    mesh.GetTriVerticies(tid, out tri);
....

Vector3d N = (tri.V1 - tri.V0).Cross(tri.V2 - tri.V0);
area_sum += 0.5 * N.Length;
}

return area_sum;
}



/// <summary>
/// Compute area of one-ring of mesh vertex by summing triangle areas.
/// If bDisjoint = true, we multiple each triangle area by 1/3
Expand Down