How to get the resulting Wire (or Edges) after BRepAlgoAPI_Fuse on Wires for 2D case?

Hello. There are 2 intersecting Wires (2 circles) lying in the same plane. How to get the result of combining them?

BRepAlgoAPI_Fuse.Shape() returns an object with all Edges separated by intersection points. But how to get only external (in this case) Edges / Wire?

Attachments: 
Kirill Gavrilov's picture

Fusing a pair of TopoDS_Wire makes no sense in OCCT world. Until TopoDS_Wire defines boundaries for some TopoDS_Face - it is nothing but a list of connected Edges.

I'm not sure if OCCT provides a dedicated API for Boolean operations in 2D space, but it is possible to accomplish fuse operation on two TopoDS_Face instances lying on the same plane. The result will be, however, not a single Face, but a Compound of three Faces sharing common boundaries (see yellow edges on screenshot below)! Internal Edges will be shared between Faces, so that they could be classified in some way.

Maybe there is a simpler way to accomplish your task in OCCT...

pload MODELING VISUALIZATION
pcylinder p1 50 100
pcylinder p2 70 100
ttranslate p2 50 0 0
explode p1 F
explode p2 F
top
donly p1_2 p2_2
fit
bfuse r p1_2 p2_2
donly r
whatis r

sewing rr r

const TopoDS_Shape theShape;
TopTools_ListOfShape aFreeEdges;

TopTools_IndexedDataMapOfShapeListOfShape anEdgeMap;
TopExp::MapShapesAndAncestors (theShape, TopAbs_EDGE, TopAbs_FACE, anEdgeMap);
for (TopTools_IndexedDataMapOfShapeListOfShape::Iterator anEdgeIter (anEdgeMap);
     anEdgeIter.More(); anEdgeIter.Next())
{
  const TopoDS_Edge& anEdge = TopoDS::Edge (anEdgeIter.Key());
  const Standard_Integer aNbNeighbours = anEdgeIter.Value().Extent();
  if (aNbNeighbours == 1)
  {
    aFreeEdges.Append (anEdge);
  }
}

// work with aFreeEdges
W W's picture

Thanks. So aFreeEdges will contain green edges? How about Cut operation?

What does sewing do? I mean what is the equivalent of these commands in C++ code?

    top
    donly p1_2 p2_2
    fit
    bfuse r p1_2 p2_2
    donly r
    whatis r

    sewing rr r

After Fuse on two faces (BRepBuilderAPI_MakeFace, BRep_Builder.Add(face, wire)) TopExp_Explorer returns two faces, not three. Do I need to create a Face bounded by Wire in a different way?

Kirill Gavrilov's picture

W W wrote:

What does sewing do?

"sewing" calls BRepBuilderAPI_Sewing, which makes TopoDS_Shell from Compound of Faces. This is not necessary in this particular case - just called it to verify that Faces produced by Boolean operation indeed share common boundaries. You can find source code of Draw Harness commands by grepping "sewing" (in quotes) in OCCT source code folder "src" or by using getsourcefile command in Draw Harness console.

> pload ALL
> getsourcefile sewing
sewing               src/BRepTest/BRepTest_SurfaceCommands.cxx
TopExp_Explorer returns two faces, not three.

The Wire should define a properly connected, oriented and closed boundary to define a proper valid Face. You may share your shapes (BRepTools::Write()) to see if there is something special in them.