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