#!/usr/bin/perl -w # TROWEL - To Render Our Wonderful Excellent Lightvectors # Use TROWEL to apply cement # # Script to cement multiple images using different weights # # requires: # cementinit, cementi, plm2pnm (executables), and cement.txt in the directory # cement.txt can have comments, and it can also have unused lightvectors, e.g. # v001 # with no cement weights after it is ignored # (this is so you can ls v???.ppm > cement.txt, or the like and then just # put weights on the ones you want to use). # # bug reports, etc: mann@eecg.toronto.edu # ############################################################# use strict; #To try and stop me from installing bugs my $filterFilePrefix="/usr/local/filters/filt"; my($lineOfInput,@inputParams); # inputparams is a list of lists, each sublist # containing picturename and the 3 weights. Yes # it hurts readability, but it gives me so much # more flexibility later... open(COMMANDFILE,") { # Parse the Blur Option "b" my $isletterb = 0; my $positionOfB; my $blursize; # blur radius # sed out comments in line, otherwise includes blur in comments. $lineOfInput =~ s/#.*//; # ".*" is the operator for what "*" in shell does printf($lineOfInput); if ($lineOfInput =~ /b/){ $isletterb = 1; # isletterb is boolean variable for existence of letter b $positionOfB = index($lineOfInput,"b"); $blursize = substr($lineOfInput,$positionOfB+2); chomp $blursize; $blursize =~ s/\s//; # sed out any spaces in blursize $lineOfInput = substr($lineOfInput,0,$positionOfB); } # $lineOfInput =~ s/^(.*?)#(.*)$/$1/; not sure this line is needed if ($lineOfInput =~ /^([\S]+)\s+([\.|\d|-]+)\s+([\.|\d|-]+)\s+([\.|\d|-]+)/ ) { if($isletterb == 1) { #cement.txt file has b and number $inputParams[$vectorIndex] -> [0] = $1; $inputParams[$vectorIndex] -> [4] = $blursize; #this is a file to be blurred } else { $inputParams[$vectorIndex] -> [0] = $1; $inputParams[$vectorIndex] -> [4] = 0; } $inputParams[$vectorIndex] -> [1] = $2; $inputParams[$vectorIndex] -> [2] = $3; $inputParams[$vectorIndex] -> [3] = $4; $vectorIndex++; } elsif (!($lineOfInput =~ /^\s*$/)) { #Allow blank lines once comments are stripped, but complain about other imparsables printf "Bad input line:\n$lineOfInput"; } } $numVectors = $vectorIndex; $vectorIndex = 0; ### if we are to blur the first file if ($inputParams[0]->[4] != 0){ # blur the first file; my $cementinitcommand = "cementinit $inputParams[0]->[0] $inputParams[0]->[1] $inputParams[0]->[2] $inputParams[0]->[3] -o trowel_out.toBeBlurred.plm\n"; system($cementinitcommand); my $blursize = $inputParams[0]->[4]; my $filterfile = $filterFilePrefix.$blursize.".txt"; my $blurcommand = "blur trowel_out.toBeBlurred.plm $filterfile trowel_out.plm"; print "yes blurring $inputParams[0]->[0] "; print "\n$blurcommand\n\n"; system($blurcommand); } ### if we are not to blur the first file else{ print "not blurring $inputParams[0]->[0] "; my $cementinitcommand = "cementinit $inputParams[0]->[0] $inputParams[0]->[1] $inputParams[0]->[2] $inputParams[0]->[3] -o trowel_out.plm\n"; system($cementinitcommand); } ### deal with the rest of the files for ($vectorIndex=1;$vectorIndex<$numVectors;$vectorIndex++) { if ($inputParams[$vectorIndex]->[4] != 0) { # we should blur this file my $cementinitcommand = "cementinit $inputParams[$vectorIndex]->[0] $inputParams[$vectorIndex]->[1] $inputParams[$vectorIndex]->[2] $inputParams[$vectorIndex]->[3] -o trowel_out.toBeBlurred.plm\n"; system($cementinitcommand); my $blursize = $inputParams[$vectorIndex]->[4]; my $filterfile = $filterFilePrefix.$blursize.".txt"; my $blurcommand = "blur trowel_out.toBeBlurred.plm $filterfile tmp.plm"; print "yes blurring $inputParams[$vectorIndex]->[0] "; print "\nblur command = $blurcommand\n\n"; system($blurcommand); my $cementiCommand = "cementi trowel_out.plm tmp.plm $inputParams[$vectorIndex]->[1] $inputParams[$vectorIndex]->[2] $inputParams[$vectorIndex]->[3] \n"; print "\n\n$cementiCommand\n\n"; system($cementiCommand); } else{ ## we shouldn't blur this file print "not blurring image $inputParams[$vectorIndex]->[0] "; my $inFile = $inputParams[$vectorIndex]->[0]; system("cementi trowel_out.plm $inFile $inputParams[$vectorIndex]->[1] $inputParams[$vectorIndex]->[2] $inputParams[$vectorIndex]->[3] \n"); } } system("plm2pnm trowel_out.plm -o trowel_out.ppm\n");