code wiki / _hdl_build / nx_twinbench.nx
nx_twinbench.nx
buildroot/runtime/_hdl_build/nx_twinbench.nx
about
nx_twinbench.nx -- ★★★THE METRIC RULER, AND THE PRIMARY INSTRUMENT OF THE DIGITAL-TWIN PROGRAM.
WHY THIS COMES FIRST. The program's governing law is capability = MIN(statistical, perceptual), and the
perceptual term has always been an OPERATOR'S GLANCE -- no organ emits it, so every "we moved 175 -> X"
has been unfalsifiable by construction. Aiming at a photoreal PLAUSIBLE human made that unavoidable:
"does this look real" is a matter of judgement. Aiming at a 1:1 TWIN OF A SPECIFIC PERSON does not.
"Is this surface within one millimetre of that person's face" is arithmetic.
★★THE TWIN TARGET MAKES MEASUREMENT EASIER, NOT HARDER -- it hands us a hard ruler the aesthetic target
never could, and this organ is that ruler.
WHAT IT MEASURES: the deviation of a candidate surface from a reference surface, as a distribution rather
than one number -- mean, RMS, p95, and max (a one-sided Hausdorff). Reported in MILLIMETRES, because a
surgeon does not plan in per-mille and a bench number that cannot be compared to a caliper is decoration.
★POINT-TO-TRIANGLE, NOT POINT-TO-VERTEX, AND THE DIFFERENCE IS NOT PEDANTRY. Nearest-VERTEX distance is
the easy version and it is BIASED: it reports error proportional to the reference's tessellation, so a
coarser reference scores worse for reasons that have nothing to do with the subject. A ruler whose reading
depends on how finely you happened to triangulate the truth is not a ruler. So every query point is
measured to the nearest point ON A TRIANGLE -- face interior, edge, or vertex, whichever is closest.
★A UNIFORM GRID, BECAUSE THE HONEST ALGORITHM MUST ALSO TERMINATE. Brute force is O(N*M): 35k vertices
against 35k triangles is 1.2 billion point-triangle tests per comparison, and a ruler nobody runs is a
ruler that does not exist. Reference triangles are bucketed into a uniform grid; a query expands its
search radius ring by ring and STOPS ONLY when the next ring cannot contain anything closer than the best
found so far. That last clause is what keeps it EXACT rather than approximate -- the grid changes the
cost, never the answer, and T6 proves it against brute force on a small mesh.
nx_twinbench cmp <candidate.nxmesh> <reference.nxmesh> [stature_mm] [layer]
nx_twinbench selftest
license_tier: ORIGINAL expect_exit: 0 No hw writes (Rule 26).
dependencies 1 imports · 0 importers
imports: nx_gate_verdict.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 32 | const TB_MAGIC_16383: i64 = 16383 |
| 33 | const TB_MAGIC_4000000000: i64 = 4000000000 |
| 34 | const TB_MAGIC_1750: i64 = 1750 |
| 35 | const TB_MAGIC_4950: i64 = 4950 |
| 36 | const TB_MAGIC_5050: i64 = 5050 |
| 37 | const TB_MAGIC_4000: i64 = 4000 |
| 38 | const TB_MAGIC_1000000: i64 = 1000000 |
| 40 | const TB_M8388607: i64 = 8388607 |
| 41 | const TB_M8388608: i64 = 8388608 |
| 42 | const TB_HDR: i64 = 16 |
| 43 | const TB_LAYENT: i64 = 24 |
| 44 | const TB_TRI: i64 = 84 |
| 45 | const TB_LID: i64 = 4 |
| 46 | const TB_Q: i64 = 1000 |
| 51 | const TB_SCALE: i64 = 1024 |
| 52 | const TB_UM: i64 = 1000 |
| 53 | const TB_STATURE: i64 = 1750 |
| 54 | const TB_GRID: i64 = 48 |
| 55 | const TB_CELLS: i64 = 110592 |
| 56 | const TB_MAXTRI: i64 = 400000 |
| 57 | const TB_MAXQ: i64 = 200000 |
| 58 | const TB_BIG: i64 = 4611686018427387903 |
| 59 | const TB_OUT: i64 = 24 |
| 60 | const TB_FRAC: i64 = 1048576 |
| 62 | const TB_TARGET: i64 = 40000 |
| 236 | const TB_MH: i64 = 8 |
functions
| 64 | func tb_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 65 | func tb_pn(v: i64) -> i64 |
| 75 | func tb_pmm(um: i64) -> i64 |
| 87 | func tb_streq(a: *u8, b: *u8) -> i64 called by 1: main |
| 92 | func tb_atoi(s: *u8) -> i64 called by 1: main |
| 98 | func tb_rd32(b: *u8, o: i64) -> i64 |
| 101 | func tb_f32mul(b: *u8, o: i64, mul: i64) -> i64 |
| 114 | func tb_isqrt(v: i64) -> i64 |
| 137 | func tb_shift_for(m: i64) -> i64 |
| 143 | func tb_sh(v: i64, sh: i64) -> i64 |
| 147 | func tb_absi(v: i64) -> i64 { if v < 0 { return 0-v } return v } |
| 148 | func tb_max6(a: i64, b: i64, c: i64, d: i64, e: i64, f: i64) -> i64 |
| 158 | func tb_frac(num: i64, den: i64) -> i64 |
| 167 | func tb_pseg2(px: i64, py: i64, pz: i64, ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64) -> i64 |
| 189 | func tb_ptri2(px: i64, py: i64, pz: i64, |
| 237 | func tb_load(path: *u8, M: *i64, cap: i64) -> i64 |
| 292 | func tb_cbrt(v: i64) -> i64 |
| 297 | func tb_grid_build(M: *i64, G: *i64, head: *i64, nxt: *i64) -> i64 |
| 330 | func tb_nearest2(px: i64, py: i64, pz: i64, M: *i64, G: *i64, head: *i64, nxt: *i64) -> i64 |
| 385 | func tb_cmp(candA: *i64, refB: *i64, out: *i64, stature: i64, target: i64) -> i64 |
| 480 | func tb_fx_quad(M: *i64, h: i64, dz: i64) -> i64 called by 1: tb_gate |
| 494 | func tb_gate() -> i64 |
| 590 | func main(argc: i64, argv: *i64) -> i64 |