2

A simple example of a python script that renders using paraview.simple is

 from paraview.simple import *                                                  
                                                                                
 sphere = Sphere(ThetaResolution=16, PhiResolution=32)                          
 shrink = Shrink(sphere)                                                        
 Show(shrink)                                                                   
 Render()
 Interact()

Can I add this render to a PyQt5 application in a manner similar to the way I can add the vtk renderer? In vtk, this is acheived with the line

from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

This interactor is added as a widget. Can I e.g. Add paraview simple renderer or interactor as a widget?

DJames
  • 571
  • 3
  • 17

1 Answers1

4

You can supply a render window and interactor when initializing QVTKRenderWindowInteractor, i.e.

import paraview.simple as pvsimple
from vtkmodules.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from PyQt5 import QtWidgets

app = QtWidgets.QApplication([])

# setup render widget
render_view = pvsimple.CreateRenderView()
render_widget = QVTKRenderWindowInteractor(rw=render_view.GetRenderWindow(),
                                           iren=render_view.GetInteractor())
render_widget.Initialize()

# add paraview simple sources/filters
sphere = pvsimple.Sphere(ThetaResolution=16, PhiResolution=32)
shrink = pvsimple.Shrink(sphere)
pvsimple.Show(shrink, render_view)

# show widget
render_widget.show()
app.exec()
Heike
  • 24,102
  • 2
  • 31
  • 45
  • Thanks for the reply. This solution seems to generate two windows: One window renders the sphere, the other window is black and manages the camera controls. Do you know why the camera controls. Do you know why this is? – DJames Sep 29 '20 at 11:13
  • Strange, I get one window which also responds to mouse interactions. Maybe it's a version thing? (I'm using python 3.7.6, paraview 5.8 and PyQt5 5.15.0 on windows 10). – Heike Sep 29 '20 at 12:30