code wiki / _hdl_build / nx_profile_semantic_overlay_t239.nx
nx_profile_semantic_overlay_t239.nx source
↩ module page · 97 lines · 5247 B
1// Diagnostic named-surface seed influence adapter; not anatomical ground truth.
2// Composes existing geodesic domain owner. Input topology/normals stay byte-identical.
3// Mapping file: <existing layer name> <group 0 torso-seed / 1 arm-seed / 2 uncertain-girdle>.
4// Identity coordinate transform is a hypothesis until source registration is qualified.
5// Usage skin.nxmesh bones.nxmesh mapping.dat out.nxmesh labels.u32
6import "nx_boneheat_lib.nx"
7func sa_u32(b:*u8,o:i64)->i64{return (b[o] as i64)|((b[o+1] as i64)<<8)|((b[o+2] as i64)<<16)|((b[o+3] as i64)<<24)}
8func sa_wr(b:*u8,o:i64,v:i64)->i64{b[o]=v as u8;b[o+1]=(v>>8) as u8;b[o+2]=(v>>16) as u8;b[o+3]=(v>>24) as u8;return 0}
9func sa_coord(b:*u8,o:i64)->i64{
10 let bits:i64=sa_u32(b,o);let e:i64=(bits>>23)&255
11 if e==0{return 0}let m:i64=((bits&8388607)|8388608)*1000
12 let sh:i64=e-150;var v:i64=0
13 if sh>=0{v=m<<sh}else{v=m>>(0-sh)}
14 if (bits>>31)!=0{return 0-v}return v
15}
16func sa_header(b:*u8,n:i64)->i64{
17 if n<16{return 0}if sa_u32(b,0)!=1397577806{return 0}
18 if b[4]!=(72 as u8){return 0}if b[5]!=(50 as u8){return 0}
19 let nl:i64=sa_u32(b,8);let nt:i64=sa_u32(b,12)
20 if nl<1{return 0}if nt<1{return 0}
21 if 16+nl*24+nt*88!=n{return 0}
22 return 1
23}
24func main(argc:i64,argv:*i64)->i64{
25 if argc!=6{return 2}
26 let sl:*i64=sys_mmap(16) as *i64;let bl:*i64=sys_mmap(16) as *i64;let ml:*i64=sys_mmap(16) as *i64
27 let s:*u8=sys_read_file(argv[1] as *u8,sl);let b:*u8=sys_read_file(argv[2] as *u8,bl);let m:*u8=sys_read_file(argv[3] as *u8,ml)
28 if (s as i64)==0{return 3}if (b as i64)==0{return 3}if (m as i64)==0{return 3}
29 if sa_header(s,sl[0])==0{return 4}if sa_header(b,bl[0])==0{return 4}
30 let nl:i64=sa_u32(b,8);let nt:i64=sa_u32(s,12);let nv:i64=nt*3
31 let sh:i64=16+sa_u32(s,8)*24;let bh:i64=16+nl*24
32 let groups:*i64=sys_mmap(nl*8) as *i64
33 var l:i64=0;while l<nl{groups[l]=0-1;l=l+1}
34 var p:i64=0;var mapped:i64=0
35 while p<ml[0]{
36 while p<ml[0]{if m[p]>(32 as u8){break}p=p+1}
37 if p>=ml[0]{break}let start:i64=p
38 while p<ml[0]{if m[p]<=(32 as u8){break}p=p+1}
39 let ln:i64=p-start;while p<ml[0]{if m[p]>(32 as u8){break}p=p+1}
40 if p>=ml[0]{return 5}let group:i64=(m[p] as i64)-48
41 if group<0{return 5}if group>2{return 5}p=p+1
42 if p<ml[0]{if m[p]>(32 as u8){return 5}}
43 var found:i64=0;l=0
44 while l<nl{
45 var k:i64=0;while k<16{if b[16+l*24+k]==(0 as u8){break}k=k+1}
46 if k==ln{var j:i64=0;while j<ln{if b[16+l*24+j]!=m[start+j]{break}j=j+1}
47 if j==ln{if groups[l]>=0{return 5}groups[l]=group;found=found+1;mapped=mapped+1}
48 }l=l+1
49 }if found!=1{return 5}
50 }
51 let two:i64=1+nv*3;let w:*i64=sys_mmap((two+1+nt*3)*8) as *i64;w[0]=nv;w[two]=nt
52 var v:i64=0;while v<nv{var c:i64=0;while c<3{w[1+v*3+c]=sa_coord(s,sh+(v/3)*84+(v%3)*12+c*4);c=c+1}w[two+1+v]=v;v=v+1}
53 let g:*i64=sys_mmap(BG_WORDS*8) as *i64
54 let cells:i64=bh_conf_cells(BH_CONF_PATH);if cells<1{return 6}
55 bh_grid_build(g,w,0,nv,cells);bh_raster(g,w,0,two,nt);bh_flood(g)
56 let vd:*i64=sys_mmap(nv*3*8) as *i64
57 var group:i64=0
58 while group<3{
59 bh_reset(g);var accepted:i64=0;var outside:i64=0;l=0
60 while l<nl{if groups[l]==group{
61 let first:i64=sa_u32(b,16+l*24+16);let count:i64=sa_u32(b,16+l*24+20)
62 if first+count>sa_u32(b,12){return 7}
63 var t:i64=first;while t<first+count{var j:i64=0;while j<3{
64 let o:i64=bh+t*84+j*12
65 let cell:i64=bh_cell_of(g,sa_coord(b,o),sa_coord(b,o+4),sa_coord(b,o+8))
66 if bh_seed(g,cell)==1{accepted=accepted+1}else{outside=outside+1}
67 j=j+1}t=t+1}
68 }l=l+1}
69 bh_kv(" group=" as *u8,group);bh_kv(" accepted_seed_samples=" as *u8,accepted);bh_kv(" outside_domain_samples=" as *u8,outside);bh_puts("\n" as *u8)
70 if accepted==0{return 8}bh_dijkstra(g)
71 let d:*i64=g[BG_DIST] as *i64
72 v=0;while v<nv{let cell:i64=bh_cell_of(g,w[1+v*3],w[2+v*3],w[3+v*3]);vd[v*3+group]=BH_DIST_INF
73 if bh_is_domain(g,cell)==1{vd[v*3+group]=d[cell]}v=v+1}
74 group=group+1
75 }
76 let labels:*u8=sys_mmap(nt*4);let counts:*i64=sys_mmap(32) as *i64;var t:i64=0
77 while t<nt{
78 var winner:i64=0-1;var mixed:i64=0;var j:i64=0
79 while j<3{v=t*3+j;var best:i64=BH_DIST_INF;var id:i64=3;group=0
80 while group<3{let d:i64=vd[v*3+group];if d<best{best=d;id=group}else{if d==best{id=3}}group=group+1}
81 if j==0{winner=id}else{if winner!=id{mixed=1}}j=j+1
82 }
83 if mixed==1{winner=3}if winner<0{winner=3}counts[winner]=counts[winner]+1;sa_wr(labels,t*4,winner)
84 // Exact IEEE754 unit colors: blue torso influence, red arm, yellow girdle, white mixed/unknown.
85 var r:i64=0;var green:i64=0;var blue:i64=0
86 if winner==0{blue=1065353216}if winner==1{r=1065353216}if winner==2{r=1065353216;green=1065353216}if winner==3{r=1065353216;green=1065353216;blue=1065353216}
87 sa_wr(s,sh+t*84+72,r);sa_wr(s,sh+t*84+76,green);sa_wr(s,sh+t*84+80,blue)
88 t=t+1
89 }
90 let out:i64=sys_openat_wr(argv[4] as *u8,420);if out<0{return 9}
91 let wrote:i64=sys_write(out,s,sl[0]);sys_close(out);if wrote!=sl[0]{return 9}
92 let lf:i64=sys_openat_wr(argv[5] as *u8,420);if lf<0{return 9}
93 let lw:i64=sys_write(lf,labels,nt*4);sys_close(lf);if lw!=nt*4{return 9}
94 bh_puts("DIAGNOSTIC identity-transform hypothesis; source-seed influence is NOT anatomical truth\n" as *u8)
95 group=0;while group<4{bh_kv(" label=" as *u8,group);bh_kv(" triangles=" as *u8,counts[group]);bh_puts("\n" as *u8);group=group+1}
96 return 0
97}