简体   繁体   中英

How to implement openvr in vtk python?

I can't make openvr and vtk python work together. Currentrly i'm using spyder ide for this.

I have done some code in C++ with vtk and openvr just changing vtkRenderer to vtkOpenVRRenderer and so on. But it doesn't work in spyder.

import vtk
import openvr


class vtk:   

    colors = vtk.vtkNamedColors()

    reader = vtk.vtkXMLPolyDataReader()
    reader.SetFileName("D:\\UNAM\\MultiBlockDataSet\\Dist\\Distancias_00_0.vtp")
    reader.Update()

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetInputConnection(reader.GetOutputPort())

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)
    actor.GetProperty().SetColor(colors.GetColor3d('Tan'))

    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    ren.SetBackground(colors.GetColor3d('AliceBlue'))

    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    ren.AddActor(actor)

    iren.Initialize()
    renWin.Render()
    ren.GetActiveCamera().SetPosition(-0.5, 0.1, 0.0)
    ren.GetActiveCamera().SetViewUp(0.1, 0.0, 1.0)
    renWin.Render()
    iren.Start()

if __name__ == "__main__":
    vtk()

Check out this post and maybe follow up on the VTK Discourse: https://discourse.vtk.org/t/python-rendering-scene-to-vr/340

EDIT: Here is some more info because linked answers are considered lame.

  1. You'll have to build VTK from source with the OpenVR stuff enabled - that's a whole other discussion
  2. You'll need to replace the following classes:

    • vtkRendererWindow --> vtkOpenVRRenderWindow
    • vtkRenderer --> vtkOpenVRRenderer
    • vtkRenderWindowInteractor --> vtkOpenVRRenderWindowINteractor
    • vtkCamera --> vtkOpenVRCamera

If you have further VTK-related questions, I would highly recommend joining the VTK discourse as it is the most active community around VTK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM