From 81fb1e0216dd1990d27c67d8b60f8e93409d18ea Mon Sep 17 00:00:00 2001 From: Pavel Govyadinov Date: Thu, 8 Aug 2019 17:40:01 -0500 Subject: [PATCH] rewrote the selection of individual fibers --- GraphCanvas.py | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 18 deletions(-) diff --git a/GraphCanvas.py b/GraphCanvas.py index 9cf11af..f832d10 100644 --- a/GraphCanvas.py +++ b/GraphCanvas.py @@ -23,6 +23,37 @@ from subgraph_shaders import vert_s, frag_s, vs_s, fs_s DEBUG = False +#class storing the path. a vertex in the path is defined as a vertex idx +#and a list of all vertices required to reach the next point in the path +class path_point: + #Init an empty vertex with no path + def __init__(self, idx): + self.idx = idx + self.v_path = [] + self.e_path = [] + + #Remove all future path vertices attached to this vertex + def clear_path(self): + self.v_path = [] + self.e_path = [] + + # == comparison operator + def __eq__(self, other): + if self.idx == other.idx: + return True + else: + return False + # != comparison operator + def __ne__(self, other): + if self.idx != other.idx: + return True + else: + return False + + def __str__(self): + print("PathPoint[", self.idx, "], Chain = [", self.v_path, "]") + + #The graph canvas class that class GraphCanvas(scene.SceneCanvas): @@ -1096,19 +1127,31 @@ class GraphCanvas(scene.SceneCanvas): Generates paths our of consecutive paths out of the selected vertices. """ def on_mouse_double_click(self, event): + + #Method to update the vertex buffer of the nodes in the graph view def update_vbo(self): self.vbo = gloo.VertexBuffer(self.data) self.program.bind(self.vbo) self.update() + #updates the path structure of the class + #source and target are of type "source" defined in this class. def add_to_path(self, source, target): - vl, el = nwt.gt.graph_tool.topology.shortest_path(self.G, self.G.vertex(source), self.G.vertex(target), weights=self.G.edge_properties["av_radius"]) - for v in vl: - if(int(v) not in self.path): - self.G.vertex_properties["selection"][v] = 2.0 - self.data['a_selection'][int(v)] = 2.0 - if(int(v) not in self.full_path): - self.full_path.append(int(v)) + vl, el = nwt.gt.graph_tool.topology.shortest_path(self.G, self.G.vertex(source.idx), self.G.vertex(target.idx), weights=self.G.edge_properties["av_radius"]) + for v in range(1, len(vl)-1): + if (self.G.vertex_properties["selection"][vl[v]] != 1.0): + self.G.vertex_properties["selection"][vl[v]] = 2.0 + self.data['a_selection'][int(vl[v])] = 2.0 + source.v_path.append(int(vl[v])) + for e in el: + source.e_path.append(e) + + + def remove_from_path(self, source): + for v in source.v_path: + self.G.vertex_properties["selection"][self.G.vertex(v)] = 0.0 + self.data['a_selection'][v] = 0.0 + source.clear_path() if (event.button == 1): if(self.view[0][0] > 0.0010): @@ -1119,32 +1162,46 @@ class GraphCanvas(scene.SceneCanvas): #if it is, select that node and turn the pathing variable on. self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 self.pathing = True - if(c_id not in self.path): - self.path.append(c_id) - self.data['a_selection'][c_id] = 1.0 - update_vbo(self) + self.path.append(path_point(c_id)) + self.data['a_selection'][c_id] = 1.0 + update_vbo(self) print("I turned on the first node") else: + #If the node is selected already, unselect it and remove from path the last occurance in the path if(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 1.0): self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 0.0 - self.path.remove(c_id) self.data['a_selection'][c_id] = 0.0 - update_vbo(self) + s_id = self.path.index(path_point(c_id)) + if(s_id == 0): + remove_from_path(self, self.path[s_id]) + else: + remove_from_path(self, self.path[s_id-1]) + remove_from_path(self, self.path[s_id]) + self.path.remove(path_point(c_id)) + #self.data['a_selection'][c_id] = 0.0 + #update_vbo(self) print("I turned off a node") elif(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 0.0): self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 - if(c_id not in self.path): - self.path.append(c_id) + #if the source is not in the path add it + if(path_point(c_id) not in self.path): + self.path.append(path_point(c_id)) + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 + self.data['a_selection'][c_id] = 1.0 + #if the source is not LAST in the path, add it. + elif(self.path[len(self.path)-1] != path_point(c_id)): + self.path.append(path_point(c_id)) + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 self.data['a_selection'][c_id] = 1.0 - update_vbo(self) print("I turned on a node") - if(len(self.path) >= 2): + if(len(self.path) >= 1): for i in range(len(self.path)-1): add_to_path(self, self.path[i], self.path[i+1]) - update_vbo(self) + update_vbo(self) #THIS IS WHERE I LEFT IT OFF. if(np.sum(self.G.vertex_properties["selection"].get_array()) == 0): self.pathing = False + update_vbo(self) -- libgit2 0.21.4