Loading meshes interactively with PyQt #1185
-
Hello everybody So far no matter what I did the plotter wouldn't update & show the recently acquired model. It seems like the plotter is initialised and then stuck. Here's one example of my efforts: class ThreeDPanel(QWidget):
def __init__(self, model_manager: ModelManager, parent = None) -> None:
super().__init__(parent)
self.frame = QFrame()
self.layout = QVBoxLayout()
self.vtkwidget = QVTKRenderWindowInteractor(self.frame)
self.setLayout(self.layout)
self.layout.addWidget(self.vtkwidget)
# Initialise the vedo Plotter which will handle 3D rendering
self.plt = Plotter(qt_widget=self.vtkwidget, bg = 'white', interactive=False)
self.plt.show()
self.frame.setLayout(self.layout)
self.show()
# Subscribe to the model manager
self._model_manager = model_manager
model_manager.subscribe(self)
def onClose(self):
self.vtkwidget.close()
def update(self) -> None:
# This function is called by the model manager when a new 3D model is loaded.
model = self._model_manager.get_current_model()
if model is None:
raise ValueError("3D panel was called to update, but no model is loaded")
self.plt.clear()
self.plt += model.to_vedo()
self.plt.show() Obviously I've verified that Would appriciate your help. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You probably just need to reset the camera.. Check out this example: import sys
import numpy as np
from PyQt5 import Qt
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vedo import Plotter, Sphere, Cone, printc
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(qt_widget=self.vtkWidget)
self.id1 = self.plt.add_callback("mouse click", self.onMouseClick)
self.id2 = self.plt.add_callback("key press", self.onKeypress)
self.plt += Cone().rotate_x(20)
self.plt.show() # <--- show the vedo rendering
# Set-up the rest of the Qt window
button = Qt.QPushButton("Button adds a Sphere")
button.setToolTip('This is an example button')
button.clicked.connect(self.onClick)
self.layout.addWidget(self.vtkWidget)
self.layout.addWidget(button)
self.frame.setLayout(self.layout)
self.setCentralWidget(self.frame)
self.show() # <--- show the Qt Window
def onMouseClick(self, evt):
printc("You have clicked your mouse button. Event info:\n", evt, c='y')
def onKeypress(self, evt):
printc("You have pressed key:", evt.keypress, c='b')
@Qt.pyqtSlot()
def onClick(self):
printc("..calling onClick")
sphere = Sphere(pos=np.random.rand(3)*10)
sphere.color(np.random.rand(3))
self.plt.add(sphere)
self.plt.reset_camera().render()
def onClose(self):
printc("..calling onClose")
self.vtkWidget.close()
if __name__ == "__main__":
app = Qt.QApplication(sys.argv)
window = MainWindow()
app.aboutToQuit.connect(window.onClose)
app.exec_() |
Beta Was this translation helpful? Give feedback.
You probably just need to reset the camera.. Check out this example: