|
From: Peter P. <pr...@us...> - 2007-02-05 18:32:52
|
Update of /cvsroot/pyxida/Pyxida/bin In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30287/bin Modified Files: animateNC.pl Log Message: Updated anim script Index: animateNC.pl =================================================================== RCS file: /cvsroot/pyxida/Pyxida/bin/animateNC.pl,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** animateNC.pl 4 Feb 2007 20:31:05 -0000 1.1 --- animateNC.pl 5 Feb 2007 18:32:39 -0000 1.2 *************** *** 4,42 **** use Getopt::Std; my %params = (); my %pos = (); ! getopts("f:", \%params); ! my $frameTime = 60; ! $frameTime = $params{'f'} if defined $params{'f'}; while (my $line = <>) { if ($line =~ m/\w\w (\d+) .* addr=(.+) c=\[(.+),(.+),(.+),(.+),h(.+)\]/) { ! my ($ts, $addr, $a, $b, $c, $d, $h) = ($1, $2, $3, $4, $5, $6, $7); ! my $dateTS = localtime($ts / 1000); ! #print STDERR "$dateTS $ts $addr $a $b $c $d $h\n"; ! $pos{$addr} = [$a, $b, $c]; #, $d, $h]; ! } } ! print "splot '-'\n"; ! foreach my $addr (keys %pos) { ! my $o = ""; ! foreach my $c (@{$pos{$addr}}) { ! $o .= "$c "; } ! chop $o; ! print "$o\n"; ! } - print "e\n"; - sub fixedNum() { my $num = shift; ! my $result = sprintf("%08d", $num); return $result; } \ No newline at end of file --- 4,85 ---- use Getopt::Std; + use IPC::Open2; my %params = (); my %pos = (); ! getopts("f:d", \%params); ! my $framePeriod = 120; # frame period in sec ! $framePeriod = $params{'f'} if defined $params{'f'}; ! ! my $debug = 0; ! $debug = 1 if defined $params{'d'}; ! ! my $frameFormat="png"; ! ! my $startFrameTS; ! my $frameCounter = 0; ! ! local (*GPIN, *GPOUT); ! open2(\*GPIN, \*GPOUT, "gnuplot"); ! ! print GPOUT "set xrange[-1000:1000]\n"; ! print GPOUT "set yrange[-1000:1000]\n"; ! print GPOUT "set zrange[-1000:1000]\n"; while (my $line = <>) { if ($line =~ m/\w\w (\d+) .* addr=(.+) c=\[(.+),(.+),(.+),(.+),h(.+)\]/) { ! my ($ts, $addr, $a, $b, $c, $d, $h) = ($1 / 1000, $2, $3, $4, $5, $6, $7); ! my $dateTS = localtime($ts); ! print STDERR "$dateTS $ts $addr $a $b $c $d $h\n" if ($debug); ! ! # TODO make the 4D->3D conversion properly ! $pos{$addr} = [$a, $b, $c]; #, $d, $h]; ! ! $startFrameTS = $ts unless defined $startFrameTS; ! ! if ($ts - $startFrameTS > $framePeriod) { ! $frameCounter++; ! &outputFrame($dateTS); ! %pos = (); ! $startFrameTS = $ts; ! print STDERR "Starting a new frame at " . $dateTS . "\n"; ! } ! ! } } ! close GPIN; ! close GPOUT; ! print STDERR "Generating animation...\n"; ! system "mencoder \"mf://*.png\" -mf fps=25 -o pyxida-anim.avi -ovc lavc -lavcopts vcodec=mpeg4"; ! print STDERR "Deleting frames...\n"; ! system "rm pyxida-anim-*.$frameFormat\n"; ! print STDERR "Done.\n"; ! ! sub outputFrame() { ! my $title = shift; ! ! my $filenameCount = &fixedNum($frameCounter); ! print GPOUT "set terminal $frameFormat size 1024,768\n"; ! print GPOUT "set output \'pyxida-anim-$filenameCount.$frameFormat\'\n"; ! print GPOUT "set title \'$title\'\n"; ! print GPOUT "splot '-' notitle\n"; ! foreach my $addr (keys %pos) { ! my $o = ""; ! foreach my $c (@{$pos{$addr}}) { ! $o .= "$c "; ! } ! chop $o; ! print GPOUT "$o\n"; } ! print GPOUT "e\n"; } sub fixedNum() { my $num = shift; ! my $result = sprintf("%05d", $num); return $result; } \ No newline at end of file |