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 | |
---|
30 | self.arc1= arc1 |
---|
31 | self.arc2=arc2 |
---|
32 | #raise "Version error", message |
---|
33 | x1= self.r1*math.cos(self.theta) |
---|
34 | y1= self.r1*math.sin(self.theta) |
---|
35 | x2= self.r2*math.cos(self.theta) |
---|
36 | y2= self.r2*math.sin(self.theta) |
---|
37 | self.line = self.axes.plot([x1,x2],[y1,y2], |
---|
38 | linestyle='-', marker='', |
---|
39 | color=self.color, |
---|
40 | visible=True)[0] |
---|
41 | |
---|
42 | self.npts = 20 |
---|
43 | |
---|
44 | self.connect_markers([self.line]) |
---|
45 | self.update() |
---|
46 | |
---|
47 | |
---|
48 | def set_layer(self, n): |
---|
49 | self.layernum = n |
---|
50 | self.update() |
---|
51 | |
---|
52 | def clear(self): |
---|
53 | self.clear_markers() |
---|
54 | try: |
---|
55 | self.line.remove() |
---|
56 | |
---|
57 | except: |
---|
58 | # Old version of matplotlib |
---|
59 | for item in range(len(self.axes.lines)): |
---|
60 | del self.axes.lines[0] |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | def get_radius(self): |
---|
65 | return self.theta |
---|
66 | |
---|
67 | def update(self,r1=None, r2=None): |
---|
68 | """ |
---|
69 | Draw the new roughness on the graph. |
---|
70 | """ |
---|
71 | # Plot inner circle |
---|
72 | if r1 !=None: |
---|
73 | self.r1=r1 |
---|
74 | if r2!=None: |
---|
75 | self.r2=r2 |
---|
76 | #print "update line ",self.r1,self.r2 |
---|
77 | #if self.theta <0: |
---|
78 | # self.theta= 2*math.pi + self.theta |
---|
79 | x1= self.r1*math.cos(self.theta) |
---|
80 | y1= self.r1*math.sin(self.theta) |
---|
81 | x2= self.r2*math.cos(self.theta) |
---|
82 | y2= self.r2*math.sin(self.theta) |
---|
83 | |
---|
84 | self.line.set(xdata=[x1,x2], ydata=[y1,y2]) |
---|
85 | return 1 |
---|
86 | |
---|
87 | def save(self, ev): |
---|
88 | """ |
---|
89 | Remember the roughness for this layer and the next so that we |
---|
90 | can restore on Esc. |
---|
91 | """ |
---|
92 | self.save_theta= self.theta |
---|
93 | self.base.freeze_axes() |
---|
94 | |
---|
95 | def moveend(self, ev): |
---|
96 | self.base.moveend(ev) |
---|
97 | |
---|
98 | def restore(self): |
---|
99 | """ |
---|
100 | Restore the roughness for this layer. |
---|
101 | """ |
---|
102 | self.theta = self.save_theta |
---|
103 | |
---|
104 | def move(self, x, y, ev): |
---|
105 | """ |
---|
106 | Process move to a new position, making sure that the move is allowed. |
---|
107 | """ |
---|
108 | self.theta= math.atan2(y,x) |
---|
109 | |
---|
110 | |
---|
111 | self.base.base.update() |
---|
112 | |
---|
113 | def set_cursor(self, x, y): |
---|
114 | self.move(x, y, None) |
---|
115 | self.update() |
---|
116 | |
---|
117 | |
---|
118 | def get_params(self): |
---|
119 | params = {} |
---|
120 | params["radius1"] = self.r1 |
---|
121 | params["radius2"] = self.r2 |
---|
122 | return params |
---|
123 | |
---|
124 | def set_params(self, params): |
---|
125 | |
---|
126 | x1 = params["radius1"] |
---|
127 | x2 = params["radius2"] |
---|
128 | self.set_cursor(x, self._inner_mouse_y) |
---|
129 | |
---|
130 | |
---|