Files
2026-09-24 10:40:57 +08:00

19 lines
880 B
Python

"""Visible depth boundaries for orthographic CAD, never hidden triangle edges."""
import numpy as np
def shade_depth_edges(pixels,depth,pixels_per_mm):
edge=np.zeros(depth.shape,dtype=bool)
threshold=max(.02,2.5/max(float(pixels_per_mm),1e-9))
# Only compare adjacent visible surfaces. An occluded triangle never enters
# the depth buffer and cannot create a line through an opaque wall.
for dy,dx in [(0,1),(1,0)]:
a=depth[:depth.shape[0]-dy or None,:depth.shape[1]-dx or None]
b=depth[dy:,dx:]
valid=np.isfinite(a)&np.isfinite(b)
delta=np.zeros_like(a);np.subtract(a,b,out=delta,where=valid)
jump=valid & (np.abs(delta)>threshold)
edge[:depth.shape[0]-dy or None,:depth.shape[1]-dx or None] |= jump
result=pixels.copy()
result[edge]=(result[edge].astype(float)*.58).astype(np.uint8)
return result