code wiki / (root) / nx_skull_canon_lib.nx

nx_skull_canon_lib.nx source

↩ module page · 936 lines · 56847 B

1// nx_skull_canon_lib.nx -- THE GENERATED SKULL'S OWN RULER: craniometric landmarks on OUR skull and on the scanned 2// oracle by ONE locator, compared in a landmark-defined frame, with bands measured off the resource (anatomy AN17, 3// 2026-09-18). 4// 5// WHY: knowledge/status/skullfit_trend.jsonl scores the generated skull as millimetres per REGION against the oracle 6// surface, and its regions are dominated by the vault and the base (n_ours 9,335 + 8,672 of about 31,000 samples), so a 7// lumpy ovoid with a 49 mm muzzle reads "4 mm mean" and its nasal region reads n=0. This library measures the FACE: the 8// craniometric landmarks that decide whether a skull reads as a skull (chin depth, the nasal aperture's position, height, 9// width and depth, the orbits' centres, widths and depths, the bizygomatic and bigonial breadths, the prosthion, the 10// bony thirds), each located by the SAME rule on both skulls, so every number is a difference between two measurements 11// and never a difference between two definitions. 12// 13// COMPOSES, NEVER RE-IMPLEMENTS: the landmark locator is nx_tissuefield_lib.tfl_locate (midline-profile extrema by 14// noise-floor prominence, support directions, rim crests); the mesh reader is its NXMSH2 welder (tfl_mesh_load); the 15// frontal depth map is its tfl_front_at. Added here, because a face ruler needs them and the locator does not name them: 16// (1) the opisthocranion (the point farthest from the glabella: maximum cranial length) and the euryons (the most 17// lateral points above the brow) as chords and supports; the piriform aperture by its RIMS (rhinion and nasospinale 18// on the midline, the lateral margins as rim crests walked by the locator's own tfl_crest rule) and the orbits by 19// theirs (the locator's supraorbital, infraorbital and ectoconchion crests plus a medial crest walked here), so 20// widths, heights and depths are rim-to-rim or rim-to-floor and a see-through hole reads DEEPER than any socket; 21// (2) THE FRAME: a translation to the nasion and no rotation (skc_frame says why); the rotation it refuses to apply -- 22// the glabella-opisthocranion chord's pitch -- is a measured quantity of its own; 23// (3) THE BANDS: the locator's own noise, measured by re-locating on rigidly perturbed copies of the same mesh (a 24// half-edge translation, a pitch and a yaw that move the vertex by one mesh edge), floored at the mesh's own 25// resolution (a vertex set e apart cannot place a point better than e/2); a paired landmark adds the oracle's own 26// bilateral asymmetry. Two further perturbations (a negative translation, a roll) are HELD OUT so a gate can ask 27// whether the bands generalise instead of reading them back to itself; 28// (4) THE MIDLINE RULES of tfl_locate with two changes, both measured on the scan and filed for the locator's owner: 29// the aperture is the most PROMINENT minimum, never the smallest absolute z; the glabella is the most anterior 30// point above the aperture floor and the pogonion the most anterior maximum below the prosthion (skc_midline_locate). 31// 32// FRAME CONVENTION: +y up, +z anterior, x lateral (nx_skullsdf emits so). The BodyParts3D oracle in knowledge/skull.nxmesh 33// is stored anterior -z, exactly as nx_skullsdf's own tune (ss_load_ref) and gapmap read it, so skc_load(path, 1) negates 34// z on load; a reflection through the coronal plane is a rotation by half a turn about y for a bilaterally symmetric 35// skull, so widths and midline coordinates are unaffected and the pair names are read as a PAIR, never as sides. 36// UNITS: the welder's u10 (tenths of a millimetre). LIB, no main. license_tier: ORIGINAL No hw writes (Rule 26). 37import "nx_syscalls.nx" 38import "nx_tissuefield_lib.nx" 39 40const SKC_I64: i64 = 8 41const SKC_Q: i64 = TFL_NQ // 4096: the frame's unit-vector scale = the mesh's own normal scale 42const SKC_LM_F: i64 = 4 // per landmark: x y z state 43const SKC_LM_N: i64 = 20 44const SKC_MEAS_N: i64 = 16 45const SKC_REC_N: i64 = SKC_LM_N * SKC_LM_F + SKC_MEAS_N 46const SKC_FR_N: i64 = 14 // frame: lateral(3) up(3) front(3) origin(3) in SKC_Q, then chord pitch and euryon roll (permil) 47// the landmark indices: the locator's names first, then the classes added here 48const SKC_VERTEX: i64 = 0 49const SKC_GLABELLA: i64 = 1 50const SKC_NASION: i64 = 2 51const SKC_RHINION: i64 = 3 52const SKC_APFLOOR: i64 = 4 53const SKC_NASOSPINALE: i64 = 5 54const SKC_PROSTHION: i64 = 6 55const SKC_SUPRAMENTALE: i64 = 7 56const SKC_POGONION: i64 = 8 57const SKC_GNATHION: i64 = 9 58const SKC_ZYGION_L: i64 = 10 59const SKC_ZYGION_R: i64 = 11 60const SKC_GONION_L: i64 = 12 61const SKC_GONION_R: i64 = 13 62const SKC_OPISTHOCRANION: i64 = 14 63const SKC_EURYON_L: i64 = 15 64const SKC_EURYON_R: i64 = 16 65const SKC_ORBIT_L: i64 = 17 // centre of the left orbit's rims (z = the eye seed's front) 66const SKC_ORBIT_R: i64 = 18 67const SKC_APERTURE: i64 = 19 // centre of the piriform aperture's rims 68// scalar measures (u10), stored after the landmarks 69const SKC_M_AP_W: i64 = 0 // aperture width, lateral rim crest to rim crest at the floor's row 70const SKC_M_AP_H: i64 = 1 // aperture height, rhinion to nasospinale 71const SKC_M_ORB_L_W: i64 = 2 72const SKC_M_ORB_L_H: i64 = 3 73const SKC_M_ORB_R_W: i64 = 4 74const SKC_M_ORB_R_H: i64 = 5 75const SKC_M_AP_DEPTH: i64 = 6 // the aperture's rim front minus its floor front 76const SKC_M_ORB_L_DEPTH: i64 = 7 77const SKC_M_ORB_R_DEPTH: i64 = 8 78const SKC_M_GOP_PITCH: i64 = 9 // the glabella-opisthocranion chord's pitch, permil rise per backward run (reported, never applied) 79const SKC_M_NV: i64 = 10 80const SKC_M_EDGE: i64 = 11 81const SKC_M_AP_BOUNDED: i64 = 12 // 1 when a rim crest walk found no surface (the measure is not a value) 82const SKC_M_ORB_BOUNDED: i64 = 13 83const SKC_M_LOCATED: i64 = 14 84const SKC_M_FALLBACK: i64 = 15 85// the quantities a gate holds to a band: each a scalar of the frame coordinates or a measure 86const SKC_QN: i64 = 18 87const SKC_Q_CHIN_DEPTH: i64 = 0 // pogonion z - glabella z (sagittal; a muzzle reads far positive) 88const SKC_Q_NASAL_POSITION: i64 = 1 // nasion y - nasospinale y (the bony nasal height) 89const SKC_Q_APERTURE_HEIGHT: i64 = 2 // rhinion to nasospinale 90const SKC_Q_APERTURE_WIDTH: i64 = 3 // lateral rim crest to rim crest 91const SKC_Q_ORBIT_SPACING: i64 = 4 // orbit centre x_l - x_r 92const SKC_Q_ORBIT_HEIGHT: i64 = 5 // glabella y - mean orbit centre y 93const SKC_Q_ORBIT_WIDTH: i64 = 6 // mean orbit width, medial crest to ectoconchion 94const SKC_Q_ZYGION_WIDTH: i64 = 7 // bizygomatic breadth 95const SKC_Q_GONION_WIDTH: i64 = 8 // bigonial breadth 96const SKC_Q_PROSTHION_DEPTH: i64 = 9 // prosthion z - glabella z 97const SKC_Q_UPPER_FACE_HEIGHT: i64 = 10 // nasion y - prosthion y 98const SKC_Q_THIRDS_IMBALANCE: i64 = 11 // (glabella y - nasospinale y) - (nasospinale y - gnathion y) 99const SKC_Q_APERTURE_DEPTH: i64 = 12 // rim front minus floor front: an opening is deep, a dent is not, a tunnel deeper than any aperture 100const SKC_Q_ORBIT_DEPTH: i64 = 13 // mean rim-minus-floor of the orbital depressions 101const SKC_Q_GOP_PITCH: i64 = 14 // the glabella-opisthocranion chord pitch, permil: where the occiput sits against the brow 102// THREE QUANTITIES ADDED 2026-09-19 BECAUSE THE TUNER FOUND THE RULER'S BLIND SPOTS: with only the fifteen above, a 103// landmark-steered fit drove the orbit sockets to 2 mm slits and the nasal bones to a 32 mm block while every quantity 104// it could see improved. Each is formed from landmarks the locator already places, so no new walk and no typed number. 105const SKC_Q_ORBIT_RIM_HEIGHT: i64 = 15 // mean supraorbital-to-infraorbital crest height: a socket, never a slit 106const SKC_Q_NASION_DEPTH: i64 = 16 // glabella z - nasion z: the dip at the root of the nose (a block fills it to zero) 107const SKC_Q_NASAL_PROJECTION: i64 = 17 // rhinion z - nasion z: how far the nasal bones come forward 108// perturbation kinds 109const SKC_P_SHIFT_POS: i64 = 0 110const SKC_P_PITCH: i64 = 1 111const SKC_P_YAW: i64 = 2 112const SKC_P_SHIFT_NEG: i64 = 3 113const SKC_P_ROLL: i64 = 4 114const SKC_BAND_KINDS: i64 = 3 // kinds 0..2 build the band; 3..4 are held out 115const SKC_HOLDOUT_KINDS: i64 = 2 116 117func skc_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } 118func skc_max(a: i64, b: i64) -> i64 { if a > b { return a } return b } 119func skc_min(a: i64, b: i64) -> i64 { if a < b { return a } return b } 120 121func skc_name(i: i64) -> *u8 { 122 if i == SKC_VERTEX { return "vertex" as *u8 } 123 if i == SKC_GLABELLA { return "glabella" as *u8 } 124 if i == SKC_NASION { return "nasion" as *u8 } 125 if i == SKC_RHINION { return "rhinion" as *u8 } 126 if i == SKC_APFLOOR { return "aperture_floor" as *u8 } 127 if i == SKC_NASOSPINALE { return "nasospinale" as *u8 } 128 if i == SKC_PROSTHION { return "prosthion" as *u8 } 129 if i == SKC_SUPRAMENTALE { return "supramentale" as *u8 } 130 if i == SKC_POGONION { return "pogonion" as *u8 } 131 if i == SKC_GNATHION { return "gnathion" as *u8 } 132 if i == SKC_ZYGION_L { return "zygion_l" as *u8 } 133 if i == SKC_ZYGION_R { return "zygion_r" as *u8 } 134 if i == SKC_GONION_L { return "gonion_l" as *u8 } 135 if i == SKC_GONION_R { return "gonion_r" as *u8 } 136 if i == SKC_OPISTHOCRANION { return "opisthocranion" as *u8 } 137 if i == SKC_EURYON_L { return "euryon_l" as *u8 } 138 if i == SKC_EURYON_R { return "euryon_r" as *u8 } 139 if i == SKC_ORBIT_L { return "orbit_l" as *u8 } 140 if i == SKC_ORBIT_R { return "orbit_r" as *u8 } 141 return "aperture" as *u8 142} 143func skc_qname(q: i64) -> *u8 { 144 if q == SKC_Q_CHIN_DEPTH { return "chin_depth" as *u8 } 145 if q == SKC_Q_NASAL_POSITION { return "nasal_position" as *u8 } 146 if q == SKC_Q_APERTURE_HEIGHT { return "aperture_height" as *u8 } 147 if q == SKC_Q_APERTURE_WIDTH { return "aperture_width" as *u8 } 148 if q == SKC_Q_ORBIT_SPACING { return "orbit_spacing" as *u8 } 149 if q == SKC_Q_ORBIT_HEIGHT { return "orbit_height" as *u8 } 150 if q == SKC_Q_ORBIT_WIDTH { return "orbit_width" as *u8 } 151 if q == SKC_Q_ZYGION_WIDTH { return "zygion_width" as *u8 } 152 if q == SKC_Q_GONION_WIDTH { return "gonion_width" as *u8 } 153 if q == SKC_Q_PROSTHION_DEPTH { return "prosthion_depth" as *u8 } 154 if q == SKC_Q_UPPER_FACE_HEIGHT { return "upper_face_height" as *u8 } 155 if q == SKC_Q_THIRDS_IMBALANCE { return "thirds_imbalance" as *u8 } 156 if q == SKC_Q_APERTURE_DEPTH { return "aperture_depth" as *u8 } 157 if q == SKC_Q_ORBIT_DEPTH { return "orbit_depth" as *u8 } 158 if q == SKC_Q_ORBIT_RIM_HEIGHT { return "orbit_rim_height" as *u8 } 159 if q == SKC_Q_NASION_DEPTH { return "nasion_depth" as *u8 } 160 if q == SKC_Q_NASAL_PROJECTION { return "nasal_projection" as *u8 } 161 return "gop_pitch" as *u8 162} 163 164// ==== records ==== 165func skc_rec_new() -> *i64 { 166 let R: *i64 = sys_mmap(SKC_REC_N * SKC_I64) as *i64 167 var i: i64 = 0 168 while i < SKC_REC_N { R[i] = 0; i = i + 1 } 169 return R 170} 171func skc_rec_copy(R: *i64) -> *i64 { 172 let C: *i64 = skc_rec_new() 173 var i: i64 = 0 174 while i < SKC_REC_N { C[i] = R[i]; i = i + 1 } 175 return C 176} 177func skc_x(R: *i64, i: i64) -> i64 { return R[i * SKC_LM_F] } 178func skc_y(R: *i64, i: i64) -> i64 { return R[i * SKC_LM_F + 1] } 179func skc_z(R: *i64, i: i64) -> i64 { return R[i * SKC_LM_F + 2] } 180func skc_state(R: *i64, i: i64) -> i64 { return R[i * SKC_LM_F + 3] } 181func skc_set(R: *i64, i: i64, x: i64, y: i64, z: i64, st: i64) -> i64 { 182 R[i * SKC_LM_F] = x; R[i * SKC_LM_F + 1] = y; R[i * SKC_LM_F + 2] = z; R[i * SKC_LM_F + 3] = st 183 return 0 184} 185func skc_meas(R: *i64, k: i64) -> i64 { return R[SKC_LM_N * SKC_LM_F + k] } 186func skc_meas_set(R: *i64, k: i64, v: i64) -> i64 { R[SKC_LM_N * SKC_LM_F + k] = v; return 0 } 187 188// ==== the mesh ==== 189// DENSIFY: the locator's midline profile takes, per band one mesh edge tall, the most anterior vertex within one edge 190// of the midline. On an irregular scan a native band holds about two vertices in that column, so roughly one band in 191// eight is EMPTY of front surface and reads the inner table of the occiput instead -- and every extremum below it 192// shifts (measured 2026-09-18 on the BodyParts3D scan: the nasion landed 151 mm behind the glabella). A regular grid 193// mesh never has that gap. The remedy is the surface's own interpolation: every triangle contributes its three edge 194// midpoints and its centroid as extra vertices (the same surface, four more samples per triangle), while the locator's 195// cell stays the scan's NATIVE mean edge, so a native band cannot be empty and no cell is finer than the data. 196// Triangles and normals are untouched (the locator reads positions only). Returns the new vertex count. 197// the lattice step per triangle: its longest edge divided by half the native cell, rounded up (Nyquist for the cell) 198func skc_lattice_n(M: *i64, t: i64, step: i64) -> i64 { 199 let vx: *i64 = M[TFL_M_VX] as *i64; let vy: *i64 = M[TFL_M_VY] as *i64; let vz: *i64 = M[TFL_M_VZ] as *i64 200 let ta: *i64 = M[TFL_M_TA] as *i64; let tb: *i64 = M[TFL_M_TB] as *i64; let tc: *i64 = M[TFL_M_TC] as *i64 201 let a: i64 = ta[t]; let b: i64 = tb[t]; let c: i64 = tc[t] 202 let ab: i64 = vm_isqrt((vx[a] - vx[b]) * (vx[a] - vx[b]) + (vy[a] - vy[b]) * (vy[a] - vy[b]) + (vz[a] - vz[b]) * (vz[a] - vz[b])) 203 let bc: i64 = vm_isqrt((vx[b] - vx[c]) * (vx[b] - vx[c]) + (vy[b] - vy[c]) * (vy[b] - vy[c]) + (vz[b] - vz[c]) * (vz[b] - vz[c])) 204 let ca: i64 = vm_isqrt((vx[c] - vx[a]) * (vx[c] - vx[a]) + (vy[c] - vy[a]) * (vy[c] - vy[a]) + (vz[c] - vz[a]) * (vz[c] - vz[a])) 205 let l: i64 = skc_max(ab, skc_max(bc, ca)) 206 var n: i64 = (l + step - 1) / step 207 if n < 1 { n = 1 } 208 return n 209} 210// MEASURED 2026-09-18, second form: a fixed four extra samples per triangle was not enough either -- the scan's 211// triangles are adaptive, 5-8 mm across smooth bone, so a native 1.5 mm cell on the forehead still read the frontal 212// sinus wall 14 mm behind the outer table on every other band. The surface is therefore sampled on a BARYCENTRIC 213// LATTICE per triangle at a step of half the native cell (Nyquist for the locator's cell): every cell the surface 214// crosses receives a sample, whatever the tessellation. 215func skc_densify(M: *i64) -> i64 { 216 let nv: i64 = M[TFL_M_NV] 217 let nt: i64 = M[TFL_M_NT] 218 let step: i64 = skc_max(M[TFL_M_EDGE] / 2, 1) 219 var total: i64 = 0 220 var t: i64 = 0 221 while t < nt { let n: i64 = skc_lattice_n(M, t, step); total = total + (n + 1) * (n + 2) / 2; t = t + 1 } 222 let vx: *i64 = M[TFL_M_VX] as *i64; let vy: *i64 = M[TFL_M_VY] as *i64; let vz: *i64 = M[TFL_M_VZ] as *i64 223 let ta: *i64 = M[TFL_M_TA] as *i64; let tb: *i64 = M[TFL_M_TB] as *i64; let tc: *i64 = M[TFL_M_TC] as *i64 224 let x2: *i64 = sys_mmap(total * SKC_I64) as *i64 225 let y2: *i64 = sys_mmap(total * SKC_I64) as *i64 226 let z2: *i64 = sys_mmap(total * SKC_I64) as *i64 227 var k: i64 = 0 228 t = 0 229 while t < nt { 230 let a: i64 = ta[t]; let b: i64 = tb[t]; let c: i64 = tc[t] 231 let n: i64 = skc_lattice_n(M, t, step) 232 var i: i64 = 0 233 while i <= n { 234 var j: i64 = 0 235 while j <= n - i { 236 x2[k] = vx[a] + (vx[b] - vx[a]) * i / n + (vx[c] - vx[a]) * j / n 237 y2[k] = vy[a] + (vy[b] - vy[a]) * i / n + (vy[c] - vy[a]) * j / n 238 z2[k] = vz[a] + (vz[b] - vz[a]) * i / n + (vz[c] - vz[a]) * j / n 239 k = k + 1 240 j = j + 1 241 } 242 i = i + 1 243 } 244 t = t + 1 245 } 246 tfl_kv("SKC-DENSIFY welded=" as *u8, nv); tfl_kv(" samples=" as *u8, k); tfl_kv(" step_u10=" as *u8, step); tfl_puts("\n" as *u8) 247 M[TFL_M_VX] = x2 as i64; M[TFL_M_VY] = y2 as i64; M[TFL_M_VZ] = z2 as i64 248 M[TFL_M_NV] = k 249 M[TFL_M_FM] = 0 250 return k 251} 252// load an NXMSH2 skull through the welder, map it into the authored frame, densify it. frame = SKC_FRAME_AUTHORED reads 253// the file as it is (x lateral, y up, z anterior: what nx_skullsdf emits); SKC_FRAME_BODYPARTS3D reads the BodyParts3D 254// body frame, which is FLOOR-ORIGIN AND z-UP (the head sits at z 1.42..1.64 m in knowledge/skull.nxmesh), y running 255// antero-posterior with the face at -y: x_a = x, y_a = z, z_a = -y -- a proper rotation of a quarter turn about x. 256// MEASURED 2026-09-18: read as y-up with z negated (every estate consumer did so), the midline profile from the front 257// is the skull BASE seen from below -- its 36 mm see-through is the foramen magnum and its lowest point the menton. 258// Returns the mesh record or 0. 259const SKC_FRAME_AUTHORED: i64 = 0 260const SKC_FRAME_BODYPARTS3D: i64 = 1 261func skc_load(path: *u8, frame: i64) -> *i64 { 262 let M: *i64 = tfl_mesh_new() 263 if tfl_mesh_load(path, M) == 0 { return 0 as *i64 } 264 if frame == SKC_FRAME_BODYPARTS3D { 265 // rotate the welded arrays first (normals are sized to the welded count), then densify 266 let vy: *i64 = M[TFL_M_VY] as *i64; let vz: *i64 = M[TFL_M_VZ] as *i64 267 let ny: *i64 = M[TFL_M_NY] as *i64; let nz: *i64 = M[TFL_M_NZ] as *i64 268 var i: i64 = 0 269 while i < M[TFL_M_NV] { 270 let y: i64 = vy[i]; vy[i] = vz[i]; vz[i] = 0 - y 271 let n: i64 = ny[i]; ny[i] = nz[i]; nz[i] = 0 - n 272 i = i + 1 273 } 274 } 275 skc_densify(M) 276 tfl_mesh_bbox_refresh(M) 277 M[TFL_M_FM] = 0 278 return M 279} 280// every located row back to NOT LOCATED, so a landmark the locator does not place on THIS mesh cannot inherit the 281// coordinates it placed on the previous one (tfl_place only writes the rows it locates) 282func skc_tab_reset(T: *i64) -> i64 { 283 var i: i64 = 0 284 while i < T[TFL_T_NROWS] { let r: *i64 = tfl_row(T, i); r[TFL_R_STATE] = TFL_ST_NONE; i = i + 1 } 285 return 0 286} 287func skc_row_state(T: *i64, name: *u8) -> i64 { 288 let i: i64 = tfl_row_find(T, name) 289 if i < 0 { return TFL_ST_NONE } 290 let r: *i64 = tfl_row(T, i) 291 return r[TFL_R_STATE] 292} 293// a rigidly perturbed copy of the mesh: positions moved about the bbox centre, topology and normals shared (the 294// locator reads positions only). Angles are one mesh edge at the vertex: sin = edge/height, cos to second order. 295func skc_perturb(M: *i64, kind: i64) -> *i64 { 296 let S: *i64 = tfl_mesh_clone_positions(M) 297 let vx: *i64 = M[TFL_M_VX] as *i64; let vy: *i64 = M[TFL_M_VY] as *i64; let vz: *i64 = M[TFL_M_VZ] as *i64 298 let sx: *i64 = S[TFL_M_VX] as *i64; let sy: *i64 = S[TFL_M_VY] as *i64; let sz: *i64 = S[TFL_M_VZ] as *i64 299 let edge: i64 = M[TFL_M_EDGE] 300 let cx: i64 = (M[TFL_M_X0] + M[TFL_M_X1]) / 2 301 let cy: i64 = (M[TFL_M_Y0] + M[TFL_M_Y1]) / 2 302 let cz: i64 = (M[TFL_M_Z0] + M[TFL_M_Z1]) / 2 303 var h: i64 = M[TFL_M_Y1] - M[TFL_M_Y0] 304 if h < 1 { h = 1 } 305 let sn: i64 = SKC_Q * edge / h 306 let cs: i64 = SKC_Q - sn * sn / (2 * SKC_Q) 307 var d: i64 = edge / 2 308 if kind == SKC_P_SHIFT_NEG { d = 0 - d } 309 var i: i64 = 0 310 while i < M[TFL_M_NV] { 311 let x: i64 = vx[i] - cx; let y: i64 = vy[i] - cy; let z: i64 = vz[i] - cz 312 var ox: i64 = x; var oy: i64 = y; var oz: i64 = z 313 if kind == SKC_P_SHIFT_POS { ox = x + d; oy = y + d; oz = z + d } 314 if kind == SKC_P_SHIFT_NEG { ox = x + d; oy = y + d; oz = z + d } 315 if kind == SKC_P_PITCH { oy = (cs * y - sn * z) / SKC_Q; oz = (sn * y + cs * z) / SKC_Q } 316 if kind == SKC_P_YAW { ox = (cs * x + sn * z) / SKC_Q; oz = (cs * z - sn * x) / SKC_Q } 317 if kind == SKC_P_ROLL { ox = (cs * x - sn * y) / SKC_Q; oy = (sn * x + cs * y) / SKC_Q } 318 sx[i] = ox + cx; sy[i] = oy + cy; sz[i] = oz + cz 319 i = i + 1 320 } 321 tfl_mesh_bbox_refresh(S) 322 S[TFL_M_FM] = 0 323 return S 324} 325 326// ==== the landmark frame ==== 327func skc_dot(ax: i64, ay: i64, az: i64, bx: i64, by: i64, bz: i64) -> i64 { return ax * bx + ay * by + az * bz } 328// normalise a vector to SKC_Q into out3; returns its length or 0 when degenerate 329func skc_unit(x: i64, y: i64, z: i64, out3: *i64) -> i64 { 330 let l: i64 = vm_isqrt(x * x + y * y + z * z) 331 if l <= 0 { out3[0] = 0; out3[1] = 0; out3[2] = 0; return 0 } 332 out3[0] = x * SKC_Q / l; out3[1] = y * SKC_Q / l; out3[2] = z * SKC_Q / l 333 return l 334} 335// F = [lateral, up, front, origin]. THE ALIGNMENT IS A TRANSLATION TO THE NASION AND NO ROTATION, on purpose: both meshes 336// declare y up and z anterior (nx_skullsdf authors its field so; the BodyParts3D scan is in the anatomical position once 337// its z-up file frame is read as such), and MEASURED 2026-09-18 a rotation derived from the vault landmarks absorbed the 338// generator's own defect into the alignment -- the egg's glabella-opisthocranion chord tilts 15 degrees backward where 339// the scan's tilts 14 degrees forward, so aligning on that chord rotated the two faces 29 degrees apart. The chord's 340// pitch and the euryon line's roll are therefore MEASURED and reported (skc_measure stores them), never applied. 341// 1 ok, 0 degenerate (a chord or a euryon line of zero length) 342func skc_frame(RAW: *i64, F: *i64) -> i64 { 343 let a: *i64 = sys_mmap(3 * SKC_I64) as *i64 344 let l: *i64 = sys_mmap(3 * SKC_I64) as *i64 345 if skc_unit(skc_x(RAW, SKC_OPISTHOCRANION) - skc_x(RAW, SKC_GLABELLA), skc_y(RAW, SKC_OPISTHOCRANION) - skc_y(RAW, SKC_GLABELLA), skc_z(RAW, SKC_OPISTHOCRANION) - skc_z(RAW, SKC_GLABELLA), a) == 0 { return 0 } 346 if skc_unit(skc_x(RAW, SKC_EURYON_L) - skc_x(RAW, SKC_EURYON_R), skc_y(RAW, SKC_EURYON_L) - skc_y(RAW, SKC_EURYON_R), skc_z(RAW, SKC_EURYON_L) - skc_z(RAW, SKC_EURYON_R), l) == 0 { return 0 } 347 F[0] = SKC_Q; F[1] = 0; F[2] = 0 348 F[3] = 0; F[4] = SKC_Q; F[5] = 0 349 F[6] = 0; F[7] = 0; F[8] = SKC_Q 350 F[9] = skc_x(RAW, SKC_NASION); F[10] = skc_y(RAW, SKC_NASION); F[11] = skc_z(RAW, SKC_NASION) 351 // the chord's pitch: the rise of the glabella->opisthocranion unit vector per unit of its backward run, permil 352 // (positive = the occiput sits higher than the glabella); the euryon line's roll likewise 353 var run: i64 = 0 - a[2] 354 if run < 1 { run = 1 } 355 F[12] = a[1] * TFL_PERMIL / run 356 var span: i64 = l[0] 357 if span < 1 { span = 1 } 358 F[13] = l[1] * TFL_PERMIL / span 359 return 1 360} 361func skc_apply(F: *i64, x: i64, y: i64, z: i64, out3: *i64) -> i64 { 362 let dx: i64 = x - F[9]; let dy: i64 = y - F[10]; let dz: i64 = z - F[11] 363 out3[0] = skc_dot(dx, dy, dz, F[0], F[1], F[2]) / SKC_Q 364 out3[1] = skc_dot(dx, dy, dz, F[3], F[4], F[5]) / SKC_Q 365 out3[2] = skc_dot(dx, dy, dz, F[6], F[7], F[8]) / SKC_Q 366 return 0 367} 368// ==== the measurement ==== 369// the vertex farthest from a point (the far end of a chord from a landmark): rotation-invariant where a support 370// direction is not -- a min-z pick slides along a rotated occiput by the pitch times the vault's radius 371func skc_farthest(M: *i64, x: i64, y: i64, z: i64) -> i64 { 372 let vx: *i64 = M[TFL_M_VX] as *i64; let vy: *i64 = M[TFL_M_VY] as *i64; let vz: *i64 = M[TFL_M_VZ] as *i64 373 var best: i64 = 0 - 1 374 var bd: i64 = 0 - 1 375 var v: i64 = 0 376 while v < M[TFL_M_NV] { 377 let dx: i64 = vx[v] - x; let dy: i64 = vy[v] - y; let dz: i64 = vz[v] - z 378 let d2: i64 = dx * dx + dy * dy + dz * dz 379 if d2 > bd { bd = d2; best = v } 380 v = v + 1 381 } 382 return best 383} 384// ONE locating pass on a mesh: the locator's landmarks, the vault frame landmarks (opisthocranion = the vertex farthest 385// from the nasion; euryons = the most lateral vertices above the brow line), the aperture and orbit rims. RAW receives 386// mesh-space coordinates. Returns the number of located rows (0 = refused: not a skull profile). 387// THE MIDLINE AND ITS DEPENDENTS, by the locator's own primitives (tfl_profile, tfl_noisefloor, tfl_extrema, 388// tfl_support, tfl_support_lat, tfl_front_at, tfl_crest) and the locator's own definitions, with ONE rule changed: 389// tfl_locate takes the aperture as the minimum with the smallest ABSOLUTE z between the first and last maximum. On the 390// generated skull that is the tunnel through the aperture (z far behind everything) and the rule holds; on the upright 391// scan the vault's top is the most posterior part of the frontal profile, so a 8 mm notch near the vertex (z 1145 u10) 392// out-deepens the real aperture (z 1647 u10, 26 mm behind the glabella) and every face landmark climbs to the top -- 393// MEASURED 2026-09-18 on knowledge/skull.nxmesh read in its true frame. Here the aperture is the minimum with the 394// greatest PROMINENCE (the lower of its two flanking maxima minus its floor): a notch is shallow against its rims, an 395// aperture is not. Everything else follows tfl_locate line for line so the two agree wherever both are valid; the rule 396// belongs in the locator and is filed for its owner (nx_tissuefield_lib is not this lane's to edit). 397// Places the same row names tfl_locate places, in T. Returns the located count, 0 = refused. 398func skc_midline_locate(M: *i64, T: *i64, KS: *i64) -> i64 { 399 let edge: i64 = M[TFL_M_EDGE] 400 let cap: i64 = (M[TFL_M_Y1] - M[TFL_M_Y0]) / edge + 2 401 let prof: *i64 = sys_mmap(cap * SKC_I64) as *i64 402 let pidx: *i64 = sys_mmap(cap * SKC_I64) as *i64 403 let nb: i64 = tfl_profile(M, prof, pidx, cap) 404 let swing: i64 = tfl_noisefloor(prof, nb, edge) 405 let ex: *i64 = sys_mmap(cap * SKC_I64) as *i64 406 let ty: *i64 = sys_mmap(cap * SKC_I64) as *i64 407 let ne: i64 = tfl_extrema(prof, nb, swing, ex, ty, cap) 408 let vx: *i64 = M[TFL_M_VX] as *i64; let vy: *i64 = M[TFL_M_VY] as *i64; let vz: *i64 = M[TFL_M_VZ] as *i64 409 tfl_kv("SKC-PROFILE bands=" as *u8, nb); tfl_kv(" swing=" as *u8, swing); tfl_kv(" extrema=" as *u8, ne); tfl_puts("\n" as *u8) 410 var top: i64 = nb - 1 411 while top > 0 { if prof[top] > TFL_ZNONE { top = 0 - top } else { top = top - 1 } } 412 if top < 0 { top = 0 - top } 413 var bot: i64 = 0 414 while bot < nb - 1 { if prof[bot] > TFL_ZNONE { bot = bot + nb } else { bot = bot + 1 } } 415 if bot >= nb { bot = bot - nb } 416 if ne < 2 { tfl_puts("SKC-LOCATE REFUSED: fewer than two profile extrema -- not a skull profile\n" as *u8); return 0 } 417 // the aperture: the most PROMINENT minimum between two maxima 418 var ap: i64 = 0 - 1 419 var bestprom: i64 = 0 - 1 420 var k: i64 = 0 421 while k < ne { 422 if ty[k] == 0 { 423 // the flanking maxima, found with flags (a cursor clobbered to break cannot report where it stopped) 424 var ka: i64 = 0 - 1 425 var j: i64 = k - 1 426 var go: i64 = 1 427 while go == 1 { if j < 0 { go = 0 } else { if ty[j] == 1 { ka = j; go = 0 } else { j = j - 1 } } } 428 var kb: i64 = 0 - 1 429 j = k + 1 430 go = 1 431 while go == 1 { if j >= ne { go = 0 } else { if ty[j] == 1 { kb = j; go = 0 } else { j = j + 1 } } } 432 if ka >= 0 { if kb >= 0 { 433 let rim: i64 = skc_min(prof[ex[ka]], prof[ex[kb]]) 434 let prom: i64 = rim - prof[ex[k]] 435 if prom > bestprom { bestprom = prom; ap = k } 436 } } 437 } 438 k = k + 1 439 } 440 if ap < 0 { tfl_puts("SKC-LOCATE REFUSED: no minimum between two maxima on the midline profile\n" as *u8); return 0 } 441 tfl_kv("SKC-APERTURE band=" as *u8, ex[ap]); tfl_kv(" prominence_u10=" as *u8, bestprom); tfl_puts("\n" as *u8) 442 // THE CLASSIC DEFINITIONS, second change to the locator's chain (MEASURED 2026-09-18 on the scan: it has no nasal-bone 443 // notch -- the profile recedes monotonically from the glabella to the aperture floor -- so "nasion = the first minimum 444 // above the aperture" climbs to a 2.6 mm supraglabellar dip and "glabella = the maximum above that" lands on the 445 // frontal eminence). Glabella = the MOST ANTERIOR band above the aperture floor (the most prominent midline point of 446 // the frontal bone); nasion = the deepest minimum between the glabella and the aperture floor, else the locator's 447 // named fallback (a quarter of the descent); rhinion = the most anterior maximum between the nasion and the aperture 448 // floor, else the locator's midpoint fallback. 449 var glab: i64 = 0 - 1 450 var glast: i64 = TFL_ST_LOCATED 451 var gz: i64 = TFL_ZNONE 452 var bnd: i64 = ex[ap] + 1 453 while bnd < nb { if prof[bnd] > gz { gz = prof[bnd]; glab = bnd } bnd = bnd + 1 } 454 if glab < 0 { glab = top; glast = TFL_ST_FALLBACK } 455 var nasb: i64 = 0 - 1 456 var nasst: i64 = TFL_ST_LOCATED 457 var nz: i64 = TFL_FAR 458 k = 0 459 while k < ne { if ty[k] == 0 { if ex[k] < glab { if ex[k] > ex[ap] { if prof[ex[k]] < nz { nz = prof[ex[k]]; nasb = ex[k] } } } } k = k + 1 } 460 if nasb < 0 { nasb = glab - (glab - ex[ap]) / 4; nasst = TFL_ST_FALLBACK } 461 var rhib: i64 = 0 - 1 462 var rhist: i64 = TFL_ST_LOCATED 463 var rz: i64 = TFL_ZNONE 464 k = 0 465 while k < ne { if ty[k] == 1 { if ex[k] < nasb { if ex[k] > ex[ap] { if prof[ex[k]] > rz { rz = prof[ex[k]]; rhib = ex[k] } } } } k = k + 1 } 466 if rhib < 0 { rhib = nasb - (nasb - ex[ap]) / 2; rhist = TFL_ST_FALLBACK } 467 var pro: i64 = 0 - 1 468 k = ap + 1 469 while k < ne { if pro < 0 { if ty[k] == 1 { pro = k } } k = k + 1 } 470 var prob: i64 = 0 - 1 471 var prost: i64 = TFL_ST_LOCATED 472 if pro >= 0 { prob = ex[pro] } else { prob = ex[ap] - (ex[ap] - bot) / 3; prost = TFL_ST_FALLBACK } 473 var nsb: i64 = ex[ap] - 1 474 var going: i64 = 1 475 while going == 1 { if nsb <= prob { going = 0 } else { if prof[nsb] > TFL_ZNONE { if prof[nsb] >= prof[prob] - swing { going = 0 } } if going == 1 { nsb = nsb - 1 } } } 476 // pogonion = the MOST ANTERIOR maximum below the prosthion (the chin's most prominent point), never merely the last 477 var pog: i64 = 0 - 1 478 var pz: i64 = TFL_ZNONE 479 k = 0 480 while k < ne { if ty[k] == 1 { if ex[k] < prob { if prof[ex[k]] > pz { pz = prof[ex[k]]; pog = k } } } k = k + 1 } 481 var pogb: i64 = 0 - 1 482 var pogst: i64 = TFL_ST_LOCATED 483 if pog >= 0 { pogb = ex[pog] } else { 484 var bz: i64 = TFL_ZNONE 485 var bb: i64 = bot 486 while bb < prob - (prob - bot) / 2 { if prof[bb] > bz { bz = prof[bb]; pogb = bb } bb = bb + 1 } 487 pogst = TFL_ST_FALLBACK 488 if pogb < 0 { pogb = bot } 489 } 490 var supb: i64 = 0 - 1 491 var supst: i64 = TFL_ST_LOCATED 492 k = 0 493 while k < ne { if ty[k] == 0 { if ex[k] < prob { if ex[k] > pogb { supb = ex[k] } } } k = k + 1 } 494 if supb < 0 { supb = pogb + (prob - pogb) / 2; supst = TFL_ST_FALLBACK } 495 tfl_place_v(T, "vertex" as *u8, M, pidx[top], TFL_ST_LOCATED) 496 tfl_place_v(T, "gnathion" as *u8, M, pidx[bot], TFL_ST_LOCATED) 497 tfl_place_v(T, "glabella" as *u8, M, pidx[glab], glast) 498 tfl_place_v(T, "nasion" as *u8, M, pidx[nasb], nasst) 499 tfl_place_v(T, "rhinion" as *u8, M, pidx[rhib], rhist) 500 tfl_place_v(T, "aperture_floor" as *u8, M, pidx[ex[ap]], TFL_ST_LOCATED) 501 tfl_place_v(T, "nasospinale" as *u8, M, pidx[nsb], TFL_ST_LOCATED) 502 tfl_place_v(T, "prosthion" as *u8, M, pidx[prob], prost) 503 tfl_place_v(T, "supramentale" as *u8, M, pidx[supb], supst) 504 tfl_place_v(T, "pogonion" as *u8, M, pidx[pogb], pogst) 505 // the dependents, as the locator derives them 506 let g: *i64 = sys_mmap(3 * SKC_I64) as *i64 507 let n3: *i64 = sys_mmap(3 * SKC_I64) as *i64 508 let ns: *i64 = sys_mmap(3 * SKC_I64) as *i64 509 let gn: *i64 = sys_mmap(3 * SKC_I64) as *i64 510 tfl_get(T, "glabella" as *u8, g); tfl_get(T, "nasion" as *u8, n3); tfl_get(T, "nasospinale" as *u8, ns); tfl_get(T, "gnathion" as *u8, gn) 511 let zc: i64 = (M[TFL_M_Z0] + M[TFL_M_Z1]) / 2 512 let zyl: i64 = tfl_support(M, 1, 0, 0, ns[1], n3[1], zc, 1) 513 let zyr: i64 = tfl_support(M, 0 - 1, 0, 0, ns[1], n3[1], zc, 0 - 1) 514 tfl_place_v(T, "zygion_l" as *u8, M, zyl, TFL_ST_LOCATED) 515 tfl_place_v(T, "zygion_r" as *u8, M, zyr, TFL_ST_LOCATED) 516 let zl: *i64 = sys_mmap(3 * SKC_I64) as *i64 517 tfl_get(T, "zygion_l" as *u8, zl) 518 let xc: i64 = (M[TFL_M_X0] + M[TFL_M_X1]) / 2 519 let halfzy: i64 = tfl_abs(zl[0] - xc) 520 let sny: i64 = (g[1] + gn[1]) / 2 521 tfl_place(T, "subnasale_canon" as *u8, xc, sny, tfl_front_at(M, xc, sny, 3), TFL_ST_LOCATED) 522 let gol: i64 = tfl_support_lat(M, 0, 0 - 1, 0 - 1, M[TFL_M_Y0], sny, zl[2] - halfzy, 1, halfzy / 2) 523 let gor: i64 = tfl_support_lat(M, 0, 0 - 1, 0 - 1, M[TFL_M_Y0], sny, zl[2] - halfzy, 0 - 1, halfzy / 2) 524 tfl_place_v(T, "gonion_l" as *u8, M, gol, TFL_ST_LOCATED) 525 tfl_place_v(T, "gonion_r" as *u8, M, gor, TFL_ST_LOCATED) 526 let pspan: i64 = tfl_patch(T, "pupil_span_permil" as *u8) * (2 * halfzy) / TFL_PERMIL 527 let eyey: i64 = g[1] - tfl_patch(T, "eye_line_permil" as *u8) * (g[1] - sny) / TFL_PERMIL 528 let exl: i64 = xc + pspan / 2 529 let exr: i64 = xc - pspan / 2 530 let reach: i64 = 3 531 tfl_place(T, "eye_l" as *u8, exl, eyey, tfl_front_at(M, exl, eyey, reach), TFL_ST_LOCATED) 532 tfl_place(T, "eye_r" as *u8, exr, eyey, tfl_front_at(M, exr, eyey, reach), TFL_ST_LOCATED) 533 let flen: i64 = tfl_patch(T, "fissure_len_permil" as *u8) * (2 * halfzy) / TFL_PERMIL 534 let semx: i64 = flen * tfl_patch(T, "lid_semi_x_permil_of_fissure" as *u8) / TFL_PERMIL 535 let semy: i64 = semx * tfl_patch(T, "lid_semi_y_permil_of_semi_x" as *u8) / TFL_PERMIL 536 let cr: *i64 = sys_mmap(3 * SKC_I64) as *i64 537 tfl_crest(M, exl, eyey, 0, 1, semy, cr); tfl_place(T, "supraorbital_l" as *u8, cr[0], cr[1], cr[2], TFL_ST_LOCATED) 538 tfl_crest(M, exr, eyey, 0, 1, semy, cr); tfl_place(T, "supraorbital_r" as *u8, cr[0], cr[1], cr[2], TFL_ST_LOCATED) 539 tfl_crest(M, exl, eyey, 0, 0 - 1, semy, cr); tfl_place(T, "infraorbital_l" as *u8, cr[0], cr[1], cr[2], TFL_ST_LOCATED) 540 tfl_crest(M, exr, eyey, 0, 0 - 1, semy, cr); tfl_place(T, "infraorbital_r" as *u8, cr[0], cr[1], cr[2], TFL_ST_LOCATED) 541 tfl_crest(M, exl, eyey, 1, 0, semx, cr); tfl_place(T, "ectoconchion_l" as *u8, cr[0], cr[1], cr[2], TFL_ST_LOCATED) 542 tfl_crest(M, exr, eyey, 0 - 1, 0, semx, cr); tfl_place(T, "ectoconchion_r" as *u8, cr[0], cr[1], cr[2], TFL_ST_LOCATED) 543 var located: i64 = 0 544 var fallback: i64 = 0 545 var i: i64 = 0 546 while i < T[TFL_T_NROWS] { 547 let r: *i64 = tfl_row(T, i) 548 if r[TFL_R_STATE] == TFL_ST_LOCATED { located = located + 1 } 549 if r[TFL_R_STATE] == TFL_ST_FALLBACK { fallback = fallback + 1 } 550 i = i + 1 551 } 552 KS[TFL_K_LOCATED] = located; KS[TFL_K_FALLBACK] = fallback 553 return located + fallback 554} 555func skc_locate_pass(M: *i64, T: *i64, RAW: *i64) -> i64 { 556 skc_tab_reset(T) 557 let KS: *i64 = sys_mmap(TFL_K_N * SKC_I64) as *i64 558 var ki: i64 = 0 559 while ki < TFL_K_N { KS[ki] = 0; ki = ki + 1 } 560 let n: i64 = skc_midline_locate(M, T, KS) 561 if n == 0 { return 0 } 562 let p: *i64 = sys_mmap(3 * SKC_I64) as *i64 563 var i: i64 = 0 564 while i < SKC_OPISTHOCRANION { 565 if tfl_get(T, skc_name(i), p) == 1 { skc_set(RAW, i, p[0], p[1], p[2], skc_row_state(T, skc_name(i))) } else { skc_set(RAW, i, 0, 0, 0, TFL_ST_NONE) } 566 i = i + 1 567 } 568 let vx: *i64 = M[TFL_M_VX] as *i64; let vy: *i64 = M[TFL_M_VY] as *i64; let vz: *i64 = M[TFL_M_VZ] as *i64 569 let gy: i64 = skc_y(RAW, SKC_GLABELLA) 570 // the vault frame landmarks: the far end of the nasion chord; the most lateral vertices above the brow line, per side 571 // the opisthocranion by its definition: the point farthest from the GLABELLA (maximum cranial length). MEASURED 572 // 2026-09-18: the point farthest from the nasion is the lower occiput, which pitched the oracle frame 22 degrees. 573 let op: i64 = skc_farthest(M, skc_x(RAW, SKC_GLABELLA), skc_y(RAW, SKC_GLABELLA), skc_z(RAW, SKC_GLABELLA)) 574 let el: i64 = tfl_support(M, 1, 0, 0, gy, M[TFL_M_Y1], M[TFL_M_Z0], 1) 575 let er: i64 = tfl_support(M, 0 - 1, 0, 0, gy, M[TFL_M_Y1], M[TFL_M_Z0], 0 - 1) 576 if op < 0 { return 0 } 577 if el < 0 { return 0 } 578 if er < 0 { return 0 } 579 skc_set(RAW, SKC_OPISTHOCRANION, vx[op], vy[op], vz[op], TFL_ST_LOCATED) 580 skc_set(RAW, SKC_EURYON_L, vx[el], vy[el], vz[el], TFL_ST_LOCATED) 581 skc_set(RAW, SKC_EURYON_R, vx[er], vy[er], vz[er], TFL_ST_LOCATED) 582 // the piriform aperture by its RIMS: the locator's rhinion (top) and nasospinale (bottom) on the midline, and the 583 // lateral margins as rim CRESTS walked from the aperture floor's row by the locator's own tfl_crest rule (the most 584 // anterior front-map point from half to one and a half of the reach), reach = half the aperture height: a piriform 585 // aperture's half-width is near a third of its height, so the walk brackets the margin with no typed width. Depth = 586 // the mean margin front minus the floor's front. A see-through hole reads deeper than any real aperture, on purpose. 587 let xc: i64 = (M[TFL_M_X0] + M[TFL_M_X1]) / 2 588 let aph: i64 = skc_max(skc_y(RAW, SKC_RHINION) - skc_y(RAW, SKC_NASOSPINALE), M[TFL_M_EDGE]) 589 let apy: i64 = skc_y(RAW, SKC_APFLOOR) 590 let cl: *i64 = sys_mmap(3 * SKC_I64) as *i64 591 let crr: *i64 = sys_mmap(3 * SKC_I64) as *i64 592 tfl_crest(M, xc, apy, 1, 0, aph / 2, cl) 593 tfl_crest(M, xc, apy, 0 - 1, 0, aph / 2, crr) 594 var apb: i64 = 0 595 if cl[2] <= TFL_ZNONE { apb = 1 } 596 if crr[2] <= TFL_ZNONE { apb = 1 } 597 let apfz: i64 = skc_z(RAW, SKC_APFLOOR) 598 skc_meas_set(RAW, SKC_M_AP_W, cl[0] - crr[0]) 599 skc_meas_set(RAW, SKC_M_AP_H, aph) 600 if apb == 0 { skc_meas_set(RAW, SKC_M_AP_DEPTH, (cl[2] + crr[2]) / 2 - apfz) } else { skc_meas_set(RAW, SKC_M_AP_DEPTH, 0) } 601 skc_meas_set(RAW, SKC_M_AP_BOUNDED, apb) 602 skc_set(RAW, SKC_APERTURE, (cl[0] + crr[0]) / 2, (skc_y(RAW, SKC_RHINION) + skc_y(RAW, SKC_NASOSPINALE)) / 2, apfz, TFL_ST_LOCATED) 603 // the orbits by their RIMS, from the locator's own rows: the supraorbital and infraorbital crests (height), the 604 // ectoconchion (lateral crest) and a medial crest walked here from the same eye seed with the same reach (the 605 // dacryon's rule): width = ectoconchion minus the medial crest, centre = the rims' midpoints, depth = the mean rim 606 // front minus the eye seed's front (a socket seen from the front is deep, a pit is shallow, a tunnel reads deeper 607 // than any socket). The reach is the locator's lid semi-axis, derived as it derives it: from the bizygomatic. 608 let halfzy: i64 = skc_abs(skc_x(RAW, SKC_ZYGION_L) - xc) 609 let flen: i64 = tfl_patch(T, "fissure_len_permil" as *u8) * (2 * halfzy) / TFL_PERMIL 610 let semx: i64 = flen * tfl_patch(T, "lid_semi_x_permil_of_fissure" as *u8) / TFL_PERMIL 611 let e3: *i64 = sys_mmap(3 * SKC_I64) as *i64 612 let su: *i64 = sys_mmap(3 * SKC_I64) as *i64 613 let inf: *i64 = sys_mmap(3 * SKC_I64) as *i64 614 let ec: *i64 = sys_mmap(3 * SKC_I64) as *i64 615 let med: *i64 = sys_mmap(3 * SKC_I64) as *i64 616 var orbb: i64 = 0 617 var side: i64 = 0 618 while side < 2 { 619 var sg: i64 = 1 620 var oi: i64 = SKC_ORBIT_L 621 var wk: i64 = SKC_M_ORB_L_W 622 var hk: i64 = SKC_M_ORB_L_H 623 var dk: i64 = SKC_M_ORB_L_DEPTH 624 var eyen: *u8 = "eye_l" as *u8 625 var sun: *u8 = "supraorbital_l" as *u8 626 var infn: *u8 = "infraorbital_l" as *u8 627 var ecn: *u8 = "ectoconchion_l" as *u8 628 if side == 1 { 629 sg = 0 - 1; oi = SKC_ORBIT_R; wk = SKC_M_ORB_R_W; hk = SKC_M_ORB_R_H; dk = SKC_M_ORB_R_DEPTH 630 eyen = "eye_r" as *u8; sun = "supraorbital_r" as *u8; infn = "infraorbital_r" as *u8; ecn = "ectoconchion_r" as *u8 631 } 632 var got: i64 = 1 633 if tfl_get(T, eyen, e3) == 0 { got = 0 } 634 if tfl_get(T, sun, su) == 0 { got = 0 } 635 if tfl_get(T, infn, inf) == 0 { got = 0 } 636 if tfl_get(T, ecn, ec) == 0 { got = 0 } 637 if got == 1 { 638 tfl_crest(M, e3[0], e3[1], 0 - sg, 0, semx, med) 639 if med[2] <= TFL_ZNONE { got = 0 } 640 if su[2] <= TFL_ZNONE { got = 0 } 641 if inf[2] <= TFL_ZNONE { got = 0 } 642 if ec[2] <= TFL_ZNONE { got = 0 } 643 if e3[2] <= TFL_ZNONE { got = 0 } 644 } 645 if got == 1 { 646 skc_meas_set(RAW, wk, skc_abs(ec[0] - med[0])) 647 skc_meas_set(RAW, hk, su[1] - inf[1]) 648 skc_meas_set(RAW, dk, (su[2] + inf[2] + ec[2] + med[2]) / 4 - e3[2]) 649 skc_set(RAW, oi, (ec[0] + med[0]) / 2, (su[1] + inf[1]) / 2, e3[2], TFL_ST_LOCATED) 650 } else { 651 skc_set(RAW, oi, 0, 0, 0, TFL_ST_NONE) 652 orbb = 1 653 } 654 side = side + 1 655 } 656 skc_meas_set(RAW, SKC_M_ORB_BOUNDED, orbb) 657 skc_meas_set(RAW, SKC_M_NV, M[TFL_M_NV]) 658 skc_meas_set(RAW, SKC_M_EDGE, M[TFL_M_EDGE]) 659 skc_meas_set(RAW, SKC_M_LOCATED, KS[TFL_K_LOCATED]) 660 skc_meas_set(RAW, SKC_M_FALLBACK, KS[TFL_K_FALLBACK]) 661 return n 662} 663// THE MEASUREMENT: one locating pass, the landmarks expressed relative to the nasion (the frame is a translation, see 664// skc_frame), the chord pitch stored as a measure. R receives frame coordinates and measures; RAWOUT (may be 0) receives 665// the mesh-space landmarks; FOUT (may be 0) receives the frame. Returns the located count (0 = refused). 666func skc_measure(M: *i64, T: *i64, R: *i64, RAWOUT: *i64, FOUT: *i64) -> i64 { 667 let RAW: *i64 = skc_rec_new() 668 let n: i64 = skc_locate_pass(M, T, RAW) 669 if n == 0 { return 0 } 670 let F: *i64 = sys_mmap(SKC_FR_N * SKC_I64) as *i64 671 if skc_frame(RAW, F) == 0 { return 0 } 672 skc_meas_set(RAW, SKC_M_GOP_PITCH, F[12]) 673 let p: *i64 = sys_mmap(3 * SKC_I64) as *i64 674 var i: i64 = 0 675 while i < SKC_LM_N { 676 skc_apply(F, skc_x(RAW, i), skc_y(RAW, i), skc_z(RAW, i), p) 677 skc_set(R, i, p[0], p[1], p[2], skc_state(RAW, i)) 678 i = i + 1 679 } 680 var k: i64 = 0 681 while k < SKC_MEAS_N { skc_meas_set(R, k, skc_meas(RAW, k)); k = k + 1 } 682 if (RAWOUT as i64) != 0 { var c: i64 = 0; while c < SKC_REC_N { RAWOUT[c] = RAW[c]; c = c + 1 } } 683 if (FOUT as i64) != 0 { var f: i64 = 0; while f < SKC_FR_N { FOUT[f] = F[f]; f = f + 1 } } 684 return n 685} 686 687// the midline profile the locator walks, printed band by band (y, z, u10) for a reader: a diagnostic, never a value 688func skc_dump_profile(M: *i64, tag: *u8) -> i64 { 689 let edge: i64 = M[TFL_M_EDGE] 690 let cap: i64 = (M[TFL_M_Y1] - M[TFL_M_Y0]) / edge + 2 691 let prof: *i64 = sys_mmap(cap * SKC_I64) as *i64 692 let pidx: *i64 = sys_mmap(cap * SKC_I64) as *i64 693 let nb: i64 = tfl_profile(M, prof, pidx, cap) 694 let vy: *i64 = M[TFL_M_VY] as *i64 695 tfl_puts("SKC-PROFILE-DUMP " as *u8); tfl_puts(tag); tfl_kv(" bands=" as *u8, nb); tfl_kv(" edge=" as *u8, edge); tfl_puts("\n" as *u8) 696 var b: i64 = nb - 1 697 while b >= 0 { 698 if prof[b] > TFL_ZNONE { tfl_puts("SKC-PROF " as *u8); tfl_puts(tag); tfl_kv(" b=" as *u8, b); tfl_kv(" y=" as *u8, vy[pidx[b]]); tfl_kv(" z=" as *u8, prof[b]); tfl_puts("\n" as *u8) } 699 b = b - 1 700 } 701 return nb 702} 703 704// run the promoted generator as a child (./nx_skullsdf.elf from the estate root) with the RESIDUAL LAYER OFF: argv 705// out sex robust G cell_um tissue k redist res_scale = <out> <sex> <robust> 0 <cell_um> 0 -1 1 <res_permil>. The 706// residual (knowledge/skull_res.dat) is the oracle's own field folded back at a scale; a substrate ruler measures the 707// RULES, so the gate asks for 0. The child's stdout goes to <out>.log. Returns its exit code or -1. 708func skc_run_generator(out: *u8, sex: i64, robust: i64, cell_um: i64, res_permil: i64) -> i64 { 709 let elf: *u8 = "./nx_skullsdf.elf" as *u8 710 let a1: *u8 = sys_mmap(32) 711 let a2: *u8 = sys_mmap(32) 712 let a4: *u8 = sys_mmap(32) 713 let a8: *u8 = sys_mmap(32) 714 tfl_catn(a1, 0, sex); tfl_catn(a2, 0, robust); tfl_catn(a4, 0, cell_um); tfl_catn(a8, 0, res_permil) 715 let argv: *i64 = sys_mmap(12 * SKC_I64) as *i64 716 argv[0] = elf as i64; argv[1] = out as i64; argv[2] = a1 as i64; argv[3] = a2 as i64; argv[4] = ("0" as *u8) as i64 717 argv[5] = a4 as i64; argv[6] = ("0" as *u8) as i64; argv[7] = ("-1" as *u8) as i64; argv[8] = ("1" as *u8) as i64; argv[9] = a8 as i64; argv[10] = 0 718 let envp: *i64 = sys_mmap(SKC_I64) as *i64 719 envp[0] = 0 720 let logp: *u8 = sys_mmap(TFL_PATHB) 721 var o: i64 = tfl_cat(logp, 0, out) 722 o = tfl_cat(logp, o, ".log" as *u8) 723 let pid: i64 = sys_fork() 724 if pid < 0 { return 0 - 1 } 725 if pid == 0 { 726 let fd: i64 = sys_openat_wr(logp, TFL_MODE644) 727 if fd >= 0 { sys_dup3(fd, TFL_STDOUT, 0) } 728 sys_execve(elf, argv, envp) 729 sys_exit_group(127) 730 } 731 let st: *i64 = sys_mmap(2 * SKC_I64) as *i64 732 st[0] = 0 733 let w: i64 = sys_wait4(pid, st, 0) 734 if w < 0 { return 0 - 1 } 735 return wait_exit_code(st[0]) 736} 737 738// ==== the quantities ==== 739func skc_quantity(R: *i64, q: i64) -> i64 { 740 if q == SKC_Q_CHIN_DEPTH { return skc_z(R, SKC_POGONION) - skc_z(R, SKC_GLABELLA) } 741 if q == SKC_Q_NASAL_POSITION { return skc_y(R, SKC_NASION) - skc_y(R, SKC_NASOSPINALE) } 742 if q == SKC_Q_APERTURE_HEIGHT { return skc_meas(R, SKC_M_AP_H) } 743 if q == SKC_Q_APERTURE_WIDTH { return skc_meas(R, SKC_M_AP_W) } 744 if q == SKC_Q_ORBIT_SPACING { return skc_x(R, SKC_ORBIT_L) - skc_x(R, SKC_ORBIT_R) } 745 if q == SKC_Q_ORBIT_HEIGHT { return skc_y(R, SKC_GLABELLA) - (skc_y(R, SKC_ORBIT_L) + skc_y(R, SKC_ORBIT_R)) / 2 } 746 if q == SKC_Q_ORBIT_WIDTH { return (skc_meas(R, SKC_M_ORB_L_W) + skc_meas(R, SKC_M_ORB_R_W)) / 2 } 747 if q == SKC_Q_ZYGION_WIDTH { return skc_x(R, SKC_ZYGION_L) - skc_x(R, SKC_ZYGION_R) } 748 if q == SKC_Q_GONION_WIDTH { return skc_x(R, SKC_GONION_L) - skc_x(R, SKC_GONION_R) } 749 if q == SKC_Q_PROSTHION_DEPTH { return skc_z(R, SKC_PROSTHION) - skc_z(R, SKC_GLABELLA) } 750 if q == SKC_Q_UPPER_FACE_HEIGHT { return skc_y(R, SKC_NASION) - skc_y(R, SKC_PROSTHION) } 751 if q == SKC_Q_THIRDS_IMBALANCE { return (skc_y(R, SKC_GLABELLA) - skc_y(R, SKC_NASOSPINALE)) - (skc_y(R, SKC_NASOSPINALE) - skc_y(R, SKC_GNATHION)) } 752 if q == SKC_Q_APERTURE_DEPTH { return skc_meas(R, SKC_M_AP_DEPTH) } 753 if q == SKC_Q_ORBIT_DEPTH { return (skc_meas(R, SKC_M_ORB_L_DEPTH) + skc_meas(R, SKC_M_ORB_R_DEPTH)) / 2 } 754 if q == SKC_Q_ORBIT_RIM_HEIGHT { return (skc_meas(R, SKC_M_ORB_L_H) + skc_meas(R, SKC_M_ORB_R_H)) / 2 } 755 if q == SKC_Q_NASION_DEPTH { return skc_z(R, SKC_GLABELLA) - skc_z(R, SKC_NASION) } 756 if q == SKC_Q_NASAL_PROJECTION { return skc_z(R, SKC_RHINION) - skc_z(R, SKC_NASION) } 757 return skc_meas(R, SKC_M_GOP_PITCH) 758} 759// a quantity's band from a band record B (per-landmark per-axis maxima and per-measure maxima): the sum of its terms 760func skc_quantity_band(B: *i64, q: i64) -> i64 { 761 if q == SKC_Q_CHIN_DEPTH { return skc_z(B, SKC_POGONION) + skc_z(B, SKC_GLABELLA) } 762 if q == SKC_Q_NASAL_POSITION { return skc_y(B, SKC_NASION) + skc_y(B, SKC_NASOSPINALE) } 763 if q == SKC_Q_APERTURE_HEIGHT { return skc_meas(B, SKC_M_AP_H) } 764 if q == SKC_Q_APERTURE_WIDTH { return skc_meas(B, SKC_M_AP_W) } 765 if q == SKC_Q_ORBIT_SPACING { return skc_x(B, SKC_ORBIT_L) + skc_x(B, SKC_ORBIT_R) } 766 if q == SKC_Q_ORBIT_HEIGHT { return skc_y(B, SKC_GLABELLA) + (skc_y(B, SKC_ORBIT_L) + skc_y(B, SKC_ORBIT_R)) / 2 } 767 if q == SKC_Q_ORBIT_WIDTH { return (skc_meas(B, SKC_M_ORB_L_W) + skc_meas(B, SKC_M_ORB_R_W)) / 2 } 768 if q == SKC_Q_ZYGION_WIDTH { return skc_x(B, SKC_ZYGION_L) + skc_x(B, SKC_ZYGION_R) } 769 if q == SKC_Q_GONION_WIDTH { return skc_x(B, SKC_GONION_L) + skc_x(B, SKC_GONION_R) } 770 if q == SKC_Q_PROSTHION_DEPTH { return skc_z(B, SKC_PROSTHION) + skc_z(B, SKC_GLABELLA) } 771 if q == SKC_Q_UPPER_FACE_HEIGHT { return skc_y(B, SKC_NASION) + skc_y(B, SKC_PROSTHION) } 772 if q == SKC_Q_THIRDS_IMBALANCE { return skc_y(B, SKC_GLABELLA) + 2 * skc_y(B, SKC_NASOSPINALE) + skc_y(B, SKC_GNATHION) } 773 if q == SKC_Q_APERTURE_DEPTH { return skc_meas(B, SKC_M_AP_DEPTH) } 774 if q == SKC_Q_ORBIT_DEPTH { return (skc_meas(B, SKC_M_ORB_L_DEPTH) + skc_meas(B, SKC_M_ORB_R_DEPTH)) / 2 } 775 if q == SKC_Q_ORBIT_RIM_HEIGHT { return (skc_meas(B, SKC_M_ORB_L_H) + skc_meas(B, SKC_M_ORB_R_H)) / 2 } 776 if q == SKC_Q_NASION_DEPTH { return skc_z(B, SKC_GLABELLA) + skc_z(B, SKC_NASION) } 777 if q == SKC_Q_NASAL_PROJECTION { return skc_z(B, SKC_RHINION) + skc_z(B, SKC_NASION) } 778 return skc_meas(B, SKC_M_GOP_PITCH) 779} 780// a paired quantity's bilateral asymmetry on ONE skull (the frame's midline is x=0 through the nasion): for a spacing 781// |x_l + x_r|, for a per-side measure half the |l - r| difference; 0 for an unpaired quantity 782func skc_quantity_asym(R: *i64, q: i64) -> i64 { 783 if q == SKC_Q_ORBIT_SPACING { return skc_abs(skc_x(R, SKC_ORBIT_L) + skc_x(R, SKC_ORBIT_R)) } 784 if q == SKC_Q_ORBIT_HEIGHT { return skc_abs(skc_y(R, SKC_ORBIT_L) - skc_y(R, SKC_ORBIT_R)) / 2 } 785 if q == SKC_Q_ORBIT_WIDTH { return skc_abs(skc_meas(R, SKC_M_ORB_L_W) - skc_meas(R, SKC_M_ORB_R_W)) / 2 } 786 if q == SKC_Q_ZYGION_WIDTH { return skc_abs(skc_x(R, SKC_ZYGION_L) + skc_x(R, SKC_ZYGION_R)) } 787 if q == SKC_Q_GONION_WIDTH { return skc_abs(skc_x(R, SKC_GONION_L) + skc_x(R, SKC_GONION_R)) } 788 if q == SKC_Q_ORBIT_DEPTH { return skc_abs(skc_meas(R, SKC_M_ORB_L_DEPTH) - skc_meas(R, SKC_M_ORB_R_DEPTH)) / 2 } 789 if q == SKC_Q_ORBIT_RIM_HEIGHT { return skc_abs(skc_meas(R, SKC_M_ORB_L_H) - skc_meas(R, SKC_M_ORB_R_H)) / 2 } 790 return 0 791} 792// 1 when every landmark a quantity reads is located (state != NONE) and its FWHM measures crossed within their spans 793func skc_quantity_ready(R: *i64, q: i64) -> i64 { 794 var ok: i64 = 1 795 if q == SKC_Q_CHIN_DEPTH { if skc_state(R, SKC_POGONION) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_GLABELLA) == TFL_ST_NONE { ok = 0 } } 796 if q == SKC_Q_NASAL_POSITION { if skc_state(R, SKC_NASION) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_NASOSPINALE) == TFL_ST_NONE { ok = 0 } } 797 if q == SKC_Q_APERTURE_HEIGHT { if skc_meas(R, SKC_M_AP_BOUNDED) == 1 { ok = 0 } } 798 if q == SKC_Q_APERTURE_WIDTH { if skc_meas(R, SKC_M_AP_BOUNDED) == 1 { ok = 0 } } 799 if q == SKC_Q_APERTURE_DEPTH { if skc_state(R, SKC_APFLOOR) == TFL_ST_NONE { ok = 0 } } 800 if q == SKC_Q_ORBIT_SPACING { if skc_state(R, SKC_ORBIT_L) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_ORBIT_R) == TFL_ST_NONE { ok = 0 } } 801 if q == SKC_Q_ORBIT_HEIGHT { if skc_state(R, SKC_ORBIT_L) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_ORBIT_R) == TFL_ST_NONE { ok = 0 } } 802 if q == SKC_Q_ORBIT_WIDTH { if skc_meas(R, SKC_M_ORB_BOUNDED) == 1 { ok = 0 } } 803 if q == SKC_Q_ORBIT_DEPTH { if skc_state(R, SKC_ORBIT_L) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_ORBIT_R) == TFL_ST_NONE { ok = 0 } } 804 if q == SKC_Q_ZYGION_WIDTH { if skc_state(R, SKC_ZYGION_L) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_ZYGION_R) == TFL_ST_NONE { ok = 0 } } 805 if q == SKC_Q_GONION_WIDTH { if skc_state(R, SKC_GONION_L) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_GONION_R) == TFL_ST_NONE { ok = 0 } } 806 if q == SKC_Q_PROSTHION_DEPTH { if skc_state(R, SKC_PROSTHION) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_GLABELLA) == TFL_ST_NONE { ok = 0 } } 807 if q == SKC_Q_UPPER_FACE_HEIGHT { if skc_state(R, SKC_NASION) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_PROSTHION) == TFL_ST_NONE { ok = 0 } } 808 if q == SKC_Q_THIRDS_IMBALANCE { if skc_state(R, SKC_GLABELLA) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_NASOSPINALE) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_GNATHION) == TFL_ST_NONE { ok = 0 } } 809 if q == SKC_Q_GOP_PITCH { if skc_state(R, SKC_GLABELLA) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_OPISTHOCRANION) == TFL_ST_NONE { ok = 0 } } 810 if q == SKC_Q_ORBIT_RIM_HEIGHT { if skc_meas(R, SKC_M_ORB_BOUNDED) == 1 { ok = 0 } } 811 if q == SKC_Q_NASION_DEPTH { if skc_state(R, SKC_GLABELLA) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_NASION) == TFL_ST_NONE { ok = 0 } } 812 if q == SKC_Q_NASAL_PROJECTION { if skc_state(R, SKC_RHINION) == TFL_ST_NONE { ok = 0 } if skc_state(R, SKC_NASION) == TFL_ST_NONE { ok = 0 } } 813 return ok 814} 815 816// ==== the bands ==== 817// fold |P - R| into B (per landmark per axis, per measure): B keeps the maximum seen 818func skc_band_fold(B: *i64, R: *i64, P: *i64) -> i64 { 819 var i: i64 = 0 820 while i < SKC_LM_N { 821 var a: i64 = 0 822 while a < 3 { 823 let d: i64 = skc_abs(P[i * SKC_LM_F + a] - R[i * SKC_LM_F + a]) 824 if d > B[i * SKC_LM_F + a] { B[i * SKC_LM_F + a] = d } 825 a = a + 1 826 } 827 i = i + 1 828 } 829 var k: i64 = 0 830 while k < SKC_MEAS_N { 831 let d: i64 = skc_abs(skc_meas(P, k) - skc_meas(R, k)) 832 if d > skc_meas(B, k) { skc_meas_set(B, k, d) } 833 k = k + 1 834 } 835 return 0 836} 837// the resolution floor: a vertex set `edge` apart cannot place a point better than half an edge per axis, and a 838// half-maximum extent (two crossings, each half a cell wide) better than one edge 839func skc_band_floor(B: *i64, edge: i64) -> i64 { 840 let half: i64 = skc_max(edge / 2, 1) 841 var i: i64 = 0 842 while i < SKC_LM_N { 843 var a: i64 = 0 844 while a < 3 { if B[i * SKC_LM_F + a] < half { B[i * SKC_LM_F + a] = half } a = a + 1 } 845 i = i + 1 846 } 847 var k: i64 = 0 848 while k < SKC_M_AP_DEPTH { if skc_meas(B, k) < edge { skc_meas_set(B, k, edge) } k = k + 1 } 849 k = SKC_M_AP_DEPTH 850 while k <= SKC_M_ORB_R_DEPTH { if skc_meas(B, k) < half { skc_meas_set(B, k, half) } k = k + 1 } 851 return 0 852} 853// the locator's noise on THIS mesh: re-locate on perturbed copies (kinds k0..k0+nk-1), B = max |delta| against R, 854// floored at the mesh's resolution. Returns the number of perturbed copies the locator accepted (a refused copy is 855// announced and skipped; zero accepted leaves only the floor, which the caller must see as UNMEASURED noise). 856func skc_bands(M: *i64, T: *i64, R: *i64, B: *i64, k0: i64, nk: i64) -> i64 { 857 var done: i64 = 0 858 var k: i64 = k0 859 while k < k0 + nk { 860 let S: *i64 = skc_perturb(M, k) 861 let P: *i64 = skc_rec_new() 862 let n: i64 = skc_measure(S, T, P, 0 as *i64, 0 as *i64) 863 if n == 0 { tfl_kv("SKC-BAND perturbation refused by the locator kind=" as *u8, k); tfl_puts("\n" as *u8) } else { 864 skc_band_fold(B, R, P) 865 done = done + 1 866 } 867 k = k + 1 868 } 869 skc_band_floor(B, M[TFL_M_EDGE]) 870 return done 871} 872// the held-out test: re-locate on kinds k0..k0+nk-1 and count the quantities that fall OUTSIDE band(B)+asym(R). 873// Every miss is named. Returns the miss count; out2[0] = quantities tested, out2[1] = copies accepted. 874func skc_holdout(M: *i64, T: *i64, R: *i64, B: *i64, k0: i64, nk: i64, out2: *i64) -> i64 { 875 var miss: i64 = 0 876 var tested: i64 = 0 877 var done: i64 = 0 878 var k: i64 = k0 879 while k < k0 + nk { 880 let S: *i64 = skc_perturb(M, k) 881 let P: *i64 = skc_rec_new() 882 let n: i64 = skc_measure(S, T, P, 0 as *i64, 0 as *i64) 883 if n == 0 { tfl_kv("SKC-HOLDOUT perturbation refused by the locator kind=" as *u8, k); tfl_puts("\n" as *u8) } else { 884 done = done + 1 885 var q: i64 = 0 886 while q < SKC_QN { 887 if skc_quantity_ready(R, q) == 1 { if skc_quantity_ready(P, q) == 1 { 888 let d: i64 = skc_abs(skc_quantity(P, q) - skc_quantity(R, q)) 889 let b: i64 = skc_quantity_band(B, q) + skc_quantity_asym(R, q) 890 tested = tested + 1 891 if d > b { 892 miss = miss + 1 893 tfl_puts("SKC-HOLDOUT MISS kind=" as *u8); tfl_pn(k); tfl_puts(" " as *u8); tfl_puts(skc_qname(q)) 894 tfl_kv(" delta=" as *u8, d); tfl_kv(" band=" as *u8, b); tfl_puts("\n" as *u8) 895 } 896 } } 897 q = q + 1 898 } 899 } 900 k = k + 1 901 } 902 out2[0] = tested 903 out2[1] = done 904 return miss 905} 906// one line for the trend spine: every quantity as ours-minus-oracle with its band, in mm10; an unready quantity prints 907// its delta as the word ABSENT so a reader cannot mistake a zero for a match 908// the count of quantities inside their band travels WITH the per-quantity list (a worklist without its count cannot be 909// ratcheted; a count without its list cannot be acted on): `inband=<n>/<SKC_QN>` is the token the learning beat reads to 910// accept or send back a tune pass (AN17, 2026-09-19). ABSENT never counts as inside. 911func skc_inband(RO: *i64, RM: *i64, BO: *i64, BM: *i64) -> i64 { 912 var inb: i64 = 0 913 var q: i64 = 0 914 while q < SKC_QN { 915 if skc_quantity_ready(RM, q) == 1 { 916 let b: i64 = skc_quantity_band(BO, q) + skc_quantity_band(BM, q) + skc_quantity_asym(RO, q) 917 if skc_abs(skc_quantity(RM, q) - skc_quantity(RO, q)) <= b { inb = inb + 1 } 918 } 919 q = q + 1 920 } 921 return inb 922} 923func skc_print_line(RO: *i64, RM: *i64, BO: *i64, BM: *i64) -> i64 { 924 tfl_puts("SKC-LANDMARKS" as *u8) 925 var q: i64 = 0 926 while q < SKC_QN { 927 let b: i64 = skc_quantity_band(BO, q) + skc_quantity_band(BM, q) + skc_quantity_asym(RO, q) 928 tfl_puts(" " as *u8); tfl_puts(skc_qname(q)); tfl_puts("=" as *u8) 929 if skc_quantity_ready(RM, q) == 1 { tfl_pn(skc_quantity(RM, q) - skc_quantity(RO, q)) } else { tfl_puts("ABSENT" as *u8) } 930 tfl_puts("/" as *u8); tfl_pn(b) 931 q = q + 1 932 } 933 tfl_puts(" inband=" as *u8); tfl_pn(skc_inband(RO, RM, BO, BM)); tfl_puts("/" as *u8); tfl_pn(SKC_QN) 934 tfl_puts("\n" as *u8) 935 return 0 936}