.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/validation/validate_send_data.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__gallery_validation_validate_send_data.py: Validate send_data ================== Show an image with points overlaid. Both the image and points are uploaded with send_data. .. GENERATED FROM PYTHON SOURCE LINES 8-80 .. image-sg:: /_gallery/validation/images/sphx_glr_validate_send_data_001.webp :alt: validate send data :srcset: /_gallery/validation/images/sphx_glr_validate_send_data_001.webp :class: sphx-glr-single-img .. code-block:: Python import imageio.v3 as iio import wgpu from rendercanvas.auto import RenderCanvas, loop import pygfx as gfx import numpy as np # Add image image_data = iio.imread("imageio:astronaut.png")[:, :, 1] tex = gfx.Texture( size=(512, 512, 1), dim=2, format=wgpu.TextureFormat.r8unorm, usage=wgpu.TextureUsage.COPY_DST, ) tex.send_data((0, 0, 0), image_data) tex.send_data((80, 100, 0), np.full((50, 50), 255, np.uint8)) tex.send_data((100, 80, 0), np.full((50, 50), 0, np.uint8)) del image_data image = gfx.Image( gfx.Geometry(grid=tex), gfx.ImageBasicMaterial(clim=(0, 255)), ) # Add points xx = [182, 180, 161, 153, 191, 237, 293, 300, 272, 267, 254] yy = [145, 131, 112, 59, 29, 14, 48, 91, 136, 137, 172] position_data = np.array([(x, y, 1) for x, y in zip(xx, yy, strict=True)], np.float32) buf = gfx.Buffer( nitems=len(xx), nbytes=len(xx) * 4 * 3, format="3xf4", usage=wgpu.BufferUsage.COPY_DST, ) buf.send_data(0, position_data) buf.send_data(10, np.array([[125, 105]], np.float32)) del position_data points = gfx.Points( gfx.Geometry(positions=buf), gfx.PointsMaterial(color="cyan", size=15, aa=True), ) # Setup for rendering canvas = RenderCanvas() renderer = gfx.renderers.WgpuRenderer(canvas) scene = gfx.Scene() scene.add(image, points) camera = gfx.PerspectiveCamera(0) camera.local.scale_y = -1 camera.show_rect(-10, 522, -10, 522) controller = gfx.PanZoomController(camera, register_events=renderer) canvas.request_draw(lambda: renderer.render(scene, camera)) if __name__ == "__main__": print(__doc__) loop.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.293 seconds) .. _sphx_glr_download__gallery_validation_validate_send_data.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: validate_send_data.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: validate_send_data.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: validate_send_data.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_ .. only:: html Interactive example ------------------- Try this example in your browser using Pyodide. Might not work with all examples and all devices. Check the output and your browser's console for details. .. raw:: html