Merge circular wires of multiple edges into one edge

I have imported a STEP file into result that has some circular wires made up of multiple edges instead of a single edge. I'd like a way to replace all of these with single edges. I can detect them fine by exploring all the wires and querying if they're made up of only GeomAbs_Circle but more than one of them with the same center point. I'm trying to use ShapeBuild_ReShape to replace the wire with a wire with only one edge, but it doesn't seem to be replacing them, in the viewer I can still select only part of the circle when in edge mode.

Here's a snippet of the relevant the code below, I'm also displaying the center of the all the circular wires on the viewer, but that part is working fine.

  ShapeBuild_ReShape reshape;
  TopExp_Explorer explorer(result, TopAbs_WIRE);
  while (explorer.More()) {
    BRepTools_WireExplorer wire(TopoDS::Wire(explorer.Current()));
    std::vector<BRepAdaptor_Curve> edges;
    while (wire.More()) {
      edges.push_back(BRepAdaptor_Curve(TopoDS::Edge(wire.Current())));
      wire.Next();
    }
    if (std::all_of(edges.begin(), edges.end(), [&](BRepAdaptor_Curve i) {
          return (i.GetType() == GeomAbs_Circle &&
                  i.Circle().Location().IsEqual(edges[0].Circle().Location(),
                                                1e-6));
        })) {
      if (edges.size() != 1) {
        gp_Circ replacement_circle =
            gp_Circ(edges[0].Circle().Position(), edges[0].Circle().Radius());
        reshape.Replace(explorer.Current(),
                        BRepBuilderAPI_MakeWire(
                            BRepBuilderAPI_MakeEdge(replacement_circle)));
        reshape.Apply(result);
      }
      TopoDS_Vertex vertex =
          BRepBuilderAPI_MakeVertex(edges[0].Circle().Location());
      Handle(AIS_Shape) ais_vertex = new AIS_Shape(vertex);
      occ_viewer_->getContext()->Display(ais_vertex, false);
    }
    explorer.Next();
  }
Mike Molinari's picture

This is not a direct link to any C++ code but the the DRAW test harness implements a command called fixsmalledges. It also has another command fixshape that handles some other things also.

https://dev.opencascade.org/doc/overview/html/occt_user_guides__test_harness.html#:~:text=fixsmalledges%20%3Cresult%3E%20%3Cshape%3E%20%5B%3Ctoler%3E%20%3Cmode%3E%20%3Cmaxangle%3E%5D

There is another command that might be of interest. The unifysamedom command will take a body and merge faces that have the same underlying surface if they are touching. It can also clean up small edges and merge edges that can be represented by a single entity.

See file \occt\occt.git-qt\src\SWDRAW\SWDRAW_ShapeUpgrade.cxx for the code related to these commands.

Damian Crosby's picture

Thanks! ShapeUpgrade_UnifySameDomainseemed to do the trick.