3.59 KB
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
Created on Mon Aug  5 15:53:16 2019

@author: pavel

    Qt wrapper/container class that handles all the top level events and maintains the
    methods necessary to use the QT signals and slots API.

from pyqtgraph.Qt import QtCore, QtGui, QtWidgets
from TubeCanvas import TubeDraw
import numpy as np
import trimesh as tm

DEBUG = False

class TubeWidget(QtGui.QWidget):
    sigUpdate = QtCore.pyqtSignal(float, float, float)
    #Initializes the QT wrapper class.
    def __init__(self):
        super(TubeWidget, self).__init__()
        box = QtGui.QVBoxLayout(self)
        self.canvas = TubeDraw()
        box.addWidget(self.canvas.native) = [0,0,0]
        self.down = False

    #Handles the mouse release event
    def on_mouse_release(self, event):

    #Handles the mouse move event
    def on_mouse_move(self, event):
        if self.down:

    #Handles the mouse press events
    def on_mouse_press(self, event):
        self.down = True
        if event.button == 2:
            menu = QtWidgets.QMenu(self)
            NS = menu.addAction('Export Model')
            action = menu.exec_(event.native.globalPos())
            if action == NS:

    #Handles the mouse wheel event
    def on_mouse_wheel(self, event):

    #controls the emit function of the QT class to send a signal to the slot
    #located in the other window.
    def sendCameraInfo(self):
        #self.view = self.canvas.view =
        #print("stuff", self.view[3, 0], self.view[3, 1], self.view[3, 2])
        if DEBUG:
    Function to receive the signal with the information necessary to visualize
    specific fibers only. With the rest of them being minimized.
    def select(self, x):
#        for e in x:
#            if e in self.canvas.edge_dict:    
#                print(self.canvas.edge_dict[e])
#            elif (e[1], e[0]) in self.canvas.edge_dict:
#                print(self.canvas.edge_dict[(e[1], e[0])])
        print("got signal", x)

        Initialization method that connects the slot to the function that handles
        the information being sent.
    def connect(self, signal_object):
    def save_stl_mesh(self):
        triangles = self.canvas.triangle_data
        caps = self.canvas.cap_data
        points = self.canvas.cylinder_data['a_position']
        colors = self.canvas.cylinder_data['a_fg_color']
        normals = self.canvas.cylinder_data['a_normal']
        mesh = tm.Trimesh(vertices=points, faces=np.append(triangles, caps, axis=0),
                          vertex_colors=colors, vertex_normals=normals)