Order a sequence of edges to make a wire

Hello, I have to create a wire adding a series of edges.

As I can read from the documentation of BRepBuilderAPI_MakeWire:

"to be added to a wire under construction, an edge (unless it is the first one) must satisfy the following condition: one of its vertices must be geometrically coincident with one of the vertices of the wire"

Someone can suggest me an efficient algorithm to create a wire from a not sorted sequence of edges?

Thanks.

Gerhard Hofmann's picture

Hi,
a simple way is ofcourse: start with a randomly choosen edge in your sequence (and start you sorted list with it), then find the edge with the lowest distance of its start or endpoint to the last edge in the sorted list and add the best edge (maybe you need to reverse the found edge).
This is not efficient when there are more than lets say 30 edges to check. If you have that many edges you would need a quadtree (2d) or an octtree (3d) to sort the egdes. As far as I know, there is no class/method that supports quadtrees or octtrees in opencascade.
best regards
Gerhard

Stephane Routelous's picture

hi,

what you can do is after calling the Add method of BrepBuilderAPI_MakeWire, test if the edge was added with the method IsDone.
if is IsDone returns false, and Error returns BRepBuilderAPI_DisconnectedWire, the edge is not connected to the already added ones.

in pseudo code :

listOfEdge loe = ....
listOfEdge tmpList;
BRepBuilderAPI_MakeWire mkWire;
while(loe.IsEmpty() == false )
{
tmpList.clear();
loop on loe
{
TopoDS_Edge currentEdge = loe.current();
mkWire.Add(currentEdge);
if ( mkWire.Error() != BRepBuilderAPI_WireDone)
{
tmpList.add(currentEdge);
}
}
loe = tmpList;

}

the code will work if you are sure all the edges are creating one and only one wire.

HTH,

Stephane

max_rome's picture

Thanks for your reply, your solution is great and I think I will use it.

Max