[vtkusers] Rendering and saving unstructured grid mesh to image file
Amine Aboufirass
amine.aboufirass at gmail.com
Tue Mar 6 07:29:02 EST 2018
Dear all,
I have an unstructured grid cell data file which I would like to render and
then save to a png image. I made use of available examples to generate a
python code which I have attached below. The file I am using this with is
also attached. The rendering seems to work but I am not sure why it cannot
send the render window content to an image. It keeps giving me the
following error:
�!: libpng warning: Image width is zero in IHDR
�!: libpng warning: Image height is zero in IHDR
I'm not sure what is causing this, I followed the documentation to the best
of my ability but still can't figure it out. Could anyone please help?
Thanks
Amine
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180306/42637413/attachment-0001.html>
-------------- next part --------------
from vtk import *
# The source file
file_name = 'MeshData.vtk'#"MeshData.vtk"
# Read the source file.
reader = vtkUnstructuredGridReader()
reader.SetFileName(file_name)
reader.Update() # Needed because of GetScalarRange
output = reader.GetOutput()
#scalar_range = output.GetScalarRange()
# Create the mapper that corresponds the objects of the vtk file
# into graphics elements
mapper = vtkDataSetMapper()
mapper.SetInputData(output)
#mapper.SetScalarRange(scalar_range)
# Create the Actor
actor = vtkActor()
actor.GetProperty().SetRepresentationToWireframe()
actor.SetMapper(mapper)
# Create the Renderer
renderer = vtkRenderer()
renderer.AddActor(actor)
renderer.SetBackground(1, 1, 1) # Set background to white
# Create the RendererWindow
renderer_window = vtkRenderWindow()
renderer_window.AddRenderer(renderer)
#Image https://www.vtk.org/Wiki/VTK/Examples/Python/Screenshot
w2if = vtk.vtkWindowToImageFilter()
w2if.SetInput(renderer_window)
w2if.Update()
writer = vtk.vtkPNGWriter()
writer.SetFileName("screenshot.png")
writer.SetInputData(w2if.GetOutput())
writer.Write()
# Create the RendererWindowInteractor and display the vtk_file
#interactor = vtkRenderWindowInteractor()
#interactor.SetRenderWindow(renderer_window)
#interactor.Initialize()
#interactor.Start()
#
-------------- next part --------------
A non-text attachment was scrubbed...
Name: MeshData.vtk
Type: application/octet-stream
Size: 566142 bytes
Desc: not available
URL: <https://vtk.org/pipermail/vtkusers/attachments/20180306/42637413/attachment-0001.obj>
More information about the vtkusers
mailing list