Example #1
0
    def __init__(self, im, conf, roi, logger):
        vispy.set_log_level('DEBUG')
        try:
            vispy.use(app='glfw', gl='gl+')
        except RuntimeError as e:
            pass

        app.Canvas.__init__(self,
                        keys = 'interactive',
                        size = (conf['ipmWidth'], conf['ipmHeight']),
                        position = (0,0),
                        title = 'IPM',
                        show = False,
                        resizable = False)


        self._rendertex = gloo.Texture2D(shape=(self.size[1], self.size[0], 4))
        self._fbo = gloo.FrameBuffer(self._rendertex,
                                    gloo.RenderBuffer((self.size[1], self.size[0])))

        try:
            fragmentShaderSourceString = open(FRAGMENT_SHADER_FILENAME).read()
        except:
            logger.fatal("%s does not exist !", FRAGMENT_SHADER_FILENAME)
            sys.exit()

        try:
            vertexShaderSourceString = open(VERTEX_SHADER_FILENAME).read()
        except:
            logger.fatal("%s does not exist !", VERTEX_SHADER_FILENAME)
            sys.exit()

        self.program = gloo.Program(vertexShaderSourceString, fragmentShaderSourceString)
        self.program["position"] = [(-1, -1), (-1, 1), (1, 1), (-1, -1), (1, 1), (1, -1)]

        gloo.set_viewport(0, 0, *self.size)

        tex = gloo.Texture2D(im)
        tex.interpolation = 'linear'
        tex.wrapping = 'repeat'
        self.program['iChannel'] = tex
        if len(im.shape) == 3:
            self.program['iChannelResolution'] = (im.shape[1], im.shape[0], im.shape[2])
        else:
            self.program['iChannelResolution'] = (im.shape[1], im.shape[0], 1)
        self.program['iResolution'] = (self.size[0], self.size[1], 0.)

        self.getUniforms(conf, roi)
        self.update()
        app.run()
        return self
Example #2
0
about the z axis and zoom in or out. Holding the alt key while
dragging the mouse cursor will translate the scene; for
two-dimensional scenes, it may be preferable to enable the `pan`
feature, which causes mouse motion to translate, rather than rotate,
the scene by default.

**Keyboard controls:** Live vispy windows also support controlling the
camera via the keyboard. Control or meta in conjunction with the arrow
keys rotate the system in 15 degree increments. The same functionality
is mapped to the I (up), J (left), K (down), and L (right) keys. X, Y,
and Z directly snap the scene to look down the x, y, or z axes,
respectively.
"""

import vispy
vispy.set_log_level('warning')

from .Scene import Scene

from .Box import Box
from .Arrows2D import Arrows2D
from .Disks import Disks
from .DiskUnions import DiskUnions
from .Ellipsoids import Ellipsoids
from .Polygons import Polygons
from .Spheropolygons import Spheropolygons
from .Voronoi import Voronoi
from .Lines import Lines
from .Spheres import Spheres
from .SpherePoints import SpherePoints
from .SphereUnions import SphereUnions
Example #3
0
from vispy import app, gloo, set_log_level
import os.path
import time


set_log_level('INFO')
gloo.gl.use_gl('gl2 debug')


class Canvas(app.Canvas):

    def __init__(self, *args, **kwargs):
        app.Canvas.__init__(self, *args, **kwargs)
        self.program = gloo.Program(self.read_shader('1.vert'), self.read_shader('1.frag'))

        # Fill screen with single quad, fragment shader does all the real work
        self.program["position"] = [(-1, -1), (-1, 1), (1, 1),
                                    (-1, -1), (1, 1), (1, -1)]

        self._starttime = time.time()
        self.program['time'] = 0

        self.program['cameraPos'] = (0.0, 3.0, -6.0)
        self.program['cameraLookat'] = (0.0, -0.85, 0.5)
        self.program['lightDir'] = (-1.4, 0.8, -1.0)  # needs to be normalized
        self.program['lightColour'] = (3.0, 1.4, 0.3)
        self.program['diffuse'] = (0.3, 0.3, 0.3)
        self.program['ambientFactor'] = 0.35
        self.program['rotateWorld'] = 1
        # self.program['ao'] = True
        # self.program['shadows'] = True
Example #4
0
    
    def __init__(self):
        # Create and open the window for user interaction.
        self.window = window.TerminalWindow()

        # Print some default lines in the terminal as hints.
        self.window.log('Operator started the chat.', align='left', color='#808080')
        self.window.log('HAL9000 joined.', align='right', color='#808080')

        # Construct and initialize the agent for this simulation.
        self.agent = HAL9000(self.window)
        self.speak = speaker()
        # Connect the terminal's existing events.
        self.window.events.user_input.connect(self.agent.on_input)
        self.window.events.user_command.connect(self.agent.on_command)

    def run(self):
        timer = vispy.app.Timer(interval=1.0)
        timer.start()
        self.speak.setDaemon(True)
        self.speak.start()
        vispy.app.run()


if __name__ == "__main__":
    vispy.set_log_level('WARNING')
    vispy.use(app='glfw')
    
    app = Application()
    app.run()
Example #5
0
        FileSystemEventHandler.__init__(self)
        self._filename = filename
        self._canvas = canvas

    def on_modified(self, event):
        if os.path.abspath(event.src_path) == self._filename:
            print("Updating shader...")

            glsl_shader = open(self._filename, 'r').read()

            self._canvas.set_shader(glsl_shader)
            self._canvas.update()


if __name__ == '__main__':
    vispy.set_log_level('WARNING')

    # GLFW not part of anaconda python distro; works fine with default (PyQt4)

    try:
        vispy.use(app='glfw')
    except RuntimeError as e:
        pass

    parser = argparse.ArgumentParser(
        description='Render a ShaderToy-style shader from the specified file.')
    parser.add_argument('input',
                        type=str,
                        help='Source shader file to load from disk.')
    parser.add_argument(
        '--size',
import vispy
from vispy import gloo, app
from vispy.io import imsave

vispy.set_log_level("error")

vertex = """

#version 130

in vec2 position;

void main()
{
    gl_Position = vec4(position, 0.0, 1.0);
}
"""

fragment = """

#version 130

uniform vec3      iResolution;           // viewport resolution (in pixels)
uniform float     iTime;                 // shader playback time (in seconds)
uniform float     iTimeDelta;            // render time (in seconds)
uniform vec4      iMouse;                // mouse pixel coords
uniform vec4      iDate;                 // (year, month, day, time in seconds)
uniform float     iSampleRate;           // sound sample rate (i.e., 44100)
uniform sampler2D iChannel0;             // input channel. XX = 2D/Cube
uniform sampler2D iChannel1;             // input channel. XX = 2D/Cube
uniform sampler2D iChannel2;             // input channel. XX = 2D/Cube
Example #7
0
class Application(object):
    def __init__(self):
        # Create and open the window for user interaction.
        self.window = window.TerminalWindow()

        # Print some default lines in the terminal as hints.
        self.window.log("Operator started the chat.", align="left", color="#808080")
        self.window.log("HAL9000 joined.", align="right", color="#808080")

        # Construct and initialize the agent for this simulation.
        self.agent = HAL9000(self.window)

        # Connect the terminal's existing events.
        self.window.events.user_input.connect(self.agent.on_input)
        self.window.events.user_command.connect(self.agent.on_command)

    def run(self):
        timer = vispy.app.Timer(interval=1.0)
        timer.connect(self.agent.update)
        timer.start()

        vispy.app.run()


if __name__ == "__main__":
    vispy.set_log_level("WARNING")
    vispy.use(app="glfw")

    app = Application()
    app.run()
                                         color=(1, 1, 1, 1),
                                         method='gl',
                                         width=1)
            view.add(ma_line)
        except:
            pass

        # view.camera.rect = (0, 0, 800, 7000)
        view.camera.set_range()


if __name__ == '__main__':
    DEBUG = 0
    if DEBUG:
        sys.argv.append("--vispy-fps")
        vispy.set_log_level("info")
        vispy.use(app="PyQt5", gl="pyopengl2")  # pyopengl2 for test
    else:
        vispy.set_log_level("info")
        vispy.use(app="PyQt5", gl="gl2")

    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    vispy_app = vispy.app.use_app()
    vispy.app.create()
    _qt_app = vispy_app.native

    # qt style
    try:
        import qdarkstyle

        _qt_app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())