Commit MetaInfo

Revisão0b4240a7b1e56cd9e3b7df7911d8f7b85cb3f905 (tree)
Hora2013-04-03 17:16:52
Autorpylaf
Commiterpylaf

Mensagem de Log

recipe for data visualizer

Mudança Sumário

Diff

diff -r a60d3d7266dc -r 0b4240a7b1e5 src/experiment/vtk_data_pylafiii.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/experiment/vtk_data_pylafiii.py Wed Apr 03 17:16:52 2013 +0900
@@ -0,0 +1,350 @@
1+# coding: utf-8
2+
3+import numpy
4+import pylafiii as laf
5+from pylafiii import Port,Logic,rule,event
6+
7+class MyRecipe001(laf.chef.Recipe):
8+ XML = '''<?xml version="1.0" ?>
9+<recipe>
10+ <netlist>
11+ <logic cls="Renderer" module="pylafiii.vtkext.base" name="renderer"/>
12+ <logic cls="TupledCombiner5" module="pylafiii.vtkext.base" name="combiner"/>
13+ <!--logic cls="Scalar" module="pylafiii.vtkext.algorithm" name="range"/-->
14+ <logic cls="OutlineFilter" module="pylafiii.vtkext.algorithm" name="outlinefilter"/>
15+ <!--logic cls="Plane" module="pylafiii.vtkext.implicit" name="plane"/-->
16+ <!--logic cls="Cutter" module="pylafiii.vtkext.algorithm" name="cutter"/-->
17+ <!--logic cls="SphereSource" module="pylafiii.vtkext.source" name="spheresource"/-->
18+ <!--logic cls="PolyDataMapper" module="pylafiii.vtkext.mapper" name="datamapper"/-->
19+ <!--logic cls="Actor" module="pylafiii.vtkext.actor" name="dataactor"/-->
20+ <logic cls="Actor" module="pylafiii.vtkext.actor" name="outlineactor"/>
21+ <logic cls="StructuredPoints" module="pylafiii.vtkext.algorithm" name="structuredpoints"/>
22+ <logic cls="TestData" module="__main__" name="testdata"/>
23+ <logic cls="PolyDataMapper" module="pylafiii.vtkext.mapper" name="outlinemapper"/>
24+ <logic cls="DataSource" module="pylafiii.vtkext.algorithm" name="datasource"/>
25+ <!--link>
26+ <port name="vtkobj" owner="datamapper"/>
27+ <port name="mapper" owner="dataactor"/>
28+ </link-->
29+ <!--link>
30+ <port name="vtkobj" owner="plane"/>
31+ <port name="func" owner="cutter"/>
32+ </link-->
33+ <!--link>
34+ <port name="vtkobj" owner="dataactor"/>
35+ <port name="hook1" owner="combiner"/>
36+ </link-->
37+ <link>
38+ <port name="vtkobj" owner="outlinemapper"/>
39+ <port name="mapper" owner="outlineactor"/>
40+ </link>
41+ <link>
42+ <port name="vtkobj" owner="structuredpoints"/>
43+ <port name="input" owner="outlinefilter"/>
44+ </link>
45+ <link>
46+ <port name="vtkobj" owner="outlineactor"/>
47+ <port name="hook0" owner="combiner"/>
48+ </link>
49+ <link>
50+ <port name="collection" owner="combiner"/>
51+ <port name="actors" owner="renderer"/>
52+ </link>
53+ <!--link>
54+ <port name="range" owner="range"/>
55+ <port name="scalarrange" owner="datamapper"/>
56+ </link-->
57+ <link>
58+ <port name="dimension" owner="datasource"/>
59+ <port name="dimension" owner="structuredpoints"/>
60+ </link>
61+ <link>
62+ <port name="vtkobj" owner="datasource"/>
63+ <port name="scalar" owner="structuredpoints"/>
64+ <!--port name="vtkobj" owner="range"/-->
65+ </link>
66+ <link>
67+ <port name="myself" owner="testdata"/>
68+ <port name="input" owner="datasource"/>
69+ </link>
70+ <link>
71+ <port name="output" owner="outlinefilter"/>
72+ <port name="input" owner="outlinemapper"/>
73+ </link>
74+ </netlist>
75+ <collabomap>
76+ <item locx="524" locy="56" name="renderer"/>
77+ <item locx="563" locy="129" name="combiner"/>
78+ <!--item locx="318" locy="332" name="range"/-->
79+ <item locx="148" locy="93" name="outlinefilter"/>
80+ <!--item locx="439" locy="220" name="plane"/-->
81+ <!--item locx="401" locy="275" name="cutter"/-->
82+ <!--item locx="527" locy="348" name="spheresource"/-->
83+ <!--item locx="363" locy="161" name="datamapper"/-->
84+ <!--item locx="350" locy="110" name="dataactor"/-->
85+ <item locx="323" locy="37" name="outlineactor"/>
86+ <item locx="121" locy="176" name="structuredpoints"/>
87+ <item locx="124" locy="298" name="testdata"/>
88+ <item locx="118" locy="37" name="outlinemapper"/>
89+ <item locx="158" locy="234" name="datasource"/>
90+ </collabomap>
91+</recipe>
92+'''
93+
94+class MyRecipe002(laf.chef.Recipe):
95+ XML = '''<?xml version="1.0" ?>
96+<recipe>
97+ <netlist>
98+ <logic cls="Renderer" module="pylafiii.vtkext.base" name="renderer"/>
99+ <logic cls="Cutter" module="pylafiii.vtkext.algorithm" name="cutter"/>
100+ <logic cls="OutlineFilter" module="pylafiii.vtkext.algorithm" name="outlinefilter"/>
101+ <logic cls="PolyDataMapper" module="pylafiii.vtkext.mapper" name="datamapper"/>
102+ <logic cls="Plane" module="pylafiii.vtkext.implicit" name="plane"/>
103+ <logic cls="PolyDataMapper" module="pylafiii.vtkext.mapper" name="outlinemapper"/>
104+ <logic cls="Scalar" module="pylafiii.vtkext.algorithm" name="range"/>
105+ <logic cls="Actor" module="pylafiii.vtkext.actor" name="dataactor"/>
106+ <logic cls="Actor" module="pylafiii.vtkext.actor" name="outlineactor"/>
107+ <logic cls="DataSource" module="pylafiii.vtkext.algorithm" name="datasource"/>
108+ <logic cls="TupledCombiner5" module="pylafiii.vtkext.base" name="combiner"/>
109+ <logic cls="TestData" module="__main__" name="testdata"/>
110+ <logic cls="StructuredPoints" module="pylafiii.vtkext.algorithm" name="structuredpoints"/>
111+ <logic cls="SphereSource" module="pylafiii.vtkext.source" name="spheresource"/>
112+ <link>
113+ <port name="myself" owner="testdata"/>
114+ <port name="input" owner="datasource"/>
115+ </link>
116+ <link>
117+ <port name="vtkobj" owner="datasource"/>
118+ <port name="scalar" owner="structuredpoints"/>
119+ </link>
120+ <link>
121+ <port name="dimension" owner="datasource"/>
122+ <port name="dimension" owner="structuredpoints"/>
123+ </link>
124+ <link>
125+ <port name="vtkobj" owner="structuredpoints"/>
126+ <port name="input" owner="outlinefilter"/>
127+ </link>
128+ <link>
129+ <port name="output" owner="outlinefilter"/>
130+ <port name="input" owner="outlinemapper"/>
131+ </link>
132+ <link>
133+ <port name="vtkobj" owner="outlinemapper"/>
134+ <port name="mapper" owner="outlineactor"/>
135+ </link>
136+ <link>
137+ <port name="vtkobj" owner="outlineactor"/>
138+ <port name="hook0" owner="combiner"/>
139+ </link>
140+ <link>
141+ <port name="vtkobj" owner="plane"/>
142+ <port name="func" owner="cutter"/>
143+ </link>
144+ <link>
145+ <port name="vtkobj" owner="datamapper"/>
146+ <port name="mapper" owner="dataactor"/>
147+ </link>
148+ <link>
149+ <port name="vtkobj" owner="dataactor"/>
150+ <port name="hook1" owner="combiner"/>
151+ </link>
152+ <link>
153+ <port name="collection" owner="combiner"/>
154+ <port name="actors" owner="renderer"/>
155+ </link>
156+ </netlist>
157+ <collabomap>
158+ <item locx="524" locy="56" name="renderer"/>
159+ <item locx="401" locy="275" name="cutter"/>
160+ <item locx="148" locy="93" name="outlinefilter"/>
161+ <item locx="363" locy="161" name="datamapper"/>
162+ <item locx="439" locy="220" name="plane"/>
163+ <item locx="118" locy="37" name="outlinemapper"/>
164+ <item locx="318" locy="332" name="range"/>
165+ <item locx="350" locy="110" name="dataactor"/>
166+ <item locx="323" locy="37" name="outlineactor"/>
167+ <item locx="158" locy="234" name="datasource"/>
168+ <item locx="563" locy="129" name="combiner"/>
169+ <item locx="124" locy="298" name="testdata"/>
170+ <item locx="121" locy="176" name="structuredpoints"/>
171+ <item locx="527" locy="348" name="spheresource"/>
172+ </collabomap>
173+</recipe>
174+'''
175+
176+class MyRecipe(laf.chef.Recipe):
177+ XML = '''<?xml version="1.0" ?>
178+<recipe>
179+ <netlist>
180+ <logic cls="Cutter" module="pylafiii.vtkext.algorithm" name="cutter"/>
181+ <logic cls="Actor" module="pylafiii.vtkext.actor" name="outlineactor"/>
182+ <logic cls="Scalar" module="pylafiii.vtkext.algorithm" name="range"/>
183+ <logic cls="StructuredPoints" module="pylafiii.vtkext.algorithm" name="structuredpoints"/>
184+ <logic cls="Actor" module="pylafiii.vtkext.actor" name="dataactor"/>
185+ <logic cls="Sequence10" module="__main__" name="4732044176"/>
186+ <logic cls="PolyDataMapper" module="pylafiii.vtkext.mapper" name="outlinemapper"/>
187+ <logic cls="TupledCombiner5" module="pylafiii.vtkext.base" name="combiner"/>
188+ <logic cls="PolyDataMapper" module="pylafiii.vtkext.mapper" name="datamapper"/>
189+ <logic cls="Plane" module="pylafiii.vtkext.implicit" name="plane"/>
190+ <logic cls="Renderer" module="pylafiii.vtkext.base" name="renderer"/>
191+ <logic cls="DataSource" module="pylafiii.vtkext.algorithm" name="datasource"/>
192+ <logic cls="OutlineFilter" module="pylafiii.vtkext.algorithm" name="outlinefilter"/>
193+ <logic cls="SphereSource" module="pylafiii.vtkext.source" name="spheresource"/>
194+ <logic cls="TestData" module="__main__" name="testdata"/>
195+ <link>
196+ <port name="vtkobj" owner="outlineactor"/>
197+ <port name="hook0" owner="combiner"/>
198+ </link>
199+ <link>
200+ <port name="vtkobj" owner="datasource"/>
201+ <port name="scalar" owner="structuredpoints"/>
202+ <port name="vtkobj" owner="range"/>
203+ </link>
204+ <link>
205+ <port name="vtkobj" owner="dataactor"/>
206+ <port name="hook1" owner="combiner"/>
207+ </link>
208+ <link>
209+ <port name="vtkobj" owner="plane"/>
210+ <port name="func" owner="cutter"/>
211+ </link>
212+ <link>
213+ <port name="vtkobj" owner="datamapper"/>
214+ <port name="mapper" owner="dataactor"/>
215+ </link>
216+ <link>
217+ <port name="update" owner="cutter"/>
218+ <port name="hook3" owner="4732044176"/>
219+ </link>
220+ <link>
221+ <port name="vtkobj" owner="structuredpoints"/>
222+ <port name="input" owner="outlinefilter"/>
223+ <port name="input" owner="cutter"/>
224+ </link>
225+ <link>
226+ <port name="output" owner="outlinefilter"/>
227+ <port name="input" owner="outlinemapper"/>
228+ </link>
229+ <link>
230+ <port name="output" owner="cutter"/>
231+ <port name="input" owner="datamapper"/>
232+ </link>
233+ <link>
234+ <port name="vtkobj" owner="outlinemapper"/>
235+ <port name="mapper" owner="outlineactor"/>
236+ </link>
237+ <link>
238+ <port name="range" owner="range"/>
239+ <port name="scalarrange" owner="datamapper"/>
240+ <port name="hook1" owner="4732044176"/>
241+ </link>
242+ <link>
243+ <port name="render" owner="renderer"/>
244+ <port name="hook0" owner="4732044176"/>
245+ </link>
246+ <link>
247+ <port name="myself" owner="testdata"/>
248+ <port name="input" owner="datasource"/>
249+ <port name="hook2" owner="4732044176"/>
250+ </link>
251+ <link>
252+ <port name="collection" owner="combiner"/>
253+ <port name="actors" owner="renderer"/>
254+ </link>
255+ <link>
256+ <port name="dimension" owner="datasource"/>
257+ <port name="dimension" owner="structuredpoints"/>
258+ </link>
259+ </netlist>
260+ <collabomap>
261+ <item locx="401" locy="275" name="cutter"/>
262+ <item locx="323" locy="37" name="outlineactor"/>
263+ <item locx="318" locy="332" name="range"/>
264+ <item locx="121" locy="176" name="structuredpoints"/>
265+ <item locx="350" locy="110" name="dataactor"/>
266+ <item locx="635" locy="239" name="4732044176"/>
267+ <item locx="118" locy="37" name="outlinemapper"/>
268+ <item locx="563" locy="129" name="combiner"/>
269+ <item locx="363" locy="161" name="datamapper"/>
270+ <item locx="439" locy="220" name="plane"/>
271+ <item locx="524" locy="56" name="renderer"/>
272+ <item locx="158" locy="234" name="datasource"/>
273+ <item locx="148" locy="93" name="outlinefilter"/>
274+ <item locx="527" locy="348" name="spheresource"/>
275+ <item locx="124" locy="298" name="testdata"/>
276+ <widget cls="AutoTrig" locx="692" locy="308" module="pylafiii.tkext" name="4587761296"/>
277+ <widget cls="AutoTrig" locx="369" locy="416" module="pylafiii.tkext" name="4442151248"/>
278+ <link>
279+ <port name="trig" owner="4732044176"/>
280+ <port name="trig" owner="4587761296"/>
281+ </link>
282+ </collabomap>
283+</recipe>
284+'''
285+
286+class TestData(Logic):
287+ def __init__(self,*args,**kw):
288+ Logic.__init__(self,*args,**kw)
289+ nz,ny,nx = laf.tkext.Point((50,50,50))
290+ z,y,x = numpy.mgrid[-1:1:nz*1j,-1:1:ny*1j,-1:1:nx*1j]
291+ self.data = numpy.cos(2. * numpy.pi * numpy.sqrt(z * z + y * y + x * x)).astype(numpy.float64)
292+# @event
293+# def theta(self):
294+# theta = self.theta
295+# nz,ny,nx = self.data.shape
296+# z,y,x = numpy.mgrid[-1:1:nz*1j,-1:1:ny*1j,-1:1:nx*1j]
297+# self.data[:,:,:] = numpy.cos(2. * numpy.pi * numpy.sqrt(z * z + y * y + x * x) + numpy.pi * theta / 180.).astype(numpy.float64)
298+ @rule
299+ def myself(self,theta=0.):
300+ nz,ny,nx = self.data.shape
301+ z,y,x = numpy.mgrid[-1:1:nz*1j,-1:1:ny*1j,-1:1:nx*1j]
302+ self.data[:,:,:] = numpy.cos(2. * numpy.pi * numpy.sqrt(z * z + y * y + x * x) + numpy.pi * theta / 180.).astype(numpy.float64)
303+ return self
304+
305+class Sequence(Logic):
306+ @classmethod
307+ def mkhooks(cls,num):
308+ cls.num = num
309+ for i in range(num):
310+ setattr(cls,'hook%d' % i,Port())
311+ @rule
312+ def trig(self):
313+ for i in range(self.num):
314+ getattr(self,'hook%d' % i)
315+
316+class Sequence10(Sequence):
317+ Sequence.mkhooks(10)
318+
319+if __name__ == '__main__':
320+ import Tkinter
321+ tk = Tkinter.Tk()
322+ rt = laf.Root()
323+ #
324+ w = laf.chef.CollaboMap(tk,name='collabomap',width=640,height=400,scrollregion=(0,0,4000,4000))
325+ w.grid(row=0,column=0,sticky=Tkinter.N+Tkinter.E+Tkinter.W+Tkinter.S)
326+ xscroll = Tkinter.Scrollbar(tk,orient=Tkinter.HORIZONTAL,command=w.xview)
327+ xscroll.grid(row=1,column=0,sticky=Tkinter.E+Tkinter.W)
328+ yscroll = Tkinter.Scrollbar(tk,orient=Tkinter.VERTICAL,command=w.yview)
329+ yscroll.grid(row=0,column=1,sticky=Tkinter.N+Tkinter.S)
330+ tk.grid_rowconfigure(0,weight=1,minsize=0)
331+ tk.grid_columnconfigure(0,weight=1,minsize=0)
332+ w = laf.chef.ClassChooser(Tkinter.Toplevel(tk,name='classchooser'),name='classchooser')
333+ w.pack(side=Tkinter.LEFT,anchor=Tkinter.NE,fill=Tkinter.BOTH,expand=True)
334+ laf.link(laf.port(tk.children['classchooser'].children['classchooser'],'chosenclass'),laf.port(tk.children['collabomap'],'chosenclass'))
335+ #
336+ x = MyRecipe()
337+ laf.chef.cook_netlist(x,master=rt)
338+ tk.children['collabomap'].cook_collabomap(x)
339+ #
340+ w = laf.vtkext.RenderWidget(Tkinter.Toplevel(tk))
341+ w.pack(side=Tkinter.LEFT,anchor=Tkinter.NE,fill=Tkinter.BOTH,expand=True)
342+ laf.link(laf.port(rt.children['renderer'],'vtkobj'),laf.port(w,'renderer'))
343+ del w
344+ #
345+ rt.children['renderer'].background = laf.tkext.Color((0.,1.,1.))
346+ rt.children['plane'].normal = laf.vtkext.implicit.Plane.Normal((0,0,1))
347+ rt.children['plane'].origin = laf.vtkext.implicit.Plane.Origin((0.,0.,24.5))
348+ #print rt.children['structuredpoints'].vtkobj
349+ #
350+ Tkinter.mainloop()
Show on old repository browser