Query upward topological connections?

Apologies if this was answered before, but how can I query upward topological connectivity in OpenCascade (e.g. shells using a face, edges using a vertices).
I am able to use TopExp_Explorer successfully to query downward topological adjacencies but not upward ones

Kirill Gavrilov's picture

TopoDS_Shape lists only it's children, but not parent shapes. To figure out where shapes are used you still need to traverse in top-bottom direction. Tools like TopExp::MapShapesAndAncestors() might be helpful to collect this information for the given shape.

Rao Garimella's picture
Rao Garimella's picture

I tried this but the map is behaving weirdly. I have one object in the map. When I ask for the index of the map from prior knowledge it tells me the index is zero but when I ask for the object related to index 0, it gives me an OutOfRangeError - instead I have to send in index 1.

    face_solid_map = TopTools_IndexedDataMapOfShapeListOfShape()
    topexp.MapShapesAndAncestors(face, TopAbs_FACE, TopAbs_SOLID, face_solid_map)

    nfs = face_solid_map.Size()
    for i in range(nfs):
        print('face_solid_map.FindFromIndex(',i+1,') ',\
        face_solid_map.FindFromIndex(i+1))                   # ok

        print('face_solid_map.FindFromIndex(',i,')',\
        face_solid_map.FindFromIndex(i))                       # error

        print('face_solid_map.FindFromIndex(face_solid_map.FindIndex(solid)) ',\
        face_solid_map.FindFromIndex(face_solid_map.FindIndex(solid))      # error
Artem Zhidkov's picture
   topexp.MapShapesAndAncestors(face, TopAbs_FACE, TopAbs_SOLID, face_solid_map)

As I understood, you sent a face as an argument, but you try to obtain mapping of faces to upward solids. You will obtain correct result, if you push a solid (or a compound) instead of a single face.

As regards indexing, yes, OCCT containers starts indexing from 1 (Fortran hangover).

Rao Garimella's picture

What worked was this:

    solid_list = face_solid_map.FindFromKey(face)
    solid_list_iterator = TopTools_ListIteratorOfListOfShape(solid_list)
    f2s = []
    while solid_list_iterator.More():
        f2s.append(solid_list_iterator.Value())
        solid_list_iterator.Next()