Changeset 8484:858657028c62 in orange
 Timestamp:
 07/27/11 15:45:39 (3 years ago)
 Branch:
 default
 Convert:
 fca882ad73d17bec0412724075ccb9929a1350b8
 Location:
 orange/OrangeWidgets/plot
 Files:

 11 added
 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/plot/owplot3d.py
r8478 r8484 115 115 PlotState = enum('IDLE', 'DRAGGING_LEGEND', 'ROTATING', 'SCALING', 'SELECTING', 'PANNING') 116 116 117 Symbol = enum('TRIANGLE', 'RECTANGLE', 'PENTAGON', 'CIRCLE') 117 Symbol = enum('RECT', 'TRIANGLE', 'DTRIANGLE', 'CIRCLE', 'LTRIANGLE', 118 'DIAMOND', 'WEDGE', 'LWEDGE', 'CROSS', 'XCROSS') 119 118 120 SelectionType = enum('ZOOM', 'RECTANGLE', 'POLYGON') 121 122 from owprimitives3d import get_symbol_data 119 123 120 124 class Legend(object): … … 203 207 204 208 class RectangleSelection(object): 205 def __init__(self, first_vertex): 209 def __init__(self, plot, first_vertex): 210 self.plot = plot 206 211 self.first_vertex = first_vertex 207 212 self.current_vertex = first_vertex … … 224 229 v1, v2 = self.first_vertex, self.current_vertex 225 230 glLineWidth(1) 226 glColor4f( 0, 0, 0, 1)231 glColor4f(*self.plot.theme.helpers_color) 227 232 draw_line(v1[0], v1[1], v1[0], v2[1]) 228 233 draw_line(v1[0], v2[1], v2[0], v2[1]) … … 244 249 245 250 class PolygonSelection(object): 246 def __init__(self, first_vertex): 251 def __init__(self, plot, first_vertex): 252 self.plot = plot 247 253 self.vertices = [first_vertex] 248 254 self.current_vertex = first_vertex … … 296 302 def draw(self): 297 303 glLineWidth(1) 298 glColor4f( 0, 0, 0, 1)304 glColor4f(*self.plot.theme.helpers_color) 299 305 if len(self.vertices) == 1: 300 306 v1, v2 = self.vertices[0], self.current_vertex … … 393 399 self.legend = Legend(self) 394 400 395 self.use_2d_symbols = True401 self.use_2d_symbols = False 396 402 self.symbol_scale = 1. 397 403 self.transparency = 255 … … 438 444 glEnable(GL_LINE_SMOOTH) 439 445 glDisable(GL_CULL_FACE) 446 glEnable(GL_MULTISAMPLE) 440 447 441 448 self.symbol_shader = QtOpenGL.QGLShaderProgram() … … 584 591 for (cmd, params) in self.commands: 585 592 if cmd == 'scatter': 586 vao_id, outline_vao_id,(X, Y, Z), labels = params593 vao_id, (X, Y, Z), labels = params 587 594 scale = numpy.maximum([0., 0., 0.], self.scale + self.additional_scale) 588 595 … … 599 606 glDrawArrays(GL_TRIANGLES, 0, vao_id.num_vertices) 600 607 glBindVertexArray(0) 601 if self.use_2d_symbols:602 glLineWidth(1)603 glBindVertexArray(outline_vao_id)604 glDrawElements(GL_LINES, outline_vao_id.num_indices, GL_UNSIGNED_INT, c_void_p(0))605 glBindVertexArray(0)608 #if self.use_2d_symbols: 609 # glLineWidth(1) 610 # glBindVertexArray(outline_vao_id) 611 # glDrawElements(GL_LINES, outline_vao_id.num_indices, GL_UNSIGNED_INT, c_void_p(0)) 612 # glBindVertexArray(0) 606 613 607 614 self.symbol_shader.release() … … 622 629 for (cmd, params) in self.commands: 623 630 if cmd == 'scatter': 624 vao_id, outline_vao_id,(X, Y, Z), labels = params631 vao_id, (X, Y, Z), labels = params 625 632 # Draw into colorpicking buffer. Each example gets its own 626 633 # unique color, carrying example's index. We also draw stencil mask … … 955 962 self.data_scale = numpy.array([scale_x, scale_y, scale_z]) 956 963 957 def generate_vertices(symbol): 958 # TODO 959 pass 960 961 # Generate vertices for shapes and also indices for outlines. 964 # TODO: if self.use_2d_symbols 965 962 966 vertices = [] 963 outline_indices = []964 index = 0965 967 ai = 1 # Array index (used in colorpicking). 966 968 for x, y, z, (r,g,b,a), size, symbol in zip(X, Y, Z, colors, sizes, symbols): … … 971 973 y *= scale_y 972 974 z *= scale_z 973 sO2 = size * 0.1 974 n = self.available_symbols[symbol % len(self.available_symbols)] 975 angle_inc = 2.*pi / n 976 angle = angle_inc / 2. 977 ai += 1 978 for i in range(n): 979 vertices.extend([x,y,z, ai, 0,0,0, r,g,b,a]) 980 vertices.extend([x,y,z, ai, cos(angle)*sO2, sin(angle)*sO2, 0, r,g,b,a]) 981 angle += angle_inc 982 vertices.extend([x,y,z, ai, cos(angle)*sO2, sin(angle)*sO2, 0, r,g,b,a]) 983 outline_indices.extend([index+1, index+2]) 984 index += 3 975 triangles = get_symbol_data(symbol) 976 ss = size*0.1 977 for (v1, v2, v3) in triangles: 978 vertices.extend([x,y,z, ai, ss*v1[0],ss*v1[1],ss*v1[2], r,g,b,a]) 979 vertices.extend([x,y,z, ai, ss*v2[0],ss*v2[1],ss*v2[2], r,g,b,a]) 980 vertices.extend([x,y,z, ai, ss*v3[0],ss*v3[1],ss*v3[2], r,g,b,a]) 985 981 986 982 # Build Vertex Buffer + Vertex Array Object. … … 1004 1000 glBindBuffer(GL_ARRAY_BUFFER, 0) 1005 1001 1006 # Outline:1007 # generate another VAO, keep the same vertex buffer, but use an index buffer1008 # this time.1009 index_buffer_id = glGenBuffers(1)1010 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_id)1011 glBufferData(GL_ELEMENT_ARRAY_BUFFER, numpy.array(outline_indices, 'I'), GL_STATIC_DRAW)1012 1013 outline_vao_id = GLuint(0)1014 glGenVertexArrays(1, outline_vao_id)1015 glBindVertexArray(outline_vao_id)1016 1017 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, index_buffer_id)1018 glBindBuffer(GL_ARRAY_BUFFER, vertex_buffer_id)1019 glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, vertex_size, c_void_p(0))1020 glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, vertex_size, c_void_p(4*4))1021 glVertexAttribPointer(2, 4, GL_FLOAT, GL_FALSE, vertex_size, c_void_p(7*4))1022 glEnableVertexAttribArray(0)1023 glEnableVertexAttribArray(1)1024 glEnableVertexAttribArray(2)1025 1026 glBindVertexArray(0)1027 glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0)1028 glBindBuffer(GL_ARRAY_BUFFER, 0)1029 1030 1002 vao_id.num_vertices = len(vertices) / (vertex_size / 4) 1031 outline_vao_id.num_indices = vao_id.num_vertices * 2 / 31032 1003 self.vertex_buffers.append(vertex_buffer_id) 1033 self.index_buffers.append(index_buffer_id)1034 1004 self.vaos.append(vao_id) 1035 self.vaos.append(outline_vao_id) 1036 self.commands.append(("scatter", [vao_id, outline_vao_id, (X,Y,Z), labels])) 1005 self.commands.append(("scatter", [vao_id, (X,Y,Z), labels])) 1037 1006 self.updateGL() 1038 1007 … … 1209 1178 if self.selection_type == SelectionType.RECTANGLE or\ 1210 1179 self.selection_type == SelectionType.ZOOM: 1211 self.new_selection = RectangleSelection( [pos.x(), pos.y()])1180 self.new_selection = RectangleSelection(self, [pos.x(), pos.y()]) 1212 1181 elif buttons & Qt.RightButton: 1213 1182 if QApplication.keyboardModifiers() & Qt.ShiftModifier: … … 1286 1255 def mouseReleaseEvent(self, event): 1287 1256 if self.state == PlotState.SELECTING and self.new_selection == None: 1288 self.new_selection = PolygonSelection( [event.pos().x(), event.pos().y()])1257 self.new_selection = PolygonSelection(self, [event.pos().x(), event.pos().y()]) 1289 1258 return 1290 1259
Note: See TracChangeset
for help on using the changeset viewer.