# How to union 3D region to calculate volume?

I have a Teapot likes:

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


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

RegionDimension[region]


2

So I have to fill it into 3D.

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


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]


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

RegionUnion @@ boundmesh


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

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:

Needs["OpenCascadeLink"]
elms = com[[#]]["MakeRepresentation"["ElementMesh"]] & /@
Range[Length[com]];
shapes = OpenCascadeShape /@ elms;
Volume[BoundaryMeshRegion[bmesh]]

0.37979

• What a Magical Grammar....
– yode
Mar 15, 2022 at 12:46
• Funny, why does the same input gets a different result...
– yode
Mar 15, 2022 at 12:59
• @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? Mar 15, 2022 at 13:18
• 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
– yode
Mar 16, 2022 at 8:52
• @yode, I don't think you can. Why do you need this? Mar 16, 2022 at 9:06