code wiki / (root) / nx_fieldfit_verified_candidate_t333.nx

nx_fieldfit_verified_candidate_t333.nx

buildroot/runtime/nx_fieldfit_verified_candidate_t333.nx

19987 B478 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic fieldfit
docsdependenciesstructsconstsfunctions

about

nx_fieldfit_lib.nx -- FIT A PARAMETRIC IMPLICIT FIELD TO A SCANNED ORACLE. The machinery nx_skullsdf's `tune` grew (anatomy AN17, 2026-09-18/19), extracted so any anatomy field -- a skull, an arm, a foot, a muscle belly, a tissue layer -- is fitted by ONE optimiser with ONE objective and ONE fit-file contract, and a defect fixed here is fixed for every field at once. The consumer hands over three functions as VALUES (NishiLang func-pointer locals and fields, indirect calls up to six arguments): field(px, py, pz, a, b, P) -> signed distance at `fq` units per millimetre (negative inside) for parameter vector P, with a and b the consumer's two policy knobs (the skull passes sex and robusticity) region(x, y, z) -> 0 .. nreg-1, the named anatomical region a point belongs to live(k) -> 1 for a station the field reads, 0 for a retired one (the descent skips it: two evaluations spent on a dead station are a pass that cannot move anything) THE OBJECTIVE IS TWO-SIDED, AND IT HAS TO BE. A one-directional score -- how far is each ORACLE point from my surface -- is trivially gamed by DELETING GEOMETRY: the skull's first tuning run shrank its orbits from 22 mm to 8 and its maxilla from 30 mm to 13, improving the number 40 percent by filling in the eye sockets, because surface that does not exist cannot be wrong. The REVERSE term charges every lattice point on OUR zero level its distance to the nearest oracle sample, so a deleted feature is EXPENSIVE by construction. (The reverse term uses the nearest oracle VERTEX from a spatial hash: an upper bound on the true point-to-surface distance -- it can overstate, never understate, the safe direction for a penalty.) THE OBJECTIVE IS REGION-BALANCED. A plain mean is dominated by whatever region has the most samples (the skull's vault and base held 9,335 + 8,672 of ~31,000, so a 49 mm muzzle and 4 mm drilled orbits read as a 4 mm skull and the surface objective fell 629 -> 531 while the chin moved +4 -> +19.6 mm). Each side is the mean of the PER-REGION means (a region with no samples abstains), so the smallest region weighs what the largest does. No weight is typed: the population decides. THE DESCENT is coordinate descent: per live station try +step then -step, keep a move only if the MEASURED objective falls; the step halves per pass, floor 1. No change is ever kept on the strength of looking better. THE FIT FILE is newline-separated integers, loaded as a PREFIX: a file shorter than the vector applies to its first entries and the rest keep their defaults, so growing a parametrisation never discards banked convergence; a file shorter than `minlen` changes nothing (parsed into a temp and applied only when long enough, so a truncated write cannot half-poison a field). Written whole by ff_save. UNITS: objectives are reported in centi-millimetres; `lat` (the reverse lattice spacing), `ext` (the half-extent the hash covers) and `dim` (cells per axis) are the consumer's, taken from the resource it fits. LIB, no main. license_tier: ORIGINAL. No hw writes (Rule 26).

dependencies 1 imports · 2 importers

nx_syscalls.nx nx_fieldfit_verified_candidate nx_fieldfit_verified_gate_t333.nx nx_skullsdf_verified_candidate_t33

imports: nx_syscalls.nx

imported by: nx_fieldfit_verified_gate_t333.nxnx_skullsdf_verified_candidate_t333.nx

structs

50struct FfCtx { field: func(i64,i64,i64,i64,i64,*i64) -> i64, region: func(i64,i64,i64) -> i64, live: func(i64) -> i64, RX: *i64, RY: *i64, RZ: *i64, RG: *i64, n: i64, head: *i64, next: *i64, ext: i64, dim: i64, lat: i64, a: i64, b: i64, fq: i64, nreg: i64, sum: *i64, cnt: *i64, np: i64, cap: i64, extra: func(*i64) -> i64, has_extra: i64 }
369struct FfFitContract { header: *u8, header_bytes: i64, np: i64, valid: func(*i64,i64) -> i64 }

consts

35const FF_I64: i64 = 8
36const FF_CENTI: i64 = 100 // objectives are centi-millimetres
37const FF_CTX_BYTES: i64 = 256 // FfCtx: 21 fields of 8 bytes, one page-rounded map
38const FF_LOAD_HDR: i64 = 16 // the two-word length record sys_read_file fills
39const FF_SAVE_DIGITS: i64 = 16 // bytes reserved per integer on save (sign + 19 digits fits a page-rounded map)
40const FF_SAVE_SLACK: i64 = 64
41const FF_MODE644: i64 = 420
361const FF_FIT_LEGACY_UNVERIFIED: i64 = 0 - 2
362const FF_FIT_CONTRACT_MISMATCH: i64 = 0 - 3
363const FF_FIT_MALFORMED: i64 = 0 - 4
364const FF_FIT_INVALID: i64 = 0 - 5
365const FF_FIT_IO: i64 = 0 - 6
366const FF_FIT_MAGIC_BYTES: i64 = 7
367const FF_FIT_I64_DIGITS: i64 = 21
368const FF_FIT_I64_POS_LIMIT: i64 = 9223372036854775807

functions

53func ff_ctx_new(np: i64, nreg: i64, cap: i64, ext: i64, dim: i64, lat: i64, fq: i64) -> *FfCtx
called by 2: mainss_tune calls 1: sys_mmap
69func ff_cell(c: *FfCtx, x: i64, y: i64, z: i64) -> i64
called by 1: ff_bin
84func ff_bin(c: *FfCtx) -> i64
called by 2: mainss_tune calls 1: ff_cell
100func ff_near(c: *FfCtx, x: i64, y: i64, z: i64) -> i64
called by 2: ff_score_revmain calls 1: ff_isqrt
145func ff_isqrt(v: i64) -> i64 { if v<=0 { return 0 } var x: i64=v; var y: i64=(x+1)/2; while y<x { x=y; y=(x+v/x)/2 } return x }
called by 1: ff_near
149func ff_regions(c: *FfCtx) -> i64
called by 2: mainss_tune
156func ff_rtab_reset(c: *FfCtx) -> i64
162func ff_rtab_mean(c: *FfCtx, fq: i64) -> i64
174func ff_score_fwd(c: *FfCtx, P: *i64) -> i64
189func ff_score_rev(c: *FfCtx, P: *i64) -> i64
219func ff_score2(c: *FfCtx, P: *i64) -> i64
228func ff_live_count(c: *FfCtx) -> i64
called by 2: mainss_tune
234func ff_puts(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
235func ff_pn(v: i64) -> i64
243func ff_descend(c: *FfCtx, P: *i64, passes: i64, step0: i64, verbose: i64) -> i64
called by 1: main calls 3: ff_score2ff_putsff_pn
278func ff_wint(b: *u8, o: i64, v: i64) -> i64
297func ff_load_prefix(path: *u8, P: *i64, np: i64, minlen: i64) -> i64
342func ff_save(path: *u8, P: *i64, np: i64) -> i64
372func ff_contract_ok(C: *FfFitContract) -> i64
381func ff_load_verified(path: *u8, P: *i64, C: *FfFitContract) -> i64
425func ff_save_verified(path: *u8, P: *i64, C: *FfFitContract) -> i64
444func ff_descend_checked(c: *FfCtx, P: *i64, passes: i64, step0: i64, verbose: i64, valid: func(*i64,i64) -> i64) -> i64
called by 2: mainss_tune calls 3: ff_score2ff_putsff_pn