Changeset 8392:c6ef4f151d5b in orange
 Timestamp:
 07/15/11 23:48:13 (3 years ago)
 Branch:
 default
 Convert:
 f78cacf1aad830a3c3a33d8371f03b38e9058a0f
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/owplot3d.py
r8391 r8392 103 103 return value 104 104 105 def normal_from_points(p1, p2, p3): 106 v1 = p2  p1 107 v2 = p3  p1 108 return normalize(numpy.cross(v1, v2)) 109 110 def draw_triangle(x0, y0, x1, y1, x2, y2): 111 glBegin(GL_TRIANGLES) 112 glVertex2f(x0, y0) 113 glVertex2f(x1, y1) 114 glVertex2f(x2, y2) 115 glEnd() 116 117 def draw_line(x0, y0, x1, y1): 118 glBegin(GL_LINES) 119 glVertex2f(x0, y0) 120 glVertex2f(x1, y1) 121 glEnd() 122 105 123 def enum(*sequential): 106 124 enums = dict(zip(sequential, range(len(sequential)))) … … 398 416 0, 0, 0, 399 417 0, 1, 0) 400 self. paint_axes()418 self.draw_grid_and_axes() 401 419 402 420 glDisable(GL_DEPTH_TEST) … … 442 460 443 461 def draw_helpers(self): 444 def draw_triangle(x0, y0, x1, y1, x2, y2):445 glBegin(GL_TRIANGLES)446 glVertex2f(x0, y0)447 glVertex2f(x1, y1)448 glVertex2f(x2, y2)449 glEnd()450 451 def draw_line(x0, y0, x1, y1):452 glBegin(GL_LINES)453 glVertex2f(x0, y0)454 glVertex2f(x1, y1)455 glEnd()456 457 462 if self.state == PlotState.SCALING: 458 463 if not self.show_legend: … … 463 468 glLoadIdentity() 464 469 x, y = self.mouse_pos.x(), self.mouse_pos.y() 465 glColor4f(0, 0,0,1)470 glColor4f(0, 0, 0, 1) 466 471 draw_triangle(x5, y30, x+5, y30, x, y40) 467 472 draw_line(x, y, x, y30) … … 473 478 draw_triangle(x+50, y, x+40, y5, x+40, y+5) 474 479 self.renderText(x+60, y+3, 475 'Scale {0} axis'.format([' x', 'z'][self.scale_x_axis]),480 'Scale {0} axis'.format(['z', 'x'][self.scale_x_axis]), 476 481 font=self.labels_font) 477 482 elif self.state == PlotState.SELECTING: … … 507 512 self.updateGL() 508 513 509 def paint_axes(self):514 def draw_grid_and_axes(self): 510 515 cam_in_space = numpy.array([ 511 516 self.camera[0]*self.camera_distance, … … 513 518 self.camera[2]*self.camera_distance 514 519 ]) 515 516 def normal_from_points(p1, p2, p3):517 v1 = p2  p1518 v2 = p3  p1519 return normalize(numpy.cross(v1, v2))520 520 521 521 def plane_visible(plane): … … 526 526 return True 527 527 528 def draw_ line(line):528 def draw_axis(line): 529 529 glColor4f(0.2, 0.2, 0.2, 1) 530 530 glLineWidth(2) # Widths > 1 are actually deprecated I think. … … 549 549 glEnd() 550 550 position += offset 551 value = position[coord_index] / (self.scale[coord_index] + self.add_scale[coord_index]) 552 value += self.center[coord_index] 551 553 self.renderText(position[0], 552 554 position[1], 553 555 position[2], 554 '{0:.2}'.format( position[coord_index]))556 '{0:.2}'.format(value)) 555 557 556 558 glDisable(GL_DEPTH_TEST) … … 572 574 cos = numpy.dot(normal, camera_vector) 573 575 cos = max(0.7, cos) 574 glColor4f(*(self.color_plane *cos))576 glColor4f(*(self.color_plane * cos)) 575 577 P11, P12, P21, P22 = numpy.asarray(axis_plane) 578 # Draw background quad first. 576 579 glBegin(GL_QUADS) 577 580 glVertex3f(*P11) … … 580 583 glVertex3f(*P22) 581 584 glEnd() 585 582 586 P22, P21 = P21, P22 583 587 glColor4f(*(self.color_grid * cos)) … … 587 591 P1vecV = P21  P11 588 592 P2vecV = P22  P12 593 # Draw grid lines. 589 594 glBegin(GL_LINES) 590 595 for i, dx in enumerate(Dx): … … 612 617 613 618 if visible_planes[0]: 614 draw_ line(self.x_axis)619 draw_axis(self.x_axis) 615 620 draw_values(self.x_axis, 0, numpy.array([0,0,1])) 616 621 elif visible_planes[2]: 617 draw_ line(self.x_axis + self.unit_z)622 draw_axis(self.x_axis + self.unit_z) 618 623 draw_values(self.x_axis + self.unit_z, 0, numpy.array([0,0,1])) 619 624 620 625 if visible_planes[1]: 621 draw_ line(self.z_axis)626 draw_axis(self.z_axis) 622 627 draw_values(self.z_axis, 2, numpy.array([1,0,0])) 623 628 elif visible_planes[3]: 624 draw_ line(self.z_axis + self.unit_x)629 draw_axis(self.z_axis + self.unit_x) 625 630 draw_values(self.z_axis + self.unit_x, 2, numpy.array([1,0,0])) 626 631 … … 638 643 numpy.array([0,0,1]), 639 644 numpy.array([1,0,0]), 640 numpy.array([0,0,1]) 641 ] 645 numpy.array([0,0,1])] 642 646 axis = y_axis_translated[rightmost_visible] 643 draw_ line(axis)647 draw_axis(axis) 644 648 normal = normals[rightmost_visible] 645 649 draw_values(y_axis_translated[rightmost_visible], 1, normal)
Note: See TracChangeset
for help on using the changeset viewer.