source: sasview/guiframe/local_perspectives/plotting/Arc.py @ f39511b

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since f39511b was 2d107b8, checked in by Gervaise Alina <gervyh@…>, 16 years ago

small changes circular averaging

  • Property mode set to 100644
File size: 4.7 KB
Line 
1#from config import printEVT
2from BaseInteractor import _BaseInteractor
3from copy import deepcopy
4import math
5
6#from Plotter1D import AddPlotEvent
7import SlicerParameters
8import wx   
9#import radii
10#(FunctionRadiusEvent, EVT_FUNC_RAD) = wx.lib.newevent.NewEvent()     
11class ArcInteractor(_BaseInteractor):
12    """
13         Select an annulus through a 2D plot
14    """
15    def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta1=math.pi/8,
16                 theta2=math.pi/4):
17       
18        _BaseInteractor.__init__(self, base, axes, color=color)
19        self.markers = []
20        self.axes = axes
21        self._inner_mouse_x = r
22        self._inner_mouse_y = 0
23       
24        self._inner_save_x  = r
25        self._inner_save_y  = 0
26       
27        self.scale = 10.0
28       
29        self.theta1=theta1
30        self.theta2=theta2
31     
32        [self.inner_circle] = self.axes.plot([],[],
33                                      linestyle='-', marker='',
34                                      color=self.color)
35        self.npts = 20
36        self.has_move= False   
37        self.connect_markers([self.inner_circle])
38        self.update()
39
40    def set_layer(self, n):
41        self.layernum = n
42        self.update()
43       
44    def clear(self):
45        self.clear_markers()
46        try:
47            self.inner_marker.remove()
48            self.inner_circle.remove()
49        except:
50            # Old version of matplotlib
51            for item in range(len(self.axes.lines)):
52                del self.axes.lines[0]
53       
54       
55       
56    def get_radius(self):
57        radius =math.sqrt(math.pow(self._inner_mouse_x, 2)+math.pow(self._inner_mouse_y, 2))
58        return radius
59       
60    def update(self,theta1=None,theta2=None):
61        """
62        Draw the new roughness on the graph.
63        """
64        # Plot inner circle
65        x = []
66        y = []
67        if theta1 !=None:
68            self.theta1= theta1
69        if theta2 !=None:
70            self.theta2= theta2
71        #print "ring update theta1 theta2", self.theta1, self.theta2
72        while self.theta2 < self.theta1: self.theta2 += 2*math.pi
73        npts = int((self.theta2 - self.theta1)/(math.pi/120))
74        for i in range(self.npts):
75           
76            phi =(self.theta2-self.theta1)/(self.npts-1)*i +self.theta1
77            #delta= phi1-phi
78            r=  math.sqrt(math.pow(self._inner_mouse_x, 2)+math.pow(self._inner_mouse_y, 2))
79            xval = 1.0*r*math.cos(phi) 
80            yval = 1.0*r*math.sin(phi) 
81            #xval = 1.0*self._inner_mouse_x*math.cos(phi)
82            #yval = 1.0*self._inner_mouse_x*math.sin(phi)
83         
84           
85            x.append(xval)
86            y.append(yval)
87       
88        #self.inner_marker.set(xdata=[self._inner_mouse_x],ydata=[0])
89        self.inner_circle.set_data(x, y) 
90       
91       
92        if self._inner_mouse_x <0:
93            self._inner_mouse_x= 0
94            self._inner_mouse_y= 0
95        r=  math.sqrt(math.pow(self._inner_mouse_x, 2)+math.pow(self._inner_mouse_y, 2))
96        x1=  r*math.cos(self.theta1)
97        y1= r*math.sin(self.theta1)
98        #x1= self._inner_mouse_x*math.cos(self.theta1)
99        #y1= self._inner_mouse_x*math.sin(self.theta1)
100        #x2= r2*math.cos(self.theta1)
101        #y2= r2*math.sin(self.theta1)
102       
103           
104       
105    def save(self, ev):
106        """
107        Remember the roughness for this layer and the next so that we
108        can restore on Esc.
109        """
110        #self._inner_save_x = self._inner_mouse_x
111        #self._inner_save_y = self._inner_mouse_y
112        self._inner_save_x = self._inner_mouse_x
113        self._inner_save_y = self._inner_mouse_y
114        self.base.freeze_axes()
115
116    def moveend(self, ev):
117        self.has_move= False
118        self.base.moveend(ev)
119           
120    def restore(self):
121        """
122        Restore the roughness for this layer.
123        """
124        self._inner_mouse_x = self._inner_save_x
125        self._inner_mouse_y = self._inner_save_y
126       
127    def move(self, x, y, ev):
128        """
129        Process move to a new position, making sure that the move is allowed.
130        """
131        #print "ring move x, y", x,y
132        self._inner_mouse_x = x
133        self._inner_mouse_y = y
134        self.has_move= True
135        self.base.base.update()
136       
137    def set_cursor(self, x, y):
138        self.move(x, y, None)
139        self.update()
140       
141       
142    def get_params(self):
143        params = {}
144        params["radius"] = self._inner_mouse_x
145        return params
146   
147    def set_params(self, params):
148
149        x = params["radius"] 
150        self.set_cursor(x, self._inner_mouse_y)
151       
152   
Note: See TracBrowser for help on using the repository browser.