Help:How to auto detect broken edges in one shape and fix them

As is shown in the attached jpg.
When I import a shape, one edge is divided into several parts by some reason. Can I detect and connect them into one by some occ functions automatically? (the example attached is simple but it may be a complex model)
For example, a rectangle is usually constructed by 4 edges. But sometimes one of them is divided to 3 edges. Then the edge number is 6 instead of 4. What I want to do is auto detect those 3 edges and connect them into 1.

Mikhail Sazonov's picture

Try the algorithm ShapeUpgrade_UnifySameDomain.

leo lei's picture

Hi. I tried this with AllowInternalEdges(false). But it still dose not work.

leo lei's picture

Can Opencascade remove vertexes or edges (lile BRepAlgoAPI_Defeaturing, only can remove faces)?
I can now detect useless vertexes and edges. I tried to remove edges by BRepTools_ReShape. But Remove() function only takes away the edges instead of reshaping the whole shape after taking away them. The result is a face with a broken wire.

gkv311 n's picture

Can Opencascade remove vertexes or edges (lile BRepAlgoAPI_Defeaturing, only can remove faces)?

What do you mean by "useless vertexes and edges"? If their removal makes shape invalid, then they aren't useless. If you expect to merge two Faces defined on different geometric surfaces into a single TopoDS_Face, then this operation could be done only by generating a new (approximated) surface with new boundaries. OCCT doesn't provide such operation, though tools like GeomPlate may be used to generate an approximated surface.

leo lei's picture

Hi, I think you misunderstand the issue. There is only one face (for simple). Take the rectangle as an example. Generally, a rectangle is composed by 1 wire. And this wire has 4 edges. But sometimes 1 edge is broken to several edges. Then this rectangle can have edges more than 4.
And what I want to do is merge those "useless" edges and make this rectangle only have 4 edges again.
"If their removal makes shape invalid, then they aren't useless." this could be right. Because I rebuild the wire. And use BRepTools_ReShape to replace the old wire(more than 4 edges) with new one(4 edges). The new wire is replaced successfully into the face. But the face is not work. It dosent show the right topology in the visualize tool "TInspector".

Mikhail Sazonov's picture

If you want to replace an edge in a face you should provide the new edge with p-curve on that face, otherwise the shape will be invalid.

The tool ShapeUpgrade_UnifySameDomain can automatically merge smoothly connected edges. You may need to turn on ConcatBSplines parameter that is false by default.

leo lei's picture

Awesome reply! I change the ConcatBSplines to be true but still remain the same result. If the reason is the P-curve of this edge is needed for this face? (Test model attached)

Attachments: 
Mikhail Sazonov's picture

I have tried unifying this face with different parameters. Nothing works, the edges are not merged. It is needed to go deep into debugging the algorithm.

You may need to add a bug in mantis for this problem. May be some day the team will take and solve it.

leo lei's picture

Thank you for the help. I will report if I find a solution or someone else can solve it.

leo lei's picture

When I replace the wire of the face, it becomes invalid. How I can do it right?

zhangchao321_1's picture

The problem was not solved now