Пример #1
0
    def write_picture(self, magnify, fname):
        ren = self.getRenderer()
        assert ren is not None
        renderLarge = vtk.vtkRenderLargeImage()
        renderLarge.SetInput(ren)
        renderLarge.SetMagnification(magnify)

        rotation = 'x'
        self.set_rotation(rotation)

        lfname = fname.lower()
        if lfname.endswith('.png'):
            writer = vtk.vtkPNGWriter()
        elif lfname.endswith('.jpeg'):
            writer = vtk.vtkJPEGWriter()
        elif lfname.endswith('.tiff'):
            writer = vtk.vtkTIFFWriter()
        elif lfname.endswith('.ps'):
            writer = vtk.vtkPostScriptWriter()
        else:
            writer = vtk.vtkPNGWriter()

        writer.SetInput(renderLarge.GetOutput())
        writer.SetFileName(fname)
        writer.Write()
Пример #2
0
    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()
Пример #3
0
    def write_picture(self, magnify, fname):
        ren = self.getRenderer()
        assert ren is not None
        renderLarge = vtk.vtkRenderLargeImage()
        renderLarge.SetInput(ren)
        renderLarge.SetMagnification(magnify)

        rotation = 'x'
        self.set_rotation(rotation)

        lfname = fname.lower()
        if lfname.endswith('.png'):
            writer = vtk.vtkPNGWriter()
        elif lfname.endswith('.jpeg'):
            writer = vtk.vtkJPEGWriter()
        elif lfname.endswith('.tiff'):
            writer = vtk.vtkTIFFWriter()
        elif lfname.endswith('.ps'):
            writer = vtk.vtkPostScriptWriter()
        else:
            writer = vtk.vtkPNGWriter()

        writer.SetInput(renderLarge.GetOutput())
        writer.SetFileName(fname)
        writer.Write()
Пример #4
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(
         self, module_manager,
         vtk.vtkPostScriptWriter(), 'Writing vtkPostScript.',
         ('vtkPostScript',), (),
         replaceDoc=True,
         inputFunctions=None, outputFunctions=None)
Пример #5
0
 def __init__(self, module_manager):
     SimpleVTKClassModuleBase.__init__(self,
                                       module_manager,
                                       vtk.vtkPostScriptWriter(),
                                       'Writing vtkPostScript.',
                                       ('vtkPostScript', ), (),
                                       replaceDoc=True,
                                       inputFunctions=None,
                                       outputFunctions=None)
Пример #6
0
def WriteImage(fileName, renWin1, rgba=True):
    """
    Write the render window view to an image file.

    Image types supported are:
     BMP, JPEG, PNM, PNG, PostScript, TIFF.
    The default parameters are used for all writers, change as needed.

    :param fileName: The file name, if no extension then PNG is assumed.
    :param renWin1: The render window.
    :param rgba: Used to set the buffer type.
    :return:
    """

    import os

    if fileName:
        # Select the writer to use.
        path, ext = os.path.splitext(fileName)
        ext = ext.lower()
        if not ext:
            ext = '.png'
            fileName = fileName + ext
        if ext == '.bmp':
            writer = vtk.vtkBMPWriter()
        elif ext == '.jpg':
            writer = vtk.vtkJPEGWriter()
        elif ext == '.pnm':
            writer = vtk.vtkPNMWriter()
        elif ext == '.ps':
            if rgba:
                rgba = False
            writer = vtk.vtkPostScriptWriter()
        elif ext == '.tiff':
            writer = vtk.vtkTIFFWriter()
        else:
            writer = vtk.vtkPNGWriter()

        windowto_image_filter = vtk.vtkWindowToImageFilter()
        windowto_image_filter.SetInput(renWin1)
        windowto_image_filter.SetScale(1)  # image quality
        if rgba:
            windowto_image_filter.SetInputBufferTypeToRGBA()
        else:
            windowto_image_filter.SetInputBufferTypeToRGB()
            # Read from the front buffer.
            windowto_image_filter.ReadFrontBufferOff()
            windowto_image_filter.Update()

        writer.SetFileName(fileName)
        writer.SetInputConnection(windowto_image_filter.GetOutputPort())
        writer.Write()
    else:
        raise RuntimeError('Need a filename.')
Пример #7
0
    def OnExportPicture(self, pubsub_evt):
        Publisher.sendMessage('Begin busy cursor')
        view_prop_list = []
        for slice_data in self.slice_data_list:
            view_prop_list.append(slice_data.box_actor)
            self.ren.RemoveViewProp(slice_data.box_actor)

        id, filename, filetype = pubsub_evt.data
        dict = {
            "AXIAL": const.AXIAL,
            "CORONAL": const.CORONAL,
            "SAGITAL": const.SAGITAL
        }

        if id == dict[self.orientation]:
            if filetype == const.FILETYPE_POV:
                renwin = self.interactor.GetRenderWindow()
                image = vtk.vtkWindowToImageFilter()
                image.SetInput(renwin)
                writer = vtk.vtkPOVExporter()
                writer.SetFilePrefix(filename.split(".")[0])
                writer.SetRenderWindow(renwin)
                writer.Write()
            else:
                ren = self.slice_data.renderer
                #Use tiling to generate a large rendering.
                image = vtk.vtkRenderLargeImage()
                image.SetInput(ren)
                image.SetMagnification(1)

                image = image.GetOutput()

                # write image file
                if (filetype == const.FILETYPE_BMP):
                    writer = vtk.vtkBMPWriter()
                elif (filetype == const.FILETYPE_JPG):
                    writer = vtk.vtkJPEGWriter()
                elif (filetype == const.FILETYPE_PNG):
                    writer = vtk.vtkPNGWriter()
                elif (filetype == const.FILETYPE_PS):
                    writer = vtk.vtkPostScriptWriter()
                elif (filetype == const.FILETYPE_TIF):
                    writer = vtk.vtkTIFFWriter()
                    filename = "%s.tif" % filename.strip(".tif")

                writer.SetInput(image)
                writer.SetFileName(filename)
                writer.Write()

            for actor in view_prop_list:
                self.ren.AddViewProp(actor)

        Publisher.sendMessage('End busy cursor')
Пример #8
0
    def OnExportPicture(self, pubsub_evt):
        Publisher.sendMessage('Begin busy cursor')
        view_prop_list = []
        for slice_data in self.slice_data_list:
            view_prop_list.append(slice_data.box_actor) 
            self.ren.RemoveViewProp(slice_data.box_actor)

        id, filename, filetype = pubsub_evt.data
        dict = {"AXIAL": const.AXIAL,
                "CORONAL": const.CORONAL,
                "SAGITAL": const.SAGITAL}

        if id == dict[self.orientation]:
            if filetype == const.FILETYPE_POV:
                renwin = self.interactor.GetRenderWindow()
                image = vtk.vtkWindowToImageFilter()
                image.SetInput(renwin)
                writer = vtk.vtkPOVExporter()
                writer.SetFilePrefix(filename.split(".")[0])
                writer.SetRenderWindow(renwin)
                writer.Write()
            else:
                ren = self.slice_data.renderer
                #Use tiling to generate a large rendering.
                image = vtk.vtkRenderLargeImage()
                image.SetInput(ren)
                image.SetMagnification(1)
                image.Update()

                image = image.GetOutput()


                # write image file
                if (filetype == const.FILETYPE_BMP):
                    writer = vtk.vtkBMPWriter()
                elif (filetype == const.FILETYPE_JPG):
                    writer =  vtk.vtkJPEGWriter()
                elif (filetype == const.FILETYPE_PNG):
                    writer = vtk.vtkPNGWriter()
                elif (filetype == const.FILETYPE_PS):
                    writer = vtk.vtkPostScriptWriter()
                elif (filetype == const.FILETYPE_TIF):
                    writer = vtk.vtkTIFFWriter()
                    filename = "%s.tif"%filename.strip(".tif")

                writer.SetInputData(image)
                writer.SetFileName(filename)
                writer.Write()

            for actor in view_prop_list:
                self.ren.AddViewProp(actor)

        Publisher.sendMessage('End busy cursor')
Пример #9
0
 def CaptureImage(self):
     if not self.image_array is None:
         self.png_number = self.png_number + 1
         png_str = str(self.png_number)
         save_file = './vtk_plot' + png_str + '.ps'
         save_file_no_space = save_file.replace(' ', '_')
         w2i = vtk.vtkWindowToImageFilter()
         writer = vtk.vtkPostScriptWriter()
         w2i.SetInput(self.renwin)
         w2i.Update()
         writer.SetInput(w2i.GetOutput())
         writer.SetFileName(save_file_no_space)
         self.renwin.Render()
         writer.Write()
 def CaptureImage(self):
   if not self.image_array is None:
     self.png_number = self.png_number + 1
     png_str = str(self.png_number)
     save_file = './vtk_plot' + png_str + '.ps'
     save_file_no_space= save_file.replace(' ','_')
     w2i = vtk.vtkWindowToImageFilter()
     writer = vtk.vtkPostScriptWriter()
     w2i.SetInput(self.renwin)
     w2i.Update()
     writer.SetInput(w2i.GetOutput())
     writer.SetFileName(save_file_no_space)
     self.renwin.Render()
     writer.Write()
Пример #11
0
 def _get_image_writer(image_type: ImageTypes) -> None:
     """Get vtk image writer for each image type."""
     if image_type == ImageTypes.png:
         writer = vtk.vtkPNGWriter()
     elif image_type == ImageTypes.bmp:
         writer = vtk.vtkBMPWriter()
     elif image_type == ImageTypes.jpg:
         writer = vtk.vtkJPEGWriter()
     elif image_type == ImageTypes.pnm:
         writer = vtk.vtkPNMWriter()
     elif image_type == ImageTypes.ps:
         writer = vtk.vtkPostScriptWriter()
     elif image_type == ImageTypes.tiff:
         writer = vtk.vtkTIFFWriter()
     else:
         raise ValueError(f'Invalid image type: {image_type}')
     return writer
Пример #12
0
 def save_ps (self, file_name=""):        
     debug ("In RenderWindow::save_ps ()")
     if not file_name:
         file_name = tk_fsave (title="Export to PostScript",
                               initialdir=Common.config.initial_dir,
                               defaultextension=".ps",
                               filetypes=[("PS files", "*.ps"),
                                          ("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.vtkPostScriptWriter ()
         ex.SetFileName (file_name)
         ex.SetInput (w2if.GetOutput ())
         ex.Write ()
         Common.state.idle ()
Пример #13
0
    def screenshot(self, checked, fname=None, size=[1920, 1080], offscreen=True):
        """take a snapshot of the vtk window"""
        self.toolbutton_screenshot.setDown(False)

        if fname is None:
            ok, fname, size = self.screenshot_dialog.get()
            if not ok:
                return

        # off screen rendering
        if VTK_MAJOR_VERSION > 6:
            offscreen = False
        if offscreen and self.offscreen_vtkrenderer is None:
            self.init_offscreen_render(size)
        elif offscreen:
            self.offscreen_vtkrenderwindow.SetSize(*size)

        # screenshot code:
        # TODO: get resolution from user
        window_image = vtk.vtkWindowToImageFilter()
        if offscreen:
            window_image.SetInput(self.offscreen_vtkrenderwindow)
        else:
            window_image.SetInput(self.vtkRenderWindow)
        window_image.SetInputBufferTypeToRGBA()
#        window_image.ReadFrontBufferOff()
        window_image.Update()

        if fname.endswith('.png'):
            writer = vtk.vtkPNGWriter()
        elif fname.endswith('.jpg'):
            writer = vtk.vtkJPEGWriter()
        elif fname.endswith('.ps'):
            writer = vtk.vtkPostScriptWriter()
        else:
            # force to png
            writer = vtk.vtkPNGWriter()
            fname += '.png'

        writer.SetFileName(fname)
        writer.SetInputConnection(window_image.GetOutputPort())
        writer.Write()
Пример #14
0
    def onTakePicture(self, event):
        renderLarge = vtk.vtkRenderLargeImage()
        renderLarge.SetInput(self.getRenderer())
        renderLarge.SetMagnification(4)

        wildcard = "PNG (*.png)|*.png|" \
            "JPEG (*.jpeg; *.jpeg; *.jpg; *.jfif)|*.jpg;*.jpeg;*.jpg;*.jfif|" \
            "TIFF (*.tif; *.tiff)|*.tif;*.tiff|" \
            "BMP (*.bmp)|*.bmp|" \
            "PostScript (*.ps)|*.ps|" \
            "All files (*.*)|*.*"

        dlg = wx.FileDialog(None, "Choose a file", self.dirname, "", wildcard,
                            wx.SAVE | wx.OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            fname = dlg.GetFilename()
            self.dirname = dlg.GetDirectory()
            fname = os.path.join(self.dirname, fname)

            print "fname = ", fname

            # We write out the image which causes the rendering to occur. If you
            # watch your screen you might see the pieces being rendered right
            # after one another.
            lfname = fname.lower()
            if lfname.endswith('.png'):
                writer = vtk.vtkPNGWriter()
            elif lfname.endswith('.jpeg'):
                writer = vtk.vtkJPEGWriter()
            elif lfname.endswith('.tiff'):
                writer = vtk.vtkTIFFWriter()
            elif lfname.endswith('.ps'):
                writer = vtk.vtkPostScriptWriter()
            else:
                writer = vtk.vtkPNGWriter()

            writer.SetInputConnection(renderLarge.GetOutputPort())
            writer.SetFileName(fname)
            writer.Write()
        dlg.Destroy()
Пример #15
0
    def onTakePicture(self, event):
        renderLarge = vtk.vtkRenderLargeImage()
        renderLarge.SetInput(self.getRenderer())
        renderLarge.SetMagnification(4)

        wildcard = "PNG (*.png)|*.png|" \
            "JPEG (*.jpeg; *.jpeg; *.jpg; *.jfif)|*.jpg;*.jpeg;*.jpg;*.jfif|" \
            "TIFF (*.tif; *.tiff)|*.tif;*.tiff|" \
            "BMP (*.bmp)|*.bmp|" \
            "PostScript (*.ps)|*.ps|" \
            "All files (*.*)|*.*"

        dlg = wx.FileDialog(None, "Choose a file", self.dirname,
                            "", wildcard, wx.SAVE | wx.OVERWRITE_PROMPT)
        if dlg.ShowModal() == wx.ID_OK:
            fname = dlg.GetFilename()
            self.dirname = dlg.GetDirectory()
            fname = os.path.join(self.dirname, fname)

            print "fname = ", fname

            # We write out the image which causes the rendering to occur. If you
            # watch your screen you might see the pieces being rendered right
            # after one another.
            lfname = fname.lower()
            if lfname.endswith('.png'):
                writer = vtk.vtkPNGWriter()
            elif lfname.endswith('.jpeg'):
                writer = vtk.vtkJPEGWriter()
            elif lfname.endswith('.tiff'):
                writer = vtk.vtkTIFFWriter()
            elif lfname.endswith('.ps'):
                writer = vtk.vtkPostScriptWriter()
            else:
                writer = vtk.vtkPNGWriter()

            writer.SetInputConnection(renderLarge.GetOutputPort())
            writer.SetFileName(fname)
            writer.Write()
        dlg.Destroy()
Пример #16
0
    def OnExportPicture(self, pubsub_evt):
        Publisher.sendMessage('Begin busy cursor')
        id, filename, filetype = pubsub_evt.data
        if id == const.VOLUME:
            if filetype == const.FILETYPE_POV:
                renwin = self.interactor.GetRenderWindow()
                image = vtk.vtkWindowToImageFilter()
                image.SetInput(renwin)
                writer = vtk.vtkPOVExporter()
                writer.SetFileName(filename)
                writer.SetRenderWindow(renwin)
                writer.Write()
            else:
                #Use tiling to generate a large rendering.
                image = vtk.vtkRenderLargeImage()
                image.SetInput(self.ren)
                image.SetMagnification(1)
                image.Update()

                image = image.GetOutput()

                # write image file
                if (filetype == const.FILETYPE_BMP):
                    writer = vtk.vtkBMPWriter()
                elif (filetype == const.FILETYPE_JPG):
                    writer =  vtk.vtkJPEGWriter()
                elif (filetype == const.FILETYPE_PNG):
                    writer = vtk.vtkPNGWriter()
                elif (filetype == const.FILETYPE_PS):
                    writer = vtk.vtkPostScriptWriter()
                elif (filetype == const.FILETYPE_TIF):
                    writer = vtk.vtkTIFFWriter()
                    filename = "%s.tif"%filename.strip(".tif")

                writer.SetInputData(image)
                writer.SetFileName(filename)
                writer.Write()
        Publisher.sendMessage('End busy cursor')
Пример #17
0
    def _export_picture(self, id, filename, filetype):
        if filetype == const.FILETYPE_POV:
            renwin = self.interactor.GetRenderWindow()
            image = vtk.vtkWindowToImageFilter()
            image.SetInput(renwin)
            writer = vtk.vtkPOVExporter()
            writer.SetFileName(filename.encode(const.FS_ENCODE))
            writer.SetRenderWindow(renwin)
            writer.Write()
        else:
            #Use tiling to generate a large rendering.
            image = vtk.vtkRenderLargeImage()
            image.SetInput(self.ren)
            image.SetMagnification(1)
            image.Update()

            image = image.GetOutput()

            # write image file
            if (filetype == const.FILETYPE_BMP):
                writer = vtk.vtkBMPWriter()
            elif (filetype == const.FILETYPE_JPG):
                writer = vtk.vtkJPEGWriter()
            elif (filetype == const.FILETYPE_PNG):
                writer = vtk.vtkPNGWriter()
            elif (filetype == const.FILETYPE_PS):
                writer = vtk.vtkPostScriptWriter()
            elif (filetype == const.FILETYPE_TIF):
                writer = vtk.vtkTIFFWriter()
                filename = u"%s.tif" % filename.strip(".tif")

            writer.SetInputData(image)
            writer.SetFileName(filename.encode(const.FS_ENCODE))
            writer.Write()

        if not os.path.exists(filename):
            wx.MessageBox(_("InVesalius was not able to export this picture"),
                          _("Export picture error"))
Пример #18
0
    def OnExportPicture(self, pubsub_evt):
        Publisher.sendMessage('Begin busy cursor')
        id, filename, filetype = pubsub_evt.data
        if id == const.VOLUME:
            if filetype == const.FILETYPE_POV:
                renwin = self.interactor.GetRenderWindow()
                image = vtk.vtkWindowToImageFilter()
                image.SetInput(renwin)
                writer = vtk.vtkPOVExporter()
                writer.SetFileName(filename)
                writer.SetRenderWindow(renwin)
                writer.Write()
            else:
                #Use tiling to generate a large rendering.
                image = vtk.vtkRenderLargeImage()
                image.SetInput(self.ren)
                image.SetMagnification(1)
                image.Update()

                image = image.GetOutput()

                # write image file
                if (filetype == const.FILETYPE_BMP):
                    writer = vtk.vtkBMPWriter()
                elif (filetype == const.FILETYPE_JPG):
                    writer = vtk.vtkJPEGWriter()
                elif (filetype == const.FILETYPE_PNG):
                    writer = vtk.vtkPNGWriter()
                elif (filetype == const.FILETYPE_PS):
                    writer = vtk.vtkPostScriptWriter()
                elif (filetype == const.FILETYPE_TIF):
                    writer = vtk.vtkTIFFWriter()
                    filename = "%s.tif" % filename.strip(".tif")

                writer.SetInputData(image)
                writer.SetFileName(filename)
                writer.Write()
        Publisher.sendMessage('End busy cursor')
Пример #19
0
 tiff2 = vtk.vtkTIFFWriter()
 tiff2.SetInputConnection(luminance.GetOutputPort())
 tiff2.SetFileName("" + str(dir) + "/tiff2.tif")
 bmp1 = vtk.vtkBMPWriter()
 bmp1.SetInputConnection(image1.GetOutputPort())
 bmp1.SetFileName("" + str(dir) + "/bmp1.bmp")
 bmp2 = vtk.vtkBMPWriter()
 bmp2.SetInputConnection(luminance.GetOutputPort())
 bmp2.SetFileName("" + str(dir) + "/bmp2.bmp")
 pnm1 = vtk.vtkPNMWriter()
 pnm1.SetInputConnection(image1.GetOutputPort())
 pnm1.SetFileName("" + str(dir) + "/pnm1.pnm")
 pnm2 = vtk.vtkPNMWriter()
 pnm2.SetInputConnection(luminance.GetOutputPort())
 pnm2.SetFileName("" + str(dir) + "/pnm2.pnm")
 psw1 = vtk.vtkPostScriptWriter()
 psw1.SetInputConnection(image1.GetOutputPort())
 psw1.SetFileName("" + str(dir) + "/psw1.ps")
 psw2 = vtk.vtkPostScriptWriter()
 psw2.SetInputConnection(luminance.GetOutputPort())
 psw2.SetFileName("" + str(dir) + "/psw2.ps")
 pngw1 = vtk.vtkPNGWriter()
 pngw1.SetInputConnection(image1.GetOutputPort())
 pngw1.SetFileName("" + str(dir) + "/pngw1.png")
 pngw2 = vtk.vtkPNGWriter()
 pngw2.SetInputConnection(luminance.GetOutputPort())
 pngw2.SetFileName("" + str(dir) + "/pngw2.png")
 jpgw1 = vtk.vtkJPEGWriter()
 jpgw1.SetInputConnection(image1.GetOutputPort())
 jpgw1.SetFileName("" + str(dir) + "/jpgw1.jpg")
 jpgw2 = vtk.vtkJPEGWriter()
Пример #20
0
 tiff2 = vtk.vtkTIFFWriter()
 tiff2.SetInputConnection(luminance.GetOutputPort())
 tiff2.SetFileName("" + str(dir) + "/tiff2.tif")
 bmp1 = vtk.vtkBMPWriter()
 bmp1.SetInputConnection(image1.GetOutputPort())
 bmp1.SetFileName("" + str(dir) + "/bmp1.bmp")
 bmp2 = vtk.vtkBMPWriter()
 bmp2.SetInputConnection(luminance.GetOutputPort())
 bmp2.SetFileName("" + str(dir) + "/bmp2.bmp")
 pnm1 = vtk.vtkPNMWriter()
 pnm1.SetInputConnection(image1.GetOutputPort())
 pnm1.SetFileName("" + str(dir) + "/pnm1.pnm")
 pnm2 = vtk.vtkPNMWriter()
 pnm2.SetInputConnection(luminance.GetOutputPort())
 pnm2.SetFileName("" + str(dir) + "/pnm2.pnm")
 psw1 = vtk.vtkPostScriptWriter()
 psw1.SetInputConnection(image1.GetOutputPort())
 psw1.SetFileName("" + str(dir) + "/psw1.ps")
 psw2 = vtk.vtkPostScriptWriter()
 psw2.SetInputConnection(luminance.GetOutputPort())
 psw2.SetFileName("" + str(dir) + "/psw2.ps")
 pngw1 = vtk.vtkPNGWriter()
 pngw1.SetInputConnection(image1.GetOutputPort())
 pngw1.SetFileName("" + str(dir) + "/pngw1.png")
 pngw2 = vtk.vtkPNGWriter()
 pngw2.SetInputConnection(luminance.GetOutputPort())
 pngw2.SetFileName("" + str(dir) + "/pngw2.png")
 jpgw1 = vtk.vtkJPEGWriter()
 jpgw1.SetInputConnection(image1.GetOutputPort())
 jpgw1.SetFileName("" + str(dir) + "/jpgw1.jpg")
 jpgw2 = vtk.vtkJPEGWriter()
Пример #21
0
def saveRendererToImg(renderer,fnOut,magnification=10):
	
	"""Saves renderer to image file.
	
	Supported extensions are:
		
		* '.ps'  (PostScript)
		* '.eps' (Encapsualted PostScript)
		* '.pdf' (Portable Document Format)
		* '.jpg' (Joint Photographic Experts Group)
		* '.png' (Portable Network Graphics)
		* '.pnm' (Portable Any Map)
		* '.tif' (Tagged Image File Format)
		* '.bmp' (Bitmap Image)
	
	Some code taken from http://www.programcreek.com/python/example/23102/vtk.vtkGL2PSExporter .
	
	Args:
		fnOut (str): Path to output file.
		renderer (vtk.vtkOpenGLRenderer): Renderer.
		
	Keyword Args:
		magnification (int): Degree of magnification.
		
	Returns:
		vtk.vtkExporter: Exporter object.
	
	"""
	
	
	#Generate exporter
	vtkImageWriters = {
		'.tif': vtk.vtkTIFFWriter(),
		'.tiff': vtk.vtkTIFFWriter(),
		'.bmp': vtk.vtkBMPWriter(),
		'.pnm': vtk.vtkPNMWriter(),
		'.png': vtk.vtkPNGWriter(),
		'.jpg': vtk.vtkJPEGWriter(),
		'.jpeg': vtk.vtkJPEGWriter(),
		'.ps': vtk.vtkPostScriptWriter(),
		'.eps': vtk.vtkPostScriptWriter(),  
		}
	
	#Get extension
	basename,ext=os.path.splitext(fnOut)

	#Large Image renderer for nicer images
	rendererLarge=vtk.vtkRenderLargeImage()
	rendererLarge.SetInput(renderer)
	rendererLarge.SetMagnification(magnification)

	#Get proper writer
	try:
		writer = vtkImageWriters[ext.lower()]
	except KeyError:
		printError("Extension "+ext+" is currently not supported")
		return None
	
	#Write
	writer.SetFileName(fnOut)
	
	writer.SetInputConnection(rendererLarge.GetOutputPort())
	writer.Write()

	return writer
Пример #22
0
def saveRendererToImg(renderer, fnOut, magnification=10):
    """Saves renderer to image file.
	
	Supported extensions are:
		
		* '.ps'  (PostScript)
		* '.eps' (Encapsualted PostScript)
		* '.pdf' (Portable Document Format)
		* '.jpg' (Joint Photographic Experts Group)
		* '.png' (Portable Network Graphics)
		* '.pnm' (Portable Any Map)
		* '.tif' (Tagged Image File Format)
		* '.bmp' (Bitmap Image)
	
	Some code taken from http://www.programcreek.com/python/example/23102/vtk.vtkGL2PSExporter .
	
	Args:
		fnOut (str): Path to output file.
		renderer (vtk.vtkOpenGLRenderer): Renderer.
		
	Keyword Args:
		magnification (int): Degree of magnification.
		
	Returns:
		vtk.vtkExporter: Exporter object.
	
	"""

    #Generate exporter
    vtkImageWriters = {
        '.tif': vtk.vtkTIFFWriter(),
        '.tiff': vtk.vtkTIFFWriter(),
        '.bmp': vtk.vtkBMPWriter(),
        '.pnm': vtk.vtkPNMWriter(),
        '.png': vtk.vtkPNGWriter(),
        '.jpg': vtk.vtkJPEGWriter(),
        '.jpeg': vtk.vtkJPEGWriter(),
        '.ps': vtk.vtkPostScriptWriter(),
        '.eps': vtk.vtkPostScriptWriter(),
    }

    #Get extension
    basename, ext = os.path.splitext(fnOut)

    #Large Image renderer for nicer images
    rendererLarge = vtk.vtkRenderLargeImage()
    rendererLarge.SetInput(renderer)
    rendererLarge.SetMagnification(magnification)

    #Get proper writer
    try:
        writer = vtkImageWriters[ext.lower()]
    except KeyError:
        printError("Extension " + ext + " is currently not supported")
        return None

    #Write
    writer.SetFileName(fnOut)

    writer.SetInputConnection(rendererLarge.GetOutputPort())
    writer.Write()

    return writer