def favour_side(self, mesh, favside):
"""This function weights the size of orientations closer than 45 deg
to a favoured side higher.
Args:
mesh (np.array): with format face_count x 6 x 3.
favside (string): the favoured side "[[0,-1,2.5],3]"
Returns:
a weighted mesh or the original mesh in case of invalid input
"""
if isinstance(favside, str):
try:
restring = r"(-?\d*\.{0,1}\d+)[, []]*(-?\d*\.{0,1}\d+)[, []]*(-?\d*\.{0,1}\d+)\D*(-?\d*\.{0,1}\d+)"
x = float(re.search(restring, favside).group(1))
y = float(re.search(restring, favside).group(2))
z = float(re.search(restring, favside).group(3))
f = float(re.search(restring, favside).group(4))
except AttributeError:
raise AttributeError("Could not parse input: favored side")
else:
raise AttributeError("Could not parse input: favored side")
norm = np.sqrt(np.sum(np.array([x, y, z])**2))
side = np.array([x, y, z])/norm
print("You favour the side {} with a factor of {}".format(
side, f))
diff = np.subtract(mesh[:, 0, :], side)
align = np.sum(diff*diff, axis=1) < 0.7654
mesh_not_align = mesh[np.logical_not(align)]
mesh_align = mesh[align]
mesh_align[:, 5, 0] = f * mesh_align[:, 5, 0] # weight aligning orientations
mesh = np.concatenate((mesh_not_align, mesh_align), axis=0)
return mesh
评论列表
文章目录