Wrong result of wire.Closed()

Hi All,

To test whether a wire is closed, I use wire.Closed(). However, for a face bounded by a outer wire, this API return false, that means the wire is not closed, but that's not true. The face is imported from a step file. I am really confused about it.
Any suggestion is welcome. Thanks in advanced.

-Cauchy Ding

Roman Lygin's picture

Hi Cauchy Ding,

TopoDS_Shape::Closed() simply returns an internal flag that should be set by an algorithm constructing a shape.

Since STEP import uses Shape Healing it should take care of that, see for instance ShapeExtend_WireData::Wire() code
which is exploited inside Shape Healing to reconstruct wires after correction.

So your case may be potentially one when you see a geometrically closed wire, but internally bounding edges do not share
vertices (because in original STEP file they were not shared and distance between them is greater than a tolerance). You
can explore a topological structure and see if the vertices are really shared. The easiest way to check this
assumption is to save your wire in a .brep file and use Draw.

Draw> restore wire.brep w
Draw> dump w

and see if the 1st and the last edge have vertices in common.

Hope this helps.
Roman

---
opencascade.blogspot.com - blog on Open CASCADE

Divya's picture

Hi Roman,
I have a set of edges and need to find out which wires they belong to?
I used the following code but it breaks while taking the value from the sequence of shapes!!
can you please tell me where am I going wrong or is there any better way to do it?

Handle(TopTools_HSequenceOfShape) Wires = new TopTools_HSequenceOfShape();
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(Edges,1 ,false,Wires);
int p=Wires->Length();
for(int a=0;a<=p;a++)
{
TopoDS_Wire W;
W=TopoDS::Wire(Wires->Value(a)); //here
}

question2:how do I use shapeanalyser_wireorder() in order to sequence the edges?

Roman Lygin's picture

Hi Divya,

The code likely throws an exception as you are trying to access the 0-th element in the sequence while indexes are numbered from 1 to Lenght().

ShapeAnalysis_WireOrder is too internal class imho. If you just need to reorder edges, ShapeFix_Wire::FixReorder() should do the work for you. However, IIRC, ShapeAnalysis_FreeBounds() should already return correctly oriented wires. So make sure first if you really need reordering.

HTH
Roman
---
opencascade.blogspot.com - the Open CASCADE blog

Divya's picture

Hi Roman,

Thanks a lot!you were right!it worked when I changed it to 1!

Divya's picture

Hi Roman,

I grouped the edges into wires using the fuction Connectedgestowires(....),whereas the returned wires when traversed through do not return actual no of edges.ie there are a few edges missing!how do I fix it.Is there any function or method you can suggest?Please help!!

Roman Lygin's picture
Divya's picture

Hi Roman!

Few edges from the list of edges I got, do not share vertices at all.
Though it looks as if all the edges are connected(in the figure) and the wire is closed!Please help!

Divya's picture

Hi Roman!
What does tolerence in ConnectEdgestoWires() mean
what values can be given to it?please help!

Roman Lygin's picture

Hi Divya,

You seem to solve the problem, right ? As explained earlier (in a referred thread), you should set shared=true if you're sure edges share their vertices. If not, you should use shared=false and set a tolerance. The tolerance will be used to classify edges as belonging to one wire if distances between their vertices are less than tolerance.

Sharing is not exact coincidence, it's an explicit sharing of the same TopoDS_TShape - refer to Part 1 of the Topology series.

Roman
---
opencascade.blogspot.com - the Open CASCADE blog

Divya's picture

HI Roman!

I set the tolerance value and it still considers only edges which share their vertices!!though i set shared to false.

here is the code i'm using:

while (ex.More())
{
moe.Add(ex.Current());
Edges->Append(ex.Current));
ex.Next();
}
Handle(TopTools_HSequenceOfShape) Edges = new TopTools_HSequenceOfShape(); Handle(TopTools_HSequenceOfShape) Wires = new TopTools_HSequenceOfShape();
ShapeAnalysis_FreeBounds::ConnectEdgesToWires(Edges,0.1,Standard_False,Wires);

when i try to access edges from wires in Wires....not all edges are shown and a few of them are open.whereas the wires are closed in reality.

I tried using wireorder and i got status as '-1' some edges are reversed,no gap remains...what does this mean?

please help!
Thanks
Divya

Roman Lygin's picture

Divya,

ShapeAnalysis_WireOrder::Status() of -1 means that it could order and orient all the edges without any gap. So this must be fine for you, right ? Check what its NbChains() and Chain() return and see if this is OK.
You use of ConnectEdgesToWires() seems OK, I don't see where the problem is without your edges.

Roman
---
opencascade.blogspot.com - the Open CASCADE blog

Divya's picture

NbChains() and Chain()parameters all return '0'. What does this mean?

Divya's picture

i use BRepTools_WireExplorer which says :

If a wire is not closed returns only a segment of edges which
length depends on started in exploration edge. If wire has
singularities (for example, loops) WireExplorer can return not all
edges in a wire. it depends on type of singularity.
what is type of singularity?
The wires I obtain from ConnectEdgesToWires(,,,Wires) is a set of open,closed wires.
Is the problem because of this?? how else can I access edges from each wire in "Wires"?
please do reply!

Divya's picture

Hi Roman,

I figured that the function ConnectEdgesToWires() does not consider the tolerance value between the edges (when false).So,it is taking only those edges which have exact coinciding vertices and ignoring edges with tolerance.As a result all the edges with tolerance are being missed out in forming wires.hence,I get incomplete wires.

Thanks for the earlier replies.