Commit 81fb1e0216dd1990d27c67d8b60f8e93409d18ea

Authored by Pavel Govyadinov
1 parent 6eb102f5

rewrote the selection of individual fibers

Showing 1 changed file with 75 additions and 18 deletions   Show diff stats
@@ -23,6 +23,37 @@ from subgraph_shaders import vert_s, frag_s, vs_s, fs_s @@ -23,6 +23,37 @@ from subgraph_shaders import vert_s, frag_s, vs_s, fs_s
23 23
24 DEBUG = False 24 DEBUG = False
25 25
  26 +#class storing the path. a vertex in the path is defined as a vertex idx
  27 +#and a list of all vertices required to reach the next point in the path
  28 +class path_point:
  29 + #Init an empty vertex with no path
  30 + def __init__(self, idx):
  31 + self.idx = idx
  32 + self.v_path = []
  33 + self.e_path = []
  34 +
  35 + #Remove all future path vertices attached to this vertex
  36 + def clear_path(self):
  37 + self.v_path = []
  38 + self.e_path = []
  39 +
  40 + # == comparison operator
  41 + def __eq__(self, other):
  42 + if self.idx == other.idx:
  43 + return True
  44 + else:
  45 + return False
  46 + # != comparison operator
  47 + def __ne__(self, other):
  48 + if self.idx != other.idx:
  49 + return True
  50 + else:
  51 + return False
  52 +
  53 + def __str__(self):
  54 + print("PathPoint[", self.idx, "], Chain = [", self.v_path, "]")
  55 +
  56 +
26 #The graph canvas class that 57 #The graph canvas class that
27 class GraphCanvas(scene.SceneCanvas): 58 class GraphCanvas(scene.SceneCanvas):
28 59
@@ -1096,19 +1127,31 @@ class GraphCanvas(scene.SceneCanvas): @@ -1096,19 +1127,31 @@ class GraphCanvas(scene.SceneCanvas):
1096 Generates paths our of consecutive paths out of the selected vertices. 1127 Generates paths our of consecutive paths out of the selected vertices.
1097 """ 1128 """
1098 def on_mouse_double_click(self, event): 1129 def on_mouse_double_click(self, event):
  1130 +
  1131 + #Method to update the vertex buffer of the nodes in the graph view
1099 def update_vbo(self): 1132 def update_vbo(self):
1100 self.vbo = gloo.VertexBuffer(self.data) 1133 self.vbo = gloo.VertexBuffer(self.data)
1101 self.program.bind(self.vbo) 1134 self.program.bind(self.vbo)
1102 self.update() 1135 self.update()
1103 1136
  1137 + #updates the path structure of the class
  1138 + #source and target are of type "source" defined in this class.
1104 def add_to_path(self, source, target): 1139 def add_to_path(self, source, target):
1105 - 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"])  
1106 - for v in vl:  
1107 - if(int(v) not in self.path):  
1108 - self.G.vertex_properties["selection"][v] = 2.0  
1109 - self.data['a_selection'][int(v)] = 2.0  
1110 - if(int(v) not in self.full_path):  
1111 - self.full_path.append(int(v)) 1140 + 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"])
  1141 + for v in range(1, len(vl)-1):
  1142 + if (self.G.vertex_properties["selection"][vl[v]] != 1.0):
  1143 + self.G.vertex_properties["selection"][vl[v]] = 2.0
  1144 + self.data['a_selection'][int(vl[v])] = 2.0
  1145 + source.v_path.append(int(vl[v]))
  1146 + for e in el:
  1147 + source.e_path.append(e)
  1148 +
  1149 +
  1150 + def remove_from_path(self, source):
  1151 + for v in source.v_path:
  1152 + self.G.vertex_properties["selection"][self.G.vertex(v)] = 0.0
  1153 + self.data['a_selection'][v] = 0.0
  1154 + source.clear_path()
1112 1155
1113 if (event.button == 1): 1156 if (event.button == 1):
1114 if(self.view[0][0] > 0.0010): 1157 if(self.view[0][0] > 0.0010):
@@ -1119,32 +1162,46 @@ class GraphCanvas(scene.SceneCanvas): @@ -1119,32 +1162,46 @@ class GraphCanvas(scene.SceneCanvas):
1119 #if it is, select that node and turn the pathing variable on. 1162 #if it is, select that node and turn the pathing variable on.
1120 self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 1163 self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0
1121 self.pathing = True 1164 self.pathing = True
1122 - if(c_id not in self.path):  
1123 - self.path.append(c_id)  
1124 - self.data['a_selection'][c_id] = 1.0  
1125 - update_vbo(self) 1165 + self.path.append(path_point(c_id))
  1166 + self.data['a_selection'][c_id] = 1.0
  1167 + update_vbo(self)
1126 print("I turned on the first node") 1168 print("I turned on the first node")
1127 else: 1169 else:
  1170 + #If the node is selected already, unselect it and remove from path the last occurance in the path
1128 if(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 1.0): 1171 if(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 1.0):
1129 self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 0.0 1172 self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 0.0
1130 - self.path.remove(c_id)  
1131 self.data['a_selection'][c_id] = 0.0 1173 self.data['a_selection'][c_id] = 0.0
1132 - update_vbo(self) 1174 + s_id = self.path.index(path_point(c_id))
  1175 + if(s_id == 0):
  1176 + remove_from_path(self, self.path[s_id])
  1177 + else:
  1178 + remove_from_path(self, self.path[s_id-1])
  1179 + remove_from_path(self, self.path[s_id])
  1180 + self.path.remove(path_point(c_id))
  1181 + #self.data['a_selection'][c_id] = 0.0
  1182 + #update_vbo(self)
1133 print("I turned off a node") 1183 print("I turned off a node")
1134 elif(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 0.0): 1184 elif(self.G.vertex_properties["selection"][self.G.vertex(c_id)] == 0.0):
1135 self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0 1185 self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0
1136 - if(c_id not in self.path):  
1137 - self.path.append(c_id) 1186 + #if the source is not in the path add it
  1187 + if(path_point(c_id) not in self.path):
  1188 + self.path.append(path_point(c_id))
  1189 + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0
  1190 + self.data['a_selection'][c_id] = 1.0
  1191 + #if the source is not LAST in the path, add it.
  1192 + elif(self.path[len(self.path)-1] != path_point(c_id)):
  1193 + self.path.append(path_point(c_id))
  1194 + self.G.vertex_properties["selection"][self.G.vertex(c_id)] = 1.0
1138 self.data['a_selection'][c_id] = 1.0 1195 self.data['a_selection'][c_id] = 1.0
1139 - update_vbo(self)  
1140 print("I turned on a node") 1196 print("I turned on a node")
1141 - if(len(self.path) >= 2): 1197 + if(len(self.path) >= 1):
1142 for i in range(len(self.path)-1): 1198 for i in range(len(self.path)-1):
1143 add_to_path(self, self.path[i], self.path[i+1]) 1199 add_to_path(self, self.path[i], self.path[i+1])
1144 - update_vbo(self) 1200 + update_vbo(self)
1145 #THIS IS WHERE I LEFT IT OFF. 1201 #THIS IS WHERE I LEFT IT OFF.
1146 if(np.sum(self.G.vertex_properties["selection"].get_array()) == 0): 1202 if(np.sum(self.G.vertex_properties["selection"].get_array()) == 0):
1147 self.pathing = False 1203 self.pathing = False
  1204 + update_vbo(self)
1148 1205
1149 1206
1150 1207