Keep the edge indices as they were, after deleting vertices?


#1

I am working on a network with leaf vertices, at one point I remove the leaves. This leads to the automatic removal of their corresponding edges and the rearrangement of the edge indices. Is there a way to keep the indices for the rest of the edges as they were before the vertex removal?


#2

can you give a visual example of what the result is now, before/after?


#3

before:

after:


#4

ha okay, now i understand.

there are no real edge indices. what is displayed is just the order (and corresponding “index”) in which the edges are looped over. nothing really changed in the data structure.

if you would like to be able to refer to the edges by an index or to the display the same indices in the drawing, use a map:

import compas
from compas.datastructures import Network
from compas.plotters import NetworkPlotter

network = Network.from_obj(compas.get('lines.obj'))

plotter = NetworkPlotter(network)

uv_index = {uv: index for index, uv in enumerate(network.edges())}

# do some deleting

plotter.draw_edges(text={uv: str(uv_index[uv]) for uv in network.edges()})
plotter.show()

let me know if that is not what you meant…

best,
tom


#5

Thanks for the response. I already had a mapping dict. For some reason, I got confused and thought that the indices for edges are like keys for vertices!