github-actions[bot] commited on
Commit ·
6d2f042
1
Parent(s): b2004ce
Automated Deploy: cabc3114361e962c4ab341306ef4fda9dc83693d
Browse files- config/runtime.py +2 -2
- scripts/test_wall_mask.py +5 -5
- services/geometry/uv_mapping.py +15 -9
- services/pipeline/builder.py +53 -48
- services/pipeline/bundle_assembly.py +4 -0
- services/wall/components.py +38 -21
- services/wall/mask.py +8 -5
- visualizer.gpu.toml +1 -1
- visualizer.hf.toml +1 -1
- visualizer.local.toml +1 -1
config/runtime.py
CHANGED
|
@@ -8,9 +8,9 @@ ENABLE_PLANE_FIT = config_bool("ENABLE_PLANE_FIT", "runtime", "enable_plane_fit"
|
|
| 8 |
ENABLE_MULTI_PLANE_SURFACES = config_bool("ENABLE_MULTI_PLANE_SURFACES", "runtime", "enable_multi_plane_surfaces", "1")
|
| 9 |
ENABLE_WALL_SEGMENTS = config_bool("ENABLE_WALL_SEGMENTS", "runtime", "enable_wall_segments", "1")
|
| 10 |
ENABLE_INTRINSIC_SHADING = config_bool("ENABLE_INTRINSIC_SHADING", "runtime", "enable_intrinsic_shading", "0")
|
| 11 |
-
ENABLE_SHADING_TRANSFER = config_bool("ENABLE_SHADING_TRANSFER", "runtime", "enable_shading_transfer", "
|
| 12 |
ENABLE_FAST_SHADOW_TRANSFER = config_bool(
|
| 13 |
-
"ENABLE_FAST_SHADOW_TRANSFER", "runtime", "enable_fast_shadow_transfer", "0",
|
| 14 |
)
|
| 15 |
WARM_START_MODELS = config_bool("WARM_START_MODELS", "runtime", "warm_start_models", "1")
|
| 16 |
|
|
|
|
| 8 |
ENABLE_MULTI_PLANE_SURFACES = config_bool("ENABLE_MULTI_PLANE_SURFACES", "runtime", "enable_multi_plane_surfaces", "1")
|
| 9 |
ENABLE_WALL_SEGMENTS = config_bool("ENABLE_WALL_SEGMENTS", "runtime", "enable_wall_segments", "1")
|
| 10 |
ENABLE_INTRINSIC_SHADING = config_bool("ENABLE_INTRINSIC_SHADING", "runtime", "enable_intrinsic_shading", "0")
|
| 11 |
+
ENABLE_SHADING_TRANSFER = config_bool("ENABLE_SHADING_TRANSFER", "runtime", "enable_shading_transfer", "0")
|
| 12 |
ENABLE_FAST_SHADOW_TRANSFER = config_bool(
|
| 13 |
+
"ENABLE_FAST_SHADOW_TRANSFER", "runtime", "enable_fast_shadow_transfer", "0", # all lighting disabled
|
| 14 |
)
|
| 15 |
WARM_START_MODELS = config_bool("WARM_START_MODELS", "runtime", "warm_start_models", "1")
|
| 16 |
|
scripts/test_wall_mask.py
CHANGED
|
@@ -265,15 +265,15 @@ def main() -> int:
|
|
| 265 |
# geometry=None short-circuits the planarity split, so the whole function is
|
| 266 |
# exercisable without a GPU.
|
| 267 |
parts, protected_out = wall_surface_components(seg_map, min_area=2000, geometry=None)
|
| 268 |
-
check("returns a list of
|
| 269 |
-
all(isinstance(item, tuple) and len(item) ==
|
| 270 |
f"got {[type(i).__name__ for i in parts[:3]]}")
|
| 271 |
check("first element is an int area",
|
| 272 |
-
all(isinstance(area, int) for area, _ in parts))
|
| 273 |
check("second element is a 2D uint8 mask",
|
| 274 |
-
all(mask.ndim == 2 and mask.dtype == np.uint8 for _, mask in parts))
|
| 275 |
check("areas are sorted largest first",
|
| 276 |
-
[a for a, _ in parts] == sorted([a for a, _ in parts], reverse=True))
|
| 277 |
check("found the wall", len(parts) >= 1, f"{len(parts)} components")
|
| 278 |
check("protected mask returned", protected_out.shape == seg_map.shape)
|
| 279 |
|
|
|
|
| 265 |
# geometry=None short-circuits the planarity split, so the whole function is
|
| 266 |
# exercisable without a GPU.
|
| 267 |
parts, protected_out = wall_surface_components(seg_map, min_area=2000, geometry=None)
|
| 268 |
+
check("returns a list of 3-tuples (area, mask, planes)",
|
| 269 |
+
all(isinstance(item, tuple) and len(item) == 3 for item in parts),
|
| 270 |
f"got {[type(i).__name__ for i in parts[:3]]}")
|
| 271 |
check("first element is an int area",
|
| 272 |
+
all(isinstance(area, int) for area, _, _ in parts))
|
| 273 |
check("second element is a 2D uint8 mask",
|
| 274 |
+
all(mask.ndim == 2 and mask.dtype == np.uint8 for _, mask, _ in parts))
|
| 275 |
check("areas are sorted largest first",
|
| 276 |
+
[a for a, _, _ in parts] == sorted([a for a, _, _ in parts], reverse=True))
|
| 277 |
check("found the wall", len(parts) >= 1, f"{len(parts)} components")
|
| 278 |
check("protected mask returned", protected_out.shape == seg_map.shape)
|
| 279 |
|
services/geometry/uv_mapping.py
CHANGED
|
@@ -146,6 +146,7 @@ def build_surface_uv_mapping(
|
|
| 146 |
# fill was written for walls and floors were left on the old path.
|
| 147 |
fill_missing_from_plane: bool = True,
|
| 148 |
vertical_ref: np.ndarray | None = None,
|
|
|
|
| 149 |
):
|
| 150 |
total_started = time.perf_counter()
|
| 151 |
phase_started = total_started
|
|
@@ -203,15 +204,20 @@ def build_surface_uv_mapping(
|
|
| 203 |
)
|
| 204 |
|
| 205 |
phase_started = time.perf_counter()
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
plane_fit_ms = (time.perf_counter() - phase_started) * 1000
|
| 216 |
if not planes:
|
| 217 |
print(
|
|
|
|
| 146 |
# fill was written for walls and floors were left on the old path.
|
| 147 |
fill_missing_from_plane: bool = True,
|
| 148 |
vertical_ref: np.ndarray | None = None,
|
| 149 |
+
precomputed_planes: list[dict] | None = None,
|
| 150 |
):
|
| 151 |
total_started = time.perf_counter()
|
| 152 |
phase_started = total_started
|
|
|
|
| 204 |
)
|
| 205 |
|
| 206 |
phase_started = time.perf_counter()
|
| 207 |
+
if precomputed_planes is not None:
|
| 208 |
+
# Reuse planes already fitted during wall discovery — avoids a
|
| 209 |
+
# duplicate RANSAC × max_planes pass.
|
| 210 |
+
planes = list(precomputed_planes)
|
| 211 |
+
else:
|
| 212 |
+
planes = fit_multi_surface_planes(points, normals, normals_reliable, mark_floor=mark_floor,
|
| 213 |
+
vertical_ref=vertical_ref)
|
| 214 |
+
if not mark_floor:
|
| 215 |
+
# One flat wall attracts several near-identical RANSAC planes when
|
| 216 |
+
# normals are noisy. Distinct plane ids mean distinct UV origins, so
|
| 217 |
+
# the tile grid would restart mid-wall. Floors keep the original
|
| 218 |
+
# behaviour untouched.
|
| 219 |
+
planes = merge_coplanar_planes(planes, surface_distance_threshold(points),
|
| 220 |
+
vertical_ref=vertical_ref)
|
| 221 |
plane_fit_ms = (time.perf_counter() - phase_started) * 1000
|
| 222 |
if not planes:
|
| 223 |
print(
|
services/pipeline/builder.py
CHANGED
|
@@ -251,41 +251,35 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 251 |
wall_mask = seg_class_mask(seg_map, class_ids({"wall"}))
|
| 252 |
wall_components = []
|
| 253 |
wall_protected_mask = None
|
| 254 |
-
|
| 255 |
-
|
| 256 |
-
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
|
|
|
|
|
|
|
| 260 |
|
| 261 |
-
# ---
|
| 262 |
-
# Wall
|
| 263 |
-
#
|
| 264 |
-
#
|
| 265 |
from concurrent.futures import ThreadPoolExecutor, Future
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
-
def _compute_wall_lighting(component_mask):
|
| 268 |
-
return build_luminance_lighting_maps(img_np, component_mask)
|
| 269 |
-
|
| 270 |
-
# Walls had no lighting switch at all: this ran for every component however
|
| 271 |
-
# the floor's flags were set, so a run with lighting off was still lit.
|
| 272 |
-
# Gated on *any* path being enabled rather than on shading transfer alone,
|
| 273 |
-
# because the GPU profile already has that false while relying on fast
|
| 274 |
-
# shadow -- keying off it would have silently unlit production walls.
|
| 275 |
wall_lighting_enabled = (
|
| 276 |
ENABLE_INTRINSIC_SHADING or ENABLE_FAST_SHADOW_TRANSFER or ENABLE_SHADING_TRANSFER
|
| 277 |
)
|
| 278 |
|
| 279 |
-
wall_lighting_futures: list[Future] = []
|
| 280 |
-
wall_executor = (
|
| 281 |
-
ThreadPoolExecutor(max_workers=max(1, len(wall_components)))
|
| 282 |
-
if wall_components and wall_lighting_enabled
|
| 283 |
-
else None
|
| 284 |
-
)
|
| 285 |
-
if wall_executor:
|
| 286 |
-
for _, cm in wall_components:
|
| 287 |
-
wall_lighting_futures.append(wall_executor.submit(_compute_wall_lighting, cm))
|
| 288 |
-
|
| 289 |
if progress_callback:
|
| 290 |
progress_callback(PipelinePhase.LIGHTING, 100)
|
| 291 |
|
|
@@ -322,16 +316,11 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 322 |
if progress_callback:
|
| 323 |
progress_callback(PipelinePhase.DIRECTION, 100)
|
| 324 |
|
| 325 |
-
#
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
wall_lighting_results.append(fut.result())
|
| 331 |
-
wall_executor.shutdown(wait=False)
|
| 332 |
-
_log_stage("Wall Lighting Wait", t0, f"components={len(wall_components)}")
|
| 333 |
-
else:
|
| 334 |
-
wall_lighting_results = [None] * len(wall_components)
|
| 335 |
|
| 336 |
# --- Package segments ---
|
| 337 |
if progress_callback:
|
|
@@ -362,17 +351,33 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 362 |
break
|
| 363 |
if floor_up is not None:
|
| 364 |
print(f'[WALL_UP] using floor normal as vertical: {floor_up.round(3).tolist()}', flush=True)
|
|
|
|
|
|
|
|
|
|
| 365 |
wall_segments = []
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
wi, cm,
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
-
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 376 |
# Only when wall discovery actually ran. With ENABLE_WALL_SEGMENTS off
|
| 377 |
# there is no protected mask and nothing to report.
|
| 378 |
if d and ENABLE_WALL_SEGMENTS:
|
|
|
|
| 251 |
wall_mask = seg_class_mask(seg_map, class_ids({"wall"}))
|
| 252 |
wall_components = []
|
| 253 |
wall_protected_mask = None
|
| 254 |
+
# Raw point maps (MoGe) are independent of the surface mask. Reuse the
|
| 255 |
+
# floor's prepared normals instead of smoothing the entire image again for
|
| 256 |
+
# every wall region and every wall UV map.
|
| 257 |
+
wall_geometry_maps = (
|
| 258 |
+
prepared_geometry_maps
|
| 259 |
+
if geometry is not None and geometry.get("points") is not None
|
| 260 |
+
else None
|
| 261 |
+
)
|
| 262 |
|
| 263 |
+
# --- Wall discovery: overlap with floor processing ---
|
| 264 |
+
# Wall discovery only needs seg_map + geometry, both available now. Running
|
| 265 |
+
# it concurrently with surface masking / UV mapping / lighting hides its
|
| 266 |
+
# cost behind work that has to happen anyway.
|
| 267 |
from concurrent.futures import ThreadPoolExecutor, Future
|
| 268 |
+
_wall_discovery_future: Future | None = None
|
| 269 |
+
_wall_discovery_started: float = 0.0
|
| 270 |
+
if ENABLE_WALL_SEGMENTS:
|
| 271 |
+
_wall_discovery_started = time.perf_counter()
|
| 272 |
+
_wall_pool = ThreadPoolExecutor(max_workers=1)
|
| 273 |
+
_wall_discovery_future = _wall_pool.submit(
|
| 274 |
+
wall_surface_components,
|
| 275 |
+
seg_map, min_floor_area, geometry,
|
| 276 |
+
image_rgb=img_np, geometry_maps=wall_geometry_maps,
|
| 277 |
+
)
|
| 278 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
wall_lighting_enabled = (
|
| 280 |
ENABLE_INTRINSIC_SHADING or ENABLE_FAST_SHADOW_TRANSFER or ENABLE_SHADING_TRANSFER
|
| 281 |
)
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
if progress_callback:
|
| 284 |
progress_callback(PipelinePhase.LIGHTING, 100)
|
| 285 |
|
|
|
|
| 316 |
if progress_callback:
|
| 317 |
progress_callback(PipelinePhase.DIRECTION, 100)
|
| 318 |
|
| 319 |
+
# --- Collect wall discovery (was running in parallel) ---
|
| 320 |
+
if _wall_discovery_future is not None:
|
| 321 |
+
wall_components, wall_protected_mask = _wall_discovery_future.result()
|
| 322 |
+
_wall_pool.shutdown(wait=False)
|
| 323 |
+
_log_stage("Wall Discovery (async)", _wall_discovery_started, f"components={len(wall_components)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
|
| 325 |
# --- Package segments ---
|
| 326 |
if progress_callback:
|
|
|
|
| 351 |
break
|
| 352 |
if floor_up is not None:
|
| 353 |
print(f'[WALL_UP] using floor normal as vertical: {floor_up.round(3).tolist()}', flush=True)
|
| 354 |
+
|
| 355 |
+
# --- Parallel wall packaging ---
|
| 356 |
+
# Each build_wall_segment is independent (no shared mutable state).
|
| 357 |
wall_segments = []
|
| 358 |
+
if wall_components:
|
| 359 |
+
def _package_one_wall(wi_cm_planes):
|
| 360 |
+
wi, cm, planes = wi_cm_planes
|
| 361 |
+
return build_wall_segment(
|
| 362 |
+
wi, cm, wall_protected_mask, geometry, img_np, wall_components, models,
|
| 363 |
+
precomputed_lighting=None,
|
| 364 |
+
up_vector=floor_up,
|
| 365 |
+
lighting_enabled=wall_lighting_enabled,
|
| 366 |
+
geometry_maps=wall_geometry_maps,
|
| 367 |
+
precomputed_planes=planes,
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
+
wall_args = [(wi, cm, planes) for wi, (_, cm, planes) in enumerate(wall_components)]
|
| 371 |
+
if len(wall_args) > 1:
|
| 372 |
+
with ThreadPoolExecutor(max_workers=min(4, len(wall_args))) as wall_pkg_pool:
|
| 373 |
+
wall_results = list(wall_pkg_pool.map(_package_one_wall, wall_args))
|
| 374 |
+
else:
|
| 375 |
+
wall_results = [_package_one_wall(wall_args[0])]
|
| 376 |
+
for ws in wall_results:
|
| 377 |
+
if ws:
|
| 378 |
+
segments.append(ws)
|
| 379 |
+
wall_segments.append(ws)
|
| 380 |
+
|
| 381 |
# Only when wall discovery actually ran. With ENABLE_WALL_SEGMENTS off
|
| 382 |
# there is no protected mask and nothing to report.
|
| 383 |
if d and ENABLE_WALL_SEGMENTS:
|
services/pipeline/bundle_assembly.py
CHANGED
|
@@ -145,6 +145,8 @@ def build_wall_segment(
|
|
| 145 |
precomputed_lighting: dict | None = None,
|
| 146 |
up_vector=None,
|
| 147 |
lighting_enabled: bool = True,
|
|
|
|
|
|
|
| 148 |
) -> dict | None:
|
| 149 |
# True vertical, taken from the floor, reaches the plane fit as well as the
|
| 150 |
# UV mapping below. The plane's basis is what the renderer falls back to
|
|
@@ -181,12 +183,14 @@ def build_wall_segment(
|
|
| 181 |
# gravity-aligned: v runs up the wall, u runs along it.
|
| 182 |
wall_mapping = build_surface_uv_mapping(
|
| 183 |
component_mask, wall_indices, geometry,
|
|
|
|
| 184 |
mark_floor=False, min_coverage=SURFACE_UV_WALL_MIN_COVERAGE,
|
| 185 |
fill_missing_from_plane=True,
|
| 186 |
# True vertical, taken from the floor. Geometry providers work in
|
| 187 |
# camera coordinates, so assuming +Y is up rotates every wall's tile
|
| 188 |
# grid by the camera's tilt.
|
| 189 |
vertical_ref=up_vector,
|
|
|
|
| 190 |
)
|
| 191 |
use_wall_uv = bool(wall_mapping and wall_mapping.get("useSurfaceUv"))
|
| 192 |
wall_mapping_metadata = wall_mapping["metadata"] if wall_mapping is not None else {}
|
|
|
|
| 145 |
precomputed_lighting: dict | None = None,
|
| 146 |
up_vector=None,
|
| 147 |
lighting_enabled: bool = True,
|
| 148 |
+
geometry_maps: dict | None = None,
|
| 149 |
+
precomputed_planes: list[dict] | None = None,
|
| 150 |
) -> dict | None:
|
| 151 |
# True vertical, taken from the floor, reaches the plane fit as well as the
|
| 152 |
# UV mapping below. The plane's basis is what the renderer falls back to
|
|
|
|
| 183 |
# gravity-aligned: v runs up the wall, u runs along it.
|
| 184 |
wall_mapping = build_surface_uv_mapping(
|
| 185 |
component_mask, wall_indices, geometry,
|
| 186 |
+
geometry_maps=geometry_maps,
|
| 187 |
mark_floor=False, min_coverage=SURFACE_UV_WALL_MIN_COVERAGE,
|
| 188 |
fill_missing_from_plane=True,
|
| 189 |
# True vertical, taken from the floor. Geometry providers work in
|
| 190 |
# camera coordinates, so assuming +Y is up rotates every wall's tile
|
| 191 |
# grid by the camera's tilt.
|
| 192 |
vertical_ref=up_vector,
|
| 193 |
+
precomputed_planes=precomputed_planes,
|
| 194 |
)
|
| 195 |
use_wall_uv = bool(wall_mapping and wall_mapping.get("useSurfaceUv"))
|
| 196 |
wall_mapping_metadata = wall_mapping["metadata"] if wall_mapping is not None else {}
|
services/wall/components.py
CHANGED
|
@@ -24,8 +24,12 @@ from state import OCCLUDER_CLASSES, class_ids
|
|
| 24 |
from utils import seg_class_mask
|
| 25 |
|
| 26 |
|
| 27 |
-
def split_region_if_not_planar(region: np.ndarray, geometry: dict | None, min_area: int
|
| 28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
Connectivity alone is not quite enough: where two walls meet at a corner
|
| 31 |
with nothing between them, segmentation bridges the corner and hands us one
|
|
@@ -39,21 +43,21 @@ def split_region_if_not_planar(region: np.ndarray, geometry: dict | None, min_ar
|
|
| 39 |
region fails that test do we fall back to multi-plane splitting.
|
| 40 |
"""
|
| 41 |
if geometry is None:
|
| 42 |
-
return [region]
|
| 43 |
-
maps = geometry_point_maps(region, geometry)
|
| 44 |
if maps is None:
|
| 45 |
-
return [region]
|
| 46 |
|
| 47 |
valid = maps["validMask"] & (region > 0)
|
| 48 |
ys, xs = np.where(valid)
|
| 49 |
if len(xs) < SURFACE_MIN_PLANE_PIXELS:
|
| 50 |
-
return [region]
|
| 51 |
points = maps["points"][ys, xs].astype(np.float32)
|
| 52 |
normals = maps["normals"][ys, xs].astype(np.float32)
|
| 53 |
finite = np.isfinite(points).all(axis=1) & np.isfinite(normals).all(axis=1)
|
| 54 |
points, normals, ys, xs = points[finite], normals[finite], ys[finite], xs[finite]
|
| 55 |
if len(points) < SURFACE_MIN_PLANE_PIXELS:
|
| 56 |
-
return [region]
|
| 57 |
|
| 58 |
threshold = surface_distance_threshold(points)
|
| 59 |
centered = points - points.mean(axis=0)
|
|
@@ -67,12 +71,12 @@ def split_region_if_not_planar(region: np.ndarray, geometry: dict | None, min_ar
|
|
| 67 |
flush=True,
|
| 68 |
)
|
| 69 |
if flatness <= threshold:
|
| 70 |
-
return [region]
|
| 71 |
|
| 72 |
lengths = np.linalg.norm(normals, axis=1)
|
| 73 |
usable = lengths > 1e-4
|
| 74 |
if int(usable.sum()) < SURFACE_MIN_PLANE_PIXELS:
|
| 75 |
-
return [region]
|
| 76 |
points, ys, xs = points[usable], ys[usable], xs[usable]
|
| 77 |
normals = normalize_vectors(normals[usable])
|
| 78 |
|
|
@@ -80,14 +84,14 @@ def split_region_if_not_planar(region: np.ndarray, geometry: dict | None, min_ar
|
|
| 80 |
planes = merge_coplanar_planes(planes, threshold)
|
| 81 |
wall_planes = [plane for plane in planes if abs(float(plane["normal"][1])) <= 0.45]
|
| 82 |
if len(wall_planes) <= 1:
|
| 83 |
-
return [region]
|
| 84 |
|
| 85 |
assignment = assign_points_to_surface_planes(points, normals, wall_planes, True)
|
| 86 |
assignment, wall_planes = merge_planes_by_point_consistency(
|
| 87 |
points, assignment, wall_planes, threshold
|
| 88 |
)
|
| 89 |
if len(wall_planes) <= 1:
|
| 90 |
-
return [region]
|
| 91 |
|
| 92 |
pieces = []
|
| 93 |
for plane_index in range(len(wall_planes)):
|
|
@@ -98,20 +102,31 @@ def split_region_if_not_planar(region: np.ndarray, geometry: dict | None, min_ar
|
|
| 98 |
piece[ys[selected], xs[selected]] = 1
|
| 99 |
pieces.append((plane_index, piece))
|
| 100 |
if not pieces:
|
| 101 |
-
return [region]
|
| 102 |
|
| 103 |
# Per-pixel assignment is the wrong tool for the seam *between* these
|
| 104 |
# pieces. At the corner every plane is equidistant, so the score collapses
|
| 105 |
# onto blended depth normals and the boundary ends up both biased and
|
| 106 |
# ragged. Put each seam back on the line where its two planes actually
|
| 107 |
# intersect -- see services/wall/corner.py for the measurements.
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict | None = None,
|
| 112 |
-
image_rgb: np.ndarray | None = None
|
|
|
|
| 113 |
"""Create clean, independently renderable wall regions.
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
Semantic wall predictions often bridge across corners and openings. Removing
|
| 116 |
protected classes before connected-component analysis prevents one warped
|
| 117 |
transform from being applied to several physically different walls.
|
|
@@ -161,14 +176,16 @@ def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict |
|
|
| 161 |
print(f"[WALL_COMPONENTS] {len(regions)} connected wall region(s)", flush=True)
|
| 162 |
|
| 163 |
# --- Stage 2: geometry only splits a region that is not actually flat -----
|
| 164 |
-
# components is a list of (area, mask)
|
| 165 |
-
#
|
| 166 |
components = []
|
| 167 |
for region in regions:
|
| 168 |
-
for piece in split_region_if_not_planar(
|
|
|
|
|
|
|
| 169 |
area = int(piece.sum())
|
| 170 |
if area >= min_area:
|
| 171 |
-
components.append((area, piece.astype(np.uint8)))
|
| 172 |
|
| 173 |
# --- Repair pass -------------------------------------------------------
|
| 174 |
# Splitting above deliberately runs on the protected-subtracted mask, so one
|
|
@@ -182,7 +199,7 @@ def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict |
|
|
| 182 |
components.sort(key=lambda item: item[0], reverse=True)
|
| 183 |
claimed = np.zeros(wall_raw.shape[:2], dtype=bool)
|
| 184 |
refined_components = []
|
| 185 |
-
for _, component_mask in components:
|
| 186 |
refined, _metadata = refine_wall_component_mask(
|
| 187 |
component_mask, wall_raw, reclaimable_mask, barrier_mask, image_rgb
|
| 188 |
)
|
|
@@ -191,13 +208,13 @@ def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict |
|
|
| 191 |
if area < min_area:
|
| 192 |
continue
|
| 193 |
claimed |= refined.astype(bool)
|
| 194 |
-
refined_components.append((area, refined))
|
| 195 |
|
| 196 |
if refined_components:
|
| 197 |
refined_components.sort(key=lambda item: item[0], reverse=True)
|
| 198 |
print(
|
| 199 |
f"[WALL_COMPONENTS] emitting {len(refined_components)} wall segment(s): "
|
| 200 |
-
f"{[area for area, _ in refined_components]} px",
|
| 201 |
flush=True,
|
| 202 |
)
|
| 203 |
return refined_components, protected
|
|
|
|
| 24 |
from utils import seg_class_mask
|
| 25 |
|
| 26 |
|
| 27 |
+
def split_region_if_not_planar(region: np.ndarray, geometry: dict | None, min_area: int,
|
| 28 |
+
*, geometry_maps: dict | None = None):
|
| 29 |
+
"""Return [(mask, planes)] tuples — one flat wall or several split pieces.
|
| 30 |
+
|
| 31 |
+
Each returned item is ``(mask, planes_list)`` where *planes_list* carries
|
| 32 |
+
the fitted plane dicts so downstream stages can skip a duplicate RANSAC.
|
| 33 |
|
| 34 |
Connectivity alone is not quite enough: where two walls meet at a corner
|
| 35 |
with nothing between them, segmentation bridges the corner and hands us one
|
|
|
|
| 43 |
region fails that test do we fall back to multi-plane splitting.
|
| 44 |
"""
|
| 45 |
if geometry is None:
|
| 46 |
+
return [(region, None)]
|
| 47 |
+
maps = geometry_maps if geometry_maps is not None else geometry_point_maps(region, geometry)
|
| 48 |
if maps is None:
|
| 49 |
+
return [(region, None)]
|
| 50 |
|
| 51 |
valid = maps["validMask"] & (region > 0)
|
| 52 |
ys, xs = np.where(valid)
|
| 53 |
if len(xs) < SURFACE_MIN_PLANE_PIXELS:
|
| 54 |
+
return [(region, None)]
|
| 55 |
points = maps["points"][ys, xs].astype(np.float32)
|
| 56 |
normals = maps["normals"][ys, xs].astype(np.float32)
|
| 57 |
finite = np.isfinite(points).all(axis=1) & np.isfinite(normals).all(axis=1)
|
| 58 |
points, normals, ys, xs = points[finite], normals[finite], ys[finite], xs[finite]
|
| 59 |
if len(points) < SURFACE_MIN_PLANE_PIXELS:
|
| 60 |
+
return [(region, None)]
|
| 61 |
|
| 62 |
threshold = surface_distance_threshold(points)
|
| 63 |
centered = points - points.mean(axis=0)
|
|
|
|
| 71 |
flush=True,
|
| 72 |
)
|
| 73 |
if flatness <= threshold:
|
| 74 |
+
return [(region, None)]
|
| 75 |
|
| 76 |
lengths = np.linalg.norm(normals, axis=1)
|
| 77 |
usable = lengths > 1e-4
|
| 78 |
if int(usable.sum()) < SURFACE_MIN_PLANE_PIXELS:
|
| 79 |
+
return [(region, None)]
|
| 80 |
points, ys, xs = points[usable], ys[usable], xs[usable]
|
| 81 |
normals = normalize_vectors(normals[usable])
|
| 82 |
|
|
|
|
| 84 |
planes = merge_coplanar_planes(planes, threshold)
|
| 85 |
wall_planes = [plane for plane in planes if abs(float(plane["normal"][1])) <= 0.45]
|
| 86 |
if len(wall_planes) <= 1:
|
| 87 |
+
return [(region, wall_planes if wall_planes else None)]
|
| 88 |
|
| 89 |
assignment = assign_points_to_surface_planes(points, normals, wall_planes, True)
|
| 90 |
assignment, wall_planes = merge_planes_by_point_consistency(
|
| 91 |
points, assignment, wall_planes, threshold
|
| 92 |
)
|
| 93 |
if len(wall_planes) <= 1:
|
| 94 |
+
return [(region, wall_planes if wall_planes else None)]
|
| 95 |
|
| 96 |
pieces = []
|
| 97 |
for plane_index in range(len(wall_planes)):
|
|
|
|
| 102 |
piece[ys[selected], xs[selected]] = 1
|
| 103 |
pieces.append((plane_index, piece))
|
| 104 |
if not pieces:
|
| 105 |
+
return [(region, None)]
|
| 106 |
|
| 107 |
# Per-pixel assignment is the wrong tool for the seam *between* these
|
| 108 |
# pieces. At the corner every plane is equidistant, so the score collapses
|
| 109 |
# onto blended depth normals and the boundary ends up both biased and
|
| 110 |
# ragged. Put each seam back on the line where its two planes actually
|
| 111 |
# intersect -- see services/wall/corner.py for the measurements.
|
| 112 |
+
straightened = straighten_piece_seams(pieces, wall_planes, maps.get("intrinsics"), min_area)
|
| 113 |
+
result = []
|
| 114 |
+
for i, mask in enumerate(straightened):
|
| 115 |
+
plane_idx = pieces[i][0] if i < len(pieces) else 0
|
| 116 |
+
piece_plane = [wall_planes[plane_idx]] if plane_idx < len(wall_planes) else None
|
| 117 |
+
result.append((mask, piece_plane))
|
| 118 |
+
return result
|
| 119 |
|
| 120 |
|
| 121 |
def wall_surface_components(seg_map: np.ndarray, min_area: int, geometry: dict | None = None,
|
| 122 |
+
image_rgb: np.ndarray | None = None,
|
| 123 |
+
*, geometry_maps: dict | None = None):
|
| 124 |
"""Create clean, independently renderable wall regions.
|
| 125 |
|
| 126 |
+
Returns ``(components, protected)`` where each component is
|
| 127 |
+
``(area, mask, precomputed_planes)`` — the planes fitted during discovery
|
| 128 |
+
so downstream stages can reuse them instead of running RANSAC again.
|
| 129 |
+
|
| 130 |
Semantic wall predictions often bridge across corners and openings. Removing
|
| 131 |
protected classes before connected-component analysis prevents one warped
|
| 132 |
transform from being applied to several physically different walls.
|
|
|
|
| 176 |
print(f"[WALL_COMPONENTS] {len(regions)} connected wall region(s)", flush=True)
|
| 177 |
|
| 178 |
# --- Stage 2: geometry only splits a region that is not actually flat -----
|
| 179 |
+
# components is a list of (area, mask, planes) tuples; planes are carried
|
| 180 |
+
# through so build_wall_segment can skip a duplicate RANSAC.
|
| 181 |
components = []
|
| 182 |
for region in regions:
|
| 183 |
+
for piece, planes in split_region_if_not_planar(
|
| 184 |
+
region, geometry, min_area, geometry_maps=geometry_maps,
|
| 185 |
+
):
|
| 186 |
area = int(piece.sum())
|
| 187 |
if area >= min_area:
|
| 188 |
+
components.append((area, piece.astype(np.uint8), planes))
|
| 189 |
|
| 190 |
# --- Repair pass -------------------------------------------------------
|
| 191 |
# Splitting above deliberately runs on the protected-subtracted mask, so one
|
|
|
|
| 199 |
components.sort(key=lambda item: item[0], reverse=True)
|
| 200 |
claimed = np.zeros(wall_raw.shape[:2], dtype=bool)
|
| 201 |
refined_components = []
|
| 202 |
+
for _, component_mask, planes in components:
|
| 203 |
refined, _metadata = refine_wall_component_mask(
|
| 204 |
component_mask, wall_raw, reclaimable_mask, barrier_mask, image_rgb
|
| 205 |
)
|
|
|
|
| 208 |
if area < min_area:
|
| 209 |
continue
|
| 210 |
claimed |= refined.astype(bool)
|
| 211 |
+
refined_components.append((area, refined, planes))
|
| 212 |
|
| 213 |
if refined_components:
|
| 214 |
refined_components.sort(key=lambda item: item[0], reverse=True)
|
| 215 |
print(
|
| 216 |
f"[WALL_COMPONENTS] emitting {len(refined_components)} wall segment(s): "
|
| 217 |
+
f"{[area for area, _ , _ in refined_components]} px",
|
| 218 |
flush=True,
|
| 219 |
)
|
| 220 |
return refined_components, protected
|
services/wall/mask.py
CHANGED
|
@@ -241,11 +241,14 @@ def refine_wall_component_mask(
|
|
| 241 |
# actually shows, then re-apply the semantic clamp -- the filter knows about
|
| 242 |
# image edges, not about classes, so on its own it would happily drift a few
|
| 243 |
# pixels onto the ceiling.
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
|
|
|
|
|
|
|
|
|
| 249 |
|
| 250 |
after = int(refined.sum())
|
| 251 |
metadata = {
|
|
|
|
| 241 |
# actually shows, then re-apply the semantic clamp -- the filter knows about
|
| 242 |
# image edges, not about classes, so on its own it would happily drift a few
|
| 243 |
# pixels onto the ceiling.
|
| 244 |
+
# Skip the guided filter for small walls — the 7 box filters on the full
|
| 245 |
+
# image cost ~200-500ms per wall and small walls don't benefit much.
|
| 246 |
+
if int(refined.sum()) >= 50000:
|
| 247 |
+
snapped = snap_mask_to_image_edges(refined, image_rgb)
|
| 248 |
+
snapped = _clamp(snapped, allowed, barrier)
|
| 249 |
+
snapped = keep_connected_to(snapped, seed)
|
| 250 |
+
if snapped.any():
|
| 251 |
+
refined = snapped
|
| 252 |
|
| 253 |
after = int(refined.sum())
|
| 254 |
metadata = {
|
visualizer.gpu.toml
CHANGED
|
@@ -20,7 +20,7 @@ enable_multi_plane_surfaces = true
|
|
| 20 |
enable_wall_segments = true
|
| 21 |
enable_intrinsic_shading = false
|
| 22 |
enable_shading_transfer = false
|
| 23 |
-
enable_fast_shadow_transfer =
|
| 24 |
fast_shadow_max_dimension = 640
|
| 25 |
enable_sam_refinement = false
|
| 26 |
enable_floor_mask_cleanup = true
|
|
|
|
| 20 |
enable_wall_segments = true
|
| 21 |
enable_intrinsic_shading = false
|
| 22 |
enable_shading_transfer = false
|
| 23 |
+
enable_fast_shadow_transfer = false
|
| 24 |
fast_shadow_max_dimension = 640
|
| 25 |
enable_sam_refinement = false
|
| 26 |
enable_floor_mask_cleanup = true
|
visualizer.hf.toml
CHANGED
|
@@ -20,7 +20,7 @@ enable_multi_plane_surfaces = true
|
|
| 20 |
enable_wall_segments = true
|
| 21 |
enable_intrinsic_shading = false
|
| 22 |
enable_shading_transfer = false
|
| 23 |
-
enable_fast_shadow_transfer =
|
| 24 |
fast_shadow_max_dimension = 640
|
| 25 |
enable_sam_refinement = false
|
| 26 |
enable_floor_mask_cleanup = true
|
|
|
|
| 20 |
enable_wall_segments = true
|
| 21 |
enable_intrinsic_shading = false
|
| 22 |
enable_shading_transfer = false
|
| 23 |
+
enable_fast_shadow_transfer = false
|
| 24 |
fast_shadow_max_dimension = 640
|
| 25 |
enable_sam_refinement = false
|
| 26 |
enable_floor_mask_cleanup = true
|
visualizer.local.toml
CHANGED
|
@@ -16,7 +16,7 @@ enable_multi_plane_surfaces = true
|
|
| 16 |
enable_wall_segments = true
|
| 17 |
enable_intrinsic_shading = false
|
| 18 |
enable_shading_transfer = false
|
| 19 |
-
enable_fast_shadow_transfer =
|
| 20 |
fast_shadow_max_dimension = 640
|
| 21 |
enable_sam_refinement = false
|
| 22 |
warm_start_models = true
|
|
|
|
| 16 |
enable_wall_segments = true
|
| 17 |
enable_intrinsic_shading = false
|
| 18 |
enable_shading_transfer = false
|
| 19 |
+
enable_fast_shadow_transfer = false
|
| 20 |
fast_shadow_max_dimension = 640
|
| 21 |
enable_sam_refinement = false
|
| 22 |
warm_start_models = true
|