def init_framefield(self):
"""Initialize the frame field based on surface curvature and normals."""
boundary_frames = []
boundary_ids = {}
# The frame field is initialized at the boundary,
# based on the curvature cross-field and normals.
for fi, face in enumerate(self.surf_mesh.faces):
# Retrieve the tet this face belongs to.
ti = self.tet_mesh.adjacent_elements[self.surf_mesh.face_map.inv[fi]][0]
tet = self.tet_mesh.elements[ti]
# Ignore faces which have 0 curvature.
if np.isclose(self.surf_mesh.k1[face[0]], 0) and np.isclose(self.surf_mesh.k2[face[0]], 0):
continue
# @TODO(aidan) Find actual face values, not vertex values.
uvw = np.hstack((np.vstack(self.surf_mesh.pdir1[face[0]]),
np.vstack(self.surf_mesh.pdir2[face[0]]),
np.vstack(self.surf_mesh.vertex_normals[face[0]])))
boundary_frames.append(Frame(uvw, tet_centroid(self.tet_mesh, ti)))
boundary_ids[ti] = len(boundary_frames) - 1
# Prepare a KDTree of boundary frame coords for quick spatial queries.
tree = spatial.KDTree(np.vstack([frame.location for frame in boundary_frames]))
# Now propagate the boundary frames throughout the tet mesh.
# Each tet frame takes the value of its nearest boundary tet.
for ti, tet in enumerate(self.tet_mesh.elements):
location = tet_centroid(self.tet_mesh, ti)
if ti in boundary_ids:
self.frames.append(Frame(boundary_frames[boundary_ids[ti]].uvw, location, True))
else:
nearest_ti = tree.query(location)[1] # Find closest boundary frame
self.frames.append(Frame(boundary_frames[nearest_ti].uvw, location, False))
评论列表
文章目录