Fuse is not merging shapes' faces

I would like to merge two cuboids such that their common faces also get merged. Currently, I am not able to get those common faces merged with the below code:

[code]
const TopoDS_Shape b1 = BRepPrimAPI_MakeBox(10, 10, 20);
const TopoDS_Shape b2 = BRepPrimAPI_MakeBox(gp_Pnt(5, 0, 0), 30, 30, 30);
const TopoDS_Shape fused = BRepAlgoAPI_Fuse(b1, b2);
[/code]

Please say how to do this.

Oliver R's picture

You could use TopExp_Explorer explore(*instance, TopAbs_FACE); to extract the faces from both objects and then fuse those. An alternative may be to compute the intersection (BRepAlgoAPI_Common) and sew the result with the fuse together (BRepBuilderAPI_Sewing). Hope this gives a starting point.

DKGH's picture

Thanks Oliver,

Kindly also include an example to illustrate for a beginner.

Oliver R's picture

The only code I have is the actual code I use. You can see that on github. https://github.com/WolframResearch/OpenCascadeLink/blob/master/OpenCasca... in that file look for the functions I mentioned in my answer.

Mikhail Sazonov's picture

It is not clear from your question what do you want to obtain. The result of fuse operation is one shell that contains faces from both arguments, some of which are splits of the original faces. This result is as on the below picture:

May be you want to get merged the result faces that occur to be located on the same plane? It is like on the following picture:

It that case all you need is just to simplify the result. For this you need to call the method SimplifyResult before getting the result:

const TopoDS_Shape b1 = BRepPrimAPI_MakeBox(10, 10, 20);
const TopoDS_Shape b2 = BRepPrimAPI_MakeBox(gp_Pnt(5, 0, 0), 30, 30, 30);
TopoDS_Shape fused;
BRepAlgoAPI_Fuse aFuse(b1, b2);
if (aFuse.IsDone())
{
  aFuse.SimplifyResult();
  fused = aFuse.Shape();
}
Attachments: 
DKGH's picture

Thank Makhail,

That was very helpful. Please feel free to answer here as well: https://stackoverflow.com/questions/73680243/getting-faces-to-merge-whil....