commit | author | age
|
a9c679
|
1 |
import os,sys |
SP |
2 |
from . import trisurf |
|
3 |
if sys.version_info<(3,0): |
|
4 |
from vtk import * |
|
5 |
|
|
6 |
|
8e3453
|
7 |
|
SP |
8 |
class MultiRender: |
|
9 |
def __init__(self,args,host): |
|
10 |
target_runs=getRargetRunIdxList(args) |
|
11 |
if target_runs==None: |
|
12 |
target_runs=list(range(1,len(host['runs'])+1)) |
|
13 |
nruns=len(target_runs) |
|
14 |
#prepare rendering window |
|
15 |
self.renderer_window = vtkRenderWindow() |
|
16 |
self.renderer_window.AddRenderer(self.renderer) |
|
17 |
self.renderer_window.SetSize(1200,600) |
|
18 |
interactor = vtkRenderWindowInteractor() |
|
19 |
interactor.SetRenderWindow(self.renderer_window) |
|
20 |
interactor.Initialize() |
|
21 |
interactor.AddObserver("TimerEvent", self.RenderUpdate) |
|
22 |
timerIDR = interactor.CreateRepeatingTimer(1000) |
|
23 |
self.filename=[] |
|
24 |
self.renderer=[] |
|
25 |
i=0 |
|
26 |
for run in target_runs: |
|
27 |
#for each target run calculate renderer location |
|
28 |
r.vtkRenderer() |
|
29 |
r.SetBackground(0,0,0) |
|
30 |
p=1.0/float(nruns) |
|
31 |
x1=i*p |
|
32 |
x2=(i+1)*p |
|
33 |
r.SetViewport(x1,0.0,x2,1.0) |
|
34 |
self.renderer.Append(r) |
|
35 |
self.renderer_window.AddRenderer(r) |
|
36 |
i=i+1 |
|
37 |
#call Renderer object with Run, renderer |
|
38 |
#start endless loop of interactor |
|
39 |
interactor.Start() |
|
40 |
|
|
41 |
def lastVTU(self,run): |
|
42 |
Dir=trisurf.Directory(maindir=run.maindir,simdir=run.subdir) |
|
43 |
filename=os.path.join("./",Dir.fullpath(),run.getLastVTU()) |
|
44 |
return filename |
|
45 |
|
|
46 |
def lastActorForRun(self,run): |
|
47 |
filename=self.lastVTU(run) |
|
48 |
reader=vtkXMLUnstructuredGridReader() |
|
49 |
reader.SetFileName(self.filename) |
|
50 |
reader.Update() # Needed because of GetScalarRange |
|
51 |
output = reader.GetOutput() |
|
52 |
scalar_range = output.GetScalarRange() |
|
53 |
mapper = vtkDataSetMapper() |
|
54 |
mapper.SetInput(output) |
|
55 |
mapper.SetScalarRange(scalar_range) |
|
56 |
|
|
57 |
# Create the Actor |
|
58 |
actor = vtkActor() |
|
59 |
actor.SetMapper(mapper) |
|
60 |
return actor |
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
def RenderUpdate(self, obj, event): |
|
65 |
i=0 |
|
66 |
for run in runs: |
|
67 |
if(self.lastVTU(run)!=self.filename[i]): |
|
68 |
#print("updejt") |
|
69 |
self.renderer.RemoveActor(self.actor) |
|
70 |
self.renderer.RemoveActor(self.textactor) |
|
71 |
self.actor=self.lastActor() |
|
72 |
self.textactor=self.textActor() |
|
73 |
self.renderer.AddActor(self.actor) |
|
74 |
self.renderer.AddActor(self.textactor) |
|
75 |
self.renderer_window.Render() |
|
76 |
#self.render.RemoveActor(self.actor) |
|
77 |
i=i+1 |
|
78 |
return |
|
79 |
|
|
80 |
|
a9c679
|
81 |
class Renderer: |
SP |
82 |
def __init__(self,args,host): |
|
83 |
self.host=host |
|
84 |
self.args=args |
|
85 |
self.renderer = vtkRenderer() |
|
86 |
self.actor=self.lastActor() |
8a1af8
|
87 |
self.textactor=self.textActor() |
a9c679
|
88 |
self.renderer.AddActor(self.actor) |
8a1af8
|
89 |
self.renderer.AddActor(self.textactor) |
a9c679
|
90 |
self.renderer.SetBackground(0, 0, 0) # Set background to white |
SP |
91 |
# Create the RendererWindow |
|
92 |
self.renderer_window = vtkRenderWindow() |
|
93 |
self.renderer_window.AddRenderer(self.renderer) |
9e5a9c
|
94 |
self.renderer_window.SetSize(1200,600) |
SP |
95 |
|
|
96 |
self.renderer.SetViewport(0.0,0.0,0.5,1.0) |
|
97 |
rend=vtk.vtkRenderer() |
|
98 |
rend.AddActor(self.actor) |
|
99 |
rend.SetViewport(0.5,0.0,1.0,1.0) |
|
100 |
self.renderer_window.AddRenderer(rend) |
a9c679
|
101 |
# Set up a check for aborting rendering. |
SP |
102 |
# Create the RendererWindowInteractor and display the vtk_file |
|
103 |
interactor = vtkRenderWindowInteractor() |
|
104 |
interactor.SetRenderWindow(self.renderer_window) |
|
105 |
interactor.Initialize() |
|
106 |
interactor.AddObserver("TimerEvent", self.RenderUpdate) |
|
107 |
timerIDR = interactor.CreateRepeatingTimer(1000) |
|
108 |
interactor.Start() |
|
109 |
|
|
110 |
return |
|
111 |
|
|
112 |
def lastVTU(self): |
|
113 |
Dir=trisurf.Directory(maindir=self.host['runs'][0].maindir,simdir=self.host['runs'][0].subdir) |
|
114 |
filename=os.path.join("./",Dir.fullpath(),self.host['runs'][0].getLastVTU()) |
|
115 |
return filename |
|
116 |
|
8a1af8
|
117 |
def textActor(self): |
SP |
118 |
textactor=vtkTextActor() |
|
119 |
textactor.SetInput(self.filename) |
|
120 |
tp=textactor.GetTextProperty() |
|
121 |
tp.SetColor(1,1,1) |
9e5a9c
|
122 |
tp.SetFontSize(11) |
8a1af8
|
123 |
textactor.SetDisplayPosition(20,30) |
SP |
124 |
return textactor |
|
125 |
|
a9c679
|
126 |
def lastActor(self): |
SP |
127 |
self.filename=self.lastVTU() |
|
128 |
reader=vtkXMLUnstructuredGridReader() |
|
129 |
reader.SetFileName(self.filename) |
|
130 |
reader.Update() # Needed because of GetScalarRange |
|
131 |
output = reader.GetOutput() |
|
132 |
scalar_range = output.GetScalarRange() |
|
133 |
mapper = vtkDataSetMapper() |
|
134 |
mapper.SetInput(output) |
|
135 |
mapper.SetScalarRange(scalar_range) |
|
136 |
|
|
137 |
# Create the Actor |
|
138 |
actor = vtkActor() |
|
139 |
actor.SetMapper(mapper) |
|
140 |
return actor |
|
141 |
|
|
142 |
|
|
143 |
def RenderUpdate(self, obj, event): |
|
144 |
if(self.lastVTU()!=self.filename): |
8a1af8
|
145 |
#print("updejt") |
a9c679
|
146 |
self.renderer.RemoveActor(self.actor) |
8a1af8
|
147 |
self.renderer.RemoveActor(self.textactor) |
a9c679
|
148 |
self.actor=self.lastActor() |
8a1af8
|
149 |
self.textactor=self.textActor() |
a9c679
|
150 |
self.renderer.AddActor(self.actor) |
8a1af8
|
151 |
self.renderer.AddActor(self.textactor) |
a9c679
|
152 |
self.renderer_window.Render() |
SP |
153 |
#self.render.RemoveActor(self.actor) |
|
154 |
|
|
155 |
return |