[vtkusers] vtkGL2PSExporter in combination with QVTKRenderWindowInteractor

Stefan Lau github at stefanlau.com
Mon Jun 29 09:07:28 EDT 2015


Hi all,

I'm trying to export an image from my application that is written in 
PyQt4 to SVG.
Since I want to get a vector graphic im using vtkGL2PSExporter for this 
purpose.
Outside of PyQt4 I can export an SVG without any issues (I tried it by 
exporting an
image from an example). When I'm trying to export the vtkRenderWindow that I
get from QVTKRenderWindowInteractor.GetRenderWindow() the output is 
corrupted
though. Some of the Elements get rendered correctly (i.e. a vtkScale) 
others just
look randomly distorted. The same happens when I run a minimal example 
(attached
to this mail).

Did anyone experience this as well? Do I call something wrong?

I appreciate any help.

Thanks,
Stefan


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):
         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_())

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150629/927f32a9/attachment.html>


More information about the vtkusers mailing list