Skip to content

render plot_surface via UV mapping when a texture is present#176

Merged
emiddell merged 2 commits into
devfrom
fix-plot-surface-texture-smearing
Jul 8, 2026
Merged

render plot_surface via UV mapping when a texture is present#176
emiddell merged 2 commits into
devfrom
fix-plot-surface-texture-smearing

Conversation

@harmening

Copy link
Copy Markdown
Contributor

Summary

cedalion.vis.blocks.plot_surface currently renders textured photogrammetry scans by sampling the JPG once per vertex (via cedalion.vtktutils.trimesh_to_vtk_polydata's mesh.visual.to_color().vertex_colors) and treating the result as point-data scalars. On dense Einstar meshes this is high enough resolution to hide the loss; on coarser Scaniverse meshes each vertex covers many texels and every sub-vertex feature — the red crosses drawn to mark optode positions during a nocap scan, the colored optode stickers on the cap — smears into a blur:
before_fix after_fix
(before vs. after fix)

The # FIXME scalars to texture? note on cedalion/vtktutils.py is exactly this issue.

Fix

  • Add cedalion.vtktutils.trimesh_to_pv_textured_polydata(mesh) -> (pv.PolyData, pv.Texture | None) that builds a pv.PolyData carrying the mesh's UVs as active texture coordinates and returns the texture image as a pv.Texture. Falls back to (polydata, None) when the mesh has no UV + image.
  • Route plot_surface's TrimeshSurface branch through the new helper whenever the trimesh has both UVs and an image. The returned texture is attached to add_mesh(texture=...), and the existing scalars is None → color="w" branch produces the correct texture rendering. **On this path smooth_shading and split_sharp_edges are set to False — their default Trues are still true for all other meshes (i.e. all meshes without texture). I think it makes sense to set them to False here, because they recompute normals and duplicate vertices along sharp edges, which can mangle UVs even after the texture path is wired up. Callers can still override via kwargs.
  • trimesh_to_vtk_polydata, VTKSurface.from_trimeshsurface, and every other caller stay untouched.
  • Add tests/test_vtktutils.py with two tests for the new helper.

@harmening harmening requested a review from emiddell July 8, 2026 09:48
@emiddell emiddell merged commit 956dddd into dev Jul 8, 2026
4 checks passed
@emiddell emiddell deleted the fix-plot-surface-texture-smearing branch July 8, 2026 13:56
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.

2 participants