|
[Sponsors] |
[General] pvbatch script for saving animations modifing each frame |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
October 29, 2013, 13:18 |
pvbatch script for saving animations modifing each frame
|
#1 |
New Member
Gaetano
Join Date: Jul 2012
Posts: 18
Rep Power: 14 |
Hi all.
I'd like to have your inputs on a problem that is puzzling me from days. I want to save an animation starting from a series of vtk. Apart from the rendering of a point field, I need a line source to be superimposed. The coordinates of the two points defining the line have to be read from a text file (two points for each vtk). I managed to create an image sequence, that is to export each single frame of my animation. Now I'd like to have only an .ogv as output of my python script. I tried something like the script here, but I wasn't successful: ----------------------------------------------------------- ERROR: In /root/ParaView-v4.0.1-source/ParaViewCore/ClientServerCore/Rendering/vtkPVCameraCueManipulator.cxx, line 94 vtkPVCameraCueManipulator (0x1ed8d550): No camera to animate. ./video3.sh: line 5: 25353 Segmentation fault /share/paraview-4.0.1-MESA/bin/pvbatch --use-offscreen-rendering screen3.py ----------------------------------------------------------- Of course the error comes from the fact that I'm not animating the camera. Another hint is here, where the suggestion is to put the rendering instructions into a "Python script to be called on every timestep" using the "Python Animation Cue". Nonetheless I couldn't find any reference/example on internet. Any suggestion? PS: the rendering instructions are those I could register using the GUI tracing tool PPS: I'm using Paraview 4.0.1 with MESA support on a Linux machine |
|
October 30, 2013, 06:31 |
Minimal script
|
#2 |
New Member
Gaetano
Join Date: Jul 2012
Posts: 18
Rep Power: 14 |
Just to give some more background, here's a minimal version of my script:
Code:
import math try: paraview.simple except: from paraview.simple import * paraview.simple._DisableFirstRenderCameraReset() # number of frames frames = 121 # time difference between steps (needed for reconstruct filenames) step = 0.05 # List containing the x and y coordinates of the two points pos = [[] for i in range(frames)] i=0 # Filename containing the coordinates in the following format: # time x_top y_top x_bottom y_bottom # 0.12 0.123456 0.123456 0.123456 0.123456 # ... in_file = open("/home/project/simulation/points.out","r") # Loop through lines in file for line in in_file: [time,xt,yt,xb,yb] = line.rsplit(' ',5) # Store the coordinate in a 2D list pos[i] = [float(xt), float(yt), float(xb), float(yb)] i = i+1 in_file.close() for i in range(frames): # Read file file = "/home/project/simulation/VTK/sim_" + str(int(i*step*1000)) + ".vtk" reader = LegacyVTKReader( FileNames=file ) RenderView1 = GetRenderView() Slice1 = Slice( SliceType="Plane" ) Slice1.SliceOffsetValues = [0.0] Slice1.SliceType = "Plane" Slice1.SliceType.Origin = [0.0, 0.0, 0.0] Slice1.SliceType.Normal = [0.0, 0.0, 1.0] DataRepresentation1 = Show() DataRepresentation1.ScaleFactor = 0.05 DataRepresentation1.SelectionPointFieldDataArrayName = 'U' DataRepresentation1.EdgeColor = [0.0, 0.0, 0.5] a1_U_PVLookupTable = GetLookupTableForArray( "U", 3, RGBPoints=[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], VectorMode='Magnitude', NanColor=[0.5, 0.5, 0.5], ColorSpace='HSV', ScalarRangeInitialized=1.0, LockScalarRange=1 ) a1_U_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] ) DataRepresentation1.ColorArrayName = 'U' DataRepresentation1.LookupTable = a1_U_PVLookupTable Line1 = Line() Line1.Point1 = [ pos[i][0], pos[i][1], 0.0] Line1.Point2 = [ pos[i][2], pos[i][3], 0.0] DataRepresentation2 = Show() DataRepresentation2.ScaleFactor = 0.02 DataRepresentation2.SelectionPointFieldDataArrayName = 'Texture Coordinates' DataRepresentation2.EdgeColor = [0.0, 0.0, 0.5] DataRepresentation2.LineWidth = 3.0 RenderView1.ResetCamera() RenderView1.CenterAxesVisibility = 0 RenderView1.OrientationAxesVisibility = 1 RenderView1.ViewSize = [ 2400, 2400 ] ScalarBarWidgetRepresentation1 = CreateScalarBar( ComponentTitle='', Title='U', Enabled=1, LabelFontSize=12, LookupTable=a1_U_PVLookupTable, TitleFontSize=12, Position=[0.9, 0.25] ) GetRenderView().Representations.append(ScalarBarWidgetRepresentation1) WriteImage('/home/project/frames/video' + str(int(i*step*1000)) + '.png') # Memory saving? Delete(reader) Delete(Slice1) Delete(Threshold1) Delete(Contour1) Delete(Line1) Is there a way to save an .ogv starting from those frames? Any comments on the script are extremely welcome! |
|
November 2, 2013, 17:09 |
|
#3 | |
Retired Super Moderator
Bruno Santos
Join Date: Mar 2009
Location: Lisbon, Portugal
Posts: 10,982
Blog Entries: 45
Rep Power: 128 |
Greetings Gaetano,
Wow, that's some heavy duty coding you want to perform! And for pvbatch, to top it off! Personally, I prefer to use GUI first for testing. And ParaView has got a marvellous feature in the "Tools" menu, namely "Start/Stop Trace". This allows us to register most of the commands we executed graphically and when we stop tracing, we get a script which most of the times gives a good code to start with. Problem is when it doesn't give us all of the code we need But in this case, I did a quick test, and the following pearls of wisdom it gave me were (with ParaView 3.12.0):
As for saving to OGV... on ParaView 4.0.1 I got this from the Python trace feature: Quote:
Bruno
__________________
|
||
November 4, 2013, 13:08 |
|
#4 | |||
New Member
Gaetano
Join Date: Jul 2012
Posts: 18
Rep Power: 14 |
Quote:
Quote:
Quote:
For future reference (and my 2 cents for the community), here's how I did it: Code:
try: paraview.simple except: from paraview.simple import * paraview.simple._DisableFirstRenderCameraReset() # number of frames frames = 121 # time difference between steps (needed for reconstruct filenames) step = 0.05 AnimationScene1 = GetAnimationScene() AnimationScene1.EndTime = frames-1 AnimationScene1.PlayMode = 'Snap To TimeSteps' RenderView1 = GetRenderView() # List containing the x and y coordinates of the two points pos = [[] for i in range(frames)] # Filename containing the coordinates in the following format: # time x_top y_top x_bottom y_bottom # 0.12 0.123456 0.123456 0.123456 0.123456 # ... in_file = open("/home/project/simulation/points.out","r") # Loop through lines in file i=0 for line in in_file: [time,xt,yt,xb,yb] = line.rsplit(' ',5) # Store the coordinate in a 2D list pos[i] = [float(xt), float(yt), float(xb), float(yb)] i = i+1 in_file.close() for i in range(frames): # Read file file = "/home/project/simulation/VTK/sim_" + str(int(i*step*1000)) + ".vtk" files.append(file) reader = LegacyVTKReader( FileNames=files ) Slice1 = Slice( SliceType="Plane" ) Slice1.SliceOffsetValues = [0.0] Slice1.SliceType = "Plane" Slice1.SliceType.Origin = [0.0, 0.0, 0.0] Slice1.SliceType.Normal = [0.0, 0.0, 1.0] DataRepresentation1 = Show() DataRepresentation1.ScaleFactor = 0.05 DataRepresentation1.SelectionPointFieldDataArrayName = 'U' DataRepresentation1.EdgeColor = [0.0, 0.0, 0.5] a1_U_PVLookupTable = GetLookupTableForArray( "U", 3, RGBPoints=[0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0], VectorMode='Magnitude', NanColor=[0.5, 0.5, 0.5], ColorSpace='HSV', ScalarRangeInitialized=1.0, LockScalarRange=1 ) a1_U_PiecewiseFunction = CreatePiecewiseFunction( Points=[0.0, 0.0, 0.5, 0.0, 1.0, 1.0, 0.5, 0.0] ) DataRepresentation1.ColorArrayName = 'U' DataRepresentation1.LookupTable = a1_U_PVLookupTable Line1 = Line() RenderView1.ResetCamera() ScalarBarWidgetRepresentation1 = CreateScalarBar( ComponentTitle='', Title='U', Enabled=1, LabelFontSize=12, LookupTable=a1_U_PVLookupTable, TitleFontSize=12, Position=[0.9, 0.25] ) GetRenderView().Representations.append(ScalarBarWidgetRepresentation1) PythonAnimationCue1 = PythonAnimationCue() PythonAnimationCue1.Script= """ def start_cue(self): pass def tick(self): i = int(GetAnimationScene().TimeKeeper.Time) RenderView1.ViewTime = i AnimationScene1.AnimationTime = i Line1 = FindSource("Line1") Line1.UpdatePipeline(GetAnimationScene().TimeKeeper.Time) Line1.Point1 = [ pos[i][0], pos[i][1], 0.0] Line1.Point2 = [ pos[i][2], pos[i][3], 0.0] DataRepresentation2 = Show() DataRepresentation2.ScaleFactor = 0.02 DataRepresentation2.SelectionPointFieldDataArrayName = 'Texture Coordinates' DataRepresentation2.EdgeColor = [0.0, 0.0, 0.5] DataRepresentation2.LineWidth = 3.0 def end_cue(self): pass """ AnimationScene1.Cues.append(PythonAnimationCue1) RenderView1.CenterAxesVisibility = 0 RenderView1.OrientationAxesVisibility = 1 RenderView1.ViewSize = [ 2400, 2400 ] WriteAnimation('/home/project/frames/video.ogv', Magnification=1, Quality=2, FrameRate=8.0) Regards, Gaetano |
||||
January 30, 2014, 06:42 |
|
#5 |
New Member
Gaetano
Join Date: Jul 2012
Posts: 18
Rep Power: 14 |
Errata corrige: my script seems to put the line at the previous instant into the current instant photogram. There is still something wrong, so be careful if you're going to use it.
Regards, Gaetano |
|
Tags |
animation, frame, pvbatch, python |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Coordinate Frame Motion | yangxu | CFX | 6 | January 25, 2022 09:51 |
Split connectors at their intersection | FOUAD12 | Pointwise & Gridgen | 3 | October 8, 2018 11:42 |
TUI Command for Cell Zone Condition? | artkingjw | FLUENT | 2 | February 25, 2018 08:38 |
Moving reference frame for turbine simulation | Rahl141 | STAR-CCM+ | 2 | December 28, 2017 07:25 |
Convert DFT of pressure in rotating frame to stationary frame | CFD-123 | FLUENT | 0 | February 12, 2015 18:51 |