code wiki / _hdl_build / nx_bodyatlas_gate.nx

nx_bodyatlas_gate.nx source

↩ module page · 136 lines · 8594 B

1// nx_bodyatlas_gate.nx -- ★HOLISTIC BEING gate (zygotebody.com + sloyd.ai): prove we generate a whole human with 2// ALL its anatomical systems as independently PEELABLE layers, and that it is PARAMETRIC. 3// T1 HOLISTIC: all 8 anatomical systems present + >=40 distinct NAMED structures head-to-toe 4// T2 PEEL (ZygoteBody): peeling the skin reveals a DIFFERENT interior (skin-view vs muscle-view vs organ-view differ, 5// each non-empty) -> the layers really are independently visible 6// T3 PARAMETRIC (Sloyd): different presets reshape the being (heavy preset fills more silhouette than lean; presets differ) 7// T4 determinism + a PEEL FILMSTRIP knowledge/nx_bodyatlas.png (skin -> muscle -> skeleton+viscera -> organs -> skeleton -> nervous) 8// license_tier: ORIGINAL expect_exit: 0 9import "nx_syscalls.nx" 10import "nx_png.nx" 11import "nx_bodyatlas.nx" 12 13func hw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 14func 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 } 15func filled(fb: *i64, n: i64) -> i64 { var c: i64=0; var i: i64=0; while i<n { let p: i64=fb[i]; let r: i64=p&255; let g: i64=(p>>8)&255; let b: i64=(p>>16)&255; if r+g+b > 96 { if b < r+g { c=c+1 } } i=i+1 } return c } 16func imdiff(a: *i64, b: *i64, n: i64) -> i64 { var s: i64=0; var i: i64=0; while i<n { let d: i64=(a[i]&255)-(b[i]&255); if d<0 {s=s-d} else {s=s+d} i=i+1 } return s } 17 18const VW: i64 = 208 19const VH: i64 = 368 20const POSE_YAW: i64 = 5400 // near-side view so sagittal limb swing (walk/sit/wave) reads 21 22func main() -> i64 { 23 hw("=== nx_bodyatlas_gate -- holistic being (all systems, peelable, parametric) ===\n" as *u8) 24 var fails: i64 = 0 25 let np: i64 = atlas_build(0) 26 let sysN: i64 = ba_systems_present() 27 let named: i64 = ba_named_count() 28 hw(" parts="); pn(np); hw(" systems="); pn(sysN); hw("/8 named-structures="); pn(named); hw("\n" as *u8) 29 hw(" per-system: skin="); pn(ba_sys_part_count(0)); hw(" muscle="); pn(ba_sys_part_count(1)); hw(" skel="); pn(ba_sys_part_count(2)); hw(" dig="); pn(ba_sys_part_count(3)) 30 hw(" circ="); pn(ba_sys_part_count(4)); hw(" resp="); pn(ba_sys_part_count(5)); hw(" uri="); pn(ba_sys_part_count(6)); hw(" nerv="); pn(ba_sys_part_count(7)); hw("\n" as *u8) 31 // T1 32 var t1: i64 = 0 33 if sysN == 8 { if named >= 40 { t1 = 1 } } 34 if t1 == 1 { hw("T1 PASS HOLISTIC: all 8 systems + >=40 named structures\n" as *u8) } else { fails=fails+1; hw("T1 FAIL\n" as *u8) } 35 36 let npx: i64 = VW*VH 37 let skin: *i64 = sys_mmap(npx*8) as *i64 38 let musc: *i64 = sys_mmap(npx*8) as *i64 39 let orgn: *i64 = sys_mmap(npx*8) as *i64 40 atlas_render(skin, VW, VH, 0, 1, 0-1) // skin only (mask bit0) 41 atlas_render(musc, VW, VH, 0, 6, 0-1) // muscle+skeleton (skin peeled) 2|4 42 atlas_render(orgn, VW, VH, 0, 120, 0-1) // viscera only (dig|circ|resp|uri) 8|16|32|64 43 let fs: i64 = filled(skin, npx) 44 let fm: i64 = filled(musc, npx) 45 let fo: i64 = filled(orgn, npx) 46 let dsm: i64 = imdiff(skin, musc, npx) 47 let dso: i64 = imdiff(skin, orgn, npx) 48 hw(" peel: filled skin="); pn(fs); hw(" muscle="); pn(fm); hw(" organs="); pn(fo); hw(" diff(skin,muscle)="); pn(dsm); hw(" diff(skin,organs)="); pn(dso); hw("\n" as *u8) 49 // T2 peel: all three views have a body, and peeling changes the image a lot 50 var t2: i64 = 0 51 if fs > npx/12 { if fm > npx/14 { if fo > npx/40 { if dsm > npx*8 { if dso > npx*8 { t2 = 1 } } } } } 52 if t2 == 1 { hw("T2 PASS PEEL: skin/muscle/viscera are distinct, non-empty layers\n" as *u8) } else { fails=fails+1; hw("T2 FAIL\n" as *u8) } 53 54 // T3 parametric: heavy vs lean silhouette 55 atlas_build(1); atlas_render(skin, VW, VH, 0, 1, 0-1); let fHeavy: i64 = filled(skin, npx) 56 atlas_build(3); atlas_render(musc, VW, VH, 0, 1, 0-1); let fLean: i64 = filled(musc, npx) 57 atlas_build(2); atlas_render(orgn, VW, VH, 0, 1, 0-1); let fFem: i64 = filled(orgn, npx) 58 let dHL: i64 = imdiff(skin, musc, npx) 59 hw(" parametric: heavy-fill="); pn(fHeavy); hw(" lean-fill="); pn(fLean); hw(" female-fill="); pn(fFem); hw(" diff(heavy,lean)="); pn(dHL); hw("\n" as *u8) 60 var t3: i64 = 0 61 if fHeavy > fLean { if dHL > npx*6 { t3 = 1 } } 62 if t3 == 1 { hw("T3 PASS PARAMETRIC: presets reshape the being (heavy>lean silhouette)\n" as *u8) } else { fails=fails+1; hw("T3 FAIL\n" as *u8) } 63 64 // T4 determinism 65 atlas_build(0) 66 let d1: *i64 = sys_mmap(npx*8) as *i64 67 let d2: *i64 = sys_mmap(npx*8) as *i64 68 atlas_render(d1, VW, VH, 3000, 30, 0-1) 69 atlas_render(d2, VW, VH, 3000, 30, 0-1) 70 var dd: i64 = 0; var i: i64 = 0 71 while i < npx { if d1[i] != d2[i] { dd = dd + 1 } i = i + 1 } 72 var t4: i64 = 0 73 if dd == 0 { t4 = 1 } 74 if t4 == 1 { hw("T4 PASS deterministic\n" as *u8) } else { fails=fails+1; hw("T4 FAIL diff="); pn(dd); hw("\n" as *u8) } 75 76 // ---- PEEL FILMSTRIP: 6 stages, front view ---- 77 atlas_build(0) 78 let masks: *i64 = sys_mmap(6*8) as *i64 79 masks[0]=1 // skin 80 masks[1]=6 // muscle (+skeleton) 2|4 81 masks[2]=252 // skeleton + all viscera 4|8|16|32|64|128 82 masks[3]=120 // viscera only 8|16|32|64 83 masks[4]=4 // skeleton only 84 masks[5]=128 // nervous only 85 let GW: i64 = VW*6 86 let gal: *i64 = sys_mmap(GW*VH*8) as *i64 87 let cell: *i64 = sys_mmap(npx*8) as *i64 88 var c: i64 = 0 89 while c < 6 { 90 atlas_render(cell, VW, VH, 2600, masks[c], 0-1) 91 var y: i64 = 0 92 while y < VH { var x: i64=0; while x<VW { gal[y*GW+c*VW+x] = cell[y*VW+x]; x=x+1 } y=y+1 } 93 c = c + 1 94 } 95 write_png(gal, GW, VH, "knowledge/nx_bodyatlas.png" as *u8) 96 hw("T5 peel filmstrip -> knowledge/nx_bodyatlas.png (skin|muscle|skeleton+viscera|organs|skeleton|nervous)\n" as *u8) 97 98 // ---- T6 R6 RIG: posing moves the limbs (the being is not a mannequin) ---- 99 atlas_build(0) 100 atlas_pose(0); atlas_render(skin, VW, VH, POSE_YAW, 1, 0-1); let fStand: i64 = filled(skin, npx) 101 atlas_pose(1); atlas_render(musc, VW, VH, POSE_YAW, 1, 0-1); let fWalk: i64 = filled(musc, npx) 102 atlas_pose(3); atlas_render(orgn, VW, VH, POSE_YAW, 1, 0-1) 103 let dSW: i64 = imdiff(skin, musc, npx) // stand vs walk: limbs swing -> large image change 104 let dSV: i64 = imdiff(skin, orgn, npx) // stand vs wave: right arm up -> large change 105 hw(" rig: stand-fill="); pn(fStand); hw(" walk-fill="); pn(fWalk); hw(" diff(stand,walk)="); pn(dSW); hw(" diff(stand,wave)="); pn(dSV); hw("\n" as *u8) 106 var t6: i64 = 0 107 if dSW > npx*4 { if dSV > npx*2 { if fWalk > npx/14 { t6 = 1 } } } // walk moves all 4 limbs; wave moves one arm 108 if t6 == 1 { hw("T6 PASS RIG: poses (walk/wave) measurably move the limbs -- a LIVING being, FK-rigged\n" as *u8) } else { fails=fails+1; hw("T6 FAIL rig static diff(stand,walk)="); pn(dSW); hw("\n" as *u8) } 109 // determinism of a posed render 110 atlas_pose(1) 111 atlas_render(d1, VW, VH, POSE_YAW, 1, 0-1) 112 atlas_render(d2, VW, VH, POSE_YAW, 1, 0-1) 113 var pdd: i64 = 0; i = 0 114 while i < npx { if d1[i] != d2[i] { pdd = pdd + 1 } i = i + 1 } 115 if pdd != 0 { fails=fails+1; hw("T6b FAIL posed render nondeterministic diff="); pn(pdd); hw("\n" as *u8) } else { hw("T6b PASS posed render deterministic\n" as *u8) } 116 // pose filmstrip: stand | walk | sit | wave (skin, side-on) 117 let poses: *i64 = sys_mmap(4*8) as *i64 118 poses[0]=0; poses[1]=1; poses[2]=2; poses[3]=3 119 let PW: i64 = VW*4 120 let pgal: *i64 = sys_mmap(PW*VH*8) as *i64 121 var pp: i64 = 0 122 while pp < 4 { 123 atlas_pose(poses[pp]) 124 atlas_render(cell, VW, VH, POSE_YAW, 1, 0-1) 125 var y: i64 = 0 126 while y < VH { var x: i64=0; while x<VW { pgal[y*PW+pp*VW+x] = cell[y*VW+x]; x=x+1 } y=y+1 } 127 pp = pp + 1 128 } 129 write_png(pgal, PW, VH, "knowledge/nx_bodyatlas_pose.png" as *u8) 130 hw("T7 pose filmstrip -> knowledge/nx_bodyatlas_pose.png (stand|walk|sit|wave)\n" as *u8) 131 132 if fails == 0 { hw("BODYATLAS-GATE GREEN -- holistic being: 8 anatomical systems, ~60 named structures head-to-toe, INDEPENDENTLY PEELABLE (ZygoteBody) + PARAMETRIC (Sloyd), 100% integer sovereign. Residual: per-part click-labels in UI + finer meshes + rigging.\n" as *u8); sys_exit(0); return 0 } 133 hw("BODYATLAS-GATE RED fails="); pn(fails); hw("\n" as *u8) 134 sys_exit(1) 135 return 1 136}