-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathutil_8cpp-source.html
476 lines (476 loc) · 68.6 KB
/
util_8cpp-source.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>pbrt: util.cpp Source File</title>
<link href="doxygen.css" rel="stylesheet" type="text/css">
<link href="tabs.css" rel="stylesheet" type="text/css">
</head><body>
<!-- Generated by Doxygen 1.5.6 -->
<div class="navigation" id="top">
<div class="tabs">
<ul>
<li><a href="index.html"><span>Main Page</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<h1>util.cpp</h1><a href="util_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001
<a name="l00002"></a>00002 <span class="comment">/*</span>
<a name="l00003"></a>00003 <span class="comment"> pbrt source code Copyright(c) 1998-2007 Matt Pharr and Greg Humphreys.</span>
<a name="l00004"></a>00004 <span class="comment"></span>
<a name="l00005"></a>00005 <span class="comment"> This file is part of pbrt.</span>
<a name="l00006"></a>00006 <span class="comment"></span>
<a name="l00007"></a>00007 <span class="comment"> pbrt is free software; you can redistribute it and/or modify</span>
<a name="l00008"></a>00008 <span class="comment"> it under the terms of the GNU General Public License as published by</span>
<a name="l00009"></a>00009 <span class="comment"> the Free Software Foundation; either version 2 of the License, or</span>
<a name="l00010"></a>00010 <span class="comment"> (at your option) any later version. Note that the text contents of</span>
<a name="l00011"></a>00011 <span class="comment"> the book "Physically Based Rendering" are *not* licensed under the</span>
<a name="l00012"></a>00012 <span class="comment"> GNU GPL.</span>
<a name="l00013"></a>00013 <span class="comment"></span>
<a name="l00014"></a>00014 <span class="comment"> pbrt is distributed in the hope that it will be useful,</span>
<a name="l00015"></a>00015 <span class="comment"> but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00016"></a>00016 <span class="comment"> MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the</span>
<a name="l00017"></a>00017 <span class="comment"> GNU General Public License for more details.</span>
<a name="l00018"></a>00018 <span class="comment"></span>
<a name="l00019"></a>00019 <span class="comment"> You should have received a copy of the GNU General Public License</span>
<a name="l00020"></a>00020 <span class="comment"> along with this program. If not, see <http://www.gnu.org/licenses/>.</span>
<a name="l00021"></a>00021 <span class="comment"></span>
<a name="l00022"></a>00022 <span class="comment"> */</span>
<a name="l00023"></a>00023
<a name="l00024"></a>00024 <span class="comment">// util.cpp*</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="pbrt_8h.html">pbrt.h</a>"</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include "<a class="code" href="timer_8h.html">timer.h</a>"</span>
<a name="l00027"></a>00027 <span class="preprocessor">#include <map></span>
<a name="l00028"></a>00028 <span class="keyword">using</span> std::map;
<a name="l00029"></a>00029 <span class="comment">// Error Reporting Includes</span>
<a name="l00030"></a>00030 <span class="preprocessor">#include <stdarg.h></span>
<a name="l00031"></a>00031 <span class="comment">// Error Reporting Definitions</span>
<a name="l00032"></a><a class="code" href="util_8cpp.html#23fa481616235c89f10f697a46849b77">00032</a> <span class="preprocessor">#define PBRT_ERROR_IGNORE 0</span>
<a name="l00033"></a><a class="code" href="util_8cpp.html#9799945fadcad47bd10e04485621095e">00033</a> <span class="preprocessor"></span><span class="preprocessor">#define PBRT_ERROR_CONTINUE 1</span>
<a name="l00034"></a><a class="code" href="util_8cpp.html#23dc591adb2ee500bffcfb4260484cfa">00034</a> <span class="preprocessor"></span><span class="preprocessor">#define PBRT_ERROR_ABORT 2</span>
<a name="l00035"></a>00035 <span class="preprocessor"></span><span class="comment">// Error Reporting Functions</span>
<a name="l00036"></a><a class="code" href="util_8cpp.html#d24f2bc901dde8c27c69ba828b9d05cd">00036</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="util_8cpp.html#d24f2bc901dde8c27c69ba828b9d05cd">processError</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *format, va_list args,
<a name="l00037"></a>00037 <span class="keyword">const</span> <span class="keywordtype">char</span> *message, <span class="keywordtype">int</span> disposition) {
<a name="l00038"></a>00038 <span class="preprocessor">#ifndef WIN32</span>
<a name="l00039"></a>00039 <span class="preprocessor"></span> <span class="keywordtype">char</span> *errorBuf;
<a name="l00040"></a>00040 vasprintf(&errorBuf, format, args);
<a name="l00041"></a>00041 <span class="preprocessor">#else</span>
<a name="l00042"></a>00042 <span class="preprocessor"></span> <span class="keywordtype">char</span> errorBuf[2048];
<a name="l00043"></a>00043 _vsnprintf(errorBuf, <span class="keyword">sizeof</span>(errorBuf), format, args);
<a name="l00044"></a>00044 <span class="preprocessor">#endif</span>
<a name="l00045"></a>00045 <span class="preprocessor"></span> <span class="comment">// Report error</span>
<a name="l00046"></a>00046 <span class="keywordflow">switch</span> (disposition) {
<a name="l00047"></a>00047 <span class="keywordflow">case</span> <a class="code" href="util_8cpp.html#23fa481616235c89f10f697a46849b77">PBRT_ERROR_IGNORE</a>:
<a name="l00048"></a>00048 <span class="keywordflow">return</span>;
<a name="l00049"></a>00049 <span class="keywordflow">case</span> <a class="code" href="util_8cpp.html#9799945fadcad47bd10e04485621095e">PBRT_ERROR_CONTINUE</a>:
<a name="l00050"></a>00050 fprintf(stderr, <span class="stringliteral">"%s: %s\n"</span>, message, errorBuf);
<a name="l00051"></a>00051 <span class="comment">// Print scene file and line number, if appropriate</span>
<a name="l00052"></a>00052 <span class="keyword">extern</span> <span class="keywordtype">int</span> <a class="code" href="pbrtlex_8l.html#7661b5d028be7f8997cef563e3890fd9">line_num</a>;
<a name="l00053"></a>00053 <span class="keywordflow">if</span> (line_num != 0) {
<a name="l00054"></a>00054 <span class="keyword">extern</span> <span class="keywordtype">string</span> <a class="code" href="core_2samplepat_8cpp.html#3ffcdfc07f90b7e8cdef3ed656156aaf">current_file</a>;
<a name="l00055"></a>00055 fprintf(stderr, <span class="stringliteral">"\tLine %d, file %s\n"</span>, line_num,
<a name="l00056"></a>00056 current_file.c_str());
<a name="l00057"></a>00057 }
<a name="l00058"></a>00058 <span class="keywordflow">break</span>;
<a name="l00059"></a>00059 <span class="keywordflow">case</span> <a class="code" href="util_8cpp.html#23dc591adb2ee500bffcfb4260484cfa">PBRT_ERROR_ABORT</a>:
<a name="l00060"></a>00060 fprintf(stderr, <span class="stringliteral">"%s: %s\n"</span>, message, errorBuf);
<a name="l00061"></a>00061 <span class="comment">// Print scene file and line number, if appropriate</span>
<a name="l00062"></a>00062 <span class="keyword">extern</span> <span class="keywordtype">int</span> line_num;
<a name="l00063"></a>00063 <span class="keywordflow">if</span> (line_num != 0) {
<a name="l00064"></a>00064 <span class="keyword">extern</span> <span class="keywordtype">string</span> <a class="code" href="core_2samplepat_8cpp.html#3ffcdfc07f90b7e8cdef3ed656156aaf">current_file</a>;
<a name="l00065"></a>00065 fprintf(stderr, <span class="stringliteral">"\tLine %d, file %s\n"</span>, line_num,
<a name="l00066"></a>00066 current_file.c_str());
<a name="l00067"></a>00067 }
<a name="l00068"></a>00068 exit(1);
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070 <span class="preprocessor">#ifndef WIN32</span>
<a name="l00071"></a>00071 <span class="preprocessor"></span> free(errorBuf);
<a name="l00072"></a>00072 <span class="preprocessor">#endif</span>
<a name="l00073"></a>00073 <span class="preprocessor"></span>}
<a name="l00074"></a><a class="code" href="util_8cpp.html#349cd361a2099e5e4cae3c0a1c33fe11">00074</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">void</span> <a class="code" href="pbrt_8h.html#e61c03aa347d076dc427f407cfafe71f">Info</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...) {
<a name="l00075"></a>00075 va_list args;
<a name="l00076"></a>00076 va_start(args, format);
<a name="l00077"></a>00077 <a class="code" href="util_8cpp.html#d24f2bc901dde8c27c69ba828b9d05cd">processError</a>(format, args, <span class="stringliteral">"Notice"</span>, <a class="code" href="util_8cpp.html#9799945fadcad47bd10e04485621095e">PBRT_ERROR_CONTINUE</a>);
<a name="l00078"></a>00078 va_end(args);
<a name="l00079"></a>00079 }
<a name="l00080"></a><a class="code" href="util_8cpp.html#88fd06ceee1aac9c08012d4e53c17cec">00080</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">void</span> <a class="code" href="pbrt_8h.html#79abc2e750c4774bd9d433ad4f6e440a">Warning</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...) {
<a name="l00081"></a>00081 va_list args;
<a name="l00082"></a>00082 va_start(args, format);
<a name="l00083"></a>00083 <a class="code" href="util_8cpp.html#d24f2bc901dde8c27c69ba828b9d05cd">processError</a>(format, args, <span class="stringliteral">"Warning"</span>, <a class="code" href="util_8cpp.html#9799945fadcad47bd10e04485621095e">PBRT_ERROR_CONTINUE</a>);
<a name="l00084"></a>00084 va_end(args);
<a name="l00085"></a>00085 }
<a name="l00086"></a><a class="code" href="util_8cpp.html#8bb425e8dcd508af4246b1c6a5615a35">00086</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">void</span> <a class="code" href="pbrt_8h.html#d1a16fc9ced4ddc376b9d3e6607be15e">Error</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...) {
<a name="l00087"></a>00087 va_list args;
<a name="l00088"></a>00088 va_start(args, format);
<a name="l00089"></a>00089 <a class="code" href="util_8cpp.html#d24f2bc901dde8c27c69ba828b9d05cd">processError</a>(format, args, <span class="stringliteral">"Error"</span>, <a class="code" href="util_8cpp.html#9799945fadcad47bd10e04485621095e">PBRT_ERROR_CONTINUE</a>);
<a name="l00090"></a>00090 va_end(args);
<a name="l00091"></a>00091 }
<a name="l00092"></a><a class="code" href="util_8cpp.html#119f8a2cb62e220af14ce8e54965d3e1">00092</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">void</span> <a class="code" href="pbrt_8h.html#63fd51330b3b9d2663a08258601448e5">Severe</a>(<span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...) {
<a name="l00093"></a>00093 va_list args;
<a name="l00094"></a>00094 va_start(args, format);
<a name="l00095"></a>00095 <a class="code" href="util_8cpp.html#d24f2bc901dde8c27c69ba828b9d05cd">processError</a>(format, args, <span class="stringliteral">"Fatal Error"</span>, <a class="code" href="util_8cpp.html#23dc591adb2ee500bffcfb4260484cfa">PBRT_ERROR_ABORT</a>);
<a name="l00096"></a>00096 va_end(args);
<a name="l00097"></a>00097 }
<a name="l00098"></a>00098 <span class="comment">// Matrix Method Definitions</span>
<a name="l00099"></a><a class="code" href="util_8cpp.html#bc9110183d0d45769bb48ac20928a7a5">00099</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">bool</span> <a class="code" href="pbrt_8h.html#bc9110183d0d45769bb48ac20928a7a5">SolveLinearSystem2x2</a>(<span class="keyword">const</span> <span class="keywordtype">float</span> A[2][2],
<a name="l00100"></a>00100 <span class="keyword">const</span> <span class="keywordtype">float</span> B[2], <span class="keywordtype">float</span> x[2]) {
<a name="l00101"></a>00101 <span class="keywordtype">float</span> det = A[0][0]*A[1][1] - A[0][1]*A[1][0];
<a name="l00102"></a>00102 <span class="keywordflow">if</span> (fabsf(det) < 1e-5)
<a name="l00103"></a>00103 <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00104"></a>00104 <span class="keywordtype">float</span> invDet = 1.0f/det;
<a name="l00105"></a>00105 x[0] = (A[1][1]*B[0] - A[0][1]*B[1]) * invDet;
<a name="l00106"></a>00106 x[1] = (A[0][0]*B[1] - A[1][0]*B[0]) * invDet;
<a name="l00107"></a>00107 <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00108"></a>00108 }
<a name="l00109"></a><a class="code" href="structMatrix4x4.html#f43064162565b6a3ad4b2dc965b3583f">00109</a> <a class="code" href="structMatrix4x4.html#714a467ba7f85f88ebe3897b5e3580be">Matrix4x4::Matrix4x4</a>(<span class="keywordtype">float</span> mat[4][4]) {
<a name="l00110"></a>00110 <a class="code" href="pbrtparse_8y.html#2ac249754cc680184bc1b7825aacb876">memcpy</a>(<a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>, mat, 16*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
<a name="l00111"></a>00111 }
<a name="l00112"></a><a class="code" href="structMatrix4x4.html#1787ddf77911b608e2c8c37cb2ff027c">00112</a> <a class="code" href="structMatrix4x4.html#714a467ba7f85f88ebe3897b5e3580be">Matrix4x4::Matrix4x4</a>(<span class="keywordtype">float</span> t00, <span class="keywordtype">float</span> t01, <span class="keywordtype">float</span> t02, <span class="keywordtype">float</span> t03,
<a name="l00113"></a>00113 <span class="keywordtype">float</span> t10, <span class="keywordtype">float</span> t11, <span class="keywordtype">float</span> t12, <span class="keywordtype">float</span> t13,
<a name="l00114"></a>00114 <span class="keywordtype">float</span> t20, <span class="keywordtype">float</span> t21, <span class="keywordtype">float</span> t22, <span class="keywordtype">float</span> t23,
<a name="l00115"></a>00115 <span class="keywordtype">float</span> t30, <span class="keywordtype">float</span> t31, <span class="keywordtype">float</span> t32, <span class="keywordtype">float</span> t33) {
<a name="l00116"></a>00116 <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][0] = t00; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][1] = t01; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][2] = t02; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][3] = t03;
<a name="l00117"></a>00117 <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][0] = t10; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][1] = t11; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][2] = t12; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][3] = t13;
<a name="l00118"></a>00118 <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][0] = t20; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][1] = t21; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][2] = t22; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][3] = t23;
<a name="l00119"></a>00119 <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][0] = t30; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][1] = t31; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][2] = t32; <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][3] = t33;
<a name="l00120"></a>00120 }
<a name="l00121"></a><a class="code" href="structMatrix4x4.html#0523a8cf829f239e2ffdd93599926e0b">00121</a> <a class="code" href="classReference.html">Reference<Matrix4x4></a> <a class="code" href="structMatrix4x4.html#0523a8cf829f239e2ffdd93599926e0b">Matrix4x4::Transpose</a>()<span class="keyword"> const </span>{
<a name="l00122"></a>00122 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="structMatrix4x4.html#714a467ba7f85f88ebe3897b5e3580be">Matrix4x4</a>(<a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][0], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][0], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][0], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][0],
<a name="l00123"></a>00123 <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][1], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][1], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][1], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][1],
<a name="l00124"></a>00124 <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][2], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][2], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][2], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][2],
<a name="l00125"></a>00125 <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[0][3], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[1][3], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[2][3], <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>[3][3]);
<a name="l00126"></a>00126 }
<a name="l00127"></a><a class="code" href="structMatrix4x4.html#8ee73c372cbe5966f7e65a0fb2a91ea8">00127</a> <a class="code" href="classReference.html">Reference<Matrix4x4></a> <a class="code" href="structMatrix4x4.html#8ee73c372cbe5966f7e65a0fb2a91ea8">Matrix4x4::Inverse</a>()<span class="keyword"> const </span>{
<a name="l00128"></a>00128 <span class="keywordtype">int</span> indxc[4], indxr[4];
<a name="l00129"></a>00129 <span class="keywordtype">int</span> ipiv[4] = { 0, 0, 0, 0 };
<a name="l00130"></a>00130 <span class="keywordtype">float</span> minv[4][4];
<a name="l00131"></a>00131 <a class="code" href="pbrtparse_8y.html#2ac249754cc680184bc1b7825aacb876">memcpy</a>(minv, <a class="code" href="structMatrix4x4.html#34704c95239da68cb2c6bfbda06b720f">m</a>, 4*4*<span class="keyword">sizeof</span>(<span class="keywordtype">float</span>));
<a name="l00132"></a>00132 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < 4; i++) {
<a name="l00133"></a>00133 <span class="keywordtype">int</span> irow = -1, icol = -1;
<a name="l00134"></a>00134 <span class="keywordtype">float</span> big = 0.;
<a name="l00135"></a>00135 <span class="comment">// Choose pivot</span>
<a name="l00136"></a>00136 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < 4; j++) {
<a name="l00137"></a>00137 <span class="keywordflow">if</span> (ipiv[j] != 1) {
<a name="l00138"></a>00138 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0; k < 4; k++) {
<a name="l00139"></a>00139 <span class="keywordflow">if</span> (ipiv[k] == 0) {
<a name="l00140"></a>00140 <span class="keywordflow">if</span> (fabsf(minv[j][k]) >= big) {
<a name="l00141"></a>00141 big = float(fabsf(minv[j][k]));
<a name="l00142"></a>00142 irow = j;
<a name="l00143"></a>00143 icol = k;
<a name="l00144"></a>00144 }
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (ipiv[k] > 1)
<a name="l00147"></a>00147 <a class="code" href="pbrt_8h.html#d1a16fc9ced4ddc376b9d3e6607be15e">Error</a>(<span class="stringliteral">"Singular matrix in MatrixInvert"</span>);
<a name="l00148"></a>00148 }
<a name="l00149"></a>00149 }
<a name="l00150"></a>00150 }
<a name="l00151"></a>00151 ++ipiv[icol];
<a name="l00152"></a>00152 <span class="comment">// Swap rows _irow_ and _icol_ for pivot</span>
<a name="l00153"></a>00153 <span class="keywordflow">if</span> (irow != icol) {
<a name="l00154"></a>00154 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0; k < 4; ++k)
<a name="l00155"></a>00155 swap(minv[irow][k], minv[icol][k]);
<a name="l00156"></a>00156 }
<a name="l00157"></a>00157 indxr[i] = irow;
<a name="l00158"></a>00158 indxc[i] = icol;
<a name="l00159"></a>00159 <span class="keywordflow">if</span> (minv[icol][icol] == 0.)
<a name="l00160"></a>00160 <a class="code" href="pbrt_8h.html#d1a16fc9ced4ddc376b9d3e6607be15e">Error</a>(<span class="stringliteral">"Singular matrix in MatrixInvert"</span>);
<a name="l00161"></a>00161 <span class="comment">// Set $m[icol][icol]$ to one by scaling row _icol_ appropriately</span>
<a name="l00162"></a>00162 <span class="keywordtype">float</span> pivinv = 1.f / minv[icol][icol];
<a name="l00163"></a>00163 minv[icol][icol] = 1.f;
<a name="l00164"></a>00164 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < 4; j++)
<a name="l00165"></a>00165 minv[icol][j] *= pivinv;
<a name="l00166"></a>00166 <span class="comment">// Subtract this row from others to zero out their columns</span>
<a name="l00167"></a>00167 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 0; j < 4; j++) {
<a name="l00168"></a>00168 <span class="keywordflow">if</span> (j != icol) {
<a name="l00169"></a>00169 <span class="keywordtype">float</span> save = minv[j][icol];
<a name="l00170"></a>00170 minv[j][icol] = 0;
<a name="l00171"></a>00171 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0; k < 4; k++)
<a name="l00172"></a>00172 minv[j][k] -= minv[icol][k]*save;
<a name="l00173"></a>00173 }
<a name="l00174"></a>00174 }
<a name="l00175"></a>00175 }
<a name="l00176"></a>00176 <span class="comment">// Swap columns to reflect permutation</span>
<a name="l00177"></a>00177 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> j = 3; j >= 0; j--) {
<a name="l00178"></a>00178 <span class="keywordflow">if</span> (indxr[j] != indxc[j]) {
<a name="l00179"></a>00179 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> k = 0; k < 4; k++)
<a name="l00180"></a>00180 swap(minv[k][indxr[j]], minv[k][indxc[j]]);
<a name="l00181"></a>00181 }
<a name="l00182"></a>00182 }
<a name="l00183"></a>00183 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="structMatrix4x4.html#714a467ba7f85f88ebe3897b5e3580be">Matrix4x4</a>(minv);
<a name="l00184"></a>00184 }
<a name="l00185"></a>00185 <span class="comment">// Statistics Definitions</span>
<a name="l00186"></a><a class="code" href="structStatTracker.html">00186</a> <span class="keyword">struct </span><a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <a class="code" href="structStatTracker.html">StatTracker</a> {
<a name="l00187"></a>00187 <a class="code" href="structStatTracker.html">StatTracker</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &cat, <span class="keyword">const</span> <span class="keywordtype">string</span> &n,
<a name="l00188"></a>00188 <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> *pa, <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> *pb = NULL,
<a name="l00189"></a>00189 <span class="keywordtype">bool</span> percentage = <span class="keyword">true</span>);
<a name="l00190"></a><a class="code" href="structStatTracker.html#96b81596b9d18bfeece20dc807481181">00190</a> <span class="keywordtype">string</span> category, name;
<a name="l00191"></a><a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">00191</a> <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> *ptra, *ptrb;
<a name="l00192"></a><a class="code" href="structStatTracker.html#9563341f2a8457357ddeeb78c959636f">00192</a> <span class="keywordtype">bool</span> percentage;
<a name="l00193"></a>00193 };
<a name="l00194"></a><a class="code" href="util_8cpp.html#20d1921336d42e8a81d7f5d9f1d5c8cc">00194</a> <span class="keyword">typedef</span> map<std::pair<string, string>, <a class="code" href="structStatTracker.html">StatTracker</a> *> <a class="code" href="util_8cpp.html#20d1921336d42e8a81d7f5d9f1d5c8cc">TrackerMap</a>;
<a name="l00195"></a><a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">00195</a> <span class="keyword">static</span> <a class="code" href="util_8cpp.html#20d1921336d42e8a81d7f5d9f1d5c8cc">TrackerMap</a> <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>;
<a name="l00196"></a><a class="code" href="util_8cpp.html#0c83a6ff8d45d1d4e3886e9eb39a167c">00196</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="util_8cpp.html#0c83a6ff8d45d1d4e3886e9eb39a167c">addTracker</a>(<a class="code" href="structStatTracker.html">StatTracker</a> *newTracker) {
<a name="l00197"></a>00197 std::pair<string, string> s = std::make_pair(newTracker-><a class="code" href="structStatTracker.html#a093276b985be6f0917fd62a120422ec">category</a>, newTracker-><a class="code" href="structStatTracker.html#96b81596b9d18bfeece20dc807481181">name</a>);
<a name="l00198"></a>00198 <span class="keywordflow">if</span> (<a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.find(s) != <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.end()) {
<a name="l00199"></a>00199 newTracker-><a class="code" href="structStatTracker.html#bf6e0f882d825dd2e7e856f51afc4e44">ptra</a> = <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>[s]->ptra;
<a name="l00200"></a>00200 newTracker-><a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">ptrb</a> = <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>[s]->ptrb;
<a name="l00201"></a>00201 <span class="keywordflow">return</span>;
<a name="l00202"></a>00202 }
<a name="l00203"></a>00203 <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>[s] = newTracker;
<a name="l00204"></a>00204 }
<a name="l00205"></a>00205 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">StatsPrintVal</a>(FILE *f, <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> v);
<a name="l00206"></a>00206 <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">StatsPrintVal</a>(FILE *f, <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> v1, <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> v2);
<a name="l00207"></a>00207 <span class="comment">// Statistics Functions</span>
<a name="l00208"></a><a class="code" href="structStatTracker.html#e3e8cc44caae20932a993675fa00f867">00208</a> <a class="code" href="structStatTracker.html#e3e8cc44caae20932a993675fa00f867">StatTracker::StatTracker</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &cat, <span class="keyword">const</span> <span class="keywordtype">string</span> &n,
<a name="l00209"></a>00209 <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> *pa, <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> *pb, <span class="keywordtype">bool</span> p) {
<a name="l00210"></a>00210 <a class="code" href="structStatTracker.html#a093276b985be6f0917fd62a120422ec">category</a> = cat;
<a name="l00211"></a>00211 <a class="code" href="structStatTracker.html#96b81596b9d18bfeece20dc807481181">name</a> = n;
<a name="l00212"></a>00212 <a class="code" href="structStatTracker.html#bf6e0f882d825dd2e7e856f51afc4e44">ptra</a> = pa;
<a name="l00213"></a>00213 <a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">ptrb</a> = pb;
<a name="l00214"></a>00214 <a class="code" href="structStatTracker.html#9563341f2a8457357ddeeb78c959636f">percentage</a> = p;
<a name="l00215"></a>00215 }
<a name="l00216"></a><a class="code" href="classStatsCounter.html#48ad8a54f12c9c2e0edfbd7ce553395f">00216</a> <a class="code" href="classStatsCounter.html#48ad8a54f12c9c2e0edfbd7ce553395f">StatsCounter::StatsCounter</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &<a class="code" href="structStatTracker.html#a093276b985be6f0917fd62a120422ec">category</a>, <span class="keyword">const</span> <span class="keywordtype">string</span> &<a class="code" href="structStatTracker.html#96b81596b9d18bfeece20dc807481181">name</a>) {
<a name="l00217"></a>00217 <a class="code" href="classStatsCounter.html#8d342c40d0ec9e1f1df06c1b9381b142">num</a> = 0;
<a name="l00218"></a>00218 <a class="code" href="util_8cpp.html#0c83a6ff8d45d1d4e3886e9eb39a167c">addTracker</a>(<span class="keyword">new</span> <a class="code" href="structStatTracker.html">StatTracker</a>(category, name, &<a class="code" href="classStatsCounter.html#8d342c40d0ec9e1f1df06c1b9381b142">num</a>));
<a name="l00219"></a>00219 }
<a name="l00220"></a><a class="code" href="classStatsRatio.html#41566d0cabea431f1638b16aece69a36">00220</a> <a class="code" href="classStatsRatio.html#41566d0cabea431f1638b16aece69a36">StatsRatio::StatsRatio</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &category, <span class="keyword">const</span> <span class="keywordtype">string</span> &name) {
<a name="l00221"></a>00221 <a class="code" href="classStatsRatio.html#187e4155d86220b82835e70509ccb74b">na</a> = <a class="code" href="classStatsRatio.html#345c11747cce856b89f60155c1e59804">nb</a> = 0;
<a name="l00222"></a>00222 <a class="code" href="util_8cpp.html#0c83a6ff8d45d1d4e3886e9eb39a167c">addTracker</a>(<span class="keyword">new</span> <a class="code" href="structStatTracker.html">StatTracker</a>(category, name, &<a class="code" href="classStatsRatio.html#187e4155d86220b82835e70509ccb74b">na</a>, &<a class="code" href="classStatsRatio.html#345c11747cce856b89f60155c1e59804">nb</a>, <span class="keyword">false</span>));
<a name="l00223"></a>00223 }
<a name="l00224"></a><a class="code" href="classStatsPercentage.html#c9527f9f9efb794f2daf5b520ab4eb15">00224</a> <a class="code" href="classStatsPercentage.html#c9527f9f9efb794f2daf5b520ab4eb15">StatsPercentage::StatsPercentage</a>(<span class="keyword">const</span> <span class="keywordtype">string</span> &category, <span class="keyword">const</span> <span class="keywordtype">string</span> &name) {
<a name="l00225"></a>00225 <a class="code" href="classStatsPercentage.html#ad71d4304a7dd12c7a08782b4602da6e">na</a> = <a class="code" href="classStatsPercentage.html#26d3ac0c5c9444511244453926ad6849">nb</a> = 0;
<a name="l00226"></a>00226 <a class="code" href="util_8cpp.html#0c83a6ff8d45d1d4e3886e9eb39a167c">addTracker</a>(<span class="keyword">new</span> <a class="code" href="structStatTracker.html">StatTracker</a>(category, name, &<a class="code" href="classStatsPercentage.html#ad71d4304a7dd12c7a08782b4602da6e">na</a>, &<a class="code" href="classStatsPercentage.html#26d3ac0c5c9444511244453926ad6849">nb</a>, <span class="keyword">true</span>));
<a name="l00227"></a>00227 }
<a name="l00228"></a><a class="code" href="util_8cpp.html#c68db060238e5514e0a610cbae6ab40b">00228</a> <span class="keywordtype">void</span> <a class="code" href="pbrt_8h.html#c68db060238e5514e0a610cbae6ab40b">StatsPrint</a>(FILE *dest) {
<a name="l00229"></a>00229 fprintf(dest, <span class="stringliteral">"Statistics:\n"</span>);
<a name="l00230"></a>00230 TrackerMap::iterator iter = <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.begin();
<a name="l00231"></a>00231 <span class="keywordtype">string</span> lastCategory;
<a name="l00232"></a>00232 <span class="keywordflow">while</span> (iter != <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.end()) {
<a name="l00233"></a>00233 <span class="comment">// Print statistic</span>
<a name="l00234"></a>00234 <a class="code" href="structStatTracker.html">StatTracker</a> *tr = iter->second;
<a name="l00235"></a>00235 <span class="keywordflow">if</span> (tr-><a class="code" href="structStatTracker.html#a093276b985be6f0917fd62a120422ec">category</a> != lastCategory) {
<a name="l00236"></a>00236 fprintf(dest, <span class="stringliteral">"%s\n"</span>, tr-><a class="code" href="structStatTracker.html#a093276b985be6f0917fd62a120422ec">category</a>.c_str());
<a name="l00237"></a>00237 lastCategory = tr-><a class="code" href="structStatTracker.html#a093276b985be6f0917fd62a120422ec">category</a>;
<a name="l00238"></a>00238 }
<a name="l00239"></a>00239 fprintf(dest, <span class="stringliteral">" %s"</span>, tr-><a class="code" href="structStatTracker.html#96b81596b9d18bfeece20dc807481181">name</a>.c_str());
<a name="l00240"></a>00240 <span class="comment">// Pad out to results column</span>
<a name="l00241"></a>00241 <span class="keywordtype">int</span> resultsColumn = 56;
<a name="l00242"></a>00242 <span class="keywordtype">int</span> paddingSpaces = resultsColumn - (int) tr-><a class="code" href="structStatTracker.html#96b81596b9d18bfeece20dc807481181">name</a>.size();
<a name="l00243"></a>00243 <span class="keywordflow">while</span> (paddingSpaces-- > 0)
<a name="l00244"></a>00244 putc(<span class="charliteral">' '</span>, dest);
<a name="l00245"></a>00245 <span class="keywordflow">if</span> (tr-><a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">ptrb</a> == NULL)
<a name="l00246"></a>00246 <a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">StatsPrintVal</a>(dest, *tr-><a class="code" href="structStatTracker.html#bf6e0f882d825dd2e7e856f51afc4e44">ptra</a>);
<a name="l00247"></a>00247 <span class="keywordflow">else</span> {
<a name="l00248"></a>00248 <span class="keywordflow">if</span> (*tr-><a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">ptrb</a> > 0) {
<a name="l00249"></a>00249 <span class="keywordtype">float</span> ratio = (float)*tr-><a class="code" href="structStatTracker.html#bf6e0f882d825dd2e7e856f51afc4e44">ptra</a> / (<span class="keywordtype">float</span>)*tr-><a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">ptrb</a>;
<a name="l00250"></a>00250 <a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">StatsPrintVal</a>(dest, *tr-><a class="code" href="structStatTracker.html#bf6e0f882d825dd2e7e856f51afc4e44">ptra</a>, *tr-><a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">ptrb</a>);
<a name="l00251"></a>00251 <span class="keywordflow">if</span> (tr-><a class="code" href="structStatTracker.html#9563341f2a8457357ddeeb78c959636f">percentage</a>)
<a name="l00252"></a>00252 fprintf(dest, <span class="stringliteral">" (%3.2f%%)"</span>, 100. * ratio);
<a name="l00253"></a>00253 <span class="keywordflow">else</span>
<a name="l00254"></a>00254 fprintf(dest, <span class="stringliteral">" (%.2fx)"</span>, ratio);
<a name="l00255"></a>00255 }
<a name="l00256"></a>00256 <span class="keywordflow">else</span>
<a name="l00257"></a>00257 <a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">StatsPrintVal</a>(dest, *tr-><a class="code" href="structStatTracker.html#bf6e0f882d825dd2e7e856f51afc4e44">ptra</a>, *tr-><a class="code" href="structStatTracker.html#a601626220c7b0032e59c781718850cc">ptrb</a>);
<a name="l00258"></a>00258 }
<a name="l00259"></a>00259 fprintf(dest, <span class="stringliteral">"\n"</span>);
<a name="l00260"></a>00260 ++iter;
<a name="l00261"></a>00261 }
<a name="l00262"></a>00262 }
<a name="l00263"></a><a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">00263</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">StatsPrintVal</a>(FILE *f, <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> v) {
<a name="l00264"></a>00264 <span class="keywordflow">if</span> (v > 1e9) fprintf(f, <span class="stringliteral">"%.3fB"</span>, v / 1e9f);
<a name="l00265"></a>00265 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (v > 1e6) fprintf(f, <span class="stringliteral">"%.3fM"</span>, v / 1e6f);
<a name="l00266"></a>00266 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (v > 1e4) fprintf(f, <span class="stringliteral">"%.1fk"</span>, v / 1e3f);
<a name="l00267"></a>00267 <span class="keywordflow">else</span> fprintf(f, <span class="stringliteral">"%.0f"</span>, (<span class="keywordtype">float</span>)v);
<a name="l00268"></a>00268 }
<a name="l00269"></a><a class="code" href="util_8cpp.html#94f72771273ab8f905b2fa32e1bdc72b">00269</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="util_8cpp.html#5e2a135093025eecd491f87a64643260">StatsPrintVal</a>(FILE *f, <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> v1,
<a name="l00270"></a>00270 <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> v2) {
<a name="l00271"></a>00271 <a class="code" href="pbrt_8h.html#8c1c8901a052f5b154294299c55e52a6">StatsCounterType</a> m = min(v1, v2);
<a name="l00272"></a>00272 <span class="keywordflow">if</span> (m > 1e9) fprintf(f, <span class="stringliteral">"%.3fB:%.3fB"</span>, v1 / 1e9f, v2 / 1e9f);
<a name="l00273"></a>00273 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (m > 1e6) fprintf(f, <span class="stringliteral">"%.3fM:%.3fM"</span>, v1 / 1e6f, v2 / 1e6f);
<a name="l00274"></a>00274 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (m > 1e4) fprintf(f, <span class="stringliteral">"%.1fk:%.1fk"</span>, v1 / 1e3f, v2 / 1e3f);
<a name="l00275"></a>00275 <span class="keywordflow">else</span> fprintf(f, <span class="stringliteral">"%.0f:%.0f"</span>, v1, v2);
<a name="l00276"></a>00276 }
<a name="l00277"></a><a class="code" href="util_8cpp.html#c1f912df42c2ae7d595973b17901a8f6">00277</a> <span class="keywordtype">void</span> <a class="code" href="pbrt_8h.html#c1f912df42c2ae7d595973b17901a8f6">StatsCleanup</a>() {
<a name="l00278"></a>00278 TrackerMap::iterator iter = <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.begin();
<a name="l00279"></a>00279 <span class="keywordtype">string</span> lastCategory;
<a name="l00280"></a>00280 <span class="keywordflow">while</span> (iter != <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.end()) {
<a name="l00281"></a>00281 <span class="keyword">delete</span> iter->second;
<a name="l00282"></a>00282 ++iter;
<a name="l00283"></a>00283 }
<a name="l00284"></a>00284 <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.erase(<a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.begin(), <a class="code" href="util_8cpp.html#0cf0370181ef86b3b42db13a71c8a7e5">trackers</a>.end());
<a name="l00285"></a>00285 }
<a name="l00286"></a>00286 <span class="comment">// Random Number State</span>
<a name="l00287"></a>00287 <span class="comment">/*</span>
<a name="l00288"></a>00288 <span class="comment"> Copyright (C) 1997 - 2002, Makoto Matsumoto and Takuji Nishimura,</span>
<a name="l00289"></a>00289 <span class="comment"> All rights reserved.</span>
<a name="l00290"></a>00290 <span class="comment"></span>
<a name="l00291"></a>00291 <span class="comment"> Redistribution and use in source and binary forms, with or without</span>
<a name="l00292"></a>00292 <span class="comment"> modification, are permitted provided that the following conditions</span>
<a name="l00293"></a>00293 <span class="comment"> are met:</span>
<a name="l00294"></a>00294 <span class="comment"></span>
<a name="l00295"></a>00295 <span class="comment"> 1. Redistributions of source code must retain the above copyright</span>
<a name="l00296"></a>00296 <span class="comment"> notice, this list of conditions and the following disclaimer.</span>
<a name="l00297"></a>00297 <span class="comment"></span>
<a name="l00298"></a>00298 <span class="comment"> 2. Redistributions in binary form must reproduce the above copyright</span>
<a name="l00299"></a>00299 <span class="comment"> notice, this list of conditions and the following disclaimer in the</span>
<a name="l00300"></a>00300 <span class="comment"> documentation and/or other materials provided with the distribution.</span>
<a name="l00301"></a>00301 <span class="comment"></span>
<a name="l00302"></a>00302 <span class="comment"> 3. The names of its contributors may not be used to endorse or promote</span>
<a name="l00303"></a>00303 <span class="comment"> products derived from this software without specific prior written</span>
<a name="l00304"></a>00304 <span class="comment"> permission.</span>
<a name="l00305"></a>00305 <span class="comment"></span>
<a name="l00306"></a>00306 <span class="comment"> THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS</span>
<a name="l00307"></a>00307 <span class="comment"> "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT</span>
<a name="l00308"></a>00308 <span class="comment"> LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR</span>
<a name="l00309"></a>00309 <span class="comment"> A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR</span>
<a name="l00310"></a>00310 <span class="comment"> CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,</span>
<a name="l00311"></a>00311 <span class="comment"> EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,</span>
<a name="l00312"></a>00312 <span class="comment"> PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR</span>
<a name="l00313"></a>00313 <span class="comment"> PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF</span>
<a name="l00314"></a>00314 <span class="comment"> LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING</span>
<a name="l00315"></a>00315 <span class="comment"> NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS</span>
<a name="l00316"></a>00316 <span class="comment"> SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.</span>
<a name="l00317"></a>00317 <span class="comment">*/</span>
<a name="l00318"></a><a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">00318</a> <span class="preprocessor">#define N 624</span>
<a name="l00319"></a><a class="code" href="util_8cpp.html#52037c938e3c1b126c6277da5ca689d0">00319</a> <span class="preprocessor"></span><span class="preprocessor">#define M 397</span>
<a name="l00320"></a><a class="code" href="util_8cpp.html#376c3581bae3c2367fc9ce694e5a8949">00320</a> <span class="preprocessor"></span><span class="preprocessor">#define MATRIX_A 0x9908b0dfUL </span><span class="comment">/* constant vector a */</span>
<a name="l00321"></a><a class="code" href="util_8cpp.html#39bc458849360f8f371b54c4365d397f">00321</a> <span class="preprocessor">#define UPPER_MASK 0x80000000UL </span><span class="comment">/* most significant w-r bits */</span>
<a name="l00322"></a><a class="code" href="util_8cpp.html#4ddd8cab3564b7a86a4b0e52ba08f70e">00322</a> <span class="preprocessor">#define LOWER_MASK 0x7fffffffUL </span><span class="comment">/* least significant r bits */</span>
<a name="l00323"></a>00323
<a name="l00324"></a><a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">00324</a> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[<a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>]; <span class="comment">/* the array for the state vector */</span>
<a name="l00325"></a><a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">00325</a> <span class="keyword">static</span> <span class="keywordtype">int</span> <a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>=<a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>+1; <span class="comment">/* mti==N+1 means mt[N] is not initialized */</span>
<a name="l00326"></a>00326 <span class="comment">// Random Number Functions</span>
<a name="l00327"></a><a class="code" href="util_8cpp.html#125b1f3b0fc68d91e9825c698159763b">00327</a> <span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="util_8cpp.html#125b1f3b0fc68d91e9825c698159763b">init_genrand</a>(<a class="code" href="pbrt_8h.html#8f25a50daf29ce2cee1ec038a4d744ea">u_long</a> seed) {
<a name="l00328"></a>00328 <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[0]= seed & 0xffffffffUL;
<a name="l00329"></a>00329 <span class="keywordflow">for</span> (<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>=1; <a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a><<a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>; <a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>++) {
<a name="l00330"></a>00330 <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>] =
<a name="l00331"></a>00331 (1812433253UL * (<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>-1] ^ (<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>-1] >> 30)) + <a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>);
<a name="l00332"></a>00332 <span class="comment">/* See Knuth TAOCP Vol2. 3rd Ed. P.106 for multiplier. */</span>
<a name="l00333"></a>00333 <span class="comment">/* In the previous versions, MSBs of the seed affect */</span>
<a name="l00334"></a>00334 <span class="comment">/* only MSBs of the array mt[]. */</span>
<a name="l00335"></a>00335 <span class="comment">/* 2002/01/09 modified by Makoto Matsumoto */</span>
<a name="l00336"></a>00336 <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>] &= 0xffffffffUL;
<a name="l00337"></a>00337 <span class="comment">/* for >32 bit machines */</span>
<a name="l00338"></a>00338 }
<a name="l00339"></a>00339 }
<a name="l00340"></a><a class="code" href="util_8cpp.html#24bf150b5ab536c63e57b778e0cc6a9d">00340</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> <a class="code" href="pbrt_8h.html#24bf150b5ab536c63e57b778e0cc6a9d">genrand_int32</a>(<span class="keywordtype">void</span>)
<a name="l00341"></a>00341 {
<a name="l00342"></a>00342 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> y;
<a name="l00343"></a>00343 <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> mag01[2]={0x0UL, <a class="code" href="util_8cpp.html#376c3581bae3c2367fc9ce694e5a8949">MATRIX_A</a>};
<a name="l00344"></a>00344 <span class="comment">/* mag01[x] = x * MATRIX_A for x=0,1 */</span>
<a name="l00345"></a>00345
<a name="l00346"></a>00346 <span class="keywordflow">if</span> (<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a> >= <a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>) { <span class="comment">/* generate N words at one time */</span>
<a name="l00347"></a>00347 <span class="keywordtype">int</span> kk;
<a name="l00348"></a>00348
<a name="l00349"></a>00349 <span class="keywordflow">if</span> (<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a> == <a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>+1) <span class="comment">/* if init_genrand() has not been called, */</span>
<a name="l00350"></a>00350 <a class="code" href="util_8cpp.html#125b1f3b0fc68d91e9825c698159763b">init_genrand</a>(5489UL); <span class="comment">/* default initial seed */</span>
<a name="l00351"></a>00351
<a name="l00352"></a>00352 <span class="keywordflow">for</span> (kk=0;kk<<a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>-<a class="code" href="util_8cpp.html#52037c938e3c1b126c6277da5ca689d0">M</a>;kk++) {
<a name="l00353"></a>00353 y = (<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk]&<a class="code" href="util_8cpp.html#39bc458849360f8f371b54c4365d397f">UPPER_MASK</a>)|(<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk+1]&<a class="code" href="util_8cpp.html#4ddd8cab3564b7a86a4b0e52ba08f70e">LOWER_MASK</a>);
<a name="l00354"></a>00354 <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk] = <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk+M] ^ (y >> 1) ^ mag01[y & 0x1UL];
<a name="l00355"></a>00355 }
<a name="l00356"></a>00356 <span class="keywordflow">for</span> (;kk<<a class="code" href="util_8cpp.html#0240ac851181b84ac374872dc5434ee4">N</a>-1;kk++) {
<a name="l00357"></a>00357 y = (<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk]&<a class="code" href="util_8cpp.html#39bc458849360f8f371b54c4365d397f">UPPER_MASK</a>)|(<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk+1]&<a class="code" href="util_8cpp.html#4ddd8cab3564b7a86a4b0e52ba08f70e">LOWER_MASK</a>);
<a name="l00358"></a>00358 <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk] = <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1UL];
<a name="l00359"></a>00359 }
<a name="l00360"></a>00360 y = (<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[N-1]&<a class="code" href="util_8cpp.html#39bc458849360f8f371b54c4365d397f">UPPER_MASK</a>)|(<a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[0]&<a class="code" href="util_8cpp.html#4ddd8cab3564b7a86a4b0e52ba08f70e">LOWER_MASK</a>);
<a name="l00361"></a>00361 <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[N-1] = <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[M-1] ^ (y >> 1) ^ mag01[y & 0x1UL];
<a name="l00362"></a>00362
<a name="l00363"></a>00363 <a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a> = 0;
<a name="l00364"></a>00364 }
<a name="l00365"></a>00365
<a name="l00366"></a>00366 y = <a class="code" href="util_8cpp.html#ff3cefd0011b487c57a7af7cb3bc499f">mt</a>[<a class="code" href="util_8cpp.html#0893639c022032e006e5b13378f7b4b2">mti</a>++];
<a name="l00367"></a>00367
<a name="l00368"></a>00368 <span class="comment">/* Tempering */</span>
<a name="l00369"></a>00369 y ^= (y >> 11);
<a name="l00370"></a>00370 y ^= (y << 7) & 0x9d2c5680UL;
<a name="l00371"></a>00371 y ^= (y << 15) & 0xefc60000UL;
<a name="l00372"></a>00372 y ^= (y >> 18);
<a name="l00373"></a>00373
<a name="l00374"></a>00374 <span class="keywordflow">return</span> y;
<a name="l00375"></a>00375 }
<a name="l00376"></a>00376 <span class="comment">/* generates a random number on [0,1]-real-interval */</span>
<a name="l00377"></a><a class="code" href="util_8cpp.html#85bdeb11319d3e31ba1d5bb7767bbb2a">00377</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">float</span> <a class="code" href="pbrt_8h.html#85bdeb11319d3e31ba1d5bb7767bbb2a">genrand_real1</a>(<span class="keywordtype">void</span>)
<a name="l00378"></a>00378 {
<a name="l00379"></a>00379 <span class="keywordflow">return</span> <a class="code" href="pbrt_8h.html#24bf150b5ab536c63e57b778e0cc6a9d">genrand_int32</a>()*((float)1.0/(<span class="keywordtype">float</span>)4294967295.0);
<a name="l00380"></a>00380 <span class="comment">/* divided by 2^32-1 */</span>
<a name="l00381"></a>00381 }
<a name="l00382"></a>00382 <span class="comment">/* generates a random number on [0,1)-real-interval */</span>
<a name="l00383"></a><a class="code" href="util_8cpp.html#2c84e6fc3b8989a8ca6f415aa5585e24">00383</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">float</span> <a class="code" href="pbrt_8h.html#2c84e6fc3b8989a8ca6f415aa5585e24">genrand_real2</a>(<span class="keywordtype">void</span>)
<a name="l00384"></a>00384 {
<a name="l00385"></a>00385 <span class="keywordflow">return</span> <a class="code" href="pbrt_8h.html#24bf150b5ab536c63e57b778e0cc6a9d">genrand_int32</a>()*((float)1.0/(<span class="keywordtype">float</span>)4294967296.0);
<a name="l00386"></a>00386 <span class="comment">/* divided by 2^32 */</span>
<a name="l00387"></a>00387 }
<a name="l00388"></a>00388 <span class="comment">// Memory Allocation Functions</span>
<a name="l00389"></a><a class="code" href="util_8cpp.html#769734241eca27cdcab005ee9e4ef80f">00389</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">void</span> *<a class="code" href="pbrt_8h.html#6999b138e9c0d348eee4455b4ba3d624">AllocAligned</a>(<span class="keywordtype">size_t</span> size) {
<a name="l00390"></a>00390 <span class="preprocessor">#ifndef L1_CACHE_LINE_SIZE</span>
<a name="l00391"></a>00391 <span class="preprocessor"></span><span class="preprocessor">#define L1_CACHE_LINE_SIZE 64</span>
<a name="l00392"></a>00392 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
<a name="l00393"></a>00393 <span class="preprocessor"></span> <span class="keywordflow">return</span> memalign(<a class="code" href="util_8cpp.html#203d046f89d0bdb05f4f6ac0abb87a9e">L1_CACHE_LINE_SIZE</a>, size);
<a name="l00394"></a>00394 }
<a name="l00395"></a><a class="code" href="util_8cpp.html#284db7668edfe772f201b605b39d11b9">00395</a> <a class="code" href="pbrt_8h.html#1ca894daa11d476d9e76947dceaf0255">COREDLL</a> <span class="keywordtype">void</span> <a class="code" href="pbrt_8h.html#338d7748e3c01292726a6e82059d90ff">FreeAligned</a>(<span class="keywordtype">void</span> *ptr) {
<a name="l00396"></a>00396 <span class="preprocessor">#ifdef WIN32 // NOBOOK</span>
<a name="l00397"></a>00397 <span class="preprocessor"></span> _aligned_free(ptr);
<a name="l00398"></a>00398 <span class="preprocessor">#else // NOBOOK</span>
<a name="l00399"></a>00399 <span class="preprocessor"></span> free(ptr);
<a name="l00400"></a>00400 <span class="preprocessor">#endif // NOBOOK</span>
<a name="l00401"></a>00401 <span class="preprocessor"></span>}
<a name="l00402"></a>00402 <span class="comment">// ProgressReporter Method Definitions</span>
<a name="l00403"></a><a class="code" href="structProgressReporter.html#93fe56c5f2ce27fd7ce2951e8c439c45">00403</a> <a class="code" href="structProgressReporter.html#93fe56c5f2ce27fd7ce2951e8c439c45">ProgressReporter::ProgressReporter</a>(<span class="keywordtype">int</span> totalWork, <span class="keyword">const</span> <span class="keywordtype">string</span> &title, <span class="keywordtype">int</span> bar_length)
<a name="l00404"></a>00404 : totalPlusses(bar_length - title.size()) {
<a name="l00405"></a>00405 <a class="code" href="structProgressReporter.html#905a955a33e9a17f7f2cc99ce199a6da">plussesPrinted</a> = 0;
<a name="l00406"></a>00406 <a class="code" href="structProgressReporter.html#35c61a91e01ead2633108e77bbc94592">frequency</a> = (float)totalWork / (<span class="keywordtype">float</span>)<a class="code" href="structProgressReporter.html#44353a8f72b5896d3fd8789cde6d95e0">totalPlusses</a>;
<a name="l00407"></a>00407 <a class="code" href="structProgressReporter.html#71ecaba625fcfd5053eb13045cb6dcba">count</a> = <a class="code" href="structProgressReporter.html#35c61a91e01ead2633108e77bbc94592">frequency</a>;
<a name="l00408"></a>00408 <a class="code" href="structProgressReporter.html#9d3ee08b2230f33fe992d5393a901288">timer</a> = <span class="keyword">new</span> <a class="code" href="classTimer.html">Timer</a>();
<a name="l00409"></a>00409 <a class="code" href="structProgressReporter.html#9d3ee08b2230f33fe992d5393a901288">timer</a>-><a class="code" href="classTimer.html#4e607b129b392c11adddd9641a320436">Start</a>();
<a name="l00410"></a>00410 <a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a> = stdout;
<a name="l00411"></a>00411 <span class="comment">// Initialize progress string</span>
<a name="l00412"></a>00412 <span class="keyword">const</span> <span class="keywordtype">int</span> bufLen = title.size() + <a class="code" href="structProgressReporter.html#44353a8f72b5896d3fd8789cde6d95e0">totalPlusses</a> + 64;
<a name="l00413"></a>00413 <a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a> = <span class="keyword">new</span> <span class="keywordtype">char</span>[bufLen];
<a name="l00414"></a>00414 snprintf(<a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a>, bufLen, <span class="stringliteral">"\r%s: ["</span>, title.c_str());
<a name="l00415"></a>00415 <a class="code" href="structProgressReporter.html#d668d1b76a50ec60b5f8e3d333ddacda">curSpace</a> = <a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a> + strlen(<a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a>);
<a name="l00416"></a>00416 <span class="keywordtype">char</span> *s = curSpace;
<a name="l00417"></a>00417 <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; i < <a class="code" href="structProgressReporter.html#44353a8f72b5896d3fd8789cde6d95e0">totalPlusses</a>; ++i)
<a name="l00418"></a>00418 *s++ = <span class="charliteral">' '</span>;
<a name="l00419"></a>00419 *s++ = <span class="charliteral">']'</span>;
<a name="l00420"></a>00420 *s++ = <span class="charliteral">' '</span>;
<a name="l00421"></a>00421 *s++ = <span class="charliteral">'\0'</span>;
<a name="l00422"></a>00422 fprintf(<a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>, <a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a>);
<a name="l00423"></a>00423 fflush(<a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>);
<a name="l00424"></a>00424 }
<a name="l00425"></a><a class="code" href="structProgressReporter.html#3be3c69439f40a8c1f56023b6ab46f99">00425</a> <a class="code" href="structProgressReporter.html#3be3c69439f40a8c1f56023b6ab46f99">ProgressReporter::~ProgressReporter</a>() { <span class="keyword">delete</span>[] <a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a>; <span class="keyword">delete</span> <a class="code" href="structProgressReporter.html#9d3ee08b2230f33fe992d5393a901288">timer</a>; }
<a name="l00426"></a><a class="code" href="structProgressReporter.html#deb36328289f937ca81e457f78781faa">00426</a> <span class="keywordtype">void</span> <a class="code" href="structProgressReporter.html#deb36328289f937ca81e457f78781faa">ProgressReporter::Update</a>(<span class="keywordtype">int</span> num)<span class="keyword"> const </span>{
<a name="l00427"></a>00427 <a class="code" href="structProgressReporter.html#71ecaba625fcfd5053eb13045cb6dcba">count</a> -= num;
<a name="l00428"></a>00428 <span class="keywordtype">bool</span> updatedAny = <span class="keyword">false</span>;
<a name="l00429"></a>00429 <span class="keywordflow">while</span> (<a class="code" href="structProgressReporter.html#71ecaba625fcfd5053eb13045cb6dcba">count</a> <= 0) {
<a name="l00430"></a>00430 <a class="code" href="structProgressReporter.html#71ecaba625fcfd5053eb13045cb6dcba">count</a> += <a class="code" href="structProgressReporter.html#35c61a91e01ead2633108e77bbc94592">frequency</a>;
<a name="l00431"></a>00431 <span class="keywordflow">if</span> (<a class="code" href="structProgressReporter.html#905a955a33e9a17f7f2cc99ce199a6da">plussesPrinted</a>++ < <a class="code" href="structProgressReporter.html#44353a8f72b5896d3fd8789cde6d95e0">totalPlusses</a>)
<a name="l00432"></a>00432 *<a class="code" href="structProgressReporter.html#d668d1b76a50ec60b5f8e3d333ddacda">curSpace</a>++ = <span class="charliteral">'+'</span>;
<a name="l00433"></a>00433 updatedAny = <span class="keyword">true</span>;
<a name="l00434"></a>00434 }
<a name="l00435"></a>00435 <span class="keywordflow">if</span> (updatedAny) {
<a name="l00436"></a>00436 fputs(<a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a>, <a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>);
<a name="l00437"></a>00437 <span class="comment">// Update elapsed time and estimated time to completion</span>
<a name="l00438"></a>00438 <span class="keywordtype">float</span> percentDone = (float)<a class="code" href="structProgressReporter.html#905a955a33e9a17f7f2cc99ce199a6da">plussesPrinted</a> / (<span class="keywordtype">float</span>)<a class="code" href="structProgressReporter.html#44353a8f72b5896d3fd8789cde6d95e0">totalPlusses</a>;
<a name="l00439"></a>00439 <span class="keywordtype">float</span> seconds = (float) <a class="code" href="structProgressReporter.html#9d3ee08b2230f33fe992d5393a901288">timer</a>-><a class="code" href="classTimer.html#910e46901f0a2eeba95153cc1e0a5fec">Time</a>();
<a name="l00440"></a>00440 <span class="keywordtype">float</span> estRemaining = seconds / percentDone - seconds;
<a name="l00441"></a>00441 <span class="keywordflow">if</span> (percentDone == 1.f)
<a name="l00442"></a>00442 fprintf(<a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>, <span class="stringliteral">" (%.1fs) "</span>, seconds);
<a name="l00443"></a>00443 <span class="keywordflow">else</span>
<a name="l00444"></a>00444 fprintf(<a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>, <span class="stringliteral">" (%.1fs|%.1fs) "</span>, seconds, max(0.f, estRemaining));
<a name="l00445"></a>00445 fflush(<a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>);
<a name="l00446"></a>00446 }
<a name="l00447"></a>00447 }
<a name="l00448"></a><a class="code" href="structProgressReporter.html#0cba41f20f2cb68ed0f583e54f22cc73">00448</a> <span class="keywordtype">void</span> <a class="code" href="structProgressReporter.html#0cba41f20f2cb68ed0f583e54f22cc73">ProgressReporter::Done</a>()<span class="keyword"> const </span>{
<a name="l00449"></a>00449 <span class="keywordflow">while</span> (<a class="code" href="structProgressReporter.html#905a955a33e9a17f7f2cc99ce199a6da">plussesPrinted</a>++ < <a class="code" href="structProgressReporter.html#44353a8f72b5896d3fd8789cde6d95e0">totalPlusses</a>)
<a name="l00450"></a>00450 *<a class="code" href="structProgressReporter.html#d668d1b76a50ec60b5f8e3d333ddacda">curSpace</a>++ = <span class="charliteral">'+'</span>;
<a name="l00451"></a>00451 fputs(<a class="code" href="structProgressReporter.html#e582732e6e138e6140eef7870ad36b15">buf</a>, <a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>);
<a name="l00452"></a>00452 <span class="keywordtype">float</span> seconds = (float) <a class="code" href="structProgressReporter.html#9d3ee08b2230f33fe992d5393a901288">timer</a>-><a class="code" href="classTimer.html#910e46901f0a2eeba95153cc1e0a5fec">Time</a>();
<a name="l00453"></a>00453 fprintf(<a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>, <span class="stringliteral">" (%.1fs) \n"</span>, seconds);
<a name="l00454"></a>00454 fflush(<a class="code" href="structProgressReporter.html#a0ee06ab7e673ed06643d100762ecbc5">outFile</a>);
<a name="l00455"></a>00455 }
</pre></div></div>
<hr size="1"><address style="text-align: right;"><small>Generated on Mon Jul 20 17:31:53 2009 for pbrt by
<a href="http://www.doxygen.org/index.html">
<img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.6 </small></address>
</body>
</html>