[37] | 1 | #! /usr/bin/tclsh |
---|
| 2 | |
---|
| 3 | # |
---|
| 4 | # vripsplit.tcl -- David Koller (dk@cs.stanford.edu), 8/14/98 |
---|
| 5 | # |
---|
| 6 | # This program is used for splitting up vrip jobs into smaller |
---|
| 7 | # subtasks. The program reads a vrip .conf file, determines |
---|
| 8 | # an appropriate decomposition of the vrip volume, and outputs a |
---|
| 9 | # new .conf and a corresponding .bbox.ply file for each subvolume. |
---|
| 10 | # |
---|
| 11 | # See usage proc below for usage... |
---|
| 12 | # |
---|
| 13 | # where <max#voxels> is the maximum voxel size of the subvolumes, |
---|
| 14 | # and resolution is the same as the value given to vripnew. |
---|
| 15 | # |
---|
| 16 | # The bounding volumes output by this program do not overlap; |
---|
| 17 | # however, the program assumes that vrip will apply a 10 voxel |
---|
| 18 | # "border" when vripping the subvolumes, so the individual bmesh's |
---|
| 19 | # which intersect this border region are included in the appropriate |
---|
| 20 | # .conf files for the subvolumes. |
---|
| 21 | # |
---|
| 22 | # The global bounding box is expanded by BBOXOVERLAP voxels in each |
---|
| 23 | # dimension beyond the exact bounding box. |
---|
| 24 | # |
---|
| 25 | # Modifications |
---|
| 26 | # ------------- |
---|
| 27 | # * Output .bbox files for each bmesh file to speed global bbox computation |
---|
| 28 | # (lucasp, 8/26/98) |
---|
| 29 | # * Output subvol filenames padded to 4 digits (lucasp, 8/26/98) |
---|
| 30 | # |
---|
| 31 | # Known Assumptions/Limitations/Bugs |
---|
| 32 | # ----------------------- |
---|
| 33 | # * Only "bmesh" commands are recognized from the .conf file |
---|
| 34 | # * Assumes that vrip will apply a 10 voxel "border" when vripping |
---|
| 35 | # the subvolumes |
---|
| 36 | # * Assumes that vrip will not change the parity of the voxel |
---|
| 37 | # dimensions of the subvolume |
---|
| 38 | # |
---|
| 39 | |
---|
| 40 | # The amount to make BBOXES overlap, in voxels, on the seams. |
---|
| 41 | # Note that it will actually increase the subvols by 2x this |
---|
| 42 | # amount in each dimension |
---|
| 43 | set BBOXOVERLAP 20; |
---|
| 44 | |
---|
| 45 | # default subvol dir |
---|
| 46 | set subvoldir "."; |
---|
| 47 | set bboxesok 0; |
---|
| 48 | |
---|
| 49 | proc usage args { |
---|
| 50 | global subvoldir; |
---|
| 51 | puts ""; |
---|
| 52 | puts "Usage: vripsplit scans.conf bbox\ |
---|
| 53 | resolution max#voxels \[-subvoldir subvoldir\]"; |
---|
| 54 | puts ""; |
---|
| 55 | puts "Where:"; |
---|
| 56 | puts " scans.conf is the conf file containing all of the scans that you"; |
---|
| 57 | puts " wish to vrip"; |
---|
| 58 | puts " bbox is something that specifies the volume to vrip. It"; |
---|
| 59 | puts " can be scans.conf, or some other conf/ply file. It"; |
---|
| 60 | puts " will vrip a volume big enough to cover bbox."; |
---|
| 61 | puts " resolution Is the voxel size"; |
---|
| 62 | puts " max\#voxels is the maximum number of voxels per chunk."; |
---|
| 63 | puts " subvoldir is where it will put all the .conf and .bbox.ply"; |
---|
| 64 | puts " files for the subvolumes. Default: $subvoldir"; |
---|
| 65 | puts ""; |
---|
| 66 | exit -1; |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | proc bbox_intersect {xmin1 ymin1 zmin1 xmax1 ymax1 zmax1 \ |
---|
| 70 | xmin2 ymin2 zmin2 xmax2 ymax2 zmax2} \ |
---|
| 71 | { |
---|
| 72 | if {$xmin1 > $xmax2} {return 0}; |
---|
| 73 | if {$xmax1 < $xmin2} {return 0}; |
---|
| 74 | if {$ymin1 > $ymax2} {return 0}; |
---|
| 75 | if {$ymax1 < $ymin2} {return 0}; |
---|
| 76 | if {$zmin1 > $zmax2} {return 0}; |
---|
| 77 | if {$zmax1 < $zmin2} {return 0}; |
---|
| 78 | |
---|
| 79 | return 1; |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | # Given a "bmesh x.ply tx ty tz q1 q2 q3 q4" line, this routine generates |
---|
| 83 | # a x.bbox file, which has two lines: |
---|
| 84 | # minx miny minz |
---|
| 85 | # maxx maxy maxz |
---|
| 86 | # |
---|
| 87 | proc confline2bbox {confline} { |
---|
| 88 | if {("bmesh" == [lindex $confline 0])} { |
---|
| 89 | set cmd "exec plyxform "; |
---|
| 90 | set cmd "$cmd -t [lindex $confline 2] [lindex $confline 3] [lindex $confline 4]"; |
---|
| 91 | set q3 [lindex $confline 8]; |
---|
| 92 | set q3 [expr -$q3]; |
---|
| 93 | set cmd "$cmd -q [lindex $confline 5] [lindex $confline 6] [lindex $confline 7] $q3"; |
---|
| 94 | set cmd "$cmd < [lindex $confline 1] | plybbox"; |
---|
| 95 | |
---|
| 96 | catch {eval $cmd} msg; |
---|
| 97 | scan $msg "%f %f %f %f %f %f" minx miny minz maxx maxy maxz; |
---|
| 98 | set plyname [lindex $confline 1]; |
---|
| 99 | # Set bboxname to be the corresponding bbox file |
---|
| 100 | regsub .ply $plyname .bbox bboxname; |
---|
| 101 | set bboxfid [open $bboxname "w+"]; |
---|
| 102 | puts $bboxfid "$minx $miny $minz"; |
---|
| 103 | puts $bboxfid "$maxx $maxy $maxz"; |
---|
| 104 | |
---|
| 105 | close $bboxfid; |
---|
| 106 | } |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | |
---|
| 110 | # Recurse through the subvols, dividing and figuring out which |
---|
| 111 | # scans intersect... |
---|
| 112 | # The args are the ranges to do (xi...xj-1, etc) |
---|
| 113 | # |
---|
| 114 | proc sort_confs {xi yi zi xn yn zn il numMeshes} { |
---|
| 115 | global BBOXOVERLAP; |
---|
| 116 | global res; |
---|
| 117 | global bound; |
---|
| 118 | global bbox; |
---|
| 119 | global conffilename; |
---|
| 120 | global svnum; |
---|
| 121 | global subvoldir; |
---|
| 122 | global meshlist; |
---|
| 123 | global subindexlist; |
---|
| 124 | |
---|
| 125 | #puts "sort_confs $xi $yi $zi $xn $yn $zn <indexlist> $numMeshes"; |
---|
| 126 | #puts $il; |
---|
| 127 | |
---|
| 128 | set xinc [expr $BBOXOVERLAP*$res]; |
---|
| 129 | set yinc [expr $BBOXOVERLAP*$res]; |
---|
| 130 | set zinc [expr $BBOXOVERLAP*$res]; |
---|
| 131 | |
---|
| 132 | set xmin [expr $bound(x,$xi) - $xinc]; |
---|
| 133 | set xmax [expr $bound(x,[expr $xi+$xn]) + $xinc]; |
---|
| 134 | set ymin [expr $bound(y,$yi) - $yinc]; |
---|
| 135 | set ymax [expr $bound(y,[expr $yi+$yn]) + $yinc]; |
---|
| 136 | set zmin [expr $bound(z,$zi) - $zinc]; |
---|
| 137 | set zmax [expr $bound(z,[expr $zi+$zn]) + $zinc]; |
---|
| 138 | |
---|
| 139 | # Figure out which meshes intersect this volume |
---|
| 140 | set mynumMeshes 0; |
---|
| 141 | set myil ""; |
---|
| 142 | |
---|
| 143 | for {set i 0} {$i < $numMeshes} {incr i} { |
---|
| 144 | set ili [lindex $il $i]; |
---|
| 145 | if {[bbox_intersect $xmin $ymin $zmin $xmax $ymax $zmax \ |
---|
| 146 | $bbox($ili,xmin) $bbox($ili,ymin) $bbox($ili,zmin) \ |
---|
| 147 | $bbox($ili,xmax) $bbox($ili,ymax) $bbox($ili,zmax)]} { |
---|
| 148 | lappend myil $ili; |
---|
| 149 | incr mynumMeshes; |
---|
| 150 | } |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | # Don't -- want to define every subvol variable |
---|
| 154 | # Quit if we have no more meshes in this subvol... |
---|
| 155 | # if {$mynumMeshes == 0} { |
---|
| 156 | # return 0; |
---|
| 157 | # } |
---|
| 158 | |
---|
| 159 | # If we have children, recurse |
---|
| 160 | if {$xn >= $yn && $xn >= $zn && $xn > 1} { |
---|
| 161 | # split in x, recurse |
---|
| 162 | set hx1 [expr int($xn / 2)]; |
---|
| 163 | set hx2 [expr int($xn - $hx1)]; |
---|
| 164 | set xj [expr $xi + $hx1]; |
---|
| 165 | sort_confs $xi $yi $zi $hx1 $yn $zn $myil $mynumMeshes; |
---|
| 166 | sort_confs $xj $yi $zi $hx2 $yn $zn $myil $mynumMeshes; |
---|
| 167 | } elseif {$yn >= $zn && $yn > 1} { |
---|
| 168 | # split in y, recurse |
---|
| 169 | set hy1 [expr int($yn / 2)]; |
---|
| 170 | set hy2 [expr int($yn - $hy1)]; |
---|
| 171 | set yj [expr $yi + $hy1]; |
---|
| 172 | sort_confs $xi $yi $zi $xn $hy1 $zn $myil $mynumMeshes; |
---|
| 173 | sort_confs $xi $yj $zi $xn $hy2 $zn $myil $mynumMeshes; |
---|
| 174 | } elseif {$zn > 1} { |
---|
| 175 | # split in z, recurse |
---|
| 176 | set hz1 [expr int($zn / 2)]; |
---|
| 177 | set hz2 [expr int($zn - $hz1)]; |
---|
| 178 | set zj [expr $zi + $hz1]; |
---|
| 179 | sort_confs $xi $yi $zi $xn $yn $hz1 $myil $mynumMeshes; |
---|
| 180 | sort_confs $xi $yi $zj $xn $yn $hz2 $myil $mynumMeshes; |
---|
| 181 | } else { |
---|
| 182 | # Remember the index list for this subvol, for later |
---|
| 183 | set subindexlist($xi,$yi,$zi) $myil; |
---|
| 184 | } |
---|
| 185 | } |
---|
| 186 | |
---|
| 187 | # |
---|
| 188 | # Main script |
---|
| 189 | # |
---|
| 190 | |
---|
| 191 | if {$argc < 4} { |
---|
| 192 | usage; |
---|
| 193 | exit -1; |
---|
| 194 | } else { |
---|
| 195 | # parse extra args first |
---|
| 196 | for {set i 4} {$i < $argc} {incr i} { |
---|
| 197 | set currarg [lindex $argv $i]; |
---|
| 198 | if {$currarg == "-subvoldir"} { |
---|
| 199 | if {$i+1 >= $argc} { |
---|
| 200 | puts "Error: -subvoldir needs second arg."; |
---|
| 201 | usage; |
---|
| 202 | exit -1; |
---|
| 203 | } |
---|
| 204 | incr i; |
---|
| 205 | set subvoldir [lindex $argv $i]; |
---|
| 206 | } elseif {$currarg == "-bboxesok"} { |
---|
| 207 | set bboxesok 1; |
---|
| 208 | } else { |
---|
| 209 | puts "Error: unhandled arg: $currarg"; |
---|
| 210 | usage; |
---|
| 211 | exit -1; |
---|
| 212 | } |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | # |
---|
| 216 | # Read the .conf file, storing the bboxes for each bmesh |
---|
| 217 | # It checks dates. If the bboxes are out of date, then |
---|
| 218 | # it will recreate them. Otherwise, it will read the |
---|
| 219 | # bbox to get the bounds of the mesh. |
---|
| 220 | # |
---|
| 221 | |
---|
| 222 | set conffilename [lindex $argv 0]; |
---|
| 223 | set bboxfilename [lindex $argv 1]; |
---|
| 224 | set res [expr double([lindex $argv 2])]; |
---|
| 225 | set maxvoxels [lindex $argv 3]; |
---|
| 226 | |
---|
| 227 | set numMeshes 0; |
---|
| 228 | |
---|
| 229 | # Verify it exists |
---|
| 230 | if { ! [file readable $conffilename] } { |
---|
| 231 | puts ""; |
---|
| 232 | puts "Error: unable to open .conf file $conffilename"; |
---|
| 233 | usage; |
---|
| 234 | exit; |
---|
| 235 | } |
---|
| 236 | |
---|
| 237 | set fileid [open $conffilename "r"]; |
---|
| 238 | |
---|
| 239 | while {[gets $fileid inline] >= 0} { |
---|
| 240 | if {[lindex $inline 0] == "bmesh"} { |
---|
| 241 | puts "Computing bounding box for [lindex $inline 1]..."; |
---|
| 242 | set plyfile [lindex $inline 1]; |
---|
| 243 | # Set bboxfile to be the corresponding bbox file |
---|
| 244 | regsub .ply $plyfile .bbox bboxfile; |
---|
| 245 | |
---|
| 246 | # Check if bbox file needs to be created or updated |
---|
| 247 | if {![file exists $bboxfile]} { |
---|
| 248 | puts "bbox does not exist, creating..."; |
---|
| 249 | confline2bbox $inline; |
---|
| 250 | } else { |
---|
| 251 | set bboxmtime [file mtime $bboxfile]; |
---|
| 252 | set confmtime [file mtime $conffilename]; |
---|
| 253 | if {$confmtime > $bboxmtime && $bboxesok == 0} { |
---|
| 254 | puts "bbox file is out of date, redoing...."; |
---|
| 255 | confline2bbox $inline; |
---|
| 256 | } |
---|
| 257 | } |
---|
| 258 | |
---|
| 259 | puts "Loading bboxfile: $bboxfile..."; |
---|
| 260 | set bboxfid [open $bboxfile "r"]; |
---|
| 261 | gets $bboxfid minline; |
---|
| 262 | gets $bboxfid maxline; |
---|
| 263 | scan $minline "%f %f %f" bbox($numMeshes,xmin) \ |
---|
| 264 | bbox($numMeshes,ymin) bbox($numMeshes,zmin); |
---|
| 265 | scan $maxline "%f %f %f" bbox($numMeshes,xmax) \ |
---|
| 266 | bbox($numMeshes,ymax) bbox($numMeshes,zmax); |
---|
| 267 | |
---|
| 268 | close $bboxfid; |
---|
| 269 | |
---|
| 270 | set bmeshinfo($numMeshes,file) [lindex $inline 1]; |
---|
| 271 | set bmeshinfo($numMeshes,tx) [lindex $inline 2]; |
---|
| 272 | set bmeshinfo($numMeshes,ty) [lindex $inline 3]; |
---|
| 273 | set bmeshinfo($numMeshes,tz) [lindex $inline 4]; |
---|
| 274 | set bmeshinfo($numMeshes,q0) [lindex $inline 5]; |
---|
| 275 | set bmeshinfo($numMeshes,q1) [lindex $inline 6]; |
---|
| 276 | set bmeshinfo($numMeshes,q2) [lindex $inline 7]; |
---|
| 277 | set bmeshinfo($numMeshes,q3) [lindex $inline 8]; |
---|
| 278 | |
---|
| 279 | incr numMeshes; |
---|
| 280 | } |
---|
| 281 | } |
---|
| 282 | close $fileid; |
---|
| 283 | puts ""; |
---|
| 284 | |
---|
| 285 | # |
---|
| 286 | # Compute the global bounding box |
---|
| 287 | # if bbox is same as input conf file, use Dave's old code. |
---|
| 288 | # if bbox is something different, ummm, uhh, figure it out. |
---|
| 289 | # |
---|
| 290 | |
---|
| 291 | if {$bboxfilename == $conffilename} { |
---|
| 292 | # Just use global bbox of already-computed scan bboxes |
---|
| 293 | set bbox(global,xmin) $bbox(0,xmin); |
---|
| 294 | set bbox(global,xmax) $bbox(0,xmax); |
---|
| 295 | set bbox(global,ymin) $bbox(0,ymin); |
---|
| 296 | set bbox(global,ymax) $bbox(0,ymax); |
---|
| 297 | set bbox(global,zmin) $bbox(0,zmin); |
---|
| 298 | set bbox(global,zmax) $bbox(0,zmax); |
---|
| 299 | |
---|
| 300 | for {set i 1} {$i < $numMeshes} {incr i} { |
---|
| 301 | if {$bbox($i,xmin) < $bbox(global,xmin)} { |
---|
| 302 | set bbox(global,xmin) $bbox($i,xmin)}; |
---|
| 303 | if {$bbox($i,xmax) > $bbox(global,xmax)} { |
---|
| 304 | set bbox(global,xmax) $bbox($i,xmax)}; |
---|
| 305 | if {$bbox($i,ymin) < $bbox(global,ymin)} { |
---|
| 306 | set bbox(global,ymin) $bbox($i,ymin)}; |
---|
| 307 | if {$bbox($i,ymax) > $bbox(global,ymax)} { |
---|
| 308 | set bbox(global,ymax) $bbox($i,ymax)}; |
---|
| 309 | if {$bbox($i,zmin) < $bbox(global,zmin)} { |
---|
| 310 | set bbox(global,zmin) $bbox($i,zmin)}; |
---|
| 311 | if {$bbox($i,zmax) > $bbox(global,zmax)} { |
---|
| 312 | set bbox(global,zmax) $bbox($i,zmax)}; |
---|
| 313 | } |
---|
| 314 | } else { |
---|
| 315 | # Compute the bbox from the bbox file... |
---|
| 316 | |
---|
| 317 | # Verify it exists |
---|
| 318 | if { ! [file readable $bboxfilename] } { |
---|
| 319 | puts ""; |
---|
| 320 | puts "Error: unable to open bbox file $bboxfilename"; |
---|
| 321 | usage; |
---|
| 322 | exit; |
---|
| 323 | } |
---|
| 324 | |
---|
| 325 | # Detect what kind of bounds we're dealing with here. |
---|
| 326 | set ext [file extension $bboxfilename]; |
---|
| 327 | if {$ext == ".ply"} { |
---|
| 328 | # Call plybbox to get bounds... |
---|
| 329 | puts "Setting bbox to include $bboxfilename..."; |
---|
| 330 | catch {exec plybbox < $bboxfilename} msg; |
---|
| 331 | |
---|
| 332 | scan $msg "%f %f %f %f %f %f" minx miny minz maxx maxy maxz; |
---|
| 333 | set bbox(global,xmin) $minx; |
---|
| 334 | set bbox(global,ymin) $miny; |
---|
| 335 | set bbox(global,zmin) $minz; |
---|
| 336 | set bbox(global,xmax) $maxx; |
---|
| 337 | set bbox(global,ymax) $maxy; |
---|
| 338 | set bbox(global,zmax) $maxz; |
---|
| 339 | |
---|
| 340 | } elseif {$ext == ".set"} { |
---|
| 341 | # run through the set file for the boundmesh limits |
---|
| 342 | set fileid [open $bboxfilename "r"]; |
---|
| 343 | |
---|
| 344 | # initialize bbox to negative size |
---|
| 345 | set bbox(global,xmin) 1e12; |
---|
| 346 | set bbox(global,ymin) 1e12; |
---|
| 347 | set bbox(global,zmin) 1e12; |
---|
| 348 | set bbox(global,xmax) -1e12; |
---|
| 349 | set bbox(global,ymax) -1e12; |
---|
| 350 | set bbox(global,zmax) -1e12; |
---|
| 351 | |
---|
| 352 | # Skip 1st two lines of the set file (header stuff) |
---|
| 353 | set numchars [gets $fileid setline]; |
---|
| 354 | set numchars [gets $fileid setline]; |
---|
| 355 | set lineno 3; |
---|
| 356 | |
---|
| 357 | # Get the xf file |
---|
| 358 | regsub .set $bboxfilename .xf xfname; |
---|
| 359 | |
---|
| 360 | # grow bbox to include each mesh in the set |
---|
| 361 | while {1} { |
---|
| 362 | set numchars [gets $fileid setline]; |
---|
| 363 | if {$numchars <= 0} { break; } |
---|
| 364 | set setply [lindex $setline 2]; |
---|
| 365 | |
---|
| 366 | # Call plyxform to get the bbox in world coordinates |
---|
| 367 | set cmd "exec plyxform -f $xfname < $setply | plybbox"; |
---|
| 368 | puts "Expanding bbox to include $setply..." |
---|
| 369 | puts "$cmd" |
---|
| 370 | catch {eval $cmd} msg; |
---|
| 371 | |
---|
| 372 | # Grow bbox to include this mesh... |
---|
| 373 | scan $msg "%f %f %f %f %f %f" newMinx newMiny newMinz \ |
---|
| 374 | newMaxx newMaxy newMaxz; |
---|
| 375 | set bbox(global,xmin) [min $bbox(global,xmin) $newMinx]; |
---|
| 376 | set bbox(global,ymin) [min $bbox(global,ymin) $newMiny]; |
---|
| 377 | set bbox(global,zmin) [min $bbox(global,zmin) $newMinz]; |
---|
| 378 | set bbox(global,xmax) [max $bbox(global,xmax) $newMaxx]; |
---|
| 379 | set bbox(global,ymax) [max $bbox(global,ymax) $newMaxy]; |
---|
| 380 | set bbox(global,zmax) [max $bbox(global,zmax) $newMaxz]; |
---|
| 381 | |
---|
| 382 | incr lineno; |
---|
| 383 | } |
---|
| 384 | close $fileid; |
---|
| 385 | |
---|
| 386 | } elseif {$ext == ".conf"} { |
---|
| 387 | # run through the conf file to get bounds |
---|
| 388 | set fileid [open $bboxfilename "r"]; |
---|
| 389 | set lineno 1; |
---|
| 390 | |
---|
| 391 | # initialize bbox to negative size |
---|
| 392 | set bbox(global,xmin) 1e12; |
---|
| 393 | set bbox(global,ymin) 1e12; |
---|
| 394 | set bbox(global,zmin) 1e12; |
---|
| 395 | set bbox(global,xmax) -1e12; |
---|
| 396 | set bbox(global,ymax) -1e12; |
---|
| 397 | set bbox(global,zmax) -1e12; |
---|
| 398 | |
---|
| 399 | # grow bbox to include each bmesh |
---|
| 400 | while {1} { |
---|
| 401 | set numchars [gets $fileid bmline]; |
---|
| 402 | if {$numchars <= 0} { break; } |
---|
| 403 | if {[lindex $bmline 0] != "bmesh"} { |
---|
| 404 | puts "Warning: skipping .conf file line $lineno."; |
---|
| 405 | puts " (vripsplit only handles bmesh lines)"; |
---|
| 406 | continue; |
---|
| 407 | } |
---|
| 408 | # Call plyxform to get the bbox in world coordinates |
---|
| 409 | set bmply [lindex $bmline 1]; |
---|
| 410 | set tx [lindex $bmline 2]; |
---|
| 411 | set ty [lindex $bmline 3]; |
---|
| 412 | set tz [lindex $bmline 4]; |
---|
| 413 | set q0 [lindex $bmline 5]; |
---|
| 414 | set q1 [lindex $bmline 6]; |
---|
| 415 | set q2 [lindex $bmline 7]; |
---|
| 416 | set q3 [lindex $bmline 8]; |
---|
| 417 | set q3 [expr -$q3]; |
---|
| 418 | set cmd "exec plyxform -t $tx $ty $tz -q $q0 $q1 $q2 $q3 \ |
---|
| 419 | < $bmply | plybbox"; |
---|
| 420 | puts "Expanding bbox to include $bmply..." |
---|
| 421 | catch {eval $cmd} msg; |
---|
| 422 | |
---|
| 423 | # Grow bbox to include this mesh... |
---|
| 424 | scan $msg "%f %f %f %f %f %f" newMinx newMiny newMinz \ |
---|
| 425 | newMaxx newMaxy newMaxz; |
---|
| 426 | set bbox(global,xmin) [min $bbox(global,xmin) $newMinx]; |
---|
| 427 | set bbox(global,ymin) [min $bbox(global,ymin) $newMiny]; |
---|
| 428 | set bbox(global,zmin) [min $bbox(global,zmin) $newMinz]; |
---|
| 429 | set bbox(global,xmax) [max $bbox(global,xmax) $newMaxx]; |
---|
| 430 | set bbox(global,ymax) [max $bbox(global,ymax) $newMaxy]; |
---|
| 431 | set bbox(global,zmax) [max $bbox(global,zmax) $newMaxz]; |
---|
| 432 | |
---|
| 433 | incr lineno; |
---|
| 434 | } |
---|
| 435 | close $fileid; |
---|
| 436 | |
---|
| 437 | } else { |
---|
| 438 | puts ""; |
---|
| 439 | puts "Error: Unrecognized/ unhandled bbox file: $bboxfilename"; |
---|
| 440 | puts " vripsplit only handles .ply and .conf..."; |
---|
| 441 | puts ""; |
---|
| 442 | exit -1; |
---|
| 443 | } |
---|
| 444 | } |
---|
| 445 | |
---|
| 446 | # debug info -- print global bbox |
---|
| 447 | puts "Global bbox: ($bbox(global,xmin) $bbox(global,ymin) $bbox(global,zmin)) to"; |
---|
| 448 | puts " ($bbox(global,xmax) $bbox(global,ymax) $bbox(global,zmax))"; |
---|
| 449 | |
---|
| 450 | # Expand the global bounding box by BBOXOVERLAP voxels in each dimension |
---|
| 451 | set expand [expr $BBOXOVERLAP * 2 * $res]; |
---|
| 452 | |
---|
| 453 | set bbox(global,xmin) [expr $bbox(global,xmin) - $expand]; |
---|
| 454 | set bbox(global,xmax) [expr $bbox(global,xmax) + $expand]; |
---|
| 455 | set bbox(global,ymin) [expr $bbox(global,ymin) - $expand]; |
---|
| 456 | set bbox(global,ymax) [expr $bbox(global,ymax) + $expand]; |
---|
| 457 | set bbox(global,zmin) [expr $bbox(global,zmin) - $expand]; |
---|
| 458 | set bbox(global,zmax) [expr $bbox(global,zmax) + $expand]; |
---|
| 459 | |
---|
| 460 | # |
---|
| 461 | # Compute the number of subvolumes, and their dimensions |
---|
| 462 | # |
---|
| 463 | |
---|
| 464 | set xlen [expr $bbox(global,xmax) - $bbox(global,xmin)]; |
---|
| 465 | set ylen [expr $bbox(global,ymax) - $bbox(global,ymin)]; |
---|
| 466 | set zlen [expr $bbox(global,zmax) - $bbox(global,zmin)]; |
---|
| 467 | |
---|
| 468 | set xvox [expr ceil($xlen / $res)]; |
---|
| 469 | set yvox [expr ceil($ylen / $res)]; |
---|
| 470 | set zvox [expr ceil($zlen / $res)]; |
---|
| 471 | |
---|
| 472 | puts "Total dimensions: $xvox x $yvox x $zvox"; |
---|
| 473 | |
---|
| 474 | set totaldivs [expr ceil($xvox*$yvox*$zvox / double($maxvoxels))]; |
---|
| 475 | |
---|
| 476 | # Initial number of divisions |
---|
| 477 | set xdivs 1; |
---|
| 478 | set ydivs 1; |
---|
| 479 | set zdivs 1; |
---|
| 480 | |
---|
| 481 | while {[expr $xdivs*$ydivs*$zdivs] < $totaldivs} { |
---|
| 482 | |
---|
| 483 | set xdivlen [expr $xlen / $xdivs]; |
---|
| 484 | set ydivlen [expr $ylen / $ydivs]; |
---|
| 485 | set zdivlen [expr $zlen / $zdivs]; |
---|
| 486 | |
---|
| 487 | if {($xdivlen >= $ydivlen) && ($xdivlen >= $zdivlen)} { |
---|
| 488 | incr xdivs; |
---|
| 489 | } elseif {($ydivlen >= $xdivlen) && ($ydivlen >= $zdivlen)} { |
---|
| 490 | incr ydivs; |
---|
| 491 | } else { |
---|
| 492 | incr zdivs; |
---|
| 493 | } |
---|
| 494 | } |
---|
| 495 | |
---|
| 496 | set xmin $bbox(global,xmin); |
---|
| 497 | set ymin $bbox(global,ymin); |
---|
| 498 | set zmin $bbox(global,zmin); |
---|
| 499 | |
---|
| 500 | for {set i 0} {$i <= $xdivs} {incr i} { |
---|
| 501 | set target [expr double($i)/$xdivs * $xlen]; |
---|
| 502 | set bound(x,$i) [expr ceil($target/$res) * $res + $xmin]; |
---|
| 503 | } |
---|
| 504 | for {set i 0} {$i <= $ydivs} {incr i} { |
---|
| 505 | set target [expr double($i)/$ydivs * $ylen]; |
---|
| 506 | set bound(y,$i) [expr ceil($target/$res) * $res + $ymin]; |
---|
| 507 | } |
---|
| 508 | for {set i 0} {$i <= $zdivs} {incr i} { |
---|
| 509 | set target [expr double($i)/$zdivs * $zlen]; |
---|
| 510 | set bound(z,$i) [expr ceil($target/$res) * $res + $zmin]; |
---|
| 511 | } |
---|
| 512 | |
---|
| 513 | # |
---|
| 514 | # Write out .bbox.ply and .conf files for each subvolume. |
---|
| 515 | # The vrip program will expand the subvolume by 10 voxels. |
---|
| 516 | # To (attempt to!) make sure that the entire sphere of influence |
---|
| 517 | # of the ramps is handled correctly, we include in the .conf |
---|
| 518 | # file any meshes that intersect this enlarged volume. |
---|
| 519 | # |
---|
| 520 | |
---|
| 521 | set svnum 0; |
---|
| 522 | |
---|
| 523 | # First do the bbox files... |
---|
| 524 | for {set x 0} {$x < $xdivs} {incr x} { |
---|
| 525 | for {set y 0} {$y < $ydivs} {incr y} { |
---|
| 526 | for {set z 0} {$z < $zdivs} {incr z} { |
---|
| 527 | |
---|
| 528 | incr svnum; |
---|
| 529 | |
---|
| 530 | # pad svnumstr with 0's to make it 4 characters long |
---|
| 531 | set svnumstr [string range "0000" 0 [expr 3 - \ |
---|
| 532 | [string length $svnum]]]; |
---|
| 533 | set svnumstr "$svnumstr$svnum"; |
---|
| 534 | |
---|
| 535 | set xmin $bound(x,$x); |
---|
| 536 | set xmax $bound(x,[expr $x+1]); |
---|
| 537 | set ymin $bound(y,$y); |
---|
| 538 | set ymax $bound(y,[expr $y+1]); |
---|
| 539 | set zmin $bound(z,$z); |
---|
| 540 | set zmax $bound(z,[expr $z+1]); |
---|
| 541 | |
---|
| 542 | set basename [file rootname $conffilename]_subvol$svnumstr; |
---|
| 543 | |
---|
| 544 | set fileid [open "$subvoldir/$basename.bbox.ply" "w"]; |
---|
| 545 | |
---|
| 546 | puts $fileid "ply"; |
---|
| 547 | puts $fileid "format ascii 1.0"; |
---|
| 548 | puts $fileid "element vertex 2"; |
---|
| 549 | puts $fileid "property float x"; |
---|
| 550 | puts $fileid "property float y"; |
---|
| 551 | puts $fileid "property float z"; |
---|
| 552 | puts $fileid "end_header"; |
---|
| 553 | puts $fileid "$xmin $ymin $zmin"; |
---|
| 554 | puts $fileid "$xmax $ymax $zmax"; |
---|
| 555 | |
---|
| 556 | close $fileid; |
---|
| 557 | } |
---|
| 558 | } |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | # |
---|
| 562 | # Now figure out the conf files. |
---|
| 563 | # Do this recursively, to try to make it go faster when we're |
---|
| 564 | # doing 1000 meshes x 1000 subvols.. :-) |
---|
| 565 | # |
---|
| 566 | |
---|
| 567 | # Precompute the meshlist lines, so we only need to figure out |
---|
| 568 | # which ones to paste into each conf file |
---|
| 569 | for {set i 0} {$i < $numMeshes} {incr i} { |
---|
| 570 | set meshlist($i) "bmesh $bmeshinfo($i,file)\ |
---|
| 571 | $bmeshinfo($i,tx) $bmeshinfo($i,ty) $bmeshinfo($i,tz)\ |
---|
| 572 | $bmeshinfo($i,q0) $bmeshinfo($i,q1)\ |
---|
| 573 | $bmeshinfo($i,q2) $bmeshinfo($i,q3)"; |
---|
| 574 | # This is the list of meshes we might possibly consider |
---|
| 575 | # at each recursive level of the traversal |
---|
| 576 | # set indexlist($i) $i; |
---|
| 577 | lappend indexlist $i; |
---|
| 578 | } |
---|
| 579 | |
---|
| 580 | set svnum 1; |
---|
| 581 | |
---|
| 582 | # Figure out which scans touch each bbox |
---|
| 583 | # This does the computation hierarchically; the next step |
---|
| 584 | # will traverse again in order, to print out |
---|
| 585 | sort_confs 0 0 0 $xdivs $ydivs $zdivs $indexlist $numMeshes; |
---|
| 586 | |
---|
| 587 | # Now write the conf files, traversing in order |
---|
| 588 | set svnum 0; |
---|
| 589 | for {set x 0} {$x < $xdivs} {incr x} { |
---|
| 590 | for {set y 0} {$y < $ydivs} {incr y} { |
---|
| 591 | for {set z 0} {$z < $zdivs} {incr z} { |
---|
| 592 | |
---|
| 593 | incr svnum; |
---|
| 594 | |
---|
| 595 | # pad svnumstr with 0's to make it 4 characters long |
---|
| 596 | set svnumstr [string range "0000" 0 [expr 3 - \ |
---|
| 597 | [string length $svnum]]]; |
---|
| 598 | set svnumstr "$svnumstr$svnum"; |
---|
| 599 | set basename [file rootname $conffilename]_subvol$svnumstr; |
---|
| 600 | set fileid [open "$subvoldir/$basename.conf" "w"]; |
---|
| 601 | |
---|
| 602 | # Put all the pre-computed bmesh lines in the conf file. |
---|
| 603 | set myil $subindexlist($x,$y,$z); |
---|
| 604 | for {set i 0} {$i < [llength $myil]} {incr i} { |
---|
| 605 | puts $fileid $meshlist([lindex $myil $i]); |
---|
| 606 | } |
---|
| 607 | close $fileid; |
---|
| 608 | } |
---|
| 609 | } |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | |
---|
| 614 | |
---|
| 615 | |
---|
| 616 | |
---|
| 617 | |
---|
| 618 | |
---|
| 619 | |
---|
| 620 | |
---|
| 621 | |
---|
| 622 | |
---|