code wiki / (root) / nx_pressure_deformation_test.nx

nx_pressure_deformation_test.nx source

↩ module page · 87 lines · 3430 B

1import "nx_syscalls.nx" 2import "nx_image.nx" 3import "nx_pressure_deformation.nx" 4 5func paint_rect_mask(mask: *Image, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 { 6 var y: i64 = y0 7 while y < y1 { 8 var x: i64 = x0 9 while x < x1 { 10 if x >= 0 { if x < mask.width { if y >= 0 { if y < mask.height { 11 nx_image_set(mask, x, y, 0, 255) 12 } } } } 13 x = x + 1 14 } 15 y = y + 1 16 } 17 return 0 18} 19 20func clear_rect_mask(mask: *Image, x0: i64, y0: i64, x1: i64, y1: i64) -> i64 { 21 var y: i64 = y0 22 while y < y1 { 23 var x: i64 = x0 24 while x < x1 { 25 if x >= 0 { if x < mask.width { if y >= 0 { if y < mask.height { 26 nx_image_set(mask, x, y, 0, 0) 27 } } } } 28 x = x + 1 29 } 30 y = y + 1 31 } 32 return 0 33} 34 35func main() -> i64 { 36 let mask: *Image = nx_image_alloc(200, 200, 1) 37 let result: *i64 = (sys_mmap(NX_PRESS_RES_FIELDS * 8 + 16)) as *i64 38 let bbox: *i64 = (sys_mmap(8 * 8 + 16)) as *i64 39 40 // T1: MANNEQUIN scenario — breast 50..150 x 50..150 fully filled, 41 // contact band 90..110 x 90..110 fully filled (rigid, no compression). 42 paint_rect_mask(mask, 50, 50, 150, 150) 43 bbox[0] = 50; bbox[1] = 50; bbox[2] = 149; bbox[3] = 149 44 bbox[4] = 90; bbox[5] = 90; bbox[6] = 109; bbox[7] = 109 45 nx_pressure_deformation(mask, bbox, result) 46 let v1: i64 = result[NX_PRESS_RES_VERDICT] 47 let c1: i64 = result[NX_PRESS_RES_COMPRESSION_Q10] 48 if v1 != NX_PRESS_VERDICT_MANNEQUIN_RIGID { return 1 } 49 if c1 < 950 { return 2 } // ratio should be near 1024 50 51 // T2: NATURAL scenario — breast fully filled, contact band has 52 // significant gap (tissue displaced). Clear 80% of contact band. 53 paint_rect_mask(mask, 50, 50, 150, 150) 54 clear_rect_mask(mask, 92, 92, 108, 108) // 16x16 cleared from 20x20 contact -> ~36% remaining 55 bbox[0] = 50; bbox[1] = 50; bbox[2] = 149; bbox[3] = 149 56 bbox[4] = 90; bbox[5] = 90; bbox[6] = 109; bbox[7] = 109 57 nx_pressure_deformation(mask, bbox, result) 58 let v2: i64 = result[NX_PRESS_RES_VERDICT] 59 let c2: i64 = result[NX_PRESS_RES_COMPRESSION_Q10] 60 if v2 != NX_PRESS_VERDICT_NATURAL { return 10 } 61 if c2 > 717 { return 11 } // must show real compression 62 63 // T3: AMBIGUOUS scenario — mild compression (small gap). 64 paint_rect_mask(mask, 50, 50, 150, 150) 65 clear_rect_mask(mask, 96, 96, 104, 104) // 8x8 cleared from 20x20 -> ~84% remaining 66 nx_pressure_deformation(mask, bbox, result) 67 let v3: i64 = result[NX_PRESS_RES_VERDICT] 68 let c3: i64 = result[NX_PRESS_RES_COMPRESSION_Q10] 69 if v3 != NX_PRESS_VERDICT_AMBIGUOUS { return 20 } 70 if c3 > 870 { return 21 } 71 if c3 < 717 { return 22 } 72 73 // T4: transition counter — natural scenario should have transitions 74 // (mask edges between cleared/filled), mannequin scenario zero. 75 paint_rect_mask(mask, 50, 50, 150, 150) 76 nx_pressure_deformation(mask, bbox, result) 77 let t_rigid: i64 = result[NX_PRESS_RES_BOUNDARY_TRANS] 78 if t_rigid != 0 { return 30 } // all pixels = 1, no transitions 79 80 paint_rect_mask(mask, 50, 50, 150, 150) 81 clear_rect_mask(mask, 92, 92, 108, 108) 82 nx_pressure_deformation(mask, bbox, result) 83 let t_def: i64 = result[NX_PRESS_RES_BOUNDARY_TRANS] 84 if t_def < 8 { return 31 } // should have 2 transitions per affected row 85 86 return 0 87}