From: ian Date: Sun, 1 Jun 2008 18:27:59 +0000 (+0000) Subject: new matrix processing for plan overlay registration X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=f67ad95d3180a8bedce33e3978ea450189272dc5;p=trains.git new matrix processing for plan overlay registration --- diff --git a/layout/.cvsignore b/layout/.cvsignore index bf50641..25ac19a 100644 --- a/layout/.cvsignore +++ b/layout/.cvsignore @@ -17,6 +17,7 @@ tmp.* ui-plan-*.ppm ui-plan-*.crop-info ui-plan-*.overlay-info +ui-plan-*.matrix-info parts.ps *-a.ps ours.graph.c @@ -26,6 +27,7 @@ ours.raw.neato ours.redacted.neato.ps ours.redacted.neato ours.redacted.forsafety +ours.redacted.for-ui ours.redacted.shellvars ours.layout-data.c detectors.pin-info diff --git a/layout/Makefile b/layout/Makefile index e7c74fe..5c7c554 100644 --- a/layout/Makefile +++ b/layout/Makefile @@ -3,7 +3,8 @@ include ../common.make M4INCS= parts.i4 -LAYOUT= ./layout -R270 +ROTATE= 270 +LAYOUT= ./layout -R$(ROTATE) E_TRACK= ArsCLMNo LAYOUTOPTS_ALL= -ep=*Cm @@ -14,6 +15,8 @@ XLAYOUTOPTS_LAYER= -e'=5AN' -E'*~=5rsm' -e'p~=5r' -e'*~=9C' -e'*=*l' \ $(LAYOUTOPTS_PS) PLANUI_PSDPI= 72 +PLANUI_WIDTH= 595 +PLANUI_HEIGHT= 842 LAYOUTOPTS_SEGS= '-e*=*rm' -Lsubseglwm=80 -Lsubseglwe=150 -Lsubseglwq=50 @@ -29,8 +32,6 @@ LPAGES= $(foreach x, 0 1 2 3 4 5 6, $(foreach y, 1 2 3 4 5, ours-p4-$xx$y.ps)) CPROGS= subseg2display compose-segenco -CPPFLAGS += -DPLANUI_PSDPI=$(PLANUI_PSDPI) - default: $(CPROGS) for-test-ui layers extras all: default lpages for-pic: ours+pindata.asm @@ -130,7 +131,8 @@ compose-segenco: compose-segenco.o %.segenco.ppm: %.segenco.ps Makefile gs -dNOPAUSE -dBATCH -dSAFER -q \ - -sDEVICE=ppmraw -r$(PLANUI_PSDPI) -g595x842 \ + -sDEVICE=ppmraw -r$(PLANUI_PSDPI) \ + -g$(PLANUI_WIDTH)x$(PLANUI_HEIGHT) \ -sOutputFile=$@.new $< && mv -f $@.new $@ ours.graph.c: extractgraph ours.dgram-bot.p0.segenco.ps @@ -170,7 +172,13 @@ parts.ps: showlib.d4 layout t.ppm: ours.dgram-bot.pa.segenco.ppm x.gdb subseg2display gdb -x x.gdb -ui-plan-%.ppm: ours.dgram-%.pa.segenco.ppm Makefile +ui-plan-%.matrix-info: ours.dgram-%.p0.segenco.ps matrix-demonstrate.ps + sed -n '1,/^%L matrix here/p' matrix-demonstrate.ps >$@.ps.new + sed -n '/^%L matrix begin/,/^%L matrix end/p' $< >>$@.ps.new + sed -e '1,/^%L matrix here/d' matrix-demonstrate.ps >>$@.ps.new + gs -sDEVICE=nullpage -dBATCH=1 -q $@.ps.new $o + +ui-plan-%.ppm: ours.dgram-%.pa.segenco.ppm pnmcrop -verbose 2>&1 <$< >$@.1.new | tee ui-plan-$*.crop-info pnmflip <$@.1.new -ccw >$@.2.new pnmpad <$@.2.new -white -l5 -r5 -t5 -b5 $o @@ -178,12 +186,9 @@ ui-plan-%.ppm: ours.dgram-%.pa.segenco.ppm Makefile ui-plan-%.crop-info: ui-plan-%.ppm @: -ui-plan-%.overlay-info: ui-plan-%.crop-info ours.redacted.for-ui Makefile - perl -ne 'm/^pnmcrop: cropping (\d+) \w+ off the (\w+)$$/' \ - -e ' and print "layout-dgram-cropped $$2 $$1\n";' \ - $@.new - egrep '^[^#]' >$@.new - mv -f $@.new $@ +ui-plan-%.overlay-info: genoverlayinfo \ + ui-plan-%.crop-info ours.redacted.for-ui ui-plan-%.matrix-info + ./$^ $(PLANUI_HEIGHT) $(PLANUI_PSDPI) $o subseg2display.o compose-segenco.o: segcmap.h diff --git a/layout/genoverlayinfo b/layout/genoverlayinfo new file mode 100755 index 0000000..69574ea --- /dev/null +++ b/layout/genoverlayinfo @@ -0,0 +1,60 @@ +#!/usr/bin/perl + +use IO::Handle; + +@ARGV==5 or die; +($cropinfo,$forui,$matrixinfo, $height,$psdpi)=@ARGV; + +open M, $matrixinfo or die $!; +$!=0; @matrix= ; +@matrix==6 or die $!; +map { die "$_ ?" unless m/^[-0-9.]+$/; } @matrix; +M->error and die $!; +close M or die $!; + +# inverting the matrix ?? +$d= 0; +for ($i=0; $i<4; $i+=2) { + $d += $matrix[$i]*$matrix[$i]; +} +$d= 1/$d; +for ($i=0; $i<4; $i++) { + $matrix[$i] *= $d; +} +$matrix[1] *= -1; +$matrix[2] *= -1; + +print STDERR join("\n",@matrix),"\n"; + +open C, $cropinfo or die $!; +while () { + next unless m/^pnmcrop: cropping (\d+) \w+ off the (\w+)$/; + $crop{$2}= $1; +} +C->error and die $!; +close C or die $!; + +open U, $forui or die $!; +while () { + chomp; + next unless m/^[^\#]/; + m/^(layout-subseg-end \w+ \w \w) ([0-9.]+) ([0-9.]+)$/ or die "$_ ?"; + ($lhs, $xup,$yup) = ($1,$2,$3); + + $xup -= $matrix[4]; + $yup -= $matrix[5]; + + $x = $xup*$matrix[0] + $yup*$matrix[2]; + $y = $xup*$matrix[1] + $yup*$matrix[3]; + + $x *= $psdpi / 72.0; + $y *= $psdpi / 72.0; + + $y= $height - $y; +# $x -= $crop{'left'}; +# $y -= $crop{'top'}; + + printf "%s %d %d\n", $lhs, $x, $y or die $!; +} +U->error and die $!; +close U or die $!; diff --git a/layout/informat.txt b/layout/informat.txt index 834a303..6b329de 100644 --- a/layout/informat.txt +++ b/layout/informat.txt @@ -324,6 +324,8 @@ Special comments in PostScript: from the loc X0,Y0,A0 to X1,Y1,A1. I is a counter which starts at 0 and is simply there to help cross-reference between various programs and formats. + %L matrix begin + %L matrix end Scope S is O! when defining object or part O diff --git a/layout/layout b/layout/layout index f131517..1186a78 100755 --- a/layout/layout +++ b/layout/layout @@ -1757,6 +1757,7 @@ sub cmd__one { o("%!\n". " /lf /Courier-New findfont $lmu_marktpt scalefont def\n". " /sf /Courier-Bold findfont $lmu_segtpt scalefont def\n". + "%L matrix begin\n". "$shiftrotate". " gsave\n"); @@ -1768,6 +1769,8 @@ if ($page_x || $page_y) { o(" -$ps_page_xmul $page_x mul -$ps_page_ymul $page_y mul translate\n". " $ptscale $ptscale scale\n"); +o("%L matrix end\n"); + newctx(); open DEBUG, ($debug ? ">&2" : ">/dev/null") or die $!; diff --git a/layout/make-dgram-make b/layout/make-dgram-make index 44c9002..18d0b2d 100755 --- a/layout/make-dgram-make +++ b/layout/make-dgram-make @@ -8,5 +8,15 @@ $stem.dgram-$dgram.run-layout: $stem.d4 layout $stem.dgram.m printf '#!/bin/sh -ex\n\$(LAYOUT) "\$\$@" %s \$<\n' "$args" >\$@.new chmod +x \$@.new && mv -f \$@.new \$@ +$stem.dgram-$dgram.matrix-info: \ + ours.dgram-%.p0.segenco.ps matrix-demonstrate.ps +END + cat <<'END' + sed -n '1,/^%L matrix here/p' matrix-demonstrate.ps >$@.ps.new + sed -n '/^%L matrix begin/,/^%L matrix end/p' $< >>$@.ps.new + sed -e '1,/^%L matrix here/d' matrix-demonstrate.ps >>$@.ps.new + gs -sDEVICE=nullpage -dBATCH=1 -q $@.ps.new $o + + END done diff --git a/layout/matrix-demonstrate.ps b/layout/matrix-demonstrate.ps new file mode 100644 index 0000000..afec16c --- /dev/null +++ b/layout/matrix-demonstrate.ps @@ -0,0 +1,22 @@ +%! + +% Hideous linear algebra +% may or may not be right but hacked until it worked +% with genoverlayinfo + +/printflt { (......................) cvs print (\n) print } bind def + + 0 0 transform + 0 1 dtransform + 1 0 dtransform + +%L matrix here + + idtransform + exch printflt printflt + + idtransform + exch printflt printflt + + itransform + exch printflt printflt diff --git a/layout/redactgraph.c b/layout/redactgraph.c index f7a351f..2f38ebc 100644 --- a/layout/redactgraph.c +++ b/layout/redactgraph.c @@ -875,8 +875,7 @@ static void printforui(void) { edgeend->edge->subseg->segment->segname, edgeend->edge->subseg->movfeat, edgeend->edge->movpos, - node->x * 72.0 / PLANUI_PSDPI, - node->y * 72.0 / PLANUI_PSDPI); + node->x, node->y); } } }