def copyVTK2(self): #from tvtk.api import tvtk, write_data #src = mayavi.tools.pipeline.get_vtk_src(self.visualization.scene.mayavi_scene.children[5]) #write_data(src[0],"test.vtk") True self.visualization.scene.mlab.options.offscreen = True fpath = os.path.abspath("clipboard.eps") f_prefix, f_ext = os.path.splitext(fpath) ex = tvtk.GL2PSExporter() ex.file_prefix = f_prefix ex.file_format = 'eps' ex.sort = 'bsp' ex.compress = 0 #ex.write3d_props_as_raster_image = 1 self.visualization.scene.save(fpath, size=(640, 640), exp=ex) #self.visualization.scene.mlab.savefig(fpath, exp=ex) #self.visualization.scene.mlab.savefig(fpath) opath = os.path.abspath("clipboard") exeln = 'inkscape -z --file "' + fpath + '" --export-emf "' + opath + '"' os.system(exeln) os.remove(fpath) mylib.set_clipboard_file(opath)
def save_gl2ps(self, file_name, exp=None): """Save scene to a vector PostScript/EPS/PDF/TeX file using GL2PS. If you choose to use a TeX file then note that only the text output is saved to the file. You will need to save the graphics separately. Keyword Arguments: file_name -- File name to save to. exp -- Optionally configured vtkGL2PSExporter object. Defaults to None and this will use the default settings with the output file type chosen based on the extention of the file name. """ # Make sure the exporter is available. if not hasattr(tvtk, 'GL2PSExporter'): msg = "Saving as a vector PS/EPS/PDF/TeX file using GL2PS is "\ "either not supported by your version of VTK or "\ "you have not configured VTK to work with GL2PS -- read "\ "the documentation for the vtkGL2PSExporter class." print msg return if len(file_name) != 0: f_prefix, f_ext = os.path.splitext(file_name) ex = None if exp: ex = exp if not isinstance(exp, tvtk.GL2PSExporter): msg = "Need a vtkGL2PSExporter you passed a "\ "%s"%exp.__class__.__name__ raise TypeError, msg ex.file_prefix = f_prefix else: ex = tvtk.GL2PSExporter() # defaults ex.file_prefix = f_prefix if f_ext == ".ps": ex.file_format = 'ps' elif f_ext == ".tex": ex.file_format = 'tex' elif f_ext == ".pdf": ex.file_format = 'pdf' else: ex.file_format = 'eps' ex.sort = 'bsp' ex.compress = 1 ex.edit_traits(kind='livemodal') self._lift() ex.render_window = self._renwin if ex.write3d_props_as_raster_image: self._exporter_write(ex) else: ex.write()
print(ErrorOut) else: printframe[0] = int(tempframe) inputcheck = 'ok' else: #The following three lines are the options for offscreen rendering without GUI. #Mayavi uses the vtk library to output. So, deactivating mayavi GUI is insufficient as the vtk GUI stops batch processsing. #So, we set the VTK export options here to stop the vtk GUI from asking confirmations. mlab.options.offscreen = True try: from tvtk.api import tvtk exp_options = tvtk.GL2PSExporter(file_format='eps', sort='bsp', compress=1) except: print('ERROR: Unable to access the vtk module.\n') sys.exit(1) printframe = np.genfromtxt(args.framefile, usecols=0, dtype=int) if np.sum(np.int32(np.isnan(printframe))) > 0: ErrorOut = 'Check the frames in the input file ' + str( args.framefile) + '. Only Integers allowed.\n' print(ErrorOut) sys.exit(1) elif np.amin(printframe) <= 0: ErrorOut = 'Check the frames in the input file ' + str(