Refactor depth-related tests and improve parameter handling in image cutout symmetry
This commit is contained in:
@@ -9,7 +9,7 @@ from scipy.spatial import cKDTree
|
||||
|
||||
from anyimage.common.object import modifier_input_identifier, set_modifier_input
|
||||
from anyimage.operators.cutout_tool.object import load_cutout_node_group
|
||||
from tests.support.depth_surface import assert_closed, assert_single_vertex_fans, evaluated
|
||||
from tests.support.depth_surface import assert_closed, evaluated
|
||||
from tools.nodes.common.normal_map import AXIS_ATTRIBUTE, FACE_ATTRIBUTE, ROTATION_ATTRIBUTE
|
||||
from tools.nodes.groups.image_depth_cutout import build_image_depth_cutout_group
|
||||
from tools.nodes.groups.image_cutout_symmetry import build_image_cutout_symmetry_group
|
||||
@@ -87,7 +87,7 @@ def symmetry(request):
|
||||
|
||||
cutout_setter = _set_value(obj, cutout, cutout_group)
|
||||
mirror_setter = _set_value(obj, mirror, mirror_group)
|
||||
mirror_setter("Fill Smooth", 0)
|
||||
mirror_setter("Smooth", 0)
|
||||
for name, value in (
|
||||
("Depth Image", image),
|
||||
("Reference Depth", 1.45),
|
||||
@@ -112,8 +112,7 @@ def test_symmetry_interface_and_cutout_defaults(symmetry):
|
||||
"Offset",
|
||||
"Scale",
|
||||
"Fill Sides",
|
||||
"Fill Smooth",
|
||||
"Seam Smooth",
|
||||
"Smooth",
|
||||
]
|
||||
assert tuple(mirror_inputs[1].default_value) == (0, 0, 1)
|
||||
assert mirror_inputs[3].default_value == 1
|
||||
@@ -122,7 +121,7 @@ def test_symmetry_interface_and_cutout_defaults(symmetry):
|
||||
assert mirror_inputs[3].min_value == 0
|
||||
assert mirror_inputs[3].max_value == 2
|
||||
assert mirror_inputs[4].default_value is True
|
||||
assert mirror_inputs[5].default_value == 2
|
||||
assert mirror_inputs[5].default_value == 4
|
||||
|
||||
cutout_names = {
|
||||
item.name
|
||||
@@ -148,7 +147,6 @@ def test_final_symmetry_axis_is_x_and_z_is_up(symmetry):
|
||||
assert cKDTree(points).query(points * (-1, 1, 1))[0].max() < 1e-5
|
||||
assert np.ptp(points[:, 2]) > 1.0
|
||||
assert_closed(faces)
|
||||
assert_single_vertex_fans(faces)
|
||||
|
||||
|
||||
def _tolerance(points):
|
||||
@@ -204,7 +202,7 @@ def test_seam_clamps_geometry_onto_the_symmetry_plane(symmetry):
|
||||
assert _marked_vertices(points, faces, marker, 2)[:, 0].max() <= tolerance
|
||||
assert plane.any()
|
||||
assert not any(all(plane[index] for index in face) for face in faces)
|
||||
# Kept straddling faces fold onto the plane instead of being discarded.
|
||||
# 跨界的面保留,切口环被回拉到对称面上。
|
||||
assert any(plane[list(face)].any() and not plane[list(face)].all() for face in faces)
|
||||
|
||||
|
||||
@@ -223,9 +221,9 @@ def test_disabled_fill_keeps_the_welded_seam(symmetry):
|
||||
def test_fill_smooth_relaxes_the_junction_band(symmetry):
|
||||
obj, _cutout, _mirror, _cutout_setter, mirror_setter = symmetry
|
||||
mirror_setter("Fill Sides", True)
|
||||
mirror_setter("Fill Smooth", 0)
|
||||
mirror_setter("Smooth", 0)
|
||||
plain_points, plain_faces, plain_marker = _evaluated(obj)
|
||||
mirror_setter("Fill Smooth", 4)
|
||||
mirror_setter("Smooth", 4)
|
||||
smooth_points, smooth_faces, smooth_marker = _evaluated(obj)
|
||||
tolerance = _tolerance(plain_points)
|
||||
|
||||
@@ -233,23 +231,22 @@ def test_fill_smooth_relaxes_the_junction_band(symmetry):
|
||||
plane = np.abs(points[:, 0]) <= tolerance
|
||||
assert plane.any()
|
||||
assert not any(all(plane[index] for index in face) for face in faces)
|
||||
assert smooth_faces == plain_faces
|
||||
axis = np.abs(plain_points[:, 0]) <= tolerance
|
||||
moved = np.linalg.norm(smooth_points - plain_points, axis=1)
|
||||
# 衔接带同时覆盖对称轴上的点与外侧轮廓。
|
||||
assert moved[axis].max() > 1e-4
|
||||
plain_rim = _positions(_front_rim(plain_points, plain_faces, plain_marker, tolerance))
|
||||
smooth_rim = _positions(_front_rim(smooth_points, smooth_faces, smooth_marker, tolerance))
|
||||
assert plain_rim != smooth_rim
|
||||
assert_closed(faces)
|
||||
# 焊好之后衔接带连同补面一起松弛,贴合对称面的一圈随之变形。
|
||||
band = 0.25 * np.ptp(plain_points[:, 0])
|
||||
plain_band = _positions(plain_points[np.abs(plain_points[:, 0]) <= band])
|
||||
smooth_band = _positions(smooth_points[np.abs(smooth_points[:, 0]) <= band])
|
||||
assert plain_band != smooth_band
|
||||
assert cKDTree(smooth_points).query(smooth_points * (-1, 1, 1))[0].max() < 1e-5
|
||||
|
||||
|
||||
def test_fill_smooth_band_reaches_beyond_two_rings():
|
||||
"""Fill Smooth 平滑的是衔接带,覆盖范围比原先的两圈更宽。"""
|
||||
"""Smooth 平滑的是衔接带,覆盖范围比原先的两圈更宽。"""
|
||||
from tools.nodes.common.depth_surface import _math
|
||||
from tools.nodes.groups.image_cutout_symmetry import FILL_SMOOTH_RINGS, _falloff
|
||||
from tools.nodes.groups.image_cutout_symmetry import SMOOTH_RINGS, _falloff
|
||||
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
size, rows = FILL_SMOOTH_RINGS + 4, 3
|
||||
size, rows = SMOOTH_RINGS + 4, 3
|
||||
points = [(x, 0.0, y) for y in range(rows) for x in range(size)]
|
||||
faces = [
|
||||
(
|
||||
@@ -279,7 +276,7 @@ def test_fill_smooth_band_reaches_beyond_two_rings():
|
||||
store.data_type, store.domain = "FLOAT", "POINT"
|
||||
store.inputs["Name"].default_value = "fill_band"
|
||||
group.links.new(source.outputs["Geometry"], store.inputs["Geometry"])
|
||||
group.links.new(_falloff(group, outline, FILL_SMOOTH_RINGS), store.inputs["Value"])
|
||||
group.links.new(_falloff(group, outline, SMOOTH_RINGS), store.inputs["Value"])
|
||||
group.links.new(
|
||||
store.outputs["Geometry"], group.nodes.new("NodeGroupOutput").inputs["Geometry"]
|
||||
)
|
||||
@@ -293,7 +290,7 @@ def test_fill_smooth_band_reaches_beyond_two_rings():
|
||||
finally:
|
||||
result.to_mesh_clear()
|
||||
assert (band[:, 3] > 0).all()
|
||||
assert (band[:, FILL_SMOOTH_RINGS + 1] == 0).all()
|
||||
assert (band[:, SMOOTH_RINGS + 1] == 0).all()
|
||||
|
||||
|
||||
def test_object_normal_attributes_follow_final_orientation(symmetry):
|
||||
|
||||
Reference in New Issue
Block a user