Changeset 8531:fb7e2b9c7c16 in orange
 Timestamp:
 07/29/11 17:39:23 (3 years ago)
 Branch:
 default
 Convert:
 0557760605dc9ccdb05a7f89ab3dbf8d951572c4
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/OrangeWidgets/plot/owplot3d.py
r8529 r8531 463 463 self.tooltip_fbo_dirty = True 464 464 self.selection_fbo_dirty = True 465 self.use_fbos = True 465 466 466 467 def __del__(self): … … 476 477 glDisable(GL_CULL_FACE) 477 478 glEnable(GL_MULTISAMPLE) 479 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) 478 480 479 481 self.symbol_shader = QtOpenGL.QGLShaderProgram() … … 532 534 pos *= scale; 533 535 vec4 off_pos = vec4(pos, 1.); 534 off_pos = vec4(pos+offset_rotated, 1.); 536 535 537 if (mode != MODE_SELECTION) { 536 // Converge symbols into points by ignoring offsets when 538 off_pos = vec4(pos+offset_rotated, 1.); 539 } 540 else { 541 // Shrunk symbols into points by ignoring offsets when 537 542 // mode == MODE_SELECTION. 538 //off_pos = vec4(pos+offset_rotated, 1.);543 gl_PointSize = 2.; 539 544 } 540 545 … … 603 608 else: 604 609 print('Failed to create selection FBO! Selections may be slow.') 610 self.use_fbos = False 605 611 self.tooltip_fbo = QtOpenGL.QGLFramebufferObject(1024, 1024, format) 606 612 if self.tooltip_fbo.isValid(): … … 608 614 else: 609 615 print('Failed to create tooltip FBO! Tooltips disabled.') 616 self.use_fbos = False 610 617 611 618 def resizeGL(self, width, height): … … 724 731 print('selection fbo was dirty') 725 732 # Draw data as points instead, this means that examples farther away 726 # will still have a good chance at being visible .733 # will still have a good chance at being visible (not covered). 727 734 self.selection_fbo.bind() 728 735 self.symbol_shader.bind() … … 731 738 glDisable(GL_BLEND) 732 739 glBindVertexArray(vao_id) 733 glDrawArrays(GL_ TRIANGLES, 0, vao_id.num_vertices)740 glDrawArrays(GL_POINTS, 0, vao_id.num_vertices) 734 741 glBindVertexArray(0) 735 742 self.symbol_shader.release() … … 1218 1225 return [] 1219 1226 1220 self.selection_fbo_dirty = True 1221 self.updateGL() 1222 1223 width, height = self.width(), self.height() 1224 # TODO: check width < fbo.width 1225 self.selection_fbo.bind() 1226 color_pixels = glReadPixels(0, 0, 1227 width, height, 1228 GL_RGBA, 1229 GL_UNSIGNED_BYTE) 1230 stencil_pixels = glReadPixels(0, 0, 1231 width, height, 1232 GL_STENCIL_INDEX, 1233 GL_FLOAT) 1234 self.selection_fbo.release() 1235 stencils = struct.unpack('f'*width*height, stencil_pixels) 1236 colors = struct.unpack('I'*width*height, color_pixels) 1237 indices = set([]) 1238 for stencil, color in zip(stencils, colors): 1239 if stencil > 0. and color < 4294967295: 1240 indices.add(color) 1241 1242 print(indices) 1243 # TODO: figure out what' causing incorrect values, filter them out 1244 # for now 1245 indices = [i for i in indices if i < len(self.commands[0][1][1][0])] 1246 return indices 1247 1248 1249 projection = QMatrix4x4() 1250 if self.use_ortho: 1251 projection.ortho(width / self.ortho_scale, width / self.ortho_scale, 1252 height / self.ortho_scale, height / self.ortho_scale, 1253 self.ortho_near, self.ortho_far) 1227 if self.use_fbos: 1228 self.selection_fbo_dirty = True 1229 self.updateGL() 1230 1231 width, height = self.width(), self.height() 1232 # TODO: check width < fbo.width 1233 self.selection_fbo.bind() 1234 color_pixels = glReadPixels(0, 0, 1235 width, height, 1236 GL_RGBA, 1237 GL_UNSIGNED_BYTE) 1238 stencil_pixels = glReadPixels(0, 0, 1239 width, height, 1240 GL_STENCIL_INDEX, 1241 GL_FLOAT) 1242 self.selection_fbo.release() 1243 stencils = struct.unpack('f'*width*height, stencil_pixels) 1244 colors = struct.unpack('I'*width*height, color_pixels) 1245 indices = set([]) 1246 for stencil, color in zip(stencils, colors): 1247 if stencil > 0. and color < 4294967295: 1248 indices.add(color) 1249 1250 print(indices) 1251 return indices 1254 1252 else: 1255 projection.perspective(self.camera_fov, float(self.width())/self.height(), 1256 self.perspective_near, self.perspective_far) 1257 1258 modelview = QMatrix4x4() 1259 modelview.lookAt(QVector3D(self.camera[0]*self.camera_distance, 1260 self.camera[1]*self.camera_distance, 1261 self.camera[2]*self.camera_distance), 1262 QVector3D(0, 0, 0), 1263 QVector3D(0, 1, 0)) 1264 1265 proj_model = projection * modelview 1266 viewport = [0, 0, self.width(), self.height()] 1267 1268 def project(x, y, z): 1269 projected = proj_model * QVector4D(x, y, z, 1) 1270 projected /= projected.z() 1271 winx = viewport[0] + (1 + projected.x()) * viewport[2] / 2 1272 winy = viewport[1] + (1 + projected.y()) * viewport[3] / 2 1273 winy = self.height()  winy 1274 return winx, winy 1275 1276 indices = [] 1277 for (cmd, params) in self.commands: 1278 if cmd == 'scatter': 1279 _, _, (X, Y, Z), _ = params 1280 for i, (x, y, z) in enumerate(zip(X, Y, Z)): 1281 x, y, z = self.transform_data_to_plot((x,y,z)) 1282 x_win, y_win = project(x, y, z) 1283 if any(sel.contains(x_win, y_win) for sel in self.selections): 1284 indices.append(i) 1285 1286 return indices 1253 projection = QMatrix4x4() 1254 if self.use_ortho: 1255 projection.ortho(width / self.ortho_scale, width / self.ortho_scale, 1256 height / self.ortho_scale, height / self.ortho_scale, 1257 self.ortho_near, self.ortho_far) 1258 else: 1259 projection.perspective(self.camera_fov, float(self.width())/self.height(), 1260 self.perspective_near, self.perspective_far) 1261 1262 modelview = QMatrix4x4() 1263 modelview.lookAt(QVector3D(self.camera[0]*self.camera_distance, 1264 self.camera[1]*self.camera_distance, 1265 self.camera[2]*self.camera_distance), 1266 QVector3D(0,1, 0), 1267 QVector3D(0, 1, 0)) 1268 1269 proj_model = projection * modelview 1270 viewport = [0, 0, self.width(), self.height()] 1271 1272 def project(x, y, z): 1273 projected = proj_model * QVector4D(x, y, z, 1) 1274 projected /= projected.z() 1275 winx = viewport[0] + (1 + projected.x()) * viewport[2] / 2 1276 winy = viewport[1] + (1 + projected.y()) * viewport[3] / 2 1277 winy = self.height()  winy 1278 return winx, winy 1279 1280 indices = [] 1281 for (cmd, params) in self.commands: 1282 if cmd == 'scatter': 1283 _, (X, Y, Z), _ = params 1284 for i, (x, y, z) in enumerate(zip(X, Y, Z)): 1285 x, y, z = self.transform_data_to_plot((x,y,z)) 1286 x_win, y_win = project(x, y, z) 1287 if any(sel.contains(x_win, y_win) for sel in self.selections): 1288 indices.append(i) 1289 1290 print(indices) 1291 return indices 1287 1292 1288 1293 def set_selection_type(self, type):
Note: See TracChangeset
for help on using the changeset viewer.