當前位置: 首頁>>代碼示例>>Python>>正文


Python vtk.vtkWindowToImageFilter方法代碼示例

本文整理匯總了Python中vtk.vtkWindowToImageFilter方法的典型用法代碼示例。如果您正苦於以下問題:Python vtk.vtkWindowToImageFilter方法的具體用法?Python vtk.vtkWindowToImageFilter怎麽用?Python vtk.vtkWindowToImageFilter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在vtk的用法示例。


在下文中一共展示了vtk.vtkWindowToImageFilter方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: image

# 需要導入模塊: import vtk [as 別名]
# 或者: from vtk import vtkWindowToImageFilter [as 別名]
def image(self):
        """Return an image array of current render window.

        To retrieve an image after the render window has been closed,
        set: `plotter.store_image = True`
        """
        if not hasattr(self, 'ren_win') and hasattr(self, 'last_image'):
            return self.last_image
        ifilter = vtk.vtkWindowToImageFilter()
        ifilter.SetInput(self.ren_win)
        ifilter.ReadFrontBufferOff()
        if self.image_transparent_background:
            ifilter.SetInputBufferTypeToRGBA()
        else:
            ifilter.SetInputBufferTypeToRGB()
        return self._run_image_filter(ifilter)

    #### Everything else #### 
開發者ID:pyvista,項目名稱:pyvista,代碼行數:20,代碼來源:plotting.py

示例2: screenshot

# 需要導入模塊: import vtk [as 別名]
# 或者: from vtk import vtkWindowToImageFilter [as 別名]
def screenshot(self, filename=None):
        w2if = vtk.vtkWindowToImageFilter()
        w2if.SetInput(self.ren_win)
        w2if.Update()
        if filename is None:
            filename = 'screenshot'
        filename = filename + '%d.png' % self.screenshot_count
        writer = vtk.vtkPNGWriter()
        writer.SetFileName(filename)
        self.screenshot_count += 1
        writer.SetInputData(w2if.GetOutput())
        writer.Write() 
開發者ID:adityadua24,項目名稱:robopy,代碼行數:14,代碼來源:graphics.py

示例3: ScreenShot

# 需要導入模塊: import vtk [as 別名]
# 或者: from vtk import vtkWindowToImageFilter [as 別名]
def ScreenShot(self, filename):
        "Create a screenshot of the visualizer in BMP format"
        win2img = vtk.vtkWindowToImageFilter()
        win2img.SetInput(self.renderWindow)
        win2img.Update()
        bmpWriter = vtk.vtkBMPWriter()
        bmpWriter.SetInput(win2img.GetOutput())
        bmpWriter.SetFileName(filename)
        bmpWriter.Write() 
開發者ID:poodarchu,項目名稱:Det3D,代碼行數:11,代碼來源:visualizercontrol.py

示例4: get_image_depth

# 需要導入模塊: import vtk [as 別名]
# 或者: from vtk import vtkWindowToImageFilter [as 別名]
def get_image_depth(self,
                        fill_value=np.nan,
                        reset_camera_clipping_range=True):
        """Return a depth image representing current render window.

        Parameters
        ----------
        fill_value : float
            Fill value for points in image that don't include objects in scene.
            To not use a fill value, pass ``None``.

        reset_camera_clipping_range : bool
            Reset the camera clipping range to include data in view?

        Return
        ------
        image_depth : numpy.ndarray
            Image of depth values from camera orthogonal to image plane

        Notes
        -----
        Values in image_depth are negative to adhere to a
        right-handed coordinate system.

        """
        if not hasattr(self, 'ren_win') and hasattr(self, 'last_image_depth'):
            zval = self.last_image_depth.copy()
            if fill_value is not None:
                zval[self._image_depth_null] = fill_value
            return zval

        # Ensure points in view are within clipping range of renderer?
        if reset_camera_clipping_range:
            self.renderer.ResetCameraClippingRange()

        # Get the z-buffer image
        ifilter = vtk.vtkWindowToImageFilter()
        ifilter.SetInput(self.ren_win)
        ifilter.ReadFrontBufferOff()
        ifilter.SetInputBufferTypeToZBuffer()
        zbuff = self._run_image_filter(ifilter)[:, :, 0]

        # Convert z-buffer values to depth from camera
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore')
            near, far = self.camera.GetClippingRange()
            if self.camera.GetParallelProjection():
                zval = (zbuff - near) / (far - near)
            else:
                zval = 2 * near * far / ((zbuff - 0.5) * 2 * (far - near) - near - far)

            # Consider image values outside clipping range as nans
            args = np.logical_or(zval < -far, np.isclose(zval, -far))
        self._image_depth_null = args
        if fill_value is not None:
            zval[args] = fill_value

        return zval 
開發者ID:pyvista,項目名稱:pyvista,代碼行數:60,代碼來源:plotting.py

示例5: vis_with_renderer

# 需要導入模塊: import vtk [as 別名]
# 或者: from vtk import vtkWindowToImageFilter [as 別名]
def vis_with_renderer(renderer):
    # Renderer

    # renderer.SetBackground(.2, .3, .4)
    renderer.SetBackground(1, 1, 1)
    renderer.ResetCamera()

    transform = vtk.vtkTransform()
    transform.Translate(1.0, 0.0, 0.0)
    axes = vtk.vtkAxesActor()
    renderer.AddActor(axes)

    # Render Window
    renderWindow = vtk.vtkRenderWindow()
    renderWindow.AddRenderer(renderer)

    # Interactor
    renderWindowInteractor = vtk.vtkRenderWindowInteractor()
    renderWindowInteractor.SetRenderWindow(renderWindow)

    def get_camera_info(obj, ev):
        if renderWindowInteractor.GetKeyCode() == "s":
            w2if = vtk.vtkWindowToImageFilter()
            w2if.SetInput(renderWindow)
            w2if.Update()

            writer = vtk.vtkPNGWriter()
            writer.SetFileName("screenshot.png")
            if vtk.VTK_MAJOR_VERSION == 5:
                writer.SetInput(w2if.GetOutput())
            else:
                writer.SetInputData(w2if.GetOutput())
            writer.Write()
            print "screenshot saved"

    style = vtk.vtkInteractorStyleSwitch()
    renderWindowInteractor.SetInteractorStyle(style)
    # style.SetCurrentStyleToTrackballActor()
    style.SetCurrentStyleToTrackballCamera()

    # Begin Interaction
    renderWindowInteractor.AddObserver(vtk.vtkCommand.KeyPressEvent, get_camera_info, 1)
    renderWindow.Render()
    renderWindowInteractor.Start() 
開發者ID:mfxox,項目名稱:ILCC,代碼行數:46,代碼來源:utility.py

示例6: vtk_basic

# 需要導入模塊: import vtk [as 別名]
# 或者: from vtk import vtkWindowToImageFilter [as 別名]
def vtk_basic( actors, embed=False, magnification=1.0 ):
    """
    Create a window, renderer, interactor, add the actors and start the thing
    
    Parameters
    ----------
    actors :  list of vtkActors
    
    Returns
    -------
    nothing
    """     
    
    # create a rendering window and renderer
    ren = vtk.vtkRenderer()
    renWin = vtk.vtkRenderWindow()
    renWin.AddRenderer(ren)
    renWin.SetSize(600,600)
    # ren.SetBackground( 1, 1, 1)
 
    # create a renderwindowinteractor
    iren = vtk.vtkRenderWindowInteractor()
    iren.SetRenderWindow(renWin)

    for a in actors:

        move( a, np.dot(Ry(-180),Rx(-180)) )
        
        # assign actor to the renderer
        ren.AddActor(a )
    
    # render
    renWin.Render()

    if embed:
        renWin.SetSize(300,300)
        grabber = vtk.vtkWindowToImageFilter()
        grabber.SetInput( renWin )
        grabber.SetMagnification( magnification )
        grabber.Update()
        
        writer = vtk.vtkPNGWriter()
        writer.SetInput( grabber.GetOutput() )
        writer.SetFileName( "screenshot.png" )
        writer.Write()
        return display.Image("screenshot.png")
    else:   
        # enable user interface interactor
        iren.Initialize()
        iren.Start() 
開發者ID:curiale,項目名稱:Medical-Image-Analysis-IPython-Tutorials,代碼行數:52,代碼來源:volumerendering.py


注:本文中的vtk.vtkWindowToImageFilter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。