GuiVisPy_tube_dual.py 4.76 KB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jan 31 15:29:40 2019

@author: pavel
`"""

from vispy import app
import vispy

import network_dep as nwt

#from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
from PyQt5 import QtCore, QtGui, QtWidgets
#import pyqtgraph as pg
import numpy as np
import math

from mpl_toolkits.mplot3d import Axes3D
#import matplotlib
#import matplotlib.pyplot as plt
#matplotlib.use('Qt5Agg')

from GraphWidget import GraphWidget
from TubeWidget import TubeWidget
#vispy.use(app='egl')


DEBUG = False

#set the backend. for different versions of PyQt
app.use_app(backend_name='PyQt5')

app.set_interactive(True)

#Define a top level application
appMain = QtWidgets.QApplication([])
#QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_ShareOpenGLContexts, True)

##Define a toplevel Widget
top = QtWidgets.QWidget()
top.resize(900, 900)


#fibers = FiberView()
fibers = TubeWidget()
fibers.canvas.create_native()
#fibers = gl.GLViewWidget()

#plt = hist.addPlot()

layout = QtWidgets.QGridLayout()
graph = GraphWidget()
graph.canvas.create_native()


fibers2 = TubeWidget()
fibers2.canvas.create_native()

graph2 = GraphWidget()
graph2.canvas.create_native()

graph.connect(fibers)
fibers.connect(graph)

graph2.connect(fibers2)
fibers2.connect(graph2)

#vspacer = QtWidgets.QSpacerItem(10,10, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)

#initialize the layoutddddddddddd

#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, 1, 3)
#layout.addItem(vspacer, 0, 2, 2, 1)
layout.addWidget(fibers.canvas.native, 0, 4, 1, 3)

layout.addWidget(graph2.canvas.native, 1, 0, 1, 3)
#layout.addItem(vspacer, 0, 2, 2, 1)
layout.addWidget(fibers2.canvas.native, 1, 4, 1, 3)

#layout.setColumnStretch(0, 2)
#layout.setRowStretch(0, 2)
#layout.setColumnStretch(2, 1)
#layout.setRowStretch(0, 1)

top.setLayout(layout)
print(layout.getContentsMargins())
top.show()

def load_nwt(filepath):
    net = nwt.Network(filepath)
    G = net.createFullGraph_gt()
    G = net.filterDisconnected(G)
    #G = net.gen_spring_onion_layout(G, 'degree', 1.0, 1000, 0.01, 1.0)
    #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")

G2, bbl2, bbu2 = load_nwt("/home/pavel/Documents/Python/GraphGuiQt/network_4.nwt")
#G2, bbl2, bbu2 = load_nwt("/home/pavel/Documents/Python/GraphGuiQt/network_4.nwt")
#nwt.Network.write_vtk(G)

#G, bbl, bbu = load_nwt("/home/pavel/Documents/Python/GraphGuiQt/net`````````work_test_251_1kx3_short_NEW.nwt")
#ret = nwt.Network.get_affinity_matrix(G, "length")
#node_image = QtGui.QImage("/home/pavel/Documents/Python/GraphGuiQt/node_tex.jpg")
#node_tex = QtGui.QBitmap.fromImage(node_image)

if DEBUG:
    print(node_tex.depth())
#fibers.opts['distance'] = 5
#    item = NodeItem(G)
#    graph.addItem(item)
#draw_histogram(G, "length")
    
        #self.canvas.events.mouse_press.connect(o_canvas.on_mouse_press)
        #self.canvas.events.mouse_release.connect(o_canvas.on_mouse_release)
        #self.canvas.events.mouse_move.connect(o_canvas.on_mouse_move)
        #self.canvas.events.mouse_wheel.connect(o_canvas.on_mouse_wheel)
#fibers.canvas.events.mouse_press.connect(fibers2.mouse_press)
#fibers.canvas.events.mouse_release.connect(fibers2.mouse_release)
#fibers.canvas.events.on_mouse_wheel.connect(fibers2.canvas.on_mouse_wheel)

graph.canvas.set_data(G, bbl, bbu)
fibers.canvas.set_data(G, bbl, bbu, 16)
fibers.set_other(fibers2)
fibers2.set_other(fibers)
graph.set_other(graph2)
graph2.set_other(graph)

graph2.canvas.set_data(G2, bbl2, bbu2, G_other=graph.canvas.G)
fibers2.canvas.set_data(G2, bbl2, bbu2, 16)
#fibers.draw_all(G, center, fibers, graph, node_tex)
graph.set_g_view(fibers)
graph2.set_g_view(fibers2)


#fibers.link_cameras(fibers2)
#fibers2.link_cameras(fibers)

## Start Qt event loop unless running in interactive mode.
if __name__ == '__main__':
    #import sys
    #if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
        #QtGui.QApplication.instance().exec_()
    app.set_interactive(enabled=True)
    app.run()