Commit MetaInfo

Revisiona60d3d7266dce4588ca7b7a36a0b22f002b1e2aa (tree)
Zeit2013-04-03 16:32:33
Autorpylaf
Commiterpylaf

Log Message

enable data visualization using vtk

Ändern Zusammenfassung

Diff

diff -r 2be6f5f1e236 -r a60d3d7266dc src/pylafiii/chef.py
--- a/src/pylafiii/chef.py Thu Mar 28 18:18:02 2013 +0900
+++ b/src/pylafiii/chef.py Wed Apr 03 16:32:33 2013 +0900
@@ -1115,7 +1115,8 @@
11151115 elif isinstance(prime.owner,Tkinter.Widget):
11161116 # ウィジェットならば collabomap のみへプライマリを登録する
11171117 name,owner = prime.name, prime.owner
1118- forcollabomap.appendChild(portitem(name,owner.name))
1118+ wname = owner.winfo_name()
1119+ forcollabomap.appendChild(portitem(name,wname))
11191120 # その他のオブジェクトを処理する
11201121 for observer in others:
11211122 name,owner = observer.name, observer.owner
diff -r 2be6f5f1e236 -r a60d3d7266dc src/pylafiii/tkext.py
--- a/src/pylafiii/tkext.py Thu Mar 28 18:18:02 2013 +0900
+++ b/src/pylafiii/tkext.py Wed Apr 03 16:32:33 2013 +0900
@@ -53,6 +53,12 @@
5353 class Point(SpecificTuple):
5454 keys = ('x','y','z')
5555
56+class Color(SpecificTuple):
57+ keys = ('red','green','blue')
58+
59+class MinMax(SpecificTuple):
60+ keys = ('min','max')
61+
5662 class TupleBridge(Logic):
5763 def __init__(self,*args,**kw):
5864 Logic.__init__(self,*args,**kw)
diff -r 2be6f5f1e236 -r a60d3d7266dc src/pylafiii/vtkext/__init__.py
--- a/src/pylafiii/vtkext/__init__.py Thu Mar 28 18:18:02 2013 +0900
+++ b/src/pylafiii/vtkext/__init__.py Wed Apr 03 16:32:33 2013 +0900
@@ -3,6 +3,7 @@
33 from actor import *
44 from algorithm import *
55 from base import *
6+from dataset import *
67 from implicit import *
78 from mapper import *
89 from source import *
diff -r 2be6f5f1e236 -r a60d3d7266dc src/pylafiii/vtkext/algorithm.py
--- a/src/pylafiii/vtkext/algorithm.py Thu Mar 28 18:18:02 2013 +0900
+++ b/src/pylafiii/vtkext/algorithm.py Wed Apr 03 16:32:33 2013 +0900
@@ -1,9 +1,11 @@
11 # coding: utf-8
22
33 import vtk
4-from pylafiii.ingredient import event,Port
4+import pylafiii
5+from pylafiii.ingredient import event,rule,Port,Logic
56 from pylafiii.tkext import SpecificTuple
67 from pylafiii.vtkext import vtkLogic
8+from vtk.util.numpy_support import numpy_to_vtk, vtk_to_numpy
79
810 class ContourFilter(vtkLogic):
911 vtkClass = vtk.vtkContourFilter
@@ -41,3 +43,69 @@
4143 @event()
4244 def model_bounds(self):
4345 self.vtkobj.SetModelBounds(*self.model_bounds)
46+
47+class Cutter(vtkLogic):
48+ vtkClass = vtk.vtkCutter
49+ input = Port()
50+ output = Port()
51+ func = Port()
52+ def initialize(self):
53+ self.output = self.vtkobj.GetOutput()
54+ def _link_func(self):
55+ self.vtkobj.SetCutFunction(self.func)
56+ def _link_input(self):
57+ self.vtkobj.SetInput(self.input)
58+ def _unlink_input(self):
59+ self.input = None
60+ self.vtkobj.SetInput(None)
61+ @rule
62+ def update(self):
63+ self.vtkobj.SetCutFunction(None)
64+ self.vtkobj.SetCutFunction(self.func)
65+
66+class StructuredPoints(vtkLogic):
67+ vtkClass = vtk.vtkStructuredPoints
68+ scalar = Port()
69+ @event
70+ def scalar(self):
71+ self.update_scalar()
72+ def _link_scalar(self):
73+ self.update_scalar()
74+ def update_scalar(self):
75+ self.vtkobj.GetPointData().SetScalars(self.scalar)
76+ @event
77+ def dimension(self):
78+ self.update_dimension()
79+ def _link_dimension(self):
80+ if self.dimension:
81+ self.update_dimension()
82+ def update_dimension(self):
83+ self.vtkobj.SetDimensions(*self.dimension)
84+
85+class Scalar(Logic):
86+ vtkobj = Port()
87+ range = Port()
88+ def _link_vtkobj(self):
89+ if self.vtkobj:
90+ rng = self.vtkobj.GetRange()
91+ self.range = pylafiii.tkext.MinMax(rng)
92+
93+class OutlineFilter(vtkLogic):
94+ vtkClass = vtk.vtkOutlineFilter
95+ output = Port()
96+ input = Port()
97+ def initialize(self):
98+ self.output = self.vtkobj.GetOutput()
99+ def _link_input(self):
100+ self.vtkobj.SetInput(self.input)
101+
102+class DataSource(Logic):
103+ input = Port()
104+ dimension = Port()
105+ vtkobj = Port()
106+ def _link_input(self):
107+ data = self.input.data
108+ nz,ny,nx = data.shape
109+ self.dimension = pylafiii.tkext.Point((nx,ny,nz))
110+ self.vtkobj = numpy_to_vtk(data.reshape(nz * ny * nx))
111+
diff -r 2be6f5f1e236 -r a60d3d7266dc src/pylafiii/vtkext/base.py
--- a/src/pylafiii/vtkext/base.py Thu Mar 28 18:18:02 2013 +0900
+++ b/src/pylafiii/vtkext/base.py Wed Apr 03 16:32:33 2013 +0900
@@ -1,6 +1,7 @@
11 # coding: utf-8
22
33 import vtk
4+import pylafiii.tkext
45 from pylafiii.ingredient import Logic,Port,rule,event
56 from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget
67
@@ -20,6 +21,10 @@
2021 vtkClass = vtk.vtkRenderer
2122 @event(())
2223 def actors(self):
24+ self.update_actors()
25+ def _link_actors(self):
26+ self.update_actors()
27+ def update_actors(self):
2328 actors = self.actors
2429 if not actors: return
2530 vtkobj = self.vtkobj
@@ -36,6 +41,11 @@
3641 candidate.append(v)
3742 for v in candidate:
3843 vtkobj.RemoveActor(v)
44+ @event
45+ def background(self):
46+ o = self.background
47+ if isinstance(o,pylafiii.tkext.Color):
48+ self.vtkobj.SetBackground(*o)
3949 @rule
4050 def render(self):
4151 # 再描画
diff -r 2be6f5f1e236 -r a60d3d7266dc src/pylafiii/vtkext/mapper.py
--- a/src/pylafiii/vtkext/mapper.py Thu Mar 28 18:18:02 2013 +0900
+++ b/src/pylafiii/vtkext/mapper.py Wed Apr 03 16:32:33 2013 +0900
@@ -12,3 +12,10 @@
1212 def _unlink_input(self):
1313 self.input = None
1414 self.vtkobj.SetInput(None)
15+ @event
16+ def scalarrange(self):
17+ self.vtkobj.SetScalarRange(self.scalarrange)
18+ def _link_scalarrange(self):
19+ rng = self.scalarrange
20+ if rng:
21+ self.vtkobj.SetScalarRange(self.scalarrange)
Show on old repository browser