def update_data(self, labels=None, setAnchors=0, **args): OWLinProj3DPlot.updateData(self, labels, setAnchors, **args) if self.anchor_data: self._build_anchor_grid() self.updateGL()
def setData(self, data, subset_data=None, **args): OWLinProj3DPlot.set_data(self, data, subset_data, **args) # No need to generate backgroud grid sphere geometry more than once if hasattr(self, '_sphere_buffer'): return self.makeCurrent() lines = [] num_parts = 30 num_horizontal_rings = 20 num_vertical_rings = 24 r = 1. for i in range(num_horizontal_rings): z_offset = float(i) * 2 / num_horizontal_rings - 1. r = (1. - z_offset**2)**0.5 for j in range(num_parts): angle_z_0 = float(j) * 2 * pi / num_parts angle_z_1 = float(j+1) * 2 * pi / num_parts lines.extend([sin(angle_z_0)*r, z_offset, cos(angle_z_0)*r, sin(angle_z_1)*r, z_offset, cos(angle_z_1)*r]) for i in range(num_vertical_rings): r = 1. phi = 2 * i * pi / num_vertical_rings for j in range(num_parts): theta_0 = (j) * pi / num_parts theta_1 = (j+1) * pi / num_parts lines.extend([sin(theta_0)*cos(phi)*r, cos(theta_0)*r, sin(theta_0)*sin(phi)*r, sin(theta_1)*cos(phi)*r, cos(theta_1)*r, sin(theta_1)*sin(phi)*r]) self._sphere_buffer = VertexBuffer(numpy.array(lines, numpy.float32), [(3, GL_FLOAT)]) self._sphere_shader = QtOpenGL.QGLShaderProgram() self._sphere_shader.addShaderFromSourceFile(QtOpenGL.QGLShader.Vertex, os.path.join(os.path.dirname(__file__), 'sphere.vs')) self._sphere_shader.addShaderFromSourceFile(QtOpenGL.QGLShader.Fragment, os.path.join(os.path.dirname(__file__), 'sphere.fs')) self._sphere_shader.bindAttributeLocation('position', 0) if not self._sphere_shader.link(): print('Failed to link sphere shader!') ## Cones cone_data = parse_obj('cone_hq.obj') vertices = [] for v0, v1, v2, n0, n1, n2 in cone_data: vertices.extend([v0[0],v0[1],v0[2], n0[0],n0[1],n0[2], v1[0],v1[1],v1[2], n1[0],n1[1],n1[2], v2[0],v2[1],v2[2], n2[0],n2[1],n2[2]]) self._cone_buffer = VertexBuffer(numpy.array(vertices, numpy.float32), [(3, GL_FLOAT), (3, GL_FLOAT)]) self._cone_shader = QtOpenGL.QGLShaderProgram() self._cone_shader.addShaderFromSourceFile(QtOpenGL.QGLShader.Vertex, os.path.join(os.path.dirname(__file__), 'cone.vs')) self._cone_shader.addShaderFromSourceFile(QtOpenGL.QGLShader.Fragment, os.path.join(os.path.dirname(__file__), 'cone.fs')) self._cone_shader.bindAttributeLocation('position', 0) self._cone_shader.bindAttributeLocation('normal', 1) if not self._cone_shader.link(): print('Failed to link cone shader!') ## Another dummy shader (anchor grid) self._grid_shader = QtOpenGL.QGLShaderProgram() self._grid_shader.addShaderFromSourceFile(QtOpenGL.QGLShader.Vertex, os.path.join(os.path.dirname(__file__), 'grid.vs')) self._grid_shader.addShaderFromSourceFile(QtOpenGL.QGLShader.Fragment, os.path.join(os.path.dirname(__file__), 'grid.fs')) self._grid_shader.bindAttributeLocation('position', 0) if not self._grid_shader.link(): print('Failed to link grid shader!') self.before_draw_callback = self.before_draw
def mouseMoveEvent(self, event): self.invert_mouse_x = self.camera_type != 0 OWLinProj3DPlot.mouseMoveEvent(self, event)
def __init__(self, widget, parent=None, name='SpherevizPlot'): OWLinProj3DPlot.__init__(self, widget, parent, name) self.camera_angle = 90 self.camera_type = 0 # Default, center, attribute self.show_anchor_grid = False
def setData(self, data, subset_data=None, **args): OWLinProj3DPlot.set_data(self, data, subset_data, **args) # No need to generate backgroud grid sphere geometry more than once if hasattr(self, '_sphere_buffer'): return self.makeCurrent() lines = [] num_parts = 30 num_horizontal_rings = 20 num_vertical_rings = 24 r = 1. for i in range(num_horizontal_rings): z_offset = float(i) * 2 / num_horizontal_rings - 1. r = (1. - z_offset**2)**0.5 for j in range(num_parts): angle_z_0 = float(j) * 2 * pi / num_parts angle_z_1 = float(j + 1) * 2 * pi / num_parts lines.extend([ sin(angle_z_0) * r, z_offset, cos(angle_z_0) * r, sin(angle_z_1) * r, z_offset, cos(angle_z_1) * r ]) for i in range(num_vertical_rings): r = 1. phi = 2 * i * pi / num_vertical_rings for j in range(num_parts): theta_0 = (j) * pi / num_parts theta_1 = (j + 1) * pi / num_parts lines.extend([ sin(theta_0) * cos(phi) * r, cos(theta_0) * r, sin(theta_0) * sin(phi) * r, sin(theta_1) * cos(phi) * r, cos(theta_1) * r, sin(theta_1) * sin(phi) * r ]) self._sphere_buffer = VertexBuffer(numpy.array(lines, numpy.float32), [(3, GL_FLOAT)]) self._sphere_shader = QtOpenGL.QGLShaderProgram() self._sphere_shader.addShaderFromSourceFile( QtOpenGL.QGLShader.Vertex, os.path.join(os.path.dirname(__file__), 'sphere.vs')) self._sphere_shader.addShaderFromSourceFile( QtOpenGL.QGLShader.Fragment, os.path.join(os.path.dirname(__file__), 'sphere.fs')) self._sphere_shader.bindAttributeLocation('position', 0) if not self._sphere_shader.link(): print('Failed to link sphere shader!') ## Cones cone_data = parse_obj('cone_hq.obj') vertices = [] for v0, v1, v2, n0, n1, n2 in cone_data: vertices.extend([ v0[0], v0[1], v0[2], n0[0], n0[1], n0[2], v1[0], v1[1], v1[2], n1[0], n1[1], n1[2], v2[0], v2[1], v2[2], n2[0], n2[1], n2[2] ]) self._cone_buffer = VertexBuffer(numpy.array(vertices, numpy.float32), [(3, GL_FLOAT), (3, GL_FLOAT)]) self._cone_shader = QtOpenGL.QGLShaderProgram() self._cone_shader.addShaderFromSourceFile( QtOpenGL.QGLShader.Vertex, os.path.join(os.path.dirname(__file__), 'cone.vs')) self._cone_shader.addShaderFromSourceFile( QtOpenGL.QGLShader.Fragment, os.path.join(os.path.dirname(__file__), 'cone.fs')) self._cone_shader.bindAttributeLocation('position', 0) self._cone_shader.bindAttributeLocation('normal', 1) if not self._cone_shader.link(): print('Failed to link cone shader!') ## Another dummy shader (anchor grid) self._grid_shader = QtOpenGL.QGLShaderProgram() self._grid_shader.addShaderFromSourceFile( QtOpenGL.QGLShader.Vertex, os.path.join(os.path.dirname(__file__), 'grid.vs')) self._grid_shader.addShaderFromSourceFile( QtOpenGL.QGLShader.Fragment, os.path.join(os.path.dirname(__file__), 'grid.fs')) self._grid_shader.bindAttributeLocation('position', 0) if not self._grid_shader.link(): print('Failed to link grid shader!') self.before_draw_callback = self.before_draw