13

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 *)

enter image description here

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["NDSolve`FEM`"]
ToElementMesh[RegionBoundary[mesh]]
(*$Failed*)

What's wrong with my attempt? Thanks!

user21
  • 39,710
  • 8
  • 110
  • 167
Ulrich Neumann
  • 53,729
  • 2
  • 23
  • 55

2 Answers2

12

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):

enter image description here

Henrik Schumacher
  • 106,770
  • 7
  • 179
  • 309
8

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["NDSolve`FEM`"]

ToElementMesh[powercrust]
ElementMesh[{{-0.410816, 0.410816}, {-0.133851, 0.133851}, {-0.251619, 0.251619}}, {TetrahedronElement["<" 25368 ">"]}]
Greg Hurst
  • 35,921
  • 1
  • 90
  • 136