当前位置:   article > 正文

PyQt PyQt5 Python VTK Qt pyqt5Gui 三维重建,可视化_qt gui显示三维

qt gui显示三维

PyQt  PyQt5  Python VTK  Qt pyqt5Gui  三维重建,可视化;

使用Python 可视化 GUI,需要用到 Qt; 这里是一个简单的例子;

基于 VTK9, pyqt5 ,python3.9

  1. #!/usr/bin/env python3
  2. import sys
  3. # noinspection PyUnresolvedReferences
  4. import vtkmodules.vtkInteractionStyle
  5. # noinspection PyUnresolvedReferences
  6. import vtkmodules.vtkRenderingOpenGL2
  7. import vtk
  8. from PyQt5 import QtCore, QtGui, QtWidgets
  9. #from PyQt5.Qt5.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
  10. from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
  11. from vtkmodules.vtkFiltersSources import vtkSphereSource
  12. from vtkmodules.vtkRenderingCore import (
  13. vtkActor,
  14. vtkPolyDataMapper,
  15. vtkRenderer
  16. )
  17. class MainWindow(QtWidgets.QMainWindow):
  18. def __init__(self, parent=None):
  19. QtWidgets.QMainWindow.__init__(self, parent)
  20. self.frame = QtWidgets.QFrame()
  21. self.vl = QtWidgets.QVBoxLayout()
  22. self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
  23. self.vl.addWidget(self.vtkWidget)
  24. self.ren = vtkRenderer()
  25. self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
  26. self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
  27. # Create source
  28. source = vtkSphereSource()
  29. source.SetCenter(0, 0, 0)
  30. source.SetRadius(5.0)
  31. # Create a mapper
  32. mapper = vtkPolyDataMapper()
  33. mapper.SetInputConnection(source.GetOutputPort())
  34. # Create an actor
  35. actor = vtkActor()
  36. actor.SetMapper(mapper)
  37. self.ren.AddActor(actor)
  38. self.ren.ResetCamera()
  39. self.frame.setLayout(self.vl)
  40. self.setCentralWidget(self.frame)
  41. self.show()
  42. self.iren.Initialize()
  43. if __name__ == "__main__":
  44. app = QtWidgets.QApplication(sys.argv)
  45. window = MainWindow()
  46. sys.exit(app.exec_())

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/746467
推荐阅读
相关标签
  

闽ICP备14008679号