class Pipeline: # Define source of pipeline grid = coprocessor.CreateProducer(datadescription, "input") if (write_full_output == True): fullWriter = pvs.XMLPUnstructuredGridWriter( Input=grid, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(fullWriter, filename='full_output_%t.pvtu', freq=1) # Create a spherical slice slice = pvs.Slice(Input=grid) slice.SliceType = 'Sphere' slice.Triangulatetheslice = 0 slice.SliceOffsetValues = [0.0] slice.SliceType.Radius = sphere_radius # Create writer for this data and register it with the pipeline sliceWriter = pvs.XMLPPolyDataWriter(Input=slice, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(sliceWriter, filename='spherical_slice_%t.pvtp', freq=1)
class Pipeline: # Define source of pipeline grid = coprocessor.CreateProducer(datadescription, "input") if (write_full_output == True): fullWriter = pvs.XMLPUnstructuredGridWriter( Input=grid, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(fullWriter, filename='full_output_%t.pvtu', freq=1) # Determine grid bounds gridBounds = grid.GetClientSideObject().GetOutputDataObject( 0).GetBounds() # Plane slice at the desired longitude slice = pvs.Slice(Input=grid) slice.SliceType = 'Plane' slice.Triangulatetheslice = 0 slice.SliceOffsetValues = [0.0] slice.SliceType.Origin = [ longitude / 180.0 * math.pi, 0, gridBounds[4] ] slice.SliceType.Normal = [1, 0, 0] # Create new writer sliceWriter = pvs.XMLPPolyDataWriter(Input=slice, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(sliceWriter, filename='meridional_slice_%t.pvtp', freq=1)
def CreatePipeline(self): ''' Create slice and integration filters different slices can be saved by adjusting the slice filter's position ''' self.slice = pvs.Slice(Input = self.reader) self.integrator = pvs.IntegrateVariables(Input = self.slice) self.integrator.DivideCellDataByVolume = True
def get_slice(self, x=0.0, y=0.0, z=0.0, normal=(0, 1, 0), source=None): slice1 = self.slice1 = pv.Slice(Input=source if source else self.nek5000) slice1.SliceType = "Plane" slice1.SliceOffsetValues = [0.0] slice1.SliceType.Origin = [x, y, z] slice1.SliceType.Normal = list(normal) # slice1.Triangulatetheslice = 0 # slice_data = vtkio.getBlockByName(mb_dset, 'mesh') # pv.SetActiveSource(slice1) return NekSlice(slice1)
def __init__(self, file_name_generator, view, data, colorByArray, steps=10, normal=[0.0, 0.0, 1.0], viewup=[0.0, 1.0, 0.0], bound_range=[0.0, 1.0], parallelScaleRatio=1.5): """ file_name_generator: the file name generator to use. Need to have ['sliceColor', 'slicePosition'] as keys. view: View proxy to render in data: Input proxy to process colorByArray: { "RTData": { "lut": ... , "type": 'POINT_DATA'} } steps: Number of slice along the given axis. Default 10 normal: Slice plane normal. Default [0,0,1] viewup=[0.0,1.0,0.0] bound_range: Array of 2 percentage of the actual data bounds. Default full bounds [0.0, 1.0] scaleParallelProj """ self.view_proxy = view self.slice = simple.Slice(SliceType="Plane", Input=data, SliceOffsetValues=[0.0]) self.sliceRepresentation = simple.Show(self.slice) self.colorByArray = colorByArray self.parallelScaleRatio = parallelScaleRatio self.slice.SliceType.Normal = normal self.dataBounds = data.GetDataInformation().GetBounds() self.normal = normal self.viewup = viewup self.origin = [ self.dataBounds[0] + bound_range[0] * (self.dataBounds[1] - self.dataBounds[0]), self.dataBounds[2] + bound_range[0] * (self.dataBounds[3] - self.dataBounds[2]), self.dataBounds[4] + bound_range[0] * (self.dataBounds[5] - self.dataBounds[4]) ] self.number_of_steps = steps ratio = (bound_range[1] - bound_range[0]) / float(steps - 1) self.origin_inc = [ normal[0] * ratio * (self.dataBounds[1] - self.dataBounds[0]), normal[1] * ratio * (self.dataBounds[3] - self.dataBounds[2]), normal[2] * ratio * (self.dataBounds[5] - self.dataBounds[4]) ] # Update file name pattern self.file_name_generator = file_name_generator
def Slice_PV_data_to_txt_file(inputFileName, outputFileName, point, normal,resolution): pvs._DisableFirstRenderCameraReset() data_vtu = pvs.XMLUnstructuredGridReader(FileName=[inputFileName]) Slice1 = pvs.Slice(SliceType="Plane") Slice1.SliceOffsetValues = [0.0] Slice1.SliceType.Origin = point Slice1.SliceType.Normal = normal CellCenters1 = pvs.CellCenters() writer = pvs.CreateWriter(outputFileName, CellCenters1) writer.Precision=resolution writer.FieldAssociation = "Points" # or "Cells" writer.UpdatePipeline()
def _sliceSurfaces(self, slice): if self.meshSlice is not None: simple.Delete(self.meshSlice) self.meshSlice = None for surface in self.surfaces: rep = simple.Show(surface) if self.sliceMode == 'XY Plane': origin = [ 0.0, 0.0, math.cos(math.radians(rep.Orientation[2])) * slice ] normal = [0.0, 0.0, 1.0] elif self.sliceMode == 'XZ Plane': origin = [ 0.0, math.cos(math.radians(rep.Orientation[1])) * slice, 0.0 ] normal = [0.0, 1.0, 0.0] else: origin = [ math.cos(math.radians(rep.Orientation[0])) * slice, 0.0, 0.0 ] normal = [1.0, 0.0, 0.0] simple.Hide(surface) self.meshSlice = simple.Slice(Input=surface, SliceType='Plane') simple.SetActiveSource(self.srcObj) self.meshSlice.SliceOffsetValues = [0.0] self.meshSlice.SliceType = 'Plane' self.meshSlice.SliceType.Origin = origin self.meshSlice.SliceType.Normal = normal meshDataRep = simple.Show(self.meshSlice) meshDataRep.Representation = 'Points' meshDataRep.LineWidth = self.CONTOUR_LINE_WIDTH meshDataRep.PointSize = self.CONTOUR_LINE_WIDTH meshDataRep.AmbientColor = rep.DiffuseColor meshDataRep.Orientation = rep.Orientation simple.SetActiveSource(self.srcObj)
def test_slice(self): pv.Connect() # using a dedicated server state for each test print "\nTEST_SLICE" # set up some processing task view_proxy = pv.CreateRenderView() view_proxy.OrientationAxesVisibility = 0 s = pv.Sphere() sliceFilt = pv.Slice( SliceType="Plane", Input=s, SliceOffsetValues=[0.0]) sliceFilt.SliceType.Normal = [0, 1, 0] sliceRep = pv.Show(sliceFilt) # make or open a cinema data store to put results in fname = "/tmp/test_pv_slice/info.json" cs = file_store.FileStore(fname) cs.add_metadata({'type': 'parametric-image-stack'}) cs.add_metadata({'store_type': 'FS'}) cs.add_metadata({'version': '0.0'}) cs.filename_pattern = "{phi}_{theta}_{offset}_{color}_slice.png" cs.add_parameter( "phi", store.make_parameter('phi', [90, 120, 140])) cs.add_parameter( "theta", store.make_parameter('theta', [-90, -30, 30, 90])) cs.add_parameter( "offset", store.make_parameter('offset', [-.4, -.2, 0, .2, .4])) cs.add_parameter( "color", store.make_parameter( 'color', ['yellow', 'cyan', "purple"], typechoice='list')) colorChoice = pv_explorers.ColorList() colorChoice.AddSolidColor('yellow', [1, 1, 0]) colorChoice.AddSolidColor('cyan', [0, 1, 1]) colorChoice.AddSolidColor('purple', [1, 0, 1]) # associate control points with parameters of the data store cam = pv_explorers.Camera([0, 0, 0], [0, 1, 0], 10.0, view_proxy) filt = pv_explorers.Slice("offset", sliceFilt) col = pv_explorers.Color("color", colorChoice, sliceRep) params = ["phi", "theta", "offset", "color"] e = pv_explorers.ImageExplorer( cs, params, [cam, filt, col], view_proxy) # run through all parameter combinations and put data into the store e.explore() # Reproduce an entry and compare vs. loaded # First set the parameters to reproduce cam.execute(store.Document({'theta': -30, 'phi': 120})) filt.execute(store.Document({'offset': -.4})) col.execute(store.Document({'color': 'cyan'})) imageslice = ch.pvRenderToArray(view_proxy) # Now load the corresponding entry cs2 = file_store.FileStore(fname) cs2.load() docs = [] for doc in cs2.find( {'theta': -30, 'phi': 120, 'offset': -.4, 'color': 'cyan'}): docs.append(doc.data) # print "gen entry: \n", # imageslice, "\n", # imageslice.shape,"\n", # "loaded: \n", # docs[0], "\n", # docs[0].shape # compare the two l2error = ch.compare_l2(imageslice, docs[0]) ncc = ch.compare_ncc(imageslice, docs[0]) self.assertTrue((l2error < 1.0) and (ncc > 0.99)) pv.Disconnect() # using a dedicated server state for each test
PlotOverLine01 = Simple.PlotOverLine( guiName="PlotOverLine01", Source="High Resolution Line Source" ) PlotOverLine01.Source.Resolution = 100 PlotOverLine01.Source.Point2 = [0.00, 0.0, 20.0] PlotOverLine01.Source.Point1 = [0.00, 0.0, 0.0] # PF = Simple.ProgrammableFilter() PF.Script = Script01 Simple.Show(PF) #-------------------------------------------------------------------------||---# #-------------------------------------------------------------------------||---# Coords = Read_dat("XXX_COORDINATES.alya") for coord in Coords: print coord, Simple.SetActiveSource(InputData) Slice01 = Simple.Slice( guiName="Slice2", SliceOffsetValues=[0.0], SliceType="Plane" ) Slice01.SliceType.Origin = coord Slice01.SliceType.Normal = [0.0, 0.0, 1.0] Simple.SetActiveSource(Slice01) Calculator01 = Simple.Calculator(guiName="Calculator1", Function='VELOC_Z*TEMPE', ResultArrayName='UT') Simple.SetActiveSource(Calculator01) IntegrateVariables01 = Simple.IntegrateVariables( guiName="IntegrateVariables2" ) Simple.SetActiveSource(IntegrateVariables01) PF = Simple.ProgrammableFilter() PF.Script = Script02 Simple.Show(PF)
ih.mag(flines[start_p].fieldLineData_f[(n * num_divs)])) contours[start_p] = test_contour_list contsphere_b[start_p] = test_points_b contsphere_f[start_p] = test_points_f min_sphr[start_p] = pv.Sphere() min_sphr[start_p].Radius = 0.06 min_sphr[start_p].Center = Bmin_loc min_sphr_disp[start_p] = pv.Show(min_sphr[start_p], rvs) min_sphr_disp[start_p].DiffuseColor = [0.0, 0.0, 0.0] Bmag_calc = pv.Calculator(Input=t96_128) Bmag_calc.ResultArrayName = 'Bmag' Bmag_calc.Function = 'mag(B)' Bmag_slice = pv.Slice(Input=Bmag_calc) Bmag_slice.SliceType = 'Plane' Bmag_slice.SliceOffsetValues = [0.0] Bmag_slice.SliceType.Origin = [-20.0, 0.0, 0.0] Bmag_slice.SliceType.Normal = [0.0, 1.0, 0.0] Bmag_contour = {} for key in contsphere_b: for x in contsphere_f[key]: pv.Hide(x, view=rvs) for x in contsphere_b[key]: pv.Hide(x, view=rvs) pv.Render(view=rvs)
def solve(filename,resolution,meshType, testColor): start = time.time() test_desc["Mesh_type"]=meshType test_desc["Test_color"]=testColor #Chargement du maillage triangulaire de la sphère #======================================================================================= my_mesh = cdmath.Mesh(filename+".med") if(not my_mesh.isTriangular()) : raise ValueError("Wrong cell types : mesh is not made of triangles") if(my_mesh.getMeshDimension()!=2) : raise ValueError("Wrong mesh dimension : expected a surface of dimension 2") if(my_mesh.getSpaceDimension()!=3) : raise ValueError("Wrong space dimension : expected a space of dimension 3") nbNodes = my_mesh.getNumberOfNodes() nbCells = my_mesh.getNumberOfCells() test_desc["Space_dimension"]=my_mesh.getSpaceDimension() test_desc["Mesh_dimension"]=my_mesh.getMeshDimension() test_desc["Mesh_number_of_elements"]=my_mesh.getNumberOfNodes() test_desc["Mesh_cell_type"]=my_mesh.getElementTypes() print("Mesh building/loading done") print("nb of nodes=", nbNodes) print("nb of cells=", nbCells) #Discrétisation du second membre et détermination des noeuds intérieurs #====================================================================== my_RHSfield = cdmath.Field("RHS_field", cdmath.NODES, my_mesh, 1) maxNbNeighbours = 0#This is to determine the number of non zero coefficients in the sparse finite element rigidity matrix #parcours des noeuds pour discrétisation du second membre et extraction du nb max voisins d'un noeud for i in range(nbNodes): Ni=my_mesh.getNode(i) x = Ni.x() y = Ni.y() z = Ni.z() my_RHSfield[i]=12*y*(3*x*x-y*y)/pow(x*x+y*y+z*z,3/2)#vecteur propre du laplacien sur la sphère if my_mesh.isBorderNode(i): # Détection des noeuds frontière raise ValueError("Mesh should not contain borders") else: maxNbNeighbours = max(1+Ni.getNumberOfCells(),maxNbNeighbours) test_desc["Mesh_max_number_of_neighbours"]=maxNbNeighbours print("Right hand side discretisation done") print("Max nb of neighbours=", maxNbNeighbours) print("Integral of the RHS", my_RHSfield.integral(0)) # Construction de la matrice de rigidité et du vecteur second membre du système linéaire #======================================================================================= Rigidite=cdmath.SparseMatrixPetsc(nbNodes,nbNodes,maxNbNeighbours)# warning : third argument is number of non zero coefficients per line RHS=cdmath.Vector(nbNodes) # Vecteurs gradient de la fonction de forme associée à chaque noeud d'un triangle GradShapeFunc0=cdmath.Vector(3) GradShapeFunc1=cdmath.Vector(3) GradShapeFunc2=cdmath.Vector(3) normalFace0=cdmath.Vector(3) normalFace1=cdmath.Vector(3) #On parcourt les triangles du domaine for i in range(nbCells): Ci=my_mesh.getCell(i) #Contribution à la matrice de rigidité nodeId0=Ci.getNodeId(0) nodeId1=Ci.getNodeId(1) nodeId2=Ci.getNodeId(2) N0=my_mesh.getNode(nodeId0) N1=my_mesh.getNode(nodeId1) N2=my_mesh.getNode(nodeId2) #Build normal to cell Ci normalFace0[0]=Ci.getNormalVector(0,0) normalFace0[1]=Ci.getNormalVector(0,1) normalFace0[2]=Ci.getNormalVector(0,2) normalFace1[0]=Ci.getNormalVector(1,0) normalFace1[1]=Ci.getNormalVector(1,1) normalFace1[2]=Ci.getNormalVector(1,2) normalCell = normalFace0.crossProduct(normalFace1) test = normalFace0.tensProduct(normalFace1) normalCell = normalCell/normalCell.norm() cellMat=cdmath.Matrix(4) cellMat[0,0]=N0.x() cellMat[0,1]=N0.y() cellMat[0,2]=N0.z() cellMat[1,0]=N1.x() cellMat[1,1]=N1.y() cellMat[1,2]=N1.z() cellMat[2,0]=N2.x() cellMat[2,1]=N2.y() cellMat[2,2]=N2.z() cellMat[3,0]=normalCell[0] cellMat[3,1]=normalCell[1] cellMat[3,2]=normalCell[2] cellMat[0,3]=1 cellMat[1,3]=1 cellMat[2,3]=1 cellMat[3,3]=0 #Formule des gradients voir EF P1 -> calcul déterminants GradShapeFunc0[0]= cellMat.partMatrix(0,0).determinant()/2 GradShapeFunc0[1]=-cellMat.partMatrix(0,1).determinant()/2 GradShapeFunc0[2]= cellMat.partMatrix(0,2).determinant()/2 GradShapeFunc1[0]=-cellMat.partMatrix(1,0).determinant()/2 GradShapeFunc1[1]= cellMat.partMatrix(1,1).determinant()/2 GradShapeFunc1[2]=-cellMat.partMatrix(1,2).determinant()/2 GradShapeFunc2[0]= cellMat.partMatrix(2,0).determinant()/2 GradShapeFunc2[1]=-cellMat.partMatrix(2,1).determinant()/2 GradShapeFunc2[2]= cellMat.partMatrix(2,2).determinant()/2 #Création d'un tableau (numéro du noeud, gradient de la fonction de forme GradShapeFuncs={nodeId0 : GradShapeFunc0} GradShapeFuncs[nodeId1]=GradShapeFunc1 GradShapeFuncs[nodeId2]=GradShapeFunc2 # Remplissage de la matrice de rigidité et du second membre for j in [nodeId0,nodeId1,nodeId2] : #Ajout de la contribution de la cellule triangulaire i au second membre du noeud j RHS[j]=Ci.getMeasure()/3*my_RHSfield[j]+RHS[j] # intégrale dans le triangle du produit f x fonction de base #Contribution de la cellule triangulaire i à la ligne j du système linéaire for k in [nodeId0,nodeId1,nodeId2] : Rigidite.addValue(j,k,GradShapeFuncs[j]*GradShapeFuncs[k]/Ci.getMeasure()) print("Linear system matrix building done") # Résolution du système linéaire #================================= LS=cdmath.LinearSolver(Rigidite,RHS,100,1.E-2,"CG","ILU")#Remplacer CG par CHOLESKY pour solveur direct LS.isSingular()#En raison de l'absence de bord LS.setComputeConditionNumber() SolSyst=LS.solve() print "Preconditioner used : ", LS.getNameOfPc() print "Number of iterations used : ", LS.getNumberOfIter() print "Final residual : ", LS.getResidu() print("Linear system solved") test_desc["Linear_solver_algorithm"]=LS.getNameOfMethod() test_desc["Linear_solver_preconditioner"]=LS.getNameOfPc() test_desc["Linear_solver_precision"]=LS.getTolerance() test_desc["Linear_solver_maximum_iterations"]=LS.getNumberMaxOfIter() test_desc["Linear_system_max_actual_iterations_number"]=LS.getNumberOfIter() test_desc["Linear_system_max_actual_error"]=LS.getResidu() test_desc["Linear_system_max_actual_condition number"]=LS.getConditionNumber() # Création du champ résultat #=========================== my_ResultField = cdmath.Field("ResultField", cdmath.NODES, my_mesh, 1) for j in range(nbNodes): my_ResultField[j]=SolSyst[j];#remplissage des valeurs pour les noeuds intérieurs #sauvegarde sur le disque dur du résultat dans un fichier paraview my_ResultField.writeVTK("FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)) end = time.time() print("Integral of the numerical solution", my_ResultField.integral(0)) print("Numerical solution of poisson equation on a sphere using finite elements done") #Calcul de l'erreur commise par rapport à la solution exacte #=========================================================== #The following formulas use the fact that the exact solution is equal the right hand side divided by 12 max_abs_sol_exacte=0 erreur_abs=0 max_sol_num=0 min_sol_num=0 for i in range(nbNodes) : if max_abs_sol_exacte < abs(my_RHSfield[i]) : max_abs_sol_exacte = abs(my_RHSfield[i]) if erreur_abs < abs(my_RHSfield[i]/12 - my_ResultField[i]) : erreur_abs = abs(my_RHSfield[i]/12 - my_ResultField[i]) if max_sol_num < my_ResultField[i] : max_sol_num = my_ResultField[i] if min_sol_num > my_ResultField[i] : min_sol_num = my_ResultField[i] max_abs_sol_exacte = max_abs_sol_exacte/12 print("Absolute error = max(| exact solution - numerical solution |) = ",erreur_abs ) print("Relative error = max(| exact solution - numerical solution |)/max(| exact solution |) = ",erreur_abs/max_abs_sol_exacte) print ("Maximum numerical solution = ", max_sol_num, " Minimum numerical solution = ", min_sol_num) test_desc["Computational_time_taken_by_run"]=end-start test_desc["Absolute_error"]=erreur_abs test_desc["Relative_error"]=erreur_abs/max_abs_sol_exacte #Postprocessing : #================ # save 3D picture PV_routines.Save_PV_data_to_picture_file("FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)+'_0.vtu',"ResultField",'NODES',"FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)) # save 3D clip VTK_routines.Clip_VTK_data_to_VTK("FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)+'_0.vtu',"Clip_VTK_data_to_VTK_"+ "FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)+'_0.vtu',[0.25,0.25,0.25], [-0.5,-0.5,-0.5],resolution ) PV_routines.Save_PV_data_to_picture_file("Clip_VTK_data_to_VTK_"+"FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)+'_0.vtu',"ResultField",'NODES',"Clip_VTK_data_to_VTK_"+"FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)) # save plot around circumference finiteElementsOnSphere_0vtu = pvs.XMLUnstructuredGridReader(FileName=["FiniteElementsOnSpherePoisson_"+meshType+str(nbNodes)+'_0.vtu']) slice1 = pvs.Slice(Input=finiteElementsOnSphere_0vtu) slice1.SliceType.Normal = [0.5, 0.5, 0.5] renderView1 = pvs.GetActiveViewOrCreate('RenderView') finiteElementsOnSphere_0vtuDisplay = pvs.Show(finiteElementsOnSphere_0vtu, renderView1) pvs.ColorBy(finiteElementsOnSphere_0vtuDisplay, ('POINTS', 'ResultField')) slice1Display = pvs.Show(slice1, renderView1) pvs.SaveScreenshot("./FiniteElementsOnSpherePoisson"+"_Slice_"+meshType+str(nbNodes)+'.png', magnification=1, quality=100, view=renderView1) plotOnSortedLines1 = pvs.PlotOnSortedLines(Input=slice1) pvs.SaveData('./FiniteElementsOnSpherePoisson_PlotOnSortedLines'+meshType+str(nbNodes)+'.csv', proxy=plotOnSortedLines1) lineChartView2 = pvs.CreateView('XYChartView') plotOnSortedLines1Display = pvs.Show(plotOnSortedLines1, lineChartView2) plotOnSortedLines1Display.UseIndexForXAxis = 0 plotOnSortedLines1Display.XArrayName = 'arc_length' plotOnSortedLines1Display.SeriesVisibility = ['ResultField (1)'] pvs.SaveScreenshot("./FiniteElementsOnSpherePoisson"+"_PlotOnSortedLine_"+meshType+str(nbNodes)+'.png', magnification=1, quality=100, view=lineChartView2) pvs.Delete(lineChartView2) with open('test_Poisson'+str(my_mesh.getMeshDimension())+'D_EF_'+meshType+str(nbCells)+ "Cells.json", 'w') as outfile: json.dump(test_desc, outfile) return erreur_abs/max_abs_sol_exacte, nbNodes, min_sol_num, max_sol_num, end - start
class Pipeline: # Define source of pipeline grid = coprocessor.CreateProducer(datadescription, "input") if (write_full_output == True): fullWriter = pvs.XMLPUnstructuredGridWriter( Input=grid, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(fullWriter, filename='full_output_%t.pvtu', freq=1) # Create a spherical slice slice = pvs.Slice(Input=grid) slice.SliceType = 'Sphere' slice.Triangulatetheslice = 0 slice.SliceOffsetValues = [0.0] slice.SliceType.Radius = sphere_radius # Generate ghost cells - needed by CellDatatoPointData filter ghosts = pvs.GhostCellsGenerator(Input=grid) ghosts.BuildIfRequired = 0 ghosts.MinimumNumberOfGhostLevels = 1 # Convert cell data to point data, which is required for good contour results # Request "piece invariance" to ensure consistent values at # partition boundaries. # # CAUTION: THIS FILTER AVERAGES DATA FROM ALL CELLS SURROUNDING A POINT, # WHICH REDUCES ACCURACY cell2point = pvs.CellDatatoPointData(Input=ghosts) # Create contours # Note that the "tube" filter can be used to highlight contours if needed. contours = pvs.Contour(Input=cell2point) contours.Isosurfaces = contour_values contours.ContourBy = ['POINTS', 'rho'] contours.PointMergeMethod = 'Uniform Binning' # Create writers for slice and contour data and register them with the pipeline # Note that slice and contours generate separate datasets, so they need to be # written to separate files. sliceWriter = pvs.XMLPPolyDataWriter(Input=slice, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(sliceWriter, filename='spherical_slice_%t.pvtp', freq=1) # Create a new render view renderView = pvs.CreateView('RenderView') renderView.ViewSize = [1500, 768] renderView.AxesGrid = 'GridAxes3DActor' renderView.StereoType = 0 renderView.CameraPosition = [0.0, 1.0, 0.3] renderView.CameraViewUp = [0.0, 0.0, 1.0] renderView.CameraParallelScale = 1.0 renderView.Background = [0.32, 0.34, 0.43] renderView.ViewTime = datadescription.GetTime() # Register the view with coprocessor # and provide it with information such as the filename to use, # how frequently to write the images, etc. coprocessor.RegisterView(renderView, filename='contours_%t.png', freq=1, fittoscreen=1, magnification=1, width=1500, height=768, cinema={}) # Create colour transfer function for field LUT = pvs.GetColorTransferFunction('rho') LUT.RGBPoints = [ dataRange[0], 0.23, 0.30, 0.75, 0.5 * sum(dataRange), 0.87, 0.87, 0.87, dataRange[1], 0.71, 0.016, 0.15 ] LUT.ScalarRangeInitialized = 1.0 # Show surface and colour by field value (which is cell data) using lookup table sphereDisplay = pvs.Show(slice, renderView) sphereDisplay.Representation = 'Surface' sphereDisplay.ColorArrayName = ['CELLS', 'rho'] sphereDisplay.LookupTable = LUT # Show coastlines contourDisplay = pvs.Show(contours, renderView) contourDisplay.Representation = 'Surface' contourDisplay.ColorArrayName = [None, ''] contourDisplay.OSPRayScaleArray = 'theta ' contourDisplay.OSPRayScaleFunction = 'PiecewiseFunction' contourDisplay.SelectOrientationVectors = 'None' contourDisplay.ScaleFactor = 1193042.2418936265 contourDisplay.SelectScaleArray = 'None' contourDisplay.GlyphType = 'Arrow' contourDisplay.GlyphTableIndexArray = 'None' contourDisplay.DataAxesGrid = 'GridAxesRepresentation' contourDisplay.PolarAxes = 'PolarAxesRepresentation' contourDisplay.GaussianRadius = 596521.1209468133 contourDisplay.SetScaleArray = ['POINTS', 'theta '] contourDisplay.ScaleTransferFunction = 'PiecewiseFunction' contourDisplay.OpacityArray = ['POINTS', 'theta '] contourDisplay.OpacityTransferFunction = 'PiecewiseFunction'
def norm_slices_along_points(pointsNm, dataNm, numSlices=10, exportpath='', ext='.csv'): """ This macro takes a series of points and a data source to be sliced. The points are used to construct a path through the data source and a slice is added at intervals of that path along the vector of that path at that point. This constructs `numSlices` slices through the dataset `dataNm`. Parameters ---------- pointsNm : string The string name of the points source to construct the path. dataNm : string The string name of the data source to slice. Make sure this data source is slice-able. numSlices : int, optional The number of slices along the path. exportpath : string, optional The absolute file path of where to save each slice ext : string, optional The file extension for saving out the slices. Default to '.csv' Notes ----- Make sure the input data source is slice-able. The SciPy module is required for this macro. """ # import the simple module from the paraview and other needed libraries import paraview.simple as pvs import numpy as np from scipy.spatial import cKDTree from vtk.util import numpy_support as nps from vtk.numpy_interface import dataset_adapter as dsa # exportpath: Where to save data. Absolute path: # Specify Points for the Line Source: line = pvs.servermanager.Fetch(pvs.FindSource(pointsNm)) # Specify data set to be sliced data = pvs.FindSource(dataNm) # get active view renderView = pvs.GetActiveViewOrCreate('RenderView') # Get the Points over the NumPy interface wpdi = dsa.WrapDataObject(line) # NumPy wrapped points points = np.array( wpdi.Points) # New NumPy array of points so we dont destroy input numPoints = line.GetNumberOfPoints() tree = cKDTree(points) dist, ptsi = tree.query(points[0], k=numPoints) # iterate of points in order (skips last point): num = 0 for i in range(0, numPoints - 1, numPoints / numSlices): # get normal pts1 = points[ptsi[i]] pts2 = points[ptsi[i + 1]] x1, y1, z1 = pts1[0], pts1[1], pts1[2] x2, y2, z2 = pts2[0], pts2[1], pts2[2] norm = [x2 - x1, y2 - y1, z2 - z1] # create slice slc = pvs.Slice(Input=data) slc.SliceType = 'Plane' # set origin at points slc.SliceType.Origin = [x1, y1, z1] # set normal as vector from current point to next point slc.SliceType.Normal = norm if exportpath != '': # save out slice with good metadata: TODO: change name # This will use a value from the point data to add to the name #num = wpdi.PointData['Advance LL (S-558)'][ptsi[i]] filename = path + 'Slice_%d%s' % (num, ext) print(filename) pvs.SaveData(filename, proxy=slc) num += 1 pvs.Show(slc, renderView) pvs.RenderAllViews() pvs.ResetCamera()
class Pipeline: # Define source of pipeline grid = coprocessor.CreateProducer(datadescription, "input") if (write_full_output == True): fullWriter = pvs.XMLPUnstructuredGridWriter( Input=grid, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(fullWriter, filename='full_output_%t.pvtu', freq=1) # Create a spherical slice slice = pvs.Slice(Input=grid) slice.SliceType = 'Sphere' slice.Triangulatetheslice = 0 slice.SliceOffsetValues = [0.0] slice.SliceType.Radius = sphere_radius # Create writer for this data and register it with the pipeline sliceWriter = pvs.XMLPPolyDataWriter(Input=slice, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(sliceWriter, filename='spherical_slice_%t.pvtp', freq=1) # Create a new render view renderView = pvs.CreateView('RenderView') renderView.ViewSize = [1500, 768] renderView.AxesGrid = 'GridAxes3DActor' renderView.StereoType = 0 renderView.CameraPosition = [-5, -2, 4] renderView.CameraViewUp = [0.5, 0.3, 0.8] renderView.CameraParallelScale = 1.7 renderView.Background = [0.32, 0.34, 0.43] renderView.ViewTime = datadescription.GetTime() # Register the view with coprocessor # and provide it with information such as the filename to use, # how frequently to write the images, etc. coprocessor.RegisterView(renderView, filename='spherical_slice_%t.png', freq=1, fittoscreen=1, magnification=1, width=1500, height=768, cinema={}) # Create colour transfer function for field LUT = pvs.GetColorTransferFunction(fieldname) LUT.RGBPoints = [ dataRange[0], 0.23, 0.30, 0.75, 0.5 * sum(dataRange), 0.87, 0.87, 0.87, dataRange[1], 0.71, 0.016, 0.15 ] LUT.ScalarRangeInitialized = 1.0 # Show surface and colour by field value (which is cell data) using lookup table sphereDisplay = pvs.Show(slice, renderView) sphereDisplay.Representation = 'Surface' sphereDisplay.ColorArrayName = ['CELLS', fieldname] sphereDisplay.LookupTable = LUT
class Pipeline: # Read topographic data topo = pvs.XMLPolyDataReader(FileName="ETOPO_10min_Ice.vtp") # Scale data to just under radius of the sphere toposcaled = pvs.Calculator(Input=topo) toposcaled.CoordinateResults = 1 toposcaled.Function = '%i*coords' % (sphere_radius * 0.99) # Define source of pipeline grid = coprocessor.CreateProducer(datadescription, "input") ghosts = pvs.GhostCellsGenerator(Input=grid) ghosts.BuildIfRequired = 0 ghosts.MinimumNumberOfGhostLevels = 1 # Create a spherical slice slice = pvs.Slice(Input=ghosts) slice.SliceType = 'Sphere' slice.Triangulatetheslice = 0 slice.SliceOffsetValues = [0.0] slice.SliceType.Radius = sphere_radius # Convert cell data to point data, which is required for good contour results # # CAUTION: THIS FILTER AVERAGES DATA FROM ALL CELLS SURROUNDING A POINT, # WHICH REDUCES ACCURACY cell2point = pvs.CellDatatoPointData(Input=slice) cell2point.PassCellData = 0 cell2point.PieceInvariant = 0 # Create contours # Note that the "tube" filter can be used to highlight contours if needed. contours = pvs.Contour(Input=cell2point) contours.Isosurfaces = contour_values contours.ContourBy = ['POINTS', 'rho'] contours.PointMergeMethod = 'Uniform Binning' # Create a new render view renderView = pvs.CreateView('RenderView') renderView.ViewSize = [1500, 768] renderView.AxesGrid = 'GridAxes3DActor' renderView.StereoType = 0 renderView.CameraPosition = [0.0, 1.0, 0.3] renderView.CameraViewUp = [0.0, 0.0, 1.0] renderView.CameraParallelScale = 1.0 renderView.Background = [0.32, 0.34, 0.43] renderView.ViewTime = datadescription.GetTime() # Register the view with coprocessor # and provide it with information such as the filename to use, # how frequently to write the images, etc. coprocessor.RegisterView(renderView, filename='topo_contours_%t.png', freq=1, fittoscreen=1, magnification=1, width=800, height=800, cinema={}) # Create colour transfer function for field LUT = pvs.GetColorTransferFunction('altitude') # Use Wikipedia LUT as provided on http://www.earthmodels.org/data-and-tools/color-tables LUT.RGBPoints = [ -11000, 0.141176470588235, 0.149019607843137, 0.686274509803922, -5499.999, 0.219607843137255, 0.227450980392157, 0.764705882352941, -5500, 0.219607843137255, 0.227450980392157, 0.764705882352941, -2999.999, 0.274509803921569, 0.282352941176471, 0.83921568627451, -3000, 0.274509803921569, 0.282352941176471, 0.83921568627451, -1999.999, 0.317647058823529, 0.4, 0.850980392156863, -2000, 0.317647058823529, 0.4, 0.850980392156863, -749.999, 0.392156862745098, 0.505882352941176, 0.874509803921569, -750, 0.392156862745098, 0.505882352941176, 0.874509803921569, -69.999, 0.513725490196078, 0.631372549019608, 0.901960784313726, -70, 0.513725490196078, 0.631372549019608, 0.901960784313726, -19.999, 0.643137254901961, 0.752941176470588, 0.941176470588235, -20, 0.643137254901961, 0.752941176470588, 0.941176470588235, 0.001, 0.666666666666667, 0.784313725490196, 1, 0, 0, 0.380392156862745, 0.27843137254902, 50.001, 0.0627450980392157, 0.47843137254902, 0.184313725490196, 50, 0.0627450980392157, 0.47843137254902, 0.184313725490196, 500.001, 0.909803921568627, 0.843137254901961, 0.490196078431373, 500, 0.909803921568627, 0.843137254901961, 0.490196078431373, 1200.001, 0.631372549019608, 0.262745098039216, 0, 1200, 0.631372549019608, 0.262745098039216, 0, 1700.001, 0.509803921568627, 0.117647058823529, 0.117647058823529, 1700, 0.509803921568627, 0.117647058823529, 0.117647058823529, 2800.001, 0.431372549019608, 0.431372549019608, 0.431372549019608, 2800, 0.431372549019608, 0.431372549019608, 0.431372549019608, 4000.001, 1, 1, 1, 4000, 1, 1, 1, 6000.001, 1, 1, 1 ] LUT.ScalarRangeInitialized = 1.0 # Show topo data sphereDisplay = pvs.Show(toposcaled, renderView) sphereDisplay.Representation = 'Surface' sphereDisplay.ColorArrayName = ['POINTS', 'altitude'] sphereDisplay.LookupTable = LUT sphereDisplay.Opacity = 1.0 # Show surface and colour by field value (which is cell data) using lookup table sphereDisplay = pvs.Show(contours, renderView) sphereDisplay.Representation = 'Surface' sphereDisplay.Opacity = 1.0
class Pipeline: grid = coprocessor.CreateProducer(datadescription, 'input') # Simulation domain outline outline = pvs.Outline(Input=grid) # Horizontal slice at the bottom slice = pvs.Slice(Input=grid) slice.SliceType = 'Plane' slice.SliceOffsetValues = [0.0] slice.SliceType.Origin = [0.0, 0.0, 101.94] slice.SliceType.Normal = [0.0, 0.0, 1.0] slice.Triangulatetheslice = False # Glyphs for representing velocity field glyph = pvs.Glyph(Input=grid, GlyphType='Arrow') glyph.Vectors = ['CELLS', 'u'] glyph.ScaleMode = 'vector' glyph.ScaleFactor = 0.01 glyph.GlyphMode = 'Every Nth Point' glyph.Stride = 200 # Create a new render view renderView = pvs.CreateView('RenderView') renderView.ViewSize = [800, 400] renderView.InteractionMode = '2D' renderView.AxesGrid = 'GridAxes3DActor' renderView.CenterOfRotation = [0.18, 0.0, 102] renderView.StereoType = 0 renderView.CameraPosition = [-3.4, -6.8, 107] renderView.CameraFocalPoint = [-0.27, -0.41, 102] renderView.CameraViewUp = [0.057, 0.49, 0.87] renderView.CameraParallelScale = 1.0 renderView.Background = [0.32, 0.34, 0.43] # Register the view with coprocessor coprocessor.RegisterView(renderView, filename='image_%t.png', freq=1, fittoscreen=0, magnification=1, width=800, height=400, cinema={}) renderView.ViewTime = datadescription.GetTime() # Get color transfer function/color map for field rho rhoLUT = pvs.GetColorTransferFunction('rho') rhoLUT.RGBPoints = [ 1.17, 0.231, 0.298, 0.752, 1.33, 0.865, 0.865, 0.865, 1.49, 0.706, 0.0157, 0.149 ] rhoLUT.ScalarRangeInitialized = 1.0 # Show slice sliceDisplay = pvs.Show(slice, renderView) sliceDisplay.Representation = 'Surface With Edges' sliceDisplay.ColorArrayName = ['CELLS', 'rho'] sliceDisplay.LookupTable = rhoLUT sliceDisplay.ScaleFactor = 0.628 sliceDisplay.SelectScaleArray = 'None' sliceDisplay.GlyphType = 'Arrow' sliceDisplay.GlyphTableIndexArray = 'None' sliceDisplay.DataAxesGrid = 'GridAxesRepresentation' sliceDisplay.PolarAxes = 'PolarAxesRepresentation' sliceDisplay.GaussianRadius = 0.314 sliceDisplay.SetScaleArray = [None, ''] sliceDisplay.ScaleTransferFunction = 'PiecewiseFunction' sliceDisplay.OpacityArray = [None, ''] sliceDisplay.OpacityTransferFunction = 'PiecewiseFunction' # Show color legend sliceDisplay.SetScalarBarVisibility(renderView, True) # Show glyph glyphDisplay = pvs.Show(glyph, renderView) # Show outline outlineDisplay = pvs.Show(outline, renderView) # Get color legend/bar for rhoLUT in view renderView rhoLUTColorBar = pvs.GetScalarBar(rhoLUT, renderView) rhoLUTColorBar.WindowLocation = 'LowerRightCorner' rhoLUTColorBar.Title = 'rho' rhoLUTColorBar.ComponentTitle = ''
def execute(self): self.cdms_variables = self.forceGetInputListFromPort('cdms_variable') for cdms_var in self.cdms_variables: #// @todo: hardcoded for now time_values = [None, 1, True] #// Get the min and max to draw default contours min = cdms_var.var.min() max = cdms_var.var.max() reader = PVCDMSReader() image_data = reader.convert(cdms_var, time=time_values) #// Make white box filter so we can work at proxy level programmable_source = pvsp.ProgrammableSource() #// Get a hole of the vtk level filter it controls ps = programmable_source.GetClientSideObject() #// Give it some data (ie the imagedata) ps.myid = image_data programmable_source.OutputDataSetType = 'vtkImageData' programmable_source.PythonPath = '' #// Make the scripts that it runs in pipeline RI and RD passes programmable_source.ScriptRequestInformation = """ executive = self.GetExecutive() outInfo = executive.GetOutputInformation(0) extents = self.myid.GetExtent() spacing = self.myid.GetSpacing() outInfo.Set(executive.WHOLE_EXTENT(), extents[0], extents[1], extents[2], extents[3], extents[4], extents[5]) outInfo.Set(vtk.vtkDataObject.SPACING(), spacing[0], spacing[1], spacing[2]) dataType = 10 # VTK_FLOAT numberOfComponents = 1 vtk.vtkDataObject.SetPointDataActiveScalarInfo(outInfo, dataType, numberOfComponents)""" programmable_source.Script = """self.GetOutput().ShallowCopy(self.myid)""" programmable_source.UpdatePipeline() pvsp.SetActiveSource(programmable_source) self.slice_by_var_name = cdms_var.varname self.slice_by_var_type = 'POINTS' if not reader.is_three_dimensional(cdms_var): data_rep = pvsp.Show(view=self.view) data_rep.LookupTable = pvsp.GetLookupTableForArray( self.slice_by_var_name, 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[ min, 0.23, 0.299, 0.754, max, 0.706, 0.016, 0.15 ], VectorMode='Magnitude', ColorSpace='Diverging', LockScalarRange=1) data_rep.ColorArrayName = self.slice_by_var_name continue functions = [] try: slice_origin = self.forceGetInputListFromPort("slice_origin") if (slice_origin == None) or len(slice_origin) == 0: bounds = image_data.GetBounds() self.slice_origin = [] self.slice_origin.append((bounds[1] + bounds[0]) / 2.0) self.slice_origin.append((bounds[3] + bounds[2]) / 2.0) self.slice_origin.append((bounds[5] + bounds[4]) / 2.0) functions.append( ('slice_origin', [str(self.slice_origin).strip('[]')])) else: self.slice_origin = [ float(d) for d in slice_origin[0].split(',') ] slice_normal = self.forceGetInputListFromPort("slice_normal") if slice_normal == None or len(slice_normal) == 0: self.slice_normal = [0.0, 0.0, 1.0] functions.append( ('slice_normal', [str(self.slice_normal).strip('[]')])) else: self.slice_normal = [ float(d) for d in slice_normal[0].split(',') ] slice_offset_values = self.forceGetInputListFromPort( "slice_offset_values") if (len(slice_offset_values) and slice_offset_values): self.slice_offset_values = [ float(d) for d in slice_offset_values[0].split(',') ] else: self.slice_offset_values = [0.0] functions.append( ('slice_offset_values', [str(self.slice_offset_values).strip('[]')])) if len(functions) > 0: self.update_functions('PVSliceRepresentation', functions) #// Create a slice representation plane_slice = pvsp.Slice(SliceType="Plane") pvsp.SetActiveSource(plane_slice) plane_slice.SliceType.Normal = self.slice_normal plane_slice.SliceType.Origin = self.slice_origin plane_slice.SliceOffsetValues = self.slice_offset_values slice_rep = pvsp.Show(view=self.view) slice_rep.LookupTable = pvsp.GetLookupTableForArray( self.slice_by_var_name, 1, NanColor=[0.25, 0.0, 0.0], RGBPoints=[ min, 0.23, 0.299, 0.754, max, 0.706, 0.016, 0.15 ], VectorMode='Magnitude', ColorSpace='Diverging', LockScalarRange=1) slice_rep.ColorArrayName = self.slice_by_var_name slice_rep.Representation = 'Surface' #// Scalar bar ScalarBarWidgetRepresentation1 = pvsp.CreateScalarBar( Title=self.slice_by_var_name, LabelFontSize=12, Enabled=1, TitleFontSize=12) self.view.Representations.append( ScalarBarWidgetRepresentation1) if not reader.is_three_dimensional(cdms_var): ScalarBarWidgetRepresentation1.LookupTable = data_rep.LookupTable else: ScalarBarWidgetRepresentation1.LookupTable = slice_rep.LookupTable except ValueError: print "[ERROR] Unable to generate slice. Please check your input values" except (RuntimeError, TypeError, NameError): print "[ERROR] Unknown error"
PV_routines.Save_PV_data_to_picture_file("FiniteElementsOnSphere" + '_0.vtu', "ResultField", 'NODES', "FiniteElementsOnSphere") resolution = 100 VTK_routines.Clip_VTK_data_to_VTK( "FiniteElementsOnSphere" + '_0.vtu', "Clip_VTK_data_to_VTK_" + "FiniteElementsOnSphere" + '_0.vtu', [0.25, 0.25, 0.25], [-0.5, -0.5, -0.5], resolution) PV_routines.Save_PV_data_to_picture_file( "Clip_VTK_data_to_VTK_" + "FiniteElementsOnSphere" + '_0.vtu', "ResultField", 'NODES', "Clip_VTK_data_to_VTK_" + "FiniteElementsOnSphere") # Plot over slice circle finiteElementsOnSphere_0vtu = pvs.XMLUnstructuredGridReader( FileName=["FiniteElementsOnSphere" + '_0.vtu']) slice1 = pvs.Slice(Input=finiteElementsOnSphere_0vtu) slice1.SliceType.Normal = [0.5, 0.5, 0.5] renderView1 = pvs.GetActiveViewOrCreate('RenderView') finiteElementsOnSphere_0vtuDisplay = pvs.Show(finiteElementsOnSphere_0vtu, renderView1) pvs.ColorBy(finiteElementsOnSphere_0vtuDisplay, ('POINTS', 'ResultField')) slice1Display = pvs.Show(slice1, renderView1) pvs.SaveScreenshot("./FiniteElementsOnSphere" + "_Slice" + '.png', magnification=1, quality=100, view=renderView1) plotOnSortedLines1 = pvs.PlotOnSortedLines(Input=slice1) lineChartView2 = pvs.CreateView('XYChartView') plotOnSortedLines1Display = pvs.Show(plotOnSortedLines1, lineChartView2) plotOnSortedLines1Display.UseIndexForXAxis = 0 plotOnSortedLines1Display.XArrayName = 'arc_length'
def StreamlinesScript(Input1, Input2, Output, N1=None, N2=None, Offset1=0.0, Offset2=0.0, CamDirVec=None, CamUpVec=None, Origin=None): ''' Creates an image with the streamlines from two VTUs. Inputs: Input1 - VTU with first direction of curvatures Input2 - VTU with second direction of curvatures N1 - List of normal of slice for VTU1 N2 - List of normal of slice for VTU2 Offset1 - Value of offset for slice of VTU1 Offset2 - Value of offset for slice of VTU2 CamDirVec - Vector for camera direction CamUpVec - Vector for camera up direction Origin - Vector with the position for the origin''' #### disable automatic camera reset on 'Show' pvs._DisableFirstRenderCameraReset() # create a new 'XML Unstructured Grid Reader' VTU1 = pvs.XMLUnstructuredGridReader(FileName=[Input1]) VTU1.PointArrayStatus = ['Curvature'] ## Fix data for Slices if N1 is None: N1 = [0.9, 0.4, 0.2] if N2 is None: # N2 = np.cross(N1,[0,0,1]) N2 = [-0.8, 0.5, 0.16] if Origin is None: Origin = paraview.servermanager.Fetch( pvs.IntegrateVariables(Input=VTU1)).GetPoint(0) # create a new 'XML Unstructured Grid Reader' VTU2 = pvs.XMLUnstructuredGridReader(FileName=[Input2]) VTU2.PointArrayStatus = ['Curvature'] # get active view renderView1 = pvs.GetActiveViewOrCreate('RenderView') # show data in view VTU1Display = pvs.Show(VTU1, renderView1) VTU1Display.Representation = 'Surface' VTU1Display.Diffuse = 0.85 VTU1Display.Ambient = 0.25 # show data in view VTU2Display = pvs.Show(VTU2, renderView1) VTU2Display.Representation = 'Surface' VTU2Display.Diffuse = 0.85 VTU2Display.Ambient = 0.25 # create a new 'Slice' slice1 = pvs.Slice(Input=VTU1) slice1.SliceType.Origin = Origin slice1.SliceType.Normal = N1 slice1.SliceType.Offset = 0.0 slice1.SliceOffsetValues = [Offset1] # create a new 'Slice' slice2 = pvs.Slice(Input=VTU2) slice2.SliceType.Origin = Origin slice2.SliceType.Normal = N2 slice2.SliceType.Offset = 0.0 slice2.SliceOffsetValues = [Offset2] # make stremlines makestream(VTU1, slice1, renderView1, [1.0, 0.0, 0.0]) makestream(VTU2, slice2, renderView1, [0.0, 0.0, 1.0]) # Save Screenshot AdjustCameraAndSave(renderView1, Output, ImageResolution=(2048, 2048), CamDirVec=CamDirVec, CamUpVec=CamUpVec) # set active source pvs.SetActiveSource(None) pvs.SetActiveView(None) pvs.Disconnect()
def render_frames( scene, frames_dir=None, frame_window=None, render_missing_frames=False, save_state_to_file=None, no_render=False, show_preview=False, show_progress=False, job_id=None, ): # Validate scene if scene["View"]["ViewSize"][0] % 16 != 0: logger.warning( "The view width should be a multiple of 16 to be compatible with" " QuickTime.") if scene["View"]["ViewSize"][1] % 2 != 0: logger.warning( "The view height should be even to be compatible with QuickTime.") render_start_time = time.time() # Setup layout layout = pv.CreateLayout("Layout") # Setup view if "Background" in scene["View"]: bg_config = scene["View"]["Background"] del scene["View"]["Background"] if isinstance(bg_config, list): if isinstance(bg_config[0], list): assert len(bg_config) == 2, ( "When 'Background' is a list of colors, it must have 2" " entries.") bg_config = dict( BackgroundColorMode="Gradient", Background=parse_as.color(bg_config[0]), Background2=parse_as.color(bg_config[1]), ) else: bg_config = dict( BackgroundColorMode="Single Color", Background=parse_as.color(bg_config), ) bg_config["UseColorPaletteForBackground"] = 0 scene["View"].update(bg_config) bg_config = None else: bg_config = None view = pv.CreateRenderView(**scene["View"]) pv.AssignViewToLayout(view=view, layout=layout, hint=0) # Set spherical background texture if bg_config is not None: bg_config["BackgroundColorMode"] = "Texture" skybox_datasource = bg_config["Datasource"] del bg_config["Datasource"] background_texture = pvserver.rendering.ImageTexture( FileName=parse_as.path(scene["Datasources"][skybox_datasource])) background_sphere = pv.Sphere(Radius=bg_config["Radius"], ThetaResolution=100, PhiResolution=100) background_texture_map = pv.TextureMaptoSphere(Input=background_sphere) pv.Show( background_texture_map, view, Texture=background_texture, BackfaceRepresentation="Cull Frontface", Ambient=1.0, ) # Load the waveform data file waveform_h5file, waveform_subfile = parse_as.file_and_subfile( scene["Datasources"]["Waveform"]) waveform_data = WaveformDataReader(FileName=waveform_h5file, Subfile=waveform_subfile) pv.UpdatePipeline() # Generate volume data from the waveform. Also sets the available time range. # TODO: Pull KeepEveryNthTimestep out of datasource waveform_to_volume_configs = scene["WaveformToVolume"] if isinstance(waveform_to_volume_configs, dict): waveform_to_volume_configs = [{ "Object": waveform_to_volume_configs, }] if "VolumeRepresentation" in scene: waveform_to_volume_configs[0]["VolumeRepresentation"] = scene[ "VolumeRepresentation"] waveform_to_volume_objects = [] for waveform_to_volume_config in waveform_to_volume_configs: volume_data = WaveformToVolume( WaveformData=waveform_data, SwshCacheDirectory=parse_as.path( scene["Datasources"]["SwshCache"]), **waveform_to_volume_config["Object"], ) if "Modes" in waveform_to_volume_config["Object"]: volume_data.Modes = waveform_to_volume_config["Object"]["Modes"] if "Polarizations" in waveform_to_volume_config["Object"]: volume_data.Polarizations = waveform_to_volume_config["Object"][ "Polarizations"] waveform_to_volume_objects.append(volume_data) # Compute timing and frames information time_range_in_M = ( volume_data.TimestepValues[0], volume_data.TimestepValues[-1], ) logger.debug(f"Full available data time range: {time_range_in_M} (in M)") if "FreezeTime" in scene["Animation"]: frozen_time = scene["Animation"]["FreezeTime"] logger.info(f"Freezing time at {frozen_time}.") view.ViewTime = frozen_time animation = None else: if "Crop" in scene["Animation"]: time_range_in_M = scene["Animation"]["Crop"] logger.debug(f"Cropping time range to {time_range_in_M} (in M).") animation_speed = scene["Animation"]["Speed"] frame_rate = scene["Animation"]["FrameRate"] num_frames = animate.num_frames( max_animation_length=time_range_in_M[1] - time_range_in_M[0], animation_speed=animation_speed, frame_rate=frame_rate, ) animation_length_in_seconds = num_frames / frame_rate animation_length_in_M = animation_length_in_seconds * animation_speed time_per_frame_in_M = animation_length_in_M / num_frames logger.info(f"Rendering {animation_length_in_seconds:.2f}s movie with" f" {num_frames} frames ({frame_rate} FPS or" f" {animation_speed:.2e} M/s or" f" {time_per_frame_in_M:.2e} M/frame)...") if frame_window is not None: animation_window_num_frames = frame_window[1] - frame_window[0] animation_window_time_range = ( time_range_in_M[0] + frame_window[0] * time_per_frame_in_M, time_range_in_M[0] + (frame_window[1] - 1) * time_per_frame_in_M, ) logger.info( f"Restricting rendering to {animation_window_num_frames} frames" f" (numbers {frame_window[0]} to {frame_window[1] - 1}).") else: animation_window_num_frames = num_frames animation_window_time_range = time_range_in_M frame_window = (0, num_frames) # Setup animation so that sources can retrieve the `UPDATE_TIME_STEP` animation = pv.GetAnimationScene() # animation.UpdateAnimationUsingDataTimeSteps() # Since the data can be evaluated at arbitrary times we define the time steps # here by setting the number of frames within the full range animation.PlayMode = "Sequence" animation.StartTime = animation_window_time_range[0] animation.EndTime = animation_window_time_range[1] animation.NumberOfFrames = animation_window_num_frames logger.debug( f"Animating from scene time {animation.StartTime} to" f" {animation.EndTime} in {animation.NumberOfFrames} frames.") def scene_time_from_real(real_time): return (real_time / animation_length_in_seconds * animation_length_in_M) # For some reason the keyframe time for animations is expected to be within # (0, 1) so we need to transform back and forth from this "normalized" time def scene_time_from_normalized(normalized_time): return animation.StartTime + normalized_time * ( animation.EndTime - animation.StartTime) def normalized_time_from_scene(scene_time): return (scene_time - animation.StartTime) / (animation.EndTime - animation.StartTime) # Setup progress measuring already here so volume data computing for # initial frame is measured if show_progress and not no_render: logging.getLogger().handlers = [TqdmLoggingHandler()] animation_window_frame_range = tqdm.trange( animation_window_num_frames, desc="Rendering", unit="frame", miniters=1, position=job_id, ) else: animation_window_frame_range = range(animation_window_num_frames) # Set the initial time step animation.GoToFirst() # Display the volume data. This will trigger computing the volume data at the # current time step. for volume_data, waveform_to_volume_config in zip( waveform_to_volume_objects, waveform_to_volume_configs): vol_repr = (waveform_to_volume_config["VolumeRepresentation"] if "VolumeRepresentation" in waveform_to_volume_config else {}) volume_color_by = config_color.extract_color_by(vol_repr) if (vol_repr["VolumeRenderingMode"] == "GPU Based" and len(volume_color_by) > 2): logger.warning( "The 'GPU Based' volume renderer doesn't support multiple" " components.") volume = pv.Show(volume_data, view, **vol_repr) pv.ColorBy(volume, value=volume_color_by) if "Slices" in scene: for slice_config in scene["Slices"]: slice_obj_config = slice_config.get("Object", {}) slice = pv.Slice(Input=volume_data) slice.SliceType = "Plane" slice.SliceOffsetValues = [0.0] slice.SliceType.Origin = slice_obj_config.get( "Origin", [0.0, 0.0, -0.3]) slice.SliceType.Normal = slice_obj_config.get( "Normal", [0.0, 0.0, 1.0]) slice_rep = pv.Show(slice, view, **slice_config.get("Representation", {})) pv.ColorBy(slice_rep, value=volume_color_by) # Display the time if "TimeAnnotation" in scene: time_annotation = pv.AnnotateTimeFilter(volume_data, **scene["TimeAnnotation"]) pv.Show(time_annotation, view, **scene["TimeAnnotationRepresentation"]) # Add spheres if "Spheres" in scene: for sphere_config in scene["Spheres"]: sphere = pv.Sphere(**sphere_config["Object"]) pv.Show(sphere, view, **sphere_config["Representation"]) # Add trajectories and objects that follow them if "Trajectories" in scene: for trajectory_config in scene["Trajectories"]: trajectory_name = trajectory_config["Name"] radial_scale = (trajectory_config["RadialScale"] if "RadialScale" in trajectory_config else 1.0) # Load the trajectory data traj_data_reader = TrajectoryDataReader( RadialScale=radial_scale, **scene["Datasources"]["Trajectories"][trajectory_name], ) # Make sure the data is loaded so we can retrieve timesteps. # TODO: This should be fixed in `TrajectoryDataReader` by # communicating time range info down the pipeline, but we had issues # with that (see also `WaveformDataReader`). traj_data_reader.UpdatePipeline() if "Objects" in trajectory_config: with animate.restore_animation_state(animation): follow_traj = FollowTrajectory( TrajectoryData=traj_data_reader) for traj_obj_config in trajectory_config["Objects"]: for traj_obj_key in traj_obj_config: if traj_obj_key in [ "Representation", "Visibility", "TimeShift", "Glyph", ]: continue traj_obj_type = getattr(pv, traj_obj_key) traj_obj_glyph = traj_obj_type( **traj_obj_config[traj_obj_key]) follow_traj.UpdatePipeline() traj_obj = pv.Glyph(Input=follow_traj, GlyphType=traj_obj_glyph) # Can't set this in the constructor for some reason traj_obj.ScaleFactor = 1.0 for glyph_property in (traj_obj_config["Glyph"] if "Glyph" in traj_obj_config else []): setattr( traj_obj, glyph_property, traj_obj_config["Glyph"][glyph_property], ) traj_obj.UpdatePipeline() if "TimeShift" in traj_obj_config: traj_obj = animate.apply_time_shift( traj_obj, traj_obj_config["TimeShift"]) pv.Show(traj_obj, view, **traj_obj_config["Representation"]) if "Visibility" in traj_obj_config: animate.apply_visibility( traj_obj, traj_obj_config["Visibility"], normalized_time_from_scene, scene_time_from_real, ) if "Tail" in trajectory_config: with animate.restore_animation_state(animation): traj_tail = TrajectoryTail(TrajectoryData=traj_data_reader) if "TimeShift" in trajectory_config: traj_tail = animate.apply_time_shift( traj_tail, trajectory_config["TimeShift"]) tail_config = trajectory_config["Tail"] traj_color_by = config_color.extract_color_by(tail_config) if "Visibility" in tail_config: tail_visibility_config = tail_config["Visibility"] del tail_config["Visibility"] else: tail_visibility_config = None tail_rep = pv.Show(traj_tail, view, **tail_config) pv.ColorBy(tail_rep, value=traj_color_by) if tail_visibility_config is not None: animate.apply_visibility( traj_tail, tail_visibility_config, normalized_time_from_scene=normalized_time_from_scene, scene_time_from_real=scene_time_from_real, ) if "Move" in trajectory_config: move_config = trajectory_config["Move"] logger.debug( f"Animating '{move_config['guiName']}' along trajectory.") with h5py.File(trajectory_file, "r") as traj_data_file: trajectory_data = np.array( traj_data_file[trajectory_subfile]) if radial_scale != 1.0: trajectory_data[:, 1:] *= radial_scale logger.debug(f"Trajectory data shape: {trajectory_data.shape}") animate.follow_path( gui_name=move_config["guiName"], trajectory_data=trajectory_data, num_keyframes=move_config["NumKeyframes"], scene_time_range=time_range_in_M, normalized_time_from_scene=normalized_time_from_scene, ) # Add non-spherical horizon shapes (instead of spherical objects following # trajectories) if "Horizons" in scene: for horizon_config in scene["Horizons"]: with animate.restore_animation_state(animation): horizon = pv.PVDReader(FileName=scene["Datasources"] ["Horizons"][horizon_config["Name"]]) if horizon_config.get("InterpolateTime", False): horizon = pv.TemporalInterpolator( Input=horizon, DiscreteTimeStepInterval=0) if "TimeShift" in horizon_config: horizon = animate.apply_time_shift(horizon, horizon_config["TimeShift"], animation) # Try to make horizon surfaces smooth. At low angular resoluton # they still show artifacts, so perhaps more can be done. horizon = pv.ExtractSurface(Input=horizon) horizon = pv.GenerateSurfaceNormals(Input=horizon) horizon_rep_config = horizon_config.get("Representation", {}) if "Representation" not in horizon_rep_config: horizon_rep_config["Representation"] = "Surface" if "AmbientColor" not in horizon_rep_config: horizon_rep_config["AmbientColor"] = [0.0, 0.0, 0.0] if "DiffuseColor" not in horizon_rep_config: horizon_rep_config["DiffuseColor"] = [0.0, 0.0, 0.0] if "Specular" not in horizon_rep_config: horizon_rep_config["Specular"] = 0.2 if "SpecularPower" not in horizon_rep_config: horizon_rep_config["SpecularPower"] = 10 if "SpecularColor" not in horizon_rep_config: horizon_rep_config["SpecularColor"] = [1.0, 1.0, 1.0] if "ColorBy" in horizon_rep_config: horizon_color_by = config_color.extract_color_by( horizon_rep_config) else: horizon_color_by = None horizon_rep = pv.Show(horizon, view, **horizon_rep_config) if horizon_color_by is not None: pv.ColorBy(horizon_rep, value=horizon_color_by) # Animate visibility if "Visibility" in horizon_config: animate.apply_visibility( horizon, horizon_config["Visibility"], normalized_time_from_scene=normalized_time_from_scene, scene_time_from_real=scene_time_from_real, ) if "Contours" in horizon_config: for contour_config in horizon_config["Contours"]: contour = pv.Contour(Input=horizon, **contour_config["Object"]) contour_rep = pv.Show(contour, view, **contour_config["Representation"]) pv.ColorBy(contour_rep, None) if "Visibility" in horizon_config: animate.apply_visibility( contour, horizon_config["Visibility"], normalized_time_from_scene= normalized_time_from_scene, scene_time_from_real=scene_time_from_real, ) # Configure transfer functions if "TransferFunctions" in scene: for tf_config in scene["TransferFunctions"]: colored_field = tf_config["Field"] transfer_fctn = pv.GetColorTransferFunction(colored_field) opacity_fctn = pv.GetOpacityTransferFunction(colored_field) tf.configure_transfer_function(transfer_fctn, opacity_fctn, tf_config["TransferFunction"]) # Save state file before configuring camera keyframes. # TODO: Make camera keyframes work with statefile if save_state_to_file is not None: pv.SaveState(save_state_to_file + ".pvsm") # Camera shots # TODO: Make this work with freezing time while the camera is swinging if animation is None: for i, shot in enumerate(scene["CameraShots"]): if (i == len(scene["CameraShots"]) - 1 or (shot["Time"] if "Time" in shot else 0.0) >= view.ViewTime): camera_motion.apply(shot) break else: camera_motion.apply_swings( scene["CameraShots"], scene_time_range=time_range_in_M, scene_time_from_real=scene_time_from_real, normalized_time_from_scene=normalized_time_from_scene, ) # Report time if animation is not None: report_time_cue = pv.PythonAnimationCue() report_time_cue.Script = """ def start_cue(self): pass def tick(self): import paraview.simple as pv import logging logger = logging.getLogger('Animation') scene_time = pv.GetActiveView().ViewTime logger.info(f"Scene time: {scene_time}") def end_cue(self): pass """ animation.Cues.append(report_time_cue) if show_preview and animation is not None: animation.PlayMode = "Real Time" animation.Duration = 10 animation.Play() animation.PlayMode = "Sequence" if no_render: logger.info("No rendering requested. Total time:" f" {time.time() - render_start_time:.2f}s") return if frames_dir is None: raise RuntimeError("Trying to render but `frames_dir` is not set.") if os.path.exists(frames_dir): logger.warning( f"Output directory '{frames_dir}' exists, files may be overwritten." ) else: os.makedirs(frames_dir) if animation is None: pv.Render() pv.SaveScreenshot(os.path.join(frames_dir, "frame.png")) else: # Iterate over frames manually to support filling in missing frames. # If `pv.SaveAnimation` would support that, here's how it could be # invoked: # pv.SaveAnimation( # os.path.join(frames_dir, 'frame.png'), # view, # animation, # FrameWindow=frame_window, # SuffixFormat='.%06d') # Note that `FrameWindow` appears to be buggy, so we set up the # `animation` according to the `frame_window` above so the frame files # are numberd correctly. for animation_window_frame_i in animation_window_frame_range: frame_i = frame_window[0] + animation_window_frame_i frame_file = os.path.join(frames_dir, f"frame.{frame_i:06d}.png") if render_missing_frames and os.path.exists(frame_file): continue logger.debug(f"Rendering frame {frame_i}...") animation.AnimationTime = ( animation.StartTime + time_per_frame_in_M * animation_window_frame_i) pv.Render() pv.SaveScreenshot(frame_file) logger.info(f"Rendered frame {frame_i}.") logger.info( f"Rendering done. Total time: {time.time() - render_start_time:.2f}s")
print(" The max exact solution is =",max_sol_exacte ) print("The max numerical solution is =",my_ResultField.getNormEuclidean().max()) assert erreur_max/max_sol_exacte <1. #Postprocessing : #================ # Save 3D picture PV_routines.Save_PV_data_to_picture_file("FiniteElementsOnTorus"+'_0.vtu',"Numerical result field",'NODES',"FiniteElementsOnTorus") resolution=100 VTK_routines.Clip_VTK_data_to_VTK("FiniteElementsOnTorus"+'_0.vtu',"Clip_VTK_data_to_VTK_"+ "FiniteElementsOnTorus"+'_0.vtu',[0.25,0.25,0.25], [-0.5,-0.5,-0.5],resolution ) PV_routines.Save_PV_data_to_picture_file("Clip_VTK_data_to_VTK_"+"FiniteElementsOnTorus"+'_0.vtu',"Numerical result field",'NODES',"Clip_VTK_data_to_VTK_"+"FiniteElementsOnTorus") # Plot over slice circle finiteElementsOnTorus_0vtu = pvs.XMLUnstructuredGridReader(FileName=["FiniteElementsOnTorus"+'_0.vtu']) slice1 = pvs.Slice(Input=finiteElementsOnTorus_0vtu) slice1.SliceType.Normal = [0.5, 0.5, 0.5] renderView1 = pvs.GetActiveViewOrCreate('RenderView') finiteElementsOnTorus_0vtuDisplay = pvs.Show(finiteElementsOnTorus_0vtu, renderView1) pvs.ColorBy(finiteElementsOnTorus_0vtuDisplay, ('POINTS', 'Numerical result field')) slice1Display = pvs.Show(slice1, renderView1) pvs.SaveScreenshot("./FiniteElementsOnTorus"+"_Slice"+'.png', magnification=1, quality=100, view=renderView1) plotOnSortedLines1 = pvs.PlotOnSortedLines(Input=slice1) lineChartView2 = pvs.CreateView('XYChartView') plotOnSortedLines1Display = pvs.Show(plotOnSortedLines1, lineChartView2) plotOnSortedLines1Display.UseIndexForXAxis = 0 plotOnSortedLines1Display.XArrayName = 'arc_length' plotOnSortedLines1Display.SeriesVisibility = ['Numerical result field (1)'] pvs.SaveScreenshot("./FiniteElementsOnTorus"+"_PlotOnSortedLine_"+'.png', magnification=1, quality=100, view=lineChartView2) pvs.Delete(lineChartView2)
class Pipeline: # Define source of pipeline grid = coprocessor.CreateProducer(datadescription, "input") if (write_full_output == True): fullWriter = pvs.XMLPUnstructuredGridWriter( Input=grid, DataMode="Appended", CompressorType="ZLib") coprocessor.RegisterWriter(fullWriter, filename='full_output_%t.pvtu', freq=1) # Horizontal slice at the bottom slice = pvs.Slice(Input=grid) slice.SliceType = 'Plane' slice.SliceOffsetValues = [0.0] slice.SliceType.Origin = [0.0, 0.0, 101.94] slice.SliceType.Normal = [0.0, 0.0, 1.0] slice.Triangulatetheslice = False # Set up spherical projection filter - we need to bridge into the # VTK universe and use a VTK transform filter; the ParaView transform filter # does not support geo transforms # Source projection - simulation data is provided in lon lat rad coordinates latlonproj = vtk.vtkGeoProjection() latlonproj.SetName('lonlat') latlonproj.SetCentralMeridian(0) # Target projection - use Mollweide here targetproj = vtk.vtkGeoProjection() targetproj.SetName('moll') targetproj.SetCentralMeridian(0) # Set up vtkGeoTransform object that defines the transformation transform = vtk.vtkGeoTransform() transform.SetSourceProjection(latlonproj) transform.SetDestinationProjection(targetproj) # Set up VTK transform filter object tffilter = vtk.vtkTransformFilter() tffilter.SetTransform(transform) tffilter.SetInputConnection( slice.GetClientSideObject().GetOutputPort(0)) # Return to ParaView universe by using a simple PassThrough filter to receive # output of the VTK transform filter passthrough = pvs.PassThrough() passthrough.GetClientSideObject().SetInputConnection( tffilter.GetOutputPort()) # Create a new render view renderView = pvs.CreateView('RenderView') renderView.ViewSize = [1500, 768] renderView.AxesGrid = 'GridAxes3DActor' renderView.StereoType = 0 renderView.CameraPosition = [0, 0, 4] renderView.CameraParallelScale = 1.7 renderView.Background = [0.32, 0.34, 0.43] renderView.ViewTime = datadescription.GetTime() # Register the view with coprocessor # and provide it with information such as the filename to use, # how frequently to write the images, etc. coprocessor.RegisterView(renderView, filename='spherical_slice_%t.png', freq=1, fittoscreen=1, magnification=1, width=1500, height=768, cinema={}) # Create colour transfer function for field LUT = pvs.GetColorTransferFunction(fieldname) LUT.RGBPoints = [ dataRange[0], 0.23, 0.30, 0.75, 0.5 * sum(dataRange), 0.87, 0.87, 0.87, dataRange[1], 0.71, 0.016, 0.15 ] LUT.ScalarRangeInitialized = 1.0 # Show surface and colour by field value (which is cell data) using lookup table sphereDisplay = pvs.Show(passthrough, renderView) sphereDisplay.Representation = 'Surface' sphereDisplay.ColorArrayName = ['CELLS', fieldname] sphereDisplay.LookupTable = LUT
def manySlicesAlongAxis(dataNm, rng, axis=0, exportpath='', ext='.csv'): """ Description ----------- Parameters ---------- `dataNm` : string - The string name of the data source to slice. - Make sure this data source is slice-able. `numSlices` : int, optional - The number of slices along the path. `exportpath` : string, optional - The absolute file path of where to save each slice `ext` : string, optional - The file extension for saving out the slices. - Default to '.csv' Notes ----- - Make sure the input data source is slice-able. - The SciPy module is required for this macro. """ # exportpath: Where to save data. Absolute path: if axis not in (0, 1, 2): raise Exception('Axis choice must be 0, 1, or 2 (x, y, or z)') # Specify data set to be sliced data = pvs.FindSource(dataNm) # get active view renderView = pvs.GetActiveViewOrCreate('RenderView') def getNorm(): norm = [0, 0, 0] norm[axis] = 1 return norm def updateOrigin(og, i): og[axis] = rng[i] return og norm = getNorm() num = 0 inputs = [] for i in range(len(rng)): # create slice slc = pvs.Slice(Input=data) slc.SliceType = 'Plane' # set origin at points og = slc.SliceType.Origin og = updateOrigin(og, i) # set normal as vector from current point to next point slc.SliceType.Normal = norm if exportpath != '': # save out slice with good metadata: TODO: change name # This will use a value from the point data to add to the name #num = wpdi.PointData['Advance LL (S-558)'][ptsi[i]] filename = path + 'Slice_%d%s' % (num, ext) print(filename) pvs.SaveData(filename, proxy=slc) num += 1 inputs.append(slc) #pvs.Show(slc, renderView) # Now append all slices into once source for easy management app = pvs.AppendDatasets(Input=inputs) pvs.RenameSource('%s-Slices' % dataNm, app) pvs.Show(app, renderView) pvs.RenderAllViews() pvs.ResetCamera() return app