render plot_surface via UV mapping when a texture is present#176
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
cedalion.vis.blocks.plot_surfacecurrently renders textured photogrammetry scans by sampling the JPG once per vertex (viacedalion.vtktutils.trimesh_to_vtk_polydata'smesh.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 vs. after fix)
The
# FIXME scalars to texture?note oncedalion/vtktutils.pyis exactly this issue.Fix
cedalion.vtktutils.trimesh_to_pv_textured_polydata(mesh) -> (pv.PolyData, pv.Texture | None)that builds apv.PolyDatacarrying the mesh's UVs as active texture coordinates and returns the texture image as apv.Texture. Falls back to(polydata, None)when the mesh has no UV + image.plot_surface'sTrimeshSurfacebranch through the new helper whenever the trimesh has both UVs and an image. The returned texture is attached toadd_mesh(texture=...), and the existingscalars is None → color="w"branch produces the correct texture rendering. **On this pathsmooth_shadingandsplit_sharp_edgesare set toFalse— their defaultTruesare still true for all other meshes (i.e. all meshes without texture). I think it makes sense to set them toFalsehere, 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.tests/test_vtktutils.pywith two tests for the new helper.