github-actions[bot] commited on
Commit ·
8e53f1d
1
Parent(s): 8864029
Automated Deploy: 23ddc51d081e41766714ef78446d5bc25617161b
Browse files- app.py +1 -1
- config/lighting.py +1 -1
- config/runtime.py +8 -1
- routes/viz2d.py +49 -2
- services/direction/analysis.py +2 -1
- services/floor/geometry_filter.py +13 -7
- services/floor/mask.py +61 -3
- services/geometry/multi_plane.py +27 -5
- services/geometry/ransac.py +86 -41
- services/geometry/uv_mapping.py +44 -14
- services/jobs/conversion.py +40 -38
- services/lighting/shading.py +76 -1
- services/pipeline/builder.py +95 -12
- services/pipeline/bundle_assembly.py +7 -1
- services/pipeline/packaging.py +59 -6
- test_fast_shadow_transfer.py +36 -0
- test_geometry_optimization.py +116 -0
- visualizer.gpu.toml +7 -5
- visualizer.hf.toml +7 -4
- visualizer.local.toml +4 -2
app.py
CHANGED
|
@@ -17,7 +17,7 @@ app.add_middleware(
|
|
| 17 |
allow_methods=["*"],
|
| 18 |
allow_headers=["*"],
|
| 19 |
)
|
| 20 |
-
app.add_middleware(GZipMiddleware, minimum_size=1024)
|
| 21 |
|
| 22 |
app.include_router(viz2d.router)
|
| 23 |
app.include_router(qa.router)
|
|
|
|
| 17 |
allow_methods=["*"],
|
| 18 |
allow_headers=["*"],
|
| 19 |
)
|
| 20 |
+
app.add_middleware(GZipMiddleware, minimum_size=1024, compresslevel=4)
|
| 21 |
|
| 22 |
app.include_router(viz2d.router)
|
| 23 |
app.include_router(qa.router)
|
config/lighting.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
LIGHTING_TRANSFER_VERSION =
|
| 2 |
|
| 3 |
SHADE_MAP_MIN = 0.15
|
| 4 |
SHADE_MAP_MAX = 1.10
|
|
|
|
| 1 |
+
LIGHTING_TRANSFER_VERSION = 5
|
| 2 |
|
| 3 |
SHADE_MAP_MIN = 0.15
|
| 4 |
SHADE_MAP_MAX = 1.10
|
config/runtime.py
CHANGED
|
@@ -6,9 +6,12 @@ ENABLE_FLOOR_MASK_CLEANUP = config_bool("ENABLE_FLOOR_MASK_CLEANUP", "runtime",
|
|
| 6 |
ENABLE_DEPTH_ESTIMATION = config_bool("ENABLE_DEPTH_ESTIMATION", "runtime", "enable_depth_estimation", "1")
|
| 7 |
ENABLE_PLANE_FIT = config_bool("ENABLE_PLANE_FIT", "runtime", "enable_plane_fit", "1")
|
| 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", "
|
| 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", "1")
|
|
|
|
|
|
|
|
|
|
| 12 |
WARM_START_MODELS = config_bool("WARM_START_MODELS", "runtime", "warm_start_models", "1")
|
| 13 |
|
| 14 |
ENABLE_ONNX_INFERENCE = config_bool("ENABLE_ONNX_INFERENCE", "runtime", "enable_onnx_inference", "0")
|
|
@@ -33,6 +36,10 @@ INFERENCE_MAX_DIMENSION = max(512, int(config_value(
|
|
| 33 |
"INFERENCE_MAX_DIMENSION", "runtime", "inference_max_dimension", "1024",
|
| 34 |
)))
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
ROOM_UPLOAD_JPEG_QUALITY = min(95, max(50, int(config_value(
|
| 37 |
"ROOM_UPLOAD_JPEG_QUALITY", "runtime", "room_upload_jpeg_quality", "85",
|
| 38 |
))))
|
|
|
|
| 6 |
ENABLE_DEPTH_ESTIMATION = config_bool("ENABLE_DEPTH_ESTIMATION", "runtime", "enable_depth_estimation", "1")
|
| 7 |
ENABLE_PLANE_FIT = config_bool("ENABLE_PLANE_FIT", "runtime", "enable_plane_fit", "1")
|
| 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", "0")
|
| 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", "1")
|
| 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 |
|
| 17 |
ENABLE_ONNX_INFERENCE = config_bool("ENABLE_ONNX_INFERENCE", "runtime", "enable_onnx_inference", "0")
|
|
|
|
| 36 |
"INFERENCE_MAX_DIMENSION", "runtime", "inference_max_dimension", "1024",
|
| 37 |
)))
|
| 38 |
|
| 39 |
+
FAST_SHADOW_MAX_DIMENSION = max(256, min(1024, int(config_value(
|
| 40 |
+
"FAST_SHADOW_MAX_DIMENSION", "runtime", "fast_shadow_max_dimension", "640",
|
| 41 |
+
))))
|
| 42 |
+
|
| 43 |
ROOM_UPLOAD_JPEG_QUALITY = min(95, max(50, int(config_value(
|
| 44 |
"ROOM_UPLOAD_JPEG_QUALITY", "runtime", "room_upload_jpeg_quality", "85",
|
| 45 |
))))
|
routes/viz2d.py
CHANGED
|
@@ -1,12 +1,13 @@
|
|
| 1 |
"""Viz2D conversion and job management routes."""
|
| 2 |
|
| 3 |
import json
|
|
|
|
| 4 |
import time
|
| 5 |
import uuid
|
| 6 |
from datetime import datetime, timezone
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
-
from fastapi import APIRouter, BackgroundTasks, File, Query, Response, UploadFile
|
| 10 |
|
| 11 |
from config.paths import JOB_DIR, UPLOAD_DIR
|
| 12 |
from config.runtime import CONVERSION_TARGET_MS, DEBUG_ARTIFACTS_ENABLED
|
|
@@ -42,12 +43,14 @@ async def convert_to_viz2d(background_tasks: BackgroundTasks, file: UploadFile =
|
|
| 42 |
content_type = "image/jpeg"
|
| 43 |
ext = ".jpg"
|
| 44 |
upload_path = UPLOAD_DIR / f"{job_id}{ext}"
|
|
|
|
| 45 |
upload_path.write_bytes(normalized_contents)
|
|
|
|
| 46 |
|
| 47 |
size_kb = len(contents) / 1024
|
| 48 |
print(
|
| 49 |
f"\n[JOB {job_id[:8]}] Upload received: {original_filename} ({size_kb:.0f} KB)"
|
| 50 |
-
f" | read={t_read:.2f}s | normalize={t_normalize:.2f}s",
|
| 51 |
flush=True,
|
| 52 |
)
|
| 53 |
|
|
@@ -65,6 +68,11 @@ async def convert_to_viz2d(background_tasks: BackgroundTasks, file: UploadFile =
|
|
| 65 |
"inputUrl": f"/uploads/{upload_path.name}",
|
| 66 |
"outputUrl": f"/viz2d/jobs/{job_id}/file",
|
| 67 |
"debugUrl": f"/viz2d/jobs/{job_id}/debug" if DEBUG_ARTIFACTS_ENABLED else None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
}
|
| 69 |
write_job(job)
|
| 70 |
background_tasks.add_task(run_conversion_task, job_id, upload_path)
|
|
@@ -93,6 +101,45 @@ async def viz2d_list_jobs(
|
|
| 93 |
return {"total": total, "offset": offset, "limit": limit, "jobs": jobs[offset : offset + limit]}
|
| 94 |
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
@router.get("/jobs/{job_id}")
|
| 97 |
async def viz2d_job_status(job_id: str):
|
| 98 |
return read_job(job_id)
|
|
|
|
| 1 |
"""Viz2D conversion and job management routes."""
|
| 2 |
|
| 3 |
import json
|
| 4 |
+
import math
|
| 5 |
import time
|
| 6 |
import uuid
|
| 7 |
from datetime import datetime, timezone
|
| 8 |
from pathlib import Path
|
| 9 |
|
| 10 |
+
from fastapi import APIRouter, BackgroundTasks, Body, File, Query, Response, UploadFile
|
| 11 |
|
| 12 |
from config.paths import JOB_DIR, UPLOAD_DIR
|
| 13 |
from config.runtime import CONVERSION_TARGET_MS, DEBUG_ARTIFACTS_ENABLED
|
|
|
|
| 43 |
content_type = "image/jpeg"
|
| 44 |
ext = ".jpg"
|
| 45 |
upload_path = UPLOAD_DIR / f"{job_id}{ext}"
|
| 46 |
+
t0 = time.perf_counter()
|
| 47 |
upload_path.write_bytes(normalized_contents)
|
| 48 |
+
t_persist = time.perf_counter() - t0
|
| 49 |
|
| 50 |
size_kb = len(contents) / 1024
|
| 51 |
print(
|
| 52 |
f"\n[JOB {job_id[:8]}] Upload received: {original_filename} ({size_kb:.0f} KB)"
|
| 53 |
+
f" | read={t_read:.2f}s | normalize={t_normalize:.2f}s | persist={t_persist:.2f}s",
|
| 54 |
flush=True,
|
| 55 |
)
|
| 56 |
|
|
|
|
| 68 |
"inputUrl": f"/uploads/{upload_path.name}",
|
| 69 |
"outputUrl": f"/viz2d/jobs/{job_id}/file",
|
| 70 |
"debugUrl": f"/viz2d/jobs/{job_id}/debug" if DEBUG_ARTIFACTS_ENABLED else None,
|
| 71 |
+
"requestTimings": {
|
| 72 |
+
"serverReadMs": round(t_read * 1000),
|
| 73 |
+
"normalizeMs": round(t_normalize * 1000),
|
| 74 |
+
"persistMs": round(t_persist * 1000),
|
| 75 |
+
},
|
| 76 |
}
|
| 77 |
write_job(job)
|
| 78 |
background_tasks.add_task(run_conversion_task, job_id, upload_path)
|
|
|
|
| 101 |
return {"total": total, "offset": offset, "limit": limit, "jobs": jobs[offset : offset + limit]}
|
| 102 |
|
| 103 |
|
| 104 |
+
@router.post("/jobs/{job_id}/client-timings")
|
| 105 |
+
async def viz2d_record_client_timings(job_id: str, payload: dict = Body(...)):
|
| 106 |
+
"""Persist bounded browser timing events alongside their conversion job."""
|
| 107 |
+
raw_events = payload.get("events")
|
| 108 |
+
if not isinstance(raw_events, list):
|
| 109 |
+
bad_request("events must be a list.")
|
| 110 |
+
|
| 111 |
+
events = []
|
| 112 |
+
for raw_event in raw_events[:20]:
|
| 113 |
+
if not isinstance(raw_event, dict):
|
| 114 |
+
continue
|
| 115 |
+
event = {}
|
| 116 |
+
for key, value in list(raw_event.items())[:40]:
|
| 117 |
+
if not isinstance(key, str) or len(key) > 64:
|
| 118 |
+
continue
|
| 119 |
+
if isinstance(value, bool):
|
| 120 |
+
event[key] = value
|
| 121 |
+
elif isinstance(value, (int, float)):
|
| 122 |
+
try:
|
| 123 |
+
numeric_value = float(value)
|
| 124 |
+
except (OverflowError, ValueError):
|
| 125 |
+
continue
|
| 126 |
+
if math.isfinite(numeric_value):
|
| 127 |
+
event[key] = round(numeric_value, 3)
|
| 128 |
+
elif isinstance(value, str):
|
| 129 |
+
event[key] = value[:200]
|
| 130 |
+
if isinstance(event.get("type"), str):
|
| 131 |
+
events.append(event)
|
| 132 |
+
|
| 133 |
+
job = read_job(job_id)
|
| 134 |
+
existing = job.get("clientTimingEvents")
|
| 135 |
+
if not isinstance(existing, list):
|
| 136 |
+
existing = []
|
| 137 |
+
job["clientTimingEvents"] = (existing + events)[-50:]
|
| 138 |
+
job["clientTimingsUpdatedAt"] = datetime.now(timezone.utc).isoformat()
|
| 139 |
+
write_job(job)
|
| 140 |
+
return {"ok": True, "stored": len(events)}
|
| 141 |
+
|
| 142 |
+
|
| 143 |
@router.get("/jobs/{job_id}")
|
| 144 |
async def viz2d_job_status(job_id: str):
|
| 145 |
return read_job(job_id)
|
services/direction/analysis.py
CHANGED
|
@@ -13,10 +13,11 @@ def floor_direction_geometry_inputs(
|
|
| 13 |
surface_mapping: dict | None,
|
| 14 |
*,
|
| 15 |
use_surface_uv: bool,
|
|
|
|
| 16 |
) -> dict:
|
| 17 |
direction_maps = surface_mapping
|
| 18 |
if direction_maps is None:
|
| 19 |
-
raw_maps = geometry_point_maps(surface_mask, geometry)
|
| 20 |
if raw_maps is not None:
|
| 21 |
direction_maps = {
|
| 22 |
"normalMap": raw_maps["normals"],
|
|
|
|
| 13 |
surface_mapping: dict | None,
|
| 14 |
*,
|
| 15 |
use_surface_uv: bool,
|
| 16 |
+
geometry_maps: dict | None = None,
|
| 17 |
) -> dict:
|
| 18 |
direction_maps = surface_mapping
|
| 19 |
if direction_maps is None:
|
| 20 |
+
raw_maps = geometry_maps if geometry_maps is not None else geometry_point_maps(surface_mask, geometry)
|
| 21 |
if raw_maps is not None:
|
| 22 |
direction_maps = {
|
| 23 |
"normalMap": raw_maps["normals"],
|
services/floor/geometry_filter.py
CHANGED
|
@@ -25,6 +25,8 @@ def filter_surface_by_floor_geometry(
|
|
| 25 |
surface: np.ndarray,
|
| 26 |
geometry: dict | None,
|
| 27 |
plane: dict | None,
|
|
|
|
|
|
|
| 28 |
) -> tuple[np.ndarray, dict]:
|
| 29 |
before = int(surface.sum())
|
| 30 |
metadata = {
|
|
@@ -43,7 +45,7 @@ def filter_surface_by_floor_geometry(
|
|
| 43 |
if not plane.get("planeNormal") or not plane.get("planeOrigin"):
|
| 44 |
return surface, metadata
|
| 45 |
|
| 46 |
-
maps = geometry_point_maps(surface, geometry)
|
| 47 |
if maps is None:
|
| 48 |
metadata["geometrySurfaceFilterReason"] = "point-map-unavailable"
|
| 49 |
return surface, metadata
|
|
@@ -68,13 +70,17 @@ def filter_surface_by_floor_geometry(
|
|
| 68 |
keep = valid & (distances <= SURFACE_PLANE_DISTANCE_METERS)
|
| 69 |
|
| 70 |
if normals is not None and normals.shape[:2] == surface.shape:
|
| 71 |
-
|
| 72 |
-
normal_valid = valid &
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
if int(normal_valid.sum()) >= SURFACE_MIN_PLANE_PIXELS:
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
alignment
|
| 78 |
keep &= (~normal_valid) | (alignment >= SURFACE_PLANE_NORMAL_MIN_COS)
|
| 79 |
metadata["geometrySurfaceNormalPixels"] = int(normal_valid.sum())
|
| 80 |
|
|
|
|
| 25 |
surface: np.ndarray,
|
| 26 |
geometry: dict | None,
|
| 27 |
plane: dict | None,
|
| 28 |
+
*,
|
| 29 |
+
geometry_maps: dict | None = None,
|
| 30 |
) -> tuple[np.ndarray, dict]:
|
| 31 |
before = int(surface.sum())
|
| 32 |
metadata = {
|
|
|
|
| 45 |
if not plane.get("planeNormal") or not plane.get("planeOrigin"):
|
| 46 |
return surface, metadata
|
| 47 |
|
| 48 |
+
maps = geometry_maps if geometry_maps is not None else geometry_point_maps(surface, geometry)
|
| 49 |
if maps is None:
|
| 50 |
metadata["geometrySurfaceFilterReason"] = "point-map-unavailable"
|
| 51 |
return surface, metadata
|
|
|
|
| 70 |
keep = valid & (distances <= SURFACE_PLANE_DISTANCE_METERS)
|
| 71 |
|
| 72 |
if normals is not None and normals.shape[:2] == surface.shape:
|
| 73 |
+
prepared_normal_valid = maps.get("normalValidMask")
|
| 74 |
+
normal_valid = valid & (
|
| 75 |
+
prepared_normal_valid
|
| 76 |
+
if prepared_normal_valid is not None and prepared_normal_valid.shape == surface.shape
|
| 77 |
+
else np.isfinite(normals).all(axis=2) & (np.linalg.norm(normals, axis=2) > 1e-4)
|
| 78 |
+
)
|
| 79 |
if int(normal_valid.sum()) >= SURFACE_MIN_PLANE_PIXELS:
|
| 80 |
+
# geometry_point_maps returns normalized normals. Reuse them
|
| 81 |
+
# directly instead of allocating and normalizing another full-size
|
| 82 |
+
# HxWx3 array for every surface-filter pass.
|
| 83 |
+
alignment = np.abs(np.einsum("ijk,k->ij", normals, plane_normal, optimize=True))
|
| 84 |
keep &= (~normal_valid) | (alignment >= SURFACE_PLANE_NORMAL_MIN_COS)
|
| 85 |
metadata["geometrySurfaceNormalPixels"] = int(normal_valid.sum())
|
| 86 |
|
services/floor/mask.py
CHANGED
|
@@ -7,6 +7,8 @@ wall_subtract - remove wall/reject pixels from a floor mask
|
|
| 7 |
build_floor_surface_mask - composite floor surface from segmentation, depth, and geometry
|
| 8 |
"""
|
| 9 |
|
|
|
|
|
|
|
| 10 |
import cv2
|
| 11 |
import numpy as np
|
| 12 |
|
|
@@ -86,7 +88,11 @@ def build_floor_surface_mask(
|
|
| 86 |
depth: np.ndarray | None,
|
| 87 |
geometry: dict | None,
|
| 88 |
plane: dict | None,
|
|
|
|
|
|
|
| 89 |
):
|
|
|
|
|
|
|
| 90 |
h, w = floor_mask.shape[:2]
|
| 91 |
kern_size = max(5, min(h, w) // 160) | 1
|
| 92 |
kern = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kern_size, kern_size))
|
|
@@ -137,19 +143,37 @@ def build_floor_surface_mask(
|
|
| 137 |
surface[occluder_mask > 0] = 0
|
| 138 |
surface[reject_mask > 0] = 0
|
| 139 |
surface[soft_covering_mask > 0] = 0
|
|
|
|
| 140 |
|
| 141 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 142 |
surface[occluder_mask > 0] = 0
|
| 143 |
surface[reject_mask > 0] = 0
|
| 144 |
surface[soft_covering_mask > 0] = 0
|
| 145 |
|
|
|
|
| 146 |
surface = clean_floor_mask(surface)
|
| 147 |
surface[occluder_mask > 0] = 0
|
| 148 |
surface[reject_mask > 0] = 0
|
| 149 |
surface[soft_covering_mask > 0] = 0
|
| 150 |
|
| 151 |
surface, edge_metadata = improve_surface_edge_coverage(surface, normal_edge_protected_mask)
|
| 152 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
surface[occluder_mask > 0] = 0
|
| 154 |
surface[reject_mask > 0] = 0
|
| 155 |
surface[soft_covering_mask > 0] = 0
|
|
@@ -158,22 +182,56 @@ def build_floor_surface_mask(
|
|
| 158 |
for k, value in post_edge_filter_metadata.items()
|
| 159 |
}
|
| 160 |
|
|
|
|
|
|
|
| 161 |
surface, soft_covering_metadata = expand_surface_over_soft_floor_coverings(
|
| 162 |
surface,
|
| 163 |
soft_covering_mask,
|
| 164 |
hard_protected_mask,
|
| 165 |
)
|
| 166 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 167 |
surface[occluder_mask > 0] = 0
|
| 168 |
surface[reject_mask > 0] = 0
|
| 169 |
post_soft_covering_filter_metadata = {
|
| 170 |
f"postSoftFloorCovering{k[0].upper()}{k[1:]}": value
|
| 171 |
for k, value in post_soft_covering_filter_metadata.items()
|
| 172 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
return surface, {
|
| 174 |
**geometry_filter_metadata,
|
| 175 |
**edge_metadata,
|
| 176 |
**post_edge_filter_metadata,
|
| 177 |
**soft_covering_metadata,
|
| 178 |
**post_soft_covering_filter_metadata,
|
|
|
|
| 179 |
}
|
|
|
|
| 7 |
build_floor_surface_mask - composite floor surface from segmentation, depth, and geometry
|
| 8 |
"""
|
| 9 |
|
| 10 |
+
import time
|
| 11 |
+
|
| 12 |
import cv2
|
| 13 |
import numpy as np
|
| 14 |
|
|
|
|
| 88 |
depth: np.ndarray | None,
|
| 89 |
geometry: dict | None,
|
| 90 |
plane: dict | None,
|
| 91 |
+
*,
|
| 92 |
+
geometry_maps: dict | None = None,
|
| 93 |
):
|
| 94 |
+
total_started = time.perf_counter()
|
| 95 |
+
phase_started = total_started
|
| 96 |
h, w = floor_mask.shape[:2]
|
| 97 |
kern_size = max(5, min(h, w) // 160) | 1
|
| 98 |
kern = cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (kern_size, kern_size))
|
|
|
|
| 143 |
surface[occluder_mask > 0] = 0
|
| 144 |
surface[reject_mask > 0] = 0
|
| 145 |
surface[soft_covering_mask > 0] = 0
|
| 146 |
+
preparation_ms = (time.perf_counter() - phase_started) * 1000
|
| 147 |
|
| 148 |
+
phase_started = time.perf_counter()
|
| 149 |
+
surface, geometry_filter_metadata = filter_surface_by_floor_geometry(
|
| 150 |
+
surface,
|
| 151 |
+
geometry,
|
| 152 |
+
plane,
|
| 153 |
+
geometry_maps=geometry_maps,
|
| 154 |
+
)
|
| 155 |
+
initial_filter_ms = (time.perf_counter() - phase_started) * 1000
|
| 156 |
surface[occluder_mask > 0] = 0
|
| 157 |
surface[reject_mask > 0] = 0
|
| 158 |
surface[soft_covering_mask > 0] = 0
|
| 159 |
|
| 160 |
+
phase_started = time.perf_counter()
|
| 161 |
surface = clean_floor_mask(surface)
|
| 162 |
surface[occluder_mask > 0] = 0
|
| 163 |
surface[reject_mask > 0] = 0
|
| 164 |
surface[soft_covering_mask > 0] = 0
|
| 165 |
|
| 166 |
surface, edge_metadata = improve_surface_edge_coverage(surface, normal_edge_protected_mask)
|
| 167 |
+
cleanup_and_edge_ms = (time.perf_counter() - phase_started) * 1000
|
| 168 |
+
|
| 169 |
+
phase_started = time.perf_counter()
|
| 170 |
+
surface, post_edge_filter_metadata = filter_surface_by_floor_geometry(
|
| 171 |
+
surface,
|
| 172 |
+
geometry,
|
| 173 |
+
plane,
|
| 174 |
+
geometry_maps=geometry_maps,
|
| 175 |
+
)
|
| 176 |
+
post_edge_filter_ms = (time.perf_counter() - phase_started) * 1000
|
| 177 |
surface[occluder_mask > 0] = 0
|
| 178 |
surface[reject_mask > 0] = 0
|
| 179 |
surface[soft_covering_mask > 0] = 0
|
|
|
|
| 182 |
for k, value in post_edge_filter_metadata.items()
|
| 183 |
}
|
| 184 |
|
| 185 |
+
phase_started = time.perf_counter()
|
| 186 |
+
surface_before_soft_covering = surface
|
| 187 |
surface, soft_covering_metadata = expand_surface_over_soft_floor_coverings(
|
| 188 |
surface,
|
| 189 |
soft_covering_mask,
|
| 190 |
hard_protected_mask,
|
| 191 |
)
|
| 192 |
+
soft_covering_ms = (time.perf_counter() - phase_started) * 1000
|
| 193 |
+
|
| 194 |
+
phase_started = time.perf_counter()
|
| 195 |
+
if surface is surface_before_soft_covering or not soft_covering_metadata["softFloorCoveringExpansionApplied"]:
|
| 196 |
+
post_soft_covering_filter_metadata = {
|
| 197 |
+
"geometrySurfaceFilterApplied": False,
|
| 198 |
+
"geometrySurfaceFilterReason": "soft-floor-surface-unchanged",
|
| 199 |
+
"geometrySurfacePixelsBefore": int(surface.sum()),
|
| 200 |
+
"geometrySurfacePixelsAfter": int(surface.sum()),
|
| 201 |
+
}
|
| 202 |
+
else:
|
| 203 |
+
surface, post_soft_covering_filter_metadata = filter_surface_by_floor_geometry(
|
| 204 |
+
surface,
|
| 205 |
+
geometry,
|
| 206 |
+
plane,
|
| 207 |
+
geometry_maps=geometry_maps,
|
| 208 |
+
)
|
| 209 |
+
post_soft_filter_ms = (time.perf_counter() - phase_started) * 1000
|
| 210 |
surface[occluder_mask > 0] = 0
|
| 211 |
surface[reject_mask > 0] = 0
|
| 212 |
post_soft_covering_filter_metadata = {
|
| 213 |
f"postSoftFloorCovering{k[0].upper()}{k[1:]}": value
|
| 214 |
for k, value in post_soft_covering_filter_metadata.items()
|
| 215 |
}
|
| 216 |
+
timing_ms = {
|
| 217 |
+
"preparation": round(preparation_ms, 2),
|
| 218 |
+
"initialGeometryFilter": round(initial_filter_ms, 2),
|
| 219 |
+
"cleanupAndEdgeRepair": round(cleanup_and_edge_ms, 2),
|
| 220 |
+
"postEdgeGeometryFilter": round(post_edge_filter_ms, 2),
|
| 221 |
+
"softFloorExpansion": round(soft_covering_ms, 2),
|
| 222 |
+
"postSoftFloorGeometryFilter": round(post_soft_filter_ms, 2),
|
| 223 |
+
"total": round((time.perf_counter() - total_started) * 1000, 2),
|
| 224 |
+
}
|
| 225 |
+
print(
|
| 226 |
+
"[SURFACE_MASKING_TIMING] "
|
| 227 |
+
+ " ".join(f"{name}={duration:.2f}ms" for name, duration in timing_ms.items()),
|
| 228 |
+
flush=True,
|
| 229 |
+
)
|
| 230 |
return surface, {
|
| 231 |
**geometry_filter_metadata,
|
| 232 |
**edge_metadata,
|
| 233 |
**post_edge_filter_metadata,
|
| 234 |
**soft_covering_metadata,
|
| 235 |
**post_soft_covering_filter_metadata,
|
| 236 |
+
"surfaceMaskingTimingMs": timing_ms,
|
| 237 |
}
|
services/geometry/multi_plane.py
CHANGED
|
@@ -22,6 +22,24 @@ from services.geometry.plane_fitting import plane_basis, surface_distance_thresh
|
|
| 22 |
from services.geometry.ransac import ransac_surface_plane, ransac_surface_plane_by_distance
|
| 23 |
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def geometry_point_maps(mask: np.ndarray, geometry: dict | None):
|
| 26 |
if not ENABLE_MULTI_PLANE_SURFACES or geometry is None:
|
| 27 |
return None
|
|
@@ -45,12 +63,12 @@ def geometry_point_maps(mask: np.ndarray, geometry: dict | None):
|
|
| 45 |
valid_mask = np.isfinite(depth_for_points) & (depth_for_points > 0.05)
|
| 46 |
point_source = f"{provider or 'depth'}-backprojection"
|
| 47 |
else:
|
| 48 |
-
points = points.astype(np.float32)
|
| 49 |
pixel_intrinsics = pixel_intrinsics_from_model(intrinsics, w, h)
|
| 50 |
if valid_mask is None:
|
| 51 |
valid_mask = np.isfinite(points).all(axis=2) & (points[:, :, 2] > 0.05)
|
| 52 |
|
| 53 |
-
valid_mask = valid_mask.astype(bool) & np.isfinite(points).all(axis=2) & (points[:, :, 2] > 0.05)
|
| 54 |
print(
|
| 55 |
"[FLOOR_3D_POINTS] point map ready for floor mapping "
|
| 56 |
f"source={point_source} provider={geometry.get('provider')} shape={points.shape} "
|
|
@@ -61,11 +79,13 @@ def geometry_point_maps(mask: np.ndarray, geometry: dict | None):
|
|
| 61 |
if normals is None or normals.shape[:2] != mask.shape:
|
| 62 |
normals = compute_normals_from_points(points, valid_mask, SURFACE_NORMAL_SMOOTHING_KERNEL)
|
| 63 |
else:
|
| 64 |
-
normals = smooth_normal_map(normals.astype(np.float32), SURFACE_NORMAL_SMOOTHING_KERNEL)
|
|
|
|
| 65 |
|
| 66 |
return {
|
| 67 |
-
"points": points.astype(np.float32),
|
| 68 |
-
"normals": normals.astype(np.float32),
|
|
|
|
| 69 |
"validMask": valid_mask,
|
| 70 |
"intrinsics": pixel_intrinsics.astype(np.float32),
|
| 71 |
"depthScale": depth_scale,
|
|
@@ -128,6 +148,8 @@ def fit_multi_surface_planes(points: np.ndarray, normals: np.ndarray, normals_re
|
|
| 128 |
if not planes:
|
| 129 |
return []
|
| 130 |
|
|
|
|
|
|
|
| 131 |
floor_id = int(np.argmax([
|
| 132 |
plane["inlierCount"] * max(0.1, abs(float(plane["normal"][1])))
|
| 133 |
for plane in planes
|
|
|
|
| 22 |
from services.geometry.ransac import ransac_surface_plane, ransac_surface_plane_by_distance
|
| 23 |
|
| 24 |
|
| 25 |
+
MIN_SECONDARY_PLANE_RATIO = 0.05
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _prune_weak_secondary_planes(planes: list[dict]) -> list[dict]:
|
| 29 |
+
if not planes:
|
| 30 |
+
return []
|
| 31 |
+
|
| 32 |
+
primary_inliers = max(plane["inlierCount"] for plane in planes)
|
| 33 |
+
retained_planes = [
|
| 34 |
+
plane
|
| 35 |
+
for plane in planes
|
| 36 |
+
if plane["inlierCount"] >= primary_inliers * MIN_SECONDARY_PLANE_RATIO
|
| 37 |
+
]
|
| 38 |
+
for plane_id, plane in enumerate(retained_planes):
|
| 39 |
+
plane["id"] = plane_id
|
| 40 |
+
return retained_planes
|
| 41 |
+
|
| 42 |
+
|
| 43 |
def geometry_point_maps(mask: np.ndarray, geometry: dict | None):
|
| 44 |
if not ENABLE_MULTI_PLANE_SURFACES or geometry is None:
|
| 45 |
return None
|
|
|
|
| 63 |
valid_mask = np.isfinite(depth_for_points) & (depth_for_points > 0.05)
|
| 64 |
point_source = f"{provider or 'depth'}-backprojection"
|
| 65 |
else:
|
| 66 |
+
points = points.astype(np.float32, copy=False)
|
| 67 |
pixel_intrinsics = pixel_intrinsics_from_model(intrinsics, w, h)
|
| 68 |
if valid_mask is None:
|
| 69 |
valid_mask = np.isfinite(points).all(axis=2) & (points[:, :, 2] > 0.05)
|
| 70 |
|
| 71 |
+
valid_mask = valid_mask.astype(bool, copy=False) & np.isfinite(points).all(axis=2) & (points[:, :, 2] > 0.05)
|
| 72 |
print(
|
| 73 |
"[FLOOR_3D_POINTS] point map ready for floor mapping "
|
| 74 |
f"source={point_source} provider={geometry.get('provider')} shape={points.shape} "
|
|
|
|
| 79 |
if normals is None or normals.shape[:2] != mask.shape:
|
| 80 |
normals = compute_normals_from_points(points, valid_mask, SURFACE_NORMAL_SMOOTHING_KERNEL)
|
| 81 |
else:
|
| 82 |
+
normals = smooth_normal_map(normals.astype(np.float32, copy=False), SURFACE_NORMAL_SMOOTHING_KERNEL)
|
| 83 |
+
normal_valid_mask = np.isfinite(normals).all(axis=2) & (np.linalg.norm(normals, axis=2) > 1e-4)
|
| 84 |
|
| 85 |
return {
|
| 86 |
+
"points": points.astype(np.float32, copy=False),
|
| 87 |
+
"normals": normals.astype(np.float32, copy=False),
|
| 88 |
+
"normalValidMask": normal_valid_mask,
|
| 89 |
"validMask": valid_mask,
|
| 90 |
"intrinsics": pixel_intrinsics.astype(np.float32),
|
| 91 |
"depthScale": depth_scale,
|
|
|
|
| 148 |
if not planes:
|
| 149 |
return []
|
| 150 |
|
| 151 |
+
planes = _prune_weak_secondary_planes(planes)
|
| 152 |
+
|
| 153 |
floor_id = int(np.argmax([
|
| 154 |
plane["inlierCount"] * max(0.1, abs(float(plane["normal"][1])))
|
| 155 |
for plane in planes
|
services/geometry/ransac.py
CHANGED
|
@@ -5,6 +5,64 @@ import numpy as np
|
|
| 5 |
from config.surface import SURFACE_MIN_PLANE_PIXELS
|
| 6 |
from services.geometry.plane_fitting import refine_plane
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def ransac_plane_fit(points: np.ndarray):
|
| 10 |
if len(points) < 1000:
|
|
@@ -53,31 +111,25 @@ def ransac_surface_plane(
|
|
| 53 |
return None
|
| 54 |
|
| 55 |
rng = np.random.default_rng(41)
|
| 56 |
-
best_normal = None
|
| 57 |
-
best_origin = None
|
| 58 |
-
best_count = 0
|
| 59 |
candidate_points = points[candidate_indices]
|
| 60 |
candidate_normals = normals[candidate_indices]
|
| 61 |
relaxed_cos = max(0.0, normal_cos - 0.15)
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
best_origin = p0
|
| 77 |
-
best_normal = normal
|
| 78 |
-
|
| 79 |
-
if best_normal is None:
|
| 80 |
return None
|
|
|
|
| 81 |
|
| 82 |
distances = np.abs((points - best_origin) @ best_normal)
|
| 83 |
align = np.abs(normals @ best_normal)
|
|
@@ -111,28 +163,21 @@ def ransac_surface_plane_by_distance(
|
|
| 111 |
return None
|
| 112 |
|
| 113 |
rng = np.random.default_rng(53)
|
| 114 |
-
best_normal = None
|
| 115 |
-
best_origin = None
|
| 116 |
-
best_count = 0
|
| 117 |
candidate_points = points[candidate_indices]
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
best_count = count
|
| 131 |
-
best_origin = p0
|
| 132 |
-
best_normal = normal
|
| 133 |
-
|
| 134 |
-
if best_normal is None:
|
| 135 |
return None
|
|
|
|
| 136 |
|
| 137 |
distances = np.abs((points - best_origin) @ best_normal)
|
| 138 |
inliers = remaining & (distances <= distance_threshold)
|
|
|
|
| 5 |
from config.surface import SURFACE_MIN_PLANE_PIXELS
|
| 6 |
from services.geometry.plane_fitting import refine_plane
|
| 7 |
|
| 8 |
+
_HYPOTHESIS_BATCH_SIZE = 32
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def _candidate_hypotheses(
|
| 12 |
+
candidate_points: np.ndarray,
|
| 13 |
+
*,
|
| 14 |
+
iterations: int,
|
| 15 |
+
rng: np.random.Generator,
|
| 16 |
+
) -> tuple[np.ndarray, np.ndarray]:
|
| 17 |
+
"""Generate the same deterministic RANSAC hypotheses without scoring each one separately."""
|
| 18 |
+
origins = []
|
| 19 |
+
normals = []
|
| 20 |
+
for _ in range(iterations):
|
| 21 |
+
local = rng.choice(len(candidate_points), size=3, replace=False)
|
| 22 |
+
p0, p1, p2 = candidate_points[local]
|
| 23 |
+
normal = np.cross(p1 - p0, p2 - p0).astype(np.float32)
|
| 24 |
+
length = float(np.linalg.norm(normal))
|
| 25 |
+
if length < 1e-6:
|
| 26 |
+
continue
|
| 27 |
+
origins.append(p0)
|
| 28 |
+
normals.append(normal / length)
|
| 29 |
+
if not origins:
|
| 30 |
+
return np.empty((0, 3), dtype=np.float32), np.empty((0, 3), dtype=np.float32)
|
| 31 |
+
return np.asarray(origins, dtype=np.float32), np.asarray(normals, dtype=np.float32)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _best_surface_hypothesis(
|
| 35 |
+
candidate_points: np.ndarray,
|
| 36 |
+
origins: np.ndarray,
|
| 37 |
+
normals: np.ndarray,
|
| 38 |
+
distance_threshold: float,
|
| 39 |
+
*,
|
| 40 |
+
candidate_normals: np.ndarray | None = None,
|
| 41 |
+
normal_cos: float | None = None,
|
| 42 |
+
) -> tuple[np.ndarray, np.ndarray] | None:
|
| 43 |
+
"""Score RANSAC hypotheses in bounded batches to avoid hundreds of tiny NumPy calls."""
|
| 44 |
+
best_count = 0
|
| 45 |
+
best_index = -1
|
| 46 |
+
for start in range(0, len(origins), _HYPOTHESIS_BATCH_SIZE):
|
| 47 |
+
stop = min(start + _HYPOTHESIS_BATCH_SIZE, len(origins))
|
| 48 |
+
batch_normals = normals[start:stop]
|
| 49 |
+
batch_origins = origins[start:stop]
|
| 50 |
+
offsets = np.sum(batch_origins * batch_normals, axis=1)
|
| 51 |
+
distances = np.abs(candidate_points @ batch_normals.T - offsets[None, :])
|
| 52 |
+
accepted = distances <= distance_threshold
|
| 53 |
+
if candidate_normals is not None and normal_cos is not None:
|
| 54 |
+
alignments = np.abs(candidate_normals @ batch_normals.T)
|
| 55 |
+
accepted &= alignments >= normal_cos
|
| 56 |
+
counts = accepted.sum(axis=0)
|
| 57 |
+
local_index = int(np.argmax(counts))
|
| 58 |
+
local_count = int(counts[local_index])
|
| 59 |
+
if local_count > best_count:
|
| 60 |
+
best_count = local_count
|
| 61 |
+
best_index = start + local_index
|
| 62 |
+
if best_index < 0:
|
| 63 |
+
return None
|
| 64 |
+
return origins[best_index], normals[best_index]
|
| 65 |
+
|
| 66 |
|
| 67 |
def ransac_plane_fit(points: np.ndarray):
|
| 68 |
if len(points) < 1000:
|
|
|
|
| 111 |
return None
|
| 112 |
|
| 113 |
rng = np.random.default_rng(41)
|
|
|
|
|
|
|
|
|
|
| 114 |
candidate_points = points[candidate_indices]
|
| 115 |
candidate_normals = normals[candidate_indices]
|
| 116 |
relaxed_cos = max(0.0, normal_cos - 0.15)
|
| 117 |
+
origins, hypothesis_normals = _candidate_hypotheses(
|
| 118 |
+
candidate_points,
|
| 119 |
+
iterations=220,
|
| 120 |
+
rng=rng,
|
| 121 |
+
)
|
| 122 |
+
best = _best_surface_hypothesis(
|
| 123 |
+
candidate_points,
|
| 124 |
+
origins,
|
| 125 |
+
hypothesis_normals,
|
| 126 |
+
distance_threshold,
|
| 127 |
+
candidate_normals=candidate_normals,
|
| 128 |
+
normal_cos=relaxed_cos,
|
| 129 |
+
)
|
| 130 |
+
if best is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
return None
|
| 132 |
+
best_origin, best_normal = best
|
| 133 |
|
| 134 |
distances = np.abs((points - best_origin) @ best_normal)
|
| 135 |
align = np.abs(normals @ best_normal)
|
|
|
|
| 163 |
return None
|
| 164 |
|
| 165 |
rng = np.random.default_rng(53)
|
|
|
|
|
|
|
|
|
|
| 166 |
candidate_points = points[candidate_indices]
|
| 167 |
+
origins, hypothesis_normals = _candidate_hypotheses(
|
| 168 |
+
candidate_points,
|
| 169 |
+
iterations=260,
|
| 170 |
+
rng=rng,
|
| 171 |
+
)
|
| 172 |
+
best = _best_surface_hypothesis(
|
| 173 |
+
candidate_points,
|
| 174 |
+
origins,
|
| 175 |
+
hypothesis_normals,
|
| 176 |
+
distance_threshold,
|
| 177 |
+
)
|
| 178 |
+
if best is None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 179 |
return None
|
| 180 |
+
best_origin, best_normal = best
|
| 181 |
|
| 182 |
distances = np.abs((points - best_origin) @ best_normal)
|
| 183 |
inliers = remaining & (distances <= distance_threshold)
|
services/geometry/uv_mapping.py
CHANGED
|
@@ -1,5 +1,7 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
|
| 5 |
from enums import TextureMappingMode, TextureMappingReason, PlaneFitMode
|
|
@@ -124,8 +126,13 @@ def build_surface_uv_mapping(
|
|
| 124 |
surface_mask: np.ndarray,
|
| 125 |
surface_indices: np.ndarray,
|
| 126 |
geometry: dict | None,
|
|
|
|
|
|
|
| 127 |
):
|
| 128 |
-
|
|
|
|
|
|
|
|
|
|
| 129 |
if maps is None:
|
| 130 |
print(
|
| 131 |
"[SURFACE_MAPPING] skipped: no point maps "
|
|
@@ -138,19 +145,17 @@ def build_surface_uv_mapping(
|
|
| 138 |
points_map = maps["points"]
|
| 139 |
normals_map = maps["normals"]
|
| 140 |
valid_mask = maps["validMask"] & (surface_mask > 0)
|
| 141 |
-
|
| 142 |
-
if len(
|
| 143 |
print(
|
| 144 |
"[SURFACE_MAPPING] skipped: too few valid surface pixels "
|
| 145 |
-
f"valid={len(
|
| 146 |
flush=True,
|
| 147 |
)
|
| 148 |
return None
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
normals_raw = normals_map[ys, xs].astype(np.float32)
|
| 153 |
-
normal_lengths = np.linalg.norm(normals_raw, axis=1)
|
| 154 |
good_points = np.isfinite(points).all(axis=1)
|
| 155 |
if int(good_points.sum()) < SURFACE_MIN_PLANE_PIXELS:
|
| 156 |
print(
|
|
@@ -162,13 +167,14 @@ def build_surface_uv_mapping(
|
|
| 162 |
|
| 163 |
valid_flat = valid_flat[good_points]
|
| 164 |
points = points[good_points]
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
normals_reliable = int(normal_good.sum()) >= SURFACE_MIN_PLANE_PIXELS
|
|
|
|
| 172 |
|
| 173 |
print(
|
| 174 |
"[SURFACE_MAPPING] candidates "
|
|
@@ -178,7 +184,9 @@ def build_surface_uv_mapping(
|
|
| 178 |
flush=True,
|
| 179 |
)
|
| 180 |
|
|
|
|
| 181 |
planes = fit_multi_surface_planes(points, normals, normals_reliable)
|
|
|
|
| 182 |
if not planes:
|
| 183 |
print(
|
| 184 |
"[SURFACE_MAPPING] skipped: no dominant planes fitted "
|
|
@@ -188,7 +196,11 @@ def build_surface_uv_mapping(
|
|
| 188 |
)
|
| 189 |
return None
|
| 190 |
|
|
|
|
| 191 |
assignment = assign_points_to_surface_planes(points, normals, planes, normals_reliable)
|
|
|
|
|
|
|
|
|
|
| 192 |
uv_by_mask = np.full((len(surface_indices), 2), np.nan, dtype=np.float32)
|
| 193 |
plane_ids = np.full(len(surface_indices), 255, dtype=np.uint8)
|
| 194 |
ordinal = np.full(surface_mask.size, -1, dtype=np.int32)
|
|
@@ -250,11 +262,24 @@ def build_surface_uv_mapping(
|
|
| 250 |
"uvWidth": float(max(uv_max[0] - uv_min[0], 0.05)),
|
| 251 |
"uvHeight": float(max(uv_max[1] - uv_min[1], 0.05)),
|
| 252 |
})
|
|
|
|
| 253 |
|
|
|
|
| 254 |
finite_uv = np.isfinite(uv_by_mask).all(axis=1)
|
| 255 |
uv_quality = analyze_surface_uv_quality(surface_mask, surface_indices, uv_by_mask, plane_ids)
|
|
|
|
| 256 |
uv_quality["surfaceUvPlaneDistanceLimitMeters"] = float(assignment_distance_limit)
|
| 257 |
uv_quality["surfaceUvRejectedByPlaneDistance"] = int(rejected_by_distance)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
print(
|
| 259 |
"[SURFACE_MAPPING] success "
|
| 260 |
f"planes={len(serializable_planes)} assignedPixels={int(finite_uv.sum())}/{len(surface_indices)} "
|
|
@@ -262,6 +287,11 @@ def build_surface_uv_mapping(
|
|
| 262 |
f"mode={uv_quality['textureMappingMode']} reason={uv_quality['textureMappingReason']}",
|
| 263 |
flush=True,
|
| 264 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
return {
|
| 267 |
"uv": uv_by_mask,
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
+
import time
|
| 4 |
+
|
| 5 |
import numpy as np
|
| 6 |
|
| 7 |
from enums import TextureMappingMode, TextureMappingReason, PlaneFitMode
|
|
|
|
| 126 |
surface_mask: np.ndarray,
|
| 127 |
surface_indices: np.ndarray,
|
| 128 |
geometry: dict | None,
|
| 129 |
+
*,
|
| 130 |
+
geometry_maps: dict | None = None,
|
| 131 |
):
|
| 132 |
+
total_started = time.perf_counter()
|
| 133 |
+
phase_started = total_started
|
| 134 |
+
maps = geometry_maps if geometry_maps is not None else geometry_point_maps(surface_mask, geometry)
|
| 135 |
+
geometry_maps_ms = (time.perf_counter() - phase_started) * 1000
|
| 136 |
if maps is None:
|
| 137 |
print(
|
| 138 |
"[SURFACE_MAPPING] skipped: no point maps "
|
|
|
|
| 145 |
points_map = maps["points"]
|
| 146 |
normals_map = maps["normals"]
|
| 147 |
valid_mask = maps["validMask"] & (surface_mask > 0)
|
| 148 |
+
valid_flat = np.flatnonzero(valid_mask.ravel()).astype(np.uint32)
|
| 149 |
+
if len(valid_flat) < SURFACE_MIN_PLANE_PIXELS:
|
| 150 |
print(
|
| 151 |
"[SURFACE_MAPPING] skipped: too few valid surface pixels "
|
| 152 |
+
f"valid={len(valid_flat)} min={SURFACE_MIN_PLANE_PIXELS}",
|
| 153 |
flush=True,
|
| 154 |
)
|
| 155 |
return None
|
| 156 |
|
| 157 |
+
points = points_map.reshape(-1, 3)[valid_flat]
|
| 158 |
+
normals = normals_map.reshape(-1, 3)[valid_flat]
|
|
|
|
|
|
|
| 159 |
good_points = np.isfinite(points).all(axis=1)
|
| 160 |
if int(good_points.sum()) < SURFACE_MIN_PLANE_PIXELS:
|
| 161 |
print(
|
|
|
|
| 167 |
|
| 168 |
valid_flat = valid_flat[good_points]
|
| 169 |
points = points[good_points]
|
| 170 |
+
normals = normals[good_points]
|
| 171 |
+
prepared_normal_valid = maps.get("normalValidMask")
|
| 172 |
+
if prepared_normal_valid is not None and prepared_normal_valid.shape == surface_mask.shape:
|
| 173 |
+
normal_good = prepared_normal_valid.ravel()[valid_flat]
|
| 174 |
+
else:
|
| 175 |
+
normal_good = np.isfinite(normals).all(axis=1) & (np.linalg.norm(normals, axis=1) > 1e-4)
|
| 176 |
normals_reliable = int(normal_good.sum()) >= SURFACE_MIN_PLANE_PIXELS
|
| 177 |
+
gather_ms = (time.perf_counter() - phase_started) * 1000 - geometry_maps_ms
|
| 178 |
|
| 179 |
print(
|
| 180 |
"[SURFACE_MAPPING] candidates "
|
|
|
|
| 184 |
flush=True,
|
| 185 |
)
|
| 186 |
|
| 187 |
+
phase_started = time.perf_counter()
|
| 188 |
planes = fit_multi_surface_planes(points, normals, normals_reliable)
|
| 189 |
+
plane_fit_ms = (time.perf_counter() - phase_started) * 1000
|
| 190 |
if not planes:
|
| 191 |
print(
|
| 192 |
"[SURFACE_MAPPING] skipped: no dominant planes fitted "
|
|
|
|
| 196 |
)
|
| 197 |
return None
|
| 198 |
|
| 199 |
+
phase_started = time.perf_counter()
|
| 200 |
assignment = assign_points_to_surface_planes(points, normals, planes, normals_reliable)
|
| 201 |
+
assignment_ms = (time.perf_counter() - phase_started) * 1000
|
| 202 |
+
|
| 203 |
+
phase_started = time.perf_counter()
|
| 204 |
uv_by_mask = np.full((len(surface_indices), 2), np.nan, dtype=np.float32)
|
| 205 |
plane_ids = np.full(len(surface_indices), 255, dtype=np.uint8)
|
| 206 |
ordinal = np.full(surface_mask.size, -1, dtype=np.int32)
|
|
|
|
| 262 |
"uvWidth": float(max(uv_max[0] - uv_min[0], 0.05)),
|
| 263 |
"uvHeight": float(max(uv_max[1] - uv_min[1], 0.05)),
|
| 264 |
})
|
| 265 |
+
projection_ms = (time.perf_counter() - phase_started) * 1000
|
| 266 |
|
| 267 |
+
phase_started = time.perf_counter()
|
| 268 |
finite_uv = np.isfinite(uv_by_mask).all(axis=1)
|
| 269 |
uv_quality = analyze_surface_uv_quality(surface_mask, surface_indices, uv_by_mask, plane_ids)
|
| 270 |
+
quality_ms = (time.perf_counter() - phase_started) * 1000
|
| 271 |
uv_quality["surfaceUvPlaneDistanceLimitMeters"] = float(assignment_distance_limit)
|
| 272 |
uv_quality["surfaceUvRejectedByPlaneDistance"] = int(rejected_by_distance)
|
| 273 |
+
timing_ms = {
|
| 274 |
+
"geometryMaps": round(geometry_maps_ms, 2),
|
| 275 |
+
"pixelGather": round(gather_ms, 2),
|
| 276 |
+
"planeFit": round(plane_fit_ms, 2),
|
| 277 |
+
"planeAssignment": round(assignment_ms, 2),
|
| 278 |
+
"projection": round(projection_ms, 2),
|
| 279 |
+
"qualityAnalysis": round(quality_ms, 2),
|
| 280 |
+
"total": round((time.perf_counter() - total_started) * 1000, 2),
|
| 281 |
+
}
|
| 282 |
+
uv_quality["surfaceUvTimingMs"] = timing_ms
|
| 283 |
print(
|
| 284 |
"[SURFACE_MAPPING] success "
|
| 285 |
f"planes={len(serializable_planes)} assignedPixels={int(finite_uv.sum())}/{len(surface_indices)} "
|
|
|
|
| 287 |
f"mode={uv_quality['textureMappingMode']} reason={uv_quality['textureMappingReason']}",
|
| 288 |
flush=True,
|
| 289 |
)
|
| 290 |
+
print(
|
| 291 |
+
"[SURFACE_MAPPING_TIMING] "
|
| 292 |
+
+ " ".join(f"{name}={duration:.2f}ms" for name, duration in timing_ms.items()),
|
| 293 |
+
flush=True,
|
| 294 |
+
)
|
| 295 |
|
| 296 |
return {
|
| 297 |
"uv": uv_by_mask,
|
services/jobs/conversion.py
CHANGED
|
@@ -67,9 +67,12 @@ def run_conversion_task(job_id: str, upload_path: Path):
|
|
| 67 |
from services.debug.capture import PipelineDebugCapture
|
| 68 |
from services.pipeline.packaging import build_manifest_segmentation_bundle
|
| 69 |
|
|
|
|
| 70 |
debug = PipelineDebugCapture(job_id) if DEBUG_ARTIFACTS_ENABLED else None
|
| 71 |
estimate_ms = estimate_conversion_ms()
|
|
|
|
| 72 |
image_bytes = upload_path.read_bytes()
|
|
|
|
| 73 |
image_url = f"/uploads/{upload_path.name}"
|
| 74 |
|
| 75 |
try:
|
|
@@ -84,50 +87,23 @@ def run_conversion_task(job_id: str, upload_path: Path):
|
|
| 84 |
estimatedRemainingMs=estimate_ms,
|
| 85 |
)
|
| 86 |
|
| 87 |
-
#
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
t_preview = time.perf_counter()
|
| 92 |
-
update_conversion_job(
|
| 93 |
-
job_id,
|
| 94 |
-
status=JobStatus.PROCESSING,
|
| 95 |
-
phase=PipelinePhase.SEGMENTATION,
|
| 96 |
-
progress=0,
|
| 97 |
-
message="Quick preview\u2026",
|
| 98 |
-
startedAt=datetime.now(timezone.utc).isoformat(),
|
| 99 |
-
)
|
| 100 |
-
preview_bundle = build_preview_bundle(image_bytes)
|
| 101 |
-
preview_binary = build_manifest_segmentation_bundle(
|
| 102 |
-
preview_bundle, job_id, image_url=image_url, include_image=False,
|
| 103 |
-
)
|
| 104 |
-
(JOB_DIR / f"{job_id}.vizbundle").write_bytes(preview_binary)
|
| 105 |
-
|
| 106 |
-
preview_ms = (time.perf_counter() - t_preview) * 1000
|
| 107 |
-
job = read_job(job_id)
|
| 108 |
-
job["status"] = JobStatus.PREVIEW_READY
|
| 109 |
-
job["phase"] = "preview-ready"
|
| 110 |
-
job["progress"] = 40
|
| 111 |
-
job["message"] = "Preview ready \u2014 enhancing quality\u2026"
|
| 112 |
-
job["previewDurationMs"] = round(preview_ms)
|
| 113 |
-
job["outputFormat"] = "split-vizbundle"
|
| 114 |
-
write_job(job)
|
| 115 |
-
print(f"[JOB {job_id[:8]}] Preview ready in {preview_ms / 1000:.2f}s", flush=True)
|
| 116 |
-
except Exception as preview_exc:
|
| 117 |
-
print(f"[JOB {job_id[:8]}] Preview failed ({preview_exc}), continuing with full pipeline.", flush=True)
|
| 118 |
-
|
| 119 |
-
# ── Phase 2: Full HD pipeline ──
|
| 120 |
with CONVERSION_GPU_LOCK:
|
|
|
|
| 121 |
t_start = time.perf_counter()
|
| 122 |
update_conversion_job(
|
| 123 |
job_id,
|
| 124 |
status=JobStatus.PROCESSING,
|
| 125 |
phase=PipelinePhase.SEGMENTATION,
|
| 126 |
-
progress=
|
| 127 |
phase_progress=0,
|
| 128 |
message="Analyzing floor (HD)\u2026",
|
| 129 |
estimatedTotalMs=estimate_ms,
|
| 130 |
estimatedRemainingMs=estimate_ms,
|
|
|
|
| 131 |
)
|
| 132 |
completed_phases: set[str] = set()
|
| 133 |
|
|
@@ -136,13 +112,11 @@ def run_conversion_task(job_id: str, upload_path: Path):
|
|
| 136 |
completed_phases.add(phase)
|
| 137 |
elapsed_ms = (time.perf_counter() - t_start) * 1000
|
| 138 |
remaining_ms = max(0, estimate_ms - elapsed_ms)
|
| 139 |
-
base_progress = 40 # preview accounts for 0-40%
|
| 140 |
hd_progress = weighted_conversion_progress(completed_phases, phase, phase_progress)
|
| 141 |
-
overall = base_progress + round(hd_progress * 0.6) # HD is 40-100%
|
| 142 |
update_conversion_job(
|
| 143 |
job_id,
|
| 144 |
phase=phase,
|
| 145 |
-
progress=
|
| 146 |
phase_progress=round(phase_progress),
|
| 147 |
message=f"Enhancing {phase.replace('-', ' ')}\u2026",
|
| 148 |
estimatedRemainingMs=round(remaining_ms),
|
|
@@ -152,13 +126,37 @@ def run_conversion_task(job_id: str, upload_path: Path):
|
|
| 152 |
|
| 153 |
bundle = build_segmentation_bundle(image_bytes, debug=debug, progress_callback=report_stage)
|
| 154 |
report_stage(PipelinePhase.PACKAGING, 25)
|
|
|
|
| 155 |
binary_bundle = build_manifest_segmentation_bundle(
|
| 156 |
bundle, job_id, image_url=image_url, include_image=False,
|
| 157 |
)
|
| 158 |
(JOB_DIR / f"{job_id}.vizbundle").write_bytes(binary_bundle)
|
|
|
|
| 159 |
report_stage(PipelinePhase.PACKAGING, 100)
|
| 160 |
elapsed_ms = (time.perf_counter() - t_start) * 1000
|
| 161 |
record_conversion_ms(elapsed_ms)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 162 |
job = read_job(job_id)
|
| 163 |
job["status"] = JobStatus.COMPLETED
|
| 164 |
job["phase"] = "completed"
|
|
@@ -170,7 +168,11 @@ def run_conversion_task(job_id: str, upload_path: Path):
|
|
| 170 |
job["durationMs"] = round(elapsed_ms)
|
| 171 |
job["modelName"] = bundle.get("modelName")
|
| 172 |
job["models"] = bundle.get("models")
|
| 173 |
-
job["pipelineStages"] =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
job["outputFormat"] = "split-vizbundle"
|
| 175 |
write_job(job)
|
| 176 |
print(f"\n[JOB {job_id[:8]}] HD conversion completed in {elapsed_ms / 1000:.2f}s\n", flush=True)
|
|
|
|
| 67 |
from services.debug.capture import PipelineDebugCapture
|
| 68 |
from services.pipeline.packaging import build_manifest_segmentation_bundle
|
| 69 |
|
| 70 |
+
task_started = time.perf_counter()
|
| 71 |
debug = PipelineDebugCapture(job_id) if DEBUG_ARTIFACTS_ENABLED else None
|
| 72 |
estimate_ms = estimate_conversion_ms()
|
| 73 |
+
t_read = time.perf_counter()
|
| 74 |
image_bytes = upload_path.read_bytes()
|
| 75 |
+
input_read_ms = (time.perf_counter() - t_read) * 1000
|
| 76 |
image_url = f"/uploads/{upload_path.name}"
|
| 77 |
|
| 78 |
try:
|
|
|
|
| 87 |
estimatedRemainingMs=estimate_ms,
|
| 88 |
)
|
| 89 |
|
| 90 |
+
# Run one authoritative HD pass. The former preview repeated
|
| 91 |
+
# segmentation and full-resolution CPU work, then was normally missed
|
| 92 |
+
# before the status returned to PROCESSING.
|
| 93 |
+
gpu_wait_started = time.perf_counter()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
with CONVERSION_GPU_LOCK:
|
| 95 |
+
gpu_queue_wait_ms = (time.perf_counter() - gpu_wait_started) * 1000
|
| 96 |
t_start = time.perf_counter()
|
| 97 |
update_conversion_job(
|
| 98 |
job_id,
|
| 99 |
status=JobStatus.PROCESSING,
|
| 100 |
phase=PipelinePhase.SEGMENTATION,
|
| 101 |
+
progress=0,
|
| 102 |
phase_progress=0,
|
| 103 |
message="Analyzing floor (HD)\u2026",
|
| 104 |
estimatedTotalMs=estimate_ms,
|
| 105 |
estimatedRemainingMs=estimate_ms,
|
| 106 |
+
gpuQueueWaitMs=round(gpu_queue_wait_ms),
|
| 107 |
)
|
| 108 |
completed_phases: set[str] = set()
|
| 109 |
|
|
|
|
| 112 |
completed_phases.add(phase)
|
| 113 |
elapsed_ms = (time.perf_counter() - t_start) * 1000
|
| 114 |
remaining_ms = max(0, estimate_ms - elapsed_ms)
|
|
|
|
| 115 |
hd_progress = weighted_conversion_progress(completed_phases, phase, phase_progress)
|
|
|
|
| 116 |
update_conversion_job(
|
| 117 |
job_id,
|
| 118 |
phase=phase,
|
| 119 |
+
progress=hd_progress,
|
| 120 |
phase_progress=round(phase_progress),
|
| 121 |
message=f"Enhancing {phase.replace('-', ' ')}\u2026",
|
| 122 |
estimatedRemainingMs=round(remaining_ms),
|
|
|
|
| 126 |
|
| 127 |
bundle = build_segmentation_bundle(image_bytes, debug=debug, progress_callback=report_stage)
|
| 128 |
report_stage(PipelinePhase.PACKAGING, 25)
|
| 129 |
+
serialization_started = time.perf_counter()
|
| 130 |
binary_bundle = build_manifest_segmentation_bundle(
|
| 131 |
bundle, job_id, image_url=image_url, include_image=False,
|
| 132 |
)
|
| 133 |
(JOB_DIR / f"{job_id}.vizbundle").write_bytes(binary_bundle)
|
| 134 |
+
serialization_ms = (time.perf_counter() - serialization_started) * 1000
|
| 135 |
report_stage(PipelinePhase.PACKAGING, 100)
|
| 136 |
elapsed_ms = (time.perf_counter() - t_start) * 1000
|
| 137 |
record_conversion_ms(elapsed_ms)
|
| 138 |
+
pipeline_stages = [
|
| 139 |
+
stage for stage in (bundle.get("pipelineStages") or [])
|
| 140 |
+
if stage.get("name") != "TOTAL"
|
| 141 |
+
]
|
| 142 |
+
pipeline_stages.append({
|
| 143 |
+
"name": "Bundle Serialization",
|
| 144 |
+
"elapsed_s": round(serialization_ms / 1000, 3),
|
| 145 |
+
"detail": f"{len(binary_bundle) / 1024:.0f} KB",
|
| 146 |
+
})
|
| 147 |
+
accounted_s = sum(float(stage.get("elapsed_s") or 0.0) for stage in pipeline_stages)
|
| 148 |
+
conversion_overhead_s = max(0.0, elapsed_ms / 1000 - accounted_s)
|
| 149 |
+
if conversion_overhead_s >= 0.001:
|
| 150 |
+
pipeline_stages.append({
|
| 151 |
+
"name": "Conversion Overhead",
|
| 152 |
+
"elapsed_s": round(conversion_overhead_s, 3),
|
| 153 |
+
"detail": "job-state updates and orchestration",
|
| 154 |
+
})
|
| 155 |
+
pipeline_stages.append({
|
| 156 |
+
"name": "TOTAL",
|
| 157 |
+
"elapsed_s": round(elapsed_ms / 1000, 3),
|
| 158 |
+
"detail": "full HD conversion",
|
| 159 |
+
})
|
| 160 |
job = read_job(job_id)
|
| 161 |
job["status"] = JobStatus.COMPLETED
|
| 162 |
job["phase"] = "completed"
|
|
|
|
| 168 |
job["durationMs"] = round(elapsed_ms)
|
| 169 |
job["modelName"] = bundle.get("modelName")
|
| 170 |
job["models"] = bundle.get("models")
|
| 171 |
+
job["pipelineStages"] = pipeline_stages
|
| 172 |
+
job["inputReadMs"] = round(input_read_ms)
|
| 173 |
+
job["gpuQueueWaitMs"] = round(gpu_queue_wait_ms)
|
| 174 |
+
job["bundleSerializationMs"] = round(serialization_ms)
|
| 175 |
+
job["taskDurationMs"] = round((time.perf_counter() - task_started) * 1000)
|
| 176 |
job["outputFormat"] = "split-vizbundle"
|
| 177 |
write_job(job)
|
| 178 |
print(f"\n[JOB {job_id[:8]}] HD conversion completed in {elapsed_ms / 1000:.2f}s\n", flush=True)
|
services/lighting/shading.py
CHANGED
|
@@ -9,6 +9,7 @@ from config.lighting import (
|
|
| 9 |
SHADE_MAP_MAX,
|
| 10 |
SHADE_MAP_MIN,
|
| 11 |
)
|
|
|
|
| 12 |
from services.lighting.luminance import (
|
| 13 |
encode_relative_map,
|
| 14 |
image_linear_luminance,
|
|
@@ -100,6 +101,74 @@ def suppress_replaced_material_lighting(
|
|
| 100 |
# Luminance-based lighting maps
|
| 101 |
# ---------------------------------------------------------------------------
|
| 102 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 103 |
def build_luminance_lighting_maps(
|
| 104 |
img_np: np.ndarray,
|
| 105 |
surface_mask: np.ndarray,
|
|
@@ -152,8 +221,14 @@ def build_luminance_lighting_maps(
|
|
| 152 |
# ---------------------------------------------------------------------------
|
| 153 |
|
| 154 |
def lighting_map_statistics(encoded: np.ndarray | None, surface_mask: np.ndarray) -> dict | None:
|
| 155 |
-
if encoded is None
|
| 156 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 157 |
decoded = SHADE_MAP_MIN + (encoded.astype(np.float32) / 255.0) * (SHADE_MAP_MAX - SHADE_MAP_MIN)
|
| 158 |
values = decoded[surface_mask > 0]
|
| 159 |
if values.size == 0:
|
|
|
|
| 9 |
SHADE_MAP_MAX,
|
| 10 |
SHADE_MAP_MIN,
|
| 11 |
)
|
| 12 |
+
from config.runtime import FAST_SHADOW_MAX_DIMENSION
|
| 13 |
from services.lighting.luminance import (
|
| 14 |
encode_relative_map,
|
| 15 |
image_linear_luminance,
|
|
|
|
| 101 |
# Luminance-based lighting maps
|
| 102 |
# ---------------------------------------------------------------------------
|
| 103 |
|
| 104 |
+
def build_fast_shadow_lighting_maps(
|
| 105 |
+
img_np: np.ndarray,
|
| 106 |
+
surface_mask: np.ndarray,
|
| 107 |
+
replaced_material_mask: np.ndarray | None = None,
|
| 108 |
+
) -> dict[str, np.ndarray | None] | None:
|
| 109 |
+
"""Extract broad room shadows on a bounded working image.
|
| 110 |
+
|
| 111 |
+
Unlike the legacy lighting path, this does not run intrinsic inference,
|
| 112 |
+
calculate reflections, or process several full-resolution float maps. The
|
| 113 |
+
resulting low-resolution shade texture is sampled linearly by the renderer.
|
| 114 |
+
"""
|
| 115 |
+
if not surface_mask.any():
|
| 116 |
+
return None
|
| 117 |
+
|
| 118 |
+
source_h, source_w = surface_mask.shape[:2]
|
| 119 |
+
scale = min(1.0, FAST_SHADOW_MAX_DIMENSION / float(max(source_h, source_w)))
|
| 120 |
+
work_w = max(1, int(round(source_w * scale)))
|
| 121 |
+
work_h = max(1, int(round(source_h * scale)))
|
| 122 |
+
|
| 123 |
+
if (work_w, work_h) == (source_w, source_h):
|
| 124 |
+
work_image = img_np
|
| 125 |
+
work_mask = surface_mask.astype(np.uint8)
|
| 126 |
+
work_replaced_mask = replaced_material_mask
|
| 127 |
+
else:
|
| 128 |
+
work_image = cv2.resize(img_np, (work_w, work_h), interpolation=cv2.INTER_AREA)
|
| 129 |
+
work_mask = cv2.resize(
|
| 130 |
+
surface_mask.astype(np.uint8),
|
| 131 |
+
(work_w, work_h),
|
| 132 |
+
interpolation=cv2.INTER_NEAREST,
|
| 133 |
+
)
|
| 134 |
+
work_replaced_mask = (
|
| 135 |
+
cv2.resize(
|
| 136 |
+
replaced_material_mask.astype(np.uint8),
|
| 137 |
+
(work_w, work_h),
|
| 138 |
+
interpolation=cv2.INTER_NEAREST,
|
| 139 |
+
)
|
| 140 |
+
if replaced_material_mask is not None
|
| 141 |
+
else None
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
luminance = image_linear_luminance(work_image)
|
| 145 |
+
floor_values = luminance[work_mask > 0]
|
| 146 |
+
floor_values = floor_values[np.isfinite(floor_values) & (floor_values > 1e-6)]
|
| 147 |
+
if floor_values.size < max(64, int(work_h * work_w * 0.002)):
|
| 148 |
+
return None
|
| 149 |
+
|
| 150 |
+
median_lum = float(np.median(floor_values))
|
| 151 |
+
if median_lum < 1e-3:
|
| 152 |
+
return None
|
| 153 |
+
|
| 154 |
+
relative = luminance / median_lum
|
| 155 |
+
relative[~np.isfinite(relative)] = 1.0
|
| 156 |
+
relative[work_mask == 0] = 1.0
|
| 157 |
+
relative = suppress_replaced_material_lighting(
|
| 158 |
+
relative,
|
| 159 |
+
work_mask,
|
| 160 |
+
work_replaced_mask,
|
| 161 |
+
)
|
| 162 |
+
shade = smooth_relative_lighting(relative, work_mask)
|
| 163 |
+
if shade is None:
|
| 164 |
+
return None
|
| 165 |
+
|
| 166 |
+
return {
|
| 167 |
+
"shadeMap": encode_relative_map(shade, SHADE_MAP_MIN, SHADE_MAP_MAX),
|
| 168 |
+
"showroomShadeMap": None,
|
| 169 |
+
"reflectionMap": None,
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
def build_luminance_lighting_maps(
|
| 173 |
img_np: np.ndarray,
|
| 174 |
surface_mask: np.ndarray,
|
|
|
|
| 221 |
# ---------------------------------------------------------------------------
|
| 222 |
|
| 223 |
def lighting_map_statistics(encoded: np.ndarray | None, surface_mask: np.ndarray) -> dict | None:
|
| 224 |
+
if encoded is None:
|
| 225 |
return None
|
| 226 |
+
if encoded.shape[:2] != surface_mask.shape[:2]:
|
| 227 |
+
surface_mask = cv2.resize(
|
| 228 |
+
surface_mask.astype(np.uint8),
|
| 229 |
+
(encoded.shape[1], encoded.shape[0]),
|
| 230 |
+
interpolation=cv2.INTER_NEAREST,
|
| 231 |
+
)
|
| 232 |
decoded = SHADE_MAP_MIN + (encoded.astype(np.float32) / 255.0) * (SHADE_MAP_MAX - SHADE_MAP_MIN)
|
| 233 |
values = decoded[surface_mask > 0]
|
| 234 |
if values.size == 0:
|
services/pipeline/builder.py
CHANGED
|
@@ -9,7 +9,12 @@ import cv2
|
|
| 9 |
import numpy as np
|
| 10 |
from PIL import Image
|
| 11 |
|
| 12 |
-
from config.runtime import
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
from models.depth import estimate_scene_geometry
|
| 14 |
from models.loader import _load_intrinsic_model
|
| 15 |
from models.segmentation import active_model_metadata, run_segmentation
|
|
@@ -18,9 +23,14 @@ from services.direction.analysis import floor_direction_geometry_inputs
|
|
| 18 |
from services.floor.edge_coverage import scaled_odd_kernel_size
|
| 19 |
from services.floor.mask import build_floor_surface_mask, clean_floor_mask, wall_subtract
|
| 20 |
from services.floor.detection import estimate_floor_plane
|
|
|
|
| 21 |
from services.geometry.uv_mapping import build_surface_uv_mapping
|
| 22 |
from services.lighting.intrinsic import build_intrinsic_lighting_maps
|
| 23 |
-
from services.lighting.shading import
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
from services.pipeline.packaging import encode_bundle_image_data_url, foreground_occlusion_mask
|
| 25 |
from services.pipeline.bundle_assembly import build_fallback_segments, build_floor_segment, build_wall_segment
|
| 26 |
from services.pipeline import debug_stages
|
|
@@ -139,14 +149,35 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 139 |
|
| 140 |
# --- Surface mask ---
|
| 141 |
t0 = time.perf_counter()
|
|
|
|
|
|
|
|
|
|
| 142 |
quad = np.asarray(plane["quad"], dtype=np.float32).reshape(4, 2) if plane and plane.get("quad") else None
|
| 143 |
-
surface_mask, edge_metadata = build_floor_surface_mask(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
replaced_material_mask = (seg_class_mask(seg_map, class_ids(REPLACEABLE_SOFT_FLOOR_CLASSES)).astype(bool) & (surface_mask > 0)).astype(np.uint8)
|
| 145 |
surface_indices = mask_to_indices(surface_mask)
|
| 146 |
occlusion_mask = foreground_occlusion_mask(surface_mask, seg_map)
|
| 147 |
occlusion_indices = mask_to_indices(occlusion_mask)
|
| 148 |
el = (time.perf_counter() - t0) * 1000
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
if d:
|
| 151 |
debug_stages.record_surface(d, img_np, floor_mask, surface_mask, occlusion_mask, edge_metadata, el)
|
| 152 |
|
|
@@ -154,12 +185,25 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 154 |
if progress_callback:
|
| 155 |
progress_callback(PipelinePhase.SURFACE_MAPPING, 0)
|
| 156 |
t0 = time.perf_counter()
|
| 157 |
-
surface_mapping = build_surface_uv_mapping(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 158 |
use_surface_uv = bool(surface_mapping and surface_mapping.get("useSurfaceUv"))
|
| 159 |
mapping_metadata = surface_mapping["metadata"] if surface_mapping is not None else {
|
| 160 |
**_DEFAULT_MAPPING_META, "surfaceUvTotalPixels": int(len(surface_indices))}
|
| 161 |
el = (time.perf_counter() - t0) * 1000
|
| 162 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
if d:
|
| 164 |
debug_stages.record_surface_mapping(d, h, w, surface_indices, surface_mapping, use_surface_uv, mapping_metadata, el)
|
| 165 |
if progress_callback:
|
|
@@ -179,6 +223,14 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 179 |
if lighting_maps and lighting_maps.get("shadeMap") is not None:
|
| 180 |
from config.models import INTRINSIC_MODEL_VERSION
|
| 181 |
lighting_source, intrinsic_lighting_used = f"intrinsic-{INTRINSIC_MODEL_VERSION}", True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
if ENABLE_SHADING_TRANSFER and (not lighting_maps or lighting_maps.get("shadeMap") is None):
|
| 183 |
lighting_maps = build_luminance_lighting_maps(img_np, surface_mask, replaced_material_mask)
|
| 184 |
if lighting_maps and lighting_maps.get("shadeMap") is not None:
|
|
@@ -187,13 +239,24 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 187 |
shade_map, showroom_shade_map, reflection_map = lighting_maps.get("shadeMap"), lighting_maps.get("showroomShadeMap"), lighting_maps.get("reflectionMap")
|
| 188 |
shade_statistics = lighting_map_statistics(shade_map, surface_mask)
|
| 189 |
el = (time.perf_counter() - t0) * 1000
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
| 191 |
if d:
|
| 192 |
debug_stages.record_lighting(d, shade_map, showroom_shade_map, reflection_map, surface_mask, lighting_source, el)
|
| 193 |
|
|
|
|
|
|
|
| 194 |
wall_mask = seg_class_mask(seg_map, class_ids({"wall"}))
|
| 195 |
-
wall_components
|
| 196 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
|
| 198 |
# --- Pre-compute wall lighting in parallel with floor direction ---
|
| 199 |
# Wall lighting was previously computed inside build_wall_segment (in the
|
|
@@ -218,7 +281,14 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 218 |
progress_callback(PipelinePhase.DIRECTION, 0)
|
| 219 |
t0 = time.perf_counter()
|
| 220 |
dir_xform = plane.get("floorTransform") if plane and plane.get("floorTransform") and float(plane.get("geometryConfidence") or 0.0) >= 0.35 else homography
|
| 221 |
-
dir_inputs = floor_direction_geometry_inputs(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
struct_mask = seg_class_mask(seg_map, class_ids({"wall", "ceiling", "door", "window", "column", "base", "railing"}))
|
| 223 |
sk = scaled_odd_kernel_size(h, w, 0.006, minimum=3)
|
| 224 |
struct_mask = cv2.dilate(struct_mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (sk, sk)), iterations=1)
|
|
@@ -242,9 +312,11 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 242 |
# Collect pre-computed wall lighting results
|
| 243 |
wall_lighting_results: list[dict | None] = []
|
| 244 |
if wall_executor:
|
|
|
|
| 245 |
for fut in wall_lighting_futures:
|
| 246 |
wall_lighting_results.append(fut.result())
|
| 247 |
wall_executor.shutdown(wait=False)
|
|
|
|
| 248 |
else:
|
| 249 |
wall_lighting_results = [None] * len(wall_components)
|
| 250 |
|
|
@@ -279,15 +351,26 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
|
|
| 279 |
if progress_callback:
|
| 280 |
progress_callback(PipelinePhase.PACKAGING, 100)
|
| 281 |
_log_stage("Packaging", t0, f"segments={len(segments)}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
total_elapsed = time.perf_counter() - t_start
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
|
| 284 |
# ── Print clean timing summary ──
|
| 285 |
_print_pipeline_summary(stage_times, total_elapsed, w, h)
|
| 286 |
|
| 287 |
if d:
|
| 288 |
d.complete(total_elapsed * 1000)
|
| 289 |
-
pixels_b64 = _pixels_b64_future.result()
|
| 290 |
-
_img_pool.shutdown(wait=False)
|
| 291 |
pipeline_stages = [
|
| 292 |
{"name": name, "elapsed_s": round(elapsed, 3), "detail": detail}
|
| 293 |
for name, elapsed, detail in stage_times
|
|
|
|
| 9 |
import numpy as np
|
| 10 |
from PIL import Image
|
| 11 |
|
| 12 |
+
from config.runtime import (
|
| 13 |
+
ENABLE_FAST_SHADOW_TRANSFER,
|
| 14 |
+
ENABLE_INTRINSIC_SHADING,
|
| 15 |
+
ENABLE_SHADING_TRANSFER,
|
| 16 |
+
ENABLE_WALL_SEGMENTS,
|
| 17 |
+
)
|
| 18 |
from models.depth import estimate_scene_geometry
|
| 19 |
from models.loader import _load_intrinsic_model
|
| 20 |
from models.segmentation import active_model_metadata, run_segmentation
|
|
|
|
| 23 |
from services.floor.edge_coverage import scaled_odd_kernel_size
|
| 24 |
from services.floor.mask import build_floor_surface_mask, clean_floor_mask, wall_subtract
|
| 25 |
from services.floor.detection import estimate_floor_plane
|
| 26 |
+
from services.geometry.multi_plane import geometry_point_maps
|
| 27 |
from services.geometry.uv_mapping import build_surface_uv_mapping
|
| 28 |
from services.lighting.intrinsic import build_intrinsic_lighting_maps
|
| 29 |
+
from services.lighting.shading import (
|
| 30 |
+
build_fast_shadow_lighting_maps,
|
| 31 |
+
build_luminance_lighting_maps,
|
| 32 |
+
lighting_map_statistics,
|
| 33 |
+
)
|
| 34 |
from services.pipeline.packaging import encode_bundle_image_data_url, foreground_occlusion_mask
|
| 35 |
from services.pipeline.bundle_assembly import build_fallback_segments, build_floor_segment, build_wall_segment
|
| 36 |
from services.pipeline import debug_stages
|
|
|
|
| 149 |
|
| 150 |
# --- Surface mask ---
|
| 151 |
t0 = time.perf_counter()
|
| 152 |
+
geometry_maps_started = time.perf_counter()
|
| 153 |
+
prepared_geometry_maps = geometry_point_maps(floor_mask, geometry)
|
| 154 |
+
geometry_maps_ms = (time.perf_counter() - geometry_maps_started) * 1000
|
| 155 |
quad = np.asarray(plane["quad"], dtype=np.float32).reshape(4, 2) if plane and plane.get("quad") else None
|
| 156 |
+
surface_mask, edge_metadata = build_floor_surface_mask(
|
| 157 |
+
floor_mask,
|
| 158 |
+
seg_map,
|
| 159 |
+
quad,
|
| 160 |
+
depth,
|
| 161 |
+
geometry,
|
| 162 |
+
plane,
|
| 163 |
+
geometry_maps=prepared_geometry_maps,
|
| 164 |
+
)
|
| 165 |
replaced_material_mask = (seg_class_mask(seg_map, class_ids(REPLACEABLE_SOFT_FLOOR_CLASSES)).astype(bool) & (surface_mask > 0)).astype(np.uint8)
|
| 166 |
surface_indices = mask_to_indices(surface_mask)
|
| 167 |
occlusion_mask = foreground_occlusion_mask(surface_mask, seg_map)
|
| 168 |
occlusion_indices = mask_to_indices(occlusion_mask)
|
| 169 |
el = (time.perf_counter() - t0) * 1000
|
| 170 |
+
surface_timing = edge_metadata.get("surfaceMaskingTimingMs") or {}
|
| 171 |
+
filter_ms = sum(float(surface_timing.get(name) or 0.0) for name in (
|
| 172 |
+
"initialGeometryFilter",
|
| 173 |
+
"postEdgeGeometryFilter",
|
| 174 |
+
"postSoftFloorGeometryFilter",
|
| 175 |
+
))
|
| 176 |
+
_log_stage(
|
| 177 |
+
"Surface Masking",
|
| 178 |
+
t0,
|
| 179 |
+
f"geometry-prep={geometry_maps_ms:.0f}ms filters={filter_ms:.0f}ms",
|
| 180 |
+
)
|
| 181 |
if d:
|
| 182 |
debug_stages.record_surface(d, img_np, floor_mask, surface_mask, occlusion_mask, edge_metadata, el)
|
| 183 |
|
|
|
|
| 185 |
if progress_callback:
|
| 186 |
progress_callback(PipelinePhase.SURFACE_MAPPING, 0)
|
| 187 |
t0 = time.perf_counter()
|
| 188 |
+
surface_mapping = build_surface_uv_mapping(
|
| 189 |
+
surface_mask,
|
| 190 |
+
surface_indices,
|
| 191 |
+
geometry,
|
| 192 |
+
geometry_maps=prepared_geometry_maps,
|
| 193 |
+
)
|
| 194 |
use_surface_uv = bool(surface_mapping and surface_mapping.get("useSurfaceUv"))
|
| 195 |
mapping_metadata = surface_mapping["metadata"] if surface_mapping is not None else {
|
| 196 |
**_DEFAULT_MAPPING_META, "surfaceUvTotalPixels": int(len(surface_indices))}
|
| 197 |
el = (time.perf_counter() - t0) * 1000
|
| 198 |
+
uv_timing = mapping_metadata.get("surfaceUvTimingMs") or {}
|
| 199 |
+
uv_detail = f"uv={'yes' if use_surface_uv else 'no'}"
|
| 200 |
+
if uv_timing:
|
| 201 |
+
uv_detail += (
|
| 202 |
+
f" fit={float(uv_timing.get('planeFit') or 0.0):.0f}ms"
|
| 203 |
+
f" assign={float(uv_timing.get('planeAssignment') or 0.0):.0f}ms"
|
| 204 |
+
f" quality={float(uv_timing.get('qualityAnalysis') or 0.0):.0f}ms"
|
| 205 |
+
)
|
| 206 |
+
_log_stage("UV Mapping", t0, uv_detail)
|
| 207 |
if d:
|
| 208 |
debug_stages.record_surface_mapping(d, h, w, surface_indices, surface_mapping, use_surface_uv, mapping_metadata, el)
|
| 209 |
if progress_callback:
|
|
|
|
| 223 |
if lighting_maps and lighting_maps.get("shadeMap") is not None:
|
| 224 |
from config.models import INTRINSIC_MODEL_VERSION
|
| 225 |
lighting_source, intrinsic_lighting_used = f"intrinsic-{INTRINSIC_MODEL_VERSION}", True
|
| 226 |
+
if ENABLE_FAST_SHADOW_TRANSFER and (not lighting_maps or lighting_maps.get("shadeMap") is None):
|
| 227 |
+
lighting_maps = build_fast_shadow_lighting_maps(
|
| 228 |
+
img_np,
|
| 229 |
+
surface_mask,
|
| 230 |
+
replaced_material_mask,
|
| 231 |
+
)
|
| 232 |
+
if lighting_maps and lighting_maps.get("shadeMap") is not None:
|
| 233 |
+
lighting_source = "fast-luminance"
|
| 234 |
if ENABLE_SHADING_TRANSFER and (not lighting_maps or lighting_maps.get("shadeMap") is None):
|
| 235 |
lighting_maps = build_luminance_lighting_maps(img_np, surface_mask, replaced_material_mask)
|
| 236 |
if lighting_maps and lighting_maps.get("shadeMap") is not None:
|
|
|
|
| 239 |
shade_map, showroom_shade_map, reflection_map = lighting_maps.get("shadeMap"), lighting_maps.get("showroomShadeMap"), lighting_maps.get("reflectionMap")
|
| 240 |
shade_statistics = lighting_map_statistics(shade_map, surface_mask)
|
| 241 |
el = (time.perf_counter() - t0) * 1000
|
| 242 |
+
lighting_detail = f"source={lighting_source}"
|
| 243 |
+
if shade_map is not None:
|
| 244 |
+
lighting_detail += f" map={shade_map.shape[1]}x{shade_map.shape[0]}"
|
| 245 |
+
_log_stage("Lighting", t0, lighting_detail)
|
| 246 |
if d:
|
| 247 |
debug_stages.record_lighting(d, shade_map, showroom_shade_map, reflection_map, surface_mask, lighting_source, el)
|
| 248 |
|
| 249 |
+
# The semantic wall mask remains useful as a structural cue for floor
|
| 250 |
+
# direction, even when wall surfaces are not emitted in the bundle.
|
| 251 |
wall_mask = seg_class_mask(seg_map, class_ids({"wall"}))
|
| 252 |
+
wall_components = []
|
| 253 |
+
wall_protected_mask = None
|
| 254 |
+
if ENABLE_WALL_SEGMENTS:
|
| 255 |
+
t0 = time.perf_counter()
|
| 256 |
+
wall_components, wall_protected_mask = wall_surface_components(
|
| 257 |
+
seg_map, min_floor_area, geometry,
|
| 258 |
+
)
|
| 259 |
+
_log_stage("Wall Discovery", t0, f"components={len(wall_components)}")
|
| 260 |
|
| 261 |
# --- Pre-compute wall lighting in parallel with floor direction ---
|
| 262 |
# Wall lighting was previously computed inside build_wall_segment (in the
|
|
|
|
| 281 |
progress_callback(PipelinePhase.DIRECTION, 0)
|
| 282 |
t0 = time.perf_counter()
|
| 283 |
dir_xform = plane.get("floorTransform") if plane and plane.get("floorTransform") and float(plane.get("geometryConfidence") or 0.0) >= 0.35 else homography
|
| 284 |
+
dir_inputs = floor_direction_geometry_inputs(
|
| 285 |
+
surface_mask,
|
| 286 |
+
geometry,
|
| 287 |
+
plane,
|
| 288 |
+
surface_mapping,
|
| 289 |
+
use_surface_uv=use_surface_uv,
|
| 290 |
+
geometry_maps=prepared_geometry_maps,
|
| 291 |
+
)
|
| 292 |
struct_mask = seg_class_mask(seg_map, class_ids({"wall", "ceiling", "door", "window", "column", "base", "railing"}))
|
| 293 |
sk = scaled_odd_kernel_size(h, w, 0.006, minimum=3)
|
| 294 |
struct_mask = cv2.dilate(struct_mask, cv2.getStructuringElement(cv2.MORPH_ELLIPSE, (sk, sk)), iterations=1)
|
|
|
|
| 312 |
# Collect pre-computed wall lighting results
|
| 313 |
wall_lighting_results: list[dict | None] = []
|
| 314 |
if wall_executor:
|
| 315 |
+
t0 = time.perf_counter()
|
| 316 |
for fut in wall_lighting_futures:
|
| 317 |
wall_lighting_results.append(fut.result())
|
| 318 |
wall_executor.shutdown(wait=False)
|
| 319 |
+
_log_stage("Wall Lighting Wait", t0, f"components={len(wall_components)}")
|
| 320 |
else:
|
| 321 |
wall_lighting_results = [None] * len(wall_components)
|
| 322 |
|
|
|
|
| 351 |
if progress_callback:
|
| 352 |
progress_callback(PipelinePhase.PACKAGING, 100)
|
| 353 |
_log_stage("Packaging", t0, f"segments={len(segments)}")
|
| 354 |
+
t0 = time.perf_counter()
|
| 355 |
+
pixels_b64 = _pixels_b64_future.result()
|
| 356 |
+
_img_pool.shutdown(wait=False)
|
| 357 |
+
_log_stage("Image Encoding Wait", t0)
|
| 358 |
+
|
| 359 |
total_elapsed = time.perf_counter() - t_start
|
| 360 |
+
accounted_elapsed = sum(elapsed for _, elapsed, _ in stage_times)
|
| 361 |
+
overhead_elapsed = max(0.0, total_elapsed - accounted_elapsed)
|
| 362 |
+
if overhead_elapsed >= 0.001:
|
| 363 |
+
stage_times.append((
|
| 364 |
+
"Pipeline Overhead",
|
| 365 |
+
overhead_elapsed,
|
| 366 |
+
"callbacks, metadata and untimed glue",
|
| 367 |
+
))
|
| 368 |
|
| 369 |
# ── Print clean timing summary ──
|
| 370 |
_print_pipeline_summary(stage_times, total_elapsed, w, h)
|
| 371 |
|
| 372 |
if d:
|
| 373 |
d.complete(total_elapsed * 1000)
|
|
|
|
|
|
|
| 374 |
pipeline_stages = [
|
| 375 |
{"name": name, "elapsed_s": round(elapsed, 3), "detail": detail}
|
| 376 |
for name, elapsed, detail in stage_times
|
services/pipeline/bundle_assembly.py
CHANGED
|
@@ -15,6 +15,7 @@ from config.lighting import (
|
|
| 15 |
SHOWROOM_SHADE_MAP_MIN,
|
| 16 |
)
|
| 17 |
from config.runtime import (
|
|
|
|
| 18 |
ENABLE_MULTI_PLANE_SURFACES,
|
| 19 |
ENABLE_PLANE_FIT,
|
| 20 |
ENABLE_SAM_REFINEMENT,
|
|
@@ -100,12 +101,17 @@ def build_floor_segment(
|
|
| 100 |
[p.get("fitMode") for p in surface_mapping["planes"]]
|
| 101 |
if surface_mapping is not None else []
|
| 102 |
),
|
| 103 |
-
"shadingTransferEnabled": ENABLE_SHADING_TRANSFER,
|
|
|
|
| 104 |
"lightingSource": lighting_source,
|
| 105 |
"lightingTransferVersion": LIGHTING_TRANSFER_VERSION,
|
| 106 |
"shadeMapEncoding": SHADE_MAP_ENCODING,
|
| 107 |
"shadeMapStatistics": shade_statistics,
|
| 108 |
"shadeMapRange": [SHADE_MAP_MIN, SHADE_MAP_MAX],
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
"showroomShadeMapRange": [SHOWROOM_SHADE_MAP_MIN, SHOWROOM_SHADE_MAP_MAX],
|
| 110 |
"renderPresetDefaults": {
|
| 111 |
"preset": "realistic",
|
|
|
|
| 15 |
SHOWROOM_SHADE_MAP_MIN,
|
| 16 |
)
|
| 17 |
from config.runtime import (
|
| 18 |
+
ENABLE_FAST_SHADOW_TRANSFER,
|
| 19 |
ENABLE_MULTI_PLANE_SURFACES,
|
| 20 |
ENABLE_PLANE_FIT,
|
| 21 |
ENABLE_SAM_REFINEMENT,
|
|
|
|
| 101 |
[p.get("fitMode") for p in surface_mapping["planes"]]
|
| 102 |
if surface_mapping is not None else []
|
| 103 |
),
|
| 104 |
+
"shadingTransferEnabled": ENABLE_SHADING_TRANSFER or ENABLE_FAST_SHADOW_TRANSFER,
|
| 105 |
+
"fastShadowTransferEnabled": ENABLE_FAST_SHADOW_TRANSFER,
|
| 106 |
"lightingSource": lighting_source,
|
| 107 |
"lightingTransferVersion": LIGHTING_TRANSFER_VERSION,
|
| 108 |
"shadeMapEncoding": SHADE_MAP_ENCODING,
|
| 109 |
"shadeMapStatistics": shade_statistics,
|
| 110 |
"shadeMapRange": [SHADE_MAP_MIN, SHADE_MAP_MAX],
|
| 111 |
+
"shadeMapSize": (
|
| 112 |
+
[int(shade_map.shape[1]), int(shade_map.shape[0])]
|
| 113 |
+
if shade_map is not None else None
|
| 114 |
+
),
|
| 115 |
"showroomShadeMapRange": [SHOWROOM_SHADE_MAP_MIN, SHOWROOM_SHADE_MAP_MAX],
|
| 116 |
"renderPresetDefaults": {
|
| 117 |
"preset": "realistic",
|
services/pipeline/packaging.py
CHANGED
|
@@ -84,6 +84,52 @@ def make_binary_ref(path: str, data: bytes, dtype: str) -> dict:
|
|
| 84 |
}
|
| 85 |
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
def encode_mask_bitset(mask_bytes: bytes, pixel_count: int) -> bytes:
|
| 88 |
"""Encode uint32 pixel indices as an exact, least-significant-bit-first bitset."""
|
| 89 |
indices = np.frombuffer(mask_bytes, dtype=np.uint32)
|
|
@@ -143,7 +189,6 @@ def build_manifest_segmentation_bundle(
|
|
| 143 |
}
|
| 144 |
|
| 145 |
lazy_asset_fields = {
|
| 146 |
-
"surfaceUv": ("surface-uv.f32", "float32"),
|
| 147 |
"surfacePlaneIds": ("surface-plane-ids.u8", "uint8"),
|
| 148 |
"shadeMap": ("shade.u8", "uint8"),
|
| 149 |
"showroomShadeMap": ("showroom-shade.u8", "uint8"),
|
|
@@ -170,6 +215,16 @@ def build_manifest_segmentation_bundle(
|
|
| 170 |
f"{len(mask_bytes)} -> {len(mask_bitset)} bytes",
|
| 171 |
flush=True,
|
| 172 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
for field, (filename, dtype) in lazy_asset_fields.items():
|
| 174 |
value = segment.get(field)
|
| 175 |
if value is None:
|
|
@@ -181,12 +236,10 @@ def build_manifest_segmentation_bundle(
|
|
| 181 |
data = base64.b64decode(value)
|
| 182 |
else:
|
| 183 |
data = bytes(value)
|
| 184 |
-
|
| 185 |
-
|
| 186 |
segment_metadata[field] = {
|
| 187 |
-
**make_binary_ref(
|
| 188 |
-
"url": f"/viz2d/jobs/{job_id}/assets/{asset_name}",
|
| 189 |
-
"lazy": True,
|
| 190 |
}
|
| 191 |
metadata["segments"].append(segment_metadata)
|
| 192 |
|
|
|
|
| 84 |
}
|
| 85 |
|
| 86 |
|
| 87 |
+
def encode_surface_uv_asset(value) -> tuple[bytes, dict]:
|
| 88 |
+
"""Quantize smooth metric UV pairs and delta-code them for HTTP gzip."""
|
| 89 |
+
if isinstance(value, np.ndarray):
|
| 90 |
+
surface_uv = np.asarray(value, dtype=np.float32).reshape(-1)
|
| 91 |
+
elif isinstance(value, str):
|
| 92 |
+
surface_uv = np.frombuffer(base64.b64decode(value), dtype=np.float32)
|
| 93 |
+
else:
|
| 94 |
+
surface_uv = np.frombuffer(bytes(value), dtype=np.float32)
|
| 95 |
+
|
| 96 |
+
if surface_uv.size == 0 or surface_uv.size % 2:
|
| 97 |
+
data = surface_uv.astype("<f4", copy=False).tobytes()
|
| 98 |
+
return data, {"dtype": "float32"}
|
| 99 |
+
|
| 100 |
+
uv_pairs = surface_uv.reshape(-1, 2)
|
| 101 |
+
valid_pairs = np.isfinite(uv_pairs).all(axis=1)
|
| 102 |
+
if not valid_pairs.any():
|
| 103 |
+
data = surface_uv.astype("<f4", copy=False).tobytes()
|
| 104 |
+
return data, {"dtype": "float32"}
|
| 105 |
+
|
| 106 |
+
finite_uv = uv_pairs[valid_pairs]
|
| 107 |
+
uv_offset = finite_uv.min(axis=0).astype(np.float64)
|
| 108 |
+
uv_max = finite_uv.max(axis=0).astype(np.float64)
|
| 109 |
+
# Reserve 65535/65535 as the invalid-UV sentinel.
|
| 110 |
+
uv_scale = (uv_max - uv_offset) / 65534.0
|
| 111 |
+
safe_scale = np.where(uv_scale > 0, uv_scale, 1.0)
|
| 112 |
+
quantized = np.full(uv_pairs.shape, 65535, dtype=np.uint16)
|
| 113 |
+
finite_quantized = np.rint((finite_uv - uv_offset) / safe_scale)
|
| 114 |
+
quantized[valid_pairs] = np.clip(finite_quantized, 0, 65534).astype(np.uint16)
|
| 115 |
+
|
| 116 |
+
delta = np.empty_like(quantized)
|
| 117 |
+
if len(quantized):
|
| 118 |
+
delta[0] = quantized[0]
|
| 119 |
+
if len(quantized) > 1:
|
| 120 |
+
difference = quantized[1:].astype(np.int32) - quantized[:-1].astype(np.int32)
|
| 121 |
+
delta[1:] = np.bitwise_and(difference, 0xFFFF).astype(np.uint16)
|
| 122 |
+
|
| 123 |
+
data = delta.astype("<u2", copy=False).tobytes()
|
| 124 |
+
return data, {
|
| 125 |
+
"dtype": "uint16",
|
| 126 |
+
"encoding": "delta-quantized-uv-v1",
|
| 127 |
+
"elementCount": int(surface_uv.size),
|
| 128 |
+
"uvOffset": [float(uv_offset[0]), float(uv_offset[1])],
|
| 129 |
+
"uvScale": [float(uv_scale[0]), float(uv_scale[1])],
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
|
| 133 |
def encode_mask_bitset(mask_bytes: bytes, pixel_count: int) -> bytes:
|
| 134 |
"""Encode uint32 pixel indices as an exact, least-significant-bit-first bitset."""
|
| 135 |
indices = np.frombuffer(mask_bytes, dtype=np.uint32)
|
|
|
|
| 189 |
}
|
| 190 |
|
| 191 |
lazy_asset_fields = {
|
|
|
|
| 192 |
"surfacePlaneIds": ("surface-plane-ids.u8", "uint8"),
|
| 193 |
"shadeMap": ("shade.u8", "uint8"),
|
| 194 |
"showroomShadeMap": ("showroom-shade.u8", "uint8"),
|
|
|
|
| 215 |
f"{len(mask_bytes)} -> {len(mask_bitset)} bytes",
|
| 216 |
flush=True,
|
| 217 |
)
|
| 218 |
+
surface_uv = segment.get("surfaceUv")
|
| 219 |
+
if surface_uv is not None:
|
| 220 |
+
data, encoding_metadata = encode_surface_uv_asset(surface_uv)
|
| 221 |
+
extension = "u16" if encoding_metadata["dtype"] == "uint16" else "f32"
|
| 222 |
+
asset_path = f"segments/{segment_index}/surface-uv.{extension}"
|
| 223 |
+
archive.writestr(asset_path, data)
|
| 224 |
+
segment_metadata["surfaceUv"] = {
|
| 225 |
+
**make_binary_ref(asset_path, data, encoding_metadata["dtype"]),
|
| 226 |
+
**encoding_metadata,
|
| 227 |
+
}
|
| 228 |
for field, (filename, dtype) in lazy_asset_fields.items():
|
| 229 |
value = segment.get(field)
|
| 230 |
if value is None:
|
|
|
|
| 236 |
data = base64.b64decode(value)
|
| 237 |
else:
|
| 238 |
data = bytes(value)
|
| 239 |
+
asset_path = f"segments/{segment_index}/{filename}"
|
| 240 |
+
archive.writestr(asset_path, data)
|
| 241 |
segment_metadata[field] = {
|
| 242 |
+
**make_binary_ref(asset_path, data, dtype),
|
|
|
|
|
|
|
| 243 |
}
|
| 244 |
metadata["segments"].append(segment_metadata)
|
| 245 |
|
test_fast_shadow_transfer.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Focused regression checks for the low-cost room-shadow extraction path."""
|
| 2 |
+
|
| 3 |
+
import unittest
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
|
| 7 |
+
from config.lighting import SHADE_MAP_MAX, SHADE_MAP_MIN
|
| 8 |
+
from config.runtime import FAST_SHADOW_MAX_DIMENSION
|
| 9 |
+
from services.lighting.luminance import decode_relative_map
|
| 10 |
+
from services.lighting.shading import build_fast_shadow_lighting_maps
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
class FastShadowTransferTests(unittest.TestCase):
|
| 14 |
+
def test_returns_compact_map_that_preserves_a_cast_shadow(self):
|
| 15 |
+
height, width = 1200, 1600
|
| 16 |
+
image = np.full((height, width, 3), 190, dtype=np.uint8)
|
| 17 |
+
image[650:1050, 850:1250] = 70
|
| 18 |
+
mask = np.zeros((height, width), dtype=np.uint8)
|
| 19 |
+
mask[400:1150, 100:1500] = 1
|
| 20 |
+
|
| 21 |
+
result = build_fast_shadow_lighting_maps(image, mask)
|
| 22 |
+
|
| 23 |
+
self.assertIsNotNone(result)
|
| 24 |
+
shade_map = result["shadeMap"]
|
| 25 |
+
self.assertLessEqual(max(shade_map.shape), FAST_SHADOW_MAX_DIMENSION)
|
| 26 |
+
self.assertLess(shade_map.size, height * width)
|
| 27 |
+
decoded = decode_relative_map(shade_map, SHADE_MAP_MIN, SHADE_MAP_MAX)
|
| 28 |
+
shadow = decoded[int(850 * shade_map.shape[0] / height), int(1050 * shade_map.shape[1] / width)]
|
| 29 |
+
lit = decoded[int(850 * shade_map.shape[0] / height), int(450 * shade_map.shape[1] / width)]
|
| 30 |
+
self.assertLess(shadow, lit)
|
| 31 |
+
self.assertIsNone(result["showroomShadeMap"])
|
| 32 |
+
self.assertIsNone(result["reflectionMap"])
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
unittest.main()
|
test_geometry_optimization.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import unittest
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from services.floor.geometry_filter import filter_surface_by_floor_geometry
|
| 6 |
+
from services.geometry.multi_plane import (
|
| 7 |
+
_prune_weak_secondary_planes,
|
| 8 |
+
geometry_point_maps,
|
| 9 |
+
)
|
| 10 |
+
from services.geometry.ransac import (
|
| 11 |
+
_best_surface_hypothesis,
|
| 12 |
+
_candidate_hypotheses,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class GeometryOptimizationTests(unittest.TestCase):
|
| 17 |
+
def test_weak_secondary_planes_are_removed_and_ids_are_reindexed(self):
|
| 18 |
+
planes = [
|
| 19 |
+
{"id": 0, "inlierCount": 325_002},
|
| 20 |
+
{"id": 1, "inlierCount": 5_302},
|
| 21 |
+
{"id": 2, "inlierCount": 26_000},
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
retained = _prune_weak_secondary_planes(planes)
|
| 25 |
+
|
| 26 |
+
self.assertEqual(
|
| 27 |
+
[plane["inlierCount"] for plane in retained],
|
| 28 |
+
[325_002, 26_000],
|
| 29 |
+
)
|
| 30 |
+
self.assertEqual([plane["id"] for plane in retained], [0, 1])
|
| 31 |
+
|
| 32 |
+
def test_batched_ransac_scoring_matches_sequential_scoring(self):
|
| 33 |
+
rng = np.random.default_rng(7)
|
| 34 |
+
xz = rng.uniform(-2, 2, size=(4_000, 2)).astype(np.float32)
|
| 35 |
+
points = np.column_stack((
|
| 36 |
+
xz[:, 0],
|
| 37 |
+
rng.normal(0, 0.008, len(xz)),
|
| 38 |
+
xz[:, 1],
|
| 39 |
+
)).astype(np.float32)
|
| 40 |
+
normals = np.tile(np.array([0, 1, 0], dtype=np.float32), (len(points), 1))
|
| 41 |
+
normals += rng.normal(0, 0.02, normals.shape).astype(np.float32)
|
| 42 |
+
normals /= np.linalg.norm(normals, axis=1, keepdims=True)
|
| 43 |
+
|
| 44 |
+
origins, hypotheses = _candidate_hypotheses(
|
| 45 |
+
points,
|
| 46 |
+
iterations=90,
|
| 47 |
+
rng=np.random.default_rng(41),
|
| 48 |
+
)
|
| 49 |
+
distance_threshold = 0.03
|
| 50 |
+
normal_cos = 0.75
|
| 51 |
+
expected_index = -1
|
| 52 |
+
expected_count = 0
|
| 53 |
+
for index, (origin, normal) in enumerate(zip(origins, hypotheses, strict=True)):
|
| 54 |
+
distances = np.abs((points - origin) @ normal)
|
| 55 |
+
alignments = np.abs(normals @ normal)
|
| 56 |
+
count = int(((distances <= distance_threshold) & (alignments >= normal_cos)).sum())
|
| 57 |
+
if count > expected_count:
|
| 58 |
+
expected_count = count
|
| 59 |
+
expected_index = index
|
| 60 |
+
|
| 61 |
+
result = _best_surface_hypothesis(
|
| 62 |
+
points,
|
| 63 |
+
origins,
|
| 64 |
+
hypotheses,
|
| 65 |
+
distance_threshold,
|
| 66 |
+
candidate_normals=normals,
|
| 67 |
+
normal_cos=normal_cos,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
self.assertIsNotNone(result)
|
| 71 |
+
origin, normal = result
|
| 72 |
+
np.testing.assert_array_equal(origin, origins[expected_index])
|
| 73 |
+
np.testing.assert_array_equal(normal, hypotheses[expected_index])
|
| 74 |
+
|
| 75 |
+
def test_prepared_geometry_maps_preserve_filter_output(self):
|
| 76 |
+
height, width = 120, 160
|
| 77 |
+
y_coordinates = np.arange(height, dtype=np.float32)[:, None]
|
| 78 |
+
x_coordinates = np.arange(width, dtype=np.float32)[None, :]
|
| 79 |
+
points = np.empty((height, width, 3), dtype=np.float32)
|
| 80 |
+
points[:, :, 0] = (x_coordinates - width / 2) / 100
|
| 81 |
+
points[:, :, 1] = 0
|
| 82 |
+
points[:, :, 2] = 1 + y_coordinates / 100
|
| 83 |
+
normals = np.zeros_like(points)
|
| 84 |
+
normals[:, :, 1] = 1
|
| 85 |
+
surface = np.zeros((height, width), dtype=np.uint8)
|
| 86 |
+
surface[height // 3:] = 1
|
| 87 |
+
geometry = {
|
| 88 |
+
"provider": "moge-2",
|
| 89 |
+
"points": points,
|
| 90 |
+
"normals": normals,
|
| 91 |
+
"validMask": np.ones((height, width), dtype=bool),
|
| 92 |
+
"intrinsics": np.eye(3, dtype=np.float32),
|
| 93 |
+
}
|
| 94 |
+
plane = {
|
| 95 |
+
"planeNormal": [0, 1, 0],
|
| 96 |
+
"planeOrigin": [0, 0, 0],
|
| 97 |
+
}
|
| 98 |
+
|
| 99 |
+
expected, expected_metadata = filter_surface_by_floor_geometry(surface, geometry, plane)
|
| 100 |
+
prepared_maps = geometry_point_maps(surface, geometry)
|
| 101 |
+
actual, actual_metadata = filter_surface_by_floor_geometry(
|
| 102 |
+
surface,
|
| 103 |
+
geometry,
|
| 104 |
+
plane,
|
| 105 |
+
geometry_maps=prepared_maps,
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
np.testing.assert_array_equal(actual, expected)
|
| 109 |
+
self.assertEqual(
|
| 110 |
+
actual_metadata["geometrySurfaceFilterReason"],
|
| 111 |
+
expected_metadata["geometrySurfaceFilterReason"],
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
unittest.main()
|
visualizer.gpu.toml
CHANGED
|
@@ -17,11 +17,13 @@ enable_depth_estimation = true
|
|
| 17 |
enable_moge_geometry = true
|
| 18 |
enable_plane_fit = true
|
| 19 |
enable_multi_plane_surfaces = true
|
| 20 |
-
enable_wall_segments =
|
| 21 |
-
enable_intrinsic_shading =
|
| 22 |
-
enable_shading_transfer =
|
|
|
|
|
|
|
| 23 |
enable_sam_refinement = false
|
| 24 |
-
enable_floor_mask_cleanup =
|
| 25 |
warm_start_models = true
|
| 26 |
debug_artifacts_enabled = false
|
| 27 |
inference_max_dimension = 1024
|
|
@@ -32,7 +34,7 @@ data_dir = "data"
|
|
| 32 |
|
| 33 |
[surface_mapping]
|
| 34 |
ransac_distance_threshold = 0.04
|
| 35 |
-
max_planes =
|
| 36 |
normal_angle_threshold_degrees = 35
|
| 37 |
normal_smoothing_kernel = 5
|
| 38 |
min_plane_pixels = 1500
|
|
|
|
| 17 |
enable_moge_geometry = true
|
| 18 |
enable_plane_fit = true
|
| 19 |
enable_multi_plane_surfaces = true
|
| 20 |
+
enable_wall_segments = false
|
| 21 |
+
enable_intrinsic_shading = false
|
| 22 |
+
enable_shading_transfer = false
|
| 23 |
+
enable_fast_shadow_transfer = true
|
| 24 |
+
fast_shadow_max_dimension = 640
|
| 25 |
enable_sam_refinement = false
|
| 26 |
+
enable_floor_mask_cleanup = true
|
| 27 |
warm_start_models = true
|
| 28 |
debug_artifacts_enabled = false
|
| 29 |
inference_max_dimension = 1024
|
|
|
|
| 34 |
|
| 35 |
[surface_mapping]
|
| 36 |
ransac_distance_threshold = 0.04
|
| 37 |
+
max_planes = 1
|
| 38 |
normal_angle_threshold_degrees = 35
|
| 39 |
normal_smoothing_kernel = 5
|
| 40 |
min_plane_pixels = 1500
|
visualizer.hf.toml
CHANGED
|
@@ -17,10 +17,13 @@ enable_depth_estimation = true
|
|
| 17 |
enable_moge_geometry = true
|
| 18 |
enable_plane_fit = true
|
| 19 |
enable_multi_plane_surfaces = true
|
| 20 |
-
enable_wall_segments =
|
| 21 |
-
enable_intrinsic_shading =
|
| 22 |
-
enable_shading_transfer =
|
|
|
|
|
|
|
| 23 |
enable_sam_refinement = false
|
|
|
|
| 24 |
debug_artifacts_enabled = false
|
| 25 |
inference_max_dimension = 1024
|
| 26 |
conversion_target_ms = 30000
|
|
@@ -28,7 +31,7 @@ data_dir = "data"
|
|
| 28 |
|
| 29 |
[surface_mapping]
|
| 30 |
ransac_distance_threshold = 0.04
|
| 31 |
-
max_planes =
|
| 32 |
normal_angle_threshold_degrees = 35
|
| 33 |
normal_smoothing_kernel = 5
|
| 34 |
min_plane_pixels = 1500
|
|
|
|
| 17 |
enable_moge_geometry = true
|
| 18 |
enable_plane_fit = true
|
| 19 |
enable_multi_plane_surfaces = true
|
| 20 |
+
enable_wall_segments = false
|
| 21 |
+
enable_intrinsic_shading = false
|
| 22 |
+
enable_shading_transfer = false
|
| 23 |
+
enable_fast_shadow_transfer = true
|
| 24 |
+
fast_shadow_max_dimension = 640
|
| 25 |
enable_sam_refinement = false
|
| 26 |
+
enable_floor_mask_cleanup = true
|
| 27 |
debug_artifacts_enabled = false
|
| 28 |
inference_max_dimension = 1024
|
| 29 |
conversion_target_ms = 30000
|
|
|
|
| 31 |
|
| 32 |
[surface_mapping]
|
| 33 |
ransac_distance_threshold = 0.04
|
| 34 |
+
max_planes = 1
|
| 35 |
normal_angle_threshold_degrees = 35
|
| 36 |
normal_smoothing_kernel = 5
|
| 37 |
min_plane_pixels = 1500
|
visualizer.local.toml
CHANGED
|
@@ -13,9 +13,11 @@ sam2_checkpoint = ""
|
|
| 13 |
enable_depth_estimation = false
|
| 14 |
enable_plane_fit = true
|
| 15 |
enable_multi_plane_surfaces = true
|
| 16 |
-
enable_wall_segments =
|
| 17 |
enable_intrinsic_shading = false
|
| 18 |
-
enable_shading_transfer =
|
|
|
|
|
|
|
| 19 |
enable_sam_refinement = false
|
| 20 |
warm_start_models = true
|
| 21 |
inference_max_dimension = 1024
|
|
|
|
| 13 |
enable_depth_estimation = false
|
| 14 |
enable_plane_fit = true
|
| 15 |
enable_multi_plane_surfaces = true
|
| 16 |
+
enable_wall_segments = false
|
| 17 |
enable_intrinsic_shading = false
|
| 18 |
+
enable_shading_transfer = false
|
| 19 |
+
enable_fast_shadow_transfer = true
|
| 20 |
+
fast_shadow_max_dimension = 640
|
| 21 |
enable_sam_refinement = false
|
| 22 |
warm_start_models = true
|
| 23 |
inference_max_dimension = 1024
|