Example #1
0
def test_show_entity():
    """Test showing an entity"""
    # Create a figure
    app = Application()
    fig = scene.CanvasWithScene(app=app)
    app.create()
    fig.size = 1, 1
    fig.show()
    camcontainer = scene.PixelCamera(fig.viewbox)
    camera = scene.ThreeDCamera(camcontainer)
    camera._fov = 90
    fig.viewbox.camera = camera
    pointscontainer = scene.Entity(fig.viewbox)
    scene.PointsEntity(pointscontainer, 1000)
    app.process_events()
    app.process_events()  # for good measure

    # Now do first-person
    camcontainer = scene.PixelCamera(fig.viewbox)
    camera = scene.FirstPersonCamera(camcontainer)
    camera.update_angles()
    fig.viewbox.camera = camera
    pointscontainer = scene.Entity(fig.viewbox)
    scene.PointsEntity(pointscontainer, 1000)
    app.process_events()
    app.process_events()  # for good measure

    # Now do 2D
    camcontainer = scene.PixelCamera(fig.viewbox)
    camera = scene.TwoDCamera(camcontainer)
    camera.xlim = -100, 500
    camera.ylim = -100, 500
    fig.viewbox.camera = camera
    pointscontainer = scene.Entity(fig.viewbox)
    scene.PointsEntity(pointscontainer, 1000)
    transforms.translate(camcontainer.transform, 50, 50)
    transforms.rotate(camcontainer.transform, 10, 0, 0, 1)
    app.process_events()
    app.process_events()  # for good measure

    fig.close()
    app.quit()
async def viewer(receive_channel, shape):
    display_shape = (512, 512)

    # init app
    app = Application()
    app.create()

    # init viewer
    canvas = scene.SceneCanvas(app=app, keys="interactive")
    canvas.size = display_shape

    # create view and image
    view = canvas.central_widget.add_view()

    # lock view
    view.camera = scene.PanZoomCamera(aspect=1, interactive=False)
    view.camera.flip = (0, 1, 0)

    image = scene.visuals.Image(np.empty(display_shape, np.uint8),
                                parent=view.scene,
                                cmap="grays")
    view.camera.set_range(margin=0)

    canvas.show()

    async with receive_channel:
        async for frame in receive_channel:
            # logger.debug(f".... average {frame.mean():.2f}")

            # resize
            frame = transform.resize(frame, display_shape)
            # rescale intensity to 8-bit
            frame = exposure.rescale_intensity(frame, out_range=np.uint8)
            # change dtype
            frame = frame.astype(np.uint8)

            image.set_data(frame)

            canvas.update()
            app.process_events()