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: pvrip2 <ply_file> <voxelsize> <subvolsize> <loadlimit_file> [options]\n"; |
---|
24 | print STDERR "e.g.: pvrip2 2mm.ply 2 400 loadlimit\n"; |
---|
25 | print STDERR "\n"; |
---|
26 | print STDERR "Options:\n"; |
---|
27 | print STDERR "\n"; |
---|
28 | print STDERR " -bound bbox.ply Will set the bounds to the extent of bbox.ply\n"; |
---|
29 | print STDERR " (not yet implemented... :-o )\n"; |
---|
30 | print STDERR " -new Runs vripnew, doing the .vri from scratch. (default)\n"; |
---|
31 | print STDERR " -update Runs vripupdate, to add more scans.\n"; |
---|
32 | print STDERR " -root rootdir Uses rootdir as the root for the subvol hierarchy\n"; |
---|
33 | print STDERR " (default is ./XXXmm/)\n"; |
---|
34 | # print STDERR " -rampscale <s> Where s is the scale-factor for the ramp in\n"; |
---|
35 | # print STDERR " vrip. If you do not supply a rampscale,\n"; |
---|
36 | # print STDERR " pvrip will use (2500*voxelsize) as the\n"; |
---|
37 | # print STDERR " default rampscale.\n"; |
---|
38 | # print STDERR " -norampscale Don't pass a rampscale to vrip. (By default,\n"; |
---|
39 | # print STDERR " pvrip passes a rampscale that overrides .vriprc).\n"; |
---|
40 | print STDERR " -ramplength <l> Will pass l as the VRIP ramp length.\n"; |
---|
41 | print STDERR " Default is 6 times the voxel size.\n"; |
---|
42 | print STDERR " -passtovrip \"X\" Will pass the string X to each vrip (at the end of the\n"; |
---|
43 | print STDERR " of the command line)\n"; |
---|
44 | print STDERR " -passtovripsurf \"X\" Will pass the string X to each vripsurf (at the end\n"; |
---|
45 | print STDERR " of the command line)\n"; |
---|
46 | print STDERR " -xload Will pop up xload windows for each host.\n"; |
---|
47 | print STDERR " -noxload Will not pop up xload windows for each host.\n"; |
---|
48 | print STDERR " (default)\n"; |
---|
49 | # print STDERR " -merge Will run plymerge/plyshared at the end to merge\n"; |
---|
50 | # print STDERR " subvols into a single mesh. (default)\n"; |
---|
51 | # print STDERR " -nomerge Will not run plymerge/plyshared.\n"; |
---|
52 | print STDERR " -merge Will run pvmerge at the end to merge\n"; |
---|
53 | print STDERR " subvols into a single mesh. (default)\n"; |
---|
54 | print STDERR " -nomerge Will not run pvmerge.\n"; |
---|
55 | print STDERR " -crunch Will run plycrunch on the subvols and final mesh,\n"; |
---|
56 | print STDERR " and generate .set files. (default)\n"; |
---|
57 | print STDERR " -nocrunch Will not run plycrunch.\n"; |
---|
58 | print STDERR " -clean Will run plyclean -defaults on the final shared mesh,\n"; |
---|
59 | print STDERR " to remove slivers (~37% less tris)\n"; |
---|
60 | print STDERR " -noclean Will not run plyclean.\n"; |
---|
61 | print STDERR " -rmtmps Will remove temporary files (.vri, etc). Which makes\n"; |
---|
62 | print STDERR " it harder to debug, but saves disk space.\n"; |
---|
63 | print STDERR "\n"; |
---|
64 | print STDERR "Notes:\n"; |
---|
65 | print STDERR " - The loadlimit file should look like this:\n"; |
---|
66 | print STDERR "radiance 6.5\n"; |
---|
67 | print STDERR "lambert 3.5\n"; |
---|
68 | print STDERR "phong 1.2\n"; |
---|
69 | print STDERR " - pvrip will not start a job on a machine unless\n"; |
---|
70 | print STDERR " the limit is larger than 1.\n"; |
---|
71 | print STDERR " - you can adjust the numbers in loadlimit while\n"; |
---|
72 | print STDERR " pvrip is running, but you cannot add, delete,\n"; |
---|
73 | print STDERR " or reorder the host lines.\n"; |
---|
74 | print STDERR "\n"; |
---|
75 | |
---|
76 | exit(-1); |
---|
77 | } |
---|
78 | |
---|
79 | # Default values |
---|
80 | $VRIPMODE = "update"; |
---|
81 | $BOUNDNAME = ""; |
---|
82 | $SVROOT = ""; |
---|
83 | $XLOADSTR = ""; |
---|
84 | #$DORAMPSCALE = 1; |
---|
85 | $DOCRUNCH = 1; |
---|
86 | $DOCLEAN = 1; |
---|
87 | $DOMERGE = 1; |
---|
88 | $starttime = time; |
---|
89 | |
---|
90 | &printUsage() if ($#ARGV == -1); |
---|
91 | |
---|
92 | # First handle all the -args, removing |
---|
93 | # them from the args list.... |
---|
94 | for ($i=0; $i <= $#ARGV; $i++) { |
---|
95 | $arg = $ARGV[$i]; |
---|
96 | if (substr($arg, 0, 1) eq "-") { |
---|
97 | if ($arg eq "-h") { |
---|
98 | # -h |
---|
99 | &printUsage; |
---|
100 | } elsif ($arg eq "-new") { |
---|
101 | # -new |
---|
102 | $VRIPMODE = "new"; |
---|
103 | splice(@ARGV, $i, 1); $i--; |
---|
104 | } elsif ($arg eq "-update") { |
---|
105 | # -update |
---|
106 | $VRIPMODE = "update"; |
---|
107 | splice(@ARGV, $i, 1); $i--; |
---|
108 | } elsif ($arg eq "-bound") { |
---|
109 | # -bound |
---|
110 | if ($i+1 > $#ARGV) { |
---|
111 | print STDERR "\nErr: -bound needs a second arg.\n"; |
---|
112 | &printUsage(); |
---|
113 | } |
---|
114 | $nextarg = $ARGV[$i+1]; |
---|
115 | $BOUNDNAME = $nextarg; |
---|
116 | splice(@ARGV, $i, 2); $i--; |
---|
117 | } elsif ($arg eq "-root") { |
---|
118 | # -root |
---|
119 | if ($i == $#ARGV) { |
---|
120 | print STDERR "\nErr: -root needs another argument.\n"; |
---|
121 | &printUsage(); |
---|
122 | } |
---|
123 | $SVROOT = $ARGV[$i+1]; |
---|
124 | $SVROOT .= "/" if (substr($SVROOT, -1, 1) ne "/"); |
---|
125 | splice(@ARGV, $i, 2); $i--; |
---|
126 | # } elsif ($arg eq "-rampscale" || |
---|
127 | # $arg eq "-rs") { |
---|
128 | # # -rampscale |
---|
129 | # if ($i == $#ARGV) { |
---|
130 | # print STDERR "\nErr: -rampscale needs another argument.\n"; |
---|
131 | # &printUsage(); |
---|
132 | # } |
---|
133 | # $RAMPSCALE = $ARGV[$i+1]; |
---|
134 | # $DORAMPSCALE = 1; |
---|
135 | # splice(@ARGV, $i, 2); $i--; |
---|
136 | # } elsif ($arg eq "-norampscale" || |
---|
137 | # $arg eq "-nrs") { |
---|
138 | # # -norampscale |
---|
139 | # $DORAMPSCALE = 0; |
---|
140 | # splice(@ARGV, $i, 1); $i--; |
---|
141 | } elsif ($arg eq "-ramplength" || |
---|
142 | $arg eq "-rl") { |
---|
143 | # -ramplength |
---|
144 | if ($i == $#ARGV) { |
---|
145 | print STDERR "\nErr: -ramplength needs another argument.\n"; |
---|
146 | &printUsage(); |
---|
147 | } |
---|
148 | $RAMPLENGTH = $ARGV[$i+1]; |
---|
149 | splice(@ARGV, $i, 2); $i--; |
---|
150 | } elsif ($arg eq "-passtovrip") { |
---|
151 | # -passtovrip |
---|
152 | $PASSTOVRIP = $ARGV[$i+1]; |
---|
153 | splice(@ARGV, $i, 2); $i--; |
---|
154 | } elsif ($arg eq "-passtovripsurf") { |
---|
155 | # -passtovripsurf |
---|
156 | $PASSTOVRIPSURF = $ARGV[$i+1]; |
---|
157 | splice(@ARGV, $i, 2); $i--; |
---|
158 | } elsif ($arg eq "-rmtmps") { |
---|
159 | # -rmtmps |
---|
160 | $DORMTMPS = 1; |
---|
161 | splice(@ARGV, $i, 1); $i--; |
---|
162 | } elsif ($arg eq "-noxload") { |
---|
163 | # -noxload |
---|
164 | $XLOADSTR = " -noxload "; |
---|
165 | splice(@ARGV, $i, 1); $i--; |
---|
166 | } elsif ($arg eq "-xload") { |
---|
167 | # -xload |
---|
168 | $XLOADSTR = " -xload "; |
---|
169 | splice(@ARGV, $i, 1); $i--; |
---|
170 | } elsif ($arg eq "-crunch") { |
---|
171 | $DOCRUNCH = 1; |
---|
172 | splice(@ARGV, $i, 1); $i--; |
---|
173 | } elsif ($arg eq "-nocrunch") { |
---|
174 | $DOCRUNCH = 0; |
---|
175 | splice(@ARGV, $i, 1); $i--; |
---|
176 | } elsif ($arg eq "-clean") { |
---|
177 | $DOCLEAN = 1; |
---|
178 | splice(@ARGV, $i, 1); $i--; |
---|
179 | } elsif ($arg eq "-noclean") { |
---|
180 | $DOCLEAN = 0; |
---|
181 | splice(@ARGV, $i, 1); $i--; |
---|
182 | } elsif ($arg eq "-merge") { |
---|
183 | $DOMERGE = 1; |
---|
184 | splice(@ARGV, $i, 1); $i--; |
---|
185 | } elsif ($arg eq "-nomerge") { |
---|
186 | $DOMERGE = 0; |
---|
187 | splice(@ARGV, $i, 1); $i--; |
---|
188 | } else { |
---|
189 | print STDERR "Error: Unhandled arg $arg.\n\n"; |
---|
190 | &printUsage(); |
---|
191 | } |
---|
192 | } |
---|
193 | } |
---|
194 | |
---|
195 | # Ok, now we should have stripped out all the -args. |
---|
196 | # So let's see if we have the right number of args remaining. |
---|
197 | if ($#ARGV != 3) { |
---|
198 | print STDERR "Err: Expected 5 real args, got ". |
---|
199 | ($#ARGV+1)." args left (after stripping -args).\n"; |
---|
200 | &printUsage(); |
---|
201 | } |
---|
202 | |
---|
203 | $PLYFILE = $ARGV[0]; |
---|
204 | $VOXELSIZE = $ARGV[1]; |
---|
205 | $SVSIZE = $ARGV[2]; |
---|
206 | $LOADFILE = $ARGV[3]; |
---|
207 | |
---|
208 | # Sanity checks on ply file |
---|
209 | die "Error: output ply filename cannot include a path.\n" |
---|
210 | if (index("/", $PLYFILE) > -1); |
---|
211 | |
---|
212 | # compute PLYBASE |
---|
213 | $PLYBASE = $PLYFILE; |
---|
214 | $PLYBASE =~ s/.ply$//; |
---|
215 | die "Error: $PLYFILE doesn't end in .ply?!?\n" if ($PLYBASE eq $PLYFILE); |
---|
216 | |
---|
217 | # Compute vri name from ply name |
---|
218 | $VRIFILE = "$PLYBASE.vri"; |
---|
219 | |
---|
220 | # Add the res to svroot... |
---|
221 | $SVROOT = "$SVROOT"."$SVSIZE"."mm"; |
---|
222 | $LOGDIR = "$SVROOT/logs_$PLYBASE"."_$$"; |
---|
223 | |
---|
224 | ## Set rampscale to default (2500*VOXELSIZE) |
---|
225 | #if ($DORAMPSCALE) { |
---|
226 | # if (!defined ($RAMPSCALE)) { |
---|
227 | # $RAMPSCALE = 2500 * $VOXELSIZE; |
---|
228 | # } |
---|
229 | #} |
---|
230 | |
---|
231 | # Set ramplength to default (6*VOXELSIZE) |
---|
232 | if (!defined ($RAMPLENGTH)) { |
---|
233 | $RAMPLENGTH = 6 * $VOXELSIZE; |
---|
234 | } |
---|
235 | |
---|
236 | |
---|
237 | # Set stdout to autoflush |
---|
238 | $| = 1; |
---|
239 | |
---|
240 | # State check... |
---|
241 | print STDERR ("pvrip2 state check:\n". |
---|
242 | "VRIPMODE: $VRIPMODE,\n". |
---|
243 | "BOUNDNAME: $BOUNDNAME,\n". |
---|
244 | "SVROOT: $SVROOT,\n". |
---|
245 | # "RAMPSCALE: $RAMPSCALE,\n", |
---|
246 | # "DORAMPSCALE: $DORAMPSCALE,\n", |
---|
247 | "RAMPLENGTH: $RAMPLENGTH,\n", |
---|
248 | "XLOADSTR: $XLOADSTR,\n". |
---|
249 | "DOCRUNCH: $DOCRUNCH,\n". |
---|
250 | "DOCLEAN: $DOCLEAN,\n". |
---|
251 | "DOMERGE: $DOMERGE.\n"); |
---|
252 | |
---|
253 | # Make sure that the proper directories exist. |
---|
254 | # Also, if we're in update mode, make sure that we can find the right .vri files. |
---|
255 | # BUGBUG: Second check not implemented yet... |
---|
256 | die "\nError: Subvol root directory $SVROOT does not exist! Aborting...\n\n" if (!-e $SVROOT); |
---|
257 | die "\nError: Subvol root $SVROOT is not a directory!?!?! Aborting...\n\n" if (!-d $SVROOT); |
---|
258 | die "\nError: Subvol root directory $SVROOT is unreadable. Aborting...\n\n" if (!-r $SVROOT); |
---|
259 | die "\nError: Subvol root directory $SVROOT is unwriteable. Aborting...\n\n" if (!-w $SVROOT); |
---|
260 | |
---|
261 | # Figure out @SUBVOLS. Strip out all path stuff... |
---|
262 | $cmd = "find $SVROOT | egrep '^$SVROOT/sv_[^_]+_[^_]+_[^_/]+\$' | sort\n"; |
---|
263 | # print "} $cmd"; |
---|
264 | @SUBVOLS = split(' ', `$cmd`); |
---|
265 | # Strip SVROOT path out of subvols... |
---|
266 | for ($i=0; $i <= $#SUBVOLS; $i++) { |
---|
267 | $SUBVOLS[$i] =~ s|^$SVROOT/||; |
---|
268 | } |
---|
269 | !$? || die "Error: find subvols returned an error. aborting.\n"; |
---|
270 | # print "Subvols: @SUBVOLS\n"; |
---|
271 | |
---|
272 | # Generate command list to vrip |
---|
273 | # (fills the array @COMMANDS) |
---|
274 | $COMMANDSFILE = "$SVROOT/$PLYBASE.commands"; |
---|
275 | |
---|
276 | print STDERR "Generating list of commands ($COMMANDSFILE)....\n"; |
---|
277 | &GenCommands(); |
---|
278 | print STDERR "Done! (Number of subvols to vrip: ".($#COMMANDS+1).")\n"; |
---|
279 | # print "Commands:\n @COMMANDS"; |
---|
280 | open(CMDFILE, ">$COMMANDSFILE"); |
---|
281 | print CMDFILE @COMMANDS; |
---|
282 | close(CMDFILE); |
---|
283 | |
---|
284 | # Create logdir (it shouldn't exist) |
---|
285 | if (!-e $LOGDIR) { |
---|
286 | $cmd = "mkdir $LOGDIR\n"; |
---|
287 | system $cmd; |
---|
288 | (!$?) || die "Error: $cmd failed....\n"; |
---|
289 | } |
---|
290 | |
---|
291 | |
---|
292 | # Now execute the commands in parallel |
---|
293 | sleep 5; # Allow for NFS propagation delay |
---|
294 | # $cmd = "/u/leslie/ply/bin/loadbalance $LOADFILE $COMMANDSFILE -logdir $LOGDIR $XLOADSTR\n"; |
---|
295 | $cmd = "loadbalance $LOADFILE $COMMANDSFILE -logdir $LOGDIR $XLOADSTR\n"; |
---|
296 | $timecmd = &timecmd($cmd); |
---|
297 | print "} $cmd"; |
---|
298 | system $timecmd; |
---|
299 | !$? || die "Error: loadbalance returned an error. aborting.\n"; |
---|
300 | |
---|
301 | # Find all the .ply files with this name in all subdirs |
---|
302 | $findplyscmd = "find $SVROOT | egrep '^$SVROOT/sv_[-0-9]+_[-0-9]+_[-0-9]+/$PLYBASE". |
---|
303 | "_[-0-9]+_[-0-9]+_[-0-9]+.ply\$'"; |
---|
304 | #print $findplyscmd; |
---|
305 | @plys = split(' ', `$findplyscmd`); |
---|
306 | |
---|
307 | # Erase any subvolume .ply files with size 0 |
---|
308 | for ($i=0; $i <= $#plys; $i++) { |
---|
309 | $ply = $plys[$i]; |
---|
310 | if (-e $ply) { |
---|
311 | # File exists |
---|
312 | $psize = -s $ply; |
---|
313 | if ($psize == 0) { |
---|
314 | # And has size zero. nuke. |
---|
315 | $cmd = "/bin/rm $ply\n"; |
---|
316 | print $cmd; |
---|
317 | system $cmd; |
---|
318 | (!$?) || die "Error: Couldn't rm zero-sized $ply...\n"; |
---|
319 | splice(@plys, $i, 1); $i--; |
---|
320 | } |
---|
321 | } |
---|
322 | } |
---|
323 | |
---|
324 | # Merge all the ply files into a single ply file, |
---|
325 | # which has redundant vertices at the subvolume boundaries: |
---|
326 | if ($DOMERGE) { |
---|
327 | # # Plymerge: Generate plymerged version |
---|
328 | # $PLYMERGED = "$PLYBASE.merged.ply"; |
---|
329 | # $cmd = "$findplyscmd | /bin/xargs plymerge > $PLYMERGED\n"; |
---|
330 | # $timecmd = &timecmd($cmd); |
---|
331 | # print "} $cmd"; |
---|
332 | # system $timecmd; |
---|
333 | # !$? || die "Error: plymerge returned an error. aborting.\n"; |
---|
334 | # # merge finished successfully - symlink it in to outfile. |
---|
335 | # `/bin/rm $PLYFILE\n` if (-e $PLYFILE); |
---|
336 | # (!$?) || die "Couldn't rm $PLYFILE. aborting.\n"; |
---|
337 | # $cmd = "ln -s $PLYMERGED $PLYFILE\n"; |
---|
338 | # system($cmd); |
---|
339 | # (!$?) || die "Couldn't $cmd. Aborting.\n"; |
---|
340 | # |
---|
341 | # # Plyshared: Remove redundant vertices |
---|
342 | # $PLYSHARED = "$PLYBASE.merged.shared.ply"; |
---|
343 | # $tolerance = $VOXELSIZE / 100; |
---|
344 | # $cmd = "plyshared -t $tolerance < $PLYMERGED > $PLYSHARED\n"; |
---|
345 | # $timecmd = &timecmd($cmd); |
---|
346 | # print "} $cmd"; |
---|
347 | # system $timecmd; |
---|
348 | # !$? || die "Error: plyshared returned an error. aborting.\n"; |
---|
349 | # # plyshared finished successfully - symlink it in to outfile. |
---|
350 | # `/bin/rm $PLYFILE\n` if (-e $PLYFILE); |
---|
351 | # (!$?) || die "Couldn't rm $PLYFILE. aborting.\n"; |
---|
352 | # $cmd = "ln -s $PLYSHARED $PLYFILE\n"; |
---|
353 | # system($cmd); |
---|
354 | # (!$?) || die "Couldn't $cmd. Aborting.\n"; |
---|
355 | |
---|
356 | # pvmerge: Generate merged version |
---|
357 | $PVMERGED = "$PLYBASE.merged.ply"; |
---|
358 | # changed path temporarily since pvmerge not in CVS - leslie |
---|
359 | $cmd = "~smr/proj/trimesh/bin.Linux/pvmerge -o $PVMERGED $SVROOT/sv_*_*_*"; |
---|
360 | # $cmd = "pvmerge -o $PVMERGED $SVROOT/sv_*_*_*"; |
---|
361 | $timecmd = &timecmd($cmd); |
---|
362 | print "} $cmd\n"; |
---|
363 | system $timecmd; |
---|
364 | !$? || die "Error: pvmerge returned an error. aborting.\n"; |
---|
365 | # merge finished successfully - symlink it in to outfile. |
---|
366 | `/bin/rm $PLYFILE\n` if (-e $PLYFILE); |
---|
367 | (!$?) || die "Couldn't rm $PLYFILE. aborting.\n"; |
---|
368 | $cmd = "ln -s $PVMERGED $PLYFILE\n"; |
---|
369 | system($cmd); |
---|
370 | (!$?) || die "Couldn't $cmd. Aborting.\n"; |
---|
371 | |
---|
372 | |
---|
373 | # Plyclean: Reduce slivers, tiny triangles. |
---|
374 | if ($DOCLEAN) { |
---|
375 | # $PLYCLEANED = "$PLYBASE.merged.shared.cleaned.ply"; |
---|
376 | # $cmd = "plyclean -defaults $PLYSHARED > $PLYCLEANED\n"; |
---|
377 | $PLYCLEANED = "$PLYBASE.merged.cleaned.ply"; |
---|
378 | # $cmd = "/u/leslie/ply/bin/plyclean -defaults $PVMERGED > $PLYCLEANED\n"; |
---|
379 | $cmd = "plyclean -defaults $PVMERGED > $PLYCLEANED\n"; |
---|
380 | $timecmd = &timecmd($cmd); |
---|
381 | print "} $cmd"; |
---|
382 | system $timecmd; |
---|
383 | !$? || die "Error: plyclean returned an error. aborting.\n"; |
---|
384 | # plyclean finished successfully - symlink it in to outfile. |
---|
385 | `/bin/rm $PLYFILE\n` if (-e $PLYFILE); |
---|
386 | (!$?) || die "Couldn't rm $PLYFILE. aborting.\n"; |
---|
387 | $cmd = "ln -s $PLYCLEANED $PLYFILE\n"; |
---|
388 | system($cmd); |
---|
389 | (!$?) || die "Couldn't $cmd. Aborting.\n"; |
---|
390 | } |
---|
391 | |
---|
392 | # Plycrunch it? |
---|
393 | if ($DOCRUNCH) { |
---|
394 | # $cmd = "/u/leslie/ply/bin/ply2crunchset -l 6 $PLYFILE\n"; |
---|
395 | $cmd = "ply2crunchset -l 6 $PLYFILE\n"; |
---|
396 | $timecmd = &timecmd($cmd); |
---|
397 | print "} $cmd"; |
---|
398 | system $timecmd; |
---|
399 | !$? || die "Error: ply2crunchset returned an error. aborting.\n"; |
---|
400 | } |
---|
401 | } |
---|
402 | |
---|
403 | # Almost done. Check logs to see if any *stderr* files are nonzero |
---|
404 | $findstderrscmd = "find $LOGDIR | grep \"_stderr_\" "; |
---|
405 | @errlogs = split(' ', `$findstderrscmd`); |
---|
406 | $NOERRS = 1; |
---|
407 | foreach $errlog (@errlogs) { |
---|
408 | if (-s $errlog != 0) { |
---|
409 | print STDERR "Warning! $errlog was nonzero. That subvol probably failed.\n"; |
---|
410 | $NOERRS = 0; |
---|
411 | } |
---|
412 | } |
---|
413 | |
---|
414 | # Compute and print running time. |
---|
415 | $endtime = time; |
---|
416 | $totaltime = $endtime - $starttime; |
---|
417 | $hours = int($totaltime / 3600); |
---|
418 | $minutes = (int (($totaltime - $hours * 3600) / 60)); |
---|
419 | $minutes = substr("000000$minutes",-2); |
---|
420 | $seconds = (int (($totaltime - ($hours * 3600 + $minutes * 60)) )); |
---|
421 | $seconds = substr("000000$seconds",-2); |
---|
422 | print "Total running time for pvrip2: $hours:$minutes:$seconds"."s.\n"; |
---|
423 | |
---|
424 | |
---|
425 | if ($NOERRS) { |
---|
426 | print "\npvrip finished successfully! (I think). :-)\n\n"; |
---|
427 | } else { |
---|
428 | print "\npvrip finished, but some subvols probably failed. :-(\n\n"; |
---|
429 | } |
---|
430 | |
---|
431 | exit(0); |
---|
432 | |
---|
433 | |
---|
434 | ###################################################################### |
---|
435 | # helper subroutine - timecmd |
---|
436 | ###################################################################### |
---|
437 | |
---|
438 | sub timecmd { |
---|
439 | $loccmd = $_[0]; |
---|
440 | # Extract program name from loccmd |
---|
441 | # strip args |
---|
442 | @words = split(' ', $loccmd); |
---|
443 | $locdescr = $words[0]; |
---|
444 | # strip path |
---|
445 | @words = split('/', $locdescr); |
---|
446 | $locdescr = $words[$#words]; |
---|
447 | |
---|
448 | $ltcmd = ("/usr/bin/time -f \"$locdescr time: user %U, system %S, elapsed %E, ". |
---|
449 | "%P CPU, page faults %F\" $loccmd"); |
---|
450 | return $ltcmd; |
---|
451 | } |
---|
452 | |
---|
453 | ###################################################################### |
---|
454 | # helper subroutine - maketodolines |
---|
455 | # Given two .conf files, it figures out which lines have been |
---|
456 | # added since the last pvrip, and generates a todo list. |
---|
457 | # Assumes that the args, conf and conftodo, have pathnames |
---|
458 | # that work w.r.t. the current working directory. |
---|
459 | ###################################################################### |
---|
460 | |
---|
461 | sub maketodolines |
---|
462 | { |
---|
463 | local($all, $conf) = @_; |
---|
464 | # First step... create associative array listing all the |
---|
465 | # ply files we've seen so far |
---|
466 | %seen = (); |
---|
467 | undef @returnlines; |
---|
468 | if (-e $conf) { |
---|
469 | open(CONF, $conf) || die "Error: couldn't open $conf...\n"; |
---|
470 | while (<CONF>) { |
---|
471 | @cwords = split(' '); |
---|
472 | $cply = $cwords[1]; |
---|
473 | $seen{$cply} = 1; |
---|
474 | } |
---|
475 | close CONF; |
---|
476 | } |
---|
477 | |
---|
478 | # Second step... for every file listed in all, add it |
---|
479 | # to the todolist if it's not already in conf... |
---|
480 | open(ALL, $all) || die "Error: couldn't open $all...\n"; |
---|
481 | while (<ALL>) { |
---|
482 | @cwords = split(' '); |
---|
483 | $cply = $cwords[1]; |
---|
484 | if ($seen{$cply} ne "1") { |
---|
485 | push(@returnlines, $_); |
---|
486 | $seen{$cply} = 1; |
---|
487 | } else { |
---|
488 | # print STDERR "Cool. $cply has been seen.\n"; |
---|
489 | } |
---|
490 | } |
---|
491 | close ALL; |
---|
492 | |
---|
493 | return @returnlines; |
---|
494 | } |
---|
495 | |
---|
496 | ###################################################################### |
---|
497 | # helper subroutine - GenCommands |
---|
498 | # Based on vripsubvollist (part of pvrip version 1) |
---|
499 | # Assumes that $SVROOT, @SUBVOLS have been set |
---|
500 | # Generates the commands to vrip all the subvols |
---|
501 | # Does not generate commands for merging, crunching back |
---|
502 | # together.... |
---|
503 | ###################################################################### |
---|
504 | |
---|
505 | sub GenCommands |
---|
506 | { |
---|
507 | local($svi); |
---|
508 | for ($svi=0; $svi <= $#SUBVOLS; $svi++) { |
---|
509 | print "Checking subvol ".($svi+1)." of ".($#SUBVOLS+1)." \r"; |
---|
510 | $subvol = $SUBVOLS[$svi]; |
---|
511 | |
---|
512 | # Compute some of the files we'll need |
---|
513 | ($dummy, $x, $y, $z) = split('_', $subvol); |
---|
514 | $numstr = "$x"."_$y"."_$z"; |
---|
515 | $ply = "$PLYBASE"."_$numstr.ply"; |
---|
516 | $vri = $ply; |
---|
517 | $vri =~ s/.ply$/.vri/; |
---|
518 | $plybig = $ply; |
---|
519 | $plybig =~ s/.ply$/_beyondbbox.ply/; |
---|
520 | $bbox = "all.bbox.ply"; |
---|
521 | $conf = $ply; |
---|
522 | $conf =~ s/.ply$/.conf/; |
---|
523 | $conftodo = $ply; |
---|
524 | $conftodo =~ s/.ply$/_todo.conf/; |
---|
525 | $automountdir = "/n/".`hostname`; chop $automountdir; |
---|
526 | $cwd = `pwd`; chop $cwd; |
---|
527 | if (substr($cwd, 0, 3) ne "/n/") { |
---|
528 | $cwd = $automountdir.$cwd; |
---|
529 | } |
---|
530 | |
---|
531 | # If we're in -new (bulldozer) mode, nuke everything that |
---|
532 | # relates to this output name... |
---|
533 | if ($VRIPMODE eq "new") { |
---|
534 | $pattern = "$SVROOT/$subvol/$ply"; |
---|
535 | $pattern =~ s|.ply$|*|; |
---|
536 | $cmd = "/bin/rm $pattern\n"; |
---|
537 | print "} $cmd"; |
---|
538 | system $cmd; |
---|
539 | (!$?) || die "Error: $cmd failed...\n"; |
---|
540 | } |
---|
541 | |
---|
542 | # Now, regardless of whether we were in bulldozer mode |
---|
543 | # or update mode, at this point we see if the subvolume |
---|
544 | # is unstarted or partially done, and pick the right |
---|
545 | # program (vrip or vripdate) to run.... |
---|
546 | @conftodolines = &maketodolines("$SVROOT/$subvol/all.conf", |
---|
547 | "$SVROOT/$subvol/$conf"); |
---|
548 | if ($#conftodolines == -1) { |
---|
549 | next; |
---|
550 | } |
---|
551 | |
---|
552 | # If there's stuff to do, write to todo file |
---|
553 | open(CONFTODO, ">$SVROOT/$subvol/$conftodo"); |
---|
554 | print CONFTODO @conftodolines; |
---|
555 | close CONFTODO; |
---|
556 | |
---|
557 | if (!-e "$SVROOT/$subvol/$vri" || |
---|
558 | !-e "$SVROOT/$subvol/$conf") { |
---|
559 | $vripstr = "vripnew"; |
---|
560 | } else { |
---|
561 | $vripstr = "vripupdate"; |
---|
562 | } |
---|
563 | |
---|
564 | |
---|
565 | # Set a few options... |
---|
566 | $crunchstr = ""; |
---|
567 | if ($DOCRUNCH) { |
---|
568 | $crunchstr = " ply2crunchset -l 6 $ply;"; |
---|
569 | } |
---|
570 | # $rampscalestr = ""; |
---|
571 | # if ($DORAMPSCALE) { |
---|
572 | # $rampscalestr = " -rampscale $RAMPSCALE "; |
---|
573 | # } |
---|
574 | $ramplengthstr = " -ramplength $RAMPLENGTH "; |
---|
575 | $rmtmpstr = ""; |
---|
576 | if ($DORMTMPS) { |
---|
577 | $rmtmpstr = "/bin/rm $plybig $vri;"; |
---|
578 | } |
---|
579 | |
---|
580 | # Amount of safety in plyculling triangles |
---|
581 | $cullEpsilon = 2.1 * $VOXELSIZE; |
---|
582 | |
---|
583 | push(@COMMANDS, |
---|
584 | "cd $cwd/$SVROOT/$subvol; ". |
---|
585 | # "time $vripstr $vri $conftodo $bbox $VOXELSIZE $rampscalestr $PASSTOVRIP -noui; ". |
---|
586 | "time $vripstr $vri $conftodo $bbox $VOXELSIZE $ramplengthstr $PASSTOVRIP -noui; ". |
---|
587 | "time vripsurf -no_remove_slivers $vri $plybig $PASSTOVRIPSURF -noui; ". |
---|
588 | "time plycull $bbox $plybig $ply $cullEpsilon; ". |
---|
589 | "$rmtmpstr $crunchstr ". |
---|
590 | "cat $conftodo >>! $conf; ". |
---|
591 | "/bin/rm $conftodo\n"); |
---|
592 | } |
---|
593 | } |
---|