• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vtk.vtkWindowToImageFilter函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vtk.vtkWindowToImageFilter函数的典型用法代码示例。如果您正苦于以下问题:Python vtkWindowToImageFilter函数的具体用法?Python vtkWindowToImageFilter怎么用?Python vtkWindowToImageFilter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了vtkWindowToImageFilter函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: save_image

 def save_image(self):
     
     from vtk import vtkJPEGWriter, vtkJPEGWriter, vtkPNGWriter
     from vtk import vtkPNMWriter, vtkWindowToImageFilter
     from os import path
      
     sourcebase, _ = path.splitext(self.source)
     fname = sourcebase+'%05g.png' % self.frameNumber
     #print fname
     
     extmap = {'.jpg' : vtkJPEGWriter,
               '.jpeg' : vtkJPEGWriter,
               '.png' : vtkPNGWriter,
               '.pnm' : vtkPNMWriter,
               }
     basename, ext = path.splitext(fname)
     try: Writer = extmap[ext.lower()]
     except KeyError:
         error_msg("Don't know how to handle %s files" % ext, parent=self)
         return
 
     renWin = self.vtk_renderer.GetRenderWindow()
     w2i = vtkWindowToImageFilter()
     writer = Writer()
     w2i.SetInput(renWin)
     w2i.Update()
     writer.SetInput(w2i.GetOutput())
     writer.SetFileName(fname)
     renWin.Render()
     writer.Write()        
开发者ID:MattAndersonPE,项目名称:anuga_core,代码行数:30,代码来源:offline.py


示例2: WriteImage

    def WriteImage(self, m_outFileName="./Dump/tmp.png", m_dimension=[400, 400]):
        """
        Write current renderer to a png file. For Debug

        :param m_outFileName:   [str] Output name of the file, can be directory name. Default="./Dump/tmp.png"
        :param m_dimension:     [x, y]. Dimension, i.e. width and height of the image file.
        :return:
        """
        if self._renderer.GetRenderWindow() == None:
            self._renderWindow.AddRenderer(self._renderer)

        elif self._renderer.GetRenderWindow() != self._renderWindow:
            self._renderer.GetRenderWindow().Finalize()
            self._renderWindow = vtk.vtkRenderWindow()
            self._renderWindow.AddRenderer(self._renderer)
        else:
            self._renderWindow = vtk.vtkRenderWindow()
            self._renderWindow.AddRenderer(self._renderer)

        self._renderWindow.SetOffScreenRendering(1)
        self._renderWindow.SetSize(m_dimension)
        self._renderWindow.Render()
        self._renderWindow.SetAAFrames(10)

        m_writer = vtk.vtkPNGWriter()
        m_wintoim = vtk.vtkWindowToImageFilter()
        m_wintoim.SetInput(self._renderWindow)
        m_wintoim.Update()

        m_writer.SetInputConnection(m_wintoim.GetOutputPort())
        m_writer.SetFileName(m_outFileName)
        m_writer.Write()

        pass
开发者ID:teracamo,项目名称:vtkSemiUniformGridding,代码行数:34,代码来源:PolyDataHandler.py


示例3: output_screenshot

    def output_screenshot(self, screenshot_fname):
        """
        Saves scene rendered in the renderer to the image
        :param ren: {vtkRenderer} renderer
        :param screenshot_fname: {str} screenshot filename
        :return: None
        """

        ren = self.get_renderer()
        renWin = vtk.vtkRenderWindow()
        renWin.SetOffScreenRendering(1)
        renWin.AddRenderer(ren)
        renWin.Render()

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

        writer = vtk.vtkPNGWriter()
        # writer.SetFileName('D:/CC3D_GIT/CompuCell3D/player5/GraphicsOffScreen/{screenshot_name}.png'.format(
        #     screenshot_name=screenshot_fname))
        writer.SetFileName(screenshot_fname)

        writer.SetInputConnection(windowToImageFilter.GetOutputPort())
        writer.Write()
开发者ID:CompuCell3D,项目名称:CompuCell3D,代码行数:25,代码来源:GenericDrawer.py


示例4: OnExport

    def OnExport(self, event):
        """Export to graphics filetype with extension ext."""
        renWin = self.widget.GetRenderWindow()
        wif = vtk.vtkWindowToImageFilter()
        wif.SetInput(renWin)

        wildcard = "PNG (*.png)|*.png|" \
            "Postscript (*.ps)|*.ps|" \
            "JPEG (*.jpg)|*.jpg"
            # "TIFF (*.tif)|*.tif"
        dialog = wx.FileDialog(None, "Export Graphics", os.getcwd(),
                               "", wildcard, wx.SAVE|wx.OVERWRITE_PROMPT)
        if dialog.ShowModal() == wx.ID_OK:
            path = dialog.GetPath()
            base, ext = os.path.splitext(path)
            if ext in ['.png', '.ps', '.jpg']:
                pass
            else:
                i = dialog.GetFilterIndex()
                ext = ['.png', '.ps', '.jpg'][i]
            # cases
            if ext == '.png':
                psw = vtk.vtkPNGWriter()
            elif ext == '.ps':
                psw = vtk.vtkPostScriptWriter()
            elif ext == '.jpg':
                psw = vtk.vtkJPEGWriter()
            psw.SetFileName(base + ext)
            psw.SetInput(wif.GetOutput())
            psw.Write()
开发者ID:cliburn,项目名称:flow,代码行数:30,代码来源:Main.py


示例5: __init__

 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkWindowToImageFilter(), 'Processing.',
         (), ('vtkImageData',),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
开发者ID:fvpolpeta,项目名称:devide,代码行数:7,代码来源:vtkWindowToImageFilter.py


示例6: captureImageFromView

  def captureImageFromView(self, view, filename):
    view.forceRender()
    # qt.QPixmap().grabWidget(...) would not grab the background
    rw = view.renderWindow()
    wti = vtk.vtkWindowToImageFilter()
    wti.SetInput(rw)
    wti.Update()
    writer = vtk.vtkPNGWriter()
    writer.SetFileName(filename)
    outputImage = wti.GetOutput()
    imageSize = outputImage.GetDimensions()

    if imageSize[0]<2 or imageSize[1]<2:
      # image is too small, most likely it is invalid
      raise ValueError('Capture image from view failed')

    # Make sure image witdth and height is even, otherwise encoding may fail
    imageWidthOdd = (imageSize[0] & 1 == 1)
    imageHeightOdd = (imageSize[1] & 1 == 1)
    if imageWidthOdd or imageHeightOdd:
      imageClipper = vtk.vtkImageClip()
      imageClipper.SetInputConnection(wti.GetOutputPort())
      extent = outputImage.GetExtent()
      imageClipper.SetOutputWholeExtent(extent[0], extent[1]-1 if imageWidthOdd else extent[1],
                                        extent[2], extent[3]-1 if imageHeightOdd else extent[3],
                                        extent[4], extent[5])
      writer.SetInputConnection(imageClipper.GetOutputPort())
    else:
      writer.SetInputConnection(wti.GetOutputPort())

    writer.Write()
开发者ID:MayeulChassagnard,项目名称:Slicer,代码行数:31,代码来源:ScreenCapture.py


示例7: get_image

 def get_image(self):
   converter = vtk.vtkWindowToImageFilter()
   converter.SetInput(self.render_window)
   converter.ReadFrontBufferOff()
   converter.Update()
   im = vtk_to_numpy(converter.GetOutput().GetPointData().GetScalars())
   return np.flipud(im.reshape(self.height, self.width, im.shape[-1]))
开发者ID:wrlife,项目名称:Colon3D,代码行数:7,代码来源:VTKViewer.py


示例8: renWriteJPEG

def renWriteJPEG(ren,args):
  #@c Save the current window image to a file
  #@c in jpeg format.  If no filename is specified,
  #@c then an interactive window is popped up asking
  #@c for a name to be given.
  #@a ren: renderer
  #@a args: filename
    if (args ==""):
        filename = raw_input("Please enter image name to save")
    else:
        filename = args
        
    if (filename ==""):
        return
        
    jwriter = vtk.vtkJPEGWriter()
    jwriter.ProgressiveOff()
    jwriter.SetQuality(95)
    ren.GetRenderWindow().Render()
    
    w2i = vtk.vtkWindowToImageFilter()
    w2i.SetInput(ren.GetRenderWindow())
    w2i.Update()
    
    jwriter.SetInput(w2i.GetOutput())
    jwriter.SetFileName(filename)
    jwriter.Write()
    
    del w2i
    del jwriter
    return 
开发者ID:gmaher,项目名称:SimVascular,代码行数:31,代码来源:renfun.py


示例9: save_png

 def save_png (self, file_name=""):
     """Requires VTK 4 to work."""
     debug ("In RenderWindow::save_png ()")
     try:
         ex = vtk.vtkPNGWriter ()
     except AttributeError:
         msg = "Saving to a PNG file is not supported by your "\
               "version of VTK.  Versions 4.0 and above support this."
         Common.print_err (msg)
         return
     if not file_name:
         file_name = tk_fsave (title="Export to PNG image",
                               initialdir=Common.config.initial_dir,
                               defaultextension=".png",
                               filetypes=[("PNG images", "*.png"),
                                          ("All files", "*")])
     if len (file_name) != 0:
         Common.state.busy ()
         w2if = vtk.vtkWindowToImageFilter ()
         w2if.SetMagnification (Common.config.magnification)
         self.lift ()
         w2if.SetInput (self.renwin)
         ex = vtk.vtkPNGWriter ()
         ex.SetFileName (file_name)
         ex.SetInput (w2if.GetOutput ())
         ex.Write () 
         Common.state.idle ()
开发者ID:sldion,项目名称:DNACC,代码行数:27,代码来源:RenderWindow.py


示例10: writeJPEG

 def writeJPEG(self, fn):
     filter = vtk.vtkWindowToImageFilter()
     filter.SetInput(self.ren_win)
     writer = vtk.vtkJPEGWriter()
     writer.SetInput(filter.GetOutput())
     writer.SetFileName(fn)
     writer.Write()
开发者ID:argreiner,项目名称:sympler,代码行数:7,代码来源:sympler_viewer.py


示例11: png

  def png(self, file, width=None,height=None,units=None,draw_white_background = 0):
        
        if self.renWin is None:
          raise Exception,"Nothing to dump aborting"
            
        if not file.split('.')[-1].lower() in ['png']:
            file+='.png'

        try:
          os.remove(file)
        except:
          pass

        if width is not None and height is not None:
          self.renWin.SetSize(width,height)
          #self.renWin.Render()
        imgfiltr = vtk.vtkWindowToImageFilter()
        imgfiltr.SetInput(self.renWin)
#        imgfiltr.SetMagnification(3)
        imgfiltr.SetInputBufferTypeToRGBA()
        imgfiltr.Update()
        writer = vtk.vtkPNGWriter()
        writer.SetInputConnection(imgfiltr.GetOutputPort())
        writer.SetFileName(file)
        writer.Write()
开发者ID:charlesdoutriaux,项目名称:uvcdat-devel,代码行数:25,代码来源:VTKPlots.py


示例12: notebookviz

def notebookviz(output):
        width,height = 400, 300
        demMapper = vtkPolyDataMapper()
        demMapper.SetInputConnection(output.GetOutputPort())

        surfaceActor = vtkActor()
        surfaceActor.SetMapper(demMapper)
        surfaceActor.GetProperty().SetDiffuseColor(1.0000, 0.3882, 0.2784)
        surfaceActor.GetProperty().SetSpecularColor(1, 1, 1)
        surfaceActor.GetProperty().SetSpecular(.4)
        surfaceActor.GetProperty().SetSpecularPower(50)

        VtkRenderer = vtkRenderer()
        VtkRenderer.SetBackground(1.0, 1.0, 1.0)
        VtkRenderer.AddActor(surfaceActor)

        renderWindow = vtkRenderWindow()
        renderWindow.SetOffScreenRendering(1)
        renderWindow.AddRenderer(VtkRenderer)
        renderWindow.SetSize(width, height)
        renderWindow.Render()

        windowToImageFilter = vtkWindowToImageFilter()
        windowToImageFilter.SetInput(renderWindow)
        windowToImageFilter.Update()

        writer = vtkPNGWriter()
        writer.SetWriteToMemory(1)
        writer.SetInputConnection(windowToImageFilter.GetOutputPort())
        writer.Write()
        data = str(buffer(writer.GetResult()))

        return Image(data)
开发者ID:kezilu,项目名称:pextant,代码行数:33,代码来源:utils.py


示例13: save

    def save(self, frames, outfile='animated.mp4'):
        '''
        takes a snapshot of the frames at given t, and returns the paths
        '''
        windowToImage = vtk.vtkWindowToImageFilter()
        windowToImage.SetInput(self.renWin)
        writer = vtk.vtkPNGWriter()
        writer.SetInput(windowToImage.GetOutput())

        slide_paths = []
        for t in frames:
            # f = NamedTemporaryFile(suffix='.png', delete=False)
            f = open("img{:0>3}.png".format(t), 'w')
            self.update_all(t=t)
            windowToImage.Modified()
            writer.SetFileName(f.name)
            writer.Write()
            slide_paths.append( f.name )

        if len(slide_paths)==1:
            if not outfile.endswith('.png'):
                raise Exception("Cannot save single snapshot videos")
            call(["mv","img000.png",outfile])
        elif outfile.endswith('.mp4'):
            call(["rm","-f", outfile])
            call(["/usr/local/bin/ffmpeg",
                    "-i","img%03d.png",
                    "-c:v","libx264","-r","30",
                    "-pix_fmt","yuv420p", outfile])
            call(["rm"]+slide_paths)
开发者ID:RodericDay,项目名称:MiniPNM,代码行数:30,代码来源:graphics.py


示例14: flush_render_buffer

def flush_render_buffer():
    '''When running as a single process use the WindowToImage filter to
    force a framebuffer read.  This bypasses driver optimizations that
    perform lazy rendering and allows you to get actual frame rates for
    a single process with a GPU.  Multi-process doesn't need this since
    compositing forces the frame buffer read.
    '''

    # If we're not using off-screen rendering then we can bypass this since
    # the frame buffer display will force a GL flush
    w = GetRenderView().SMProxy.GetRenderWindow()
    if not w.GetOffScreenRendering():
        return

    import vtk

    # If we're using MPI we can also bypass this since compositing will
    # for a GL flush
    controller = vtk.vtkMultiProcessController.GetGlobalController()
    if controller.GetNumberOfProcesses() > 1:
        return

    # Force a GL flush by retrieving the frame buffer image
    w2i = vtk.vtkWindowToImageFilter()
    w2i.ReadFrontBufferOff()
    w2i.ShouldRerenderOff()
    w2i.SetInput(w)
    w2i.Modified()
    w2i.Update()
开发者ID:151706061,项目名称:ParaView,代码行数:29,代码来源:manyspheres.py


示例15: saveToPNG

 def saveToPNG(self, filename):
     """ saveToPNG(filename: str) -> filename or vtkUnsignedCharArray
     
     Save the current widget contents to an image file. If
     str==None, then it returns the vtkUnsignedCharArray containing
     the PNG image. Otherwise, the filename is returned.
     
     """
     w2i = vtk.vtkWindowToImageFilter()
     w2i.ReadFrontBufferOff()
     w2i.SetInput(self.mRenWin)
     # Render twice to get a clean image on the back buffer
     if self.mRenWin.GetInteractor():
         self.mRenWin.GetInteractor().Render()
         self.mRenWin.GetInteractor().Render()
     else:
         self.mRenWin.Render()
         self.mRenWin.Render()
     w2i.Update()
     writer = vtk.vtkPNGWriter()
     writer.SetInputConnection(w2i.GetOutputPort())
     if filename!=None:
         writer.SetFileName(filename)
     else:
         writer.WriteToMemoryOn()
     writer.Write()
     if filename:
         return filename
     else:
         return writer.GetResult()
开发者ID:CMUSV-VisTrails,项目名称:WorkflowRecommendation,代码行数:30,代码来源:vtkcell.py


示例16: compute

    def compute(self):
        r = self.get_input("renderer").vtkInstance
        window = vtk.vtkRenderWindow()
        w = self.force_get_input("width", 512)
        h = self.force_get_input("height", 512)
        window.OffScreenRenderingOn()
        window.SetSize(w, h)
        # r.ResetCamera()

        widget = None
        if system.systemType=='Darwin':
            from PyQt4 import QtCore, QtGui
            widget = QtGui.QWidget(None, QtCore.Qt.FramelessWindowHint)
            widget.resize(w, h)
            widget.show()
            window.SetWindowInfo(str(int(widget.winId())))    
       
        window.AddRenderer(r)
#        window.Start()
        window.Render()
        win2image = vtk.vtkWindowToImageFilter()
        win2image.SetInput(window)
        win2image.Update()
        writer = vtk.vtkPNGWriter()
        writer.SetInput(win2image.GetOutput())
        output = self.interpreter.filePool.create_file(suffix='.png')
        writer.SetFileName(output.name)
        writer.Write()
        window.Finalize()
        if widget!=None:
            widget.close()
        self.set_output("image", output)
开发者ID:Nikea,项目名称:VisTrails,代码行数:32,代码来源:offscreen.py


示例17: SavePNG

def SavePNG():
	png_number=__main__.png_number 	
	option_verbose=__main__.option_verbose
	option_prefix=__main__.option_prefix
	renwin=__main__.renwin

	rtTimer=vtk.vtkTimerLog

	my_print(option_verbose,'----------------------------')
	my_print(option_verbose,'Saving PNG')
	rtStartCPU=rtTimer.GetCPUTime()

	w2i = vtk.vtkWindowToImageFilter()
    	w2i.SetInput(renwin)
    	w2i.Update()

	filepng=option_prefix+'_%03d.png' %png_number 
	my_print(option_verbose,'Start writing PNG file', filepng)
	pngw = vtk.vtkPNGWriter() 
	pngw.SetInputConnection(w2i.GetOutputPort()) 
	pngw.SetFileName(filepng) 
	pngw.Write()

	rtEndCPU=rtTimer.GetCPUTime()
	my_print(option_verbose,'End writing PNG file')
	my_print(option_verbose,'CPU time:', rtEndCPU-rtStartCPU)

	__main__.png_number=png_number+1 
开发者ID:PBrockmann,项目名称:VTK_Mapper,代码行数:28,代码来源:mylib_save.py


示例18: drawLineLineTest

def drawLineLineTest():
    myscreen = ovdvtk.VTKScreen()
    myscreen.camera.SetPosition(0.01, 0,  1000 ) 
    myscreen.camera.SetFocalPoint(0, 0, 0)
    myscreen.camera.SetClippingRange(-100,3000)
    w2if = vtk.vtkWindowToImageFilter()
    w2if.SetInput(myscreen.renWin)
    lwr = vtk.vtkPNGWriter()
    lwr.SetInput( w2if.GetOutput() )
    
    l1 = Line( math.cos(1),   math.sin(1)   , 1 , +1) # first line-site
    drawLine(myscreen, l1, ovdvtk.yellow )
    
    l2 = Line( math.cos(3),   math.sin(3)   , 1 , -1) # second line-site
    drawLine(myscreen, l2, ovdvtk.orange )
    
    l1l2 = LineLine( l1, l2 ) # bisectors
    l2l1 = LineLine( l2, l1 ) # it should not matter if we call with (l1,l2) or (l2,l1) (?)
    print l1l2
    print l2l1
    b1= Bisector( l1l2 )
    b2= Bisector( l2l1 )
    drawBisector( myscreen, b1 )
    drawBisector( myscreen, b2 )
    myscreen.render()
    myscreen.iren.Start()
开发者ID:kaben,项目名称:openvoronoi,代码行数:26,代码来源:voronoi_bisectors.py


示例19: show

def show(window, name=None, magnification=2):
    interactor = vtk.vtkRenderWindowInteractor()
    interactor.SetRenderWindow(window)

    interactor.Initialize()
    window.Render()
    interactor.Start()

    windowToImageFilter = vtk.vtkWindowToImageFilter()
    windowToImageFilter.SetInput(window)
    windowToImageFilter.SetMagnification(magnification)
    windowToImageFilter.SetInputBufferTypeToRGBA()
    windowToImageFilter.ReadFrontBufferOff()
    windowToImageFilter.Update()
    writer = vtk.vtkPNGWriter()
    if name is None:
        filehandler = NamedTemporaryFile(delete=False)
    else:
        filehandler = open(name, 'w')
    writer.SetFileName(filehandler.name)
    writer.SetInputConnection(windowToImageFilter.GetOutputPort())
    writer.Write()
    window.Finalize()
    interactor.TerminateApp()
    del interactor
    axes = plt.subplot()
    axes.imshow(img.imread(filehandler.name))
    axes.axis('off')
    if name is None:
        os.unlink(filehandler.name)
开发者ID:pfernique,项目名称:wanda,代码行数:30,代码来源:frame.py


示例20: save_rendered

    def save_rendered(self, image_file_name):
        "Output snapshot to image file"

        image_file_type = os.path.splitext(image_file_name)[1]

        # Remove existing image file
        if os.path.exists(image_file_name):
            if os.path.isfile(image_file_name):
                os.remove(image_file_name)
            else:
                raise VisualizerError \
                    ('Cannot overwrite image file: ' + image_file_name)

        if image_file_type == '.bmp':
            writer = vtk.vtkBMPWriter()
        elif image_file_type == '.jpg':
            writer = vtk.vtkJPEGWriter()
        elif image_file_type == '.png':
            writer = vtk.vtkPNGWriter()
        elif image_file_type == '.tif':
            writer = vtk.vtkTIFFWriter()
        else:
            error_info = 'Illegal image-file type: ' + image_file_type + '\n'
            error_info += 'Please choose from "bmp","jpg","png","tif".'
            raise VisualizerError(error_info)

        w2i = vtk.vtkWindowToImageFilter()
        w2i.SetInput(self.window)
        self.window.Render()

        writer.SetInput(w2i.GetOutput())
        writer.SetFileName(image_file_name)
        writer.Write()
开发者ID:ecell,项目名称:pd_visualizer,代码行数:33,代码来源:visualizer.py



注:本文中的vtk.vtkWindowToImageFilter函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vtk.vtkXMLImageDataReader函数代码示例发布时间:2022-05-26
下一篇:
Python vtk.vtkWarpScalar函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap