Wed, 05/17/2023 - 09:51
I'm trying to understand topological structures of OpenCASCADE, and have a problem with a simple cylinder, as created and exported from FreeCAD.
As far as I understand, face / loop / edge / coedge of other geometric kernels are named Face / Wire / TEdge / Edge in OCCT, with a minor exception that several 3D edges can be represented with a single TEdge but with different translations.
The sample cylinder has one seam edge, so it should have 3 edges (line + 2 circles), and 4 coedges in 1 loop (linear edge used both directions). The coedges A, B, C, D are show on the attached image: the direction is chosen so that the face is on the left of it when moving along a coedge (looking from outside solid). The correct order of coedges in the loop is A, C, B, D, or any of its circular shifts. In particular, the coedges C and D (linear ones) cannot be adjacent in the loop, because then A and B need to connect with each other, and they have no common vertex.
I load the solid from .brep file format, then call ShapeUpgrade_RemoveLocations to remove TEdge sharing, then use TopoDS_Iterator on the face, and TopoDS_Iterator on its only wire. I indeed see 4 Edges in Wire, which refer to 3 distinct TEdges. However, the first two Edges in the Wire share the same TEdge, meaning that they are C and D, which cannot be adjacent in a correct loop.
Then I decided to look at the .brep file (attached). It contains:
- 1 Ve: I guess the second vertex is the translated version of this vertex.
- 2 Ed: I guess one circular edge is translated version of the other one.
- There is a Wi with the following children:
+9 0 -9 0 -8 0 +8 2 *
.
The wire has 4 edges in it. The first two edges 9 are used in opposite directions and have same translation, so these must be linear edges C and D. The last two edges 8 are used with different translations, so these must be circular edges A and B. So inspecting the file confirms that C and D are adjacent to each other in a wire, meaning that loop order is incorrect.
What do I do wrong? Does OCCT guarantee that order of Edges in a Wire is correct, i.e. start of the next Edge is the same Vertex as the end of the last Edge? Is there a way to get all loops with such conventions?
Wed, 05/17/2023 - 18:34
The order of edges returned by TopoDS_Iterator has no any sense. To get the right order use BRepTools_WireExplorer.
Wed, 05/17/2023 - 20:43
Yes, BRepTools_WireExplorer fixes the problem of adjacent linear Edges.
Now I only need to understand where to get proper orientation from. It seems that WireExplorer returns Edges which have proper orientation flag imbued inside them, so I should ignore BRepTools_WireExplorer::Orientation method and take Orientation from the Edge.
Thank you!