I'm trying to combine several adjacent solids into a compound with shared faces. The best way I've found to do this so far is to cut each object out of the combination of all the objects. This way, Cut will create multiple solids that share their faces. However, one of the cases where Cut does NOT create shared faces is when two boxes share a face. If one box is slightly larger or smaller than the other, then cutting works fine, but if the adjacent faces are the same size, then cut will not remove the duplicate face. Running BRepAlgoAPI_Check on the resulting compound contains BOPAlgo_SelfIntersect statuses, and if I open the brep file in Gmsh, I can see two surfaces between the boxes instead of one. How can I get BRepAlgoAPI_Cut to more consistently find the shared faces? If that's not possible, how can I remove the duplicate surface myself after running the Cut?
//Create the boxes double factor = 1; // 0.99999 or 1.000001 work double boxSize = 0.5; TopoDS_Shape box1 = BRepPrimAPI_MakeBox(gp_Pnt(-boxSize*factor,-boxSize*factor,0),gp_Pnt(boxSize*factor,boxSize*factor,boxSize)); TopoDS_Shape box2 = BRepPrimAPI_MakeBox(gp_Pnt(-boxSize,-boxSize,-boxSize),gp_Pnt(boxSize,boxSize,0)); //Cut the objects so they share their faces TopoDS_Shape block = BRepAlgoAPI_Fuse(box1,box2); box1 = BRepAlgoAPI_Cut(block,box2); box2 = BRepAlgoAPI_Cut(block,box1); //Create the compound TopoDS_Compound compound; BRep_Builder solidBuilder; solidBuilder.MakeCompound(compound); solidBuilder.Add(compound,box1); solidBuilder.Add(compound,box2); BRepAlgoAPI_Check check(compound); std::cout << "Valid: " << check.IsValid() << std::endl; //This returns false because of BOPAlgo_SelfIntersect BRepTools::Write(compound,"example.brep");