TopTools_IndexedDataMapOfShapeListOfShape ?

Can some one explain me ho to access its data. I see it is used by the TopExp::MapShapesAndAncestors, How do we know we accessed the sub-shapes or their ancestors ? I understand it used a TCollection_MapHasher (Which i don't understand neither) and a TCollection_List. But that's all i understand from it.... Thanks in advance Omar Msaaf

Maxim ZVEREV's picture

Hello!

TopTools_IndexedMapOfShapeListOfShape used with TopoDS_Shape as a key and TopTools_ListOfShape as a value. You can see methods in TCollection_IndexedDataMap.cdl to know how to access keys and values (For example, use method TCollection_IndexedDataMap.Contains(aKey) to know if there is key aKey presented in this map. MapHashers is used to make search in maps (which is organized as hash tables). And this class used to obtain hash codes from the objects which would be used as keys. Each of such objects must have its own hash code. You can see that TopoDS_Shape has a method ::HashCode. So, if you will need in future to store your own objects in maps you should write your own ::HashCode method which will be unique for each instance of your object(unless you will derive your classes from such classes in which ::HashCode already presented).

Method TopExp::MapShapeAndAncestors allows to have map with shapes as a key and list of its supershapes (ancestors) as a value. For example, you have Shell and you want to obtain all edges from this shell but also you want to know all faces which is attached to each edge. You can do this by using TopExp::MapShapesAndAncestors:

TopTools_IndexedDataMapOfShapeListOfShape aEdgeFaceMap;

TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aEdgeFaceMap);

//now we want to iterate it

Standard_Integer i, nE = aEdgeFaceMap.Extent();

for(i = 1; i <= nE; i++) {

const TopoDS_Edge& E = TopoDS::Edge(aEdgeFaceMap.FindKey(i));

//obtain list of all faces which is shared by this edge , i.e. neighboring faces

const TopTools_ListOfShape& aListOfFaces = aEdgeFaceMap.FindFromIndex(i);

//and you do something with faces

}

Note that in CAS.CADE there are several maps and you can find TCollection_IndexedDataMap and TCollection_DataMap, but they are the separate classes. For example, you can use index in iterating in IndexedDataMap (as in previous example), but you can not remove any item from such map unless the last one (or totally clear the map). In DataMap you can not use indexing in iterating and you should iterate such maps with help of dedicated iterator but you can remove items from the middle of the map.

Hope it will help you,

Best regards,

Maxim Zverev.

Msaaf Omar's picture

Thanks a lot Best regards. Omar Msaaf