Search code examples
pythonvtkpoint-clouds

How to draw mouse-rotatable point cloud in python with vtk


I need to draw rotatable point cloud in python, here is what I've found on the net:

import vtk_visualizer as vv
import numpy as np
xyz = np.random.rand(1000, 3)
vtkControl = vv.VTKVisualizerControl()
vtkControl.AddPointCloudActor(xyz)
vtkControl.Render()
vtkControl.ResetCamera()

It shows window for few moments, but then window hides, so I can't rotate it with mouse. How can I fix it?


Solution

  • This is solution, which I've found:

    import vtk_visualizer as vv
    import numpy as np
    import sys
    from PyQt5.QtWidgets import *
    xyz = np.random.rand(1000, 3)
    vtkControl = vv.VTKVisualizerControl()
    vtkControl.AddPointCloudActor(xyz)
    app = QApplication.instance()
    if app is None:
        app = QApplication(sys.argv)
    app.exec_()