I'm working on a generative design project for 3D models. I need to create a simple QT application that allows the user to view meshes using VTK and includes a few buttons for feedback into the generation algorithms.
GUIs are something completely new to me so I'm quite stumped on how to integrate the code from here for a viewer into a wider program. For now I'm merely trying to create a single button and a 3D cone in the viewer.
My code so far crashes when run. It uses the QVTKRenderWindowInteractor() object from the link given, with the object directly pasted into the file.
try:
import sys
import vtk
from PyQt5.QtWidgets import QWidget, QSizePolicy, QApplication, QPushButton, QVBoxLayout
from PyQt5.QtCore import Qt, pyqtSignal, QTimer, QObject, QSize, QEvent
except ImportError:
raise ImportError("Cannot load either PyQt5")
import vtk
class neuralDesignerApp(QWidget):
def __init__(self):
super(QWidget,self).__init__()
self.initUI()
def initUI(self):
app = QApplication(['QVTKRenderWindowInteractor'])
vtkWindow = QVTKRenderWindowInteractor(self)
vtkWindow.Initialize()
vtkWindow.Start()
ren = vtk.vtkRenderer()
vtkWindow.GetRenderWindow().AddRenderer(ren)
cone = vtk.vtkConeSource()
cone.SetResolution(8)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren.AddActor(coneActor)
btn1 = QPushButton("Button 1", self)
vbox = QVBoxLayout()
vbox.addWidget(vtkWindow)
vbox.addWidget(btn1)
self.setLayout(vbox)
self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Neural Designer')
self.show()