1 | set tcl_prompt1 {puts -nonewline "vrip> "} |
---|
2 | set tcl_prompt2 {puts -nonewline "> "} |
---|
3 | |
---|
4 | if {[info exists env(HOSTTYPE)]} { |
---|
5 | if {$env(HOSTTYPE) == "i386-linux"} { |
---|
6 | set isLinux 1 |
---|
7 | } else { |
---|
8 | set isLinux 0 |
---|
9 | } |
---|
10 | } else { |
---|
11 | set isLinux 0 |
---|
12 | } |
---|
13 | |
---|
14 | if {[file exists /usr/tmp/openspace]} { |
---|
15 | puts "Using /usr/tmp/openspace/" |
---|
16 | set tempDir "/usr/tmp/openspace" |
---|
17 | } elseif {[file exists /usr/tmp]} { |
---|
18 | set tempDir "/usr/tmp" |
---|
19 | } elseif {[file exists /var/tmp]} { |
---|
20 | set tempDir "/var/tmp" |
---|
21 | } elseif {[file exists /tmp]} { |
---|
22 | set tempDir "/tmp" |
---|
23 | } |
---|
24 | |
---|
25 | set CywarpAngle "" |
---|
26 | set CywarpSTZoom 1.0 |
---|
27 | set CywarpYZoom 1.0 |
---|
28 | |
---|
29 | set sliceNum 0 |
---|
30 | set weightScale 1 |
---|
31 | set sliceDirection "y" |
---|
32 | set maxWeightScale 256 |
---|
33 | set useNorm 0 |
---|
34 | set useOffsetScale 0 |
---|
35 | set sliceOffset 32768 |
---|
36 | set sliceDivisor 256 |
---|
37 | set conservativeBbox 0 |
---|
38 | set conservativeBboxFactor 1.2 |
---|
39 | |
---|
40 | proc uiExists {} { |
---|
41 | global noui |
---|
42 | return [expr ! $noui] |
---|
43 | } |
---|
44 | |
---|
45 | |
---|
46 | proc newgrid args { |
---|
47 | global useNorm |
---|
48 | |
---|
49 | if {!$useNorm} { |
---|
50 | eval vrip_newgridrle $args |
---|
51 | } else { |
---|
52 | eval vrip_newgridnormrle $args |
---|
53 | } |
---|
54 | update_slice |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | proc readgrid args { |
---|
59 | eval vrip_readgrid $args |
---|
60 | update_slice |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | proc bmeshlinwarp args { |
---|
65 | global CywarpSTZoom |
---|
66 | global CywarpYZoom |
---|
67 | global CywarpAngle |
---|
68 | |
---|
69 | puts "Creating ply file..." |
---|
70 | set fileName [dowarp [lindex $args 0]] |
---|
71 | |
---|
72 | global useNorm |
---|
73 | |
---|
74 | set newArgs [lreplace $args 0 0 $fileName] |
---|
75 | |
---|
76 | eval vrip_rangescanlin $newArgs |
---|
77 | |
---|
78 | update_slice |
---|
79 | |
---|
80 | # exec rm $fileName |
---|
81 | pcreate /bin/rm $fileName |
---|
82 | } |
---|
83 | |
---|
84 | |
---|
85 | proc bmeshwarp args { |
---|
86 | global CywarpSTZoom |
---|
87 | global CywarpYZoom |
---|
88 | global CywarpAngle |
---|
89 | |
---|
90 | puts "Creating ply file using ($CywarpSTZoom, $CywarpYZoom, $CywarpAngle)..." |
---|
91 | set fileName [dowarp [lindex $args 0]] |
---|
92 | |
---|
93 | global useNorm |
---|
94 | |
---|
95 | set newArgs [lreplace $args 0 0 $fileName] |
---|
96 | |
---|
97 | if {!$useNorm} { |
---|
98 | eval vrip_rangescanrle $newArgs |
---|
99 | } else { |
---|
100 | eval vrip_rangescannormrle $newArgs |
---|
101 | } |
---|
102 | update_slice |
---|
103 | |
---|
104 | # exec rm $fileName |
---|
105 | pcreate /bin/rm $fileName |
---|
106 | } |
---|
107 | |
---|
108 | |
---|
109 | proc dowarp name { |
---|
110 | global CywarpSTZoom |
---|
111 | global CywarpYZoom |
---|
112 | global CywarpAngle |
---|
113 | |
---|
114 | set root [file rootname $name] |
---|
115 | set frameFile ${root}.cmp |
---|
116 | set i 0 |
---|
117 | while {1} { |
---|
118 | set plyFile ${tempDir}/temp_$i.ply |
---|
119 | if {![file exists $plyFile]} { |
---|
120 | break |
---|
121 | } |
---|
122 | incr i |
---|
123 | } |
---|
124 | |
---|
125 | if {$CywarpAngle == ""} { |
---|
126 | |
---|
127 | # catch {exec cywarp $frameFile $plyFile -stzoom $CywarpSTZoom -yzoom $CywarpYZoom} msg |
---|
128 | |
---|
129 | pcreate /u/curless/scripts/cywarp $frameFile $plyFile -stzoom $CywarpSTZoom -yzoom $CywarpYZoom |
---|
130 | |
---|
131 | } else { |
---|
132 | |
---|
133 | # catch {exec cywarp $frameFile $plyFile -stzoom $CywarpSTZoom -yzoom $CywarpYZoom -wangle $CywarpAngle} msg |
---|
134 | |
---|
135 | pcreate /u/curless/scripts/cywarp $frameFile $plyFile -stzoom $CywarpSTZoom -yzoom $CywarpYZoom -wangle $CywarpAngle |
---|
136 | |
---|
137 | } |
---|
138 | |
---|
139 | return $plyFile |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | proc bmesh args { |
---|
144 | global useNorm |
---|
145 | |
---|
146 | if {!$useNorm} { |
---|
147 | eval vrip_rangescanrle $args |
---|
148 | } else { |
---|
149 | eval vrip_rangescannormrle $args |
---|
150 | } |
---|
151 | update_slice |
---|
152 | } |
---|
153 | |
---|
154 | proc bmeshlin args { |
---|
155 | eval vrip_rangescanlin $args |
---|
156 | update_slice |
---|
157 | } |
---|
158 | |
---|
159 | proc bmeshp args { |
---|
160 | eval vrip_rangescanpersp $args |
---|
161 | update_slice |
---|
162 | } |
---|
163 | |
---|
164 | proc vrip_slicer {} { |
---|
165 | global slicerWin |
---|
166 | wm geometry $slicerWin "+40+40" |
---|
167 | wm deiconify $slicerWin |
---|
168 | } |
---|
169 | |
---|
170 | |
---|
171 | proc vrip_render_view {} { |
---|
172 | global renderWin |
---|
173 | wm geometry $renderWin "+40+40" |
---|
174 | wm deiconify $renderWin |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | proc writeirisslice {name count} { |
---|
179 | global vripSlice |
---|
180 | |
---|
181 | # Set up frame count suffix |
---|
182 | if {$count < 10} { |
---|
183 | set suffix 000${count} |
---|
184 | } elseif {$count < 100} { |
---|
185 | set suffix 00${count} |
---|
186 | } elseif {$count < 1000} { |
---|
187 | set suffix 0${count} |
---|
188 | } else { |
---|
189 | set suffix ${count} |
---|
190 | } |
---|
191 | |
---|
192 | $vripSlice write ${name}${suffix}.ppm -format ppm |
---|
193 | exec fromppm ${name}${suffix}.ppm ${name}${suffix}.rgb |
---|
194 | exec /bin/rm ${name}${suffix}.ppm |
---|
195 | } |
---|
196 | |
---|
197 | proc update_slice {} { |
---|
198 | global vripSlice |
---|
199 | global sliceDirection |
---|
200 | global sliceNum |
---|
201 | global weightScale |
---|
202 | global slice_scale |
---|
203 | global useNorm |
---|
204 | global sliceOffset |
---|
205 | global sliceDivisor |
---|
206 | |
---|
207 | if {$sliceDirection == "x"} { |
---|
208 | if {!$useNorm} { |
---|
209 | set size [lindex [vrip_inforle] 1] |
---|
210 | } else { |
---|
211 | set size [lindex [vrip_infonormrle] 1] |
---|
212 | } |
---|
213 | } elseif {$sliceDirection == "y"} { |
---|
214 | if {!$useNorm} { |
---|
215 | set size [lindex [vrip_inforle] 3] |
---|
216 | } else { |
---|
217 | set size [lindex [vrip_infonormrle] 3] |
---|
218 | } |
---|
219 | } elseif {$sliceDirection == "z"} { |
---|
220 | if {!$useNorm} { |
---|
221 | set size [lindex [vrip_inforle] 5] |
---|
222 | } else { |
---|
223 | set size [lindex [vrip_infonormrle] 5] |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | if {[uiExists]} { |
---|
228 | $slice_scale configure -to $size |
---|
229 | |
---|
230 | if {!$useNorm} { |
---|
231 | vrip_setphotoslice $vripSlice $sliceNum \ |
---|
232 | $sliceDirection $weightScale |
---|
233 | vrip_photoslicerle $vripSlice $sliceNum \ |
---|
234 | $sliceDirection $weightScale $sliceOffset $sliceDivisor |
---|
235 | } else { |
---|
236 | vrip_photoslicenormrle $vripSlice $sliceNum \ |
---|
237 | $sliceDirection $weightScale |
---|
238 | } |
---|
239 | } |
---|
240 | } |
---|
241 | |
---|
242 | # JED - just stole from above, so that I could use it elsewhere. |
---|
243 | # didn't bother to really understand it. |
---|
244 | proc get_slice_size {} { |
---|
245 | global vripSlice |
---|
246 | global sliceDirection |
---|
247 | global sliceNum |
---|
248 | global weightScale |
---|
249 | global slice_scale |
---|
250 | global useNorm |
---|
251 | |
---|
252 | if {$sliceDirection == "x"} { |
---|
253 | if {!$useNorm} { |
---|
254 | set size [lindex [vrip_inforle] 1] |
---|
255 | } else { |
---|
256 | set size [lindex [vrip_infonormrle] 1] |
---|
257 | } |
---|
258 | } elseif {$sliceDirection == "y"} { |
---|
259 | if {!$useNorm} { |
---|
260 | set size [lindex [vrip_inforle] 3] |
---|
261 | } else { |
---|
262 | set size [lindex [vrip_infonormrle] 3] |
---|
263 | } |
---|
264 | } elseif {$sliceDirection == "z"} { |
---|
265 | if {!$useNorm} { |
---|
266 | set size [lindex [vrip_inforle] 5] |
---|
267 | } else { |
---|
268 | set size [lindex [vrip_infonormrle] 5] |
---|
269 | } |
---|
270 | } |
---|
271 | |
---|
272 | return $size |
---|
273 | } |
---|
274 | |
---|
275 | proc change_weight_scale {scale} { |
---|
276 | global weightScale |
---|
277 | set weightScale $scale |
---|
278 | update_slice |
---|
279 | } |
---|
280 | |
---|
281 | proc change_offset {offset} { |
---|
282 | global sliceOffset |
---|
283 | set sliceOffset $offset |
---|
284 | update_slice |
---|
285 | } |
---|
286 | |
---|
287 | proc change_divisor {divisor} { |
---|
288 | global sliceDivisor |
---|
289 | set sliceDivisor $divisor |
---|
290 | update_slice |
---|
291 | } |
---|
292 | |
---|
293 | |
---|
294 | proc change_slice {slice} { |
---|
295 | global sliceNum |
---|
296 | set sliceNum $slice |
---|
297 | update_slice |
---|
298 | } |
---|
299 | |
---|
300 | proc get_voxel_info {u v} { |
---|
301 | global sliceNum |
---|
302 | global sliceDirection |
---|
303 | global useNorm |
---|
304 | |
---|
305 | if {$useNorm} return "" |
---|
306 | if {$sliceDirection == "x"} { |
---|
307 | return [vrip_getvoxelrle $sliceNum $v $u] |
---|
308 | } elseif {$sliceDirection == "y"} { |
---|
309 | return [vrip_getvoxelrle $u $sliceNum $v] |
---|
310 | } elseif {$sliceDirection == "z"} { |
---|
311 | return [vrip_getvoxelrle $u $v $sliceNum] |
---|
312 | } |
---|
313 | } |
---|
314 | |
---|
315 | |
---|
316 | #################### UI stuff start ########################## |
---|
317 | |
---|
318 | if {[uiExists]} { |
---|
319 | |
---|
320 | if {$isLinux} { |
---|
321 | set renderWin [toplevel .renderWin] |
---|
322 | } else { |
---|
323 | set renderWin [toplevel .renderWin -visual {truecolor 24}] |
---|
324 | } |
---|
325 | |
---|
326 | wm withdraw $renderWin |
---|
327 | set renderPhoto [image create photo renderPhoto -palette 256] |
---|
328 | set renderContainer [label $renderWin.renderContainer -image $renderPhoto] |
---|
329 | pack $renderContainer |
---|
330 | vrip_setrenderphoto $renderPhoto |
---|
331 | $renderPhoto put black -to 0 0 199 199 |
---|
332 | |
---|
333 | wm withdraw . |
---|
334 | if {$isLinux} { |
---|
335 | set slicerWin [toplevel .slicerWin] |
---|
336 | } else { |
---|
337 | set slicerWin [toplevel .slicerWin -visual {truecolor 24}] |
---|
338 | } |
---|
339 | wm withdraw $slicerWin |
---|
340 | |
---|
341 | set frame1 [frame $slicerWin.frame1] |
---|
342 | if {$isLinux} { |
---|
343 | set vripSlice [image create photo vripSlice -palette 256/0/256] |
---|
344 | } else { |
---|
345 | set vripSlice [image create photo vripSlice] |
---|
346 | } |
---|
347 | set sliceContainer [label $frame1.sliceContainer -image $vripSlice \ |
---|
348 | -cursor crosshair -borderwidth 0 -highlightthickness 0] |
---|
349 | |
---|
350 | set sliceFrame [frame $slicerWin.frame1.sliceFrame] |
---|
351 | set slice_scale [scale $sliceFrame.scale -from 0 \ |
---|
352 | -command "change_slice" \ |
---|
353 | -label "Slice number" -orient horizontal\ |
---|
354 | -length 150] |
---|
355 | pack append $sliceFrame $slice_scale {left padx 0} |
---|
356 | |
---|
357 | if {$useOffsetScale} { |
---|
358 | set offsetFrame [frame $slicerWin.frame1.offsetFrame] |
---|
359 | set offset_scale [scale $offsetFrame.scale -from 0 -to 65535 \ |
---|
360 | -command "change_offset" \ |
---|
361 | -label "Offset" \ |
---|
362 | -orient horizontal -length 150 ] |
---|
363 | $offset_scale set $sliceOffset |
---|
364 | pack append $offsetFrame $offset_scale {left padx 0} |
---|
365 | |
---|
366 | set divisorFrame [frame $slicerWin.frame1.divisorFrame] |
---|
367 | set divisor_scale [scale $divisorFrame.scale -from 1 -to 256 \ |
---|
368 | -command "change_divisor" \ |
---|
369 | -label "Divisor" \ |
---|
370 | -orient horizontal -length 150] |
---|
371 | $divisor_scale set $sliceDivisor |
---|
372 | pack append $divisorFrame $divisor_scale {left padx 0} |
---|
373 | } |
---|
374 | |
---|
375 | set weightFrame [frame $slicerWin.frame1.weightFrame] |
---|
376 | set weight_scale [scale $weightFrame.scale -from 1 -to $maxWeightScale \ |
---|
377 | -command "change_weight_scale" \ |
---|
378 | -label "Weight scale" \ |
---|
379 | -orient horizontal -length 150] |
---|
380 | pack append $weightFrame $weight_scale {left padx 0} |
---|
381 | |
---|
382 | set showWeights 0 |
---|
383 | set frame2 [frame $slicerWin.frame2] |
---|
384 | pack append $frame2 \ |
---|
385 | [label $frame2.sliceDirLabel -text "Slice direction"] {top pady 0} \ |
---|
386 | [radiobutton $frame2.b1 -relief flat -text "X" \ |
---|
387 | -variable sliceDirection -value x ] {left padx 0}\ |
---|
388 | [radiobutton $frame2.b2 -relief flat -text "Y" \ |
---|
389 | -variable sliceDirection -value y -state active] {left padx 0}\ |
---|
390 | [radiobutton $frame2.b3 -relief flat -text "Z" \ |
---|
391 | -variable sliceDirection -value z] {left padx 0}\ |
---|
392 | |
---|
393 | #pack append $frame1 $photo {left padx 0} $slice_scale {left padx 0} |
---|
394 | |
---|
395 | if {$useOffsetScale} { |
---|
396 | pack append $frame1 $sliceFrame {top pady 10} \ |
---|
397 | $offsetFrame {top pady 0} \ |
---|
398 | $divisorFrame {top pady 0} \ |
---|
399 | $weightFrame {top pady 0} \ |
---|
400 | [checkbutton $frame1.showWeights -text "Show weights" \ |
---|
401 | -variable showWeights \ |
---|
402 | -command {vrip_param -show_conf_slice |
---|
403 | $showWeights; update_slice}] \ |
---|
404 | {top pady 0} \ |
---|
405 | $sliceContainer {top pady 0} \ |
---|
406 | [label $frame1.infoLabel -textvariable infoLabelStr -font 7x13] {top pady 0} |
---|
407 | } else { |
---|
408 | pack append $frame1 $sliceFrame {top pady 10} \ |
---|
409 | $weightFrame {top pady 0} \ |
---|
410 | [checkbutton $frame1.showWeights -text "Show weights" \ |
---|
411 | -variable showWeights \ |
---|
412 | -command {vrip_param -show_conf_slice |
---|
413 | $showWeights; update_slice}] \ |
---|
414 | {top pady 0} \ |
---|
415 | $sliceContainer {top pady 0} \ |
---|
416 | [label $frame1.infoLabel -textvariable infoLabelStr -font 7x13] {top pady 0} |
---|
417 | } |
---|
418 | |
---|
419 | bind $sliceContainer <Motion> {set infoLabelStr [get_voxel_info %x %y]} |
---|
420 | |
---|
421 | pack append $slicerWin $frame2 {top pady 0} $frame1 {top pady 0} |
---|
422 | |
---|
423 | # end of ui-only stuff |
---|
424 | } |
---|
425 | |
---|
426 | proc write_slice {name im} { |
---|
427 | puts "Saving slice .. $name" |
---|
428 | $im write $name |
---|
429 | } |
---|
430 | |
---|
431 | proc set_slice {num} { |
---|
432 | global sliceNum |
---|
433 | set sliceNum $num |
---|
434 | |
---|
435 | } |
---|
436 | |
---|
437 | proc write_slice_movie {name slice} { |
---|
438 | |
---|
439 | set size [get_slice_size] |
---|
440 | puts "Size .. $size" |
---|
441 | exec mkdir -p $name |
---|
442 | |
---|
443 | for {set i 0} {$i < $size} {incr i} { |
---|
444 | set_slice $i |
---|
445 | set numname [expr $i + 10000] |
---|
446 | update_slice |
---|
447 | set filename "$name/$numname.ppm" |
---|
448 | puts $filename |
---|
449 | write_slice $filename $slice |
---|
450 | } |
---|
451 | } |
---|
452 | |
---|
453 | proc write_smooth_movie {name slice} { |
---|
454 | set size 15 |
---|
455 | puts "Size .. $size" |
---|
456 | exec mkdir -p $name |
---|
457 | |
---|
458 | for {set i 0} {$i < $size} {incr i} { |
---|
459 | set numname [expr $i + 10000] |
---|
460 | update_slice |
---|
461 | set filename "$name/$numname.ppm" |
---|
462 | puts $filename |
---|
463 | write_slice $filename $slice |
---|
464 | vrip_muckWithVol |
---|
465 | |
---|
466 | } |
---|
467 | |
---|
468 | } |
---|
469 | |
---|
470 | # Creates an alias for a command name |
---|
471 | proc alias {newname oldname} { |
---|
472 | eval "proc $newname args \{eval \"$oldname \$args\"\}" |
---|
473 | } |
---|
474 | |
---|
475 | proc do_nothing args {} |
---|
476 | |
---|
477 | alias show_render vrip_render_view |
---|
478 | alias slicer vrip_slicer |
---|
479 | alias cube vrip_cube |
---|
480 | alias transpxz vrip_transpxzrle |
---|
481 | |
---|
482 | if ($useNorm) { |
---|
483 | alias writegrid vrip_writegridnorm |
---|
484 | } else { |
---|
485 | alias writegrid vrip_writegrid |
---|
486 | } |
---|
487 | |
---|
488 | |
---|
489 | alias fill vrip_fillrle |
---|
490 | alias ellipse vrip_ellipserle |
---|
491 | alias cylinder vrip_cylinderrle |
---|
492 | alias extract vrip_extract |
---|
493 | alias avgdown vrip_avgdownrle |
---|
494 | alias blurvb vrip_blurvb |
---|
495 | |
---|
496 | alias camera do_nothing |
---|
497 | alias mesh do_nothing |
---|
498 | alias bpolygon do_nothing |
---|
499 | alias view do_nothing |
---|
500 | |
---|
501 | alias param vrip_param |
---|
502 | alias quit exit |
---|
503 | |
---|
504 | proc newfromply {plyfile res} { |
---|
505 | global env |
---|
506 | global conservativeBbox |
---|
507 | global conservativeBboxFactor |
---|
508 | |
---|
509 | catch {exec plybbox < $plyfile} msg |
---|
510 | |
---|
511 | scan $msg "%f %f %f %f %f %f" minx miny minz maxx maxy maxz |
---|
512 | set xlen [expr $maxx - $minx] |
---|
513 | set ylen [expr $maxy - $miny] |
---|
514 | set zlen [expr $maxz - $minz] |
---|
515 | set orgx [expr $xlen/2 + $minx] |
---|
516 | set orgy [expr $ylen/2 + $miny] |
---|
517 | set orgz [expr $zlen/2 + $minz] |
---|
518 | |
---|
519 | #if {$xlen > $ylen} {set maxdim $xlen} else {set maxdim $ylen} |
---|
520 | #if {$maxdim < $zlen} {set maxdim $zlen} |
---|
521 | #set dim [expr int(1.2*$maxdim/$res)] |
---|
522 | #puts "$xlen $ylen $zlen" |
---|
523 | #puts "newgrid $dim $res $orgx $orgy $orgz" |
---|
524 | #newgrid $dim $res $orgx $orgy $orgz |
---|
525 | |
---|
526 | if {$conservativeBbox} { |
---|
527 | set xdim [expr int($xlen/$res*$conservativeBboxFactor)] |
---|
528 | set ydim [expr int($ylen/$res*$conservativeBboxFactor)] |
---|
529 | set zdim [expr int($zlen/$res*$conservativeBboxFactor)] |
---|
530 | } else { |
---|
531 | set xdim [expr int($xlen/$res) + 10] |
---|
532 | set ydim [expr int($ylen/$res) + 10] |
---|
533 | set zdim [expr int($zlen/$res) + 10] |
---|
534 | } |
---|
535 | |
---|
536 | # We want to guarantee that the parity of the number of voxels |
---|
537 | # has not changed; this guarantees consistent alignment of the |
---|
538 | # grid w.r.t. the grid center -- David Koller (dk@cs.stanford.edu) |
---|
539 | if {[expr (round($xlen/$res))%2] != [expr $xdim%2]} {incr xdim} |
---|
540 | if {[expr (round($ylen/$res))%2] != [expr $ydim%2]} {incr ydim} |
---|
541 | if {[expr (round($zlen/$res))%2] != [expr $zdim%2]} {incr zdim} |
---|
542 | |
---|
543 | puts "newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz" |
---|
544 | newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz |
---|
545 | } |
---|
546 | |
---|
547 | |
---|
548 | proc newfromcyl {cylfile res} { |
---|
549 | global env |
---|
550 | global isLinux |
---|
551 | global conservativeBbox |
---|
552 | global conservativeBboxFactor |
---|
553 | |
---|
554 | set i 0 |
---|
555 | while {1} { |
---|
556 | set tmpPlyFile ${tempDir}/temp_$i.ply |
---|
557 | if {![file exists $tmpPlyFile]} { |
---|
558 | break |
---|
559 | } |
---|
560 | incr i |
---|
561 | } |
---|
562 | |
---|
563 | puts "Creating $tmpPlyFile for temporary usage..." |
---|
564 | if {$isLinux} { |
---|
565 | catch {exec cyb2ply $cylfile $tmpPlyFile} msg |
---|
566 | catch {exec plyxform -r 0 180 0 < $tmpPlyFile | plybbox} msg |
---|
567 | } else { |
---|
568 | catch {exec cyb2ply $cylfile $tmpPlyFile} msg |
---|
569 | catch {exec plyxform -r 0 180 0 < $tmpPlyFile | plybbox} msg |
---|
570 | } |
---|
571 | |
---|
572 | puts "Removing $tmpPlyFile..." |
---|
573 | catch {exec /bin/rm $tmpPlyFile} tmp |
---|
574 | scan $msg "%f %f %f %f %f %f" minx miny minz maxx maxy maxz |
---|
575 | set xlen [expr $maxx - $minx] |
---|
576 | set ylen [expr $maxy - $miny] |
---|
577 | set zlen [expr $maxz - $minz] |
---|
578 | set orgx [expr $xlen/2 + $minx] |
---|
579 | set orgy [expr $ylen/2 + $miny] |
---|
580 | set orgz [expr $zlen/2 + $minz] |
---|
581 | |
---|
582 | #if {$xlen > $ylen} {set maxdim $xlen} else {set maxdim $ylen} |
---|
583 | #if {$maxdim < $zlen} {set maxdim $zlen} |
---|
584 | #set dim [expr int(1.2*$maxdim/$res)] |
---|
585 | #puts "newgrid $dim $res $orgx $orgy $orgz" |
---|
586 | #newgrid $dim $res $orgx $orgy $orgz |
---|
587 | |
---|
588 | if {$conservativeBbox} { |
---|
589 | set xdim [expr int($xlen/$res*$conservativeBboxFactor)] |
---|
590 | set ydim [expr int($ylen/$res*$conservativeBboxFactor)] |
---|
591 | set zdim [expr int($zlen/$res*$conservativeBboxFactor)] |
---|
592 | } else { |
---|
593 | set xdim [expr int($xlen/$res) + 10] |
---|
594 | set ydim [expr int($ylen/$res) + 10] |
---|
595 | set zdim [expr int($zlen/$res) + 10] |
---|
596 | } |
---|
597 | |
---|
598 | # We want to guarantee that the parity of the number of voxels |
---|
599 | # has not changed; this guarantees consistent alignment of the |
---|
600 | # grid w.r.t. the grid center -- David Koller (dk@cs.stanford.edu) |
---|
601 | if {[expr (round($xlen/$res))%2] != [expr $xdim%2]} {incr xdim} |
---|
602 | if {[expr (round($ylen/$res))%2] != [expr $ydim%2]} {incr ydim} |
---|
603 | if {[expr (round($zlen/$res))%2] != [expr $zdim%2]} {incr zdim} |
---|
604 | |
---|
605 | puts "newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz" |
---|
606 | newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz |
---|
607 | } |
---|
608 | |
---|
609 | |
---|
610 | proc max {a b} { |
---|
611 | if {$a > $b} { |
---|
612 | return $a |
---|
613 | } else { |
---|
614 | return $b |
---|
615 | } |
---|
616 | } |
---|
617 | |
---|
618 | |
---|
619 | proc min {a b} { |
---|
620 | if {$a < $b} { |
---|
621 | return $a |
---|
622 | } else { |
---|
623 | return $b |
---|
624 | } |
---|
625 | } |
---|
626 | |
---|
627 | |
---|
628 | proc newfromconf {confFile res} { |
---|
629 | global env |
---|
630 | global conservativeBbox |
---|
631 | global conservativeBboxFactor |
---|
632 | |
---|
633 | set fileid [open $confFile "r"] |
---|
634 | set count 0 |
---|
635 | set numchars [gets $fileid line($count)] |
---|
636 | incr count |
---|
637 | while {$numchars > 0} { |
---|
638 | set numchars [gets $fileid line($count)] |
---|
639 | incr count |
---|
640 | } |
---|
641 | |
---|
642 | close $fileid |
---|
643 | |
---|
644 | set count [expr $count -1] |
---|
645 | |
---|
646 | set minx 10000000 |
---|
647 | set miny 10000000 |
---|
648 | set minz 10000000 |
---|
649 | set maxx -10000000 |
---|
650 | set maxy -10000000 |
---|
651 | set maxz -10000000 |
---|
652 | |
---|
653 | for {set index 0} {$index < $count} {incr index} { |
---|
654 | set curline $line($index) |
---|
655 | if {("bmesh" == [lindex $curline 0])} { |
---|
656 | set cmd "exec plyxform " |
---|
657 | |
---|
658 | set cmd "$cmd -t [lindex $curline 2] [lindex $curline 3] [lindex $curline 4]" |
---|
659 | set q3 [lindex $curline 8] |
---|
660 | set q3 [expr -$q3] |
---|
661 | set cmd "$cmd -q [lindex $curline 5] [lindex $curline 6] [lindex $curline 7] $q3" |
---|
662 | set cmd "$cmd < [lindex $curline 1] | plybbox" |
---|
663 | catch {eval $cmd} msg |
---|
664 | |
---|
665 | scan $msg "%f %f %f %f %f %f" newMinx newMiny newMinz \ |
---|
666 | newMaxx newMaxy newMaxz |
---|
667 | |
---|
668 | set minx [min $minx $newMinx] |
---|
669 | set miny [min $miny $newMiny] |
---|
670 | set minz [min $minz $newMinz] |
---|
671 | |
---|
672 | set maxx [max $maxx $newMaxx] |
---|
673 | set maxy [max $maxy $newMaxy] |
---|
674 | set maxz [max $maxz $newMaxz] |
---|
675 | |
---|
676 | } |
---|
677 | } |
---|
678 | |
---|
679 | |
---|
680 | |
---|
681 | set xlen [expr $maxx - $minx] |
---|
682 | set ylen [expr $maxy - $miny] |
---|
683 | set zlen [expr $maxz - $minz] |
---|
684 | set orgx [expr $xlen/2 + $minx] |
---|
685 | set orgy [expr $ylen/2 + $miny] |
---|
686 | set orgz [expr $zlen/2 + $minz] |
---|
687 | |
---|
688 | #if {$xlen > $ylen} {set maxdim $xlen} else {set maxdim $ylen} |
---|
689 | #if {$maxdim < $zlen} {set maxdim $zlen} |
---|
690 | #set dim [expr int(1.2*$maxdim/$res)] |
---|
691 | #puts "$xlen $ylen $zlen" |
---|
692 | #puts "newgrid $dim $res $orgx $orgy $orgz" |
---|
693 | #newgrid $dim $res $orgx $orgy $orgz |
---|
694 | |
---|
695 | if {$conservativeBbox} { |
---|
696 | set xdim [expr int($xlen/$res*$conservativeBboxFactor)] |
---|
697 | set ydim [expr int($ylen/$res*$conservativeBboxFactor)] |
---|
698 | set zdim [expr int($zlen/$res*$conservativeBboxFactor)] |
---|
699 | } else { |
---|
700 | set xdim [expr int($xlen/$res) + 10] |
---|
701 | set ydim [expr int($ylen/$res) + 10] |
---|
702 | set zdim [expr int($zlen/$res) + 10] |
---|
703 | } |
---|
704 | |
---|
705 | # We want to guarantee that the parity of the number of voxels |
---|
706 | # has not changed; this guarantees consistent alignment of the |
---|
707 | # grid w.r.t. the grid center -- David Koller (dk@cs.stanford.edu) |
---|
708 | if {[expr (round($xlen/$res))%2] != [expr $xdim%2]} {incr xdim} |
---|
709 | if {[expr (round($ylen/$res))%2] != [expr $ydim%2]} {incr ydim} |
---|
710 | if {[expr (round($zlen/$res))%2] != [expr $zdim%2]} {incr zdim} |
---|
711 | |
---|
712 | puts "newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz" |
---|
713 | newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz |
---|
714 | } |
---|
715 | |
---|
716 | |
---|
717 | proc newfromlist {listfile res} { |
---|
718 | global env |
---|
719 | global conservativeBbox |
---|
720 | global conservativeBboxFactor |
---|
721 | |
---|
722 | set fileid [open $listfile "r"] |
---|
723 | set count 0 |
---|
724 | set numchars [gets $fileid line($count)] |
---|
725 | incr count |
---|
726 | while {$numchars > 0} { |
---|
727 | set numchars [gets $fileid line($count)] |
---|
728 | incr count |
---|
729 | } |
---|
730 | |
---|
731 | close $fileid |
---|
732 | |
---|
733 | set count [expr $count -1] |
---|
734 | |
---|
735 | set minx 10000000 |
---|
736 | set miny 10000000 |
---|
737 | set minz 10000000 |
---|
738 | set maxx -10000000 |
---|
739 | set maxy -10000000 |
---|
740 | set maxz -10000000 |
---|
741 | |
---|
742 | for {set index 0} {$index < $count} {incr index} { |
---|
743 | set curmesh $line($index) |
---|
744 | set rootName [file root $curmesh] |
---|
745 | set xfFile "${rootName}.xf" |
---|
746 | if {[file exists $xfFile]} { |
---|
747 | set cmd "exec plyxform -f $xfFile < $curmesh | plybbox" |
---|
748 | } else { |
---|
749 | set cmd "exec plybbox < $curmesh" |
---|
750 | } |
---|
751 | |
---|
752 | catch {eval $cmd} msg |
---|
753 | |
---|
754 | scan $msg "%f %f %f %f %f %f" newMinx newMiny newMinz \ |
---|
755 | newMaxx newMaxy newMaxz |
---|
756 | |
---|
757 | set minx [min $minx $newMinx] |
---|
758 | set miny [min $miny $newMiny] |
---|
759 | set minz [min $minz $newMinz] |
---|
760 | |
---|
761 | set maxx [max $maxx $newMaxx] |
---|
762 | set maxy [max $maxy $newMaxy] |
---|
763 | set maxz [max $maxz $newMaxz] |
---|
764 | } |
---|
765 | |
---|
766 | set xlen [expr $maxx - $minx] |
---|
767 | set ylen [expr $maxy - $miny] |
---|
768 | set zlen [expr $maxz - $minz] |
---|
769 | set orgx [expr $xlen/2 + $minx] |
---|
770 | set orgy [expr $ylen/2 + $miny] |
---|
771 | set orgz [expr $zlen/2 + $minz] |
---|
772 | |
---|
773 | #if {$xlen > $ylen} {set maxdim $xlen} else {set maxdim $ylen} |
---|
774 | #if {$maxdim < $zlen} {set maxdim $zlen} |
---|
775 | #set dim [expr int(1.2*$maxdim/$res)] |
---|
776 | #puts "$xlen $ylen $zlen" |
---|
777 | #puts "newgrid $dim $res $orgx $orgy $orgz" |
---|
778 | #newgrid $dim $res $orgx $orgy $orgz |
---|
779 | |
---|
780 | if {$conservativeBbox} { |
---|
781 | set xdim [expr int($xlen/$res*$conservativeBboxFactor)] |
---|
782 | set ydim [expr int($ylen/$res*$conservativeBboxFactor)] |
---|
783 | set zdim [expr int($zlen/$res*$conservativeBboxFactor)] |
---|
784 | } else { |
---|
785 | set xdim [expr int($xlen/$res) + 10] |
---|
786 | set ydim [expr int($ylen/$res) + 10] |
---|
787 | set zdim [expr int($zlen/$res) + 10] |
---|
788 | } |
---|
789 | |
---|
790 | # We want to guarantee that the parity of the number of voxels |
---|
791 | # has not changed; this guarantees consistent alignment of the |
---|
792 | # grid w.r.t. the grid center -- David Koller (dk@cs.stanford.edu) |
---|
793 | if {[expr (round($xlen/$res))%2] != [expr $xdim%2]} {incr xdim} |
---|
794 | if {[expr (round($ylen/$res))%2] != [expr $ydim%2]} {incr ydim} |
---|
795 | if {[expr (round($zlen/$res))%2] != [expr $zdim%2]} {incr zdim} |
---|
796 | |
---|
797 | puts "newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz" |
---|
798 | newgrid $xdim $ydim $zdim $res $orgx $orgy $orgz |
---|
799 | } |
---|
800 | |
---|
801 | |
---|
802 | proc fillprep {} { |
---|
803 | fill 1 0 |
---|
804 | vrip_param -use_tails 1 -fill_gaps 1 -fill_bg 0 |
---|
805 | alias bmesh bmeshlin |
---|
806 | } |
---|
807 | |
---|
808 | |
---|
809 | proc newFromConf {gridFile confFile boundMesh voxelSize} { |
---|
810 | |
---|
811 | set ext [file extension $boundMesh] |
---|
812 | if {$ext == ".ply"} { |
---|
813 | newfromply $boundMesh $voxelSize |
---|
814 | } elseif {$ext == ".conf"} { |
---|
815 | newfromconf $boundMesh $voxelSize |
---|
816 | } elseif {$ext == ".cyb"} { |
---|
817 | # this doesn't actually work, though it would be nice |
---|
818 | # to support cylindrical scans somehow... |
---|
819 | newfromcyl $boundMesh $voxelSize |
---|
820 | } else { |
---|
821 | newfromlist $boundMesh $voxelSize |
---|
822 | } |
---|
823 | |
---|
824 | fill 1 0 |
---|
825 | |
---|
826 | set ext [file extension $confFile] |
---|
827 | if {$ext == ".conf"} { |
---|
828 | source $confFile |
---|
829 | } else { |
---|
830 | set fileid [open $confFile r] |
---|
831 | set numchars [gets $fileid filename] |
---|
832 | puts $numchars |
---|
833 | while {$numchars > 0} { |
---|
834 | bmesh $filename |
---|
835 | set numchars [gets $fileid filename] |
---|
836 | } |
---|
837 | close $fileid |
---|
838 | } |
---|
839 | |
---|
840 | puts "Writing to file ${gridFile}..." |
---|
841 | flush stdout |
---|
842 | writegrid $gridFile |
---|
843 | } |
---|
844 | |
---|
845 | |
---|
846 | proc updateFromConf {gridFile confFile} { |
---|
847 | |
---|
848 | readgrid $gridFile |
---|
849 | |
---|
850 | set ext [file extension $confFile] |
---|
851 | if {$ext == ".conf"} { |
---|
852 | source $confFile |
---|
853 | } else { |
---|
854 | set fileid [open $confFile r] |
---|
855 | set numchars [gets $fileid filename] |
---|
856 | puts $numchars |
---|
857 | while {$numchars > 0} { |
---|
858 | bmesh $filename |
---|
859 | set numchars [gets $fileid filename] |
---|
860 | } |
---|
861 | close $fileid |
---|
862 | } |
---|
863 | |
---|
864 | puts "" |
---|
865 | puts "Writing to file ${gridFile}..." |
---|
866 | flush stdout |
---|
867 | writegrid $gridFile |
---|
868 | } |
---|
869 | |
---|
870 | proc updateSilFromConf {gridFile confFile} { |
---|
871 | |
---|
872 | readgrid $gridFile |
---|
873 | |
---|
874 | set fileid [open $confFile "r"] |
---|
875 | set count 0 |
---|
876 | set numchars [gets $fileid line($count)] |
---|
877 | incr count |
---|
878 | while {$numchars > 0} { |
---|
879 | set numchars [gets $fileid line($count)] |
---|
880 | incr count |
---|
881 | } |
---|
882 | close $fileid |
---|
883 | |
---|
884 | for {set i 0} {$i < $count} {incr i} { |
---|
885 | set curline $line($i) |
---|
886 | if {("bmesh" == [lindex $curline 0]) } { |
---|
887 | set mesh [lindex $curline 1] |
---|
888 | catch {exec plyhead $mesh} msg |
---|
889 | set x [string last echo_lgincr $msg] |
---|
890 | set x [expr $x + [string length echo_lgincr] + 1] |
---|
891 | set x [string range $msg $x end] |
---|
892 | scan $x %f lgincr |
---|
893 | set image "[file root $mesh].rgb" |
---|
894 | exec oneband $image ${tempDir}/_temp.bw 1 |
---|
895 | exec iflip ${tempDir}/_temp.bw ${tempDir}/_temp2.bw xy |
---|
896 | exec cybsil2ply ${tempDir}/_temp2.bw ${tempDir}/_temp.ply $lgincr |
---|
897 | set newCmd [lreplace $curline 1 1 "${tempDir}/_temp.ply"] |
---|
898 | eval $newCmd |
---|
899 | exec rm ${tempDir}/_temp.bw ${tempDir}/_temp2.bw ${tempDir}/_temp.ply |
---|
900 | } |
---|
901 | } |
---|
902 | |
---|
903 | puts "" |
---|
904 | puts "Writing to file ${gridFile}..." |
---|
905 | flush stdout |
---|
906 | writegrid $gridFile |
---|
907 | } |
---|
908 | |
---|
909 | |
---|
910 | proc changeRampScale {scale} { |
---|
911 | vrip_param -ramp_width [expr 0.002 * $scale] |
---|
912 | vrip_param -w1 [expr 0.003 * $scale] |
---|
913 | vrip_param -w2 [expr 0.0025 * $scale] |
---|
914 | vrip_param -w3 [expr -0.001 * $scale] |
---|
915 | vrip_param -w4 [expr -0.0015 * $scale] |
---|
916 | vrip_param -w5 [expr -0.002 * $scale] |
---|
917 | } |
---|
918 | |
---|
919 | set resToScaleMap(0.002) 6 |
---|
920 | set resToScaleMap(0.001) 3 |
---|
921 | set resToScaleMap(0.0005) 1.5 |
---|
922 | set resToScaleMap(0.00035) 1 |
---|
923 | set resToScaleMap(0.00025) 0.5 |
---|
924 | |
---|
925 | changeRampScale 1.5 |
---|
926 | |
---|
927 | #vrip_param -max_boundary_steps 3 -view_weight_exp 1 |
---|
928 | |
---|
929 | #vrip_param -min_view_dot 0.25 |
---|
930 | |
---|
931 | #vrip_param -max_edge_length [expr 0.003 * $scale] |
---|
932 | |
---|
933 | |
---|
934 | |
---|
935 | |
---|
936 | newgrid 100 0.0005 |
---|
937 | |
---|
938 | if {[uiExists]} { |
---|
939 | bind all <Escape> {puts ""; exit} |
---|
940 | } |
---|