def update_cinema(cinema_params, view, specLevel, writer, controller): import paraview.tpl.cinema_python.adaptors.explorers as explorers import paraview.tpl.cinema_python.adaptors.paraview.pv_explorers as pv_explorers import paraview.tpl.cinema_python.adaptors.paraview.pv_introspect as pv_introspect import os.path cdb_filename = os.path.join(controller.GetImageExtractsOutputDirectory(), writer.FileName) info_json = os.path.join(cdb_filename, "info.json") # figure out what we show now pxystate = pv_introspect.record_visibility() # a conservative global bounds for consistent z scaling minbds, maxbds = pv_introspect.max_bounds() # make sure depth rasters are consistent view.MaxClipBounds = [minbds, maxbds, minbds, maxbds, minbds, maxbds] view.LockBounds = 1 tracks = {} if "phi" in cinema_params: tracks["phi"] = cinema_params["phi"] if "theta" in cinema_params: tracks["theta"] = cinema_params["theta"] if "roll" in cinema_params: tracks["roll"] = cinema_params["roll"] if specLevel == "B": p = pv_introspect.inspect(skip_invisible=True) else: p = pv_introspect.inspect(skip_invisible=False) fs = pv_introspect.make_cinema_store( p, info_json, view, forcetime="%.6e" % controller.GetTime(), userDefined=tracks, specLevel=specLevel, camType=cinema_params["camera"], extension=".png", disableValues=cinema_params["noValues"]) # all nodes participate, but only root can writes out the files pm = sm.vtkProcessModule.GetProcessModule() pid = pm.GetPartitionId() new_files = {} ret = pv_introspect.explore( fs, p, iSave=(pid == 0), currentTime={'time': "%.6e" % controller.GetTime()}, userDefined=tracks, specLevel=specLevel, camType=cinema_params["camera"], tracking=cinema_params["tracking"], # now we can rely on float textures everywhere floatValues=True, disableValues=cinema_params["noValues"]) if pid == 0: fs.save() new_files = {} new_files[cdb_filename] = ret #restore what we showed pv_introspect.restore_visibility(pxystate)
def UpdateCinema(self, view, datadescription, specLevel): """ called from catalyst at each timestep to add to the cinema database """ if not view.IsA("vtkSMRenderViewProxy") == True: return try: import paraview.tpl.cinema_python.adaptors.explorers as explorers import paraview.tpl.cinema_python.adaptors.paraview.pv_explorers as pv_explorers import paraview.tpl.cinema_python.adaptors.paraview.pv_introspect as pv_introspect except ImportError as e: import paraview paraview.print_error("Cannot import cinema") paraview.print_error(e) return #figure out where to put this store import os.path vfname = view.cpFileName extension = os.path.splitext(vfname)[1] vfname = vfname[0:vfname.rfind("_")] #strip _num.ext fname = os.path.join(os.path.dirname(vfname), "cinema", os.path.basename(vfname), "info.json") def float_limiter(x): #a shame, but needed to make sure python, javascript and (directory/file)name agree if isinstance(x, (float)): return '%.6e' % x #arbitrarily chose 6 significant digits else: return x #what time? time = datadescription.GetTime() view.ViewTime = time formatted_time = float_limiter(time) #ensure that cinema operates on the specified view simple.SetActiveView(view) # Include camera information in the user defined parameters. # pv_introspect uses __CinemaTracks to customize the exploration. co = view.cpCinemaOptions camType = co["camera"] if "phi" in co: self.__CinemaTracks["phi"] = co["phi"] if "theta" in co: self.__CinemaTracks["theta"] = co["theta"] if "roll" in co: self.__CinemaTracks["roll"] = co["roll"] tracking_def = {} if "tracking" in co: tracking_def = co['tracking'] #figure out what we show now pxystate = pv_introspect.record_visibility() # a conservative global bounds for consistent z scaling minbds, maxbds = pv_introspect.max_bounds() #make sure depth rasters are consistent view.MaxClipBounds = [minbds, maxbds, minbds, maxbds, minbds, maxbds] view.LockBounds = 1 disableValues = False if 'noValues' not in co else co['noValues'] if specLevel == "B": p = pv_introspect.inspect(skip_invisible=True) else: p = pv_introspect.inspect(skip_invisible=False) fs = pv_introspect.make_cinema_store(p, fname, view, forcetime=formatted_time, userDefined=self.__CinemaTracks, specLevel=specLevel, camType=camType, extension=extension, disableValues=disableValues) #all nodes participate, but only root can writes out the files pm = servermanager.vtkProcessModule.GetProcessModule() pid = pm.GetPartitionId() enableFloatVal = False if 'floatValues' not in co else co['floatValues'] new_files = {} ret = pv_introspect.explore(fs, p, iSave=(pid == 0), currentTime={'time': formatted_time}, userDefined=self.__CinemaTracks, specLevel=specLevel, camType=camType, tracking=tracking_def, floatValues=enableFloatVal, disableValues=disableValues) if pid == 0: fs.save() new_files[vfname] = ret view.LockBounds = 0 #restore what we showed pv_introspect.restore_visibility(pxystate) return os.path.basename(vfname), new_files
def UpdateCinema(self, view, datadescription, specLevel): """ called from catalyst at each timestep to add to the cinema database """ if not view.IsA("vtkSMRenderViewProxy") == True: return try: import paraview.tpl.cinema_python.adaptors.explorers as explorers import paraview.tpl.cinema_python.adaptors.paraview.pv_explorers as pv_explorers import paraview.tpl.cinema_python.adaptors.paraview.pv_introspect as pv_introspect except ImportError as e: import paraview paraview.print_error("Cannot import cinema") paraview.print_error(e) return #figure out where to put this store import os.path vfname = view.cpFileName extension = os.path.splitext(vfname)[1] vfname = vfname[0:vfname.rfind("_")] #strip _num.ext fname = os.path.join(os.path.dirname(vfname), "cinema", os.path.basename(vfname), "info.json") def float_limiter(x): #a shame, but needed to make sure python, javascript and (directory/file)name agree if isinstance(x, (float)): return '%.6e' % x #arbitrarily chose 6 significant digits else: return x #what time? time = datadescription.GetTime() view.ViewTime = time formatted_time = float_limiter(time) #ensure that cinema operates on the specified view simple.SetActiveView(view) # Include camera information in the user defined parameters. # pv_introspect uses __CinemaTracks to customize the exploration. co = view.cpCinemaOptions camType = co["camera"] if "phi" in co: self.__CinemaTracks["phi"] = co["phi"] if "theta" in co: self.__CinemaTracks["theta"] = co["theta"] if "roll" in co: self.__CinemaTracks["roll"] = co["roll"] tracking_def = {} if "tracking" in co: tracking_def = co['tracking'] #figure out what we show now pxystate= pv_introspect.record_visibility() # a conservative global bounds for consistent z scaling minbds, maxbds = pv_introspect.max_bounds() #make sure depth rasters are consistent view.MaxClipBounds = [minbds, maxbds, minbds, maxbds, minbds, maxbds] view.LockBounds = 1 disableValues = False if 'noValues' not in co else co['noValues'] if specLevel=="B": p = pv_introspect.inspect(skip_invisible=True) else: p = pv_introspect.inspect(skip_invisible=False) fs = pv_introspect.make_cinema_store(p, fname, view, forcetime = formatted_time, userDefined = self.__CinemaTracks, specLevel = specLevel, camType = camType, extension = extension, disableValues = disableValues) #all nodes participate, but only root can writes out the files pm = servermanager.vtkProcessModule.GetProcessModule() pid = pm.GetPartitionId() enableFloatVal = False if 'floatValues' not in co else co['floatValues'] new_files = {} ret = pv_introspect.explore(fs, p, iSave = (pid == 0), currentTime = {'time':formatted_time}, userDefined = self.__CinemaTracks, specLevel = specLevel, camType = camType, tracking = tracking_def, floatValues = enableFloatVal, disableValues = disableValues) if pid == 0: fs.save() new_files[vfname] = ret; view.LockBounds = 0 #restore what we showed pv_introspect.restore_visibility(pxystate) return os.path.basename(vfname), new_files