[vtkusers] vtkGL2PSExporter in combination with QVTKRenderWindowInteractor
Stefan Lau
github at stefanlau.com
Mon Jun 29 08:54:47 EDT 2015
Hi,
I'm trying to export an image from my application created in PyQt4 to a
vector image. While the vtkGL2PSExporter works fine from outside my QT
application, when trying to export the image from inside it the output
looks corrupted. A minimal example can be found at the end of this
email. Did I miss something (or call something incorrectly)? Is this a
known issue?
Version: VTK 6.1.0
Thanks for any help,
Stefan Lau
Minimal Example:
#!/usr/bin/env python
import sys
import os
import vtk
from PyQt4 import QtCore, QtGui
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent = None):
QtGui.QMainWindow.__init__(self, parent)
self.frame = QtGui.QFrame()
self.vl = QtGui.QVBoxLayout()
self.vtkWidget = QVTKRenderWindowInteractor(self.frame)
self.vl.addWidget(self.vtkWidget)
self.ren = vtk.vtkRenderer()
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
# Create source
source = vtk.vtkSphereSource()
source.SetCenter(0, 0, 0)
source.SetRadius(5.0)
# Create a mapper
mapper = vtk.vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
# Create an actor
actor = vtk.vtkActor()
actor.SetMapper(mapper)
button = QtGui.QPushButton(self.frame)
button.setGeometry(20, 20, 32, 32)
button.setIcon(QtGui.QIcon.fromTheme('document-save'))
button.setToolTip('Save Visualization')
button.clicked.connect(self.store_visualization)
self.ren.AddActor(actor)
self.ren.ResetCamera()
self.frame.setLayout(self.vl)
self.setCentralWidget(self.frame)
self.show()
self.iren.Initialize()
def store_visualization(self, render_window):
file_name = str(QtGui.QFileDialog.getSaveFileName(
self,
'Save Visualization',
os.path.join(os.getcwd(), '/visualization.svg'),
'SVG-Images (*.svg)'
))
if len(file_name) > 0:
exporter = vtk.vtkGL2PSExporter()
exporter.SetRenderWindow(self.vtkWidget.GetRenderWindow())
exporter.SetFileFormatToSVG()
exporter.CompressOff()
exporter.DrawBackgroundOff()
exporter.SetFilePrefix(os.path.splitext(file_name)[0])
exporter.Write()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())
More information about the vtkusers
mailing list