# Meshing the cow

As a simple example for applying stl-files I took "cow" out of MMA example data. I'm able to discretize the Graphic without problems

kuh = ExampleData[{"Geometry3D", "Cow"}]
mesh=DiscretizeGraphics[kuh,MeshCellStyle -> {{1, All} -> Red}] (* MeshRegion *)


to get an stl-like triangle surface, which seems to be ok

ConstantRegionQ[mesh]
(*True*)


for further meshing, but my attempt to create a volumemesh fails

Needs["NDSolveFEM"]
ToElementMesh[RegionBoundary[mesh]]
(*$Failed*)  What's wrong with my attempt? Thanks! • Just drop the RegionBoundary and it should work. – Pinti Mar 7 at 11:02 • Unfortunately no: ToElementMesh[mesh] (*$Failed*) – Ulrich Neumann Mar 7 at 11:11
• Did you know that you can just do ExampleData[{"Geometry3D", "Cow"}, "MeshRegion"]? – J. M. will be back soon Mar 7 at 11:21
• @ Piniti Thanks, it seems to be a problem of MMA version 11.0.1 – Ulrich Neumann Mar 7 at 11:23
• However, FindMeshDefects[ExampleData[{"Geometry3D", "Cow"}, "MeshRegion"]] shows that a conversion to a volume mesh might not be straightforward. – J. M. will be back soon Mar 7 at 11:23

The cow mesh is an example of a "broken" mesh. Try

mesh =  RepairMesh[mesh]


before sending it to ToElementMesh.

Among other nice meshes, you can find a free and "clean" cow mesh also on Keenan Crane's homepage:

https://www.cs.cmu.edu/~kmcrane/Projects/ModelRepository/

This is the model (without texture):

• Thanks, but nothing changes: meshR = RepairMesh[mesh ]; ToElementMesh[meshR] (*\$Failed*) – Ulrich Neumann Mar 7 at 11:34
• @Ulrich, running FindMeshDefects[meshR] should show what may be causing the failure. – J. M. will be back soon Mar 7 at 11:37
• Apparently version 11.3 can cope both with the unrepaired and the repaired mesh. So I don't know what to do. The mesh has self-intersections so tet-meshing it is nontrivial. – Henrik Schumacher Mar 7 at 11:39
• Obviously the example isn't as simple as I hoped for. Thank you Henrik and J.M. – Ulrich Neumann Mar 7 at 11:41
• @Ulrich By the way, a good and clean mesh is the "Triceratops". – Henrik Schumacher Mar 7 at 11:44

As other's have stated, the issue is self intersecting facets:

mr = RepairMesh[ExampleData[{"Geometry3D", "Cow"}, "MeshRegion"]];

FindMeshDefects[mr]


If we could determine if a point is 'inside' the cow, we could use a naive variant of the powercrust algorithm. Here 'inside' is not necessarily well defined.

Luckily we can use isInside defined specifically for this model here!

dm = DelaunayMesh[MeshCoordinates[mr]];

powercrust = BoundaryMesh @ MeshRegion[
MeshCoordinates[dm],
Pick[MeshCells[dm, 3], isInside /@ PropertyValue[{dm, 3}, MeshCellCentroid]]
];

Needs["NDSolveFEM"]

ToElementMesh[powercrust]

ElementMesh[{{-0.410816, 0.410816}, {-0.133851, 0.133851}, {-0.251619, 0.251619}}, {TetrahedronElement["<" 25368 ">"]}]