Blame view

GuiVisPy_tube.py 3.76 KB
9f9f1788   Pavel Govyadinov   clead up version ...
1
2
3
4
5
6
7
8
9
  #!/usr/bin/env python3
  # -*- coding: utf-8 -*-
  """
  Created on Thu Jan 31 15:29:40 2019
  
  @author: pavel
  `"""
  
  from vispy import app
4407a915   Pavel Govyadinov   working with new ...
10
  import vispy
9f9f1788   Pavel Govyadinov   clead up version ...
11
12
13
  
  import network_dep as nwt
  
4407a915   Pavel Govyadinov   working with new ...
14
15
16
  #from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
  from PyQt5 import QtCore, QtGui, QtWidgets
  #import pyqtgraph as pg
9f9f1788   Pavel Govyadinov   clead up version ...
17
18
19
20
  import numpy as np
  import math
  
  from mpl_toolkits.mplot3d import Axes3D
4407a915   Pavel Govyadinov   working with new ...
21
22
23
  #import matplotlib
  #import matplotlib.pyplot as plt
  #matplotlib.use('Qt5Agg')
9f9f1788   Pavel Govyadinov   clead up version ...
24
25
26
  
  from GraphWidget import GraphWidget
  from TubeWidget import TubeWidget
4407a915   Pavel Govyadinov   working with new ...
27
  #vispy.use(app='egl')
9f9f1788   Pavel Govyadinov   clead up version ...
28
29
  
  
6eb102f5   Pavel Govyadinov   Fixed issue cause...
30
31
  DEBUG = False
  
9f9f1788   Pavel Govyadinov   clead up version ...
32
33
34
  #set the backend. for different versions of PyQt
  app.use_app(backend_name='PyQt5')
  
4407a915   Pavel Govyadinov   working with new ...
35
36
  app.set_interactive(True)
  
9f9f1788   Pavel Govyadinov   clead up version ...
37
  #Define a top level application
4407a915   Pavel Govyadinov   working with new ...
38
39
  appMain = QtWidgets.QApplication([])
  #QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts, True)
9f9f1788   Pavel Govyadinov   clead up version ...
40
41
  
  ##Define a toplevel Widget
4407a915   Pavel Govyadinov   working with new ...
42
  top = QtWidgets.QWidget()
9f9f1788   Pavel Govyadinov   clead up version ...
43
44
45
  top.resize(900, 900)
  
  
9f9f1788   Pavel Govyadinov   clead up version ...
46
47
48
49
50
51
52
  #fibers = FiberView()
  fibers = TubeWidget()
  fibers.canvas.create_native()
  #fibers = gl.GLViewWidget()
  
  #plt = hist.addPlot()
  
4407a915   Pavel Govyadinov   working with new ...
53
  layout = QtWidgets.QGridLayout()
9f9f1788   Pavel Govyadinov   clead up version ...
54
55
56
57
  graph = GraphWidget()
  graph.canvas.create_native()
  
  graph.connect(fibers)
6aca1767   Pavel Govyadinov   Added a signal to...
58
  fibers.connect(graph)
9f9f1788   Pavel Govyadinov   clead up version ...
59
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
60
  #vspacer = QtWidgets.QSpacerItem(10,10, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
9f9f1788   Pavel Govyadinov   clead up version ...
61
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
62
  #initialize the layoutddddddddddd
4407a915   Pavel Govyadinov   working with new ...
63
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
64
65
66
67
68
69
70
71
72
  #addLayout(QLayout *layout, int row, int column, int rowSpan, int columnSpan
  #, Qt::Alignment alignment = Qt::Alignment())
  #layout.addWidget(graph.canvas.native, 0, 0, 2, 3)
  #layout.addItem(vspacer, 0, 1, 2, 3)
  #layout.addWidget(fibers.canvas.native, 0, 2, 2, 3)
  
  layout.addWidget(graph.canvas.native, 0, 0, 2, 3)
  #layout.addItem(vspacer, 0, 2, 2, 1)
  layout.addWidget(fibers.canvas.native, 0, 4, 2, 3)
9f9f1788   Pavel Govyadinov   clead up version ...
73
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
74
75
76
77
  #layout.setColumnStretch(0, 2)
  #layout.setRowStretch(0, 2)
  #layout.setColumnStretch(2, 1)
  #layout.setRowStretch(0, 1)
9f9f1788   Pavel Govyadinov   clead up version ...
78
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
79
80
81
  top.setLayout(layout)
  print(layout.getContentsMargins())
  top.show()
9f9f1788   Pavel Govyadinov   clead up version ...
82
83
84
85
86
  
  def load_nwt(filepath):
      net = nwt.Network(filepath)
      G = net.createFullGraph_gt()
      G = net.filterDisconnected(G)
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
87
      #G = net.gen_spring_onion_layout(G, 'degree', 1.0, 1000, 0.01, 1.0)
9f9f1788   Pavel Govyadinov   clead up version ...
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
      #G = net.filterFullGraph_gt(G, erode=True)
      #G = net.filterFullGraph_gt(G, erode=True)
      #G = net.gen_new_fd_layout(G)
      #G = net.filterBorder(G)
      #nwt.Network.saveGraph_gt(nwt, G, "FilteredNetwork_JACK_3.nwt")
      color = np.zeros(4, dtype = np.double)
      color = [0.0, 1.0, 0.0, 1.0]
      G.edge_properties["RGBA"] = G.new_edge_property("vector<double>", val=color)
      color = [1.0, 0.0, 0.0, 0.9]
      G.vertex_properties["RGBA"] = G.new_vertex_property("vector<double>", val=color)
      bbl, bbu = net.aabb()
  
  
      return G, bbl, bbu
  
  G, bbl, bbu = load_nwt("/home/pavel/Documents/Python/GraphGuiQt/network_4.nwt")
  #nwt.Network.write_vtk(G)
  
193cb4c6   Pavel Govyadinov   need this to test
106
  #G, bbl, bbu = load_nwt("/home/pavel/Documents/Python/GraphGuiQt/net`````````work_test_251_1kx3_short_NEW.nwt")
9f9f1788   Pavel Govyadinov   clead up version ...
107
  #ret = nwt.Network.get_affinity_matrix(G, "length")
4407a915   Pavel Govyadinov   working with new ...
108
109
  #node_image = QtGui.QImage("/home/pavel/Documents/Python/GraphGuiQt/node_tex.jpg")
  #node_tex = QtGui.QBitmap.fromImage(node_image)
6eb102f5   Pavel Govyadinov   Fixed issue cause...
110
111
112
  
  if DEBUG:
      print(node_tex.depth())
9f9f1788   Pavel Govyadinov   clead up version ...
113
114
115
116
  center = (bbu-bbl)/2.0
  #fibers.opts['distance'] = 5
  #    item = NodeItem(G)
  #    graph.addItem(item)
25fa0bfe   Pavel Govyadinov   Stable, pre-vispy...
117
  #draw_histogram(G, "length")
9f9f1788   Pavel Govyadinov   clead up version ...
118
119
120
121
  graph.canvas.set_data(G, bbl, bbu)
  fibers.canvas.set_data(G, bbl, bbu, 16)
  #fibers.draw_all(G, center, fibers, graph, node_tex)
  graph.set_g_view(fibers)
4407a915   Pavel Govyadinov   working with new ...
122
  
17e4b25a   Pavel Govyadinov   Bug fixes, Dual v...
123
124
125
126
127
128
  graph.label = QtWidgets.QLabel(graph)
  graph.label.setFrameStyle(QtWidgets.QFrame.Panel | QtWidgets.QFrame.Sunken)
  graph.label.setText("STUFF")
  graph.label.setAlignment(QtCore.Qt.AlignTop | QtCore.Qt.AlignRight)
  graph.label.raise_()
  
9f9f1788   Pavel Govyadinov   clead up version ...
129
130
  ## Start Qt event loop unless running in interactive mode.
  if __name__ == '__main__':
4407a915   Pavel Govyadinov   working with new ...
131
132
133
134
135
      #import sys
      #if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
          #QtGui.QApplication.instance().exec_()
      app.set_interactive(enabled=True)
      app.run()
9f9f1788   Pavel Govyadinov   clead up version ...