[2d107b8] | 1 | #TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it |
---|
| 2 | # before pushing a new 1D data update. |
---|
| 3 | |
---|
| 4 | # |
---|
| 5 | #TODO: NEED MAJOR REFACTOR |
---|
| 6 | # |
---|
| 7 | |
---|
| 8 | |
---|
| 9 | # Debug printout |
---|
[38224f10] | 10 | #from config import printEVT |
---|
[2d107b8] | 11 | from BaseInteractor import _BaseInteractor |
---|
| 12 | from copy import deepcopy |
---|
| 13 | import math |
---|
| 14 | |
---|
[38224f10] | 15 | #from Plotter1D import AddPlotEvent |
---|
[2d107b8] | 16 | import SlicerParameters |
---|
| 17 | import wx |
---|
| 18 | |
---|
[38224f10] | 19 | class BoxInteractor(_BaseInteractor): |
---|
[2d107b8] | 20 | """ |
---|
| 21 | Select an annulus through a 2D plot |
---|
| 22 | """ |
---|
[c73d871] | 23 | def __init__(self,base,axes,color='black', zorder=3, |
---|
| 24 | x_min=0.0025, x_max=0.0025, y_min=0.0025, y_max=0.0025): |
---|
[2d107b8] | 25 | |
---|
| 26 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 27 | self.markers = [] |
---|
| 28 | self.axes = axes |
---|
| 29 | self.qmax = self.base.qmax |
---|
| 30 | self.connect = self.base.connect |
---|
[8ff3ec1] | 31 | self.xmin= -1* x_min |
---|
| 32 | self.ymin= -1* y_min |
---|
[b6b1669] | 33 | |
---|
[8ff3ec1] | 34 | self.xmax= x_max |
---|
| 35 | self.ymax= y_max |
---|
| 36 | |
---|
[b6b1669] | 37 | self.theta2= math.pi/4 |
---|
[2d107b8] | 38 | ## Number of points on the plot |
---|
| 39 | self.nbins = 20 |
---|
[38224f10] | 40 | self.count=0 |
---|
| 41 | self.error=0 |
---|
[c73d871] | 42 | self.main_line = LineInteractor(self, self.base.subplot,color='orange', |
---|
[030873e] | 43 | zorder=zorder, ymin=y_min ,ymax=y_max, |
---|
[8ff3ec1] | 44 | theta= self.theta2) |
---|
| 45 | self.main_line.qmax = self.base.qmax |
---|
| 46 | |
---|
[c73d871] | 47 | self.left_line = VerticalLine(self, self.base.subplot,color='blue', |
---|
| 48 | zorder=zorder, |
---|
| 49 | mline= self.main_line, |
---|
| 50 | ymin= self.ymin , |
---|
| 51 | ymax= self.ymax , |
---|
| 52 | xmin=self.xmin, |
---|
| 53 | xmax=self.xmin, |
---|
[8ff3ec1] | 54 | theta2= self.theta2) |
---|
[2d107b8] | 55 | self.left_line.qmax = self.base.qmax |
---|
| 56 | |
---|
[c73d871] | 57 | self.right_line= VerticalLine(self, self.base.subplot,color='black', |
---|
| 58 | zorder=zorder, |
---|
| 59 | mline= self.main_line, |
---|
| 60 | ymin= self.ymin , |
---|
| 61 | ymax= self.ymax, |
---|
| 62 | xmin= self.xmax, |
---|
| 63 | xmax= self.xmax, |
---|
| 64 | theta2= self.theta2) |
---|
[2d107b8] | 65 | self.right_line.qmax = self.base.qmax |
---|
| 66 | |
---|
[c73d871] | 67 | self.top_line= HorizontalLine(self, self.base.subplot,color='green', |
---|
| 68 | zorder=zorder, |
---|
[030873e] | 69 | mline= self.main_line, |
---|
| 70 | xmin=self.right_line.x1, |
---|
| 71 | xmax=self.left_line.x1, |
---|
| 72 | ymin=self.right_line.y1, |
---|
| 73 | ymax=self.left_line.y1) |
---|
| 74 | self.top_line.qmax= self.base.qmax |
---|
| 75 | |
---|
| 76 | self.bottom_line= HorizontalLine(self, self.base.subplot,color='grey', |
---|
| 77 | zorder=zorder, |
---|
| 78 | mline= self.main_line, |
---|
| 79 | xmin=self.right_line.x2, |
---|
| 80 | xmax=self.left_line.x2, |
---|
| 81 | ymin=self.right_line.y2, |
---|
| 82 | ymax=self.left_line.y2) |
---|
| 83 | self.bottom_line.qmax= self.base.qmax |
---|
[38224f10] | 84 | self.update() |
---|
| 85 | #self._post_data() |
---|
[2d107b8] | 86 | |
---|
| 87 | # Bind to slice parameter events |
---|
| 88 | self.base.parent.Bind(SlicerParameters.EVT_SLICER_PARS, self._onEVT_SLICER_PARS) |
---|
| 89 | |
---|
| 90 | |
---|
| 91 | def _onEVT_SLICER_PARS(self, event): |
---|
[38224f10] | 92 | #printEVT("AnnulusSlicer._onEVT_SLICER_PARS") |
---|
[2d107b8] | 93 | event.Skip() |
---|
| 94 | if event.type == self.__class__.__name__: |
---|
| 95 | #self.set_params(event.params) |
---|
| 96 | self.base.update() |
---|
| 97 | |
---|
| 98 | def update_and_post(self): |
---|
| 99 | self.update() |
---|
| 100 | self._post_data() |
---|
| 101 | |
---|
| 102 | def save_data(self, path, image, x, y): |
---|
| 103 | output = open(path, 'w') |
---|
| 104 | |
---|
| 105 | data_x, data_y = self.get_data(image, x, y) |
---|
| 106 | |
---|
| 107 | output.write("<phi> <average>\n") |
---|
| 108 | for i in range(len(data_x)): |
---|
| 109 | output.write("%g %g\n" % (data_x[i], data_y[i])) |
---|
| 110 | output.close() |
---|
| 111 | |
---|
| 112 | def set_layer(self, n): |
---|
| 113 | self.layernum = n |
---|
| 114 | self.update() |
---|
| 115 | |
---|
| 116 | def clear(self): |
---|
| 117 | self.clear_markers() |
---|
[38224f10] | 118 | self.left_line.clear() |
---|
| 119 | self.right_line.clear() |
---|
[030873e] | 120 | self.top_line.clear() |
---|
| 121 | self.bottom_line.clear() |
---|
[8ff3ec1] | 122 | self.main_line.clear() |
---|
[2d107b8] | 123 | #self.base.connect.disconnect() |
---|
| 124 | self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) |
---|
| 125 | |
---|
| 126 | def update(self): |
---|
| 127 | """ |
---|
| 128 | Respond to changes in the model by recalculating the profiles and |
---|
| 129 | resetting the widgets. |
---|
| 130 | """ |
---|
[8ff3ec1] | 131 | |
---|
| 132 | if self.main_line.has_move: |
---|
[c73d871] | 133 | |
---|
[8ff3ec1] | 134 | self.main_line.update() |
---|
[d5a792a] | 135 | self.left_line.update( |
---|
[c73d871] | 136 | xmin= self.xmin, |
---|
| 137 | xmax= self.xmin, |
---|
| 138 | ymin= self.ymin, |
---|
| 139 | ymax=self.ymax, |
---|
| 140 | translation=True) |
---|
[d5a792a] | 141 | self.right_line.update( |
---|
[c73d871] | 142 | xmin= self.xmax, |
---|
| 143 | xmax= self.xmax, |
---|
| 144 | ymin= self.ymin, |
---|
| 145 | ymax=self.ymax, |
---|
| 146 | translation=True) |
---|
[030873e] | 147 | self.top_line.update(xmin= self.right_line.x1, |
---|
| 148 | xmax= self.left_line.x1, |
---|
| 149 | ymin= self.right_line.y1, |
---|
| 150 | ymax= self.left_line.y1) |
---|
| 151 | self.bottom_line.update(xmin= self.right_line.x2, |
---|
| 152 | xmax= self.left_line.x2, |
---|
| 153 | ymin= self.right_line.y2, |
---|
| 154 | ymax= self.left_line.y2) |
---|
[2d107b8] | 155 | if self.left_line.has_move: |
---|
| 156 | print "left has moved" |
---|
[d5a792a] | 157 | self.left_line.update() |
---|
| 158 | self.right_line.update(opline= self.left_line ) |
---|
[030873e] | 159 | |
---|
| 160 | self.top_line.update(xmin= self.right_line.x2, |
---|
| 161 | xmax= self.left_line.x1, |
---|
| 162 | ymin= self.right_line.y2, |
---|
| 163 | ymax= self.left_line.y1) |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | self.bottom_line.update(xmin= self.right_line.x1, |
---|
| 167 | xmax= self.left_line.x2, |
---|
| 168 | ymin= self.right_line.y1, |
---|
| 169 | ymax= self.left_line.y2) |
---|
| 170 | |
---|
[2d107b8] | 171 | if self.right_line.has_move: |
---|
| 172 | print "right has moved" |
---|
[d5a792a] | 173 | self.right_line.update() |
---|
| 174 | self.left_line.update(opline= self.right_line ) |
---|
[2d107b8] | 175 | |
---|
[030873e] | 176 | self.top_line.update(xmin= self.right_line.x1, |
---|
| 177 | xmax= self.left_line.x2, |
---|
| 178 | ymin= self.right_line.y1, |
---|
| 179 | ymax= self.left_line.y2) |
---|
[2d107b8] | 180 | |
---|
[030873e] | 181 | self.bottom_line.update(xmin= self.right_line.x2, |
---|
| 182 | xmax= self.left_line.x1, |
---|
| 183 | ymin= self.right_line.y2, |
---|
| 184 | ymax= self.left_line.y1) |
---|
[2d107b8] | 185 | if self.top_line.has_move: |
---|
[030873e] | 186 | self.top_line.update(translation=True) |
---|
[2d107b8] | 187 | def save(self, ev): |
---|
| 188 | """ |
---|
| 189 | Remember the roughness for this layer and the next so that we |
---|
| 190 | can restore on Esc. |
---|
| 191 | """ |
---|
| 192 | self.base.freeze_axes() |
---|
| 193 | self.inner_circle.save(ev) |
---|
| 194 | self.outer_circle.save(ev) |
---|
| 195 | |
---|
| 196 | def _post_data(self): |
---|
| 197 | # Compute data |
---|
[d054809] | 198 | #data = self.base.data2D |
---|
| 199 | #from DataLoader.manipulations import Boxavg |
---|
| 200 | #radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) |
---|
| 201 | #x_min= self.left_line.xmin |
---|
| 202 | #x_max= self.right_line.xmax |
---|
[c73d871] | 203 | #y_min= self.bottom_line.y |
---|
| 204 | #y_max= self.top_line.y |
---|
| 205 | #box = Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) |
---|
[38224f10] | 206 | |
---|
[c73d871] | 207 | #self.count, self.error= box(self.base.data2D) |
---|
[b319def8] | 208 | |
---|
[d054809] | 209 | print "post data" |
---|
[b319def8] | 210 | |
---|
[38224f10] | 211 | |
---|
[2d107b8] | 212 | def moveend(self, ev): |
---|
| 213 | self.base.thaw_axes() |
---|
| 214 | |
---|
| 215 | # Post paramters |
---|
| 216 | event = SlicerParameters.SlicerParameterEvent() |
---|
| 217 | event.type = self.__class__.__name__ |
---|
| 218 | #event.params = self.get_params() |
---|
| 219 | wx.PostEvent(self.base.parent, event) |
---|
| 220 | |
---|
| 221 | self._post_data() |
---|
| 222 | |
---|
| 223 | def restore(self): |
---|
| 224 | """ |
---|
| 225 | Restore the roughness for this layer. |
---|
| 226 | """ |
---|
| 227 | self.inner_circle.restore() |
---|
| 228 | self.outer_circle.restore() |
---|
| 229 | |
---|
| 230 | def move(self, x, y, ev): |
---|
| 231 | """ |
---|
| 232 | Process move to a new position, making sure that the move is allowed. |
---|
| 233 | """ |
---|
| 234 | pass |
---|
| 235 | |
---|
| 236 | def set_cursor(self, x, y): |
---|
| 237 | pass |
---|
| 238 | |
---|
| 239 | def get_params(self): |
---|
| 240 | params = {} |
---|
[c73d871] | 241 | params["x_min"] = self.left_line.L_width |
---|
| 242 | params["x_max"] = self.right_line.R_width |
---|
| 243 | #params["y_min"] = self.bottom_line.y |
---|
| 244 | #params["y_max"] = self.top_line.y |
---|
[38224f10] | 245 | params["count"] = self.count |
---|
| 246 | params["error"] = self.error |
---|
[8ff3ec1] | 247 | params["phi"] = self.main_line.theta |
---|
[2d107b8] | 248 | return params |
---|
| 249 | |
---|
| 250 | def set_params(self, params): |
---|
| 251 | |
---|
[38224f10] | 252 | x_min = params["x_min"] |
---|
| 253 | x_max = params["x_max"] |
---|
[c73d871] | 254 | #y_min = params["y_min"] |
---|
| 255 | #y_max = params["y_max"] |
---|
[8ff3ec1] | 256 | theta = params["theta"] |
---|
[2d107b8] | 257 | |
---|
[38224f10] | 258 | self.left_line.update(ymin= y_min ,ymax= y_max) |
---|
| 259 | self.right_line.update(ymin= y_min ,ymax= y_max) |
---|
[c73d871] | 260 | #self.top_line.update( xmin= x_min ,xmax= xmax) |
---|
| 261 | #self.bottom_line.update(xmin= xmin ,xmax= xmax) |
---|
[8ff3ec1] | 262 | self.main_line.update(theta) |
---|
| 263 | |
---|
[38224f10] | 264 | self._post_data() |
---|
[2d107b8] | 265 | def freeze_axes(self): |
---|
| 266 | self.base.freeze_axes() |
---|
| 267 | |
---|
| 268 | def thaw_axes(self): |
---|
| 269 | self.base.thaw_axes() |
---|
| 270 | |
---|
| 271 | def draw(self): |
---|
| 272 | self.base.draw() |
---|
| 273 | |
---|
| 274 | class HorizontalLine(_BaseInteractor): |
---|
| 275 | """ |
---|
| 276 | Select an annulus through a 2D plot |
---|
| 277 | """ |
---|
[030873e] | 278 | def __init__(self,base,axes,color='black', zorder=5,mline=None,ymin=None, ymax=None, y=0.5, |
---|
[8ff3ec1] | 279 | xmin=0.0,xmax=0.5, |
---|
| 280 | theta2= math.pi/3 ): |
---|
[2d107b8] | 281 | |
---|
| 282 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 283 | self.markers = [] |
---|
| 284 | self.axes = axes |
---|
| 285 | |
---|
[030873e] | 286 | self.ymin= ymin |
---|
| 287 | self.save_ymin = ymin |
---|
| 288 | self.mline = mline |
---|
| 289 | self.ymax= ymax |
---|
| 290 | self.save_ymax = ymax |
---|
[7ab9241] | 291 | self.xmin = xmin |
---|
| 292 | self.save_xmin = xmin |
---|
| 293 | self.xmax = xmax |
---|
| 294 | self.save_xmax = xmax |
---|
[030873e] | 295 | self.top_hight= self.ymax |
---|
[8ff3ec1] | 296 | |
---|
[78ed1ad] | 297 | self.theta2 = theta2 |
---|
[8ff3ec1] | 298 | |
---|
[030873e] | 299 | self.line = self.axes.plot([self.xmax,self.xmin], |
---|
| 300 | [self.ymax,self.ymin], |
---|
[2d107b8] | 301 | linestyle='-', marker='', |
---|
| 302 | color=self.color, |
---|
| 303 | visible=True)[0] |
---|
[8ff3ec1] | 304 | |
---|
[c73d871] | 305 | |
---|
| 306 | |
---|
[2d107b8] | 307 | self.npts = 20 |
---|
| 308 | self.has_move=False |
---|
| 309 | self.connect_markers([self.line]) |
---|
[030873e] | 310 | self.update(xmin= self.xmin, |
---|
| 311 | xmax= self.xmax, |
---|
| 312 | ymin= self.ymin, |
---|
| 313 | ymax= self.ymax) |
---|
[2d107b8] | 314 | |
---|
| 315 | def set_layer(self, n): |
---|
| 316 | self.layernum = n |
---|
| 317 | self.update() |
---|
| 318 | |
---|
| 319 | def clear(self): |
---|
| 320 | self.clear_markers() |
---|
| 321 | try: |
---|
| 322 | |
---|
| 323 | self.line.remove() |
---|
| 324 | except: |
---|
| 325 | # Old version of matplotlib |
---|
| 326 | for item in range(len(self.axes.lines)): |
---|
| 327 | del self.axes.lines[0] |
---|
[030873e] | 328 | |
---|
[2d107b8] | 329 | def get_radius(self): |
---|
| 330 | |
---|
| 331 | return 0 |
---|
[8ff3ec1] | 332 | |
---|
[b6b1669] | 333 | def update(self,xmin=None, xmax=None,ymin=None,ymax=None, mline=None,translation=False): |
---|
[2d107b8] | 334 | """ |
---|
| 335 | Draw the new roughness on the graph. |
---|
| 336 | """ |
---|
[b6b1669] | 337 | if translation : |
---|
[030873e] | 338 | print "translation ",self.top_hight |
---|
| 339 | self.x1= self.xmax + self.top_hight*math.sin(math.pi/2 + self.mline.theta) |
---|
| 340 | self.x2= self.xmin + self.top_hight*math.sin(math.pi/2 + self.mline.theta) |
---|
| 341 | self.y1= self.ymin - self.top_hight*math.cos(math.pi/2 + self.mline.theta) |
---|
| 342 | self.y2= self.ymax -self.top_hight*math.cos(math.pi/2 + self.mline.theta) |
---|
| 343 | self.line.set(xdata=[self.x1,self.x2], |
---|
| 344 | ydata=[self.y1,self.y2]) |
---|
| 345 | return |
---|
| 346 | #print "update main line", self.has_move |
---|
| 347 | self.xmin=xmin |
---|
| 348 | self.xmax=xmax |
---|
| 349 | self.ymin=ymin |
---|
| 350 | self.ymax=ymax |
---|
| 351 | self.line.set(xdata=[self.xmin,self.xmax], |
---|
| 352 | ydata=[self.ymin,self.ymax]) |
---|
| 353 | |
---|
[2d107b8] | 354 | |
---|
| 355 | |
---|
| 356 | def save(self, ev): |
---|
| 357 | """ |
---|
| 358 | Remember the roughness for this layer and the next so that we |
---|
| 359 | can restore on Esc. |
---|
| 360 | """ |
---|
| 361 | self.save_xmin= self.xmin |
---|
| 362 | self.save_xmax= self.xmax |
---|
| 363 | |
---|
[030873e] | 364 | self.save_ymin= self.ymin |
---|
| 365 | self.save_ymax= self.ymax |
---|
| 366 | self.top_hight= self.ymax |
---|
[2d107b8] | 367 | self.base.freeze_axes() |
---|
| 368 | |
---|
| 369 | def moveend(self, ev): |
---|
[030873e] | 370 | |
---|
[2d107b8] | 371 | self.has_move=False |
---|
| 372 | self.base.moveend(ev) |
---|
| 373 | |
---|
| 374 | def restore(self): |
---|
| 375 | """ |
---|
| 376 | Restore the roughness for this layer. |
---|
| 377 | """ |
---|
[030873e] | 378 | self.xmin = self.save_xmin |
---|
| 379 | self.xmax = self.save_xmax |
---|
[2d107b8] | 380 | self.ymin = self.save_ymin |
---|
| 381 | self.ymax = self.save_ymax |
---|
| 382 | |
---|
| 383 | def move(self, x, y, ev): |
---|
| 384 | """ |
---|
| 385 | Process move to a new position, making sure that the move is allowed. |
---|
| 386 | """ |
---|
| 387 | |
---|
[030873e] | 388 | self.top_hight= y |
---|
[2d107b8] | 389 | self.has_move=True |
---|
| 390 | self.base.base.update() |
---|
| 391 | |
---|
| 392 | def set_cursor(self, x, y): |
---|
| 393 | self.move(x, y, None) |
---|
| 394 | self.update() |
---|
| 395 | |
---|
| 396 | |
---|
| 397 | def get_params(self): |
---|
| 398 | params = {} |
---|
| 399 | params["radius"] = self.xmin |
---|
| 400 | params["theta"] = self.xmax |
---|
| 401 | return params |
---|
| 402 | |
---|
| 403 | def set_params(self, params): |
---|
| 404 | |
---|
| 405 | x = params["radius"] |
---|
| 406 | self.set_cursor(x, self._inner_mouse_y) |
---|
| 407 | |
---|
| 408 | |
---|
| 409 | |
---|
| 410 | |
---|
| 411 | class VerticalLine(_BaseInteractor): |
---|
| 412 | """ |
---|
| 413 | Select an annulus through a 2D plot |
---|
| 414 | """ |
---|
[c73d871] | 415 | def __init__(self,base,axes,color='black', zorder=5, mline=None, ymin=0.0, |
---|
| 416 | ymax=0.5,xmin=-0.5,xmax=0.5, |
---|
[8ff3ec1] | 417 | theta2= math.pi/3 ): |
---|
[2d107b8] | 418 | |
---|
| 419 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 420 | self.markers = [] |
---|
| 421 | self.axes = axes |
---|
[030873e] | 422 | |
---|
[c73d871] | 423 | self.L_width=xmin |
---|
[030873e] | 424 | self.save_L_width=xmin |
---|
| 425 | |
---|
[c73d871] | 426 | self.save_xmin= xmin |
---|
| 427 | self.R_width=xmax |
---|
| 428 | self.save_xmax=xmax |
---|
| 429 | self.ymin=ymin |
---|
| 430 | self.save_ymin= ymin |
---|
[2d107b8] | 431 | self.ymax=ymax |
---|
[c73d871] | 432 | self.save_ymax= ymax |
---|
[030873e] | 433 | |
---|
[8ff3ec1] | 434 | self.theta2= theta2 |
---|
| 435 | |
---|
[030873e] | 436 | self.mline= mline |
---|
| 437 | |
---|
[c73d871] | 438 | self.detax=0 |
---|
| 439 | self.deltay=0 |
---|
[b6b1669] | 440 | |
---|
[d5a792a] | 441 | |
---|
[c73d871] | 442 | self.clickxf=0 |
---|
| 443 | self.clickyf=0 |
---|
| 444 | self.x1= mline.x1 + xmin*math.cos(math.pi/2 - self.theta2) |
---|
| 445 | self.x2= mline.x2 + xmin*math.cos(math.pi/2 - self.theta2) |
---|
| 446 | self.y1= mline.y1 - xmin*math.sin(math.pi/2 - self.theta2) |
---|
| 447 | self.y2= mline.y2 - xmin*math.sin(math.pi/2 - self.theta2) |
---|
[b6b1669] | 448 | |
---|
[c73d871] | 449 | self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2], |
---|
[2d107b8] | 450 | linestyle='-', marker='', |
---|
| 451 | color=self.color, |
---|
| 452 | visible=True)[0] |
---|
| 453 | |
---|
| 454 | self.npts = 20 |
---|
[8ff3ec1] | 455 | # Check vertical line motion |
---|
[2d107b8] | 456 | self.has_move=False |
---|
| 457 | self.connect_markers([self.line]) |
---|
| 458 | self.update() |
---|
| 459 | |
---|
| 460 | def set_layer(self, n): |
---|
| 461 | self.layernum = n |
---|
| 462 | self.update() |
---|
| 463 | |
---|
| 464 | def clear(self): |
---|
| 465 | self.clear_markers() |
---|
| 466 | try: |
---|
| 467 | |
---|
| 468 | self.line.remove() |
---|
| 469 | except: |
---|
| 470 | # Old version of matplotlib |
---|
| 471 | for item in range(len(self.axes.lines)): |
---|
| 472 | del self.axes.lines[0] |
---|
[c73d871] | 473 | |
---|
| 474 | |
---|
[2d107b8] | 475 | def get_radius(self): |
---|
| 476 | return 0 |
---|
[8ff3ec1] | 477 | |
---|
[d5a792a] | 478 | def update(self,xmin=None,xmax=None,ymin=None, ymax=None, opline=None,translation=False): |
---|
[2d107b8] | 479 | """ |
---|
| 480 | Draw the new roughness on the graph. |
---|
| 481 | """ |
---|
[d5a792a] | 482 | if opline !=None: |
---|
[030873e] | 483 | self.x1= -1*opline.x1 |
---|
| 484 | self.x2= -1*opline.x2 |
---|
| 485 | self.y1= -1*opline.y1 |
---|
| 486 | self.y2= -1*opline.y2 |
---|
| 487 | self.line.set(xdata=[self.x1,self.x2], |
---|
| 488 | ydata=[self.y1,self.y2]) |
---|
[d5a792a] | 489 | return |
---|
[c73d871] | 490 | if xmin== None: |
---|
| 491 | xmin= self.L_width |
---|
| 492 | if xmax== None: |
---|
| 493 | xmax= self.R_width |
---|
[030873e] | 494 | #print "vertical line: xmin, xmax , ymin , ymax", xmin, self.mline.theta |
---|
[c73d871] | 495 | self.x1= self.mline.x1 + xmin*math.cos(math.pi/2 - self.mline.theta) |
---|
| 496 | self.x2= self.mline.x2 + xmin*math.cos(math.pi/2 - self.mline.theta) |
---|
| 497 | self.y1= self.mline.y1 - xmin*math.sin(math.pi/2 - self.mline.theta) |
---|
| 498 | self.y2= self.mline.y2 - xmin*math.sin(math.pi/2 - self.mline.theta) |
---|
[030873e] | 499 | #print "vertical line: main line value ", self.mline.x1, self.mline.x2, self.mline.y1,self.mline.y2 |
---|
| 500 | #print "vertical line: new value ", self.x1, self.x2, self.y1,self.y2 |
---|
[b6b1669] | 501 | |
---|
[c73d871] | 502 | self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) |
---|
[d5a792a] | 503 | if opline !=None: |
---|
| 504 | self.line.set(xdata=[-1*self.opline.x1,-1*self.opline.x2], |
---|
| 505 | ydata=[self.opline.y1,self.opline.y2]) |
---|
| 506 | return |
---|
[c73d871] | 507 | if translation: |
---|
[030873e] | 508 | print "xmin L_width", xmin, self.L_width |
---|
[d5a792a] | 509 | self.x1= self.mline.x1 + self.L_width*math.cos(math.pi/2 - self.mline.theta) |
---|
| 510 | self.x2= self.mline.x2 + self.L_width*math.cos(math.pi/2 - self.mline.theta) |
---|
| 511 | self.y1= self.mline.y1 - self.L_width*math.sin(math.pi/2 - self.mline.theta) |
---|
| 512 | self.y2= self.mline.y2 - self.L_width*math.sin(math.pi/2 - self.mline.theta) |
---|
| 513 | |
---|
| 514 | print"translation x1, x2,y1,y2",self.x1, self.x2,self.y1,self.y2 |
---|
[c73d871] | 515 | self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) |
---|
[030873e] | 516 | |
---|
| 517 | |
---|
[2d107b8] | 518 | def save(self, ev): |
---|
| 519 | """ |
---|
| 520 | Remember the roughness for this layer and the next so that we |
---|
| 521 | can restore on Esc. |
---|
| 522 | """ |
---|
[030873e] | 523 | self.save_L_width= self.L_width |
---|
[d054809] | 524 | self.save_xmin= self.x1 |
---|
| 525 | self.save_xmax= self.x2 |
---|
| 526 | self.save_ymin= self.y1 |
---|
| 527 | self.save_ymax= self.y2 |
---|
[8ff3ec1] | 528 | |
---|
[2d107b8] | 529 | self.base.freeze_axes() |
---|
| 530 | |
---|
| 531 | def moveend(self, ev): |
---|
[030873e] | 532 | |
---|
[2d107b8] | 533 | self.has_move=False |
---|
| 534 | self.base.moveend(ev) |
---|
| 535 | |
---|
| 536 | def restore(self): |
---|
| 537 | """ |
---|
| 538 | Restore the roughness for this layer. |
---|
| 539 | """ |
---|
[78ed1ad] | 540 | self.xmin = self.save_xmin |
---|
| 541 | self.xmax = self.save_xmax |
---|
[d5a792a] | 542 | self.ymin = self.save_ymin |
---|
| 543 | self.ymax = self.save_ymax |
---|
[030873e] | 544 | self.L_width= self.save_L_width |
---|
[78ed1ad] | 545 | |
---|
[2d107b8] | 546 | def move(self, x, y, ev): |
---|
| 547 | """ |
---|
| 548 | Process move to a new position, making sure that the move is allowed. |
---|
| 549 | """ |
---|
[8ff3ec1] | 550 | self.has_move=True |
---|
[030873e] | 551 | self.L_width = x |
---|
| 552 | print "move L_width", self.L_width |
---|
[8ff3ec1] | 553 | self.base.base.update() |
---|
| 554 | |
---|
| 555 | |
---|
| 556 | def set_cursor(self, x, y): |
---|
| 557 | self.move(x, y, None) |
---|
| 558 | self.update() |
---|
| 559 | |
---|
| 560 | |
---|
| 561 | def get_params(self): |
---|
| 562 | params = {} |
---|
| 563 | params["x"] = self.xmin |
---|
| 564 | params["ymin"] = self.ymin |
---|
| 565 | params["ymax"] = self.ymax |
---|
| 566 | return params |
---|
| 567 | |
---|
| 568 | def set_params(self, params): |
---|
| 569 | """ |
---|
| 570 | Draw a vertical line given some value of params |
---|
| 571 | @param params: a dictionary containing value for x, ymin , ymax to draw |
---|
| 572 | a vertical line |
---|
| 573 | """ |
---|
| 574 | x = params["x"] |
---|
| 575 | ymin = params["ymin"] |
---|
| 576 | ymax = params["ymax"] |
---|
| 577 | #self.set_cursor(x, self._inner_mouse_y) |
---|
| 578 | self.update(self,x =x,ymin =ymin, ymax =ymax) |
---|
[2d107b8] | 579 | |
---|
[8ff3ec1] | 580 | |
---|
| 581 | |
---|
| 582 | class LineInteractor(_BaseInteractor): |
---|
| 583 | """ |
---|
| 584 | Select an annulus through a 2D plot |
---|
| 585 | """ |
---|
[030873e] | 586 | def __init__(self,base,axes,color='black', zorder=5, ymin=1.0,ymax=1.0,theta=math.pi/4): |
---|
[8ff3ec1] | 587 | |
---|
| 588 | _BaseInteractor.__init__(self, base, axes, color=color) |
---|
| 589 | self.markers = [] |
---|
| 590 | self.axes = axes |
---|
[2d107b8] | 591 | |
---|
[8ff3ec1] | 592 | self.save_theta = theta |
---|
| 593 | self.theta= theta |
---|
[2d107b8] | 594 | |
---|
[030873e] | 595 | self.radius1 = ymax |
---|
| 596 | self.radius2 = ymin |
---|
[8ff3ec1] | 597 | self.scale = 10.0 |
---|
| 598 | |
---|
| 599 | # Inner circle |
---|
[030873e] | 600 | self.x1= self.radius1*math.cos(self.theta) |
---|
| 601 | self.y1= self.radius1*math.sin(self.theta) |
---|
| 602 | self.x2= -1*self.radius2*math.cos(self.theta) |
---|
| 603 | self.y2= -1*self.radius2*math.sin(self.theta) |
---|
[8ff3ec1] | 604 | |
---|
[c73d871] | 605 | self.line = self.axes.plot([self.x1,self.x2],[self.y1,self.y2], |
---|
[8ff3ec1] | 606 | linestyle='-', marker='', |
---|
| 607 | color=self.color, |
---|
| 608 | visible=True)[0] |
---|
| 609 | |
---|
| 610 | self.npts = 20 |
---|
| 611 | self.has_move=False |
---|
| 612 | self.connect_markers([self.line]) |
---|
| 613 | self.update() |
---|
| 614 | |
---|
| 615 | def set_layer(self, n): |
---|
| 616 | |
---|
| 617 | self.layernum = n |
---|
| 618 | self.update() |
---|
| 619 | |
---|
| 620 | def clear(self): |
---|
| 621 | """ |
---|
| 622 | Remove the line of the plot |
---|
| 623 | """ |
---|
| 624 | self.clear_markers() |
---|
| 625 | try: |
---|
| 626 | self.line.remove() |
---|
| 627 | except: |
---|
| 628 | # Old version of matplotlib |
---|
| 629 | for item in range(len(self.axes.lines)): |
---|
| 630 | del self.axes.lines[0] |
---|
| 631 | |
---|
| 632 | |
---|
| 633 | |
---|
| 634 | def get_delta_angle(self): |
---|
| 635 | """ |
---|
| 636 | return difference between initial angle and the final angle during |
---|
| 637 | rotation |
---|
| 638 | """ |
---|
| 639 | return self.theta - self.save_theta |
---|
| 640 | |
---|
[030873e] | 641 | def update(self, theta=None,radius1=None,radius2=None): |
---|
[8ff3ec1] | 642 | """ |
---|
| 643 | Draw a line given and angle relative to the x-axis and a radius |
---|
| 644 | @param theta: the angle realtive to the x-axis |
---|
| 645 | @param radius: the distance between the center and one end of the line |
---|
| 646 | """ |
---|
| 647 | |
---|
| 648 | if theta !=None: |
---|
| 649 | self.theta= theta |
---|
[030873e] | 650 | if radius1 !=None: |
---|
| 651 | self.radius1 =radius1 |
---|
| 652 | if radius2 !=None: |
---|
| 653 | self.radius2 =radius2 |
---|
| 654 | print "update main line", math.degrees(self.theta),self.radius1, self.radius2 |
---|
| 655 | self.x1= self.radius1*math.cos(self.theta) |
---|
| 656 | self.y1= self.radius1*math.sin(self.theta) |
---|
| 657 | self.x2= -1*self.radius2*math.cos(self.theta) |
---|
| 658 | self.y2= -1*self.radius2*math.sin(self.theta) |
---|
[8ff3ec1] | 659 | |
---|
[c73d871] | 660 | self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) |
---|
[8ff3ec1] | 661 | |
---|
| 662 | |
---|
| 663 | |
---|
| 664 | def save(self, ev): |
---|
| 665 | """ |
---|
| 666 | Remember the roughness for this layer and the next so that we |
---|
| 667 | can restore on Esc. |
---|
| 668 | """ |
---|
| 669 | self.save_theta= self.theta |
---|
| 670 | self.base.freeze_axes() |
---|
| 671 | |
---|
| 672 | def moveend(self, ev): |
---|
| 673 | |
---|
| 674 | self.has_move=False |
---|
| 675 | self.base.moveend(ev) |
---|
| 676 | |
---|
| 677 | def restore(self): |
---|
| 678 | """ |
---|
| 679 | Restore the roughness for this layer. |
---|
| 680 | """ |
---|
| 681 | self.theta = self.save_theta |
---|
| 682 | |
---|
| 683 | def move(self, x, y, ev): |
---|
| 684 | """ |
---|
| 685 | Process move to a new position, making sure that the move is allowed. |
---|
| 686 | """ |
---|
| 687 | self.theta= math.atan2(y,x) |
---|
| 688 | #print "main_line previous theta --- next theta ",math.degrees(self.save_theta),math.degrees(self.theta) |
---|
[2d107b8] | 689 | self.has_move=True |
---|
| 690 | self.base.base.update() |
---|
| 691 | |
---|
[8ff3ec1] | 692 | |
---|
[2d107b8] | 693 | def set_cursor(self, x, y): |
---|
[8ff3ec1] | 694 | |
---|
[2d107b8] | 695 | self.move(x, y, None) |
---|
| 696 | self.update() |
---|
| 697 | |
---|
| 698 | |
---|
| 699 | def get_params(self): |
---|
[8ff3ec1] | 700 | """ |
---|
| 701 | return params a dictionary containing values of paramters necessary to draw |
---|
| 702 | this line |
---|
| 703 | """ |
---|
[2d107b8] | 704 | params = {} |
---|
[030873e] | 705 | params["ymax"] = self.radius1 |
---|
| 706 | params["ymin"] = self.radius2 |
---|
[8ff3ec1] | 707 | params["theta"] = self.theta |
---|
[2d107b8] | 708 | return params |
---|
| 709 | |
---|
| 710 | def set_params(self, params): |
---|
[8ff3ec1] | 711 | """ |
---|
| 712 | Draw the line given value contains by params |
---|
| 713 | @param params: dictionary containing name of parameters and their values |
---|
| 714 | """ |
---|
[030873e] | 715 | radius1 = params["ymax"] |
---|
| 716 | radius2 = params["ymin"] |
---|
[8ff3ec1] | 717 | theta = params["theta"] |
---|
[030873e] | 718 | self.update(x, theta= theta , radius1 = radius1 ,radius2 = radius2) |
---|
[2d107b8] | 719 | |
---|
| 720 | |
---|
| 721 | |
---|
[8ff3ec1] | 722 | |
---|
[2d107b8] | 723 | |
---|