exploring vertices of a TopoDS_Face

I need to iterate over the vertices of a TopoDS_Face in clockwise order and I am using the following code to do that.

TopoDS_Face face = ...;

for(TopExp_Explorer expVert(*face, TopAbs_VERTEX); expVert.More(); expVert.Next())
{
TopoDS_Vertex vert = TopoDS::Vertex(expVert.Current());
// process the vertex
// ...
}

I am finding that the vertices do not appear in the order of the edges. Also, each vertex appears twice. For example,
if I have a square with the following vertices:
v1 = (0, 0, 0)
v2 = (1, 0, 0)
v3 = (1, 1, 0)
v4 = (0, 1, 0)

The vertices do not appear in the order (v1, v2, v3, v4) as I would expect. Does anyone know the correct way of iterating over the vertices of a TopoDS_Face?

thanks,
-vivek

Udo's picture

Hi Vivek,

as I understand the TopExp_Explorer, it breaks down the topology in its elements. That means it first takes the edges of a face and then iterates through the vertices in this edge. As each vertex belongs to two edges (if they are connected in this vertex), it appears twice.
I think you should try to use BRepTools_Wire_Explorer and call CurrentVertex().

Regards,

Udo

Vivek's picture

Hi Udo,

Thanks a lot for the hint. It worked....but now I am having trouble with the order of the vertices. I am using Orientation() of the wire to decide the correct order of the vertices but I still get wrong order for vertices of some faces.

thanks,

-vivek

Vivek's picture

If I check the Orientation() of the face then it works but not if I check the Orientation() of the wire. I am happy that it's woking but also uncomfortable because I don't know why it's working. Does anyone have any insights into what is really happening. I expect that a face and the underlying wire for that face should have the same Orientation() but they don't.

-vivek

Udo's picture

If you use the WireExplorer it will access the edges of the wire in theire order of connection. What the explorer returns depends on the way you build up your wire. You can connect the edges cw or ccw. However, I would expect the oriantation of the resulting face to change to the oposite direction. If you can post an example, I can try explain that in a better way.

Regards,

Udo

Trond's picture

I also have problem with the order of the vertices. In this example:

TopoDS_Solid theBox = BRepPrimAPI_MakeBox(200,60,60);

when I try to explore the edges of the faces, I get the following result:
2
--------->
ª |
| |3
|1 |
| «
--------->
4

How do I extract the vertices of the face in the right order?

regards,
Trond

Trond's picture

Sorry, it didn't take the special characters.
The Edges are like this (in 2D):
1) (0,0) to (0,60)
2) (0,60) to (60,60)
3) (60,60) to (60,0)
4) (0,0) to (60,0)

Why does not the 4th edge go from (60,0) to (0,0)?

Jahfer's picture

Hi Vivek,

I am a new to this field.

How to find the vertices from "TopoDS_Vertex". Can you give some code for doing this?

Hoping a reply soon.

TIA,

Ragards,
Jahfer

Robert W.'s picture

Hi, i am having the exact same problem, the order of vertices in a wire does not seem to make any sense to me. I am using TopExp_Explorer to get the vertives out of a wire. Even tried to get Edges first, but still the same result. Any ideas? I can provide an example as soon as i am again at work.