Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
peng00bo00 committed Aug 1, 2023
1 parent f2f55b0 commit 268462c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ dmypy.json

# Pyre type checker
.pyre/

# mesh
*.obj
2 changes: 1 addition & 1 deletion willmore/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .quaternion import Quaternion, QuaternionMatrix, QList
from .mesh import Mesh
from .util import timeit
from .util import timeit, findOrigin, volume, normalizeMesh

from .fairing import WillmoreFlow
from .curvature_transfer_step import curvature_transfer_step
70 changes: 69 additions & 1 deletion willmore/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,72 @@ def area_normalization(V, F) -> QuaternionMatrix:
R[Fj, Fi] -= 0.5*w
R[Fj, Fj] += 0.5*w

return R
return R

def findOrigin(V: np.ndarray, F: np.ndarray) -> np.ndarray:
"""A helper function to find the center of mesh.
Args:
V: vertices
F: faces
Return:
x0: center of the mesh
"""

weights = 0
x0 = np.zeros(3)

for (i, j, k) in F:
vi, vj, vk = V[i], V[j], V[k]

## volume of the tetrahedron
vol = np.dot(vi, np.cross(vj, vk)) / 6

weights += vol
x0 += vol * (vi + vj + vk) / 4

return x0 / weights

def volume(V: np.ndarray, F: np.ndarray) -> float:
"""A helper function to find volume of the mesh.
Args:
V: vertices
F: faces
Return:
vol: volume of the mesh
"""

vol = 0.
for (i, j, k) in F:
vi, vj, vk = V[i], V[j], V[k]

## volume of the tetrahedron
vol += np.dot(vi, np.cross(vj, vk)) / 6

return vol

def normalizeMesh(V: np.ndarray, F: np.ndarray) -> np.ndarray:
"""A helper function to normalize the mesh to unit volume.
Args:
V: vertices
F: faces
Return:
Vnew: new vertices coordinates
"""

## move to center
c = findOrigin(V, F)
Vnew = V - c

## solve volume
vol = volume(Vnew, F)

## normalize volume
Vnew /= np.power(vol, 1/3)

return Vnew

0 comments on commit 268462c

Please sign in to comment.