Files
Aislo/B04_PreProcess/B04_PreProcess_Engine_Ground.py
T
eomsangdonandClaude Opus 5.5 3a29e0480f feat(642): 점진 TIN(PTD) 내장 지면 필터 — 분류 없는 LAS 기본 필터 ptd · 화면 이름 「점진 TIN」
- 새 B04_PreProcess_Engine_Filter_PTD.py — 0.5 m 칸 최저 후보 · 시작 간격(기본 10 m) 칸 최저 씨앗 · 자료 가장자리 1/4 간격 씨앗 · 삼각형마다 문턱(장면 셋 평지 3°·0.3 m / 완경사 6°·0.5 m / 급경사 10°·0.7 m · 기본 급경사) 안 가장 가까운 후보를 더함 · 굵게 → 가늘게 다짐(후보가 모두 면 위로 뜬 칸에 반 간격 씨앗 · 2.5 m 까지) · 외딴 가시 · 잡점 꼭짓점 걷음 · 마지막 판정 = 면 아래 최대 거리 · 면 위 0.2 m · numpy · scipy 만 · 4,900 만 점 덩이 처리
- 삼각형 찾기 · 무게 직접 셈 — scipy find_simplex · transform 이 이 PC 에서 BLAS 스레드 다툼으로 수십 배 느림
- 필터 목록 ptd 한 줄(Engine_Ground · SURFACE_MODEL_SOURCE_FILTERS · 표본기 SurfaceFilter · B04 드롭다운) · SURFACE_AUTO_FALLBACK_FILTER = ptd(요구 559) · 설정 SURFACE_PTD_SCENE · SURFACE_PTD_SEED_SPACING_M
- 용화(분류 숨김) 업체 분류 대비 맞음 · 놓침 · 잘못 넣음 = CSF 55.1 · 44.9 · 12.2 → PTD 88.6 · 11.4 · 12.0 % · 급경사 놓침 60.9 → 19.3 % · 180 초 · +1.2 GB
- 새 지킴 시험 test_642_ptd_filter(합성 비탈 + 나무 · 급경사 놓침 상한)
- 낡은 시험 고침 test_b04_ground_filters — 분류 없을 때 자동 필터가 csf → ptd(요구 559 사용자 확정)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 23:02:31 +09:00

96 lines
3.7 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_PTD import filter_ptd
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,
"ptd": filter_ptd,
"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는 분류가 있어도 함께 만든다** — csf 처리 결과를 눈으로 검증할 수
있어야 하기 때문이다 (2026-09-01 사용자 확정). 분류가 없으면 csf 하나만 남는다.
"""
usable = usable_conditional_filters(structured_data)
return [*usable[:1], 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