--- ray/src/util/genBSDF.pl 2016/09/16 20:01:29 2.68 +++ ray/src/util/genBSDF.pl 2017/02/07 19:53:59 2.74 @@ -1,5 +1,5 @@ #!/usr/bin/perl -w -# RCSid $Id: genBSDF.pl,v 2.68 2016/09/16 20:01:29 greg Exp $ +# RCSid $Id: genBSDF.pl,v 2.74 2017/02/07 19:53:59 greg Exp $ # # Compute BSDF based on geometry and material description # @@ -21,6 +21,7 @@ if ($#ARGV == 1 && "$ARGV[0]" =~ /^-rec/) { @ARGV = ; close MYAVH; chomp @ARGV; + $recovery = 0; if (open(MYPH, "< $td/phase.txt")) { while () { chomp($recovery = $_); @@ -83,7 +84,7 @@ if ($windoz) { $rmtmp = "rm -rf $td"; } my @savedARGV = @ARGV; -my $rfluxmtx = "rfluxmtx -ab 5 -ad 700 -lw 3e-6"; +my $rfluxmtx = "rfluxmtx -ab 5 -ad 700 -lw 3e-6 -w-"; my $wrapper = "wrapBSDF"; my $tensortree = 0; my $ttlog2 = 4; @@ -169,7 +170,7 @@ if ( !defined $recovery ) { } } if ( $#dim != 5 ) { - @dim = split ' ', `getbbox -h $radscn`; + @dim = split ' ', `getbbox -h -w $radscn`; } die "Device entirely inside room!\n" if ( $dim[4] >= 0 ); if ( $dim[5] > 1e-5 ) { @@ -200,7 +201,7 @@ if ( !defined $recovery ) { } close MYAVH; # Generate octree - system "oconv -w $radscn > $octree"; + system "oconv -w -f $radscn > $octree"; die "Could not compile scene\n" if ( $? ); # Add MGF description if requested if ( $geout ) { @@ -248,13 +249,6 @@ if ( !defined $recovery ) { } print STDERR "Recover using: $0 -recover $td\n"; } -# Open unbuffered progress file -open(MYPH, ">> $td/phase.txt"); -{ - my $ofh = select MYPH; - $| = 1; - select $ofh; -} $curphase = 0; # Create data segments (all the work happens here) if ( $tensortree ) { @@ -274,14 +268,34 @@ exec $rmtmp; # Function to determine if next phase should be skipped or recovered sub do_phase { $curphase++; - if (defined $recovery) { - if ($recovery > $curphase) { return 0; } - if ($recovery == $curphase) { return -1; } + if ( defined $recovery ) { + if ( $recovery > $curphase ) { return 0; } + if ( $recovery == $curphase ) { return -1; } } + open(MYPH, ">> $td/phase.txt"); print MYPH "$curphase\n"; + close MYPH; return 1; } +# Check if we are in active phase (not skipping parts) +sub active_phase { + if ( defined $recovery ) { + if ( $recovery > $curphase ) { return 0; } + if ( $recovery == $curphase ) { return -1; } + } + return 1; +} + +# Function to run program and check output if in active phase +sub run_check { + if ( !active_phase() ) { return; } + my $cmd = shift; + # print STDERR "Running: $cmd\n"; + system $cmd; + die "Failure running: $cmd\n" if ( $? ); +} + #++++++++++++++ Tensor tree BSDF generation ++++++++++++++# sub do_tree_bsdf { @@ -294,9 +308,8 @@ sub do_tree_bsdf { # Call rfluxmtx and process tensor tree BSDF for the given direction sub do_ttree_dir { my $forw = shift; - my $r = do_phase(); - if (!$r) { return; } - $r = ($r < 0) ? " -r" : ""; + my $dop = do_phase(); + my $r = ($dop < 0) ? " -r" : ""; my $cmd; if ( $tensortree == 3 ) { # Isotropic BSDF @@ -335,9 +348,11 @@ sub do_ttree_dir { $cmd = "$rfluxmtx$r -h -ff $sender $receivers -i $octree"; } } - # print STDERR "Starting: $cmd\n"; - system $cmd; - die "Failure running rfluxmtx" if ( $? ); + if ( $dop ) { + # print STDERR "Running: $cmd\n"; + system $cmd; + die "Failure running rfluxmtx" if ( $? ); + } ttree_out($forw); } # end of do_ttree_dir() @@ -420,27 +435,27 @@ sub ttree_comp { $cmd .= " -of $src " . "| rttree_reduce$avg -h -ff -t $pcull -r $tensortree -g $ttlog2"; } - # print STDERR "Running: $cmd\n"; - system "$cmd > $dest"; - die "Failure running rttree_reduce" if ( $? ); + run_check "$cmd > $dest"; } else { if ($windoz) { $cmd = "rcollate -ho -oc 1 $src | " . $cmd ; } else { $cmd .= " $src"; } - open(DATOUT, "> $dest"); - print DATOUT "{\n"; - close DATOUT; - # print STDERR "Running: $cmd\n"; - system "$cmd >> $dest"; - die "Failure running rcalc" if ( $? ); - open(DATOUT, ">> $dest"); - for (my $i = ($tensortree==3)*$ns*$ns*$ns/2; $i-- > 0; ) { - print DATOUT "0\n"; + if ( active_phase() ) { + open(DATOUT, "> $dest"); + print DATOUT "{\n"; + close DATOUT; + # print STDERR "Running: $cmd\n"; + system "$cmd >> $dest"; + die "Failure running rcalc" if ( $? ); + open(DATOUT, ">> $dest"); + for (my $i = ($tensortree==3)*$ns*$ns*$ns/2; $i-- > 0; ) { + print DATOUT "0\n"; + } + print DATOUT "}\n"; + close DATOUT; } - print DATOUT "}\n"; - close DATOUT; } if ( "$spec" ne "$curspec" ) { $wrapper .= " -s $spec"; @@ -463,15 +478,15 @@ sub do_matrix_bsdf { # Call rfluxmtx and process tensor tree BSDF for the given direction sub do_matrix_dir { my $forw = shift; - my $r = do_phase(); - if (!$r) { return; } - $r = ($r < 0) ? " -r" : ""; - my $cmd; + my $dop = do_phase(); + my $r = ($dop < 0) ? " -r" : ""; my $sender = ($bsender,$fsender)[$forw]; - $cmd = "$rfluxmtx$r -fd $sender $receivers -i $octree"; - # print STDERR "Starting: $cmd\n"; - system $cmd; - die "Failure running rfluxmtx" if ( $? ); + my $cmd = "$rfluxmtx$r -fd $sender $receivers -i $octree"; + if ( $dop ) { + # print STDERR "Running: $cmd\n"; + system $cmd; + die "Failure running rfluxmtx" if ( $? ); + } matrix_out($forw); } # end of do_matrix_dir() @@ -515,10 +530,8 @@ sub matrix_comp { } elsif ("$spec" eq "CIE-Z") { $cmd .= " -c 0.0241 0.1229 0.8530"; } - $cmd .= " $src | rcollate -ho -oc 145"; - # print STDERR "Running: $cmd\n"; - system "$cmd > $dest"; - die "Failure running rmtxop" if ( $? ); + $cmd .= " $src | getinfo -"; + run_check "$cmd > $dest"; if ( "$spec" ne "$curspec" ) { $wrapper .= " -s $spec"; $curspec = $spec;