[vtkusers] vtkGL2PSExporter in combination with QVTKRenderWindowInteractor

David Lonie david.lonie at kitware.com
Mon Jun 29 10:23:03 EDT 2015


and the attachment...

On Mon, Jun 29, 2015 at 10:22 AM, David Lonie <david.lonie at kitware.com>
wrote:

> Running the test script works for me -- see attachment, the VTK window is
> on the right, and the svg rendered in chrome on the left.
>
> Some other issues that might be coming into play:
>
> 1) What Qt version are you using, and
> 2) Which OpenGL backend is being used on VTK? (Did you explicitly select
> the experimental OpenGL2 backend while building VTK?)
>
> Dave
>
>
> On Mon, Jun 29, 2015 at 8:54 AM, Stefan Lau <github at stefanlau.com> wrote:
>
>> 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_())
>> _______________________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the VTK FAQ at:
>> http://www.vtk.org/Wiki/VTK_FAQ
>>
>> Search the list archives at: http://markmail.org/search/?q=vtkusers
>>
>> Follow this link to subscribe/unsubscribe:
>> http://public.kitware.com/mailman/listinfo/vtkusers
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150629/6d509698/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qsvg.png
Type: image/png
Size: 35058 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20150629/6d509698/attachment.png>


More information about the vtkusers mailing list