Ejemplo n.º 1
0
    def build_vtk_renderer(self):

        # offscreen rendering
        if (vtk.vtkVersion().GetVTKMajorVersion() == 5.0):
            graphics_factory = vtk.vtkGraphicsFactory()
            graphics_factory.SetOffScreenOnlyMode( 1);
            graphics_factory.SetUseMesaClasses( 1 );
            imaging_factory = vtk.vtkImagingFactory()
            imaging_factory.SetUseMesaClasses( 1 );
  
        self.renderer = vtk.vtkRenderer()
        self.renderer.SetBackground(1, 1, 1)
        self.render_window = vtk.vtkRenderWindow()
        # offscreen rendering
        self.render_window.SetOffScreenRendering(1)

        self.render_window.AddRenderer(self.renderer)
        # create a renderwindowinteractor
        #if self.interact:
        #self.iren = vtk.vtkRenderWindowInteractor()
        #self.iren.SetRenderWindow(self.render_window)

        # scalar bar        
        self.scalarbar = vtk.vtkScalarBarActor()
        # To avoid uninitialized warning in VTK 6
        self.scalarbar.SetTitle("") 
        # black text since background is white for printing
        self.scalarbar.GetLabelTextProperty().SetColor(0, 0, 0)
        self.scalarbar.GetTitleTextProperty().SetColor(0, 0, 0)
Ejemplo n.º 2
0
    def build_vtk_renderer(self):

        # offscreen rendering
        if (vtk.vtkVersion().GetVTKMajorVersion() == 5.0):
            graphics_factory = vtk.vtkGraphicsFactory()
            graphics_factory.SetOffScreenOnlyMode( 1);
            graphics_factory.SetUseMesaClasses( 1 );
            imaging_factory = vtk.vtkImagingFactory()
            imaging_factory.SetUseMesaClasses( 1 );
  
        self.renderer = vtk.vtkRenderer()
        self.renderer.SetBackground(1, 1, 1)
        self.render_window = vtk.vtkRenderWindow()
        # offscreen rendering
        self.render_window.SetOffScreenRendering(1)

        self.render_window.AddRenderer(self.renderer)
        # create a renderwindowinteractor
        #if self.interact:
        #self.iren = vtk.vtkRenderWindowInteractor()
        #self.iren.SetRenderWindow(self.render_window)

        # scalar bar        
        self.scalarbar = vtk.vtkScalarBarActor()
        # To avoid uninitialized warning in VTK 6
        self.scalarbar.SetTitle("") 
        # black text since background is white for printing
        self.scalarbar.GetLabelTextProperty().SetColor(0, 0, 0)
        self.scalarbar.GetTitleTextProperty().SetColor(0, 0, 0)
Ejemplo n.º 3
0
def set_off_screen_rendering(window):
    'Turn on off-screen rendering, if available'
    gfx_factory = vtk.vtkGraphicsFactory()
    gfx_factory.SetOffScreenOnlyMode(1)
    gfx_factory.SetUseMesaClasses(1)

    img_factory = vtk.vtkImagingFactory()
    img_factory.SetUseMesaClasses(1)

    window.SetOffScreenRendering(1)
Ejemplo n.º 4
0
    def gen_mesh_probe_png(self, probe, png_filename):
        """
        Generate PNG image of the FE mesh.

        Parameters
        ----------
        probe : VTK objectstr
            The probe, VTKPolyData or VTKSource.
        png_filename : str
            The name of the output PNG file.
        """

        surface = vtk.vtkDataSetSurfaceFilter()
        if vtk_version < 6:
            surface.SetInput(self.vtkdata)

        else:
            surface.SetInputData(self.vtkdata)

        surface.Update()

        gf = vtk.vtkGraphicsFactory()
        gf.SetOffScreenOnlyMode(1)
        gf.SetUseMesaClasses(1)

        ifa = vtk.vtkImagingFactory()
        ifa.SetUseMesaClasses(1)

        mapper = vtk.vtkPolyDataMapper()
        if vtk_version < 6:
            mapper.SetInput(surface.GetOutput())

        else:
            mapper.SetInputData(surface.GetOutput())

        mapper.SetScalarModeToUseCellData()

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetOpacity(0.33)

        mapper2 = vtk.vtkPolyDataMapper()
        if hasattr(probe, 'GetOutput'):
            probe0 = probe.GetOutput()

        else:
            probe0 = probe

        if vtk_version < 6:
            mapper2.SetInput(probe0)

        else:
            mapper2.SetInputData(probe0)

        actor2 = vtk.vtkActor()
        actor2.SetMapper(mapper2)
        actor2.GetProperty().SetColor(0,0,0)
        actor2.GetProperty().SetLineWidth(2)
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetOffScreenRendering(1)
        renWin.AddRenderer(ren)
        ren.AddActor(actor)
        ren.AddActor(actor2)
        ren.SetBackground(1, 1, 1)
        renWin.Render()

        image = vtk.vtkWindowToImageFilter()
        image.SetInput(renWin)
        image.Update()

        writer = vtk.vtkPNGWriter()
        writer.SetFileName(png_filename)
        if vtk_version < 6:
            writer.SetInput(image.GetOutput())

        else:
            writer.SetInputData(image.GetOutput())

        writer.Write()
Ejemplo n.º 5
0
def gen_shot(vtk_filename, png_filename):
    """
    Generate PNG image of the FE mesh.

    Parameters
    ----------
    vtk_filename : str
        The input mesh filename (file in VTK format).

    png_filename : str
        The name of the output PNG file.
    """

    reader = vtk.vtkUnstructuredGridReader()
    reader.SetFileName(vtk_filename)
    reader.Update()
    bnd = reader.GetOutput().GetPoints().GetBounds()

    surface0 = vtk.vtkDataSetSurfaceFilter()
    surface0.SetInput(reader.GetOutput())
    surface0.Update()

    if abs(bnd[5] - bnd[4]) > 1.0e-12:
        tr = vtk.vtkTransform()
        tr.RotateWXYZ(45, 1, 1, 1)

        trFilter = vtk.vtkTransformPolyDataFilter()
        trFilter.SetTransform(tr)
        trFilter.SetInputConnection(surface0.GetOutputPort())
        trFilter.Update()
        surface = trFilter

    else:
        surface = surface0

    ca, cb = surface.GetOutput().GetCellData().GetScalars().GetRange()

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(0.667, 0.667)
    lut.SetSaturationRange(0.0, 1.0)
    lut.SetValueRange(0.8, 1.0)
    lut.SetAlphaRange(1.0, 1.0)
    lut.SetTableRange(ca, cb)

    gf = vtk.vtkGraphicsFactory()
    gf.SetOffScreenOnlyMode(1)
    gf.SetUseMesaClasses(1)

    ifa = vtk.vtkImagingFactory()
    ifa.SetUseMesaClasses(1)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetLookupTable(lut)
    mapper.SetScalarRange(ca, cb)
    mapper.SetInput(surface.GetOutput())
    mapper.SetScalarModeToUseCellData()

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    mapper2 = vtk.vtkPolyDataMapper()
    mapper2.SetInput(surface.GetOutput())
    actor2 = vtk.vtkActor()
    actor2.SetMapper(mapper2)
    actor2.GetProperty().SetRepresentationToWireframe()

    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.SetOffScreenRendering(1)
    renWin.AddRenderer(ren)
    ren.AddActor(actor)
    ren.AddActor(actor2)
    renWin.Render()

    image = vtk.vtkWindowToImageFilter()
    image.SetInput(renWin)
    image.Update()

    base, _ = os.path.splitext(vtk_filename)
    writer = vtk.vtkPNGWriter()
    writer.SetFileName(png_filename)
    writer.SetInput(image.GetOutput())
    writer.Write()
Ejemplo n.º 6
0
def gen_shot(vtk_filename, png_filename):
    """
    Generate PNG image of the FE mesh.

    Parameters
    ----------
    vtk_filename : str
        The input mesh filename (file in VTK format).

    png_filename : str
        The name of the output PNG file.
    """

    reader = vtk.vtkUnstructuredGridReader()
    reader.SetFileName(vtk_filename)
    reader.Update()
    bnd = reader.GetOutput().GetPoints().GetBounds()

    surface0 = vtk.vtkDataSetSurfaceFilter()
    surface0.SetInput(reader.GetOutput())
    surface0.Update()

    if abs(bnd[5] - bnd[4]) > 1.0e-12:
        tr = vtk.vtkTransform()
        tr.RotateWXYZ(45,1,1,1)

        trFilter = vtk.vtkTransformPolyDataFilter()
        trFilter.SetTransform(tr)
        trFilter.SetInputConnection(surface0.GetOutputPort())
        trFilter.Update()
        surface = trFilter

    else:
        surface = surface0

    ca,cb = surface.GetOutput().GetCellData().GetScalars().GetRange()

    lut = vtk.vtkLookupTable()
    lut.SetHueRange(0.667, 0.667)
    lut.SetSaturationRange(0.0, 1.0)
    lut.SetValueRange(0.8, 1.0)
    lut.SetAlphaRange(1.0, 1.0)
    lut.SetTableRange(ca,cb)

    gf = vtk.vtkGraphicsFactory()
    gf.SetOffScreenOnlyMode(1)
    gf.SetUseMesaClasses(1)

    ifa = vtk.vtkImagingFactory()
    ifa.SetUseMesaClasses(1)

    mapper = vtk.vtkPolyDataMapper()
    mapper.SetLookupTable(lut)
    mapper.SetScalarRange(ca,cb);
    mapper.SetInput(surface.GetOutput())
    mapper.SetScalarModeToUseCellData()

    actor = vtk.vtkActor()
    actor.SetMapper(mapper)

    mapper2 = vtk.vtkPolyDataMapper()
    mapper2.SetInput(surface.GetOutput())
    actor2 = vtk.vtkActor()
    actor2.SetMapper(mapper2)
    actor2.GetProperty().SetRepresentationToWireframe()

    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.SetOffScreenRendering(1)
    renWin.AddRenderer(ren)
    ren.AddActor(actor)
    ren.AddActor(actor2)
    renWin.Render()

    image = vtk.vtkWindowToImageFilter()
    image.SetInput(renWin)
    image.Update()

    base, _ = os.path.splitext(vtk_filename)
    writer = vtk.vtkPNGWriter()
    writer.SetFileName(png_filename)
    writer.SetInput(image.GetOutput())
    writer.Write()
Ejemplo n.º 7
0
    def gen_mesh_probe_png(self, probe, png_filename):
        """
        Generate PNG image of the FE mesh.

        Parameters
        ----------
        probe : VTK objectstr
            The probe, VTKPolyData or VTKSource.
        png_filename : str
            The name of the output PNG file.
        """

        surface = vtk.vtkDataSetSurfaceFilter()
        if vtk_version < 6:
            surface.SetInput(self.vtkdata)

        else:
            surface.SetInputData(self.vtkdata)

        surface.Update()

        gf = vtk.vtkGraphicsFactory()
        gf.SetOffScreenOnlyMode(1)
        gf.SetUseMesaClasses(1)

        ifa = vtk.vtkImagingFactory()
        ifa.SetUseMesaClasses(1)

        mapper = vtk.vtkPolyDataMapper()
        if vtk_version < 6:
            mapper.SetInput(surface.GetOutput())

        else:
            mapper.SetInputData(surface.GetOutput())

        mapper.SetScalarModeToUseCellData()

        actor = vtk.vtkActor()
        actor.SetMapper(mapper)
        actor.GetProperty().SetOpacity(0.33)

        mapper2 = vtk.vtkPolyDataMapper()
        if hasattr(probe, 'GetOutput'):
            probe0 = probe.GetOutput()

        else:
            probe0 = probe

        if vtk_version < 6:
            mapper2.SetInput(probe0)

        else:
            mapper2.SetInputData(probe0)

        actor2 = vtk.vtkActor()
        actor2.SetMapper(mapper2)
        actor2.GetProperty().SetColor(0,0,0)
        actor2.GetProperty().SetLineWidth(2)
        ren = vtk.vtkRenderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetOffScreenRendering(1)
        renWin.AddRenderer(ren)
        ren.AddActor(actor)
        ren.AddActor(actor2)
        ren.SetBackground(1, 1, 1)
        renWin.Render()

        image = vtk.vtkWindowToImageFilter()
        image.SetInput(renWin)
        image.Update()

        writer = vtk.vtkPNGWriter()
        writer.SetFileName(png_filename)
        if vtk_version < 6:
            writer.SetInput(image.GetOutput())

        else:
            writer.SetInputData(image.GetOutput())

        writer.Write()
Ejemplo n.º 8
0
# boy do *I* feel old fashioned writing it this way
# surely there's another way to do it: - something to do later
for i in range(len(x)):
    for j in range(len(y)):
	z[i,j] = x[i]*exp(-x[i]*x[i] - y[j]*y[j])


import vtk

interactive = True

if not interactive:
    _factGraphics = vtk.vtkGraphicsFactory()
    _factGraphics.SetUseMesaClasses(1)
    _factImage = vtk.vtkImagingFactory()
    _factImage.SetUseMesaClasses(1)

# set up the renderer and the render window
_ren = vtk.vtkRenderer()
_renWin = vtk.vtkRenderWindow()
_renWin.AddRenderer(_ren)
_renWin.SetSize(640,480)
if not interactive:
    _renWin.OffScreenRenderingOn()

# set up the points
_points = vtk.vtkPoints()
_points.SetNumberOfPoints(len(x))
_index = 0
for i in range(len(x)):