Blame view

GraphWidget.py 24.5 KB
9f9f1788   Pavel Govyadinov   clead up version ...
1
2
3
4
5
6
7
  #!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  """
  Created on Mon Aug  5 15:42:19 2019
  
  @author: pavel
  """
9f9f1788   Pavel Govyadinov   clead up version ...
8
  from GraphCanvas import GraphCanvas
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
9
10
  from HistogramWidget import HistogramWidget
  #from NodeInformationWidget import NodeInfoWidget
4407a915   Pavel Govyadinov   working with new ...
11
  from PyQt5 import QtCore, QtGui, QtWidgets
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
12
  from PyQt5.Qt import QRect
9f9f1788   Pavel Govyadinov   clead up version ...
13
  import network_dep as nwt
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
14
15
  from TubeWidget import TubeWidget
  from vispy.scene.visuals import Text
9f9f1788   Pavel Govyadinov   clead up version ...
16
  
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
17
18
  import numpy as np
  
6eb102f5   Pavel Govyadinov   Fixed issue cause...
19
  DEBUG = False
9f9f1788   Pavel Govyadinov   clead up version ...
20
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
  
  
  class NodeInfoWidget(QtWidgets.QWidget):
      def __init__(self, *args, **kwargs):
          QtWidgets.QWidget.__init__(self)
          self.layout = QtWidgets.QGridLayout()
          self.resize(900, 300)
          self.bar = None
          print("stuff 22")
          if 'hist' in kwargs: 
              print("stuff")
              self.bar = HistogramWidget()
              self.bar.canvas.create_native()
          self.fibers_mini = TubeWidget()
          self.fibers_mini.canvas.create_native()
  
          self.graph_mini1 = GraphWidget()
          self.graph_mini1.canvas.create_native()
          self.graph_mini2 = GraphWidget()
          self.graph_mini2.canvas.create_native()
          self.graph_mini3 = GraphWidget()
          self.graph_mini3.canvas.create_native()
          self.graph_mini4 = GraphWidget()
          self.graph_mini4.canvas.create_native()
   
  
         
          self.graph_mini1.connect(self.fibers_mini)
          self.fibers_mini.connect(self.graph_mini1)
          self.fibers_mini.connect(self.graph_mini2)
          self.fibers_mini.connect(self.graph_mini3)
          self.fibers_mini.connect(self.graph_mini4)
          
          
          self.layout.addWidget(self.graph_mini1.canvas.native, 0, 0, 1, 1)
          self.layout.addWidget(self.graph_mini2.canvas.native, 0, 1, 1, 1)
          self.layout.addWidget(self.graph_mini3.canvas.native, 1, 0, 1, 1)
          self.layout.addWidget(self.graph_mini4.canvas.native, 1, 1, 1, 1)
          #layout.addItem(vspacer, 0, 2, 2, 1)
          if self.bar == None:
              self.layout.addWidget(self.fibers_mini.canvas.native, 0, 2, 2, 2)
          else:
              self.layout.addWidget(self.fibers_mini.canvas.native, 0, 2, 1, 1)
              self.layout.addWidget(self.bar.canvas.native, 1, 2, 1, 1)
          #layout.setColumnStretch(0, 2)
          #layout.setRowStretch(0, 2)
          #layout.setColumnStretch(2, 1)
          #layout.setRowStretch(0, 1)
          
          self.setLayout(self.layout)
          #print(layout.getContentsMargins())
          #top.show()
          
  
  #    def paintEvent(self, e):
  #        dc = QPainter(self)
          
      def bye(self):
          self.exit(0)
  
9f9f1788   Pavel Govyadinov   clead up version ...
81
82
83
84
85
  """    
  Initializes the entire QTlayout and sets the mouse press events.
  These are connected to the slots such that each is processes by this class
  and the class it wraps.
  """    
4407a915   Pavel Govyadinov   working with new ...
86
87
  #class GraphWidget(QtGui.QWidget):
  class GraphWidget(QtWidgets.QWidget):
6aca1767   Pavel Govyadinov   Added a signal to...
88
      select = QtCore.pyqtSignal(list)
9f9f1788   Pavel Govyadinov   clead up version ...
89
90
      def __init__(self):
          super(GraphWidget, self).__init__()
4407a915   Pavel Govyadinov   working with new ...
91
          box = QtWidgets.QVBoxLayout(self)
9f9f1788   Pavel Govyadinov   clead up version ...
92
93
94
          self.resize(500,500)
          self.setLayout(box)
          self.canvas = GraphCanvas()
4407a915   Pavel Govyadinov   working with new ...
95
          self.setUpdatesEnabled(True)
9f9f1788   Pavel Govyadinov   clead up version ...
96
97
98
99
100
          #self.canvas.create_native()
          box.addWidget(self.canvas.native)
          self.color = True
          self.use_3D = False
          self.camera = [0,0,0]
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
101
          self.other = None
9f9f1788   Pavel Govyadinov   clead up version ...
102
103
104
105
106
  
          self.canvas.events.mouse_press.connect(self.on_mouse_press)
          self.canvas.events.mouse_release.connect(self.on_mouse_release)
          self.canvas.events.mouse_move.connect(self.on_mouse_move)
          self.canvas.events.mouse_double_click.connect(self.on_mouse_double_click)
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
107
          self.w = None
4407a915   Pavel Govyadinov   working with new ...
108
          #self.canvas.events.
9f9f1788   Pavel Govyadinov   clead up version ...
109
          #self.show()
4407a915   Pavel Govyadinov   working with new ...
110
          #self.repaint()
9f9f1788   Pavel Govyadinov   clead up version ...
111
112
113
114
115
116
117
118
119
120
  
      """
      Handles the right click mouse event at the QWidget level.
      Depending on where the mouse button in clicked and the current zoom level,
      the function gets the unique id of the node, cluster or background under the
      cursor and opens a context menu based on the ID.
      
      The context menu level actions are also coded in this section of the code.
      """
      def on_mouse_press(self, event):
4407a915   Pavel Govyadinov   working with new ...
121
          self.canvas.set_current(event)
9f9f1788   Pavel Govyadinov   clead up version ...
122
123
          if event.button == 2:
              if self.canvas.view[0][0] >= 0.0010:
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
124
                  self.canvas.refresh()
9f9f1788   Pavel Govyadinov   clead up version ...
125
                  c_id = self.canvas.get_clicked_id(event)
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
126
                  self.canvas.refresh()
9f9f1788   Pavel Govyadinov   clead up version ...
127
              else:
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
128
                  self.canvas.refresh()
9f9f1788   Pavel Govyadinov   clead up version ...
129
                  c_id = self.canvas.get_clicked_id(event, clusters=True)
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
130
                  self.canvas.refresh()
9f9f1788   Pavel Govyadinov   clead up version ...
131
132
133
134
              #right click
              if(c_id == None):
                  menu = QtWidgets.QMenu(self)
                  NS = menu.addAction('Node Size')
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
135
136
                  if (self.canvas.path != []):
                      FNP = menu.addAction("Filter Network Path")
9f9f1788   Pavel Govyadinov   clead up version ...
137
138
139
140
141
142
143
144
145
                  #tmp = menu.addAction('temp')
                  tmp = menu.addMenu('Node Color')
                  vertex_props = self.canvas.G.vertex_properties.keys()
                  vertex_actions = []
                  for i in range(len(vertex_props)):
                      if(vertex_props[i] != "map" or vertex_props[i] != "RGBA"):
                          vertex_actions.append(tmp.addAction(vertex_props[i]))
                  #tmp.addAction("Cluster")
                  #NC = menu.addAction('Node Color')
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
146
                  EXP = menu.addAction('Export VTK')
9f9f1788   Pavel Govyadinov   clead up version ...
147
148
                  #EXP_adv = menu.addAction('Export VTK Advanced')
                  NL = menu.addAction('New Layout')
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
149
150
151
                  NSL = menu.addAction('New Spring-Onion Layout (sum)')
                  NSLMI = menu.addAction('New Spring-Onion Layout(max)')
                  EXPAND = menu.addAction('Expand')
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
152
153
                  CL = menu.addAction('Cluster_Layout')
                  
9f9f1788   Pavel Govyadinov   clead up version ...
154
                  action = menu.exec_(event.native.globalPos())
6eb102f5   Pavel Govyadinov   Fixed issue cause...
155
156
                  if DEBUG:
                      print(action)
9f9f1788   Pavel Govyadinov   clead up version ...
157
158
159
160
161
162
                  for i in range(len(vertex_actions)):
                      if action == vertex_actions[i]:
                          if vertex_props[i] == "clusters":
                              self.canvas.color_vertices(self.canvas.G, vertex_props[i], dtype=True)
                          else:
                              self.canvas.color_vertices(self.canvas.G, vertex_props[i])
6eb102f5   Pavel Govyadinov   Fixed issue cause...
163
164
165
                              
                          if DEBUG:
                              print(vertex_props[i])
9f9f1788   Pavel Govyadinov   clead up version ...
166
167
168
169
170
171
                  if action == NS:
                      if self.use_3D == False:
                          self.use_3D = True
                      else:
                          self.use_3D = False
                          self.canvas.size_vertices(self.canvas.G, 'degree' )
6eb102f5   Pavel Govyadinov   Fixed issue cause...
172
                          self.canvas.color_vertices(self.canvas.G, 'degree')
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
173
174
175
176
177
178
179
180
181
182
183
                  if (self.canvas.path != []):
                      if action == FNP:
                          net = nwt.Network()
                          G1 = net.filterBorder(self.canvas.G)
                          BB = nwt.AABB(G1)
                          self.canvas.set_graph(G1, BB.A, BB.B, subgraph=True)
                          self.test.canvas.set_data(G1, BB.A, BB.B, 16)
                          self.canvas.refresh()
                          self.test.canvas.refresh()
                          #self.canvas.set_data()
  
9f9f1788   Pavel Govyadinov   clead up version ...
184
185
186
                  #if action == NC:
                  #    self.canvas.color_vertices(self.canvas.G, not self.color)
                  #    self.color = not self.color
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
187
188
                  if action == EXP:
                      nwt.Network.write_vtk(self.canvas.G, "./nwt_small.vtk")
9f9f1788   Pavel Govyadinov   clead up version ...
189
190
191
192
193
194
  #                if action == EXP_adv:
  #                    nwt.Network.write_vtk(self.canvas.G, "./nwt_median_binned.vtk")
  #                    nwt.Network.write_vtk(self.canvas.G, "./nwt_median_non_binned.vtk", binning=False)
  #                    nwt.Network.write_vtk(self.canvas.G, "./nwt_points_wise_binned.vtk", camera=self.camera, binning = True)
  #                    nwt.Network.write_vtk(self.canvas.G, "./nwt_points_wise_non_binned.vtk", camera=self.camera, binning = False)
                  if action == tmp:
6eb102f5   Pavel Govyadinov   Fixed issue cause...
195
196
                      if DEBUG:
                          print("Stuff")
9f9f1788   Pavel Govyadinov   clead up version ...
197
198
199
200
201
202
203
                      #self.cb = QtWidgets.QComboBox()
                      #vertex_props = self.canvas.G.vertex_properties.keys()
                      #for i in range(len(vertex_props)):
                      #    self.cb.addItem(vertex_props[i])
                      #self.cb.currentIndexChanged.connect(self.selection_change)
                      #self.cb.show()
                  if action == NL:
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
204
205
206
207
208
209
                      old_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                      nG = nwt.Network.gen_new_fd_layout(self.canvas.G)
                      new_pos = nG.vertex_properties["pos"].get_2d_array(range(3)).T
                      self.canvas.animate(old_pos, new_pos)
                      
                      #self.canvas.gen_vertex_vbo(self.canvas.G)
9f9f1788   Pavel Govyadinov   clead up version ...
210
                      #self.canvas.set_data(self.canvas.G, self.canvas.bbl, self.canvas.bbu)
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
                      #self.canvas.expand_clusters(self.canvas.G, self.canvas.n_c)
                  if action == NSL:
                      old_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                      nG = nwt.Network.gen_spring_onion_layout(self.canvas.G, 'degree', 1.0, 1000, 0.01, 1.0)
                      new_pos = nG.vertex_properties["pos"].get_2d_array(range(3)).T
                      
                      self.canvas.animate(old_pos, new_pos)
                      #self.canvas.set_data(nG, self.canvas.bbl, self.canvas.bbu)
                      
                      #self.canvas.gen_vertex_vbo(self.canvas.G)
                      #self.canvas.expand_clusters(self.canvas.G, self.canvas.n_c)
                  if action == NSLMI:
                      old_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                      nG = nwt.Network.gen_spring_onion_layout(self.canvas.G, 'degree', 1.0, 1000, 0.01, 1.0, False)
                      new_pos = nG.vertex_properties["pos"].get_2d_array(range(3)).T
                      
                      self.canvas.animate(old_pos, new_pos)
                      #self.canvas.set_data(nG, self.canvas.bbl, self.canvas.bbu)
                      #self.canvas.expand_clusters(self.canvas.G, self.canvas.n_c)
                      
                      #self.canvas.gen_vertex_vbo(self.canvas.G)
                      
                  if action == EXPAND:
                      #self.canvas.gen_vertex_vbo(self.canvas.G)
                      old_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
9f9f1788   Pavel Govyadinov   clead up version ...
236
                      self.canvas.expand_clusters(self.canvas.G, self.canvas.n_c)
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
237
238
239
240
                      new_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                      #self.canvas.expand_clusters(self.canvas.G, self.canvas.n_c)
                      
                      self.canvas.animate(old_pos, new_pos)
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
241
242
243
244
245
246
247
248
249
250
                  if action == CL:
                      old_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                      self.canvas.voronoi_layout()
                      new_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                      if self.other != None:
                          other_old_pos = self.other.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                          self.other.canvas.voronoi_layout(G_c = self.canvas.G_cluster)
                          other_new_pos = self.other.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
                          self.other.canvas.animate(other_old_pos, other_new_pos)
                      self.canvas.animate(old_pos, new_pos)
9f9f1788   Pavel Govyadinov   clead up version ...
251
252
253
254
                      #self.canvas.size_vertices(self.canvas.G, 'degree_volume')
              else:
                  if self.canvas.view[0][0] >= 0.0010:
                      menu = QtWidgets.QMenu(self)
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
255
256
257
258
                      MnOC = menu.addAction('Minimize Other Clusters')
                      RA   = menu.addAction('Reset Alpha')
                      NI = menu.addAction('Display Node Info')
                      CI = menu.addAction('Display Cluster Info')
9f9f1788   Pavel Govyadinov   clead up version ...
259
                      action = menu.exec_(event.native.globalPos())
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
                      if action == MnOC:
                          self.canvas.set_current(event)
                          self.canvas.refresh()
                          c_id = self.canvas.get_clicked_id(event)
                          
                          cluster_id = self.canvas.G.vp["clusters"][self.canvas.G.vertex(c_id)]
                          self.select.emit(self.canvas.get_cluster(cluster_id))
                      if action == RA:
                          t = []
                          self.select.emit(self.canvas.get_cluster(t))
                      if action == NI:
                          self.canvas.set_current(event)
                          self.canvas.refresh()
                          c_id = self.canvas.get_clicked_id(event)
                          self.canvas.refresh()
9f9f1788   Pavel Govyadinov   clead up version ...
275
                          print("Display Node Info")
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
                          self.w = NodeInfoWidget()
                          
                          #generate the subgraph around the node
                          vfilt = np.zeros([self.canvas.G.num_vertices(), 1], dtype="bool")
                          center = self.canvas.G.vp["pos"][self.canvas.G.vertex(c_id)]
                          for v in self.canvas.G.vertex(c_id).all_neighbors():
                              vfilt[int(v)] = 1
                          vfilt[int(c_id)] = 1
                          vfilt_prop = self.canvas.G.new_vertex_property("bool", vals = vfilt)
                          self.canvas.G.set_vertex_filter(vfilt_prop)
                          
                              #get the filtered properties
                          g = nwt.gt.Graph(self.canvas.G, prune=True, directed=False)
                          BB = nwt.AABB(g)
                          #print(BB.A)
                          #print(BB.B)
                          self.canvas.G.clear_filters()
                          self.w.setGeometry(QRect(100, 100, 900, 800))
                          self.w.graph_mini1.canvas.set_graph(g, BB.A, BB.B)
                          self.w.graph_mini1.canvas.center_camera_on(center)
                          self.w.graph_mini1.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini1.canvas.color_vertices(g, "clusters")
                          
                          self.w.graph_mini2.canvas.set_graph(g, BB.A, BB.B)
                          self.w.graph_mini2.canvas.center_camera_on(center)
                          self.w.graph_mini2.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini2.canvas.color_vertices(g, "degree")
                          
                          self.w.graph_mini3.canvas.set_graph(g, BB.A, BB.B)
                          #self.w.graph_mini3.canvas.set_view_matrix(self.canvas.view)
                          self.w.graph_mini3.canvas.center_camera_on(center)
                          self.w.graph_mini3.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini3.canvas.color_vertices(g, "bc")
                          
                          self.w.graph_mini4.canvas.set_graph(g, BB.A, BB.B)
                          #self.w.graph_mini4.canvas.set_view_matrix(self.canvas.view)
                          self.w.graph_mini4.canvas.center_camera_on(center)
                          self.w.graph_mini4.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini4.canvas.color_vertices(g, "degree_volume")
                          
                          self.w.fibers_mini.canvas.set_data(g, BB.A, BB.B, 16)
                          self.w.show()
                      if action == CI:
                          self.canvas.set_current(event)
                          self.canvas.refresh()
                          c_id = self.canvas.get_clicked_id(event)
                          #self.canvas.refresh()
                          self.w = NodeInfoWidget(hist=True)
                          #self.w = NodeInfoWidget()
                          
                          cluster_id = self.canvas.G.vp["clusters"][self.canvas.G.vertex(c_id)]
                          num_v_in_cluster = len(np.argwhere(self.canvas.labels == cluster_id))
                          vfilt = np.zeros([self.canvas.G.num_vertices(), 1], dtype="bool")
                          vfilt[np.argwhere(self.canvas.labels == cluster_id)] = 1
                          vfilt_prop = self.canvas.G.new_vertex_property("bool", vals = vfilt)
                          self.canvas.G.set_vertex_filter(vfilt_prop)
                      
                          #get the filtered properties
                          g = nwt.gt.Graph(self.canvas.G, prune=True, directed=False)
                          positions = g.vertex_properties["pos"].get_2d_array(range(3)).T
                          center = np.sum(positions, 0)/num_v_in_cluster
                          self.canvas.G.clear_filters()
                          
                          BB = nwt.AABB(g)
                          self.canvas.G.clear_filters()
                          self.w.setGeometry(QRect(100, 100, 900, 800))
                          self.w.graph_mini1.canvas.set_graph(g, BB.A, BB.B)
                          self.w.graph_mini1.canvas.center_camera_on(center)
                          self.w.graph_mini1.canvas.zoom_camera_on(self.canvas.scale)
                          
                          self.w.graph_mini2.canvas.set_graph(g, BB.A, BB.B)
                          self.w.graph_mini2.canvas.center_camera_on(center)
                          self.w.graph_mini2.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini2.canvas.color_vertices(g, "degree")
                          
                          self.w.graph_mini3.canvas.set_graph(g, BB.A, BB.B)
                          #self.w.graph_mini3.canvas.set_view_matrix(self.canvas.view)
                          self.w.graph_mini3.canvas.center_camera_on(center)
                          self.w.graph_mini3.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini3.canvas.color_vertices(g, "bc")
                          
                          self.w.graph_mini4.canvas.set_graph(g, BB.A, BB.B)
                          #self.w.graph_mini4.canvas.set_view_matrix(self.canvas.view)
                          self.w.graph_mini4.canvas.center_camera_on(center)
                          self.w.graph_mini4.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini4.canvas.color_vertices(g, "degree_volume")
                          
                          self.w.fibers_mini.canvas.set_data(g, BB.A, BB.B, 16)
                          
                          self.w.bar.set_Graph(g)
                          
                          self.w.show()
                          
                          print("Display Cluster Info")
9f9f1788   Pavel Govyadinov   clead up version ...
370
371
372
                  else:
                      menu = QtWidgets.QMenu(self)
                      MnOC = menu.addAction('Minimize Other Clusters')
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
373
                      CI = menu.addAction('Display Cluster Info')
9f9f1788   Pavel Govyadinov   clead up version ...
374
375
376
                      RA   = menu.addAction('Reset Alpha')
                      action = menu.exec_(event.native.globalPos())
                      if action == MnOC:
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
377
378
379
380
381
382
383
                          self.canvas.set_current(event)
                          self.canvas.refresh()
                          c_id = self.canvas.get_clicked_id(event, clusters=True)
                          self.canvas.refresh()
                          
                          cluster_id = self.canvas.G.vp["clusters"][c_id]
                          self.select.emit(self.canvas.get_path(cluster_id))
9f9f1788   Pavel Govyadinov   clead up version ...
384
                      if action == RA:
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
                          t = []
                          self.select.emit(self.canvas.get_cluster(t))
                      if action == CI:
                          self.canvas.set_current(event)
                          self.canvas.refresh()
                          c_id = self.canvas.get_clicked_id(event, clusters=True)
                          self.canvas.refresh()
                          
                          self.w = NodeInfoWidget(hist=True)
                          #self.w = NodeInfoWidget()
                          
                          cluster_id = self.canvas.G.vp["clusters"][c_id]
                          num_v_in_cluster = len(np.argwhere(self.canvas.labels == c_id))
                          vfilt = np.zeros([self.canvas.G.num_vertices(), 1], dtype="bool")
                          vfilt[np.argwhere(self.canvas.labels == c_id)] = 1
                          vfilt_prop = self.canvas.G.new_vertex_property("bool", vals = vfilt)
                          self.canvas.G.set_vertex_filter(vfilt_prop)
                      
                          #get the filtered properties
                          g = nwt.gt.Graph(self.canvas.G, prune=True, directed=False)
                          positions = g.vertex_properties["pos"].get_2d_array(range(3)).T
                          center = np.sum(positions, 0)/num_v_in_cluster
                          self.canvas.G.clear_filters()
                          
                          BB = nwt.AABB(g)
                          self.canvas.G.clear_filters()
                          self.w.setGeometry(QRect(100, 100, 900, 800))
                          self.w.graph_mini1.canvas.set_graph(g, BB.A, BB.B)
                          self.w.graph_mini1.canvas.center_camera_on(center)
                          self.w.graph_mini1.canvas.zoom_camera_on(self.canvas.scale)
                          
                          self.w.graph_mini2.canvas.set_graph(g, BB.A, BB.B)
                          self.w.graph_mini2.canvas.center_camera_on(center)
                          self.w.graph_mini2.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini2.canvas.color_vertices(g, "degree")
                          
                          self.w.graph_mini3.canvas.set_graph(g, BB.A, BB.B)
                          #self.w.graph_mini3.canvas.set_view_matrix(self.canvas.view)
                          self.w.graph_mini3.canvas.center_camera_on(center)
                          self.w.graph_mini3.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini3.canvas.color_vertices(g, "bc")
                          
                          self.w.graph_mini4.canvas.set_graph(g, BB.A, BB.B)
                          #self.w.graph_mini4.canvas.set_view_matrix(self.canvas.view)
                          self.w.graph_mini4.canvas.center_camera_on(center)
                          self.w.graph_mini4.canvas.zoom_camera_on(self.canvas.scale)
                          self.w.graph_mini4.canvas.color_vertices(g, "degree_volume")
                          
                          self.w.fibers_mini.canvas.set_data(g, BB.A, BB.B, 16)
                          
                          self.w.bar.set_Graph(g)
                          self.w.show()
                          
                          print("Display Cluster Info")
                          
9f9f1788   Pavel Govyadinov   clead up version ...
440
441
442
443
444
445
  
  
  #    def selection_change(self, i):
  #        self.canvas.size_vertices(self.canvas.G, self.cb.currentText())
  
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
446
447
448
      def set_other(self, other):
          self.other = other
  
9f9f1788   Pavel Govyadinov   clead up version ...
449
450
451
452
      """
          Handles the mouse double click event.
          Pass-through function.
      """
4407a915   Pavel Govyadinov   working with new ...
453
      
9f9f1788   Pavel Govyadinov   clead up version ...
454
      def on_mouse_double_click(self, event):
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
455
          self.canvas.set_current(event)
2282da38   Pavel Govyadinov   added path select...
456
457
          self.canvas.update_path(event)
          self.select.emit(self.canvas.get_path())
4407a915   Pavel Govyadinov   working with new ...
458
459
  #        old_pos = self.canvas.G.vertex_properties["pos"].get_2d_array(range(3)).T
  #        nG = nwt.Network.gen_new_fd_layout(self.canvas.G)
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
460
461
          #    def animate(self, new_G):
  #            
4407a915   Pavel Govyadinov   working with new ...
462
463
  #        new_pos = nG.vertex_properties["pos"].get_2d_array(range(3)).T
  #        self.canvas.animate(old_pos, new_pos)
9f9f1788   Pavel Govyadinov   clead up version ...
464
465
466
467
468
469
470
471
472
473
474
475
476
  
      """
          Handles the mouse release event.
          Pass-through function.
      """
      def on_mouse_release(self, event):
          n = 1
  
      """
          Handles the mouse move event.
          Pass-through function.
      """
      def on_mouse_move(self, event):
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
477
478
479
480
481
          self.canvas.set_current(event)
          self.canvas.refresh()
          c_id = self.canvas.get_clicked_id(event)
          self.canvas.refresh()
          print(c_id)
9f9f1788   Pavel Govyadinov   clead up version ...
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
  
      """
          Internal function that interacts with the tube visualization.
      """
      def set_g_view(self, test):
          self.test = test
  
      """
          Function to handle the pyqt Slot that receives the interacted-with signal
          from the Tube visualization. The signal sends the camera position in 3D coordinates
          every time the camera is moved.
      """
      @QtCore.pyqtSlot(float, float, float)
      def sigUpdate(self, x, y, z):
          self.camera = [x,y,z]
          if(self.use_3D == True):
              self.camera = [x,y,z]
              self.canvas.vertexSizeFromDistance(self.canvas.G, [x,y,z])
              self.canvas.vertexAlphaFromDistance(self.canvas.G, [x,y,z])
6eb102f5   Pavel Govyadinov   Fixed issue cause...
501
502
              if DEBUG:
                  print("got signal", x, y, z)
9f9f1788   Pavel Govyadinov   clead up version ...
503
504
505
506
507
508
509
  
      """
          Initialization method that connects the slot to the function that handles
          the information being sent.
      """
      def connect(self, signal_object):
          signal_object.sigUpdate.connect(self.sigUpdate)