code wiki / _hdl_build / nx_biotwin_morphometrics.nx

nx_biotwin_morphometrics.nx source

↩ module page · 131 lines · 7763 B

1// nx_biotwin_morphometrics.nx -- BIOTWIN rung-1 ORGAN: derive the morphometric axes from the visualise-body 2// substrate, emit a provenance-carrying evidence artifact for board axis 8 (morphometric-derivation, COU-1). 3// 4// Composes nx_bodyatlas ba_sdf (the sovereign integer SDF being -- QOI[0] visualise-own-body substrate, 833). 5// For each derived axis it emits: value, the TRANSFORM that produced it, the INPUT landmarks it consumed, the 6// input measurement resolution, the banked canon band, and whether it lands in band. Plus cross-body 7// generalisation (the same engine on 3 body presets), a determinism witness, and the rule-26 promotion fence. 8// 9// HONEST: this is the DERIVATION TRANSFORM only. Image-space photogrammetry-capture (axis 6) and anatomical- 10// landmarking (axis 7) remain GAP, so the "derive morphometrics from a scan" QOI stays capped. No output of 11// this organ may inform a decision about a real person. 12// license_tier: ORIGINAL expect_exit: 0 13import "nx_syscalls.nx" 14import "nx_biotwin_morpho.nx" 15const K_MAGIC_262144: i64 = 262144 16 17func ocat(o: *u8, at: i64, s: *u8) -> i64 { var i: i64=0; var a: i64=at; while s[i]!=(0 as u8){o[a]=s[i]; a=a+1; i=i+1} return a } 18func onum(o: *u8, at: i64, v: i64) -> i64 { 19 var a: i64=at; var m: i64=v 20 if m==0 { o[a]=48 as u8; return a+1 } 21 if m<0 { o[a]=45 as u8; a=a+1; m=0-m } 22 let t: *u8 = sys_mmap(32); var k: i64=0 23 while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } 24 var q: i64=k-1 25 while q>=0 { o[a]=t[q]; a=a+1; q=q-1 } 26 return a 27} 28func heads_of(LM: *i64) -> i64 { 29 let stature: i64 = LM[LM_CROWN] - LM[LM_SOLE] 30 let headh: i64 = LM[LM_CROWN] - LM[LM_CHIN] 31 if headh == 0 { return 0 } 32 return stature*10/headh 33} 34 35func main() -> i64 { 36 let OUT: *i64 = sys_mmap(N_AX*AX_STRIDE*8) as *i64 37 bm_derive(0, OUT) 38 39 // determinism witness: two independent derivations of preset 0 must hash identically 40 let c1: i64 = bm_checksum(0) 41 let c2: i64 = bm_checksum(0) 42 var det: i64 = 0 43 if c1 == c2 { det = 1 } 44 45 // landmarks for preset 0 (captured before cross-body rebuilds the atlas) + cross-body presets 46 let LM0: *i64 = sys_mmap(N_LM*8) as *i64 47 bm_measure(0, LM0) 48 let LM2: *i64 = sys_mmap(N_LM*8) as *i64 49 bm_measure(2, LM2) 50 let LM3: *i64 = sys_mmap(N_LM*8) as *i64 51 bm_measure(3, LM3) 52 let stat0: i64 = LM0[LM_CROWN] - LM0[LM_SOLE] 53 let stat2: i64 = LM2[LM_CROWN] - LM2[LM_SOLE] 54 let stat3: i64 = LM3[LM_CROWN] - LM3[LM_SOLE] 55 56 let fb: i64 = bm_fence_blocked() 57 58 // ---- emit JSON ---- 59 let jb: *u8 = sys_mmap(K_MAGIC_262144) 60 var j: i64 = 0 61 j = ocat(jb, j, "{\x22v\x22:1,\x22organ\x22:\x22nx_biotwin_morphometrics\x22,\x22board_axis\x22:\x22morphometric-derivation\x22,\x22cou_tier\x22:1" as *u8) 62 j = ocat(jb, j, ",\x22substrate\x22:\x22nx_bodyatlas ba_sdf -- the sovereign integer SDF being (QOI[0] visualise-own-body substrate, coverage 833)\x22" as *u8) 63 j = ocat(jb, j, ",\x22ruler\x22:\x22banked anthropometric canon knowledge/anthropometry_banked.txt (7.5-heads / leg / arm / shoulder-hip / fingertip-drop)\x22" as *u8) 64 j = ocat(jb, j, ",\x22method\x22:\x22integer/fixed-point derivation from geometric landmarks; every axis carries provenance (input landmarks + transform) and its input measurement resolution\x22" as *u8) 65 66 // landmarks (preset 0), in SDF units 67 j = ocat(jb, j, ",\x22landmarks_preset0_sdf_units\x22:{\x22crown_y\x22:" as *u8); j = onum(jb, j, LM0[LM_CROWN]) 68 j = ocat(jb, j, ",\x22chin_y\x22:" as *u8); j = onum(jb, j, LM0[LM_CHIN]) 69 j = ocat(jb, j, ",\x22sole_y\x22:" as *u8); j = onum(jb, j, LM0[LM_SOLE]) 70 j = ocat(jb, j, ",\x22crotch_y\x22:" as *u8); j = onum(jb, j, LM0[LM_CROTCH]) 71 j = ocat(jb, j, ",\x22acromion_y\x22:" as *u8); j = onum(jb, j, LM0[LM_ACRO]) 72 j = ocat(jb, j, ",\x22fingertip_y\x22:" as *u8); j = onum(jb, j, LM0[LM_FTIP]) 73 j = ocat(jb, j, ",\x22shoulder_hw\x22:" as *u8); j = onum(jb, j, LM0[LM_SHW]) 74 j = ocat(jb, j, ",\x22hip_hw\x22:" as *u8); j = onum(jb, j, LM0[LM_HIPW]) 75 j = ocat(jb, j, "}" as *u8) 76 77 // derived axes with provenance 78 j = ocat(jb, j, ",\x22derived_axes\x22:[" as *u8) 79 var k: i64 = 0 80 while k < N_AX { 81 let base: i64 = k*AX_STRIDE 82 let val: i64 = OUT[base+AX_VAL] 83 let lo: i64 = OUT[base+AX_LO] 84 let hi: i64 = OUT[base+AX_HI] 85 let res: i64 = OUT[base+AX_RES] 86 var inb: i64 = 0 87 if val >= lo { if val <= hi { inb = 1 } } 88 if k > 0 { j = ocat(jb, j, "," as *u8) } 89 j = ocat(jb, j, "{\x22axis\x22:\x22" as *u8); j = ocat(jb, j, OUT[base+AX_NM] as *u8) 90 j = ocat(jb, j, "\x22,\x22value\x22:" as *u8); j = onum(jb, j, val) 91 j = ocat(jb, j, ",\x22transform\x22:\x22" as *u8); j = ocat(jb, j, OUT[base+AX_TF] as *u8) 92 j = ocat(jb, j, "\x22,\x22inputs\x22:\x22" as *u8); j = ocat(jb, j, OUT[base+AX_IN] as *u8) 93 j = ocat(jb, j, "\x22,\x22input_resolution_pm\x22:" as *u8); j = onum(jb, j, res) 94 j = ocat(jb, j, ",\x22canon_lo\x22:" as *u8); j = onum(jb, j, lo) 95 j = ocat(jb, j, ",\x22canon_hi\x22:" as *u8); j = onum(jb, j, hi) 96 j = ocat(jb, j, ",\x22in_band\x22:" as *u8); j = onum(jb, j, inb) 97 j = ocat(jb, j, "}" as *u8) 98 k = k + 1 99 } 100 j = ocat(jb, j, "]" as *u8) 101 102 // cross-body generalisation: same engine, 3 body presets; heads-tall stays canon-valid while stature varies 103 j = ocat(jb, j, ",\x22cross_body_generalisation\x22:[" as *u8) 104 j = ocat(jb, j, "{\x22preset\x22:0,\x22body\x22:\x22default-male\x22,\x22stature\x22:" as *u8); j = onum(jb, j, stat0) 105 j = ocat(jb, j, ",\x22heads_tall_x10\x22:" as *u8); j = onum(jb, j, heads_of(LM0)); j = ocat(jb, j, "}" as *u8) 106 j = ocat(jb, j, ",{\x22preset\x22:2,\x22body\x22:\x22female\x22,\x22stature\x22:" as *u8); j = onum(jb, j, stat2) 107 j = ocat(jb, j, ",\x22heads_tall_x10\x22:" as *u8); j = onum(jb, j, heads_of(LM2)); j = ocat(jb, j, "}" as *u8) 108 j = ocat(jb, j, ",{\x22preset\x22:3,\x22body\x22:\x22tall-lean\x22,\x22stature\x22:" as *u8); j = onum(jb, j, stat3) 109 j = ocat(jb, j, ",\x22heads_tall_x10\x22:" as *u8); j = onum(jb, j, heads_of(LM3)); j = ocat(jb, j, "}]" as *u8) 110 111 // determinism 112 j = ocat(jb, j, ",\x22determinism\x22:{\x22repeat_derivation_identical\x22:" as *u8); j = onum(jb, j, det) 113 j = ocat(jb, j, ",\x22checksum\x22:" as *u8); j = onum(jb, j, c1); j = ocat(jb, j, "}" as *u8) 114 115 // the fence, re-proven every run 116 j = ocat(jb, j, ",\x22fence\x22:{\x22morpho_fence_blocked\x22:" as *u8); j = onum(jb, j, fb) 117 j = ocat(jb, j, ",\x22rule\x22:\x22rule-26 promotion clamp -- a morphometric MEASUREMENT can never be promoted to a clinical or genomic CLAIM. A permanent planted lie (a caller claim of clinical/genomic-ready) is forced back to measurement-only every run; morpho_fence_blocked>=1 proves the clamp fires. Composes with the board axis-21 fence.\x22" as *u8) 118 j = ocat(jb, j, ",\x22downstream_fenced\x22:\x22clinical-decision (COU-3 FENCED-NEEDS-INVIVO), genomic-target-inference (COU-4 HARD-FENCED-BY-LAW)\x22}" as *u8) 119 120 // honesty 121 j = ocat(jb, j, ",\x22honest\x22:\x22This is the DERIVATION TRANSFORM only (geometry->numbers), proven on the sovereign SDF being. Image-space photogrammetry-capture (axis 6) and anatomical-landmarking (axis 7) remain GAP, so the derive-morphometrics-from-a-scan QOI stays capped below full readiness. No output may inform a decision about a real person.\x22}" as *u8) 122 123 // write the artifact + echo to stdout 124 let path: *u8 = "knowledge/nx_biotwin_morphometrics.json\x00" as *u8 125 let fd: i64 = sys_openat_wr(path, 0x1a4) 126 if fd >= 0 { sys_write(fd, jb, j) 127 sys_close(fd) } 128 sys_write(1, jb, j) 129 sys_write(1, "\n" as *u8, 1) 130 return 0 131}