nodeslicer/core/pdf_exporter/depth_rasterizer.py
2026-07-31 14:25:38 +03:00

37 lines
1.3 KiB
Python

"""
SA2 Performance Profiling & Vector Edge Debug Export Module.
Saves input vector edge debug data and cProfile statistics when debug_sa2 is enabled.
"""
from typing import Any
import numpy as np
from numpy.typing import NDArray
def save_sa2_debug_data(
edges: NDArray[np.float64] | None,
obj_name: str,
filepath: str | Any
) -> None:
"""
Saves debug edge vector data files in the same folder as the output PDF:
- {name}_sa2_debug_edges.txt (Input 2D edge vector coordinates fed to SA2)
"""
if filepath is None:
return
from pathlib import Path
pdf_path = Path(filepath)
out_dir = pdf_path.parent
out_dir.mkdir(parents=True, exist_ok=True)
clean_name = pdf_path.stem if pdf_path.suffix.lower() == ".pdf" else str(obj_name)
base_prefix = out_dir / f"{clean_name}_sa2_debug"
# Save input edge coordinates as text file
if edges is not None and len(edges) > 0:
txt_file = f"{base_prefix}_edges.txt"
with open(txt_file, "w") as f:
f.write(f"# SA2 Input 2D Edges Debug for {clean_name}\n")
f.write(f"# Format: x1 y1 x2 y2\n")
for segment in edges:
(x1, y1), (x2, y2) = segment[0], segment[1]
f.write(f"{x1:.4f} {y1:.4f} {x2:.4f} {y2:.4f}\n")