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}")