Changeset dd40217 in sasview for guiframe/local_perspectives
- Timestamp:
- Jan 9, 2009 3:45:30 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 9b05b2f
- Parents:
- 3554b99a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/boxSlicer.py
r3554b99a rdd40217 25 25 @note 1st line equation is y= a1*x +b1 ; 2nd line equation is y= a2*x +b2 26 26 """ 27 x= ( b2- b1) /(a1- a 1)27 x= ( b2- b1) /(a1- a2) 28 28 y= ( -a2*b1 + a1*b2 )/(a1 -a2) 29 29 return x, y … … 64 64 theta2= self.theta2) 65 65 self.left_line.qmax = self.base.qmax 66 67 self.right_line= VerticalLine(self, self.base.subplot,color='black', 68 zorder=zorder, 69 mline= self.main_line, 70 ymin= self.ymin , 71 ymax= self.ymax, 72 xmin= self.xmax, 73 xmax= self.xmax, 74 theta2= self.theta2) 75 self.right_line.qmax = self.base.qmax 76 77 self.top_line= HorizontalLine(self, self.base.subplot,color='green', 78 zorder=zorder, 79 mline= self.main_line, 80 xmin=self.right_line.x1, 81 xmax=self.left_line.x1, 82 ymin=self.right_line.y1, 83 ymax=self.left_line.y1) 84 self.top_line.qmax= self.base.qmax 85 86 self.bottom_line= HorizontalLine(self, self.base.subplot,color='gray', 87 zorder=zorder, 88 mline= self.main_line, 89 xmin=self.right_line.x2, 90 xmax=self.left_line.x2, 91 ymin=self.right_line.y2, 92 ymax=self.left_line.y2) 93 self.bottom_line.qmax= self.base.qmax 94 66 95 self.update() 67 96 #self._post_data() … … 117 146 xmax= self.xmin, 118 147 ymin= self.ymin, 119 ymax=self.ymax, 120 translation=True) 121 148 ymax=self.ymax 149 ) 150 self.right_line.update( 151 xmin= self.xmax, 152 xmax= self.xmax, 153 ymin= self.ymin, 154 ymax=self.ymax) 155 self.top_line.update(xmin= self.right_line.x1, 156 xmax= self.left_line.x1, 157 ymin= self.right_line.y1, 158 ymax= self.left_line.y1) 159 self.bottom_line.update(xmin= self.right_line.x2, 160 xmax= self.left_line.x2, 161 ymin= self.right_line.y2, 162 ymax= self.left_line.y2) 163 if self.top_line.has_move: 164 print "top has moved",self.left_line.slope, self.top_line.slope 165 x2, y2= find_intersection(a1= self.left_line.slope, 166 a2= self.top_line.slope, 167 b1= self.left_line.b, 168 b2= self.top_line.b ) 169 print "x, y max: ",x2,y2 170 x1, y1= find_intersection(a1= self.right_line.slope, 171 a2= self.top_line.slope, 172 b1= self.right_line.b, 173 b2= self.top_line.b ) 174 print "x, y min: ",x1 ,y1 175 self.top_line.update(xmin= x2, 176 ymin= y2, 177 xmax= x1, 178 ymax= y1) 179 180 self.bottom_line.update(xmin= -x2, 181 ymin= -y2, 182 xmax= -x1, 183 ymax= -y1) 184 self.left_line.update(xmin= -x1, 185 ymin= -y1, 186 xmax= x2, 187 ymax= y2, 188 translation= True) 189 self.right_line.update( 190 xmin= -x2, 191 ymin= -y2, 192 xmax= x1, 193 ymax= y1, 194 translation= True) 195 print "top has moved",self.left_line.slope, self.top_line.slope 196 x2, y2= find_intersection(a1= self.main_line.slope, 197 a2= self.top_line.slope, 198 b1= self.main_line.b, 199 b2= self.top_line.b ) 200 print "main x, y max: ",x2,y2 201 x1, y1= find_intersection(a1= self.main_line.slope, 202 a2= self.bottom_line.slope, 203 b1= self.main_line.b, 204 b2= self.bottom_line.b ) 205 print "main x, y min: ",x1,y1 206 self.main_line.update(x1= -x2, 207 y1= -y2, 208 x2= x2, 209 y2= y2, 210 translation= True) 211 if self.bottom_line.has_move: 212 213 print "bottom has moved",self.left_line.slope, self.bottom_line.slope 214 x2, y2= find_intersection(a1= self.left_line.slope, 215 a2= self.bottom_line.slope, 216 b1= self.left_line.b, 217 b2= self.bottom_line.b ) 218 print "x, y max: ",x2,y2 219 x1, y1= find_intersection(a1= self.right_line.slope, 220 a2= self.bottom_line.slope, 221 b1= self.right_line.b, 222 b2= self.bottom_line.b ) 223 print "x, y min: ",x1 ,y1 224 self.bottom_line.update(xmin= x2, 225 ymin= y2, 226 xmax= x1, 227 ymax= y1) 228 229 self.top_line.update(xmin= -x2, 230 ymin= -y2, 231 xmax= -x1, 232 ymax= -y1) 233 self.left_line.update(xmin= -x1, 234 ymin= -y1, 235 xmax= x2, 236 ymax= y2, 237 translation= True) 238 self.right_line.update( 239 xmin= -x2, 240 ymin= -y2, 241 xmax= x1, 242 ymax= y1, 243 translation= True) 244 print "bottom has moved",self.left_line.slope, self.bottom_line.slope 245 x2, y2= find_intersection(a1= self.main_line.slope, 246 a2= self.bottom_line.slope, 247 b1= self.main_line.b, 248 b2= self.bottom_line.b ) 249 print "main x, y max: ",x2,y2 250 x1, y1= find_intersection(a1= self.main_line.slope, 251 a2= self.top_line.slope, 252 b1= self.main_line.b, 253 b2= self.top_line.b ) 254 print "main x, y min: ",x1,y1 255 self.main_line.update(x1= -x2, 256 y1= -y2, 257 x2= x2, 258 y2= y2, 259 translation= True) 260 if self.left_line.has_move: 261 print "left_line has moved",self.left_line.slope, self.top_line.slope 262 x2, y2= find_intersection(a1= self.left_line.slope, 263 a2= self.top_line.slope, 264 b1= self.left_line.b, 265 b2= self.top_line.b ) 266 print "main x, y max: ",x2,y2 267 x1, y1= find_intersection(a1= self.left_line.slope, 268 a2= self.bottom_line.slope, 269 b1= self.left_line.b, 270 b2= self.bottom_line.b ) 271 self.left_line.update(xmin = x1, 272 xmax = x2, 273 ymin= y1, 274 ymax= y2, 275 translation=True) 276 277 self.right_line.update(xmin = -x1, 278 xmax = -x2, 279 ymin= -y1, 280 ymax= -y2, 281 translation=True) 282 283 self.bottom_line.update(xmin= x1, 284 ymin= y1, 285 xmax= -x2, 286 ymax= -y2) 287 288 self.top_line.update(xmin= x2, 289 ymin= y2, 290 xmax= -x1, 291 ymax= -y1) 292 print "initial xmin", self.xmin 293 self.xmin= math.sqrt(math.pow((self.main_line.x2 - self.left_line.x2),2)\ 294 +math.pow((self.main_line.y2 - self.left_line.y2),2)) 295 296 print "new xmin ", self.xmin, self.main_line.x2 , self.left_line.x2 297 if self.right_line.has_move: 298 print "right_line has moved",self.right_line.slope, self.top_line.slope 299 x2, y2= find_intersection(a1= self.right_line.slope, 300 a2= self.top_line.slope, 301 b1= self.right_line.b, 302 b2= self.top_line.b ) 303 print "main x, y max: ",x2,y2 304 x1, y1= find_intersection(a1= self.right_line.slope, 305 a2= self.bottom_line.slope, 306 b1= self.right_line.b, 307 b2= self.bottom_line.b ) 308 self.right_line.update(xmin = x1, 309 xmax = x2, 310 ymin= y1, 311 ymax= y2, 312 translation=True) 313 314 self.left_line.update(xmin = -x1, 315 xmax = -x2, 316 ymin= -y1, 317 ymax= -y2, 318 translation=True) 319 320 self.bottom_line.update(xmin= x1, 321 ymin= y1, 322 xmax= -x2, 323 ymax= -y2) 324 325 self.top_line.update(xmin= x2, 326 ymin= y2, 327 xmax= -x1, 328 ymax= -y1) 329 330 print "initial xmax", self.xmax 331 self.xmax= math.sqrt(math.pow((self.main_line.x2 - self.right_line.x2),2)\ 332 +math.pow((self.main_line.y2 - self.right_line.y2),2)) 333 print "new xmax",self.xmax 122 334 def save(self, ev): 123 335 """ … … 174 386 def get_params(self): 175 387 params = {} 176 388 params["x1"]= self.xmax 389 params["y1"]= self.ymin 390 params["x2"]= self.xmin 391 params["y2"]= self.ymax 177 392 params["phi"] = self.main_line.theta 178 393 return params 179 394 180 395 def set_params(self, params): 181 182 396 self.xmax = params["x1"] 397 self.ymin = params["y1"] 398 self.xmin = params["x2"] 399 self.ymax = params["y2"] 183 400 theta = params["theta"] 184 401 print "theta setparams",theta 185 self.main_line.update(theta) 186 402 self.main_line.update(radius1= math.fabs(self.ymax), radius2= math.fabs(self.ymin), theta= theta) 403 self.left_line.update(xmin= -1*self.xmin) 404 self.right_line.update(xmin= self.xmax) 405 406 self.top_line.update(xmin= self.right_line.x1, 407 xmax= self.left_line.x1, 408 ymin= self.right_line.y1, 409 ymax= self.left_line.y1) 410 self.bottom_line.update(xmin= self.right_line.x2, 411 xmax= self.left_line.x2, 412 ymin= self.right_line.y2, 413 ymax= self.left_line.y2) 187 414 self._post_data() 188 415 def freeze_axes(self): … … 206 433 self.markers = [] 207 434 self.axes = axes 208 self.x1= self.xmax209 self.save_x1= self.xmax210 211 self.x2= self.xmin212 self.save_x2= self.xmin213 214 self.y1= self.ymax215 self.save_y1= self.ymax216 217 self.y2= self.ymin218 self.save_y2= self.ymin435 self.x1= xmax 436 self.save_x1= xmax 437 438 self.x2= xmin 439 self.save_x2= xmin 440 441 self.y1= ymax 442 self.save_y1= ymax 443 444 self.y2= ymin 445 self.save_y2= ymin 219 446 self.mline= mline 220 447 self.line = self.axes.plot([self.x1,self.x2], … … 224 451 visible=True)[0] 225 452 226 self.slope= -1 *math.tan(self.mline.theta)453 self.slope= -1/math.tan(self.mline.theta) 227 454 self.b= self.y1- self.slope* self.x1 228 455 self.save_b= self.b 229 456 print "slope from point",(self.y2- self.y1)/(self.x2- self.x1) 230 457 print "my slope horizontal", self.slope 231 print "b from point ", self.y2- self.slope*self.x 1, self.b458 print "b from point ", self.y2- self.slope*self.x2, self.b 232 459 self.npts = 20 233 460 self.has_move=False … … 257 484 Draw the new roughness on the graph. 258 485 """ 259 if translation : 260 print "translation ",self.top_hight 261 self.x1= self.xmax +_self.top_hight*math.sin(math.pi/2 + self.mline.theta) 262 self.x2= self.xmin +self.top_hight*math.sin(math.pi/2 + self.mline.theta) 263 self.y1= self.ymin - self.top_hight*math.sin(math.pi/2 + self.mline.theta) 264 self.y2= self.ymax -self.top_hight*math.sin(math.pi/2 + self.mline.theta) 265 self.line.set(xdata=[self.x1,self.x2], 266 ydata=[self.y1,self.y2]) 267 return 486 self.slope= -1/math.tan(self.mline.theta) 268 487 if xmin !=None: 269 488 self.x2 = xmin … … 274 493 if ymax != None: 275 494 self.y1 = ymax 495 self.b= self.y1- self.slope * self.x1 276 496 self.line.set(xdata=[self.x1,self.x2], 277 497 ydata=[self.y1,self.y2]) … … 289 509 self.save_y1= self.y1 290 510 self.save_y2= self.y2 511 self.save_b= self.b 291 512 292 513 self.base.freeze_axes() … … 305 526 self.y1 = self.save_y1 306 527 self.y2 = self.save_y2 528 self.b = self.save_b 307 529 308 530 def move(self, x, y, ev): … … 310 532 Process move to a new position, making sure that the move is allowed. 311 533 """ 312 self.b = - self.slope.x 534 print "horizontal move x y ", x, y 535 self.b = y - (-1/self.mline.slope) *x 313 536 self.has_move=True 314 537 self.base.base.update() … … 388 611 Draw the new roughness on the graph. 389 612 """ 613 614 self.slope= math.tan(self.mline.theta) 615 if translation: 616 if xmin!=None: 617 self.x2=xmin 618 self.xmin= xmin 619 if xmax!=None: 620 self.x1=xmax 621 if ymin!=None: 622 self.y2=ymin 623 if ymax!=None: 624 self.y1=ymax 625 self.line.set(xdata=[self.x1,self.x2], 626 ydata=[self.y1,self.y2]) 627 self.b= self.y1- self.slope * self.x1 628 return 629 390 630 self.x1= self.mline.x1 + self.xmin*math.cos(math.pi/2 - self.mline.theta) 391 631 self.x2= self.mline.x2 + self.xmin*math.cos(math.pi/2 - self.mline.theta) … … 394 634 self.line.set(xdata=[self.x1,self.x2], 395 635 ydata=[self.y1,self.y2]) 396 #print "update slope ", (self.y2-self.y1)/(self.x2- self.x1)636 print "update slope ", (self.y2-self.y1)/(self.x2- self.x1) 397 637 #print "main slope", math.tan(self.mline.theta) 398 638 … … 402 642 can restore on Esc. 403 643 """ 404 self.save_L_width= self.L_width 405 self.save_xmin= self.x1 406 self.save_xmax= self.x2 407 self.save_ymin= self.y1 408 self.save_ymax= self.y2 644 self.save_x1= self.x1 645 self.save_x2= self.x2 646 self.save_y1= self.y1 647 self.save_y2= self.y2 409 648 410 649 self.base.freeze_axes() … … 432 671 433 672 # compute the b intercept of the vertical line 434 self.b= math.fabs( y - self.mline.theta * x) 435 436 437 print "move L_width", self.L_width, self.L_hight 673 self.b=y - self.mline.slope * x 674 675 438 676 self.base.base.update() 439 677 … … 478 716 self.theta= theta 479 717 480 self.radius1 = ymax481 self.radius2 = ymin718 self.radius1 = math.fabs(ymax) 719 self.radius2 = math.fabs(ymin) 482 720 self.scale = 10.0 483 721 … … 492 730 color=self.color, 493 731 visible=True)[0] 494 732 self.slope= math.tan(self.theta) 733 self.b= math.fabs(self.y1- self.slope * self.x1) 734 print "intercept main",math.fabs(self.y2- self.slope * self.x2),math.fabs(self.y1- self.slope * self.x1) 495 735 self.npts = 20 496 736 self.has_move=False … … 524 764 return self.theta - self.save_theta 525 765 526 def update(self, theta=None,radius1=None,radius2=None): 766 def update(self,x1=None, 767 y1=None, 768 x2=None, 769 y2=None, 770 translation=False, 771 xmin=None,vline=None, theta=None,radius1=None,radius2=None): 527 772 """ 528 773 Draw a line given and angle relative to the x-axis and a radius … … 530 775 @param radius: the distance between the center and one end of the line 531 776 """ 532 777 if translation: 778 if x1 !=None: 779 self.x1= x1 780 if x2 !=None: 781 self.x2= x2 782 if y1 !=None: 783 self.y1= y1 784 if y2 !=None: 785 self.y2= y2 786 787 self.line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y2]) 788 self.radius1= math.fabs(self.x1/math.cos(self.theta)) 789 self.radius2= math.fabs(self.x2/math.cos(self.theta)) 790 print "radius 1, radius2", self.radius1, self.radius2 791 return 792 533 793 if theta !=None: 534 794 self.theta= theta … … 538 798 self.radius2 =radius2 539 799 print "update main line", math.degrees(self.theta),self.radius1, self.radius2 540 800 print "smain radius 1 2", self.radius1, self.radius2 541 801 self.x1= self.radius1*math.cos(self.theta) 542 802 self.y1= self.radius1*math.sin(self.theta) … … 575 835 """ 576 836 self.theta= math.atan2(y,x) 837 self.slope= math.tan(self.theta) 838 self.b= y - self.slope *x 839 840 print "main move slope , theta, b", self.slope, self.theta, self.b 841 577 842 #print "main_line previous theta --- next theta ",math.degrees(self.save_theta),math.degrees(self.theta) 578 843 self.has_move=True
Note: See TracChangeset
for help on using the changeset viewer.