code wiki / _hdl_build / nx_svmetrology.nx

nx_svmetrology.nx

buildroot/runtime/_hdl_build/nx_svmetrology.nx

18392 B371 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_svmetrology.nx -- THE MULTI-CUE SCALE SOLVER (debts 1785958292 + 1785957867; operator 2026-08-05: "be clever but stay reproducible"). Single-view metrology done as an OVER-DETERMINED system. THE DOCTRINE, IN CODE: never choose a reference. Every scale cue in a scene is an independent estimate of ONE unknown (camera height, in micrometres), so N cues leave N-1 degrees of freedom of VALIDATION. Fuse by inverse-variance weighting, then TEST the agreement with chi-square. Below threshold: report the interval. Above: REFUSE and NAME THE OUTLIER -- averaging away a disagreement hides the broken assumption that caused it (a partition is a claim; check the parts sum). A SINGLE CUE IS NEVER VALIDATED: 0 dof means there is nothing to check it against, and the organ says so out loud rather than reporting a confident number. GEOMETRY (Criminisi/Reid/Zisserman single-view metrology): for a flat ground plane the horizon sits at camera-optical-axis height, so for any object standing ON that plane, with no focal length needed: h_obj / h_cam = (y_base - y_top) / (y_base - y_horizon) LEVERAGE LAW (measured 2026-08-05): the error scales INVERSELY with (y_base - y_horizon), so a NEAR reference beats a distant one however crisp the distant one looks. The organ reports that denominator as `leverage_px` on every cue it derives, so a caller can see which reference is worth having. nx_svmetrology camheight <y_base> <y_top> <y_horizon> <h_obj_um> <sigma_permil> -> one cue row nx_svmetrology height <y_base> <y_top> <y_horizon> <h_cam_um> <sigma_permil> -> a height, given scale nx_svmetrology fuse <cuefile> [max_reduced_chi2_x100] -> posterior + chi2 + residuals nx_svmetrology selftest CUE ROWS (tab-separated; the cue registry plane uses the same shape): cue <TAB> <name> <TAB> <value_um> <TAB> <sigma_um> [<TAB> provenance [<TAB> source]] license_tier: ORIGINAL expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_svmetrology.nx

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main hw sys_write sys_exit sv_same sv_selftest sv_wr sys_openat_wr sys_write ↻ sys_close hw ↻ sv_runfile sys_mmap sv_read sys_openat_rd sys_read sys_close ↻ sv_refuse hw ↻ sv_fuse sys_mmap ↻ sv_eol sv_cols sv_same ↻ sv_int sv_refuse ↻ sv_isqrt hw ↻ pn sys_mmap ↻ sys_write ↻ sv_pr sys_write ↻ sv_camheight sv_refuse ↻ hw ↻ pn ↻ pn ↻ sv_camheight ↻ sv_argint

structs

none

consts

27const SV_MAGIC_2000: i64 = 2000
28const SV_MAGIC_1700000: i64 = 1700000
30const SV_CAP: i64 = 262144
31const SV_MAXCUE: i64 = 256
32const SV_WK: i64 = 1000000000000
33const SV_DEFCHI: i64 = 400
34const SV_TAB: i64 = 9
35const SV_NL: i64 = 10

functions

37func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
38func pn(v: i64) -> i64 { let b: *u8=sys_mmap(32) as *u8; var x: i64=v; var ng: i64=0; if x<0{ng=1;x=0-x} var i: i64=31; if x==0{b[i]=48 as u8;i=i-1} while x>0{b[i]=(48+x%10) as u8;x=x/10;i=i-1} if ng==1{b[i]=45 as u8;i=i-1} sys_write(1,(b as i64+i+1) as *u8,31-i); return 0 }
39func sv_pr(b: *u8, a: i64, e: i64) -> i64 { if e > a { sys_write(1, ((b as i64)+a) as *u8, e-a) } return 0 }
called by 1: sv_fuse calls 1: sys_write
40func sv_isqrt(x: i64) -> i64
called by 1: sv_fuse
47func sv_refuse(reason: *u8) -> i64 { hw("SVMETROLOGY REFUSED: " as *u8); hw(reason); hw("\n" as *u8); return 0 }
51func sv_eol(b: *u8, n: i64, i: i64) -> i64
called by 1: sv_fuse
57func sv_cols(b: *u8, ls: i64, le: i64, col: *i64, maxc: i64) -> i64
called by 1: sv_fuse
72func sv_int(b: *u8, a: i64, e: i64) -> i64
called by 1: sv_fuse
85func sv_same(b: *u8, a: i64, e: i64, lit: *u8) -> i64
called by 2: sv_fusemain
93func sv_argint(s: *u8) -> i64
called by 1: main
106func sv_read(path: *u8, buf: *u8, cap: i64) -> i64
122func sv_camheight(yb: i64, yt: i64, yh: i64, hobj: i64, sigpm: i64) -> i64
called by 2: sv_selftestmain calls 3: sv_refusehwpn
144func sv_height(yb: i64, yt: i64, yh: i64, hcam: i64, sigpm: i64) -> i64
called by 1: main calls 3: sv_refusehwpn
160func sv_fuse(buf: *u8, n: i64, maxchi: i64) -> i64
291func sv_wr(path: *u8, s: *u8) -> i64
300func sv_runfile(path: *u8, maxchi: i64) -> i64
306func sv_selftest() -> i64
339func main(argc: i64, argv: *i64) -> i64