I have a Teapot likes:

region = RepairMesh[ExampleData[{"Geometry3D", "UtahTeapot"}, "MeshRegion"]]

enter image description here

I want to calculate the volume of it, but it just 2 dimension as this code:



So I have to fill it into 3D.

com = ConnectedMeshComponents[region];
boundmesh = BoundaryMeshRegion[MeshCoordinates[#], MeshCells[#, 2]] & /@ com
RegionDimension /@ boundmesh

enter image description here

Note that these sections have overlapping parts:

Show[RegionPlot3D[First[boundmesh], PlotStyle -> Directive[Opacity[0.4], Red]], 
 RegionPlot3D[#, PlotStyle -> Directive[Blue]] & /@ Rest[boundmesh], Boxed -> False]

enter image description here

So let's union it, but I get an error information:

RegionUnion @@ boundmesh

enter image description here

It is a bug? And how to union all parts to calculate the volume of this tea-pot?


1 Answer 1


You can use OpenCascadeLink for that. Convert the pieces you have into a boundary element mesh, convert those to OpenCascade, make the union and convert back:

elms = com[[#]]["MakeRepresentation"["ElementMesh"]] & /@ 
shapes = OpenCascadeShape /@ elms;
union = OpenCascadeShapeUnion[shapes];
bmesh = OpenCascadeShapeSurfaceMeshToBoundaryMesh[union];

  • 2
    $\begingroup$ What a Magical Grammar.... $\endgroup$
    – yode
    Mar 15, 2022 at 12:46
  • $\begingroup$ Funny, why does the same input gets a different result... $\endgroup$
    – yode
    Mar 15, 2022 at 12:59
  • $\begingroup$ @yode, I am not sure this is the same input. The boundary ElementMesh of region can not be converted to a BoundaryMeshRegion, because it's not a closed region - that's what you need the union in the first place, not? $\endgroup$
    – user21
    Mar 15, 2022 at 13:18
  • $\begingroup$ I would like to ask you an additional question if I don't use ConnectedMeshComponents to generate that com for you. Now you only have that region. Can you get the finally result by it? I've tried for a long time but I can't $\endgroup$
    – yode
    Mar 16, 2022 at 8:52
  • $\begingroup$ @yode, I don't think you can. Why do you need this? $\endgroup$
    – user21
    Mar 16, 2022 at 9:06

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.