How to use the vispy.visuals.transforms.STTransform 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 / examples / basics / visuals / mesh.py View on Github external
self.meshes.append(visuals.MeshVisual(verts, faces, vcolor,
                                              shading='flat'))
        self.meshes.append(visuals.MeshVisual(verts, faces, vcolor,
                                              shading='smooth'))

        # Lay out meshes in a grid
        grid = (3, 3)
        s = 300. / max(grid)
        for i, mesh in enumerate(self.meshes):
            x = 800. * (i % grid[0]) / grid[0] + 400. / grid[0] - 2
            y = 800. * (i // grid[1]) / grid[1] + 400. / grid[1] + 2
            transform = ChainTransform([STTransform(translate=(x, y),
                                                    scale=(s, s, s)),
                                        self.rotation])
            mesh.transform = transform
            mesh.transforms.scene_transform = STTransform(scale=(1, 1, 0.01))

        self.show()

        self.timer = app.Timer(connect=self.rotate)
        self.timer.start(0.016)
github vispy / vispy / examples / basics / visuals / polygon_visual.py View on Github external
def __init__(self):
        app.Canvas.__init__(self, keys='interactive', size=(800, 800))
        global pos
        self.visuals = []
        polygon = visuals.PolygonVisual(pos=pos, color=(0.8, .2, 0, 1),
                                        border_color=(1, 1, 1, 1),
                                        border_width=3)
        polygon.transform = transforms.STTransform(scale=(200, 200),
                                                   translate=(600, 600))
        self.visuals.append(polygon)

        ellipse = visuals.EllipseVisual(center=(0, 0, 0), radius=(100, 150),
                                        color=(0.2, 0.2, 0.8, 1),
                                        border_color=(1, 1, 1, 1),
                                        border_width=3,
                                        start_angle=180., span_angle=150.)
        ellipse.transform = transforms.STTransform(scale=(0.9, 1.5),
                                                   translate=(200, 300))
        self.visuals.append(ellipse)

        rect = visuals.RectangleVisual(center=(600, 200, 0), height=200.,
                                       width=300.,
                                       radius=[30., 30., 0., 0.],
                                       color=(0.5, 0.5, 0.2, 1),
github EtienneCmb / visbrain / visbrain / objects / visbrain_obj.py View on Github external
def __init__(self, name, parent=None, transform=None, verbose=None, **kw):
        """Init."""
        _VisbrainObj.__init__(self, **kw)
        self._node = vispy.scene.Node(name=name)
        self._node.parent = parent
        self._csize = None  # canvas size
        self._shortcuts = {}
        # Name :
        assert isinstance(name, str)
        self._name = name
        # Transformation :
        if transform is None:
            transform = vist.STTransform()
        self._node.transform = transform
        # Verbose :
        set_log_level(verbose)
        logger.info('%s created' % repr(self))
github EtienneCmb / visbrain / visbrain / objects / source_obj.py View on Github external
symbol=symbol, parent=self._node)
        self._sources.set_gl_state('translucent', depth_test=True,
                                   cull_face=False)

        # _______________________ TEXT _______________________
        tvisible = text is None
        self._text = [''] * len(self) if tvisible else text
        self._text = np.array(self._text)
        assert len(self._text) == len(self)
        self._sources_text = visuals.Text(self._text, pos=self._xyz,
                                          bold=text_bold, name='Text',
                                          color=color2vb(text_color),
                                          font_size=text_size,
                                          parent=self._node)
        self._sources_text.visible = not tvisible
        tr = vist.STTransform(translate=text_translate)
        self._sources_text.transform = tr

        # _______________________ UPDATE _______________________
        # Radius / color :
        self.visible = visible
        self._update_radius()
        self.alpha = alpha
        self._update_color()
github vispy / vispy / examples / basics / visuals / line_transform.py View on Github external
self.lines[3].transform = (center *
                                   STTransform(translate=(-200, -200, 0),
                                               scale=(200, 1)) *
                                   LogTransform(base=(10, 0, 0)) *
                                   STTransform(translate=(1, 0, 0)))

        self.lines[4].transform = MatrixTransform()
        self.lines[4].transform.rotate(45, (0, 0, 1))
        self.lines[4].transform.scale((0.3, 0.3, 1))
        self.lines[4].transform.translate((200, 200, 0))

        self.lines[5].transform = (STTransform(translate=(200, 600, 0),
                                               scale=(5, 5)) *
                                   PolarTransform() *
                                   LogTransform(base=(2, 0, 0)) *
                                   STTransform(scale=(0.01, 0.1),
                                               translate=(4, 20)))

        self.show()
github ssec / sift / uwsift / view / scene_graph.py View on Github external
layer[Info.CELL_WIDTH],
            layer[Info.CELL_HEIGHT],
            name=str(uuid),
            clim=p.climits,
            gamma=p.gamma,
            interpolation='nearest',
            method='tiled',
            cmap=self.document.find_colormap(p.colormap),
            double=False,
            texture_shape=DEFAULT_TEXTURE_SHAPE,
            wrap_lon=False,
            parent=self.main_map,
            projection=layer[Info.PROJ],
        )
        image.transform = PROJ4Transform(layer[Info.PROJ], inverse=True)
        image.transform *= STTransform(translate=(0, 0, -50.0))
        self.image_elements[uuid] = image
        self.layer_set.add_layer(image)
        image.determine_reference_points()
        self.on_view_change(None)
github vispy / vispy / examples / basics / visuals / modular_components.py View on Github external
dasher = DashComponent(pos)
        self.line.color_components = [VertexColorComponent(color), dasher]

        app.Canvas.__init__(self, keys='interactive')
        self.size = (800, 800)
        self.show()

        self.timer = app.Timer(connect=self.wobble,
                                     interval=0.02,
                                     start=True)
        
        self.tr_sys = visuals.transforms.TransformSystem(self)
        self.tr_sys.visual_to_document = (STTransform(scale=(40, 100), 
                                                      translate=(400, 400)) *
                                          SineTransform() *
                                          STTransform(scale=(10, 3)))
github HENDRIX-ZT2 / pyaudiorestoration / pyaudiorestoration / util / spectrum.py View on Github external
range(0, num_bins, self.MAX_TEXTURE_SIZE)]):
			imdata_piece = imdata[y:y + self.MAX_TEXTURE_SIZE, x:x + self.MAX_TEXTURE_SIZE]
			num_piece_bins, num_piece_ffts = imdata_piece.shape

			# to get correct heights for subsequent pieces, the start y has to be added in mel space
			height_Hz_in = int(num_piece_bins / num_bins * sr / 2)
			ystart_Hz = (y / num_bins * sr / 2)
			height_Hz_corrected = to_Hz(to_mel(height_Hz_in + ystart_Hz) - to_mel(ystart_Hz))
			x_start = x * hop / sr + self.delta
			x_len = num_piece_ffts * hop / sr

			# do the dB conversion here because the tracers don't like it
			self.pieces[i].tex.set_data(units.to_dB(imdata_piece))
			self.pieces[i].set_size((x_len, height_Hz_corrected))
			# add this piece's offset with STT
			self.pieces[i].transform = visuals.transforms.STTransform(
				translate=(x_start, to_mel(ystart_Hz))) * self.mel_transform
			self.pieces[i].bb.left = x_start
			self.pieces[i].bb.right = x_start + x_len
			self.pieces[i].update()
			self.pieces[i].show()
github EtienneCmb / visbrain / visbrain / objects / topo_obj.py View on Github external
self.node_headfull.transform = circle
            # Text translation :
            tr = np.array([0., .8, 0.]) + np.array(chan_offset)
        else:
            # Get coordinates of references along the x and y-axis :
            ref_x, ref_y = self._get_ref_coordinates()
            # Recenter the topoplot :
            t = vist.ChainTransform()
            t.prepend(vprecenter(head))
            # Rescale (-ref_x:ref_x, -ref_y:ref_y) (ref_x != ref_y => ellipse)
            coef_x = 2 * ref_x / head[:, 0].max()
            coef_y = 2 * ref_y / head[:, 1].max()
            t.prepend(vist.STTransform(scale=(coef_x, coef_y, 1.)))
            self.node_head.transform = t
            # Rescale between (-1:1, -1:1) = circle :
            circle = vist.STTransform(scale=(.5 / ref_x, .5 / ref_y, 1.))
            self.node_headfull.transform = circle
            # Text translation :
            tr = np.array([0., .04, 0.]) + np.array(chan_offset)
        self.chan_text.transform = vist.STTransform(translate=tr)

        # ================== GRID INTERPOLATION ==================
        # Interpolation vectors :
        x = y = np.arange(0, self._pix, 1)
        xnew = ynew = np.arange(0, self._pix, self._interp)

        # Grid interpolation function :
        def _grid_interpolation(grid):
            f = interp2d(x, y, grid, kind='linear')
            return f(xnew, ynew)
        self._grid_interpolation = _grid_interpolation
github vispy / vispy / examples / basics / visuals / line_transform.py View on Github external
center = STTransform(translate=(400, 400))

        self.lines[0].transform = center

        self.lines[1].transform = (center *
                                   STTransform(scale=(1, 0.1, 1)))

        self.lines[2].transform = (center *
                                   STTransform(translate=(200, 200, 0)) *
                                   STTransform(scale=(0.3, 0.5, 1)))

        self.lines[3].transform = (center *
                                   STTransform(translate=(-200, -200, 0),
                                               scale=(200, 1)) *
                                   LogTransform(base=(10, 0, 0)) *
                                   STTransform(translate=(1, 0, 0)))

        self.lines[4].transform = MatrixTransform()
        self.lines[4].transform.rotate(45, (0, 0, 1))
        self.lines[4].transform.scale((0.3, 0.3, 1))
        self.lines[4].transform.translate((200, 200, 0))

        self.lines[5].transform = (STTransform(translate=(200, 600, 0),
                                               scale=(5, 5)) *
                                   PolarTransform() *
                                   LogTransform(base=(2, 0, 0)) *
                                   STTransform(scale=(0.01, 0.1),
                                               translate=(4, 20)))

        self.show()