Beispiel #1
0
def axis_visual(scale=1.0, parent=None):
    """
    Returns a :class:`vispy.scene.visuals.XYZAxis` class instance using given
    scale.

    Parameters
    ----------
    scale : numeric, optional
        Axis visual scale.
    parent : Node, optional
        Parent of the axis visual in the `SceneGraph`.

    Returns
    -------
    XYZAxis
        Axis visual.
    """

    axis = XYZAxis(parent=parent)

    transform = AffineTransform()
    transform.scale((scale, scale, scale))
    axis.transform = transform

    return axis
Beispiel #2
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive', size=(800, 550))

        self.meshes = []
        self.rotation = AffineTransform()

        # Generate some data to work with
        global mdata
        mdata = create_sphere(20, 40, 1.0)

        # Mesh with pre-indexed vertices, uniform color
        self.meshes.append(visuals.MeshVisual(meshdata=mdata, color='r'))

        ## Mesh with pre-indexed vertices, per-face color
        ##   Because vertices are pre-indexed, we get a different color
        ##   every time a vertex is visited, resulting in sharp color
        ##   differences between edges.
        verts = mdata.get_vertices(indexed='faces')
        nf = verts.size // 9
        fcolor = np.ones((nf, 3, 4), dtype=np.float32)
        fcolor[..., 0] = np.linspace(1, 0, nf)[:, np.newaxis]
        fcolor[..., 1] = np.random.normal(size=nf)[:, np.newaxis]
        fcolor[..., 2] = np.linspace(0, 1, nf)[:, np.newaxis]
        mesh = visuals.MeshVisual(vertices=verts, face_colors=fcolor)
        self.meshes.append(mesh)

        ## Mesh with unindexed vertices, per-vertex color
        ##   Because vertices are unindexed, we get the same color
        ##   every time a vertex is visited, resulting in no color differences
        ##   between edges.
        verts = mdata.get_vertices()
        faces = mdata.get_faces()
        nv = verts.size // 3
        vcolor = np.ones((nv, 4), dtype=np.float32)
        vcolor[:, 0] = np.linspace(1, 0, nv)
        vcolor[:, 1] = np.random.normal(size=nv)
        vcolor[:, 2] = np.linspace(0, 1, nv)
        self.meshes.append(visuals.MeshVisual(verts, faces, vcolor))
        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, 1)), self.rotation
            ])
            tr_sys = visuals.transforms.TransformSystem(self)
            tr_sys.visual_to_document = transform
            mesh.tr_sys = tr_sys

        self.show()

        self.timer = app.Timer(connect=self.rotate)
        self.timer.start(0.016)
Beispiel #3
0
    def __init__(self):
        self.images = [visuals.ImageVisual(image, method='impostor')
                       for i in range(4)]
        self.images[0].transform = (STTransform(scale=(30, 30),
                                                translate=(600, 600)) * 
                                    SineTransform() *
                                    STTransform(scale=(0.1, 0.1),
                                                translate=(-5, -5)))

        tr = AffineTransform()
        tr.rotate(30, (0, 0, 1))
        tr.scale((3, 3))
        self.images[1].transform = (STTransform(translate=(200, 600)) *
                                    tr *
                                    STTransform(translate=(-50, -50)))

        self.images[2].transform = (STTransform(scale=(3, -150),
                                                translate=(200, 100)) *
                                    LogTransform((0, 2, 0)) *
                                    STTransform(scale=(1, -0.01),
                                                translate=(-50, 1.3)))

        self.images[3].transform = (STTransform(scale=(400, 400),
                                                translate=(600, 300)) *
                                    PolarTransform() *
                                    STTransform(scale=(np.pi/200, 0.005),
                                                translate=(-3*np.pi/4., 0.1)))

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

        for img in self.images:
            img.tr_sys = TransformSystem(self)
            img.tr_sys.visual_to_document = img.transform
Beispiel #4
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive', size=(800, 550))
        
        self.meshes = []
        self.rotation = AffineTransform()

        # Generate some data to work with
        global mdata
        mdata = create_sphere(20, 40, 1.0)

        # Mesh with pre-indexed vertices, uniform color
        self.meshes.append(visuals.MeshVisual(meshdata=mdata, color='r'))

        ## Mesh with pre-indexed vertices, per-face color
        ##   Because vertices are pre-indexed, we get a different color
        ##   every time a vertex is visited, resulting in sharp color
        ##   differences between edges.
        verts = mdata.get_vertices(indexed='faces')
        nf = verts.size//9
        fcolor = np.ones((nf, 3, 4), dtype=np.float32)
        fcolor[..., 0] = np.linspace(1, 0, nf)[:, np.newaxis]
        fcolor[..., 1] = np.random.normal(size=nf)[:, np.newaxis]
        fcolor[..., 2] = np.linspace(0, 1, nf)[:, np.newaxis]
        mesh = visuals.MeshVisual(vertices=verts, face_colors=fcolor)
        self.meshes.append(mesh)

        ## Mesh with unindexed vertices, per-vertex color
        ##   Because vertices are unindexed, we get the same color
        ##   every time a vertex is visited, resulting in no color differences
        ##   between edges.
        verts = mdata.get_vertices()
        faces = mdata.get_faces()
        nv = verts.size//3
        vcolor = np.ones((nv, 4), dtype=np.float32)
        vcolor[:, 0] = np.linspace(1, 0, nv)
        vcolor[:, 1] = np.random.normal(size=nv)
        vcolor[:, 2] = np.linspace(0, 1, nv)
        self.meshes.append(visuals.MeshVisual(verts, faces, vcolor))
        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, 1)),
                                        self.rotation])
            tr_sys = visuals.transforms.TransformSystem(self)
            tr_sys.visual_to_document = transform
            mesh.tr_sys = tr_sys

        self.show()

        self.timer = app.Timer(connect=self.rotate)
        self.timer.start(0.016)
Beispiel #5
0
    def __init__(self):
        vispy.app.Canvas.__init__(self, keys='interactive', size=(800, 800))

        self.images = [visuals.ImageVisual(image, method='impostor')
                       for i in range(4)]
        self.images[0].transform = (STTransform(scale=(30, 30),
                                                translate=(600, 600)) *
                                    SineTransform() *
                                    STTransform(scale=(0.1, 0.1),
                                                translate=(-5, -5)))

        tr = AffineTransform()
        tr.rotate(30, (0, 0, 1))
        tr.scale((3, 3))
        self.images[1].transform = (STTransform(translate=(200, 600)) *
                                    tr *
                                    STTransform(translate=(-50, -50)))

        self.images[2].transform = (STTransform(scale=(3, -150),
                                                translate=(200, 100)) *
                                    LogTransform((0, 2, 0)) *
                                    STTransform(scale=(1, -0.01),
                                                translate=(-50, 1.3)))

        self.images[3].transform = (STTransform(scale=(400, 400),
                                                translate=(600, 300)) *
                                    PolarTransform() *
                                    STTransform(scale=(np.pi/200, 0.005),
                                                translate=(-3*np.pi/4., 0.1)))

        for img in self.images:
            img.tr_sys = TransformSystem(self)
            img.tr_sys.visual_to_document = img.transform

        self.show()
Beispiel #6
0
    def __init__(self):
        app.Canvas.__init__(self, keys=None, size=(360, 360))

        self.data = np.zeros((360, 360))

        for i in range(0,90):
            self.data[i,:] = i * 90

        self.image = visuals.ImageVisual(self.data, method='auto', cmap='cubehelix', clim='auto')
        self.image.tr_sys = TransformSystem(self)

        tr = AffineTransform()
        tr.rotate(90, (0, 0, 1))
        self.image.transform = (STTransform(scale=(3.5,3.5), translate=(180, 180, 1)) *
                                tr *
                                PolarTransform())
        self.image.tr_sys.visual_to_document = self.image.transform

        self._timer = app.Timer(start=False)
        self._timer.connect(self.update)
        self._timer.start()
        self.show()
        self.measure_fps()
Beispiel #7
0
    def __init__(self):

        # Define several Line visuals that use the same position data
        # but have different colors and transformations
        colors = [color, (1, 0, 0, 1), (0, 1, 0, 1), (0, 0, 1, 1),
                  (1, 1, 0, 1), (1, 1, 1, 1)]

        self.lines = [visuals.LineVisual(pos=pos, color=colors[i])
                      for i in range(6)]

        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 = AffineTransform()
        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)))

        app.Canvas.__init__(self, keys='interactive')
        self.size = (800, 800)
        self.show()
        
        for line in self.lines:
            tr_sys = visuals.transforms.TransformSystem(self)
            tr_sys.visual_to_document = line.transform
            line.tr_sys = tr_sys
Beispiel #8
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')
        
        self.meshes = []
        self.rotation = AffineTransform()

        # Generate some data to work with
        global mdata
        mdata = create_sphere(20, 40, 1.0)

        # Mesh with pre-indexed vertices, uniform color
        verts = mdata.get_vertices(indexed='faces')
        mesh = ModularMesh(pos=verts, color=(1, 0, 0, 1))
        self.meshes.append(mesh)

        # Mesh with pre-indexed vertices, per-face color
        #   Because vertices are pre-indexed, we get a different color
        #   every time a vertex is visited, resulting in sharp color
        #   differences between edges.
        nf = verts.size//9
        fcolor = np.ones((nf, 3, 4), dtype=np.float32)
        fcolor[..., 0] = np.linspace(1, 0, nf)[:, np.newaxis]
        fcolor[..., 1] = np.random.normal(size=nf)[:, np.newaxis]
        fcolor[..., 2] = np.linspace(0, 1, nf)[:, np.newaxis]
        mesh = ModularMesh(pos=verts, color=fcolor)
        self.meshes.append(mesh)

        # Mesh with unindexed vertices, per-vertex color
        #   Because vertices are unindexed, we get the same color
        #   every time a vertex is visited, resulting in no color differences
        #   between edges.
        verts = mdata.get_vertices()
        faces = mdata.get_faces()
        nv = verts.size//3
        vcolor = np.ones((nv, 4), dtype=np.float32)
        vcolor[:, 0] = np.linspace(1, 0, nv)
        vcolor[:, 1] = np.random.normal(size=nv)
        vcolor[:, 2] = np.linspace(0, 1, nv)
        mesh = ModularMesh(pos=verts, faces=faces, color=vcolor)
        self.meshes.append(mesh)

        # Mesh colored by vertices + grid contours
        mesh = ModularMesh(pos=verts, faces=faces)
        mesh.color_components = [VertexColorComponent(vcolor),
                                 GridContourComponent(spacing=(0.13, 0.13,
                                                               0.13))]
        self.meshes.append(mesh)

        # Phong shaded mesh
        mesh = ModularMesh(pos=verts, faces=faces)
        normal_comp = VertexNormalComponent(mdata)
        mesh.color_components = [VertexColorComponent(vcolor),
                                 GridContourComponent(spacing=(0.1, 0.1, 0.1)),
                                 ShadingComponent(normal_comp,
                                                  lights=[((-1, 1, -1),
                                                          (1.0, 1.0, 1.0))],
                                                  ambient=0.2)]
        self.meshes.append(mesh)

        # Phong shaded mesh, flat faces
        mesh = ModularMesh(pos=mdata.get_vertices(indexed='faces'))
        normal_comp = VertexNormalComponent(mdata, smooth=False)
        mesh.color_components = [
            VertexColorComponent(vcolor[mdata.get_faces()]),
            GridContourComponent(spacing=(0.1, 0.1, 0.1)),
            ShadingComponent(normal_comp, lights=[((-1, 1, -1),
                                                  (1.0, 1.0, 1.0))],
                             ambient=0.2)]
        self.meshes.append(mesh)

        # 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
            mesh.transform = ChainTransform([STTransform(translate=(x, y),
                                                         scale=(s, s, 1)),
                                             self.rotation])
            mesh.tr_sys = visuals.transforms.TransformSystem(self)
            mesh.tr_sys.visual_to_document = mesh.transform

        self.size = (800, 800)
        self.show()

        self.timer = app.Timer(connect=self.rotate)
        self.timer.start(0.016)
Beispiel #9
0
    def __init__(self):
        app.Canvas.__init__(self, keys='interactive')

        self.meshes = []
        self.rotation = AffineTransform()

        # Generate some data to work with
        global mdata
        mdata = create_sphere(20, 40, 1.0)

        # Mesh with pre-indexed vertices, uniform color
        verts = mdata.get_vertices(indexed='faces')
        mesh = ModularMesh(pos=verts, color=(1, 0, 0, 1))
        self.meshes.append(mesh)

        # Mesh with pre-indexed vertices, per-face color
        #   Because vertices are pre-indexed, we get a different color
        #   every time a vertex is visited, resulting in sharp color
        #   differences between edges.
        nf = verts.size // 9
        fcolor = np.ones((nf, 3, 4), dtype=np.float32)
        fcolor[..., 0] = np.linspace(1, 0, nf)[:, np.newaxis]
        fcolor[..., 1] = np.random.normal(size=nf)[:, np.newaxis]
        fcolor[..., 2] = np.linspace(0, 1, nf)[:, np.newaxis]
        mesh = ModularMesh(pos=verts, color=fcolor)
        self.meshes.append(mesh)

        # Mesh with unindexed vertices, per-vertex color
        #   Because vertices are unindexed, we get the same color
        #   every time a vertex is visited, resulting in no color differences
        #   between edges.
        verts = mdata.get_vertices()
        faces = mdata.get_faces()
        nv = verts.size // 3
        vcolor = np.ones((nv, 4), dtype=np.float32)
        vcolor[:, 0] = np.linspace(1, 0, nv)
        vcolor[:, 1] = np.random.normal(size=nv)
        vcolor[:, 2] = np.linspace(0, 1, nv)
        mesh = ModularMesh(pos=verts, faces=faces, color=vcolor)
        self.meshes.append(mesh)

        # Mesh colored by vertices + grid contours
        mesh = ModularMesh(pos=verts, faces=faces)
        mesh.color_components = [
            VertexColorComponent(vcolor),
            GridContourComponent(spacing=(0.13, 0.13, 0.13))
        ]
        self.meshes.append(mesh)

        # Phong shaded mesh
        mesh = ModularMesh(pos=verts, faces=faces)
        normal_comp = VertexNormalComponent(mdata)
        mesh.color_components = [
            VertexColorComponent(vcolor),
            GridContourComponent(spacing=(0.1, 0.1, 0.1)),
            ShadingComponent(normal_comp,
                             lights=[((-1, 1, -1), (1.0, 1.0, 1.0))],
                             ambient=0.2)
        ]
        self.meshes.append(mesh)

        # Phong shaded mesh, flat faces
        mesh = ModularMesh(pos=mdata.get_vertices(indexed='faces'))
        normal_comp = VertexNormalComponent(mdata, smooth=False)
        mesh.color_components = [
            VertexColorComponent(vcolor[mdata.get_faces()]),
            GridContourComponent(spacing=(0.1, 0.1, 0.1)),
            ShadingComponent(normal_comp,
                             lights=[((-1, 1, -1), (1.0, 1.0, 1.0))],
                             ambient=0.2)
        ]
        self.meshes.append(mesh)

        # 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
            mesh.transform = ChainTransform([
                STTransform(translate=(x, y), scale=(s, s, 1)), self.rotation
            ])
            mesh.tr_sys = visuals.transforms.TransformSystem(self)
            mesh.tr_sys.visual_to_document = mesh.transform

        self.size = (800, 800)
        self.show()

        self.timer = app.Timer(connect=self.rotate)
        self.timer.start(0.016)