Refactor depth reference handling and cleanup
- Unified reference depth calculation to use a single implementation in common/depth.py. - Removed server-side reference depth computation and adjusted depth.json to only include image_size and intrinsics. - Updated depth texture handling to ignore transparent, invalid, and non-positive pixels when calculating reference depth. - Changed reference depth calculation to use the 95th percentile of valid depth values. - Adjusted depth direction fitting to return a flat direction when no samples are available. - Removed cleanup threshold parameters from Cutout and related nodes, simplifying the interface. - Updated tests to verify new reference depth logic and ensure compatibility with existing functionality.
This commit is contained in:
@@ -8,7 +8,7 @@ import numpy as np
|
||||
from tests.support.nodes import CUTOUT_BUILDERS
|
||||
|
||||
|
||||
def surface(*, step=6.0, size=1.0, resolution=2, wrapper=False):
|
||||
def surface(*, step=6.0, size=1.0, resolution=2):
|
||||
bpy.ops.wm.read_factory_settings(use_empty=True)
|
||||
group = CUTOUT_BUILDERS["DEPTH_SOLID"]()
|
||||
# Two columns with a complete depth jump along their common boundary.
|
||||
@@ -70,8 +70,6 @@ def surface(*, step=6.0, size=1.0, resolution=2, wrapper=False):
|
||||
("Boundary Smooth", 0),
|
||||
):
|
||||
set_value(name, value)
|
||||
if wrapper:
|
||||
set_value("Cleanup Threshold", 0.0)
|
||||
return obj, set_value
|
||||
|
||||
|
||||
|
||||
@@ -60,7 +60,6 @@ def _create_cutout_shape(
|
||||
bpy.context,
|
||||
source,
|
||||
shape,
|
||||
edge_length,
|
||||
selection_mask.values,
|
||||
selection_mask.bounds,
|
||||
base_shape,
|
||||
@@ -71,13 +70,13 @@ def _create_cutout_shape(
|
||||
)
|
||||
|
||||
|
||||
def _depth_image(points, valid, name="Depth"):
|
||||
def _depth_image(points, alpha, name="Depth"):
|
||||
points = np.asarray(points, dtype=np.float32)
|
||||
valid = np.asarray(valid, dtype=bool)
|
||||
height, width = valid.shape
|
||||
alpha = np.asarray(alpha, dtype=np.float32)
|
||||
height, width = alpha.shape
|
||||
pixels = np.zeros((height, width, 4), dtype=np.float32)
|
||||
pixels[..., :3] = points
|
||||
pixels[..., 3] = valid
|
||||
pixels[..., 3] = alpha
|
||||
image = bpy.data.images.new(
|
||||
name,
|
||||
width=width,
|
||||
@@ -92,11 +91,10 @@ def _depth_image(points, valid, name="Depth"):
|
||||
return image
|
||||
|
||||
|
||||
def _depth_metadata(intrinsics, image_size, reference_depth):
|
||||
def _depth_metadata(intrinsics, image_size):
|
||||
return {
|
||||
"intrinsics": tuple(tuple(float(value) for value in row) for row in intrinsics),
|
||||
"image_size": tuple(int(value) for value in image_size),
|
||||
"reference_depth": float(reference_depth),
|
||||
}
|
||||
|
||||
|
||||
@@ -115,11 +113,6 @@ def _add_cutout_modifier(obj, shape):
|
||||
modifier.node_group = group
|
||||
if shape in {"FLAT", "DEPTH_SOLID"}:
|
||||
object_data.set_modifier_input(modifier, object_data.modifier_input_identifier(group, "Mode"), 1)
|
||||
object_data.set_modifier_input(
|
||||
modifier,
|
||||
object_data.modifier_input_identifier(group, "Cleanup Threshold"),
|
||||
0.0,
|
||||
)
|
||||
if shape == "DEPTH_SOLID":
|
||||
object_data.set_modifier_input(
|
||||
modifier,
|
||||
@@ -129,73 +122,3 @@ def _add_cutout_modifier(obj, shape):
|
||||
return modifier
|
||||
|
||||
|
||||
def _depth_surface_step_object():
|
||||
vertices = [(float(x), float(y), 0.0) for y in range(3) for x in range(3)]
|
||||
faces = []
|
||||
for y in range(2):
|
||||
for x in range(2):
|
||||
a = y * 3 + x
|
||||
faces.extend(((a, a + 1, a + 4), (a, a + 4, a + 3)))
|
||||
data = bpy.data.meshes.new("Depth Surface Step")
|
||||
data.from_pydata(vertices, (), faces)
|
||||
uv_layer = data.uv_layers.new(name="UVMap")
|
||||
for loop in data.loops:
|
||||
coordinate = data.vertices[loop.vertex_index].co
|
||||
uv_layer.data[loop.index].uv = (coordinate.x * 0.5, coordinate.y * 0.5)
|
||||
obj = bpy.data.objects.new("Depth Surface Step", data)
|
||||
bpy.context.collection.objects.link(obj)
|
||||
modifier = _add_cutout_modifier(obj, "DEPTH_SOLID")
|
||||
|
||||
points = np.empty((3, 3, 3), dtype=np.float32)
|
||||
for y in range(3):
|
||||
for x in range(3):
|
||||
points[y, x] = (float(x), -float(y), 1.0)
|
||||
points[0, 0, 2] = 6.0
|
||||
depth_image = _depth_image(points, np.ones((3, 3), dtype=bool))
|
||||
for name, value in (
|
||||
("Depth Image", depth_image),
|
||||
("Depth Scale", 1.0),
|
||||
("Uniform Scale", 1.0),
|
||||
("Reference Depth", 1.0),
|
||||
("Thickness", 0.0),
|
||||
):
|
||||
object_data.set_modifier_input(
|
||||
modifier,
|
||||
object_data.modifier_input_identifier(
|
||||
modifier.node_group, name,
|
||||
subtype="DISTANCE" if name == "Thickness" else None,
|
||||
),
|
||||
value,
|
||||
)
|
||||
return obj, modifier
|
||||
|
||||
|
||||
def _evaluated_topology(obj):
|
||||
evaluated = obj.evaluated_get(bpy.context.evaluated_depsgraph_get())
|
||||
result = evaluated.to_mesh()
|
||||
try:
|
||||
face_edges = {
|
||||
tuple(sorted((start, end)))
|
||||
for polygon in result.polygons
|
||||
for start, end in zip(
|
||||
polygon.vertices,
|
||||
(*polygon.vertices[1:], polygon.vertices[0]),
|
||||
)
|
||||
}
|
||||
mesh_edges = {
|
||||
tuple(sorted(edge.vertices))
|
||||
for edge in result.edges
|
||||
}
|
||||
face_vertices = {
|
||||
vertex
|
||||
for polygon in result.polygons
|
||||
for vertex in polygon.vertices
|
||||
}
|
||||
return (
|
||||
len(result.vertices),
|
||||
len(result.polygons),
|
||||
mesh_edges - face_edges,
|
||||
set(range(len(result.vertices))) - face_vertices,
|
||||
)
|
||||
finally:
|
||||
evaluated.to_mesh_clear()
|
||||
|
||||
Reference in New Issue
Block a user