link rum global scalex, doors, door1, door2, originx, originy procedure main(av) local d #----------------------------------------------------------------- d := rumwizard() d.show_modal() #-------------------------------------------------------------------- &window := open("Roominator","g", "image="||av[1]) | stop("Usage: ruminator image.gif") WAttrib("label=Roominator: Please Click on the ORIGIN") while (e := Event()) ~=== &lpress do if e === "q" then exit(0) WAttrib("fg=green") originx := &x originy := &y DrawPoint(&x,&y) WAttrib("label=Roominator Scaling; Please Click on (5.0,0.0)") while (e := Event()) ~=== &lpress do if e === "q" then exit(0) scalex := (&x - originx) / 10 WAttrib("label=Roominator: one foot = " || scalex || " pixels") WAttrib("fg=red","drawop=reverse") repeat { e := Event() case e of { "q": { exit(0) } &lpress: { x1 := &x; y1 := &y; x2 := y2 := &null } "t": { if \x1 & \y1 & \x2 & \y2 then { write("should extract doorplate texture at ", x1, ",", y1, " - ", x2, ",", y2) } } &lrelease: { DrawLine(x1,y1,x1,\y2) | next # erase DrawLine(x1,y1,\x2,y1) # erase DrawLine(x1,\y2,\x2,\y2) # erase DrawLine(\x2,y1,\x2,\y2) # erase doors := [] write(abs(x1-x2)/scalex,"x",abs(y1-y2)/scalex, " room from ", x1, ",", y1, " - ", x2, ",", y2) convert(x1,y1) convert(x2,y2) y := y1; x := x1 cornerpixel := &null door1 := door2 := &null every p := Pixel(x1,y1,x2-x1,1) do { cornerpixel := checkwall(cornerpixel, p) if bilevel(p) ~=== bilevel(cornerpixel) then { if not (/door1 := x) then door2 := x } else { foundydoor(\door1, \door2, \y) door1 := door2 := &null } x +:= 1 } foundydoor(\door1, \door2, \y) door1 := door2 := &null y := y2; x := x1 cornerpixel := &null door1 := door2 := &null every p := Pixel(x1,y2,x2-x1,1) do { cornerpixel := checkwall(cornerpixel, p) if bilevel(p) ~=== bilevel(cornerpixel) then { if not (/door1 := x) then door2 := x } x +:= 1 } foundydoor(\door1, \door2, \y) door1 := door2 := &null y := y1; x := x1 cornerpixel := &null door1 := door2 := &null every p := Pixel(x1,y1,1,y2-y1) do { cornerpixel := checkwall(cornerpixel, p) if bilevel(p) ~=== bilevel(cornerpixel) then { if not (/door1 := y) then door2 := y } y +:= 1 } foundxdoor(\door1, \door2, \x) door1 := door2 := &null x := x2; y := y1 cornerpixel := &null door1 := door2 := &null every p := Pixel(x,y,1,y2-y1) do { cornerpixel := checkwall(cornerpixel, p) if bilevel(p) ~=== bilevel(cornerpixel) then { if not (/door1 := y) then door2 := y } y +:= 1 } foundxdoor(\door1, \door2, \x) door1 := door2 := &null write(*doors , " doors found") } &ldrag: { DrawLine(x1,y1,x1,\y2) # erase DrawLine(x1,y1,\x2,y1) # erase DrawLine(x1,\y2,\x2,\y2) # erase DrawLine(\x2,y1,\x2,\y2) # erase x2 := &x; y2 := &y DrawLine(x1,y1,x1,\y2) # erase DrawLine(x1,y1,\x2,y1) # erase DrawLine(x1,\y2,\x2,\y2) # erase DrawLine(\x2,y1,\x2,\y2) # erase } default : { } } } end procedure dist(x1,y1,x2,y2) return sqrt(abs(x1-x2)^2 + abs(y1-y2)^2) end procedure bilevel(c) c ? { r := tab(find(",")) ="," g := tab(find(",")) ="," b := tab(0) } if r < 32767 then r := 0 else r := 65535 if g < 32767 then g := 0 else g := 65535 if b < 32767 then b := 0 else b := 65535 return r || "," || g || "," || b end procedure checkwall(cornerpixel, p) if (/cornerpixel := p) & (p ~=== "0,0,0") then { write("corner ", image(p), " vs. ", image("0,0,0")) } return cornerpixel end procedure founddoor(door1, door2) doorsize := abs(\door1-\door2)/scalex if doorsize = 0 then { write("discarding door size 0"); fail } write(doorsize, "' door from ", \door1,",",y," - ", \door2,",",y) return end procedure foundydoor(door1, door2,y) if founddoor(door1, door2) then put(doors, [\door1,y,\door2,y]) end procedure foundxdoor(door1, door2,x) if founddoor(door1, door2) then put(doors, [x, \door1, x ,\door2]) end procedure convert(x,y) write("converting ", x,",",y, " to world coordinates") # this gives the coordinates in feet x -:= originx y -:= originy x /:= real(scalex) y /:= real(scalex) # this converts feet to world coordinates x /:= 2 y /:= 2 write("\t -> ", x, ",", y) end