1 | |
---|
2 | proc usage args { |
---|
3 | puts "" |
---|
4 | puts "Usage: vripsurf \[options\] <vrip_file> <ply_file>" |
---|
5 | puts " " |
---|
6 | puts " Options:" |
---|
7 | puts " -remove_slivers (default)" |
---|
8 | puts " -no_remove_slivers" |
---|
9 | puts " -fill_holes" |
---|
10 | puts " -filter_holes" |
---|
11 | puts " -crunch" |
---|
12 | puts " " |
---|
13 | exit |
---|
14 | } |
---|
15 | |
---|
16 | # Print usage if necessary... |
---|
17 | if {$argc == 0 || [lindex $argv 0] == "-h"} { |
---|
18 | usage |
---|
19 | } |
---|
20 | |
---|
21 | vrip_param -quiet 1 |
---|
22 | |
---|
23 | set vripDir $env(VRIP_DIR) |
---|
24 | |
---|
25 | # Set gridFile, plyFile to be empty, and fill them in |
---|
26 | # with the first two non-"-" arguments |
---|
27 | set gridFile "" |
---|
28 | set plyFile "" |
---|
29 | |
---|
30 | set fillHoles 0 |
---|
31 | set filterHoles 0 |
---|
32 | set removeSlivers 1 |
---|
33 | set useValueWeight 0 |
---|
34 | set generateNorm 0 |
---|
35 | set gradientForConfidence 0 |
---|
36 | set marchArgs "" |
---|
37 | set crunch 0 |
---|
38 | |
---|
39 | # Parse arguments |
---|
40 | for {set i 0} {$i < $argc} {incr i} { |
---|
41 | set arg [lindex $argv $i] |
---|
42 | if {[string index $arg 0] == "-"} { |
---|
43 | # Parse -flags |
---|
44 | |
---|
45 | if {$arg == "-h"} { |
---|
46 | usage |
---|
47 | } elseif {$arg == "-fill_holes"} { |
---|
48 | set fillHoles 1 |
---|
49 | } elseif {$arg == "-remove_slivers"} { |
---|
50 | set removeSlivers 1 |
---|
51 | } elseif {$arg == "-no_remove_slivers"} { |
---|
52 | set removeSlivers 0 |
---|
53 | } elseif {$arg == "-filter_holes"} { |
---|
54 | set filterHoles 1 |
---|
55 | } elseif {$arg == "-crunch"} { |
---|
56 | set crunch 1 |
---|
57 | } elseif {$arg == "-thresh"} { |
---|
58 | incr i |
---|
59 | set arg [lindex $argv $i] |
---|
60 | set marchArgs "$marchArgs -thresh $arg" |
---|
61 | } elseif {$arg == "-norm"} { |
---|
62 | set generateNorm 1 |
---|
63 | set marchArgs "$marchArgs -n" |
---|
64 | } elseif {$arg == "-vw"} { |
---|
65 | set useValueWeight 1 |
---|
66 | set marchArgs "$marchArgs -vw" |
---|
67 | } elseif {$arg == "-gc"} { |
---|
68 | set gradientForConfidence 1 |
---|
69 | set marchArgs "$marchArgs -gc" |
---|
70 | } else { |
---|
71 | puts "Invalid argument '$arg'." |
---|
72 | usage |
---|
73 | exit |
---|
74 | } |
---|
75 | |
---|
76 | } else { |
---|
77 | # Parse non--flag arguments |
---|
78 | if {$gridFile == ""} { |
---|
79 | set gridFile $arg |
---|
80 | } elseif {$plyFile == ""} { |
---|
81 | set plyFile $arg |
---|
82 | } else { |
---|
83 | puts "Error: unhandled argument: $arg" |
---|
84 | exit |
---|
85 | } |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | # Check to make sure we got the required args... |
---|
90 | if {$gridFile == "" || $plyFile == ""} { |
---|
91 | usage |
---|
92 | } |
---|
93 | |
---|
94 | #check 1st arg for validity |
---|
95 | if {![file isfile $gridFile]} { |
---|
96 | puts stderr "Error: Could not open grid file: $gridFile" |
---|
97 | exit |
---|
98 | } |
---|
99 | |
---|
100 | |
---|
101 | # Figure out where to save tmp files. If /usr/tmp/openspace/ |
---|
102 | # exists, use that instead. (lucas mod) |
---|
103 | if {[file exists /usr/tmp/openspace]} { |
---|
104 | puts "Using /usr/tmp/openspace/" |
---|
105 | set tempDir "/usr/tmp/openspace" |
---|
106 | } elseif {[file exists /usr/tmp]} { |
---|
107 | set tempDir "/usr/tmp" |
---|
108 | } elseif {[file exists /var/tmp]} { |
---|
109 | set tempDir "/var/tmp" |
---|
110 | } elseif {[file exists /tmp]} { |
---|
111 | set tempDir "/tmp" |
---|
112 | } |
---|
113 | |
---|
114 | if {[file extension $gridFile] == ".flat"} { |
---|
115 | vrip_readflatgrid $gridFile |
---|
116 | } else { |
---|
117 | readgrid $gridFile |
---|
118 | } |
---|
119 | |
---|
120 | if {$fillHoles} { |
---|
121 | puts "Preparing for marching cubes" |
---|
122 | vrip_varfromconst |
---|
123 | |
---|
124 | set i 0 |
---|
125 | |
---|
126 | while {1} { |
---|
127 | set tempFileName $tempDir/temp_$i.occ |
---|
128 | if {![file exists $tempFileName]} { |
---|
129 | break |
---|
130 | } |
---|
131 | incr i |
---|
132 | } |
---|
133 | puts "Creating $tempFileName..." |
---|
134 | flush stdout |
---|
135 | writegrid $tempFileName |
---|
136 | exec chmod +w $tempFileName |
---|
137 | |
---|
138 | puts "Generating polygons with marching cubes..." |
---|
139 | flush stdout |
---|
140 | set cmd "exec vripmarch $marchArgs $tempFileName $plyFile -1 >@stdout" |
---|
141 | |
---|
142 | # set cmd "exec /u/leslie/ply/src/march/vripmarch $marchArgs $tempFileName $plyFile -1 >@stdout" |
---|
143 | eval $cmd |
---|
144 | |
---|
145 | puts "Removing $tempFileName..." |
---|
146 | flush stdout |
---|
147 | exec rm $tempFileName 2> /dev/null |
---|
148 | |
---|
149 | puts "Extracting largest connected component..." |
---|
150 | flush stdout |
---|
151 | exec plycomps -m 1 $plyFile -t 1 < $plyFile 2> /dev/null |
---|
152 | |
---|
153 | } else { |
---|
154 | if {0} { |
---|
155 | puts "Generating polygons with marching cubes..." |
---|
156 | flush stdout |
---|
157 | |
---|
158 | set cmd "exec vripmarch $marchArgs $gridFile $plyFile >@stdout" |
---|
159 | |
---|
160 | # set cmd "exec /u/leslie/ply/src/march/vripmarch $marchArgs $gridFile $plyFile >@stdout" |
---|
161 | |
---|
162 | eval $cmd |
---|
163 | } else { |
---|
164 | puts "Preparing for marching cubes" |
---|
165 | vrip_varfromconst |
---|
166 | |
---|
167 | set i 0 |
---|
168 | while {1} { |
---|
169 | set tempFileName $tempDir/temp_$i.vri |
---|
170 | if {![file exists $tempFileName]} { |
---|
171 | break |
---|
172 | } |
---|
173 | incr i |
---|
174 | } |
---|
175 | puts "Creating $tempFileName..." |
---|
176 | flush stdout |
---|
177 | writegrid $tempFileName |
---|
178 | exec chmod +w $tempFileName |
---|
179 | |
---|
180 | puts "Generating polygons with marching cubes..." |
---|
181 | flush stdout |
---|
182 | |
---|
183 | set cmd "exec vripmarch $marchArgs $tempFileName $plyFile >@stdout" |
---|
184 | # set cmd "exec /u/leslie/ply/src/march/vripmarch $marchArgs $tempFileName $plyFile >@stdout" |
---|
185 | |
---|
186 | eval $cmd |
---|
187 | puts "Removing $tempFileName..." |
---|
188 | flush stdout |
---|
189 | exec rm $tempFileName 2> /dev/null |
---|
190 | } |
---|
191 | } |
---|
192 | |
---|
193 | if {$removeSlivers} { |
---|
194 | puts "Running plyclean to remove sliver triangles..." |
---|
195 | flush stdout |
---|
196 | catch {exec plyclean -q -defaults -o $plyFile $plyFile} msg |
---|
197 | # catch {exec /u/leslie/ply/src/plyclean/plyclean -q -defaults -o $plyFile $plyFile} msg |
---|
198 | puts $msg |
---|
199 | } |
---|
200 | |
---|
201 | if {$filterHoles} { |
---|
202 | exec trifilt $plyFile $plyFile \ |
---|
203 | -iters 50 -alpha 0.67 -lambda -0.63 -minconf 0.025 -confsteps 8 |
---|
204 | } |
---|
205 | |
---|
206 | if {$crunch} { |
---|
207 | puts "Generating multi-res..." |
---|
208 | flush stdout |
---|
209 | exec ply2crunchset $plyFile 2>/dev/null |
---|
210 | } |
---|
211 | |
---|
212 | |
---|
213 | exit |
---|
214 | |
---|