File size: 2,180 Bytes
22d58cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import os
import math
from paraview.simple import *

SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
VTI_PATH = os.path.join(SCRIPT_DIR, 'RTI_velocity_0060.vti')
OUTPUT_IMG = os.path.join(SCRIPT_DIR, 'gt_image.png')
OUTPUT_STATE = os.path.join(SCRIPT_DIR, 'gt_state.pvsm')

reader = XMLImageDataReader(FileName=[VTI_PATH])
reader.UpdatePipeline()

# Create circular seed points using programmable source
circleSource = ProgrammableSource()
circleSource.OutputDataSetType = 'vtkPolyData'
circleSource.Script = """
import vtk
import math
points = vtk.vtkPoints()
num_points = 40
radius = 30.0
cx, cy, cz = 64.0, 64.0, 64.0
for i in range(num_points):
    angle = 2.0 * math.pi * i / num_points
    x = cx + radius * math.cos(angle)
    z = cz + radius * math.sin(angle)
    points.InsertNextPoint(x, cy, z)
output.SetPoints(points)
"""
circleSource.UpdatePipeline()

# Stream tracer with point cloud seed from circle
streamSurface = StreamTracerWithCustomSource(Input=reader, SeedSource=circleSource)
streamSurface.Vectors = ['POINTS', 'vector']
streamSurface.IntegrationDirection = 'BOTH'
streamSurface.MaximumStreamlineLength = 200.0
streamSurface.UpdatePipeline()

# Create ribbon surface
ribbon = Ribbon(Input=streamSurface)
ribbon.Scalars = ['POINTS', 'vy']
ribbon.Width = 1.2
ribbon.UpdatePipeline()

renderView = GetActiveViewOrCreate('RenderView')
renderView.ViewSize = [1024, 1024]
renderView.Background = [0.0, 0.0, 0.0]

ribbonDisplay = Show(ribbon, renderView)
ribbonDisplay.Representation = 'Surface'
ribbonDisplay.Opacity = 0.85
ColorBy(ribbonDisplay, ('POINTS', 'vy'))

vyLUT = GetColorTransferFunction('vy')
vyLUT.ApplyPreset('Cool to Warm (Extended)', True)

ribbonDisplay.SetScalarBarVisibility(renderView, True)
colorBar = GetScalarBar(vyLUT, renderView)
colorBar.Title = 'Vertical Velocity (vy)'
colorBar.ComponentTitle = ''

# Elevated camera view
renderView.CameraPosition = [64.0, 200.0, 150.0]
renderView.CameraFocalPoint = [63.5, 63.5, 63.5]
renderView.CameraViewUp = [0.0, 0.0, 1.0]
renderView.ResetCamera()
Render()

SaveScreenshot(OUTPUT_IMG, renderView, ImageResolution=[1024, 1024])
SaveState(OUTPUT_STATE)
print(f"Task 18 done: {OUTPUT_IMG}")