fix(B04): NURBS 곡면 발산 — 평활계수 완화·표고 범위 방어·등고선 레벨 상한 순서
csf-nurbs 등고선 캐시가 Maximum allowed size exceeded로 실패하던 문제. 평활계수 s가 제어점당 잔차제곱 0.01(RMS 0.1m)로 너무 빡빡해 FITPACK이 제어점 수(122x113)보다 많은 knot(126x117)을 밀어넣고 계수가 발산했다. 실측 표고: csf 1e105, grid_min_z 1e10. grid_min_z는 footprint 안쪽만 보고 z 범위를 잡아 조용히 통과하고 있었다. - ModelContext에 fit_nurbs_spline/evaluate_nurbs_spline 신설. 모델 빌더와 등고선 엔진이 같은 곡면을 각각 만들면서 s 식이 두 곳에 중복돼 있었다. - NURBS_RESIDUAL_PER_CONTROL_POINT = 1.0 (RMS 1m). knot이 17~35로 떨어지고 세 지면 필터 모두 데이터 표고 범위 안에 머문다. NURBS는 평활 곡면 표현이라 이 정도 완화가 맞다. - 평가 결과가 제어 표고 범위(±50% 여유)를 벗어나면 잘라내고 경고를 남긴다. 방치하면 float32 캐스팅에서 inf가 되어 프리뷰 색상(nan)과 등고선까지 번진다. - extract_contours_from_grid: 레벨 수 상한 검사를 np.arange 앞으로 옮겼다. 뒤에 있어서 상한이 무용지물이었다 — 배열이 만들어지기 전에 터진다. 확인: 3필터 모두 곡면이 제어 표고 범위 내(grid_min_z 503.6~573.1, csf 504.7~552.3, pmf 504.6~551.8), 등고선 0.55~1.64초에 정상 산출. 표고 범위 1e12 격자도 예외 없이 처리. tmp/tests 59건 통과. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,7 @@ from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
from scipy.interpolate import RBFInterpolator, RectBivariateSpline
|
||||
from scipy.interpolate import RBFInterpolator
|
||||
from scipy.spatial import Delaunay
|
||||
|
||||
from B04_PreProcess.B04_PreProcess_Engine_ModelContext import (
|
||||
@@ -17,6 +17,8 @@ from B04_PreProcess.B04_PreProcess_Engine_ModelContext import (
|
||||
artifact_size,
|
||||
atomic_npz,
|
||||
clip_and_compact_mesh,
|
||||
evaluate_nurbs_spline,
|
||||
fit_nurbs_spline,
|
||||
grid_faces,
|
||||
grid_vertices,
|
||||
with_footprint,
|
||||
@@ -125,18 +127,13 @@ def build_nurbs(
|
||||
control_resolution = max(patch_size / max(controls - 1, 1), 0.25)
|
||||
x_control, y_control, z_control = context.grid(control_resolution)
|
||||
progress(30)
|
||||
spline = RectBivariateSpline(
|
||||
y_control,
|
||||
x_control,
|
||||
z_control,
|
||||
kx=min(degree, len(y_control) - 1),
|
||||
ky=min(degree, len(x_control) - 1),
|
||||
s=float(len(x_control) * len(y_control)) * 0.01,
|
||||
)
|
||||
spline, z_range = fit_nurbs_spline(x_control, y_control, z_control, degree)
|
||||
x_preview, y_preview, _ = context.preview_grid(
|
||||
float(context.config["dtm_grid_resolution_meters"])
|
||||
)
|
||||
z_preview = np.asarray(spline(y_preview, x_preview), dtype=np.float32)
|
||||
z_preview = evaluate_nurbs_spline(spline, y_preview, x_preview, z_range, stem).astype(
|
||||
np.float32
|
||||
)
|
||||
progress(65)
|
||||
vertices = grid_vertices(x_preview, y_preview, z_preview)
|
||||
faces = grid_faces(len(y_preview), len(x_preview))
|
||||
|
||||
Reference in New Issue
Block a user