Exemplo n.º 1
0
    def __init__(self,size):
        app.Canvas.__init__(self,
                            title='Hello OpenGL',
                            keys='interactive',
                            size=size)

        builtins.width, builtins.height = size

        self.startTime = time()
        self.program = gloo.Program(vertex, fragment)

        self.vertices = gloo.VertexBuffer(np.array([
            [.5, .5],
            [.5, -.5],
            [-.5, -.5],
            [-.5, .5]]).astype(np.float32))

        self.indices = gloo.IndexBuffer([0, 1, 3, 1, 2, 3])
        self.texCoord = [(1, 1), (1, 0), (0, 0), (0, 1)]
        self.texture1 = Texture2D(data=io.imread('../Assets/container.jpg', flipVertically=True))
        self.texture2 = Texture2D(data=io.imread('../Assets/smiley.jpg', flipVertically=True))

        self.model = None
        self.view = None
        self.projection = None

        self.program['a_position'] = self.vertices
        self.program['aTexCoord'] = self.texCoord
        self.program['texture1'] = self.texture1
        self.program['texture2'] = self.texture2

        self.timer = app.Timer('auto', self.on_timer, start=True)


        self.show()
Exemplo n.º 2
0
    def draw(self, program, azimuth, elevation):

        indices = np.array([])
        for i in range(1, self.steps):
            current_el = self.el[i] * 180 / np.pi
            if current_el > np.abs(elevation):
                break

            p1 = 0
            p2 = i
            p3 = i + 1

            indices = np.append(indices, [(p1, p2, p3)])

        indices = gloo.IndexBuffer(indices.astype(np.uint32))

        program['u_model'] = rotate(azimuth, (0, 1, 0))

        if elevation > 0:
            program['a_position'] = self.vertices_pos
        else:
            program['a_position'] = self.vertices_neg

        program['a_sourceColour'] = self.colors
        program.draw('triangle_strip', indices=indices)
Exemplo n.º 3
0
    def _compute_bbox(self):

        self.bb = []
        minx, maxx = min(self.vertices[:, 0]), max(self.vertices[:, 0])
        miny, maxy = min(self.vertices[:, 1]), max(self.vertices[:, 1])
        minz, maxz = min(self.vertices[:, 2]), max(self.vertices[:, 2])
        self.bb.append([minx, miny, minz])
        self.bb.append([minx, maxy, minz])
        self.bb.append([minx, miny, maxz])
        self.bb.append([minx, maxy, maxz])
        self.bb.append([maxx, miny, minz])
        self.bb.append([maxx, maxy, minz])
        self.bb.append([maxx, miny, maxz])
        self.bb.append([maxx, maxy, maxz])
        self.bb = np.asarray(self.bb, dtype=np.float32)
        #self.diameter = max(pdist(self.bb, 'euclidean'))

        # Set up rendering data
        colors = [[1, 0, 0], [1, 1, 0], [0, 1, 0], [0, 1, 1], [0, 0, 1],
                  [0, 1, 0], [0.5, 0, 0.5], [0, 0.5, 0.5]]
        indices = [
            0, 1, 0, 2, 3, 1, 3, 2, 4, 5, 4, 6, 7, 5, 7, 6, 0, 4, 1, 5, 2, 6,
            3, 7
        ]

        vertices_type = [('a_position', np.float32, 3),
                         ('a_color', np.float32, 3)]
        collated = np.asarray(list(zip(self.bb, colors)), vertices_type)
        self.bb_vbuffer = gloo.VertexBuffer(collated)
        self.bb_ibuffer = gloo.IndexBuffer(indices)
Exemplo n.º 4
0
 def __init__(self, surface, sky="fluffy_clouds.png", bed="seabed.png"):
     app.Canvas.__init__(self,
                         size=(600, 600),
                         title="Water surface simulator 2")
     self.surface = surface
     self.sky = io.read_png(sky)
     self.bed = io.read_png(bed)
     self.program = gloo.Program(VS, FS_triangle)
     self.program_point = gloo.Program(VS, FS_point)
     pos = self.surface.position()
     self.program["a_position"] = pos
     self.program_point["a_position"] = pos
     self.program['u_sky_texture'] = gloo.Texture2D(self.sky,
                                                    wrapping='repeat',
                                                    interpolation='linear')
     self.program['u_bed_texture'] = gloo.Texture2D(self.bed,
                                                    wrapping='repeat',
                                                    interpolation='linear')
     self.program_point["u_eye_height"] = self.program["u_eye_height"] = 3
     self.program["u_alpha"] = 0.9
     self.program["u_bed_depth"] = 1
     self.triangles = gloo.IndexBuffer(self.surface.triangulation())
     self.are_points_visible = False
     self._timer = app.Timer('auto', connect=self.on_timer, start=True)
     self.activate_zoom()
     self.show()
Exemplo n.º 5
0
    def __init__(self, **kwargs):
        # Initialize the canvas for real
        app.Canvas.__init__(self, keys='interactive', **kwargs)
        self.size = 512, 512
        self.position = 50, 50

        self.vbo = gloo.VertexBuffer(data)
        self.index = gloo.IndexBuffer(edges)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.program = gloo.Program(vert, frag)
        self.program.bind(self.vbo)
        self.program['u_size'] = 1
        self.program['u_antialias'] = u_antialias
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_projection'] = self.projection

        self.program_e = gloo.Program(vs, fs)
        self.program_e.bind(self.vbo)

        set_state(clear_color='white', depth_test=False, blend=True,
                  blend_func=('src_alpha', 'one_minus_src_alpha'))
Exemplo n.º 6
0
    def __init__(self, size):
        self.size = size

        s = size / 2
        v1 = np.array([-s, -s, -s])
        v2 = np.array([-s, -s, s])
        v3 = np.array([s, -s, s])
        v4 = np.array([s, -s, -s])
        v5 = np.array([-s, s, -s])
        v6 = np.array([-s, s, s])
        v7 = np.array([s, s, s])
        v8 = np.array([s, s, -s])

        self.vertices = np.array(
            [[v1], [v2], [v3], [v4], [v5], [v6], [v7], [v8]], dtype=np.float32)

        self.indices = np.array([
            0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 3, 7, 2, 6,
            1, 5
        ],
                                dtype=np.uint32)

        self.indices = gloo.IndexBuffer(self.indices)

        num_vertices = int(self.vertices.size / 3)
        color = np.array([0.0, 0.0, 0.0, 1.0])
        pixel_colors = np.tile(color, (num_vertices, 1))

        self.colors = pixel_colors.astype(np.float32)
Exemplo n.º 7
0
    def __init__(self):
        """конструктор обьекта окна"""
        app.Canvas.__init__(self, title="step 5", size=(500, 500), vsync=True)

        gloo.set_state(clear_color=(0, 0, 0, 1), depth_test=True,
                       blend=False)  # step5

        self.program = gloo.Program(vert, frag)
        self.surface = Surface(
        )  # обьект, который будет давать состояние поверхности
        self.program["a_position"] = self.surface.position(
        )  # xy=const шейдеру,

        sun = np.array([1, 0, 1], dtype=np.float32)  # step5
        sun /= np.linalg.norm(sun)
        self.program["u_sun_direction"] = sun
        self.program["u_sun_color"] = np.array([0.5, 0.5, 0], dtype=np.float32)
        self.program["u_ambient_color"] = np.array([0.2, 0.2, 0.5],
                                                   dtype=np.float32)

        self.triangles = gloo.IndexBuffer(self.surface.triangulation())
        self.t = 0  # t - time
        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
        self.activate_zoom()
        self.show()
Exemplo n.º 8
0
    def __init__(self,
                 mesh,
                 position=(0.0, 0.0, 0.0),
                 orientation=None,
                 color=(255., 0., 0., 255.0),
                 faces=None,
                 shader_manager=None):
        '''Orientation must be a 4x4 rotation matrix'''
        self.position = np.array(position, dtype=np.float32)
        if orientation is None:
            self.orientation = np.eye(4)
        else:
            assert orientation.shape == (
                4, 4), "Orientation must be a 4x4 numpy array"
            self.orientation = orientation

        if len(color) == 3:
            color = color + (255, )
        self.color = np.array(color,
                              dtype=np.float32) / 255.  # Normalize to [0, 1]

        self.program = gloo.Program(self._vertex_shader, self._fragment_shader)
        self.program.bind(mesh)
        self.faces = gloo.IndexBuffer(faces)

        self.model = np.eye(4, dtype=np.float32)
        self.model = self.model.dot(translate(self.position))
        self.view = np.eye(4, dtype=np.float32)

        self.projection = perspective(30.0, 800 / float(800), 2.0, 500.0)
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_projection'] = self.projection
        self.program['u_color'] = self.color
        self.children = []
Exemplo n.º 9
0
    def __init__(self, parent):
        self._parent = parent
        self._vbo = gloo.VertexBuffer()

        self._pos = None
        self._color = None

        self._da = visuals.line.dash_atlas.DashAtlas()
        dash_index, dash_period = self._da['dashed']
        joins = visuals.line.line.joins
        caps = visuals.line.line.caps
        self._U = dict(dash_index=dash_index,
                       dash_period=dash_period,
                       linejoin=joins['round'],
                       linecaps=(caps['|'], caps['|']),
                       dash_caps=(caps['='], caps['=']),
                       antialias=1.0)
        self._dash_atlas = gloo.Texture2D(self._da._data)

        Visual.__init__(self,
                        vcode=self.VERTEX_SHADER,
                        fcode=self.FRAGMENT_SHADER)
        self._index_buffer = gloo.IndexBuffer()
        self.set_gl_state('translucent', depth_test=False)
        self._draw_mode = 'triangles'
    def __init__(self):
        app.Canvas.__init__(self,
                            title='Hello OpenGL',
                            keys='interactive')

        self.startTime = time()
        self.program = gloo.Program(vertex, fragment)

        self.vertices = gloo.VertexBuffer(np.array([
            [.5, .5],
            [.5, -.5],
            [-.5, -.5],
            [-.5, .5]]).astype(np.float32))

        self.indices = gloo.IndexBuffer([0, 1, 3, 1, 2, 3])
        self.texCoord = [(1, 1), (1, 0), (0, 0), (0, 1)]
        self.texture1 = Texture2D(data=io.imread('../Assets/container.jpg', flipVertically=True))
        self.texture2 = Texture2D(data=io.imread('../Assets/smiley.jpg', flipVertically=True))

        #trans stores matrix in glm format
        #_trans stores matrix in numpy format
        self.trans = None
        self._trans = None

        self.program['a_position'] = self.vertices
        self.program['aTexCoord'] = self.texCoord
        self.program['texture1'] = self.texture1
        self.program['texture2'] = self.texture2



        self.timer = app.Timer('auto', self.on_timer, start=True)
        self.show()
Exemplo n.º 11
0
    def __init__(self):
        app.Canvas.__init__(self, close_keys='escape')
        self.size = 800, 600

        self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
        
        self.theta, self.phi = 0, 0
        self.translate = 3
        
        # self.program.bind(gloo.VertexBuffer(data))
        # data['a_position'] = pos
        # data['a_normal'] = normals
        # data['a_curv'] = curv
        # data['a_stc'] = a_stc
        for _ in ('a_position', 'a_normal',
                  'a_curv', 'a_stc'):
            self.program[_] = data[_]
        
        self.faces = gloo.IndexBuffer(faces.ravel().astype(np.uint32))
        
        self.program['u_color'] = 1, 1, 1, 1
        self.program['u_light_position'] = (1., 1., 1.)
        self.program['u_light_intensity'] = (1., 1., 1.)
        
        self.update_matrices()
Exemplo n.º 12
0
    def __init__(self):
        self.program = gloo.Program(self.VERT_SHADER, self.FRAG_SHADER)

        brain = np.load(
            load_data_file('brain/brain.npz', force_download='2014-09-04'))
        data = brain['vertex_buffer']
        faces = brain['index_buffer']

        self.theta, self.phi = -80, 180
        self.translate = 3

        self.faces = gloo.IndexBuffer(faces)
        self.program.bind(gloo.VertexBuffer(data))

        self.model = translate(np.eye(4), 0, 0, -5)
        self.program['model'] = self.model

        self.view = np.eye(4)
        self.program['view'] = self.view
        self.program['u_color'] = 1, 1, 1, 1
        self.program['u_light_position'] = (1., 1., 1.)
        self.program['u_light_intensity'] = (1., 1., 1.)

        self.projection = np.eye(4)
        self.program['projection'] = self.projection
Exemplo n.º 13
0
    def __init__(self):
        app.Canvas.__init__(self, title='Hello OpenGL', keys='interactive')

        # geometry shaders require full OpenGL namespace provided by PyOpenGL

        self.program = gloo.Program(vertex, fragment)

        self.vertices = gloo.VertexBuffer(
            np.array([[.5, .5], [.5, -.5], [-.5, -.5],
                      [-.5, .5]]).astype(np.float32))

        self.indices = gloo.IndexBuffer([0, 1, 3, 1, 2, 3])

        # when tex coords are greater than (0, 1) then repeat, clamped to edge are used
        self.texCoord = [(1 * 4, 1 * 4), (1 * 4, 0), (0, 0), (0, 1 * 4)]

        # self.texture = Texture2D(data=io.imread('smiley.jpg'),
        #                         interpolation='linear',
        #                         wrapping='repeat')

        self.texture = Texture2D(data=io.imread('../Assets/smiley.jpg'),
                                 interpolation='nearest',
                                 wrapping='repeat')

        self.program['a_position'] = self.vertices
        self.program['aTexCoord'] = self.texCoord
        self.program['ourTexture'] = self.texture

        self.program['ourTexture'] = self.texture
        self.timer = app.Timer('auto', self.on_timer, start=True)
        self.show()
Exemplo n.º 14
0
    def on_timer(self, event):
        self.program.bind(gloo.VertexBuffer(self.data))
        self.program_e.bind(gloo.VertexBuffer(self.data))
        self.index = gloo.IndexBuffer(self.edges)
        gloo.clear(color=True, depth=True)

        self.update()
Exemplo n.º 15
0
 def __init__(self, n=50):
     app.Canvas.__init__(self)
     self.program = gloo.Program(vertex, fragment)
     self.program['x'] = gloo.VertexBuffer(np.linspace(-1.0, +1.0, n).astype(np.float32))
     self.program['y'] = gloo.VertexBuffer(np.random.uniform(-0.5, +0.5, n).astype(np.float32))
     self.program['u_color'] = np.array((1., 0., 0., 1.), dtype=np.float32)
     self.program['u_mat'] = np.eye(4).astype(np.float32)
     self.index = gloo.IndexBuffer(np.arange(n).astype(np.uint16))
Exemplo n.º 16
0
 def __init__(self):
     app.Canvas.__init__(self, size=(600, 600), close_keys='escape')
     self.program = gloo.Program(VERT_SHADER, FRAG_SHADER)
     self.program.bind(gloo.VertexBuffer(V))
     for n, v in uniforms.iteritems():
         self.program[n] = v
     self.program['u_dash_atlas'] = gloo.Texture2D(u_dash_atlas)
     self.index = gloo.IndexBuffer(I)
Exemplo n.º 17
0
    def __init__(self,
                 points,
                 simplices,
                 vertex_color=None,
                 mask_color=None,
                 alpha=1.0,
                 mode='triangles'):
        """ initialize tetrahedra face plot

        Parameters
        ----------
        points : NDArray of float32
            N x 3 points coordinates
        simplices : NDArray of uint32
            N x 4 connectivity matrix

        Note
        ----
        initialize triangles structure
        """
        Visual.__init__(self, vcode=vert, fcode=frag)

        # set data
        self.shared_program.vert['position'] = gloo.VertexBuffer(points)
        if vertex_color is None:
            vertex_color = np.ones((points.shape[0], 4), dtype=np.float32)
        else:
            assert vertex_color.shape[0] == points.shape[0]
            # vertex color may be grayscale
            if np.ndim(vertex_color) == 1:
                f = vertex_color[:, np.newaxis]
                v = np.repeat(f, 4, axis=1)
                v[:, -1] = 1.0
                vertex_color = v.astype(np.float32)
        self.shared_program['a_color'] = vertex_color

        # mask colors, alpha channel is not used when mask_color is given.
        if mask_color is None:
            mask_color = [1.0, 1.0, 1.0, alpha]
        self.shared_program['u_color'] = mask_color

        # build buffer
        if mode is 'triangles':
            vbo = sim2tri(simplices)
        elif mode is 'lines':
            vbo = sim2edge(simplices)
        else:
            raise ValueError('Drawing mode = ' + mode + ' not supported')
        self._index_buffer = gloo.IndexBuffer(vbo)

        # config OpenGL, 'translucent' or 'additive'
        self.set_gl_state('additive',
                          blend=True,
                          depth_test=False,
                          cull_face=False,
                          polygon_offset_fill=False,
                          polygon_offset=(1, 1))
        self._draw_mode = mode
Exemplo n.º 18
0
    def __init__(self,
                 vertices,
                 faces,
                 size,
                 K,
                 R,
                 t,
                 clip_near,
                 clip_far,
                 bg_color=(0.0, 0.0, 0.0, 0.0),
                 ambient_weight=0.1,
                 render_rgb=True,
                 render_depth=True,
                 render_normal=True):
        """
        mode is from ['rgb', 'depth', 'normal', 'rgb+depth', 'rgb_normal', 'depth+normal', 'rgb+depth+normal']
        """
        app.Canvas.__init__(self, show=False, size=size)

        #gloo.gl.use_gl('gl2 debug')

        self.size = size
        self.shape = (self.size[1], self.size[0])
        self.bg_color = bg_color
        self.ambient_weight = ambient_weight
        self.render_rgb = render_rgb
        self.render_depth = render_depth
        self.render_normal = render_normal

        self.rgb = np.array([])
        self.depth = np.array([])
        self.normal = np.array([])

        # Model matrix
        self.mat_model = np.eye(
            4, dtype=np.float32)  # From object space to world space

        # View matrix (transforming also the coordinate system from OpenCV to
        # OpenGL camera space)
        self.mat_view = np.eye(
            4, dtype=np.float32)  # From world space to eye space
        self.mat_view[:3, :3], self.mat_view[:3, 3] = R, t.squeeze()
        yz_flip = np.eye(4, dtype=np.float32)
        yz_flip[1, 1], yz_flip[2, 2] = -1, -1
        self.mat_view = yz_flip.dot(
            self.mat_view)  # OpenCV to OpenGL camera system
        self.mat_view = self.mat_view.T  # OpenGL expects column-wise matrix format

        # Projection matrix
        self.mat_proj = _compute_calib_proj(K, 0, 0, size[0], size[1],
                                            clip_near, clip_far)

        # Create buffers
        self.vertex_buffer = gloo.VertexBuffer(vertices)
        self.index_buffer = gloo.IndexBuffer(faces.flatten().astype(np.uint32))

        # We manually draw the hidden canvas
        self.update()
Exemplo n.º 19
0
 def Quadcopter(self, nr, nc, r, l):
     quad_frame, colors = vis_util.create_quad_frame(rows=nr,
                                                     cols=nc,
                                                     radius=r,
                                                     length=l,
                                                     offset=True)
     quad_mesh = vis_util.MyMeshData()
     quad_mesh.set_vertices(quad_frame.get_vertices())
     quad_mesh.set_faces(quad_frame.get_faces())
     quad_mesh.set_vertex_colors(colors)
     vertices, filled, outline = quad_mesh.get_glTriangles()
     # make vertex array, etc
     self.filled_buf = gloo.IndexBuffer(filled)
     self.outline_buf = gloo.IndexBuffer(outline)
     self.vertices_buff = gloo.VertexBuffer(vertices)
     # orientation
     if self.QuadState == None:
         self.orientation_quat = Quaternion(1, 0, 0, 0)
Exemplo n.º 20
0
 def load_mesh(self):
     verts, faces, normals, texcoords = io.read_mesh('mesh.obj')
     data = np.zeros(verts.shape[0], [('vertex', np.float32, 3),
                         ('normal', np.float32, 3)])
     data['vertex'] = verts
     data['normal'] = normals
     vertexbuffer = gloo.VertexBuffer(data)
     self.indices = gloo.IndexBuffer(faces)
     self.program.bind(vertexbuffer)
Exemplo n.º 21
0
    def __init__(self,
                 surface,
                 sky="textures/fluffy_clouds.png",
                 bed="textures/sand.png"):
        # self.method = RungeKutta()
        self.method = Euler()

        self.surface = surface
        self.sky = io.read_png(sky)
        self.bed = io.read_png(bed)
        app.Canvas.__init__(self, size=(400, 400), title="water")

        self.program = gloo.Program(vertex_shader, fragment_shader)
        self.program_point = gloo.Program(vertex_shader, point_fragment_shader)

        pos = self.surface.position()

        self.camera_height = 1.0
        self.program["a_position"] = pos
        self.program_point["a_position"] = pos
        self.program['u_sky_texture'] = gloo.Texture2D(self.sky,
                                                       wrapping='repeat',
                                                       interpolation='linear')
        self.program['u_bed_texture'] = gloo.Texture2D(self.bed,
                                                       wrapping='repeat',
                                                       interpolation='linear')
        self.program_point['u_camera_height'] = self.program[
            'u_camera_height'] = self.camera_height
        self.program_point["u_eye_height"] = self.program["u_eye_height"] = 1
        self.program["u_alpha"] = 0.9
        self.program["u_bed_depth"] = 2
        self.program["u_sun_direction"] = normalize([0, 1, 0.1])
        self.program["u_sun_diffused_color"] = [1, 0.8, 1]
        self.program["u_sun_reflected_color"] = [1, 0.8, 0.6]
        self.program["u_water_ambient_color"] = [0.1, 0.2, 0.2]
        self.program["u_water_depth_color"] = [0, 0.1, 0.1]
        self.triangles = gloo.IndexBuffer(self.surface.triangulation())

        self.h_description = None

        self.camera = np.array([0, 0, 1])
        self.up = np.array([0, 1, 0])
        self.set_camera()
        self.are_points_visible = False
        self.drag_start = None
        self.diffused_flag = True
        self.reflected_flag = True
        self.bed_flag = True
        self.stop_flag = False
        self.depth_flag = True
        self.sky_flag = True
        self.apply_flags()

        self._timer = app.Timer('auto', connect=self.on_timer, start=True)
        self.activate_zoom()
        self.show()
Exemplo n.º 22
0
def create_sphere():
    vtype = [('a_position', np.float32, 3),
             ('a_texcoord', np.float32, 3)]
    V, F, N, T = io.read_mesh(Path('./obj/sphere.obj'))
    f_buf = gloo.IndexBuffer(F)
    v_buf = np.zeros(len(V), dtype=vtype)
    v_buf['a_position'] = V
    v_buf['a_texcoord'] = T
    v_buf = gloo.VertexBuffer(v_buf)
    return v_buf, f_buf
Exemplo n.º 23
0
    def __init__(self, **kwargs):
        # Initialize the canvas for real
        app.Canvas.__init__(self,
                            keys='interactive',
                            size=(512, 512),
                            **kwargs)
        ps = self.pixel_scale
        self.position = 50, 50

        n = 100
        ne = 100
        data = np.zeros(n,
                        dtype=[
                            ('a_position', np.float32, 3),
                            ('a_fg_color', np.float32, 4),
                            ('a_bg_color', np.float32, 4),
                            ('a_size', np.float32, 1),
                            ('a_linewidth', np.float32, 1),
                        ])
        edges = np.random.randint(size=(ne, 2), low=0,
                                  high=n).astype(np.uint32)
        data['a_position'] = np.hstack(
            (.25 * np.random.randn(n, 2), np.zeros((n, 1))))
        data['a_fg_color'] = 0, 0, 0, 1
        color = np.random.uniform(0.5, 1., (n, 3))
        data['a_bg_color'] = np.hstack((color, np.ones((n, 1))))
        data['a_size'] = np.random.randint(size=n, low=8 * ps, high=20 * ps)
        data['a_linewidth'] = 1. * ps
        u_antialias = 1

        self.vbo = gloo.VertexBuffer(data)
        self.index = gloo.IndexBuffer(edges)
        self.view = np.eye(4, dtype=np.float32)
        self.model = np.eye(4, dtype=np.float32)
        self.projection = np.eye(4, dtype=np.float32)

        self.program = gloo.Program(vert, frag)
        self.program.bind(self.vbo)
        self.program['u_size'] = 1
        self.program['u_antialias'] = u_antialias
        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_projection'] = self.projection

        set_viewport(0, 0, *self.physical_size)

        self.program_e = gloo.Program(vs, fs)
        self.program_e.bind(self.vbo)

        set_state(clear_color='white',
                  depth_test=False,
                  blend=True,
                  blend_func=('src_alpha', 'one_minus_src_alpha'))

        self.show()
Exemplo n.º 24
0
    def __init__(self,
                 shape,
                 K,
                 models,
                 clip_near,
                 clip_far,
                 bg_color=(0.0, 0.0, 0.0, 0.0),
                 ambient_weight=0.1,
                 render_rgb=True,
                 render_depth=True,
                 render_obj_coords=True,
                 render_segmentation=True,
                 render_bounding_boxes=True):

        app.Canvas.__init__(self, show=False, size=(shape[1], shape[0]))

        #gloo.gl.use_gl('gl2 debug')

        self.size = (shape[1], shape[0])
        self.shape = shape
        self.bg_color = bg_color
        self.ambient_weight = ambient_weight
        self.render_rgb = render_rgb
        self.render_depth = render_depth
        self.render_obj_coords = render_obj_coords
        self.render_segmentation = render_segmentation
        self.render_bounding_boxes = render_bounding_boxes
        self.models = models

        self.rgb = np.array([])
        self.depth = np.array([])
        self.obj_coords = np.array([])
        self.obj_coords_rep = np.array([])
        self.segmentation = np.array([])

        # Model matrix
        self.mat_model = np.eye(
            4, dtype=np.float32)  # From object space to world space

        # Projection matrix
        self.mat_proj = _compute_calib_proj(K, 0, 0, self.size[0],
                                            self.size[1], clip_near, clip_far)

        self.vertex_buffers = []
        self.index_buffers = []
        self.poses = []

        for model in models:
            self.vertex_buffers.append(gloo.VertexBuffer(model['vertices']))
            self.index_buffers.append(
                gloo.IndexBuffer(model['faces'].flatten().astype(np.uint32)))
            self.poses.append({'R': model['R'], 't': model['t']})

        # We manually draw the hidden canvas
        self.update()
    def __init__(self, *args, **kwargs):
        visual.SphericalVisual.__init__(self, *args, **kwargs)

        self.sphere = sphere.UVSphere(azim_lvls=50, elev_lvls=25)
        self.index_buffer = gloo.IndexBuffer(self.sphere.indices)
        self.position_buffer = gloo.VertexBuffer(self.sphere.a_position)
        self.bg = gloo.Program(
            self.load_vertex_shader('./static_background.vert'),
            self.load_shader('./static_background.frag'))
        self.bg['a_position'] = self.position_buffer
        self.u_color.connect(self.bg)
Exemplo n.º 26
0
    def _set_bbox_buffer(self, colors):
        indices = [
            0, 1, 0, 2, 3, 1, 3, 2, 4, 5, 4, 6, 7, 5, 7, 6, 0, 4, 1, 5, 2, 6,
            3, 7
        ]

        vertices_type = [('a_position', np.float32, 3),
                         ('a_color', np.float32, 3)]
        collated = np.asarray(list(zip(self.bb, colors)), vertices_type)
        self.bb_vbuffer = gloo.VertexBuffer(collated)
        self.bb_ibuffer = gloo.IndexBuffer(indices)
Exemplo n.º 27
0
    def __init__(self, mesh, opacity=1):
        self._shader = gloo.Program(self.VERT_SHADER, self.FRAG_SHADER)
        self._shader['u_opacity'] = opacity
        self._shader['position'] = as_float_array(mesh.vertices)
        self._shader['color'] = as_float_array(mesh.colors)
        self._edges = gloo.IndexBuffer(extract_edges(mesh.faces))

        I = np.eye(4, dtype=np.float32)
        self.set_model_matrix(I)
        self.set_view_matrix(I)
        self.set_projection_matrix(I)
Exemplo n.º 28
0
    def __init__(self):
        visuals.Visual.__init__(self)

        # Create an interesting mesh shape for demonstration.
        fname = io.load_data_file('orig/triceratops.obj.gz')
        vertices, faces, normals, tex = io.read_mesh(fname)

        self._ibo = gloo.IndexBuffer(faces)

        self.program = visuals.shaders.ModularProgram(vertex_shader,
                                                      fragment_shader)
        self.program.vert['position'] = gloo.VertexBuffer(vertices)
Exemplo n.º 29
0
 def _setup_coordinate_system(self):
     self.cs = [[0, 0, 0], [self.diameter * 0.4, 0, 0], [0, 0, 0],
                [0, self.diameter * 0.45, 0], [0, 0, 0],
                [0, 0, self.diameter * 0.4]]
     colors = [[0.8, 0, 0], [0.8, 0, 0], [0, 0.8, 0], [0, 0.8, 0],
               [0, 0, 0.8], [0, 0, 0.8]]
     indices = [0, 1, 2, 3, 4, 5]
     vertices_type = [('a_position', np.float32, 3),
                      ('a_color', np.float32, 3)]
     collated = np.asarray(list(zip(self.cs, colors)), vertices_type)
     self.cs_vbuffer = gloo.VertexBuffer(collated)
     self.cs_ibuffer = gloo.IndexBuffer(indices)
Exemplo n.º 30
0
    def __init__(self):
        app.Canvas.__init__(self,
                            title='Hello OpenGL',
                            keys='interactive')

        self.program1 = gloo.Program(vertex, fragmentWhite)
        self.program2 = gloo.Program(vertex, fragmentOrange)
        self.vertices = gloo.VertexBuffer(np.array([[-0.5, -0.5],
                                          [0.0, -0.5],
                                          [-0.25,  0.5],
                                           [0.5, -0.5],
                                          [0.0, -0.5],
                                          [0.25,  0.5]]).astype(np.float32))

        self.indices1 = gloo.IndexBuffer([0, 1, 2])
        self.indices2 = gloo.IndexBuffer([3, 4, 5])

        self.program1['a_position'] = self.vertices
        self.program2['a_position'] = self.vertices

        self.show()