def WriteImages(self, datadescription, rescale_lookuptable=False, image_quality=None, padding_amount=0): """This method will update all views, if present and write output images, as needed. **Parameters** datadescription Catalyst data-description object rescale_lookuptable (bool, optional) If True, when all lookup tables are rescaled using current data ranges before saving the images. Defaults to False. image_quality (int, optional) If specified, should be a value in the range (0, 100) that specifies the image quality. For JPEG, 0 is low quality i.e. max compression, 100 is best quality i.e. least compression. For legacy reasons, this is inverted for PNG (which uses lossless compression). For PNG, 0 is no compression i.e maximum image size, while 100 is most compressed and hence least image size. If not specified, for saving PNGs 0 is assumed to minimize performance impact. padding_amount (int, optional) Amount to pad the time index by. """ timestep = datadescription.GetTimeStep() cinema_dirs = [] for view in self.__ViewsList: if (view.cpFrequency and self.NeedToOutput(datadescription, view.cpFrequency)) or \ datadescription.GetForceOutput() == True: fname = view.cpFileName ts = str(timestep).rjust(padding_amount, '0') fname = fname.replace("%t", ts) if view.cpFitToScreen != 0: view.ViewTime = datadescription.GetTime() if view.IsA("vtkSMRenderViewProxy") == True: view.ResetCamera() elif view.IsA("vtkSMContextViewProxy") == True: view.ResetDisplay() else: print(' do not know what to do with a ', view.GetClassName()) view.ViewTime = datadescription.GetTime() if rescale_lookuptable: self.RescaleDataRange(view, datadescription.GetTime()) cinemaOptions = view.cpCinemaOptions if cinemaOptions and 'camera' in cinemaOptions: if 'composite' in view.cpCinemaOptions and view.cpCinemaOptions[ 'composite'] == True: dirname, filelist = self.UpdateCinema(view, datadescription, specLevel="B") else: dirname, filelist = self.UpdateCinema(view, datadescription, specLevel="A") if dirname: self.__AppendCViewToCinemaDTable( timestep, "view_%s" % self.__ViewsList.index(view), filelist) cinema_dirs.append(dirname) else: if '/' in fname and createDirectoriesIfNeeded: oktowrite = [1.] import vtk comm = vtk.vtkMultiProcessController.GetGlobalController( ) if comm.GetLocalProcessId() == 0: import os newDir = fname[0:fname.rfind('/')] try: os.makedirs(newDir) except OSError: if not os.path.isdir(newDir): print("ERROR: Cannot make directory for", fname, ". No image will be output.") oktowrite[0] = 0. comm.Broadcast(oktowrite, 1, 0) if oktowrite[0] == 0: # we can't make the directory so no reason to update the pipeline return if image_quality is None and fname.endswith('png'): # for png quality = 0 means no compression. compression can be a potentially # very costly serial operation on process 0 quality = 0 elif image_quality is not None: quality = int(image_quality) else: # let simple.SaveScreenshot pick a default. quality = None simple.SaveScreenshot(fname, view, magnification=view.cpMagnification, quality=quality) self.__AppendToCinemaDTable( timestep, "view_%s" % self.__ViewsList.index(view), fname) if len(cinema_dirs) > 1: import paraview.tpl.cinema_python.adaptors.paraview.pv_introspect as pv_introspect pv_introspect.make_workspace_file("cinema\\", cinema_dirs) self.__FinalizeCinemaDTable()
def WriteImages(self, datadescription, rescale_lookuptable=False, image_quality=None, padding_amount=0): """This method will update all views, if present and write output images, as needed. **Parameters** datadescription Catalyst data-description object rescale_lookuptable (bool, optional) If True, when all lookup tables are rescaled using current data ranges before saving the images. Defaults to False. image_quality (int, optional) If specified, should be a value in the range (0, 100) that specifies the image quality. For JPEG, 0 is low quality i.e. max compression, 100 is best quality i.e. least compression. For legacy reasons, this is inverted for PNG (which uses lossless compression). For PNG, 0 is no compression i.e maximum image size, while 100 is most compressed and hence least image size. If not specified, for saving PNGs 0 is assumed to minimize performance impact. padding_amount (int, optional) Amount to pad the time index by. """ timestep = datadescription.GetTimeStep() cinema_dirs = [] for view in self.__ViewsList: if (view.cpFrequency and self.NeedToOutput(datadescription, view.cpFrequency)) or \ datadescription.GetForceOutput() == True: fname = view.cpFileName ts = str(timestep).rjust(padding_amount, '0') fname = fname.replace("%t", ts) if view.cpFitToScreen != 0: view.ViewTime = datadescription.GetTime() if view.IsA("vtkSMRenderViewProxy") == True: view.ResetCamera() elif view.IsA("vtkSMContextViewProxy") == True: view.ResetDisplay() else: print (' do not know what to do with a ', view.GetClassName()) view.ViewTime = datadescription.GetTime() if rescale_lookuptable: self.RescaleDataRange(view, datadescription.GetTime()) cinemaOptions = view.cpCinemaOptions if cinemaOptions and 'camera' in cinemaOptions: if 'composite' in view.cpCinemaOptions and view.cpCinemaOptions['composite'] == True: dirname, filelist = self.UpdateCinema(view, datadescription, specLevel="B") else: dirname, filelist = self.UpdateCinema(view, datadescription, specLevel="A") if dirname: self.__AppendCViewToCinemaDTable(timestep, "view_%s" % self.__ViewsList.index(view), filelist) cinema_dirs.append(dirname) else: if '/' in fname and createDirectoriesIfNeeded: oktowrite = [1.] import vtk comm = vtk.vtkMultiProcessController.GetGlobalController() if comm.GetLocalProcessId() == 0: import os newDir = fname[0:fname.rfind('/')] try: os.makedirs(newDir) except OSError: if not os.path.isdir(newDir): print ("ERROR: Cannot make directory for", fname, ". No image will be output.") oktowrite[0] = 0. comm.Broadcast(oktowrite, 1, 0) if oktowrite[0] == 0: # we can't make the directory so no reason to update the pipeline return if image_quality is None and fname.endswith('png'): # for png quality = 0 means no compression. compression can be a potentially # very costly serial operation on process 0 quality = 0 elif image_quality is not None: quality = int(image_quality) else: # let simple.SaveScreenshot pick a default. quality = None simple.SaveScreenshot(fname, view, magnification=view.cpMagnification, quality=quality) self.__AppendToCinemaDTable(timestep, "view_%s" % self.__ViewsList.index(view), fname) if len(cinema_dirs) > 1: import paraview.tpl.cinema_python.adaptors.paraview.pv_introspect as pv_introspect pv_introspect.make_workspace_file("cinema\\", cinema_dirs) self.__FinalizeCinemaDTable()