-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvelocity_video_2.py
161 lines (124 loc) · 5.65 KB
/
velocity_video_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# trace generated using paraview version 5.10.0
#import paraview
#paraview.compatibility.major = 5
#paraview.compatibility.minor = 10
#### import the simple module from the paraview
from paraview.simple import *
from pathlib import Path
import os
import re
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()
directory_folder = "Folder_Output"
parent_dir_folder = os.getcwd()
path_folder = os.path.join(parent_dir_folder, directory_folder)
Files = Path(path_folder)
# Iterate directory
res=[]
a=0.0
for f in Files.iterdir():
for file in Files.iterdir():
if re.match("Output_3_\d+\.vtk", file.name):
Output, degree, number=file.stem.split('_')
if(a == float(number)):
res.append(str(file))
a+=1
# create a new 'Legacy VTK Reader'
output_3_ = LegacyVTKReader(registrationName='Output_3_*', FileNames= res)
# get animation scene
animationScene1 = GetAnimationScene()
# update animation scene based on data timesteps
animationScene1.UpdateAnimationUsingDataTimeSteps()
# get active view
renderView1 = GetActiveViewOrCreate('RenderView')
# show data in view
output_3_Display = Show(output_3_, renderView1, 'UnstructuredGridRepresentation')
# get color transfer function/color map for 'cell_desnity'
cell_desnityLUT = GetColorTransferFunction('cell_desnity')
# get opacity transfer function/opacity map for 'cell_desnity'
cell_desnityPWF = GetOpacityTransferFunction('cell_desnity')
# trace defaults for the display properties.
output_3_Display.Representation = 'Surface'
output_3_Display.ColorArrayName = ['POINTS', 'cell_desnity']
output_3_Display.LookupTable = cell_desnityLUT
output_3_Display.SelectTCoordArray = 'None'
output_3_Display.SelectNormalArray = 'None'
output_3_Display.SelectTangentArray = 'None'
output_3_Display.OSPRayScaleArray = 'cell_desnity'
output_3_Display.OSPRayScaleFunction = 'PiecewiseFunction'
output_3_Display.SelectOrientationVectors = 'displacement'
output_3_Display.ScaleFactor = 0.20035666100000002
output_3_Display.SelectScaleArray = 'cell_desnity'
output_3_Display.GlyphType = 'Arrow'
output_3_Display.GlyphTableIndexArray = 'cell_desnity'
output_3_Display.GaussianRadius = 0.010017833050000001
output_3_Display.SetScaleArray = ['POINTS', 'cell_desnity']
output_3_Display.ScaleTransferFunction = 'PiecewiseFunction'
output_3_Display.OpacityArray = ['POINTS', 'cell_desnity']
output_3_Display.OpacityTransferFunction = 'PiecewiseFunction'
output_3_Display.DataAxesGrid = 'GridAxesRepresentation'
output_3_Display.PolarAxes = 'PolarAxesRepresentation'
output_3_Display.ScalarOpacityFunction = cell_desnityPWF
output_3_Display.ScalarOpacityUnitDistance = 0.3538057902458452
output_3_Display.OpacityArrayName = ['POINTS', 'cell_desnity']
# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
output_3_Display.ScaleTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.1757813367477812e-38, 1.0, 0.5, 0.0]
# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
output_3_Display.OpacityTransferFunction.Points = [0.0, 0.0, 0.5, 0.0, 1.1757813367477812e-38, 1.0, 0.5, 0.0]
# reset view to fit data
renderView1.ResetCamera(False)
#changing interaction mode based on data extents
renderView1.CameraPosition = [-1.000356661, 0.998216695, 10000.0]
# show color bar/color legend
output_3_Display.SetScalarBarVisibility(renderView1, True)
# update the view to ensure updated data information
renderView1.Update()
# set scalar coloring
ColorBy(output_3_Display, ('POINTS', 'velocity', 'Magnitude'))
# Hide the scalar bar for this color map if no visible data is colored by it.
HideScalarBarIfNotNeeded(cell_desnityLUT, renderView1)
# rescale color and/or opacity maps used to include current data range
output_3_Display.RescaleTransferFunctionToDataRange(True, False)
# show color bar/color legend
output_3_Display.SetScalarBarVisibility(renderView1, True)
# get color transfer function/color map for 'velocity'
velocityLUT = GetColorTransferFunction('velocity')
# get opacity transfer function/opacity map for 'velocity'
velocityPWF = GetOpacityTransferFunction('velocity')
# Rescale transfer function
velocityLUT.RescaleTransferFunction(0.0, 6.0)
# Rescale transfer function
velocityPWF.RescaleTransferFunction(0.0, 6.0)
# get layout
layout1 = GetLayout()
# layout/tab size in pixels
layout1.SetSize(2000, 1354)
# current camera placement for renderView1
renderView1.InteractionMode = '2D'
renderView1.CameraPosition = [-1.000356661, 0.998216695, 10000.0]
renderView1.CameraFocalPoint = [-1.000356661, 0.998216695, 0.0]
renderView1.CameraParallelScale = 1.4152231609833807
# save animation
SaveAnimation(str(path_folder)+'/Velocity.avi', renderView1, ImageResolution=[2000, 1352],
OverrideColorPalette='WhiteBackground',
FrameRate=10,
FrameWindow=[0, len(res)])
#================================================================
# addendum: following script captures some of the application
# state to faithfully reproduce the visualization during playback
#================================================================
#--------------------------------
# saving layout sizes for layouts
# layout/tab size in pixels
layout1.SetSize(2000, 1354)
#-----------------------------------
# saving camera placements for views
# current camera placement for renderView1
renderView1.InteractionMode = '2D'
renderView1.CameraPosition = [-1.000356661, 0.998216695, 10000.0]
renderView1.CameraFocalPoint = [-1.000356661, 0.998216695, 0.0]
renderView1.CameraParallelScale = 1.4152231609833807
#--------------------------------------------
# uncomment the following to render all views
# RenderAllViews()
# alternatively, if you want to write images, you can use SaveScreenshot(...).