我有一个 VTK 卷,我想在 OpenGL 中可视化,如本例所示。
如果我理解正确,则会初始化一个 GLUT 窗口,并通过使用 ExternalVTKWidget 完成 OpenGL 中的渲染,但我似乎无法在 Python 中找到它的等价物。有人可以指导/指向正确的方向,或者举一个将 VTK 数据传递到 OpenGL 窗口的示例吗?
这是我目前拥有的代码:
from OpenGL.GL import*
from OpenGL.GLU import*
from OpenGL.GLUT import*
import sys
import math
import vtkmodules.vtkInteractionStyle
import vtkmodules.vtkRenderingOpenGL2
from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkRenderingCore import (
vtkActor,
vtkPolyDataMapper,
vtkRenderWindow,
vtkRenderer,
vtkRenderWindowInteractor
)
def plotpoints():
colors = vtkNamedColors()
cone = vtkConeSource()
cone.SetHeight(3.0)
cone.SetRadius(1.0)
cone.SetResolution(10)
coneMapper = vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtkActor()
coneActor.SetMapper(coneMapper)
coneActor.GetProperty().SetColor(colors.GetColor3d('MistyRose'))
ren1 = vtkExternalOpenGLRenderWindow()
ren1.AddActor(coneActor)
ren1.SetBackground(colors.GetColor3d('MidnightBlue'))
ren1.Render()
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow(renWin)
interactor.Start()
def main():
glutInit(sys.argv)
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB)
glutInitWindowSize(500,500)
glutInitWindowPosition(50,50)
glutCreateWindow("Plot Cone")
glutDisplayFunc(plotpoints)
glutIdleFunc(plotpoints)
glutMainLoop()
main()