Revisão | a60d3d7266dce4588ca7b7a36a0b22f002b1e2aa (tree) |
---|---|
Hora | 2013-04-03 16:32:33 |
Autor | pylaf |
Commiter | pylaf |
enable data visualization using vtk
@@ -1115,7 +1115,8 @@ | ||
1115 | 1115 | elif isinstance(prime.owner,Tkinter.Widget): |
1116 | 1116 | # ウィジェットならば collabomap のみへプライマリを登録する |
1117 | 1117 | name,owner = prime.name, prime.owner |
1118 | - forcollabomap.appendChild(portitem(name,owner.name)) | |
1118 | + wname = owner.winfo_name() | |
1119 | + forcollabomap.appendChild(portitem(name,wname)) | |
1119 | 1120 | # その他のオブジェクトを処理する |
1120 | 1121 | for observer in others: |
1121 | 1122 | name,owner = observer.name, observer.owner |
@@ -53,6 +53,12 @@ | ||
53 | 53 | class Point(SpecificTuple): |
54 | 54 | keys = ('x','y','z') |
55 | 55 | |
56 | +class Color(SpecificTuple): | |
57 | + keys = ('red','green','blue') | |
58 | + | |
59 | +class MinMax(SpecificTuple): | |
60 | + keys = ('min','max') | |
61 | + | |
56 | 62 | class TupleBridge(Logic): |
57 | 63 | def __init__(self,*args,**kw): |
58 | 64 | Logic.__init__(self,*args,**kw) |
@@ -3,6 +3,7 @@ | ||
3 | 3 | from actor import * |
4 | 4 | from algorithm import * |
5 | 5 | from base import * |
6 | +from dataset import * | |
6 | 7 | from implicit import * |
7 | 8 | from mapper import * |
8 | 9 | from source import * |
@@ -1,9 +1,11 @@ | ||
1 | 1 | # coding: utf-8 |
2 | 2 | |
3 | 3 | import vtk |
4 | -from pylafiii.ingredient import event,Port | |
4 | +import pylafiii | |
5 | +from pylafiii.ingredient import event,rule,Port,Logic | |
5 | 6 | from pylafiii.tkext import SpecificTuple |
6 | 7 | from pylafiii.vtkext import vtkLogic |
8 | +from vtk.util.numpy_support import numpy_to_vtk, vtk_to_numpy | |
7 | 9 | |
8 | 10 | class ContourFilter(vtkLogic): |
9 | 11 | vtkClass = vtk.vtkContourFilter |
@@ -41,3 +43,69 @@ | ||
41 | 43 | @event() |
42 | 44 | def model_bounds(self): |
43 | 45 | 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 | + |
@@ -1,6 +1,7 @@ | ||
1 | 1 | # coding: utf-8 |
2 | 2 | |
3 | 3 | import vtk |
4 | +import pylafiii.tkext | |
4 | 5 | from pylafiii.ingredient import Logic,Port,rule,event |
5 | 6 | from vtk.tk.vtkTkRenderWidget import vtkTkRenderWidget |
6 | 7 |
@@ -20,6 +21,10 @@ | ||
20 | 21 | vtkClass = vtk.vtkRenderer |
21 | 22 | @event(()) |
22 | 23 | def actors(self): |
24 | + self.update_actors() | |
25 | + def _link_actors(self): | |
26 | + self.update_actors() | |
27 | + def update_actors(self): | |
23 | 28 | actors = self.actors |
24 | 29 | if not actors: return |
25 | 30 | vtkobj = self.vtkobj |
@@ -36,6 +41,11 @@ | ||
36 | 41 | candidate.append(v) |
37 | 42 | for v in candidate: |
38 | 43 | 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) | |
39 | 49 | @rule |
40 | 50 | def render(self): |
41 | 51 | # 再描画 |
@@ -12,3 +12,10 @@ | ||
12 | 12 | def _unlink_input(self): |
13 | 13 | self.input = None |
14 | 14 | 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) |