# Load a test mesh
mesh_registered = tcmesh.ObjMesh.read_obj(f"datasets/wrapping_example/Drosophila_reference_registered.obj")Warning: readOBJ() ignored non-comment line 1:
o Drosophila_reference_preregistered
smoothing - Mesh smoothinglibiglWe implement Laplacian and Taubin smoothing for vertex positions using libigl’s Laplacian operator.
Get uniform Laplacian (purely connectivity-based) as a sparse matrix.
If normalize, the diagonal = -1. Else, the diagonal equals the number of neighbors.
def smooth_laplacian(
mesh:ObjMesh, # Initial mesh.
lamb:float=0.5, # Filter strength. Higher = more smoothing.
n_iter:int=10, # Filter iterations
method:str='explicit', # Can use "explicit" (fast, simple) or "implicit" (slow, more accurate) methods.
boundary:str='fixed', # Whether to allow mesh boundaries to move
)->ObjMesh: # Smoothed mesh.
Smooth mesh vertex positions using Laplacian filter.
Assumes mesh is triangular.
Warning: readOBJ() ignored non-comment line 1:
o Drosophila_reference_preregistered
True
Smooth using Taubin filter (like Laplacian, but avoids shrinkage).
Assumes mesh is triangular. See “Improved Laplacian Smoothing of Noisy Surface Meshes” J. Vollmer, R. Mencl, and H. Muller.
Sometimes, UV maps can become very deformed, or even display self-intersection. Smoothing can fix this.
Smooth mesh texture positions using Laplacian filter.
This function is very helpful in fixing UV maps with flipped triangles, as detected by igl.flipped_triangles. Assumes mesh is triangular.
Smooth, but project at each step so the mesh vertices are back on the surface. This is very useful to smooth out surface-surface maps.
def smooth_laplacian_on_surface(
mesh:ObjMesh, # Initial mesh.
n_iter:int=10, # Number of iterations at each step
lamb:float=0.5, # Filter strength. Higher = more smoothing.
n_iter_laplace:int=10, # Laplace filter iterations. If reprojection messes up your mesh, decrease this number.
boundary:str='fixed', # Whether to allow mesh boundaries to move
)->ObjMesh: # Smoothed mesh.
Smooth mesh vertex positions using Laplacian filter and project vertices back to the original surface.
Alternates between Laplacian smoothing and projecting back to the original surface. Uses explicit method for Laplacian smoothing