Skip to content

feat(plotting): add plot_surface for displaying meshes in napari - #263

Draft
FelipeCybis wants to merge 1 commit into
atlas-meshfrom
worktree-plot-surface
Draft

FelipeCybis wants to merge 1 commit into
atlas-meshfrom
worktree-plot-surface

Conversation

@FelipeCybis

@FelipeCybis FelipeCybis commented Jul 7, 2026

Copy link
Copy Markdown
Member

Closes #262. Closes #335.

Stacked on #448 (multi-region get_mesh and batched mesh prefetch), which is stacked on #446.

What

Adds two napari helpers for meshes, the mesh counterpart to plot_napari:

  • confusius.plotting.plot_surface(mesh, ...): a thin wrapper over napari.Viewer.add_surface taking a bare (vertices, faces) tuple, with optional per-vertex values for colormapped shading.
  • confusius.plotting.plot_atlas_mesh(atlas, regions, sides, ...): the atlas-aware version, which pulls the meshes, per-vertex colors, layer name, axis labels, and units from the atlas Dataset before handing off to plot_surface. Also reachable as ds.atlas.plot.mesh(...), through a new AtlasPlotAccessor hanging off the .atlas namespace.
import confusius as cf

atlas = cf.datasets.fetch_brainglobe_atlas("allen_mouse_25um")
viewer, _ = cf.plotting.plot_napari(atlas.atlas.reference)
cf.plotting.plot_atlas_mesh(atlas, ["VISp", "AUDp", "MOp"], viewer=viewer)

Both switch the viewer to 3D (ndisplay = 3): in 2D a Surface layer is drawn only as its cross-section with the current slice plane, which leaves a 3D mesh all but invisible.

Because get_mesh returns vertices already in the atlas physical space, and image layers sit at their physical origin and spacing, surfaces line up with the image layers without any scale/translate juggling.

Multiple regions per call (#335)

plot_atlas_mesh takes the same regions/sides arguments as the multi-region get_mesh from #448 and merges every requested region into a single Surface layer, giving each region its own atlas color through the layer's vertex_colors. An explicit colormap, or per-vertex values, still overrides that. The layer is named after the region (full name plus acronym) when a single region is requested, and after the requested acronyms otherwise.

Tests

  • TestPlotSurface and TestPlotAtlasMesh in tests/unit/test_plotting/test_napari.py: mesh and values round-tripping into the layer, the flat-surface default, overlay on an existing viewer with units, name and per-vertex colors read from the atlas, hemisphere clipping, the multi-region merge (face re-indexing and per-region colors), and accessor delegation.

Docs

  • Changelog entry under 0.7.1.dev0.
  • "Region Surface Meshes" in the atlas user guide now shows plot.mesh for display.
  • New row in the visualization user-guide tool table. The API reference pages pick both functions up via __all__.

@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.30508% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/confusius/plotting/napari.py 97.67% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

📖 Doc preview: https://confusius.tools/pr-preview/pr-263/

Add `plot_surface`, a thin wrapper over `napari.Viewer.add_surface` for a bare
`(vertices, faces)` mesh with optional per-vertex values, and `plot_atlas_mesh`
(also `ds.atlas.plot.mesh` via the new `AtlasPlotAccessor`), which pulls meshes,
per-vertex atlas colors, layer name, world axis labels, and units from an atlas
Dataset and merges every requested region into one Surface layer. Both switch
the viewer to 3D.

Builds on the multi-region `get_mesh` dict API. Mesh vertices are world
`(z, y, x)` coordinates, so surfaces coincide with image layers placed by
`plot_napari` under the VoxelData model; a unit test checks a mesh vertex
against the image layer's own voxel-to-world mapping on a shifted grid.

Closes #262. Closes #335.
@FelipeCybis
FelipeCybis force-pushed the worktree-plot-surface branch from aa7f881 to c66db00 Compare September 2, 2026 13:17
@FelipeCybis
FelipeCybis changed the base branch from get-bounding-box to atlas-mesh September 2, 2026 13:19

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Atlas get_mesh should be able to handle multiple meshes in the same call Add plot_surface for displaying meshes in napari

1 participant