How to use the vispy.gloo.VertexBuffer function in vispy

To help you get started, we’ve selected a few vispy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github vispy / vispy / vispy / visuals / gridlines.py View on Github external
def _buffer(self):
        if self._vbo is None:
            # quad covers entire view; frag. shader will deal with image shape
            quad = np.array([[-1, -1, 0], [1, -1, 0], [1, 1, 0],
                             [-1, -1, 0], [1, 1, 0], [-1, 1, 0]],
                            dtype=np.float32)
            self._vbo = gloo.VertexBuffer(quad)
        return self._vbo
github vispy / vispy / examples / demo / gloo / unstructured_2d.py View on Github external
edges = tri.simplices.astype(np.uint32)
        uv = []
        for c in [u, v]:
            if c is not None:
                c = c.astype('f4')
                c = .5 + .5 * c / np.abs(c).max()
                uv.append(c)
        data = np.column_stack(
            [
                x.astype('f4'),
                y.astype('f4')
            ] + uv
        ).view(dtype=[('position', 'f4', (2,)),
                      ('texcoord', 'f4', (2 if v is not None else 1,)),
                      ])
        self.vbo = gloo.VertexBuffer(data)
        self.index = gloo.IndexBuffer(edges)

        gloo.set_state(blend=True, clear_color='white',
                       blend_func=('src_alpha', 'one_minus_src_alpha'))
github EtienneCmb / visbrain / visbrain / vbrain / visuals / ConnectVisual.py View on Github external
def update_position(self):
        """
        """
        self.shared_program.vert['a_position'] = gloo.VertexBuffer(
                                            self.a_position.astype(np.float32))
github wonambi-python / wonambi / wonambi / viz / visuals.py View on Github external
def __init__(self, meshdata):
        Visual.__init__(self, VERT_SHADER, FRAG_SHADER)

        v = meshdata.get_vertices(indexed='faces').astype(float32)
        self._vertices = VertexBuffer(v)

        v_norm = meshdata.get_vertex_normals(indexed='faces').astype(float32)
        self._normals = VertexBuffer(v_norm)

        v_col = meshdata.get_vertex_colors(indexed='faces').astype(float32)
        self._colors = VertexBuffer(v_col)

        self.set_light(position=(1., 0., 0.),
                       ambient=.2,
                       diffuse=.8,
                       )
        self._draw_mode = 'triangles'
        # self.set_gl_state('opaque', depth_test=True, cull_face=True)
        self.set_gl_state('translucent', depth_test=True, cull_face=False, blend=True, blend_func=('src_alpha', 'one_minus_src_alpha'))
github vispy / vispy / examples / demo / gloo / molecular_viewer.py View on Github external
def load_data(self):
        n = self._nAtoms

        data = np.zeros(n, [('a_position', np.float32, 3),
                            ('a_color', np.float32, 3),
                            ('a_radius', np.float32, 1)])

        data['a_position'] = self.coords
        data['a_color'] = self.atomsColours
        data['a_radius'] = self.atomsScales*self.ps

        self.program.bind(gloo.VertexBuffer(data))

        self.program['u_model'] = self.model
        self.program['u_view'] = self.view
        self.program['u_light_position'] = 0., 0., 2.
        self.program['u_light_spec_position'] = -5., 5., -5.
github vispy / vispy / vispy / scene / visuals / line.py View on Github external
connect.
        """
        if pos is not None:
            vbo = gloo.VertexBuffer(np.asarray(pos, dtype=np.float32))
            if pos.shape[-1] == 2:
                self._pos_expr = vec2to4(vbo)
            elif pos.shape[-1] == 3:
                self._pos_expr = vec3to4(vbo)
            else:
                raise TypeError("pos array should have 2 or 3 elements in last"
                                " axis.")
            self._vbo = vbo
        
        if color is not None:
            if isinstance(color, np.ndarray) and color.ndim > 1:
                self._color = gloo.VertexBuffer(color.astype(np.float32))
            else:
                self._color = Color(color).rgba
                
        if connect is not None:
            if isinstance(connect, np.ndarray):
                self._connect = gloo.IndexBuffer(connect.astype(np.uint32))
            else:
                self._connect = connect
            
        self.update()
github EtienneCmb / visbrain / visbrain / ndviz / visuals / NdpltMesh.py View on Github external
# ----------------------------------
        # Not found color :
        else:
            raise ValueError("The color parameter is not recognized.")

        # Get a (m, n, 3) color array copy :
        # self._colsh = a_color.reshape(self.m, self.n, 3)

        #######################################################################
        # BUFFER
        #######################################################################
        # =====================================================
        # Data buffer :
        self._dbuffer = gloo.VertexBuffer((data-data_mean)/data_max)
        self._ibuffer = gloo.VertexBuffer(index)
        self.shared_program.vert['a_position'] = self._dbuffer
        self.shared_program.vert['a_index'] = self._ibuffer
        # =====================================================
        # Color buffer :
        self._cbuffer = gloo.VertexBuffer(np.ascontiguousarray(a_color))
        self.shared_program.vert['a_color'] = self._cbuffer
        # =====================================================
        # Args buffer :
        self.shared_program.vert['u_scale'] = scale
        self.shared_program.vert['u_size'] = self.dim
        self.shared_program.vert['u_n'] = n
        self.shared_program.vert['u_space'] = space
github vispy / vispy / examples / basics / visuals / line_visual2.py View on Github external
# Define how we are going to specify position and color
        self._program.vert['gl_Position'] = '$transform(vec4($position, 1.0))'
        self._program.frag['gl_FragColor'] = 'vec4($color, 1.0)'
        
        # Set position data
        assert data is not None
        vbo = gloo.VertexBuffer(data)
        self._program.vert['position'] = vbo
        
        self._program.vert['transform'] = self.transform.shader_map()
        
        # Create some variables related to color. We use a combination
        # of these depending on the kind of color being set.
        # We predefine them here so that we can re-use VBO and uniforms
        vbo = gloo.VertexBuffer(data)
        self._color_var = Variable('uniform vec3 color')
        self._colors_var = Variable('attribute vec3 color', vbo)
        self._color_varying = Varying('v_color')
        
        self.set_color((0, 0, 1))
        if color is not None:
            self.set_color(color)
github EtienneCmb / visbrain / visbrain / visuals / brain_visual.py View on Github external
self._alphas[vertices, to_overlay] = 1.  # transparency level

        # -------------------------------------------------------------
        # TEXTURE COLOR
        # -------------------------------------------------------------
        # Colormap interpolation (if needed):
        colormap = Colormap(**kwargs)
        vec = np.linspace(data_lim[0], data_lim[1], LUT_LEN)
        self._text2d_data[to_overlay, ...] = colormap.to_rgba(vec)

        # -------------------------------------------------------------
        # BUFFERS
        # -------------------------------------------------------------
        if need_reshape:
            # Re-define buffers :
            self._xrange_buffer = gloo.VertexBuffer(self._xrange)
            self._text2d = gloo.Texture2D(self._text2d_data)
            self._alphas_buffer = gloo.VertexBuffer(self._alphas)
            # Send buffers to vertex shader :
            self.shared_program.vert['u_range'] = self._xrange_buffer
            self.shared_program.vert['u_alphas'] = self._alphas_buffer
            self.shared_program.vert['u_over_text'] = self._text2d
        else:
            self._xrange_buffer.set_data(self._xrange)
            self._text2d.set_data(self._text2d_data)
            self._alphas_buffer.set_data(self._alphas)
        # Update the number of overlays :
        self._n_overlay = to_overlay + 1
        self.shared_program.vert['u_n_overlays'] = self._n_overlay
github spyking-circus / spyking-circus-ort / circusort / block / gui / views / traces.py View on Github external
mads_thresholds = np.zeros((nb_samples_per_signal * self.nb_channels,), dtype=np.float32)

        # Channel selection
        channel_selected_signal = np.ones(self.nb_channels*nb_samples_per_signal, dtype=np.float32)
        channel_selected_mads = np.ones(self.nb_channels*2*(nb_buffers_per_signal+1), dtype=np.float32)
        channel_selected_box = np.ones(self.nb_channels*5, dtype=np.float32)

        # Define GLSL program.
        self.programs['signals'] = LinesPlot(vert=SIGNAL_VERT_SHADER, frag=SIGNAL_FRAG_SHADER)
        self.programs['signals']['a_signal_index'] = gloo.VertexBuffer(signal_indices)
        self.programs['signals']['a_signal_position'] = gloo.VertexBuffer(signal_positions)
        self.programs['signals']['a_signal_value'] = gloo.VertexBuffer(self._signal_values.reshape(-1, 1))
        self.programs['signals']['a_spike_threshold'] = mads_thresholds
        self.programs['signals']['a_channel_selected_signal'] = channel_selected_signal
        self.programs['signals']['a_color_spikes'] = 1.0
        self.programs['signals']['a_sample_index'] = gloo.VertexBuffer(sample_indices)
        self.programs['signals']['u_nb_samples_per_signal'] = nb_samples_per_signal
        self.programs['signals']['u_x_min'] = self.probe.x_limits[0]
        self.programs['signals']['u_x_max'] = self.probe.x_limits[1]
        self.programs['signals']['u_y_min'] = self.probe.y_limits[0]
        self.programs['signals']['u_y_max'] = self.probe.y_limits[1]
        self.programs['signals']['u_d_scale'] = self.probe.minimum_interelectrode_distance
        self.programs['signals']['u_t_scale'] = self._time_max / params['time']['init']
        self.programs['signals']['u_v_scale'] = params['voltage']['init']

        # MADs.

        # Generate the MADs values.
        mads_indices = np.arange(0, self.nb_channels, dtype=np.float32)
        mads_indices = np.repeat(mads_indices, repeats=2 * (nb_buffers_per_signal + 1))
        mads_positions = np.c_[
            np.repeat(self.probe.x.astype(np.float32), repeats=2 * (nb_buffers_per_signal + 1)),