Repository navigation
Add high-level mesh-based API for SPHARM parametrization - #24
Open
keisuke-ishihara wants to merge 5 commits into
Open
keisuke-ishihara wants to merge 5 commits into
keisuke-ishihara wants to merge 5 commits into
Conversation
Bumps [pypa/gh-action-pypi-publish](https://github.com/pypa/gh-action-pypi-publish) from 1.4.2 to 1.13.0. - [Release notes](https://github.com/pypa/gh-action-pypi-publish/releases) - [Commits](pypa/gh-action-pypi-publish@v1.4.2...v1.13.0) --- updated-dependencies: - dependency-name: pypa/gh-action-pypi-publish dependency-version: 1.13.0 dependency-type: direct:production ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Closes #3. Adds public entry points to compute spherical harmonics coefficients directly from a surface mesh, exposing functionality the library already implemented internally (get_shcoeffs voxelizes/re-meshes an image before fitting on mesh point coordinates). shparam.py: - get_shcoeffs_from_mesh(mesh, lmax, ...): fit directly from a vtkPolyData. - get_shcoeffs_from_vertices_faces(vertices, faces, lmax, ...): wrapper for raw numpy arrays. - Factor the shared fitting math into _get_shcoeffs_from_mesh_coords so the image and mesh paths use one implementation. Return shape matches get_shcoeffs; the image_ slot is None for mesh input. - Center on the vertex-mean centroid and align on the mesh point cloud; the caller's mesh is deep-copied so it is not mutated. shtools.py: - get_mesh_from_vertices_faces: build a triangular vtkPolyData with hard-error validation (shape, finite values, index bounds). - check_mesh_for_parametrization: warn (never raise) on non-watertight meshes (vtkFeatureEdges, after cleaning coincident points) and off-center centroids (vtkSelectEnclosedPoints). - get_alignment_angle_2d / align_points_2d: factor the PCA angle math out of align_image_2d so image and point-cloud alignment share it. Co-Authored-By: Claude Code <noreply@anthropic.com>
Add a Notes section clarifying that alignment_2d/make_unique behave the same as in get_shcoeffs, but the mesh path aligns on surface vertices and rotates points directly (vs. voxel-volume PCA + image rotation), so the two paths are not guaranteed to produce bit-identical orientations. Co-Authored-By: Claude Code <noreply@anthropic.com>
…om package Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This branch has not been deployed
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
Closes #23.
get_shcoeffs()currently accepts only binary images, even though the library already converts images to avtkPolyDatamesh internally before fitting spherical harmonics. This PR exposes that mesh path directly so users with existing surface meshes (from meshing pipelines, simulation outputs, etc.) don't need to voxelize them back into images — a lossy and unnecessary round-trip.shparam.get_shcoeffs_from_mesh(mesh, lmax, alignment_2d=True, make_unique=False)— accepts avtk.vtkPolyData, returns the same nested-tuple structure asget_shcoeffs(withimage_set toNone)shparam.get_shcoeffs_from_vertices_faces(vertices, faces, lmax, alignment_2d=True, make_unique=False)— convenience wrapper for users working with raw numpy arraysshparam._get_shcoeffs_from_mesh_coords— private core extracted fromget_shcoeffs, shared by both the image and mesh paths to avoid duplicationshtools.get_mesh_from_vertices_faces(vertices, faces, center=True)— builds and validates avtkPolyDatafrom numpy arraysshtools.check_mesh_for_parametrization(mesh)— non-raising warnings for geometric assumption violations (non-watertight surface, centroid outside mesh)shtools.align_points_2d(x, y, make_unique=False)— PCA-based 2D alignment, refactored out of the shared alignment logicValidation
ValueErrorValueErrorUserWarning(computation proceeds)UserWarning(computation proceeds)Note on alignment
The 2D alignment angle is not guaranteed to be bit-identical between
get_shcoeffsandget_shcoeffs_from_meshfor the same object, since PCA runs on different point sets (voxel coordinates vs. surface vertices). Documented in the docstring.Test plan
tests/test_shparam_mesh.pycovering mesh and vertices/faces entry points, validation errors, and warnings🤖 Generated with Claude Code