Significant Bug in ShapeAnalysis_FreeBounds::ConnectEdgesToWires

All,
ShapeAnalysis_Freebounds::ConnectEdgesToWires fails to work properly on some shapes. Here is some code and output to demonstrate the failure. Has anyone else found this problem and if so did they find a work around?

//On entry to the code below, Shape is a Compound containing a single Solid.

//Collect all the edges of the section. These are not returned in any particular order.
Handle(TopTools_HSequenceOfShape) Edges = new TopTools_HSequenceOfShape();
for (TopExp_Explorer Ex(Shape,TopAbs_EDGE); Ex.More(); Ex.Next())
Edges->Append(TopoDS::Edge(Ex.Current()));

//Example Operation 1: Generate wires from the edges and determined the nature of the underlying curves.
Handle(TopTools_HSequenceOfShape) Wires = new TopTools_HSequenceOfShape(); //Will hold the wires found
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(Edges,Precision::Confusion(),Standard_False,Wires); //Wonderful tool?
for(int w=1; wLength();w++)
{ //For each wire
TopoDS_Wire Wire = TopoDS::Wire(Wires->Value(w));
if(Wire.Closed())
TRACE(" Wire %ld is Closed\n",w);
else
TRACE(" Wire %ld is Open\n",w);
{
int e = 0;
for(BRepTools_WireExplorer aWireExp(TopoDS::Wire(Wires->Value(w))); aWireExp.More(); aWireExp.Next())
{ //For each edge in wire. Note that BRepTools_WireExplorer returns edges in order!
TopoDS_Edge aEdge = TopoDS::Edge(aWireExp.Current());
//Analysis of Edge
Standard_Real First, Last;
Handle(Geom_Curve) curve = BRep_Tool::Curve(aEdge,First,Last); //Extract the curve from the edge
GeomAdaptor_Curve aAdaptedCurve(curve);
GeomAbs_CurveType curveType = aAdaptedCurve.GetType();
gp_Pnt pnt1, pnt2;
aAdaptedCurve.D0(First,pnt1);
aAdaptedCurve.D0(Last,pnt2);
int nPoles = 2;
if (curveType == GeomAbs_BezierCurve || curveType == GeomAbs_BSplineCurve)
nPoles = aAdaptedCurve.NbPoles();
TRACE("%ld\t%ld\t%ld\t%ld\t%ld\t%f\t%f\t%f\t%f\t%f\t%f\n",w,e,curveType,aEdge.Orientation(),nPoles,
pnt1.X(),pnt1.Y(),pnt1.Z(),pnt2.X(),pnt2.Y(),pnt2.Z());
e++;
}

}

}

Wire 1 is Closed
Wire Edge Type Oriet Poles x1 y1 z1 x2 y2 z2
1 0 6 0 101 412.485388 -0.000002 2.999994 415.395805 -0.000002 2.999994
1 1 6 0 101 415.395805 -0.000002 2.999994 425.449971 -20.902084 2.999994
1 2 6 0 101 425.449971 -20.902084 2.999994 449.527053 0.529165 2.999994
1 3 6 0 101 449.527053 0.529165 2.999994 459.052053 0.529165 2.999994
1 4 6 0 101 459.052053 0.529165 2.999994 459.052053 -47.624999 2.999994
1 5 6 0 101 459.052053 -47.624999 2.999994 435.504137 -47.889583 2.999994
1 6 6 0 101 435.504137 -47.889583 2.999994 435.504137 -63.235415 2.999994
1 7 6 0 101 435.504137 -63.235415 2.999994 420.952055 -56.885416 2.999994
1 8 6 0 101 420.952055 -56.885416 2.999994 348.720808 -60.854165 2.999994
1 9 6 0 101 348.720808 -60.854165 2.999994 -175.154164 -76.993748 2.999994
1 10 6 0 101 -175.154164 -76.993748 2.999994 -242.093744 -49.477083 2.999994
1 11 6 0 101 -242.093744 -49.477083 2.999994 -262.995826 -24.606251 2.999994
1 12 6 0 101 -262.995826 -24.606251 2.999994 -268.816659 -18.520834 2.999994
1 13 6 0 101 -268.816659 -18.520834 2.999994 -268.816659 -13.493751 2.999994
1 14 6 0 101 -268.816659 -13.493751 2.999994 -243.416653 -13.493751 2.999994
1 15 6 0 101 -243.416653 -13.493765 2.999994 -218.545821 -13.493764 2.999994
Wire 2 is Open
2 0 6 0 101 -218.545821 -13.493764 2.999994 -222.249987 -23.812513 2.999994
2 1 6 0 101 -222.249987 -23.812513 2.999994 -173.302073 -23.812510 2.999994
2 2 6 0 101 -173.302073 -23.812510 2.999994 -176.212490 -13.229178 2.999994
2 3 6 0 101 -176.212490 -13.229178 2.999994 -149.224991 -13.229176 2.999994
2 4 6 0 101 -149.224991 -13.229176 2.999994 -149.224992 -0.000002 2.999994
2 5 6 0 101 -149.224993 -0.000002 2.999994 -112.183334 -0.000002 2.999994
2 6 6 0 101 -112.183334 -0.000002 2.999994 -112.183334 -23.283334 2.999994
2 7 6 0 101 -112.183334 -23.283334 2.999994 -108.214584 -28.575000 2.999994
2 8 6 0 101 -108.214584 -28.575000 2.999994 -60.589587 -28.575000 2.999994
2 9 6 0 101 -60.589587 -28.575000 2.999994 -56.091670 -23.812501 2.999994
2 10 6 0 101 -56.091670 -23.812501 2.999994 -56.091670 -0.000002 2.999994
2 11 6 0 101 -56.091670 -0.000002 2.999994 0.000000 -0.000002 2.999994
2 12 6 0 101 0.000000 -0.000002 2.999994 0.000001 -16.668749 2.999994
2 13 6 0 101 0.000001 -16.668749 2.999994 102.658329 -16.668742 2.999994
2 14 6 0 101 102.658329 -16.668742 2.999994 102.658328 -0.000002 2.999994
2 15 6 0 101 102.658328 -0.000002 2.999994 148.431243 -0.000002 2.999994
2 16 6 0 101 148.431242 -0.000002 2.999994 148.431243 -16.668739 2.999994
2 17 6 0 101 148.431243 -16.668739 2.999994 322.791651 -16.404144 2.999994
2 18 6 0 101 322.791651 -16.404144 2.999994 327.818733 -8.731228 2.999994
2 19 6 0 101 327.818733 -8.731228 2.999994 323.849983 -0.264562 2.999994
2 20 6 0 101 323.849983 -0.264562 2.999994 322.262483 -0.264562 2.999994
2 21 6 0 101 322.262483 -0.264562 2.999994 322.262483 -0.000002 2.999994
2 22 6 0 101 322.262483 -0.000002 2.999994 398.727056 -0.000002 2.999994
2 23 6 0 101 398.727056 -0.000002 2.999994 398.727056 5.027110 2.999994
2 24 6 0 101 398.727055 5.027109 2.999994 406.399978 5.027110 2.999994
2 25 6 0 101 406.399978 5.027110 2.999994 406.399979 0.000027 2.999994
2 26 6 0 101 406.399979 0.000027 2.999994 412.485389 0.000027 2.999994

Clearly, the routine is failing badly. Wire 1 should not be closed and there is no reason the two wires shouldn't have been collapsed into a single wire that is closed.

Before I dig down into the guts of OCC, any deeper than I already have, has anybody found and perhaps fixed this problem before? Is this fixed in 6.3.1? I'm using 6.3.0.

Regards,
Tim

tmay's picture

I figured some one would want to know what the order of the original edges processed were so here is that data, along with the result produced:

Original Edges
0 6 0 101 -242.093744 -49.477083 2.999994 -262.995826 -24.606251 2.999994
1 6 0 101 -262.995826 -24.606251 2.999994 -268.816659 -18.520834 2.999994
2 6 0 101 -175.154164 -76.993748 2.999994 -242.093744 -49.477083 2.999994
3 6 0 101 -268.816659 -18.520834 2.999994 -268.816659 -13.493751 2.999994
4 6 0 101 348.720808 -60.854165 2.999994 -175.154164 -76.993748 2.999994
5 6 0 101 420.952055 -56.885416 2.999994 348.720808 -60.854165 2.999994
6 6 0 101 435.504137 -63.235415 2.999994 420.952055 -56.885416 2.999994
7 6 0 101 435.504137 -47.889583 2.999994 435.504137 -63.235415 2.999994
8 6 0 101 459.052053 -47.624999 2.999994 435.504137 -47.889583 2.999994
9 6 0 101 459.052053 0.529165 2.999994 459.052053 -47.624999 2.999994
10 6 0 101 449.527053 0.529165 2.999994 459.052053 0.529165 2.999994
11 6 0 101 425.449971 -20.902084 2.999994 449.527053 0.529165 2.999994
12 6 0 101 415.395805 -0.000002 2.999994 425.449971 -20.902084 2.999994
13 6 0 101 412.485388 -0.000002 2.999994 415.395805 -0.000002 2.999994
14 6 0 101 406.399979 0.000027 2.999994 412.485389 0.000027 2.999994
15 6 0 101 406.399978 5.027110 2.999994 406.399979 0.000027 2.999994
16 6 0 101 398.727055 5.027109 2.999994 406.399978 5.027110 2.999994
17 6 0 101 398.727056 -0.000002 2.999994 398.727056 5.027110 2.999994
18 6 0 101 322.262483 -0.000002 2.999994 398.727056 -0.000002 2.999994
19 6 0 101 322.262483 -0.264562 2.999994 322.262483 -0.000002 2.999994
20 6 0 101 323.849983 -0.264562 2.999994 322.262483 -0.264562 2.999994
21 6 0 101 327.818733 -8.731228 2.999994 323.849983 -0.264562 2.999994
22 6 0 101 322.791651 -16.404144 2.999994 327.818733 -8.731228 2.999994
23 6 0 101 148.431243 -16.668739 2.999994 322.791651 -16.404144 2.999994
24 6 0 101 148.431242 -0.000002 2.999994 148.431243 -16.668739 2.999994
25 6 0 101 102.658328 -0.000002 2.999994 148.431243 -0.000002 2.999994
26 6 0 101 102.658329 -16.668742 2.999994 102.658328 -0.000002 2.999994
27 6 0 101 0.000001 -16.668749 2.999994 102.658329 -16.668742 2.999994
28 6 0 101 0.000000 -0.000002 2.999994 0.000001 -16.668749 2.999994
29 6 0 101 -56.091670 -0.000002 2.999994 0.000000 -0.000002 2.999994
30 6 0 101 -56.091670 -23.812501 2.999994 -56.091670 -0.000002 2.999994
31 6 0 101 -60.589587 -28.575000 2.999994 -56.091670 -23.812501 2.999994
32 6 0 101 -108.214584 -28.575000 2.999994 -60.589587 -28.575000 2.999994
33 6 0 101 -112.183334 -23.283334 2.999994 -108.214584 -28.575000 2.999994
34 6 0 101 -112.183334 -0.000002 2.999994 -112.183334 -23.283334 2.999994
35 6 0 101 -149.224993 -0.000002 2.999994 -112.183334 -0.000002 2.999994
36 6 0 101 -149.224991 -13.229176 2.999994 -149.224992 -0.000002 2.999994
37 6 0 101 -176.212490 -13.229178 2.999994 -149.224991 -13.229176 2.999994
38 6 0 101 -173.302073 -23.812510 2.999994 -176.212490 -13.229178 2.999994
39 6 0 101 -222.249987 -23.812513 2.999994 -173.302073 -23.812510 2.999994
40 6 0 101 -218.545821 -13.493764 2.999994 -222.249987 -23.812513 2.999994
41 6 0 101 -243.416653 -13.493765 2.999994 -218.545821 -13.493764 2.999994
42 6 0 101 -268.816659 -13.493751 2.999994 -243.416653 -13.493751 2.999994
Output from ConnectEdgesToWires:
Wire 1 is Closed
1 0 6 0 101 412.485388 -0.000002 2.999994 415.395805 -0.000002 2.999994
1 1 6 0 101 415.395805 -0.000002 2.999994 425.449971 -20.902084 2.999994
1 2 6 0 101 425.449971 -20.902084 2.999994 449.527053 0.529165 2.999994
1 3 6 0 101 449.527053 0.529165 2.999994 459.052053 0.529165 2.999994
1 4 6 0 101 459.052053 0.529165 2.999994 459.052053 -47.624999 2.999994
1 5 6 0 101 459.052053 -47.624999 2.999994 435.504137 -47.889583 2.999994
1 6 6 0 101 435.504137 -47.889583 2.999994 435.504137 -63.235415 2.999994
1 7 6 0 101 435.504137 -63.235415 2.999994 420.952055 -56.885416 2.999994
1 8 6 0 101 420.952055 -56.885416 2.999994 348.720808 -60.854165 2.999994
1 9 6 0 101 348.720808 -60.854165 2.999994 -175.154164 -76.993748 2.999994
1 10 6 0 101 -175.154164 -76.993748 2.999994 -242.093744 -49.477083 2.999994
1 11 6 0 101 -242.093744 -49.477083 2.999994 -262.995826 -24.606251 2.999994
1 12 6 0 101 -262.995826 -24.606251 2.999994 -268.816659 -18.520834 2.999994
1 13 6 0 101 -268.816659 -18.520834 2.999994 -268.816659 -13.493751 2.999994
1 14 6 0 101 -268.816659 -13.493751 2.999994 -243.416653 -13.493751 2.999994
1 15 6 0 101 -243.416653 -13.493765 2.999994 -218.545821 -13.493764 2.999994
Wire 2 is Open
2 0 6 0 101 -218.545821 -13.493764 2.999994 -222.249987 -23.812513 2.999994
2 1 6 0 101 -222.249987 -23.812513 2.999994 -173.302073 -23.812510 2.999994
2 2 6 0 101 -173.302073 -23.812510 2.999994 -176.212490 -13.229178 2.999994
2 3 6 0 101 -176.212490 -13.229178 2.999994 -149.224991 -13.229176 2.999994
2 4 6 0 101 -149.224991 -13.229176 2.999994 -149.224992 -0.000002 2.999994
2 5 6 0 101 -149.224993 -0.000002 2.999994 -112.183334 -0.000002 2.999994
2 6 6 0 101 -112.183334 -0.000002 2.999994 -112.183334 -23.283334 2.999994
2 7 6 0 101 -112.183334 -23.283334 2.999994 -108.214584 -28.575000 2.999994
2 8 6 0 101 -108.214584 -28.575000 2.999994 -60.589587 -28.575000 2.999994
2 9 6 0 101 -60.589587 -28.575000 2.999994 -56.091670 -23.812501 2.999994
2 10 6 0 101 -56.091670 -23.812501 2.999994 -56.091670 -0.000002 2.999994
2 11 6 0 101 -56.091670 -0.000002 2.999994 0.000000 -0.000002 2.999994
2 12 6 0 101 0.000000 -0.000002 2.999994 0.000001 -16.668749 2.999994
2 13 6 0 101 0.000001 -16.668749 2.999994 102.658329 -16.668742 2.999994
2 14 6 0 101 102.658329 -16.668742 2.999994 102.658328 -0.000002 2.999994
2 15 6 0 101 102.658328 -0.000002 2.999994 148.431243 -0.000002 2.999994
2 16 6 0 101 148.431242 -0.000002 2.999994 148.431243 -16.668739 2.999994
2 17 6 0 101 148.431243 -16.668739 2.999994 322.791651 -16.404144 2.999994
2 18 6 0 101 322.791651 -16.404144 2.999994 327.818733 -8.731228 2.999994
2 19 6 0 101 327.818733 -8.731228 2.999994 323.849983 -0.264562 2.999994
2 20 6 0 101 323.849983 -0.264562 2.999994 322.262483 -0.264562 2.999994
2 21 6 0 101 322.262483 -0.264562 2.999994 322.262483 -0.000002 2.999994
2 22 6 0 101 322.262483 -0.000002 2.999994 398.727056 -0.000002 2.999994
2 23 6 0 101 398.727056 -0.000002 2.999994 398.727056 5.027110 2.999994
2 24 6 0 101 398.727055 5.027109 2.999994 406.399978 5.027110 2.999994
2 25 6 0 101 406.399978 5.027110 2.999994 406.399979 0.000027 2.999994
2 26 6 0 101 406.399979 0.000027 2.999994 412.485389 0.000027 2.999994

BTW, I have run this routine with various tolerence settings. The problem seems insentive to the tolerence setting.
Tim