1 | #from config import printEVT |
---|
2 | from BaseInteractor import _BaseInteractor |
---|
3 | from copy import deepcopy |
---|
4 | import math |
---|
5 | |
---|
6 | #from Plotter1D import AddPlotEvent |
---|
7 | import SlicerParameters |
---|
8 | import wx |
---|
9 | |
---|
10 | import wx.lib.newevent |
---|
11 | |
---|
12 | class RadiusInteractor(_BaseInteractor): |
---|
13 | """ |
---|
14 | Select an annulus through a 2D plot |
---|
15 | """ |
---|
16 | def __init__(self,base,axes,color='black', zorder=5, arc1=None,arc2=None, |
---|
17 | theta=math.pi/8): |
---|
18 | |
---|
19 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
20 | self.markers = [] |
---|
21 | self.axes = axes |
---|
22 | |
---|
23 | self.r1 = arc1.get_radius() |
---|
24 | self.r2 = arc2.get_radius() |
---|
25 | #print "radius init", self.r1, self.r2 |
---|
26 | self.theta=theta |
---|
27 | self.save_theta= theta |
---|
28 | #self.scale = 10.0 |
---|
29 | self.move_stop=False |
---|
30 | self.theta_left=None |
---|
31 | self.theta_right=None |
---|
32 | self.arc1= arc1 |
---|
33 | self.arc2=arc2 |
---|
34 | #raise "Version error", message |
---|
35 | x1= self.r1*math.cos(self.theta) |
---|
36 | y1= self.r1*math.sin(self.theta) |
---|
37 | x2= self.r2*math.cos(self.theta) |
---|
38 | y2= self.r2*math.sin(self.theta) |
---|
39 | self.line = self.axes.plot([x1,x2],[y1,y2], |
---|
40 | linestyle='-', marker='', |
---|
41 | color=self.color, |
---|
42 | visible=True)[0] |
---|
43 | self.phi= theta |
---|
44 | self.npts = 20 |
---|
45 | self.has_move= False |
---|
46 | self.connect_markers([self.line]) |
---|
47 | self.update() |
---|
48 | |
---|
49 | |
---|
50 | def set_layer(self, n): |
---|
51 | self.layernum = n |
---|
52 | self.update() |
---|
53 | |
---|
54 | def clear(self): |
---|
55 | self.clear_markers() |
---|
56 | try: |
---|
57 | self.line.remove() |
---|
58 | |
---|
59 | except: |
---|
60 | # Old version of matplotlib |
---|
61 | for item in range(len(self.axes.lines)): |
---|
62 | del self.axes.lines[0] |
---|
63 | |
---|
64 | |
---|
65 | |
---|
66 | def get_radius(self): |
---|
67 | return self.theta |
---|
68 | |
---|
69 | def update(self,r1=None, r2=None, theta_right=None, theta_left=None): |
---|
70 | """ |
---|
71 | Draw the new roughness on the graph. |
---|
72 | """ |
---|
73 | if r1 !=None: |
---|
74 | self.r1=r1 |
---|
75 | if r2!=None: |
---|
76 | self.r2=r2 |
---|
77 | """ |
---|
78 | self.theta_left=theta_left |
---|
79 | self.theta_right=theta_right |
---|
80 | if r1 !=None: |
---|
81 | self.r1=r1 |
---|
82 | if r2!=None: |
---|
83 | self.r2=r2 |
---|
84 | if theta_right!=None: |
---|
85 | if theta_right < self.theta: |
---|
86 | self.move_stop=True |
---|
87 | else: |
---|
88 | self.move_stop=False |
---|
89 | if theta_left !=None: |
---|
90 | if theta_left > self.theta: |
---|
91 | self.move_stop=True |
---|
92 | else: |
---|
93 | self.move_stop=False |
---|
94 | if theta_left ==None and theta_right==None: |
---|
95 | self.move_stop=True |
---|
96 | """ |
---|
97 | #print "in the edge theta_right theta_left",theta_right,theta_left,self.theta |
---|
98 | x1= self.r1*math.cos(self.theta) |
---|
99 | y1= self.r1*math.sin(self.theta) |
---|
100 | x2= self.r2*math.cos(self.theta) |
---|
101 | y2= self.r2*math.sin(self.theta) |
---|
102 | |
---|
103 | self.line.set(xdata=[x1,x2], ydata=[y1,y2]) |
---|
104 | |
---|
105 | |
---|
106 | def save(self, ev): |
---|
107 | """ |
---|
108 | Remember the roughness for this layer and the next so that we |
---|
109 | can restore on Esc. |
---|
110 | """ |
---|
111 | self.save_theta= self.theta |
---|
112 | self.base.freeze_axes() |
---|
113 | |
---|
114 | def moveend(self, ev): |
---|
115 | self.has_move= False |
---|
116 | self.base.moveend(ev) |
---|
117 | |
---|
118 | def restore(self): |
---|
119 | """ |
---|
120 | Restore the roughness for this layer. |
---|
121 | """ |
---|
122 | self.theta = self.save_theta |
---|
123 | |
---|
124 | def move(self, x, y, ev): |
---|
125 | """ |
---|
126 | Process move to a new position, making sure that the move is allowed. |
---|
127 | """ |
---|
128 | #print "on move theta left , theta right",self.theta_left,self.theta_right |
---|
129 | theta= math.atan2(y,x) |
---|
130 | """print "on move theta left , theta right",self.theta_left,self.theta_right,theta |
---|
131 | if self.theta_left !=None: |
---|
132 | if self.theta_left >= theta: |
---|
133 | print "went hier" |
---|
134 | self.move_stop= True |
---|
135 | if self.theta_right !=None: |
---|
136 | if self.theta_right <= theta: |
---|
137 | self.move_stop= True |
---|
138 | |
---|
139 | self.move_stop= True |
---|
140 | if self.move_stop: |
---|
141 | """ |
---|
142 | self.theta= math.atan2(y,x) |
---|
143 | self.has_move= True |
---|
144 | |
---|
145 | self.base.base.update() |
---|
146 | |
---|
147 | def set_cursor(self, x, y): |
---|
148 | self.move(x, y, None) |
---|
149 | self.update() |
---|
150 | |
---|
151 | |
---|
152 | def get_params(self): |
---|
153 | params = {} |
---|
154 | params["radius1"] = self.r1 |
---|
155 | params["radius2"] = self.r2 |
---|
156 | return params |
---|
157 | |
---|
158 | def set_params(self, params): |
---|
159 | |
---|
160 | x1 = params["radius1"] |
---|
161 | x2 = params["radius2"] |
---|
162 | self.set_cursor(x, self._inner_mouse_y) |
---|
163 | |
---|
164 | |
---|