opencascade

Getting faces to merge while merging shapes in OpenCASCADE


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:

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

Please say how to do this.


Solution

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

    Not simplified fuse result

    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:

    Simplified fuse result

    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();
    }