Skip to content

Instantly share code, notes, and snippets.

@PaulDebus
Last active August 21, 2018 09:17
Show Gist options
  • Save PaulDebus/9065af47f1e3aad94b1f7d189518f2cb to your computer and use it in GitHub Desktop.
Save PaulDebus/9065af47f1e3aad94b1f7d189518f2cb to your computer and use it in GitHub Desktop.
Minimal working example for https://github.com/vispy/vispy/issues/1508
from vispy import scene
import numpy as np
from PySide2 import QtGui, QtWidgets, QtCore
class MyCanvas2D(scene.SceneCanvas):
def __init__(self, vertices, faces):
super(MyCanvas2D, self).__init__(keys=None, bgcolor="white")
self.unfreeze()
self.view = self.central_widget.add_view()
self.view.camera = "panzoom"
border = np.empty((faces.shape[0]*3, 2))
for i in range(faces.shape[0]):
tri = faces[i]
border[3*i+0] = [tri[0], tri[1]]
border[3*i+1] = [tri[1], tri[2]]
border[3*i+2] = [tri[2], tri[0]]
self.line = scene.visuals.Line(parent=self.view.scene, color="black",
pos=vertices, connect=border)
self.mesh = scene.visuals.Mesh(parent=self.view.scene, color="red", mode="lines",
vertices=vertices + [0, 5], faces=faces)
self.freeze()
class MyCanvas3D(scene.SceneCanvas):
def __init__(self, vertices, faces):
super(MyCanvas3D, self).__init__(keys=None, bgcolor="white")
self.unfreeze()
self.view = self.central_widget.add_view()
self.view.camera = "arcball"
self.mesh = scene.visuals.Mesh(parent=self.view.scene, vertices=vertices,
faces=faces)
self.freeze()
class MyWindow(QtWidgets.QMainWindow):
def __init__(self):
super(MyWindow, self).__init__(None)
vertices = np.array([[0.537705, 0.20005],
[0.182211, -2.04804],
[-1.7101, -0.906589],
[2.49874, -1.04955],
[0.394538, -3.07266],
[-0.233476, -0.880998],
[0.5, 1.],
[1.4319, -1.16265]])
faces = np.array([[4, 3, 7],
[0, 7, 3],
[7, 0, 5],
[2, 5, 0],
[1, 5, 2],
[5, 1, 7],
[7, 1, 4],
[2, 4, 1],
[0, 6, 2],
[3, 6, 0]])
splitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal)
self.canvas2d = MyCanvas2D(vertices, faces)
self.canvas2d.create_native()
splitter.addWidget(self.canvas2d.native)
self.canvas3d = MyCanvas3D(vertices, faces)
self.canvas3d.create_native()
splitter.addWidget(self.canvas3d.native)
self.setCentralWidget(splitter)
if __name__ == "__main__":
app = QtWidgets.QApplication([])
win = MyWindow()
win.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment