Trisurf Monte Carlo simulator
Samo Penic
2016-07-08 a9c679d4e4b49e44542bac81ef4ef65c94418eff
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()
13         self.renderer.AddActor(self.actor)
14         self.renderer.SetBackground(0, 0, 0) # Set background to white
15
16         # Create the RendererWindow
17         self.renderer_window = vtkRenderWindow()
18         self.renderer_window.AddRenderer(self.renderer)
19         
20 # Set up a check for aborting rendering.
21         # Create the RendererWindowInteractor and display the vtk_file
22         interactor = vtkRenderWindowInteractor()
23         interactor.SetRenderWindow(self.renderer_window)
24         interactor.Initialize()
25          interactor.AddObserver("TimerEvent", self.RenderUpdate)
26         timerIDR = interactor.CreateRepeatingTimer(1000)
27         interactor.Start()
28
29         return
30
31     def lastVTU(self):
32         Dir=trisurf.Directory(maindir=self.host['runs'][0].maindir,simdir=self.host['runs'][0].subdir)
33         filename=os.path.join("./",Dir.fullpath(),self.host['runs'][0].getLastVTU())
34         return filename
35
36     def lastActor(self):
37         self.filename=self.lastVTU()
38         reader=vtkXMLUnstructuredGridReader()
39         reader.SetFileName(self.filename)
40         reader.Update() # Needed because of GetScalarRange
41         output = reader.GetOutput()
42         scalar_range = output.GetScalarRange()
43         mapper = vtkDataSetMapper()
44         mapper.SetInput(output)
45         mapper.SetScalarRange(scalar_range)
46
47         # Create the Actor
48         actor = vtkActor()
49         actor.SetMapper(mapper)
50         return actor
51
52
53     def RenderUpdate(self, obj, event):
54         if(self.lastVTU()!=self.filename):
55             print("updejt")
56             self.renderer.RemoveActor(self.actor)
57             self.actor=self.lastActor()
58             self.renderer.AddActor(self.actor)
59             self.renderer_window.Render()
60         #self.render.RemoveActor(self.actor)
61         
62         return