[vtkusers] Offscreen rendering on Linux, segmentation fault

Martin Dunschen zabaione at uk2.net
Mon Feb 21 07:35:30 EST 2005


Hi

I am trying to use the offscreen rendering capabilities of VTK in
connection with Mesa. After a bit of work I finally managed to compile a
version of VTK that allows to use mangled Mesa.

I used the latest VTK sources via cvs (as of Saturday19.2.2005), and I
tried the attached code using Mesa version 6 and version 4
(www.mesa3d.org). If I enable offscreen rendering, I get a segmentation
fault. With normal (onscreen) rendering the script works fine.

My Linux is Debian.

Am I doing something wrong?

Any help would be greatly appreciated.

Martin

----------------------------------->8------------------------->8
import vtk
from vtk.util.colors import tomato

class STLPolyData:
        def __init__(self):
                self.points = vtk.vtkPoints()
                self.cells = vtk.vtkCellArray()


        def PushTriangle(self, x0, y0, z0, x1, y1, z1, x2, y2, z2):
                id0 = self.points.InsertNextPoint(x0, y0, z0)
                id1 = self.points.InsertNextPoint(x1, y1, z1)
                id2 = self.points.InsertNextPoint(x2, y2, z2)

                self.cells.InsertNextCell(3)
                self.cells.InsertCellPoint(id0)
                self.cells.InsertCellPoint(id1)
                self.cells.InsertCellPoint(id2)

        def SaveToPNG(self, fname):
                triangles = vtk.vtkPolyData()
                triangles.SetPoints(self.points)
                triangles.SetPolys(self.cells)
                print "triangles"

                mp = vtk.vtkMesaPolyDataMapper()
                mp.SetInput(triangles)
                print "polydatamapper"

                actor = vtk.vtkMesaActor()
                actor.SetMapper(mp)
                actor.GetProperty().SetColor(tomato)
                actor.RotateX(-45.0)
                actor.RotateZ(-30.0)
                print "actor"

                ren = vtk.vtkMesaRenderer()
                ren.AddActor(actor)
                ren.SetBackground(0.1, 0.2, 0.4)
                ren.GetActiveCamera().Zoom(1.5)
                print "renderer"

                renwin = vtk.vtkXMesaRenderWindow()
                renwin.SetOffScreenRendering(0) # set to 1 and the code
wont crash...
                renwin.SetSize(500, 500)
                renwin.AddRenderer(ren)

                filter = vtk.vtkWindowToImageFilter()
                filter.SetInput(renwin)

                writer = vtk.vtkPNGWriter()
                writer.SetInput(filter.GetOutput())
                writer.SetFileName(fname)
                writer.Write()
                print "write"


if __name__ == "__main__":
        stlpd = STLPolyData()
        stlpd.PushTriangle(0., 0., 0., 1., 0., 0., 1., 1., 0.)
        stlpd.SaveToPNG("test.png")




More information about the vtkusers mailing list