Trisurf Monte Carlo simulator
Samo Penic
2016-07-09 9e5a9c0f110d3ed02751c9d44a3716caa6010a70
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
7 class Renderer:
8     def __init__(self,args,host):
9         self.host=host
10         self.args=args
11         self.renderer = vtkRenderer()
12         self.actor=self.lastActor()
8a1af8 13         self.textactor=self.textActor()
a9c679 14         self.renderer.AddActor(self.actor)
8a1af8 15         self.renderer.AddActor(self.textactor)
a9c679 16         self.renderer.SetBackground(0, 0, 0) # Set background to white
SP 17         # Create the RendererWindow
18         self.renderer_window = vtkRenderWindow()
19         self.renderer_window.AddRenderer(self.renderer)
9e5a9c 20         self.renderer_window.SetSize(1200,600)
SP 21     
22         self.renderer.SetViewport(0.0,0.0,0.5,1.0)
23         rend=vtk.vtkRenderer()
24         rend.AddActor(self.actor)
25         rend.SetViewport(0.5,0.0,1.0,1.0)
26         self.renderer_window.AddRenderer(rend)    
a9c679 27 # Set up a check for aborting rendering.
SP 28         # Create the RendererWindowInteractor and display the vtk_file
29         interactor = vtkRenderWindowInteractor()
30         interactor.SetRenderWindow(self.renderer_window)
31         interactor.Initialize()
32          interactor.AddObserver("TimerEvent", self.RenderUpdate)
33         timerIDR = interactor.CreateRepeatingTimer(1000)
34         interactor.Start()
35
36         return
37
38     def lastVTU(self):
39         Dir=trisurf.Directory(maindir=self.host['runs'][0].maindir,simdir=self.host['runs'][0].subdir)
40         filename=os.path.join("./",Dir.fullpath(),self.host['runs'][0].getLastVTU())
41         return filename
42
8a1af8 43     def textActor(self):
SP 44         textactor=vtkTextActor()
45         textactor.SetInput(self.filename)
46         tp=textactor.GetTextProperty()
47         tp.SetColor(1,1,1)
9e5a9c 48         tp.SetFontSize(11)
8a1af8 49         textactor.SetDisplayPosition(20,30)
SP 50         return textactor
51
a9c679 52     def lastActor(self):
SP 53         self.filename=self.lastVTU()
54         reader=vtkXMLUnstructuredGridReader()
55         reader.SetFileName(self.filename)
56         reader.Update() # Needed because of GetScalarRange
57         output = reader.GetOutput()
58         scalar_range = output.GetScalarRange()
59         mapper = vtkDataSetMapper()
60         mapper.SetInput(output)
61         mapper.SetScalarRange(scalar_range)
62
63         # Create the Actor
64         actor = vtkActor()
65         actor.SetMapper(mapper)
66         return actor
67
68
69     def RenderUpdate(self, obj, event):
70         if(self.lastVTU()!=self.filename):
8a1af8 71             #print("updejt")
a9c679 72             self.renderer.RemoveActor(self.actor)
8a1af8 73             self.renderer.RemoveActor(self.textactor)
a9c679 74             self.actor=self.lastActor()
8a1af8 75             self.textactor=self.textActor()
a9c679 76             self.renderer.AddActor(self.actor)
8a1af8 77             self.renderer.AddActor(self.textactor)
a9c679 78             self.renderer_window.Render()
SP 79         #self.render.RemoveActor(self.actor)
80         
81         return