-
Hi, thank you for creating vedo! It's a really nice library. I'm creating a Qt application in which I would like to use vedo to do some mesh manipulation (cutting, smoothing etc.). I'd like a user to be able to press a button to start e.g. the box cutter tool. Here's an example based on one of the vedo Qt examples. import sys
from PySide2 import QtWidgets, QtCore
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vedo import Plotter, Mesh, dataurl
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
QtWidgets.QMainWindow.__init__(self, parent)
self.frame = QtWidgets.QFrame()
self.layout = QtWidgets.QVBoxLayout()
self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
# Create renderer and add the vedo objects and callbacks
self.plt = Plotter(qtWidget=self.vtkWidget)
mesh = Mesh(dataurl+'cow.vtk')
self.plt += mesh
self.plt.show()
# Add buttons for starting cutting tools
spherical_cutter_button = QtWidgets.QPushButton("Start the spherical cutter")
spherical_cutter_button.clicked.connect(lambda: self.addCutterTool(mode='sphere'))
box_cutter_button = QtWidgets.QPushButton("Start the box cutter")
box_cutter_button.clicked.connect(lambda: self.addCutterTool(mode='box'))
# Set-up the rest of the Qt window
self.layout.addWidget(self.vtkWidget)
self.layout.addWidget(spherical_cutter_button)
self.layout.addWidget(box_cutter_button)
self.frame.setLayout(self.layout)
self.setCentralWidget(self.frame)
self.show()
@QtCore.Slot()
def addCutterTool(self, mode):
self.plt.addCutterTool(mode=mode)
def onClose(self):
#Disable the interactor before closing to prevent it
#from trying to act on already deleted items
self.vtkWidget.close()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
app.aboutToQuit.connect(window.onClose) # <-- connect the onClose event
app.exec_() The above example has a single mesh and two buttons - one button to start a spherical cutter and another to start a box cutter. However, as soon as a button is pressed, the cutting is performed - it is not possible to interactively move the cutting tool to select which region to cut. Is what I'm trying to do possible with |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi - thanks, unfortunately I'm very naive about Qt in general, plus the cutterTool is a bit buggy under certain circumstances and would need a revision.. still the QtInteractor seems to intercept the Start() call that's why it disappears immediately, but you can activate manually the widget in this way: import sys
# from PySide2 import QtWidgets, QtCore
from PyQt5 import Qt
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vedo import Plotter, Mesh, dataurl
class MainWindow(Qt.QMainWindow):
def __init__(self, parent=None):
Qt.QMainWindow.__init__(self, parent)
self.frame = Qt.QFrame()
self.layout = Qt.QVBoxLayout()
self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
# Create renderer and add the vedo objects and callbacks
self.plt = Plotter(qtWidget=self.vtkWidget)
mesh = Mesh(dataurl+'cow.vtk')
self.plt += mesh
self.plt.show()
box_cutter_button_on = Qt.QPushButton("Start the box cutter")
box_cutter_button_on.clicked.connect(self.ctool_start)
box_cutter_button_off = Qt.QPushButton("Stop the box cutter")
box_cutter_button_off.clicked.connect(self.ctool_stop)
# Set-up the rest of the Qt window
self.layout.addWidget(self.vtkWidget)
self.layout.addWidget(box_cutter_button_on)
self.layout.addWidget(box_cutter_button_off)
self.frame.setLayout(self.layout)
self.setCentralWidget(self.frame)
self.show()
def ctool_start(self):
self.plt.addCutterTool(mode='box')
self.plt.widgets[-1].On()
def ctool_stop(self):
self.plt.widgets[-1].Off()
def onClose(self):
#Disable the interactor before closing to prevent it
#from trying to act on already deleted items
self.vtkWidget.close()
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
window = MainWindow()
app.aboutToQuit.connect(window.onClose) # <-- connect the onClose event
app.exec_() Hope this helps! |
Beta Was this translation helpful? Give feedback.
Hi - thanks, unfortunately I'm very naive about Qt in general, plus the cutterTool is a bit buggy under certain circumstances and would need a revision.. still the QtInteractor seems to intercept the Start() call that's why it disappears immediately, but you can activate manually the widget in this way: