Vertices connection

I am going to detect the connected vertices in a model. The connection relation is determined by the edges. Now, I have already had the map of vertices, but I don't know how to extend one vertice to another vertice so that they serve as two endpoints of an edge. Is there someone knowing some class in OCC?

Rob Bachrach's picture

From your question, I am not sure how much information you have. In any case, you can create a map of vertices to the edges they connect with:

TopTools_IndexedDataMapOfShapeListOfShape mapVertexEdge;
TopExp::MapShapesAndAncestors(myShape, TopAbs_VERTEX, TopAbs_EDGE, mapVertexEdge);

I don't believe there is a CASCADE function to get a list of the
connectivity between edges. I use the following:

TopTools_IndexedDataMapOfShapeListOfShape mapEdgeEdge;
// create an empty list of edges
TopTools_ListOfShape listEdge;

// visit the edges in the geometry shape
TopExp_Explorer exEdge;
for (exEdge.Init(myShape, TopAbs_EDGE); exEdge.More(); exEdge.Next()) {
const TopoDS_Shape &edge = exEdge.Current();

// visit the vertexes on this edge
TopExp_Explorer exVertex;
for (exVertex.Init(edge, TopAbs_VERTEX);
exVertex.More(); exVertex.Next()) {
const TopoDS_Shape &vertex = exVertex.Current();

// get the list of edges attached to this vertex
const TopTools_ListOfShape &listAtt = mapVertexEdge.FindFromKey(vertex);

// loop through the edge list
TopTools_ListIteratorOfListOfShape itEdge;
for (itEdge.Initialize(listAtt); itEdge.More(); itEdge.Next()) {
// if (not the current edge) add it to the list
if (itEdge.Value() != edge) {
// first, make sure it is not already in the list
TopTools_ListIteratorOfListOfShape itCheck;
for (itCheck.Initialize(listEdge); itCheck.More(); itCheck.Next()) {
if (itCheck.Value() == itEdge.Value()) break;
}
if (!itCheck.More()) listEdge.Append(itEdge.Value());
}
}
}
// store the list for this face
mapEdgeEdge.Add(edge, listEdge);

// clear the list for the next iteration
listEdge.Clear();
}

Ming's picture

Hi,Rob
Thank you very much for the info you provided, with which I can implement what I need easily.

jelle's picture

How about this? Perhaps this call wasnt available in earlier versions of OCC?

ipdb> TopExp().FirstVertex(edg)

Out[0]: >
ipdb> TopExp().LastVertex(edg)

Out[0]: >