github-actions[bot] commited on
Commit
a0e83d6
·
1 Parent(s): fbb8e8b

Automated Deploy: 76c6a0d09cac4517c9f40419cbd71b9296afedc8

Browse files
app.py CHANGED
@@ -7,7 +7,7 @@ from fastapi.staticfiles import StaticFiles
7
 
8
  from config.paths import MATERIAL_DIR, UPLOAD_DIR
9
  from models.loader import warm_start_models
10
- from routes import floor_direction, gemini, harmonization, materials, qa, segmentation, viz2d
11
 
12
  app = FastAPI()
13
 
@@ -25,7 +25,6 @@ app.include_router(gemini.router)
25
  app.include_router(materials.router)
26
  app.include_router(segmentation.router)
27
  app.include_router(floor_direction.router)
28
- app.include_router(harmonization.router)
29
 
30
 
31
  @app.on_event("startup")
 
7
 
8
  from config.paths import MATERIAL_DIR, UPLOAD_DIR
9
  from models.loader import warm_start_models
10
+ from routes import floor_direction, gemini, materials, qa, segmentation, viz2d
11
 
12
  app = FastAPI()
13
 
 
25
  app.include_router(materials.router)
26
  app.include_router(segmentation.router)
27
  app.include_router(floor_direction.router)
 
28
 
29
 
30
  @app.on_event("startup")
requirements-base.txt CHANGED
@@ -13,6 +13,4 @@ tokenizers==0.20.3
13
  transformers==4.46.3
14
  uvicorn==0.34.2
15
  scipy
16
- diffusers>=0.30.0
17
- accelerate>=0.33.0
18
  git+https://github.com/compphoto/Intrinsic.git
 
13
  transformers==4.46.3
14
  uvicorn==0.34.2
15
  scipy
 
 
16
  git+https://github.com/compphoto/Intrinsic.git
requirements.txt CHANGED
@@ -19,7 +19,7 @@ h11==0.16.0
19
  hf-xet==1.1.2
20
  httpcore==1.0.9
21
  httpx==0.28.1
22
- huggingface-hub>=0.33.5,<2.0
23
  idna==3.10
24
  Jinja2==3.1.6
25
  kiwisolver==1.4.8
@@ -86,6 +86,4 @@ urllib3==2.4.0
86
  uvicorn==0.34.2
87
  websockets==15.0.1
88
  scipy
89
- diffusers>=0.30.0
90
- accelerate>=0.33.0
91
  git+https://github.com/compphoto/Intrinsic.git
 
19
  hf-xet==1.1.2
20
  httpcore==1.0.9
21
  httpx==0.28.1
22
+ huggingface-hub==0.32.0
23
  idna==3.10
24
  Jinja2==3.1.6
25
  kiwisolver==1.4.8
 
86
  uvicorn==0.34.2
87
  websockets==15.0.1
88
  scipy
 
 
89
  git+https://github.com/compphoto/Intrinsic.git
routes/viz2d.py CHANGED
@@ -1,11 +1,12 @@
1
  """Viz2D conversion and job management routes."""
2
 
 
3
  import time
4
  import uuid
5
  from datetime import datetime, timezone
6
  from pathlib import Path
7
 
8
- from fastapi import APIRouter, BackgroundTasks, File, Response, UploadFile
9
 
10
  from config.paths import JOB_DIR, UPLOAD_DIR
11
  from config.runtime import CONVERSION_TARGET_MS, DEBUG_ARTIFACTS_ENABLED
@@ -71,6 +72,27 @@ async def convert_to_viz2d(background_tasks: BackgroundTasks, file: UploadFile =
71
  return job
72
 
73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  @router.get("/jobs/{job_id}")
75
  async def viz2d_job_status(job_id: str):
76
  return read_job(job_id)
 
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
 
72
  return job
73
 
74
 
75
+ @router.get("/jobs")
76
+ async def viz2d_list_jobs(
77
+ status: str | None = Query(None, description="Filter by status: COMPLETED, FAILED, PROCESSING"),
78
+ limit: int = Query(50, ge=1, le=200),
79
+ offset: int = Query(0, ge=0),
80
+ ):
81
+ """List all jobs, newest first."""
82
+ job_files = sorted(JOB_DIR.glob("*.json"), key=lambda p: p.stat().st_mtime, reverse=True)
83
+ jobs = []
84
+ for path in job_files:
85
+ try:
86
+ job = json.loads(path.read_text())
87
+ except (json.JSONDecodeError, OSError):
88
+ continue
89
+ if status and job.get("status") != status:
90
+ continue
91
+ jobs.append(job)
92
+ total = len(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)
services/jobs/conversion.py CHANGED
@@ -170,6 +170,7 @@ 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["outputFormat"] = "split-vizbundle"
174
  write_job(job)
175
  print(f"\n[JOB {job_id[:8]}] HD conversion completed in {elapsed_ms / 1000:.2f}s\n", flush=True)
 
170
  job["durationMs"] = round(elapsed_ms)
171
  job["modelName"] = bundle.get("modelName")
172
  job["models"] = bundle.get("models")
173
+ job["pipelineStages"] = bundle.get("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)
services/lighting/intrinsic.py CHANGED
@@ -135,83 +135,62 @@ def align_intrinsic_shading_to_luminance(
135
  # Intrinsic lighting maps
136
  # ---------------------------------------------------------------------------
137
 
138
- _INTRINSIC_MAX_DIM = 512 # Intrinsic model runs at reduced resolution for speed
139
-
140
-
141
  def build_intrinsic_lighting_maps(
142
  img_np: np.ndarray,
143
  surface_mask: np.ndarray,
144
  replaced_material_mask: np.ndarray | None = None,
145
  ) -> dict[str, np.ndarray | None] | None:
146
- import cv2
147
  if not surface_mask.any() or intrinsic_models is None:
148
  return None
149
 
150
  try:
151
- orig_h, orig_w = img_np.shape[:2]
152
-
153
- # Downscale for faster intrinsic inference
154
- largest = max(orig_h, orig_w)
155
- if largest > _INTRINSIC_MAX_DIM:
156
- scale = _INTRINSIC_MAX_DIM / float(largest)
157
- new_w = max(1, int(round(orig_w * scale)))
158
- new_h = max(1, int(round(orig_h * scale)))
159
- img_s = cv2.resize(img_np, (new_w, new_h), interpolation=cv2.INTER_AREA)
160
- mask_s = cv2.resize(surface_mask.astype(np.uint8), (new_w, new_h), interpolation=cv2.INTER_NEAREST)
161
- repl_s = cv2.resize(replaced_material_mask.astype(np.uint8), (new_w, new_h), interpolation=cv2.INTER_NEAREST) if replaced_material_mask is not None else None
162
- else:
163
- img_s, mask_s, repl_s = img_np, surface_mask, replaced_material_mask
164
-
165
- img_float = img_s.astype(np.float32) / 255.0
166
  from intrinsic.pipeline import run_pipeline
167
  results = run_pipeline(intrinsic_models, img_float, device=str(device))
168
  shading = extract_intrinsic_shading(results)
169
  if shading is None:
170
  return None
171
 
172
- relative = normalize_relative_shading(shading, mask_s)
173
  if relative is None:
174
  return None
175
- relative, alignment = align_intrinsic_shading_to_luminance(relative, img_s, mask_s)
176
- smoothed = smooth_relative_lighting(relative, mask_s)
177
  if smoothed is None:
178
  return None
179
 
180
- luminance_maps = build_luminance_lighting_maps(img_s, mask_s, repl_s)
 
 
 
 
181
  if luminance_maps and luminance_maps.get("shadeMap") is not None:
182
  observed = decode_relative_map(
183
  luminance_maps["shadeMap"],
184
  SHADE_MAP_MIN,
185
  SHADE_MAP_MAX,
186
  )
187
- smoothed = preserve_observed_lighting(smoothed, observed, mask_s)
188
  alignment = f"{alignment}+observed-lighting"
189
- smoothed = suppress_replaced_material_lighting(smoothed, mask_s, repl_s)
 
 
 
 
190
  print(f"[LIGHTING] intrinsic shading alignment={alignment}", flush=True)
191
 
192
  from services.lighting.showroom import build_showroom_shade_map_from_relative
193
  from services.lighting.reflection import build_reflection_map
194
 
195
- shade_encoded = encode_relative_map(smoothed, SHADE_MAP_MIN, SHADE_MAP_MAX)
196
- showroom_encoded = build_showroom_shade_map_from_relative(smoothed, mask_s)
197
- reflection_encoded = build_reflection_map(img_s, mask_s, smoothed, repl_s)
198
-
199
- # Upscale back to original resolution if we downscaled
200
- if largest > _INTRINSIC_MAX_DIM:
201
- def _up(arr):
202
- if arr is None:
203
- return None
204
- if arr.shape[0] == orig_h and arr.shape[1] == orig_w:
205
- return arr
206
- return cv2.resize(arr, (orig_w, orig_h), interpolation=cv2.INTER_LINEAR)
207
- shade_encoded = _up(shade_encoded)
208
- showroom_encoded = _up(showroom_encoded)
209
- reflection_encoded = _up(reflection_encoded)
210
-
211
  return {
212
- "shadeMap": shade_encoded,
213
- "showroomShadeMap": showroom_encoded,
214
- "reflectionMap": reflection_encoded,
 
 
 
 
 
215
  }
216
  except Exception as exc:
217
  print(f"Intrinsic shading decomposition failed: {exc}. Falling back to default luminance shading.", flush=True)
 
135
  # Intrinsic lighting maps
136
  # ---------------------------------------------------------------------------
137
 
 
 
 
138
  def build_intrinsic_lighting_maps(
139
  img_np: np.ndarray,
140
  surface_mask: np.ndarray,
141
  replaced_material_mask: np.ndarray | None = None,
142
  ) -> dict[str, np.ndarray | None] | None:
 
143
  if not surface_mask.any() or intrinsic_models is None:
144
  return None
145
 
146
  try:
147
+ img_float = img_np.astype(np.float32) / 255.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
  from intrinsic.pipeline import run_pipeline
149
  results = run_pipeline(intrinsic_models, img_float, device=str(device))
150
  shading = extract_intrinsic_shading(results)
151
  if shading is None:
152
  return None
153
 
154
+ relative = normalize_relative_shading(shading, surface_mask)
155
  if relative is None:
156
  return None
157
+ relative, alignment = align_intrinsic_shading_to_luminance(relative, img_np, surface_mask)
158
+ smoothed = smooth_relative_lighting(relative, surface_mask)
159
  if smoothed is None:
160
  return None
161
 
162
+ luminance_maps = build_luminance_lighting_maps(
163
+ img_np,
164
+ surface_mask,
165
+ replaced_material_mask,
166
+ )
167
  if luminance_maps and luminance_maps.get("shadeMap") is not None:
168
  observed = decode_relative_map(
169
  luminance_maps["shadeMap"],
170
  SHADE_MAP_MIN,
171
  SHADE_MAP_MAX,
172
  )
173
+ smoothed = preserve_observed_lighting(smoothed, observed, surface_mask)
174
  alignment = f"{alignment}+observed-lighting"
175
+ smoothed = suppress_replaced_material_lighting(
176
+ smoothed,
177
+ surface_mask,
178
+ replaced_material_mask,
179
+ )
180
  print(f"[LIGHTING] intrinsic shading alignment={alignment}", flush=True)
181
 
182
  from services.lighting.showroom import build_showroom_shade_map_from_relative
183
  from services.lighting.reflection import build_reflection_map
184
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
185
  return {
186
+ "shadeMap": encode_relative_map(smoothed, SHADE_MAP_MIN, SHADE_MAP_MAX),
187
+ "showroomShadeMap": build_showroom_shade_map_from_relative(smoothed, surface_mask),
188
+ "reflectionMap": build_reflection_map(
189
+ img_np,
190
+ surface_mask,
191
+ smoothed,
192
+ replaced_material_mask,
193
+ ),
194
  }
195
  except Exception as exc:
196
  print(f"Intrinsic shading decomposition failed: {exc}. Falling back to default luminance shading.", flush=True)
services/lighting/shading.py CHANGED
@@ -100,43 +100,6 @@ def suppress_replaced_material_lighting(
100
  # Luminance-based lighting maps
101
  # ---------------------------------------------------------------------------
102
 
103
- _LIGHTING_MAX_DIM = 800 # Compute lighting at this resolution for speed
104
-
105
-
106
- def _downscale_for_lighting(
107
- img_np: np.ndarray,
108
- surface_mask: np.ndarray,
109
- replaced_material_mask: np.ndarray | None,
110
- ):
111
- """Downscale inputs if the image exceeds _LIGHTING_MAX_DIM.
112
-
113
- Returns (img, mask, replaced, scale) — scale is 1.0 when no resize needed.
114
- """
115
- h, w = img_np.shape[:2]
116
- largest = max(h, w)
117
- if largest <= _LIGHTING_MAX_DIM:
118
- return img_np, surface_mask, replaced_material_mask, 1.0
119
-
120
- scale = _LIGHTING_MAX_DIM / float(largest)
121
- new_w = max(1, int(round(w * scale)))
122
- new_h = max(1, int(round(h * scale)))
123
- img_s = cv2.resize(img_np, (new_w, new_h), interpolation=cv2.INTER_AREA)
124
- mask_s = cv2.resize(surface_mask.astype(np.uint8), (new_w, new_h), interpolation=cv2.INTER_NEAREST)
125
- repl_s = None
126
- if replaced_material_mask is not None:
127
- repl_s = cv2.resize(replaced_material_mask.astype(np.uint8), (new_w, new_h), interpolation=cv2.INTER_NEAREST)
128
- return img_s, mask_s, repl_s, scale
129
-
130
-
131
- def _upscale_map(encoded: np.ndarray | None, target_h: int, target_w: int) -> np.ndarray | None:
132
- """Upscale an encoded uint8 map back to original resolution."""
133
- if encoded is None:
134
- return None
135
- if encoded.shape[0] == target_h and encoded.shape[1] == target_w:
136
- return encoded
137
- return cv2.resize(encoded, (target_w, target_h), interpolation=cv2.INTER_LINEAR)
138
-
139
-
140
  def build_luminance_lighting_maps(
141
  img_np: np.ndarray,
142
  surface_mask: np.ndarray,
@@ -145,15 +108,8 @@ def build_luminance_lighting_maps(
145
  if not surface_mask.any():
146
  return None
147
 
148
- orig_h, orig_w = surface_mask.shape[:2]
149
-
150
- # Downscale for speed — shade/reflection maps are low-frequency signals
151
- img_s, mask_s, repl_s, scale = _downscale_for_lighting(
152
- img_np, surface_mask, replaced_material_mask,
153
- )
154
-
155
- mask = mask_s.astype(np.uint8)
156
- luminance = image_linear_luminance(img_s)
157
  h, w = mask.shape[:2]
158
  floor_values = luminance[mask > 0]
159
  if floor_values.size < max(256, int(h * w * 0.002)):
@@ -170,7 +126,7 @@ def build_luminance_lighting_maps(
170
  relative = suppress_replaced_material_lighting(
171
  relative,
172
  mask,
173
- repl_s,
174
  )
175
  shade = smooth_relative_lighting(relative, mask)
176
  if shade is None:
@@ -179,25 +135,15 @@ def build_luminance_lighting_maps(
179
  from services.lighting.showroom import build_showroom_shade_map_from_relative
180
  from services.lighting.reflection import build_reflection_map
181
 
182
- shade_encoded = encode_relative_map(shade, SHADE_MAP_MIN, SHADE_MAP_MAX)
183
- showroom_encoded = build_showroom_shade_map_from_relative(shade, mask)
184
- reflection_encoded = build_reflection_map(
185
- img_s,
186
- mask_s,
187
- None,
188
- repl_s,
189
- )
190
-
191
- # Upscale back to original resolution if we downscaled
192
- if scale < 1.0:
193
- shade_encoded = _upscale_map(shade_encoded, orig_h, orig_w)
194
- showroom_encoded = _upscale_map(showroom_encoded, orig_h, orig_w)
195
- reflection_encoded = _upscale_map(reflection_encoded, orig_h, orig_w)
196
-
197
  return {
198
- "shadeMap": shade_encoded,
199
- "showroomShadeMap": showroom_encoded,
200
- "reflectionMap": reflection_encoded,
 
 
 
 
 
201
  }
202
 
203
 
 
100
  # Luminance-based lighting maps
101
  # ---------------------------------------------------------------------------
102
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  def build_luminance_lighting_maps(
104
  img_np: np.ndarray,
105
  surface_mask: np.ndarray,
 
108
  if not surface_mask.any():
109
  return None
110
 
111
+ mask = surface_mask.astype(np.uint8)
112
+ luminance = image_linear_luminance(img_np)
 
 
 
 
 
 
 
113
  h, w = mask.shape[:2]
114
  floor_values = luminance[mask > 0]
115
  if floor_values.size < max(256, int(h * w * 0.002)):
 
126
  relative = suppress_replaced_material_lighting(
127
  relative,
128
  mask,
129
+ replaced_material_mask,
130
  )
131
  shade = smooth_relative_lighting(relative, mask)
132
  if shade is None:
 
135
  from services.lighting.showroom import build_showroom_shade_map_from_relative
136
  from services.lighting.reflection import build_reflection_map
137
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  return {
139
+ "shadeMap": encode_relative_map(shade, SHADE_MAP_MIN, SHADE_MAP_MAX),
140
+ "showroomShadeMap": build_showroom_shade_map_from_relative(shade, mask),
141
+ "reflectionMap": build_reflection_map(
142
+ img_np,
143
+ surface_mask,
144
+ None,
145
+ replaced_material_mask,
146
+ ),
147
  }
148
 
149
 
services/pipeline/builder.py CHANGED
@@ -150,36 +150,9 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
150
  if d:
151
  debug_stages.record_surface(d, img_np, floor_mask, surface_mask, occlusion_mask, edge_metadata, el)
152
 
153
- # --- UV Mapping + Lighting (parallel — both depend only on surface_mask) ---
154
  if progress_callback:
155
  progress_callback(PipelinePhase.SURFACE_MAPPING, 0)
156
- progress_callback(PipelinePhase.LIGHTING, 0)
157
-
158
- # Kick off lighting in a background thread while UV mapping runs on main thread
159
- from concurrent.futures import ThreadPoolExecutor as _LightPool
160
-
161
- def _compute_lighting():
162
- _lighting_maps = None
163
- _lighting_source, _intrinsic_used = None, False
164
- if ENABLE_SHADING_TRANSFER and ENABLE_INTRINSIC_SHADING:
165
- if state.intrinsic_models is None:
166
- _load_intrinsic_model()
167
- if state.intrinsic_models is not None:
168
- _lighting_maps = build_intrinsic_lighting_maps(img_np, surface_mask, replaced_material_mask)
169
- if _lighting_maps and _lighting_maps.get("shadeMap") is not None:
170
- from config.models import INTRINSIC_MODEL_VERSION
171
- _lighting_source, _intrinsic_used = f"intrinsic-{INTRINSIC_MODEL_VERSION}", True
172
- if ENABLE_SHADING_TRANSFER and (not _lighting_maps or _lighting_maps.get("shadeMap") is None):
173
- _lighting_maps = build_luminance_lighting_maps(img_np, surface_mask, replaced_material_mask)
174
- if _lighting_maps and _lighting_maps.get("shadeMap") is not None:
175
- _lighting_source = "luminance"
176
- return _lighting_maps, _lighting_source, _intrinsic_used
177
-
178
- t_lighting_start = time.perf_counter()
179
- _light_pool = _LightPool(max_workers=1)
180
- _lighting_future = _light_pool.submit(_compute_lighting)
181
-
182
- # UV mapping runs on main thread concurrently with lighting
183
  t0 = time.perf_counter()
184
  surface_mapping = build_surface_uv_mapping(surface_mask, surface_indices, geometry)
185
  use_surface_uv = bool(surface_mapping and surface_mapping.get("useSurfaceUv"))
@@ -192,6 +165,32 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
192
  if progress_callback:
193
  progress_callback(PipelinePhase.SURFACE_MAPPING, 100)
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  wall_mask = seg_class_mask(seg_map, class_ids({"wall"}))
196
  wall_components, wall_protected_mask = (
197
  wall_surface_components(seg_map, min_floor_area, geometry) if ENABLE_WALL_SEGMENTS else ([], np.zeros_like(wall_mask)))
@@ -211,6 +210,9 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
211
  for _, cm in wall_components:
212
  wall_lighting_futures.append(wall_executor.submit(_compute_wall_lighting, cm))
213
 
 
 
 
214
  # --- Floor direction ---
215
  if progress_callback:
216
  progress_callback(PipelinePhase.DIRECTION, 0)
@@ -237,19 +239,6 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
237
  if progress_callback:
238
  progress_callback(PipelinePhase.DIRECTION, 100)
239
 
240
-
241
- lighting_maps, lighting_source, intrinsic_lighting_used = _lighting_future.result()
242
- _light_pool.shutdown(wait=False)
243
- shade_map, showroom_shade_map, reflection_map = None, None, None
244
- if lighting_maps:
245
- shade_map, showroom_shade_map, reflection_map = lighting_maps.get("shadeMap"), lighting_maps.get("showroomShadeMap"), lighting_maps.get("reflectionMap")
246
- shade_statistics = lighting_map_statistics(shade_map, surface_mask)
247
- _log_stage("Lighting", t_lighting_start, f"source={lighting_source}")
248
- if d:
249
- debug_stages.record_lighting(d, shade_map, showroom_shade_map, reflection_map, surface_mask, lighting_source, (time.perf_counter() - t_lighting_start) * 1000)
250
- if progress_callback:
251
- progress_callback(PipelinePhase.LIGHTING, 100)
252
-
253
  # Collect pre-computed wall lighting results
254
  wall_lighting_results: list[dict | None] = []
255
  if wall_executor:
@@ -299,8 +288,17 @@ def build_segmentation_bundle(contents: bytes, debug: PipelineDebugCapture | Non
299
  d.complete(total_elapsed * 1000)
300
  pixels_b64 = _pixels_b64_future.result()
301
  _img_pool.shutdown(wait=False)
 
 
 
 
 
 
 
 
302
  return {"width": w, "height": h, "pixels": pixels_b64, "segments": segments,
303
- "modelName": models["segmentation"]["name"], "models": models}
 
304
 
305
 
306
  def _print_pipeline_summary(
 
150
  if d:
151
  debug_stages.record_surface(d, img_np, floor_mask, surface_mask, occlusion_mask, edge_metadata, el)
152
 
153
+ # --- Surface UV mapping ---
154
  if progress_callback:
155
  progress_callback(PipelinePhase.SURFACE_MAPPING, 0)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156
  t0 = time.perf_counter()
157
  surface_mapping = build_surface_uv_mapping(surface_mask, surface_indices, geometry)
158
  use_surface_uv = bool(surface_mapping and surface_mapping.get("useSurfaceUv"))
 
165
  if progress_callback:
166
  progress_callback(PipelinePhase.SURFACE_MAPPING, 100)
167
 
168
+ # --- Lighting ---
169
+ if progress_callback:
170
+ progress_callback(PipelinePhase.LIGHTING, 0)
171
+ t0 = time.perf_counter()
172
+ lighting_maps, shade_map, showroom_shade_map, reflection_map = None, None, None, None
173
+ lighting_source, intrinsic_lighting_used = None, False
174
+ if ENABLE_SHADING_TRANSFER and ENABLE_INTRINSIC_SHADING:
175
+ if state.intrinsic_models is None:
176
+ _load_intrinsic_model()
177
+ if state.intrinsic_models is not None:
178
+ lighting_maps = build_intrinsic_lighting_maps(img_np, surface_mask, replaced_material_mask)
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:
185
+ lighting_source = "luminance"
186
+ if lighting_maps:
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
+ _log_stage("Lighting", t0, f"source={lighting_source}")
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, wall_protected_mask = (
196
  wall_surface_components(seg_map, min_floor_area, geometry) if ENABLE_WALL_SEGMENTS else ([], np.zeros_like(wall_mask)))
 
210
  for _, cm in wall_components:
211
  wall_lighting_futures.append(wall_executor.submit(_compute_wall_lighting, cm))
212
 
213
+ if progress_callback:
214
+ progress_callback(PipelinePhase.LIGHTING, 100)
215
+
216
  # --- Floor direction ---
217
  if progress_callback:
218
  progress_callback(PipelinePhase.DIRECTION, 0)
 
239
  if progress_callback:
240
  progress_callback(PipelinePhase.DIRECTION, 100)
241
 
 
 
 
 
 
 
 
 
 
 
 
 
 
242
  # Collect pre-computed wall lighting results
243
  wall_lighting_results: list[dict | None] = []
244
  if wall_executor:
 
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
294
+ ]
295
+ pipeline_stages.append({
296
+ "name": "TOTAL", "elapsed_s": round(total_elapsed, 3), "detail": f"{w}x{h}",
297
+ })
298
+
299
  return {"width": w, "height": h, "pixels": pixels_b64, "segments": segments,
300
+ "modelName": models["segmentation"]["name"], "models": models,
301
+ "pipelineStages": pipeline_stages}
302
 
303
 
304
  def _print_pipeline_summary(