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
| try: import vtkmodules.all as vtk except ImportError: import vtk r = vtk.vtkFLUENTReader() r.SetFileName(r'fluent.cas') r.EnableAllCellArrays() r.Update()
data = r.GetOutput().GetBlock(0).GetCellData() arrays_number = data.GetNumberOfArrays() for i in range(arrays_number): array_name = data.GetArrayName(i) print(array_name) NAME = 'PRESSURE' scalars = vtk.vtkFloatArray() scalars = r.GetOutput().GetBlock(0).GetCellData().GetArray(NAME) g = vtk.vtkGeometryFilter() g.SetInputConnection(r.GetOutputPort()) lut = vtk.vtkLookupTable() lut.SetHueRange(0.667, 0) lut.Build()
plane = vtk.vtkPlane() plane.SetOrigin(0, 0, 0) plane.SetNormal(1, 0, 0)
cutter = vtk.vtkCutter() cutter.SetCutFunction(plane) cutter.SetInputConnection(r.GetOutputPort()) cutter.Update()
GeoMapper = vtk.vtkCompositePolyDataMapper() GeoMapper.SetInputConnection(g.GetOutputPort()) GeoActor = vtk.vtkActor() GeoActor.SetMapper(GeoMapper) GeoRen = vtk.vtkRenderer() GeoRen.SetViewport(0.0, 0.5, 0.5, 1.0) GeoRen.GradientBackgroundOn() GeoRen.SetBackground(1, 1, 1) GeoRen.SetBackground2(0.4, 0.55, 0.75) GeoRen.AddActor(GeoActor)
MeshMapper = vtk.vtkCompositePolyDataMapper() MeshMapper.SetInputConnection(g.GetOutputPort()) MeshActor = vtk.vtkActor() MeshActor.SetMapper(MeshMapper) MeshProp = MeshActor.GetProperty() MeshProp.EdgeVisibilityOn() MeshRen = vtk.vtkRenderer() MeshRen.SetViewport(0.5, 0.5, 1.0, 1.0) MeshRen.GradientBackgroundOn() MeshRen.SetBackground(1, 1, 1) MeshRen.SetBackground2(0.4, 0.55, 0.75) MeshRen.AddActor(MeshActor)
TempMapper = vtk.vtkCompositePolyDataMapper() TempMapper.SetInputConnection(g.GetOutputPort()) TempMapper.SetScalarModeToUseCellFieldData() TempMapper.SelectColorArray(NAME) TempMapper.SetScalarRange(scalars.GetRange()) TempMapper.SetLookupTable(lut) TempActor = vtk.vtkActor() TempActor.SetMapper(TempMapper) TempRen = vtk.vtkRenderer() TempRen.SetViewport(0.0, 0.0, 0.5, 0.5) TempRen.GradientBackgroundOn() TempRen.SetBackground(1, 1, 1) TempRen.SetBackground2(0.4, 0.55, 0.75) TempRen.AddActor(TempActor)
SliceMapper = vtk.vtkCompositePolyDataMapper() SliceMapper.SetInputConnection(cutter.GetOutputPort()) SliceMapper.SetScalarModeToUseCellFieldData() SliceMapper.SelectColorArray(NAME) SliceMapper.SetScalarRange(scalars.GetRange()) SliceMapper.SetLookupTable(lut) SliceActor = vtk.vtkActor() SliceActor.SetMapper(SliceMapper) SliceRen = vtk.vtkRenderer() SliceRen.SetViewport(0.5, 0.0, 1.0, 0.5) SliceRen.GradientBackgroundOn() SliceRen.SetBackground(1, 1, 1) SliceRen.SetBackground2(0.4, 0.55, 0.75) SliceRen.AddActor(SliceActor)
legendBar = vtk.vtkScalarBarActor() legendBar.SetOrientationToVertical() legendBar.SetLookupTable(lut) legenProp = vtk.vtkTextProperty() legenProp.SetColor(0, 0, 0) legenProp.SetFontSize(20) legenProp.SetFontFamilyToArial() legenProp.ItalicOff() legenProp.BoldOff() legendBar.UnconstrainedFontSizeOn() legendBar.SetTitleTextProperty(legenProp) legendBar.SetLabelTextProperty(legenProp) legendBar.SetLabelFormat("%5.2f") legendBar.SetTitle("tempereture") TempRen.AddActor(legendBar) SliceRen.AddActor(legendBar)
renWin = vtk.vtkRenderWindow() renWin.AddRenderer(GeoRen) renWin.AddRenderer(MeshRen) renWin.AddRenderer(TempRen) renWin.AddRenderer(SliceRen) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin)
renWin.SetSize(300, 300) renWin.Render()
iren.Initialize() iren.Start()
|