Пример #1
0
    def __init__(self,
                 transform=None,
                 viewport=None,
                 color=(1, 1, 1, 1),
                 **kwargs):
        dtype = [('position', (np.float32, 2), '!local', (0, 0)),
                 ('texcoord', (np.float32, 2), '!local', (0, 0)),
                 ('offset', (np.float32, 1), '!local', 0),
                 ('origin', (np.float32, 3), 'shared', (0, 0, 0)),
                 ('color', (np.float32, 4), 'shared', color)]

        print('===========================')
        if "vertex" in kwargs.keys():
            vertex = kwargs["vertex"]
            del kwargs["vertex"]
        else:
            vertex = library.get('collections/agg-glyph.vert')

        if "fragment" in kwargs.keys():
            fragment = kwargs["vertex"]
            del kwargs["vertex"]
        else:
            fragment = library.get('collections/agg-glyph.frag')

        Collection.__init__(self,
                            dtype=dtype,
                            itype=np.uint32,
                            mode=gl.GL_TRIANGLES,
                            vertex=vertex,
                            fragment=fragment)

        program = self._programs[0]

        if transform is not None:
            program["transform"] = transform
        else:
            program["transform"] = Position()

        if "viewport" in program.hooks:
            if viewport is not None:
                program["viewport"] = viewport
            else:
                program["viewport"] = Viewport()

        manager = FontManager()
        atlas = manager.atlas_agg
        self['atlas_data'] = atlas
        self['atlas_data'].interpolation = gl.GL_LINEAR
        self['atlas_shape'] = atlas.shape[1], atlas.shape[0]
Пример #2
0
    def __init__(self, transform=None, viewport=None, **kwargs):
        dtype = [('position', (np.float32, 2), '!local', (0, 0)),
                 ('texcoord', (np.float32, 2), '!local', (0, 0)),
                 ('origin', (np.float32, 3), 'shared', (0, 0, 0)),
                 ('direction', (np.float32, 3), 'shared', (1, 0, 0)),
                 ('scale', (np.float32, 1), 'shared', 0.005),
                 ('color', (np.float32, 4), 'shared', (0, 0, 0, 1))]

        if "vertex" in kwargs.keys():
            vertex = library.get(kwargs["vertex"])
            del kwargs["vertex"]
        else:
            vertex = library.get('collections/sdf-glyph.vert')

        if "fragment" in kwargs.keys():
            fragment = library.get(kwargs["fragment"])
            del kwargs["fragment"]
        else:
            fragment = library.get('collections/sdf-glyph.frag')

        Collection.__init__(self,
                            dtype=dtype,
                            itype=np.uint32,
                            mode=gl.GL_TRIANGLES,
                            vertex=vertex,
                            fragment=fragment)
        program = self._programs[0]
        if transform is not None:
            program["transform"] = transform
#        else:
#            program["transform"] = Position()

        if "viewport" in program.hooks:
            if viewport is not None:
                program["viewport"] = viewport
            else:
                program["viewport"] = Viewport()

        manager = FontManager()
        atlas = manager.atlas_sdf
        self['u_kernel'] = data.get("spatial-filters.npy")
        self['atlas_data'] = atlas
        self['atlas_data'].interpolation = gl.GL_LINEAR
        self['atlas_shape'] = atlas.shape[1], atlas.shape[0]
Пример #3
0
"""Based on lorenz.py in glumpy repo."""
from __future__ import division
from glumpy import app
from glumpy.transforms import Position, Trackball, Viewport
from grid import grid
from skeleton_vis import LimbCollection

window = app.Window(width=1000, height=800, color=(1, 1, 1, 1))
transform = Trackball(Position())
viewport = Viewport()

pose_scale = 2.5
ticks = grid(transform, viewport, scale=pose_scale)
limb_collections = []


@window.event
def on_draw(dt):
    window.clear()
    ticks.draw()
    for limb_collection in limb_collections:
        limb_collection.draw()


@window.event
def on_key_press(key, modifiers):
    if key == app.window.key.SPACE:
        reset()


def reset():
Пример #4
0
    def __init__(self, user_dtype=None, transform=None, viewport=None,
                 vertex=None, fragment=None, **kwargs):
        """
        Initialize the collection.

        Parameters
        ----------

        user_dtype: list
            The base dtype can be completed (appended) by the used_dtype. It
            only make sense if user also provide vertex and/or fragment shaders

        viewport: glumpy.Transforms
            The viewport to use to render the collection

        transform: glumpy.Tranforms
            The default vertex shader apply the supplied transform to the
            vertices positions before computing the actual vertices positions
            for path thickness.

        vertex: string
            Vertex shader code

        fragment: string
            Fragment  shader code

        color : string
            'local', 'shared' or 'global'
        """
        base_dtype = [ ('position', (np.float32, 3), "!local", (0,0,0)),
                       ('size',     (np.float32, 1), "global", 3.0),
                       ('color',    (np.float32, 4), "global", (0,0,0,1) ) ]

        dtype = base_dtype
        if user_dtype:
            dtype.extend(user_dtype)

        if vertex is None:
            vertex = library.get("collections/raw-point.vert")
        if fragment is None:
            fragment= library.get("collections/raw-point.frag")

        Collection.__init__(self, dtype=dtype, itype=None, mode=gl.GL_POINTS,
                            vertex=vertex, fragment=fragment, **kwargs)

        # Set hooks if necessary
        program = self._programs[0]

        if "transform" in program.hooks:
            if transform is not None:
                # FIXME: this line break things because snippet code will be included
                #        and it messes with new snippet code
                # program["transform"] = Position()
                program["transform"] = transform
            else:
                program["transform"] = Position()

        if "viewport" in program.hooks:
            if viewport is not None:
                # FIXME: this line break things because snippet code will be included
                #        and it messes with new snippet code
                # program["viewport"] = Viewport()
                program["viewport"] = viewport
            else:
                program["viewport"] = Viewport()
Пример #5
0
    def __init__(self,
                 user_dtype=None,
                 transform=None,
                 viewport=None,
                 vertex=None,
                 fragment=None,
                 **kwargs):
        """
        Initialize the collection.

        Parameters
        ----------

        user_dtype: list
            The base dtype can be completed (appended) by the used_dtype. It
            only make sense if user also provide vertex and/or fragment shaders

        viewport: glumpy.Transforms
            The viewport to use to render the collection

        transform: glumpy.Tranforms
            The default vertex shader apply the supplied transform to the
            vertices positions before computing the actual vertices positions
            for path thickness. Note that it is necessary to add the
            glumpy.transforms.Viewport transform at the end of the supplied transform.

        vertex: string
            Vertex shader code

        fragment: string
            Fragment  shader code

        color : string
            'local', 'shared' or 'global'
        """

        base_dtype = [('position', (np.float32, 3), '!local', (0, 0, 0)),
                      ('id', (np.float32, 1), '!local', 0),
                      ('color', (np.float32, 4), 'local', (0, 0, 0, 1))]

        dtype = base_dtype
        if user_dtype:
            dtype.extend(user_dtype)

        if vertex is None:
            vertex = library.get('collections/raw-path.vert')
        if fragment is None:
            fragment = library.get('collections/raw-path.frag')

        Collection.__init__(self,
                            dtype=dtype,
                            itype=None,
                            mode=gl.GL_LINE_STRIP,
                            vertex=vertex,
                            fragment=fragment,
                            **kwargs)

        # Set hooks if necessary
        program = self._programs[0]
        if "transform" in program.hooks:
            if transform is not None:
                program["transform"] = transform
            else:
                program["transform"] = Position()

        if "viewport" in program.hooks:
            if viewport is not None:
                program["viewport"] = viewport
            else:
                program["viewport"] = Viewport()
Пример #6
0
    def __init__(self,
                 marker='heart',
                 user_dtype=None,
                 transform=None,
                 viewport=None,
                 vertex=None,
                 fragment=None,
                 **kwargs):
        """
        Initialize the collection.

        Parameters
        ----------

        user_dtype: list
            The base dtype can be completed (appended) by the used_dtype. It
            only make sense if user also provide vertex and/or fragment shaders

        transform: glumpy.Tranforms
            The default vertex shader apply the supplied transform to the
            vertices positions before computing the actual vertices positions
            for path thickness. Note that it is necessary to add the
            glumpy.transforms.Viewport transform at the end of the supplied transform.

        vertex: string
            Vertex shader code

        fragment: string
            Fragment  shader code

        size : string
            'local', 'shared' or 'global'

        orientation : string
            'local', 'shared' or 'global'

        fg_color : string
            'local', 'shared' or 'global'

        bg_color : string
            'local', 'shared' or 'global'

        linewidth : string
            'local', 'shared' or 'global'

        antialias : string
            'local', 'shared' or 'global'
        """

        base_dtype = [('position', (np.float32, 3), '!local', (0, 0, 0)),
                      ('size', (np.float32, 1), 'local', 1),
                      ('marker', (np.float32, 1), 'local', 1),
                      ('orientation', (np.float32, 1), 'local', 0.0),
                      ('fg_color', (np.float32, 4), 'local', (0, 0, 0, 1)),
                      ('bg_color', (np.float32, 4), 'local', (1, 1, 1, 1)),
                      ('linewidth', (np.float32, 1), 'global', 1.0),
                      ('antialias', (np.float32, 1), 'global', 1.0)]
        dtype = base_dtype
        if user_dtype:
            dtype.extend(user_dtype)

        if vertex is None:
            vertex = library.get('collections/marker.vert')
        if fragment is None:
            fragment = library.get('collections/marker.frag')

        Collection.__init__(self,
                            dtype=dtype,
                            itype=None,
                            mode=gl.GL_POINTS,
                            vertex=vertex,
                            fragment=fragment,
                            **kwargs)

        # Set hooks if necessary
        program = self._programs[0]
        if "transform" in program.hooks:
            if transform is not None:
                program["transform"] = transform
            else:
                program["transform"] = Position()

        if "viewport" in program.hooks:
            if viewport is not None:
                program["viewport"] = viewport
            else:
                program["viewport"] = Viewport()

        program["marker"] = marker
        program["paint"] = "outline"
Пример #7
0
@window.event
def on_draw(dt):
    window.clear()
    program.draw(gl.GL_TRIANGLE_STRIP)


program = gloo.Program(vertex, fragment, count=4)
program['position'] = [(-1, -1), (-1, +1), (+1, -1), (+1, +1)]
program['texture'] = data.get("earth.jpg")
program['texture'].interpolation = gl.GL_LINEAR
program['major_width'] = 2.0
program['minor_width'] = 1.0
program['major_color'] = 0, 0, 0, 1
program['minor_color'] = 0, 0, 0, 1
program['antialias'] = 1.0
program['viewport'] = Viewport()

# Polar projection
# ----------------

# # This scales texture coordinates into cartesian coordinates
# program['scale1'] = Position(
#     LinearScale(name = 'x', domain=(0,1), range=(-5.1,5.1), discard=False, clamp=False),
#     LinearScale(name = 'y', domain=(0,1), range=(-5.1,5.1), discard=False, clamp=False))

# # Actual projection
# program['projection'] = PolarProjection()
# program['major_step'] = 1.00, np.pi/6
# program['minor_step'] = 0.25, np.pi/60

# # This scales projected coordinates into texture coordinates