Smooth mesh using open3d's Laplacian smoothing.
PARAMETER | DESCRIPTION |
x | TYPE: MeshNeuron | Volume | Trimesh |
iterations | Round of smoothing to apply.
TYPE: int DEFAULT: 5 |
L | Diffusion speed constant lambda. Larger = more aggressive
smoothing.
TYPE: float [0-1] DEFAULT: 0.5 |
inplace | If True, will perform simplication on `x`. If False, will
simplify and return a copy.
TYPE: bool DEFAULT: False |
RETURNS | DESCRIPTION |
smoothed | |
Source code in navis/meshes/o3d.py
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 | def smooth_mesh_open3d(x, iterations=5, L=0.5, inplace=False):
"""Smooth mesh using open3d's Laplacian smoothing.
Parameters
----------
x : MeshNeuron | Volume | Trimesh
Mesh object to simplify.
iterations : int
Round of smoothing to apply.
L : float [0-1]
Diffusion speed constant lambda. Larger = more aggressive
smoothing.
inplace : bool
If True, will perform simplication on `x`. If False, will
simplify and return a copy.
Returns
-------
smoothed
Smoothed mesh object.
"""
if not isinstance(x, (core.MeshNeuron, core.Volume, tm.Trimesh)):
raise TypeError('Expected MeshNeuron, Volume or trimesh.Trimesh, '
f'got "{type(x)}"')
mesh_o3d = make_o3d_mesh(x)
if L > 1 or L < 0:
raise ValueError(f'`L` (lambda) must be between 0 and 1, got "{L}"')
result = mesh_o3d.filter_smooth_laplacian(iterations, L)
if not inplace:
x = x.copy()
x.vertices = np.asarray(result.vertices)
x.faces = np.asarray(result.triangles)
return x
|