13
$\begingroup$

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!

$\endgroup$
7
  • $\begingroup$ Just drop the RegionBoundary and it should work. $\endgroup$
    – Pinti
    Commented Mar 7, 2019 at 11:02
  • $\begingroup$ Unfortunately no: ToElementMesh[mesh] (*$Failed*) $\endgroup$ Commented Mar 7, 2019 at 11:11
  • 1
    $\begingroup$ Did you know that you can just do ExampleData[{"Geometry3D", "Cow"}, "MeshRegion"]? $\endgroup$ Commented Mar 7, 2019 at 11:21
  • 1
    $\begingroup$ @ Piniti Thanks, it seems to be a problem of MMA version 11.0.1 $\endgroup$ Commented Mar 7, 2019 at 11:23
  • 1
    $\begingroup$ However, FindMeshDefects[ExampleData[{"Geometry3D", "Cow"}, "MeshRegion"]] shows that a conversion to a volume mesh might not be straightforward. $\endgroup$ Commented Mar 7, 2019 at 11:23

2 Answers 2

12
$\begingroup$

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

$\endgroup$
6
  • $\begingroup$ Thanks, but nothing changes: meshR = RepairMesh[mesh ]; ToElementMesh[meshR] (*$Failed*) $\endgroup$ Commented Mar 7, 2019 at 11:34
  • 2
    $\begingroup$ @Ulrich, running FindMeshDefects[meshR] should show what may be causing the failure. $\endgroup$ Commented Mar 7, 2019 at 11:37
  • $\begingroup$ 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. $\endgroup$ Commented Mar 7, 2019 at 11:39
  • $\begingroup$ Obviously the example isn't as simple as I hoped for. Thank you Henrik and J.M. $\endgroup$ Commented Mar 7, 2019 at 11:41
  • 1
    $\begingroup$ @Ulrich By the way, a good and clean mesh is the "Triceratops". $\endgroup$ Commented Mar 7, 2019 at 11:44
8
$\begingroup$

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 ">"]}]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.