지면 필터를 고쳐 지면점이 9~26배 늘자, 필터 전체 x 표현 전체를 미리 만드는 자동 전처리가 감당 못 할 만큼 길어졌다(용화 기준 15~20 모델). 산출물 대부분은 아무도 열어 보지 않는다. - 자동 전처리는 기본 필터 1종 x SURFACE_AUTO_METHODS(dtm) 만 만든다. 스무딩 유무 두 벌은 기존대로 같이 나온다. - 기본 필터는 고정값이 아니라 입력 LAS를 보고 정한다 — 지면분류(class 2)가 있으면 classification, 없으면 csf. csf는 분류 없는 LAS를 필터링하기 위한 수단이므로 그때만 쓴다. - 관리자가 B04 드롭다운을 바꾸면 그 조합이 이미 저장돼 있는지 보고, 없으면 모달로 물은 뒤 그 조합만 계산해 영구 저장한다. 취소하면 드롭다운을 되돌린다. 이미 있으면 묻지 않고 저장된 데이터를 그대로 쓴다. - config_signature에서 source_filters·precompute를 뺀다. 이 둘은 "무엇을 만들지"를 고르는 값이라 서명에 넣으면 조합을 바꿀 때마다 manifest가 통째로 폐기돼 이전에 만들어 둔 조합이 사라진다. - analyzeSurface가 API_ANALYSIS_TIMEOUT_MS를 쓴다 — 기본 30초로는 조합 하나를 만드는 동안 abort 된다. detect_extra_filters()는 resolve_auto_source_filters()로 대체했다. 필터를 말없이 덧붙이는 대신, 자동 경로의 기본값을 정하는 판정으로 쓴다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
94 lines
3.5 KiB
Python
94 lines
3.5 KiB
Python
"""B04 지면 필터 오케스트레이션.
|
|
|
|
구조화된 포인트클라우드(structured.npz)에 대해 grid_min_z/csf/pmf/ransac
|
|
필터를 실행하여 지면 마스크 딕셔너리를 만든다. 필터 선택은 config의
|
|
source_filters를 따른다.
|
|
"""
|
|
|
|
from typing import Any
|
|
|
|
import numpy as np
|
|
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_Classification import (
|
|
filter_classification,
|
|
has_classified_ground,
|
|
)
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_CSF import filter_csf
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_Grid import filter_grid_min_z
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_PMF import filter_pmf
|
|
from B04_PreProcess.B04_PreProcess_Engine_Filter_RANSAC import filter_ransac
|
|
from config.config_system import SURFACE_AUTO_FALLBACK_FILTER
|
|
|
|
# 필터 키 → 함수 매핑
|
|
_FILTERS = {
|
|
"grid_min_z": filter_grid_min_z,
|
|
"csf": filter_csf,
|
|
"pmf": filter_pmf,
|
|
"ransac": filter_ransac,
|
|
"classification": filter_classification,
|
|
}
|
|
|
|
# LAS에 지면분류가 실제로 들어 있을 때만 쓰는 필터 (미분류 LAS에서는 마스크가 빈다)
|
|
_CONDITIONAL_FILTERS = {"classification": has_classified_ground}
|
|
|
|
|
|
def available_filters() -> tuple[str, ...]:
|
|
return tuple(_FILTERS.keys())
|
|
|
|
|
|
def usable_conditional_filters(
|
|
structured_data: dict[str, Any] | np.lib.npyio.NpzFile,
|
|
) -> list[str]:
|
|
"""이 LAS에서 실제로 쓸 수 있는 조건부 필터를 고른다 (드롭다운 노출용)."""
|
|
return [key for key, is_usable in _CONDITIONAL_FILTERS.items() if is_usable(structured_data)]
|
|
|
|
|
|
def resolve_auto_source_filters(
|
|
structured_data: dict[str, Any] | np.lib.npyio.NpzFile,
|
|
) -> list[str]:
|
|
"""자동 전처리가 만들 기본 필터를 입력 LAS를 보고 정한다.
|
|
|
|
업체가 이미 지면을 분류해 놨으면 그것을 쓴다 — 계산이 없고 품질도 가장 안정적이다.
|
|
csf는 분류가 없는 LAS의 지면을 추려내기 위한 수단이므로 그때만 쓴다
|
|
(2026-09-01 사용자 확정).
|
|
"""
|
|
usable = usable_conditional_filters(structured_data)
|
|
return usable[:1] if usable else [SURFACE_AUTO_FALLBACK_FILTER]
|
|
|
|
|
|
def run_ground_filter(
|
|
filter_key: str, structured_data: dict[str, Any] | np.lib.npyio.NpzFile
|
|
) -> np.ndarray:
|
|
"""단일 지면 필터를 실행해 불리언 마스크를 반환한다."""
|
|
if filter_key not in _FILTERS:
|
|
raise ValueError(f"알 수 없는 지면 필터입니다: {filter_key}")
|
|
return np.asarray(_FILTERS[filter_key](structured_data), dtype=bool)
|
|
|
|
|
|
def build_ground_masks(
|
|
structured_data: dict[str, Any] | np.lib.npyio.NpzFile,
|
|
filter_keys: tuple[str, ...] | list[str],
|
|
) -> dict[str, np.ndarray]:
|
|
"""지정한 필터들을 실행해 {filter_key: mask} 딕셔너리를 만든다."""
|
|
masks: dict[str, np.ndarray] = {}
|
|
for filter_key in filter_keys:
|
|
masks[filter_key] = run_ground_filter(filter_key, structured_data)
|
|
return masks
|
|
|
|
|
|
def summarize_masks(
|
|
structured_data: dict[str, Any] | np.lib.npyio.NpzFile,
|
|
masks: dict[str, np.ndarray],
|
|
) -> dict[str, dict[str, Any]]:
|
|
"""각 필터 마스크의 지면 포인트 수·비율 요약을 만든다."""
|
|
total = int(len(structured_data["xyz"]))
|
|
summary: dict[str, dict[str, Any]] = {}
|
|
for filter_key, mask in masks.items():
|
|
ground = int(np.count_nonzero(mask))
|
|
summary[filter_key] = {
|
|
"ground_point_count": ground,
|
|
"total_point_count": total,
|
|
"ground_ratio": round(ground / total, 4) if total else 0.0,
|
|
}
|
|
return summary
|