[37] | 1 | #!/usr/bin/perl |
---|
| 2 | # |
---|
| 3 | # pvrip: Takes a vrip file (output), conf file, bound mesh, res in |
---|
| 4 | # meters, max voxels per chunk, and loadlimit file. |
---|
| 5 | # |
---|
| 6 | # All of these are the same as vrip, except the loadlimit file, |
---|
| 7 | # which lists the desired load on the various parallel machines. |
---|
| 8 | # It looks something like: |
---|
| 9 | # radiance 4 |
---|
| 10 | # maglio 3 |
---|
| 11 | # cesello 2.2 |
---|
| 12 | # blackout 1.4 |
---|
| 13 | # lambert 7 |
---|
| 14 | # wavelet 1.2 |
---|
| 15 | # blueridge 1.4 |
---|
| 16 | # |
---|
| 17 | # You can edit the numbers while it's running, but you cannot |
---|
| 18 | # change the order of the list, or add/remove machines while |
---|
| 19 | # it's running. |
---|
| 20 | |
---|
| 21 | sub printUsage { |
---|
| 22 | print STDERR "\n"; |
---|
| 23 | print STDERR "Usage: pvrip <vri_file> <ply_file> <conf_file> <boundmesh> \\\n". |
---|
| 24 | " <res(m)> <max_voxels_per_chunk> <loadlimit_file> [options]\n"; |
---|
| 25 | print STDERR "e.g.: pvrip v2mm.vri v2mm.ply v.conf v.bbox.ply 2.0 40M loadlimit\n"; |
---|
| 26 | print STDERR " or: pvrip v5mm.vri v5mm.ply v.conf v.conf 5.0 9500K ~/loadlimit \\\n"; |
---|
| 27 | print STDERR " -noxload -logdir logs -subvoldir subvols\n"; |
---|
| 28 | print STDERR "\n"; |
---|
| 29 | print STDERR "Options:\n"; |
---|
| 30 | print STDERR " -rampscale <s> Where s is the scale-factor for the ramp in\n"; |
---|
| 31 | print STDERR " vrip. If you do not supply a rampscale,\n"; |
---|
| 32 | print STDERR " pvrip will use (2500*voxelsize) as the\n"; |
---|
| 33 | print STDERR " default rampscale.\n"; |
---|
| 34 | print STDERR " -norampscale Don't pass a rampscale to vrip. (By default,\n"; |
---|
| 35 | print STDERR " pvrip passes a rampscale that overrides .vriprc).\n"; |
---|
| 36 | print STDERR " -logdir <dir> Where dir is the directory to store all the\n"; |
---|
| 37 | print STDERR " log files (cmd, stdout, stderr for each chunk).\n"; |
---|
| 38 | print STDERR " default logdir is logs_PID (Process ID).\n"; |
---|
| 39 | print STDERR " -subvoldir <dir> Where dir is the directory to store all the\n"; |
---|
| 40 | print STDERR " subvol .conf/.vri/.ply files.\n"; |
---|
| 41 | print STDERR " default subvoldir is subvols_PID.\n"; |
---|
| 42 | print STDERR " -bboxesok Disables the check to see if bboxes are up to date.\n"; |
---|
| 43 | print STDERR " Normally, bboxes are updated if they are older than the\n"; |
---|
| 44 | print STDERR " conf file, since changing the conf transforms will outdate\n"; |
---|
| 45 | print STDERR " the bbox. But if you're *sure* your bboxes are ok, this\n"; |
---|
| 46 | print STDERR " will speed it up.\n"; |
---|
| 47 | print STDERR " -passtovrip \"X\" Will pass the string X to each vrip (at the end of the\n"; |
---|
| 48 | print STDERR " of the command line)\n"; |
---|
| 49 | print STDERR " -passtovripsurf \"X\" Will pass the string X to each vripsurf (at the end\n"; |
---|
| 50 | print STDERR " of the command line)\n"; |
---|
| 51 | print STDERR " -xload Will pop up xload windows for each host.\n"; |
---|
| 52 | print STDERR " -noxload Will not pop up xload windows for each host.\n"; |
---|
| 53 | print STDERR " (default)\n"; |
---|
| 54 | print STDERR " -merge Will run plymerge/plyshared at the end to merge\n"; |
---|
| 55 | print STDERR " subvols into a single mesh. (default)\n"; |
---|
| 56 | print STDERR " -nomerge Will not run plymerge/plyshared.\n"; |
---|
| 57 | print STDERR " -crunch Will run plycrunch on the subvols and final mesh,\n"; |
---|
| 58 | print STDERR " and generate .set files. (default)\n"; |
---|
| 59 | print STDERR " -nocrunch Will not run plycrunch.\n"; |
---|
| 60 | print STDERR " -clean Will run plyclean -defaults on the final shared mesh,\n"; |
---|
| 61 | print STDERR " to remove slivers (~37% less tris)\n"; |
---|
| 62 | print STDERR " -noclean Will not run plyclean.\n"; |
---|
| 63 | print STDERR "\n"; |
---|
| 64 | print STDERR "Notes:\n"; |
---|
| 65 | print STDERR " - max_voxels_per_chunk recognizes K and M, eg, 20K, 50M\n"; |
---|
| 66 | print STDERR " - The loadlimit file should look like this:\n"; |
---|
| 67 | print STDERR "radiance 6.5\n"; |
---|
| 68 | print STDERR "lambert 3.5\n"; |
---|
| 69 | print STDERR "phong 1.2\n"; |
---|
| 70 | print STDERR " - pvrip will not start a job on a machine unless\n"; |
---|
| 71 | print STDERR " the limit is larger than 1.\n"; |
---|
| 72 | print STDERR " - you can adjust the numbers in loadlimit while\n"; |
---|
| 73 | print STDERR " pvrip is running, but you cannot add, delete,\n"; |
---|
| 74 | print STDERR " or reorder the host lines.\n"; |
---|
| 75 | print STDERR "\n"; |
---|
| 76 | |
---|
| 77 | exit(-1); |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | if ($#ARGV < 6) { |
---|
| 81 | &printUsage(); |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | $VRIFILE = $ARGV[0]; |
---|
| 85 | $PLYFILE = $ARGV[1]; |
---|
| 86 | $CONFFILE = $ARGV[2]; |
---|
| 87 | $BOUNDFILE = $ARGV[3]; |
---|
| 88 | $RES = $ARGV[4]; |
---|
| 89 | $MAXVOX = $ARGV[5]; |
---|
| 90 | $LOADFILE = $ARGV[6]; |
---|
| 91 | |
---|
| 92 | # Default values |
---|
| 93 | $LOGDIR = "logs_$$"; |
---|
| 94 | $XLOADSTR = ""; |
---|
| 95 | $SUBVOLDIR = "subvols_$$"; |
---|
| 96 | $DOCRUNCH = 1; |
---|
| 97 | $DOCLEAN = 1; |
---|
| 98 | $DOMERGE = 1; |
---|
| 99 | $BBOXESOKSTR = ""; |
---|
| 100 | $RAMPSCALE = 2500 * $RES; |
---|
| 101 | $PASSTOVRIP = ""; |
---|
| 102 | $PASSTOVRIPSURF = ""; |
---|
| 103 | |
---|
| 104 | # Parse the -arguments |
---|
| 105 | $currarg = 7; |
---|
| 106 | while ($currarg <= $#ARGV) { |
---|
| 107 | if ($ARGV[$currarg] eq "-logdir" || |
---|
| 108 | $ARGV[$currarg] eq "-ld") { |
---|
| 109 | $LOGDIR = $ARGV[$currarg+1]; |
---|
| 110 | $currarg +=2; |
---|
| 111 | if ($LOGDIR eq "") { |
---|
| 112 | print STDERR "Error: no logdir???\n\n"; |
---|
| 113 | &printUsage(); |
---|
| 114 | } |
---|
| 115 | } elsif ($ARGV[$currarg] eq "-subvoldir" || |
---|
| 116 | $ARGV[$currarg] eq "-sd") { |
---|
| 117 | $SUBVOLDIR = $ARGV[$currarg+1]; |
---|
| 118 | $currarg +=2; |
---|
| 119 | if ($SUBVOLDIR eq "") { |
---|
| 120 | print STDERR "Error: no subvoldir???\n\n"; |
---|
| 121 | &printUsage(); |
---|
| 122 | } |
---|
| 123 | } elsif ($ARGV[$currarg] eq "-rampscale" || |
---|
| 124 | $ARGV[$currarg] eq "-rs") { |
---|
| 125 | $RAMPSCALE = $ARGV[$currarg+1]; |
---|
| 126 | $currarg +=2; |
---|
| 127 | if ($RAMPSCALE eq "") { |
---|
| 128 | print STDERR "Error: no rampscale???\n\n"; |
---|
| 129 | &printUsage; |
---|
| 130 | } |
---|
| 131 | } elsif ($ARGV[$currarg] eq "-passtovrip") { |
---|
| 132 | $PASSTOVRIP .= $ARGV[$currarg+1]; |
---|
| 133 | $currarg +=2; |
---|
| 134 | } elsif ($ARGV[$currarg] eq "-passtovripsurf") { |
---|
| 135 | $PASSTOVRIPSURF .= $ARGV[$currarg+1]; |
---|
| 136 | $currarg +=2; |
---|
| 137 | } elsif ($ARGV[$currarg] eq "-norampscale") { |
---|
| 138 | # Turn off the default rampscale |
---|
| 139 | undef($RAMPSCALE); |
---|
| 140 | $currarg++; |
---|
| 141 | } elsif ($ARGV[$currarg] eq "-bboxesok") { |
---|
| 142 | $BBOXESOKSTR = " -bboxesok "; |
---|
| 143 | $currarg++; |
---|
| 144 | } elsif ($ARGV[$currarg] eq "-noxload") { |
---|
| 145 | $XLOADSTR = " -noxload "; |
---|
| 146 | $currarg++; |
---|
| 147 | } elsif ($ARGV[$currarg] eq "-xload") { |
---|
| 148 | $XLOADSTR = " -xload "; |
---|
| 149 | $currarg++; |
---|
| 150 | } elsif ($ARGV[$currarg] eq "-crunch") { |
---|
| 151 | $DOCRUNCH = 1; |
---|
| 152 | $currarg++; |
---|
| 153 | } elsif ($ARGV[$currarg] eq "-nocrunch") { |
---|
| 154 | $DOCRUNCH = 0; |
---|
| 155 | $currarg++; |
---|
| 156 | } elsif ($ARGV[$currarg] eq "-clean") { |
---|
| 157 | $DOCLEAN = 1; |
---|
| 158 | $currarg++; |
---|
| 159 | } elsif ($ARGV[$currarg] eq "-noclean") { |
---|
| 160 | $DOCLEAN = 0; |
---|
| 161 | $currarg++; |
---|
| 162 | } elsif ($ARGV[$currarg] eq "-merge") { |
---|
| 163 | $DOMERGE = 1; |
---|
| 164 | $currarg++; |
---|
| 165 | } elsif ($ARGV[$currarg] eq "-nomerge") { |
---|
| 166 | $DOMERGE = 0; |
---|
| 167 | $currarg++; |
---|
| 168 | } else { |
---|
| 169 | print STDERR "Error: Unhandled arg $ARGV[$currarg].\n\n"; |
---|
| 170 | &printUsage(); |
---|
| 171 | } |
---|
| 172 | } |
---|
| 173 | |
---|
| 174 | # Allow k, K, m, M for MAXVOX (e.g. 40M) |
---|
| 175 | $MAXVOX =~ s/k/000/g; $MAXVOX =~ s/K/000/g; |
---|
| 176 | $MAXVOX =~ s/m/000000/g; $MAXVOX =~ s/M/000000/g; |
---|
| 177 | |
---|
| 178 | |
---|
| 179 | # Make sure subvoldir is usable, |
---|
| 180 | # And clean it out if it already exists |
---|
| 181 | if (-e $SUBVOLDIR) { |
---|
| 182 | if (-d $SUBVOLDIR) { |
---|
| 183 | -x $SUBVOLDIR || die "Error: subvoldir $SUBVOLDIR does not have execute permissions\n"; |
---|
| 184 | -w $SUBVOLDIR || die "Error: subvoldir $SUBVOLDIR does not have write permissions\n"; |
---|
| 185 | |
---|
| 186 | # print "Note, loadbalance using existing subvoldir $SUBVOLDIR...\n"; |
---|
| 187 | # Clear any old loadbalance logfiles |
---|
| 188 | $cmd = "cd $SUBVOLDIR; /bin/ls | /bin/grep 'subvol' | ". |
---|
| 189 | "/bin/xargs /bin/rm -f\n"; |
---|
| 190 | print "} Clearing old subvol files...."; |
---|
| 191 | system $cmd; |
---|
| 192 | print "Done.\n"; |
---|
| 193 | } else { |
---|
| 194 | print STDERR "Error: loadbalance: subvoldir $SUBVOLDIR exists, \n". |
---|
| 195 | "and is not a directory.\n"; |
---|
| 196 | printUsage(); |
---|
| 197 | } |
---|
| 198 | } else { |
---|
| 199 | # make subvoldir |
---|
| 200 | $errmsg = `mkdir $SUBVOLDIR\n`; |
---|
| 201 | if ($?) { |
---|
| 202 | die "Error: Could not mkdir $SUBVOLDIR\n"; |
---|
| 203 | } |
---|
| 204 | } |
---|
| 205 | |
---|
| 206 | # Run vripsplit |
---|
| 207 | $cmd = "vripsplit $CONFFILE $BOUNDFILE $RES $MAXVOX -subvoldir $SUBVOLDIR $BBOXESOKSTR\n"; |
---|
| 208 | $timecmd = &timecmd($cmd); |
---|
| 209 | print "} $cmd"; |
---|
| 210 | system $timecmd; |
---|
| 211 | !$? || die "Error: vripsplit returned an error. aborting.\n"; |
---|
| 212 | |
---|
| 213 | # Generate command list to vrip |
---|
| 214 | # First set a couple of options for vripsubvollist |
---|
| 215 | if ($DOCRUNCH) { $CRUNCHSTR = " -crunch "; } |
---|
| 216 | else {$CRUNCHSTR = "";} |
---|
| 217 | if (defined($RAMPSCALE)) { |
---|
| 218 | $RAMPSCALESTR = " -rampscale $RAMPSCALE "; |
---|
| 219 | } else { |
---|
| 220 | $RAMPSCALESTR = ""; |
---|
| 221 | } |
---|
| 222 | |
---|
| 223 | # Pass args blindly to vrip/vripsurf? |
---|
| 224 | $PASS_STR = ""; |
---|
| 225 | if ($PASSTOVRIP ne "") { |
---|
| 226 | $PASS_STR .= "-passtovrip \"$PASSTOVRIP\" "; |
---|
| 227 | } |
---|
| 228 | if ($PASSTOVRIPSURF ne "") { |
---|
| 229 | $PASS_STR .= "-passtovripsurf \"$PASSTOVRIPSURF\" "; |
---|
| 230 | } |
---|
| 231 | |
---|
| 232 | |
---|
| 233 | # Call vripsubvollist to actually generate the commands |
---|
| 234 | $cmd = "find $SUBVOLDIR | grep subvol | grep .conf | sort | ". |
---|
| 235 | "/bin/xargs vripsubvollist $CRUNCHSTR $RAMPSCALESTR $PASS_STR $RES > commands\n"; |
---|
| 236 | print "} $cmd"; |
---|
| 237 | |
---|
| 238 | system $cmd; |
---|
| 239 | !$? || die "Error: vripsubvollist returned an error. aborting.\n"; |
---|
| 240 | |
---|
| 241 | # Figure out how many subvol pieces there shall be |
---|
| 242 | $cmd = "wc -l commands\n"; |
---|
| 243 | $nsvs = int(`$cmd`); |
---|
| 244 | print "Number of subvolumes: $nsvs\n"; |
---|
| 245 | |
---|
| 246 | # Now execute the commands in parallel |
---|
| 247 | $cmd = "loadbalance $LOADFILE commands -logdir $LOGDIR $XLOADSTR\n"; |
---|
| 248 | $timecmd = &timecmd($cmd); |
---|
| 249 | print "} $cmd"; |
---|
| 250 | system $timecmd; |
---|
| 251 | !$? || die "Error: loadbalance returned an error. aborting.\n"; |
---|
| 252 | |
---|
| 253 | # Erase any subvolume .ply files with size 0 |
---|
| 254 | $cmd = "/bin/find $SUBVOLDIR | egrep \"subvol....\.ply\"\n"; |
---|
| 255 | @allplys = `$cmd`; |
---|
| 256 | for ($ii=0; $ii <= $#allplys; $ii++) { |
---|
| 257 | if (-z $allplys[$ii]) { |
---|
| 258 | # Zero size -- nuke |
---|
| 259 | $cmd = "/bin/rm $SUBVOLDIR/$allplys[$ii]\n"; |
---|
| 260 | print "} $cmd"; |
---|
| 261 | system $cmd; |
---|
| 262 | !$? || die "Error: removing zero-size .plys failed. aborting.\n"; |
---|
| 263 | } |
---|
| 264 | } |
---|
| 265 | |
---|
| 266 | # Merge all the ply files into a single ply file, |
---|
| 267 | # which has redundant vertices at the subvolume boundaries: |
---|
| 268 | if ($DOMERGE) { |
---|
| 269 | $cmd = "/bin/find $SUBVOLDIR | /bin/egrep \"subvol....\.ply\" | /bin/xargs plymerge > $PLYFILE.unshared\n"; |
---|
| 270 | $timecmd = &timecmd($cmd); |
---|
| 271 | print "} $cmd"; |
---|
| 272 | system $timecmd; |
---|
| 273 | !$? || die "Error: plymerge returned an error. aborting.\n"; |
---|
| 274 | |
---|
| 275 | # Remove redundant vertices |
---|
| 276 | $cmd = "plyshared < $PLYFILE.unshared > $PLYFILE\n"; |
---|
| 277 | $timecmd = &timecmd($cmd); |
---|
| 278 | print "} $cmd"; |
---|
| 279 | system $timecmd; |
---|
| 280 | !$? || die "Error: plyshared returned an error. aborting.\n"; |
---|
| 281 | |
---|
| 282 | # Plyclean it, to reduce slivers? |
---|
| 283 | if ($DOCLEAN) { |
---|
| 284 | $PLYCLEAN = $PLYFILE; |
---|
| 285 | $PLYCLEAN =~ s/.ply/_clean.ply/g; |
---|
| 286 | $cmd = "plyclean -defaults $PLYFILE > $PLYCLEAN\n"; |
---|
| 287 | $timecmd = &timecmd($cmd); |
---|
| 288 | print "} $cmd"; |
---|
| 289 | system $timecmd; |
---|
| 290 | !$? || die "Error: plyclean returned an error. aborting.\n"; |
---|
| 291 | # otherwise, mv plyclean into place |
---|
| 292 | |
---|
| 293 | $PLYRAW = $PLYFILE; |
---|
| 294 | $PLYRAW =~ s/.ply/_raw.ply/g; |
---|
| 295 | $cmd = "/bin/mv $PLYFILE $PLYRAW; /bin/mv $PLYCLEAN $PLYFILE\n"; |
---|
| 296 | $timecmd = &timecmd($cmd); |
---|
| 297 | print "} $cmd"; |
---|
| 298 | system $timecmd; |
---|
| 299 | !$? || die "Error: mv returned an error. aborting.\n"; |
---|
| 300 | } |
---|
| 301 | |
---|
| 302 | # Plycrunch it? |
---|
| 303 | if ($DOCRUNCH) { |
---|
| 304 | $cmd = "ply2crunchset -l 6 $PLYFILE\n"; |
---|
| 305 | $timecmd = &timecmd($cmd); |
---|
| 306 | print "} $cmd"; |
---|
| 307 | system $timecmd; |
---|
| 308 | !$? || die "Error: ply2crunchset returned an error. aborting.\n"; |
---|
| 309 | } |
---|
| 310 | } |
---|
| 311 | # Done |
---|
| 312 | print "pvrip finished successfully.\n"; |
---|
| 313 | |
---|
| 314 | |
---|
| 315 | ###################################################################### |
---|
| 316 | # helper subroutines |
---|
| 317 | ###################################################################### |
---|
| 318 | |
---|
| 319 | |
---|
| 320 | |
---|
| 321 | sub timecmd { |
---|
| 322 | $loccmd = $_[0]; |
---|
| 323 | # Extract program name from loccmd |
---|
| 324 | # strip args |
---|
| 325 | @words = split(' ', $loccmd); |
---|
| 326 | $locdescr = $words[0]; |
---|
| 327 | # strip path |
---|
| 328 | @words = split('/', $locdescr); |
---|
| 329 | $locdescr = $words[$#words]; |
---|
| 330 | |
---|
| 331 | $ltcmd = ("/usr/bin/time -f \"$locdescr time: user %U, system %S, elapsed %E, ". |
---|
| 332 | "%P CPU, page faults %F\" $loccmd"); |
---|
| 333 | return $ltcmd; |
---|
| 334 | } |
---|