260705_2
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
"""B04 지면 필터 오케스트레이션.
|
||||
|
||||
구조화된 포인트클라우드(structured.npz)에 대해 grid_min_z/csf/pmf/ransac
|
||||
필터를 실행하여 지면 마스크 딕셔너리를 만든다. 필터 선택은 config의
|
||||
source_filters를 따른다.
|
||||
"""
|
||||
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
|
||||
from B04_wf1_Surface.B04_wf1_Surface_Engine_Filter_CSF import filter_csf
|
||||
from B04_wf1_Surface.B04_wf1_Surface_Engine_Filter_Grid import filter_grid_min_z
|
||||
from B04_wf1_Surface.B04_wf1_Surface_Engine_Filter_PMF import filter_pmf
|
||||
from B04_wf1_Surface.B04_wf1_Surface_Engine_Filter_RANSAC import filter_ransac
|
||||
|
||||
# 필터 키 → 함수 매핑
|
||||
_FILTERS = {
|
||||
"grid_min_z": filter_grid_min_z,
|
||||
"csf": filter_csf,
|
||||
"pmf": filter_pmf,
|
||||
"ransac": filter_ransac,
|
||||
}
|
||||
|
||||
|
||||
def available_filters() -> tuple[str, ...]:
|
||||
return tuple(_FILTERS.keys())
|
||||
|
||||
|
||||
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
|
||||
Reference in New Issue
Block a user