Understanding PythonOCC - Retrieving some basic information with TopExp_Explorer

César

Looking around for some CAD
Hi to all.

I have written a small Python script that creates a simple 2D surface (square) and then loops over its constituent elements, namely faces, wires, edges and vertices, to retrieve some basic information. I would like to access (if possible) the following information:

- Face label: Meaning an index/number identifying the face. Is there such a thing?
- Face connectivity: Meaning the ordered list of vertices making up the face.
- Edge label: Same as face label
- Edge connectivity: Same as face connectivity
- Vertex label: Same as face label
- Vertex coordinates: The X-, Y- and Z-coodinates that define the vertex location in space.

I have tried to retrieve this information using the TopExp_Explorer class from the OCC.Core.TopExp package but cannot go beyond the pure shape abstraction. Attached you can find the Python script. Any feedback or comment would be immensly appreciated.

Great to find this community!

Cheers ;)
 

Attachments

  • exploreShape.txt
    2 KB · Views: 2

Quaoar

Administrator
Staff member
Hello @César and welcome to the forum.

I don't have PyOCC environment configured on my current laptop, so I can comment using C++ and you'll probably figure it out for Python.

Face label: Meaning an index/number identifying the face. Is there such a thing?

Face/edge/vertex indexation is usually done with TopExp::MapShapes() static function. E.g.:

Code:
TopTools_IndexedMapOfShape faceMap;
TopExp::MapShapes(shape, TopAbs_FACE, faceMap);
 
for (int f = 1; f <= faceMap.Extent(); f++)
{
  // `f` is your 1-based face index.
}

Face connectivity: Meaning the ordered list of vertices making up the face.

This is done like this:

Code:
TopTools_IndexedDataMapOfShapeListOfShape M;
TopExp::MapShapesAndAncestors(shape, TopAbs_VERTEX, TopAbs_FACE, M);

I.e., you build a child-parent relationship map, and you're free to specify the subshape type you want, e.g., vertices-to-faces (like in the snippet above), edges-to-faces, etc.

Vertex coordinates: The X-, Y- and Z-coodinates that define the vertex location in space.

To access geometry (point, curve, surface) from topology (vertex, edge, face), you should normally use BRep_Tool, e.g., for your specific question it would be:

Code:
gp_Pnt P = BRep_Tool::Pnt(vertex);
 
Top