-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.html
555 lines (451 loc) · 24.2 KB
/
README.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
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<link type="text/css" rel="stylesheet" href="css/github-markdown.css"/>
<link rel="stylesheet" href="css/github-markdown.css">
<style>
.markdown-body {
box-sizing: border-box;
min-width: 200px;
max-width: 980px;
margin: 0 auto;
padding: 45px;
}
</head>
<body>
<pre><code>@media (max-width: 767px) {
.markdown-body {
padding: 15px;
}
}
</code></pre>
<p></style>
<article class="markdown-body"></p>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ TeX: { equationNumbers: {autoNumber: "all"} } });
</script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
<div style="display:none">
<span class="math">\(\newcommand{\A}{\mat{A}}\)</span>
<span class="math">\(\newcommand{\B}{\mat{B}}\)</span>
<span class="math">\(\newcommand{\C}{\mat{C}}\)</span>
<span class="math">\(\newcommand{\D}{\mat{D}}\)</span>
<span class="math">\(\newcommand{\E}{\mat{E}}\)</span>
<span class="math">\(\newcommand{\F}{\mat{F}}\)</span>
<span class="math">\(\newcommand{\G}{\mat{G}}\)</span>
<span class="math">\(\newcommand{\H}{\mat{H}}\)</span>
<span class="math">\(\newcommand{\I}{\mat{I}}\)</span>
<span class="math">\(\newcommand{\J}{\mat{J}}\)</span>
<span class="math">\(\newcommand{\K}{\mat{K}}\)</span>
<span class="math">\(\newcommand{\L}{\mat{L}}\)</span>
<span class="math">\(\newcommand{\M}{\mat{M}}\)</span>
<span class="math">\(\newcommand{\N}{\mat{N}}\)</span>
<span class="math">\(\newcommand{\One}{\mathbf{1}}\)</span>
<span class="math">\(\newcommand{\P}{\mat{P}}\)</span>
<span class="math">\(\newcommand{\Q}{\mat{Q}}\)</span>
<span class="math">\(\newcommand{\Rot}{\mat{R}}\)</span>
<span class="math">\(\newcommand{\R}{\mathbb{R}}\)</span>
<span class="math">\(\newcommand{\S}{\mathcal{S}}\)</span>
<span class="math">\(\newcommand{\T}{\mat{T}}\)</span>
<span class="math">\(\newcommand{\U}{\mat{U}}\)</span>
<span class="math">\(\newcommand{\V}{\mat{V}}\)</span>
<span class="math">\(\newcommand{\W}{\mat{W}}\)</span>
<span class="math">\(\newcommand{\X}{\mat{X}}\)</span>
<span class="math">\(\newcommand{\Y}{\mat{Y}}\)</span>
<span class="math">\(\newcommand{\argmax}{\mathop{\text{argmax}}}\)</span>
<span class="math">\(\newcommand{\argmin}{\mathop{\text{argmin}}}\)</span>
<span class="math">\(\newcommand{\a}{\vec{a}}\)</span>
<span class="math">\(\newcommand{\b}{\vec{b}}\)</span>
<span class="math">\(\newcommand{\c}{\vec{c}}\)</span>
<span class="math">\(\newcommand{\d}{\vec{d}}\)</span>
<span class="math">\(\newcommand{\e}{\vec{e}}\)</span>
<span class="math">\(\newcommand{\f}{\vec{f}}\)</span>
<span class="math">\(\newcommand{\g}{\vec{g}}\)</span>
<span class="math">\(\newcommand{\mat}[1]{\mathbf{#1}}\)</span>
<span class="math">\(\newcommand{\min}{\mathop{\text{min}}}\)</span>
<span class="math">\(\newcommand{\m}{\vec{m}}\)</span>
<span class="math">\(\newcommand{\n}{\vec{n}}\)</span>
<span class="math">\(\newcommand{\p}{\vec{p}}\)</span>
<span class="math">\(\newcommand{\q}{\vec{q}}\)</span>
<span class="math">\(\newcommand{\r}{\vec{r}}\)</span>
<span class="math">\(\newcommand{\transpose}{{\mathsf T}}\)</span>
<span class="math">\(\newcommand{\tr}[1]{\mathop{\text{tr}}{\left(#1\right)}}\)</span>
<span class="math">\(\newcommand{\s}{\vec{s}}\)</span>
<span class="math">\(\newcommand{\t}{\vec{t}}\)</span>
<span class="math">\(\newcommand{\u}{\vec{u}}\)</span>
<span class="math">\(\newcommand{\vec}[1]{\mathbf{#1}}\)</span>
<span class="math">\(\newcommand{\x}{\vec{x}}\)</span>
<span class="math">\(\newcommand{\y}{\vec{y}}\)</span>
<span class="math">\(\newcommand{\z}{\vec{z}}\)</span>
<span class="math">\(\newcommand{\0}{\vec{0}}\)</span>
<span class="math">\(\renewcommand{\v}{\vec{v}}\)</span>
<!-- https://github.com/mathjax/MathJax/issues/1766 -->
<span class="math">\(\renewcommand{\hat}[1]{\widehat{#1}}\)</span>
</div>
<h1 id="computergraphics–boundingvolumehierarchy">Computer Graphics – Bounding Volume Hierarchy</h1>
<blockquote>
<p><strong>To get started:</strong> Clone this repository </p>
<pre><code>git clone --recursive http://github.com/[username]/computer-graphics-bounding-volume-hierarchy.git
</code></pre>
</blockquote>
<h2 id="background">Background</h2>
<h3 id="readsection12.3offundamentalsofcomputergraphics4thedition.">Read Section 12.3 of <em>Fundamentals of Computer Graphics (4th Edition)</em>.</h3>
<figure>
<img src="images/rubber-ducky-aabb-tree.png" alt="Visualize of all of the boxes of a hierarchical axis-aligned bounding-box tree
around the triangles of a rubber
ducky
mesh." />
<figcaption>Visualize of all of the boxes of a hierarchical axis-aligned bounding-box tree
around the triangles of a <a href="https://en.wikipedia.org/wiki/Rubber_duck">rubber
ducky</a>
mesh.</figcaption>
</figure>
<h3 id="objectpartitioning">Object partitioning</h3>
<p>In this assignment, you will build an Axis-Aligned Bounding-Box
<a href="https://en.wikipedia.org/wiki/Tree_structure">Tree</a> (AABB Tree). This is one of the simplest
instances of an <em>object partitioning</em> scheme, where a group of input objects are
arranged into a <a href="https://en.wikipedia.org/wiki/Bounding_volume_hierarchy">bounding volume
hierarchy</a>.</p>
<figure>
<img src="images/Example_of_bounding_volume_hierarchy.png" alt="In the scene on the left, there are six objects. All objects fit into the
axis-aligned bounding box A (the root of the tree), then we cluster nearby
objects into subtrees rooted at B and C. We continue to apply this
process recursively until leaves of the tree store a single object. Tree shown
on right. (image
source)" />
<figcaption>In the “scene” on the left, there are six objects. All objects fit into the
axis-aligned bounding box <strong>A</strong> (the root of the tree), then we cluster nearby
objects into subtrees rooted at <strong>B</strong> and <strong>C</strong>. We continue to apply this
process recursively until leaves of the tree store a single object. Tree shown
on right. (<a href="https://commons.wikimedia.org/wiki/File:Example_of_bounding_volume_hierarchy.svg">image
source</a>)</figcaption>
</figure>
<p>In our assignment, we will build a binary tree. Conducting queries on the tree
will be reminiscent of searching for values in a <a href="https://en.wikipedia.org/wiki/Binary_search_tree">binary search
tree</a>. However, objects in our
tree will not be <em>perfectly</em> sorted. In general, the bounding boxes of
“relatives” (even siblings) in our tree will overlap spatially.</p>
<figure>
<img src="images/more-realistic-bvh-example.png" alt="In most cases, bounding boxes will overlap. The tree topology remains the same
in this case. (original image
source)" />
<figcaption>In most cases, bounding boxes will overlap. The tree topology remains the same
in this case. (<a href="https://commons.wikimedia.org/wiki/File:Example_of_bounding_volume_hierarchy.svg">original image
source</a>)</figcaption>
</figure>
<p>By allowing bounding boxes to overlap we avoid the need to geometric split our
objects.</p>
<blockquote>
<p><strong>Question:</strong> If we use overlapping bounding boxes (i.e., no splitting) to
build an AABB Tree , how many leaves will there be?</p>
</blockquote>
<figure>
<img src="images/point-cloud-aabb-tree.gif" alt="The AABB Tree around a point cloud starts with a single box. The next level
has two boxes, roughly splitting the first box. This process continues
recursively until theres only a single point in the
box." />
<figcaption>The AABB Tree around a point cloud starts with a single box. The next level
has two boxes, roughly splitting the first box. This process continues
recursively until there’s only a single point in the
box.</figcaption>
</figure>
<p>In contrast, space partitioning schemes (e.g., <a href="https://en.wikipedia.org/wiki/K-d_tree">kd
trees</a> or
<a href="https://en.wikipedia.org/wiki/Octree">octrees</a>) divide space <em>perfectly</em> at
each level of the tree, with no overlapping. This makes query code easy to
write, but necessitates splitting of objects that inevitably straddle partition
boundaries.</p>
<blockquote>
<p><strong>Question:</strong> Which is better for an unstructured set of points, <em>space partitioning</em> or
<em>object partitioning</em>?</p>
<p><strong>Hint:</strong> No perfect answer, but consider: do you ever need to split a point?</p>
</blockquote>
<h3 id="boundingprimitives">Bounding primitives</h3>
<p>In this assignment, we will use axis-aligned bounding boxes (AABBs) to enclose
groups of objects (e.g., points, triangles, other bounding boxes). In general,
AABBs will <em>not</em> tightly enclose a set of objects. However, operations (e.g.,
growing the bounding box, testing ray-intersection or determining closest-point
distances with an <em>axis-aligned</em> bounding box) usually reduce to trivial
per-component arithmetic. This means the code is simple to write/debug and also
inexpensive to evaluate.</p>
<figure>
<img src="images/bounding-primitives.png" alt="Minimal axis-aligned bounding boxes provide a good trade-off between
tightness, ease of construction and ease of query
evaluation." />
<figcaption>Minimal axis-aligned bounding boxes provide a good trade-off between
tightness, ease of construction and ease of query
evaluation.</figcaption>
</figure>
<h3 id="ray-intersectionqueries">Ray-intersection queries</h3>
<p>See Section 12.3 of <em>Fundamentals of Computer Graphics (4th Edition)</em>.</p>
<h3 id="distancequeries">Distance queries</h3>
<p>The recursive algorithm in <em>Fundamentals of Computer Graphics (4th Edition)</em> for
ray-AABBTree-intersection is essentially performing a <a href="https://en.wikipedia.org/wiki/Depth-first_search">depth first
search</a>. The search usually
doesn’t have to visit the entire tree because most boxes are not hit by the
given ray. In this way, many search paths are quickly aborted.</p>
<p>On the other hand, using this style of depth-first search for closest point
queries can be a disaster. Every box has <em>some</em> closest point to our query. A
naive depth-first search could end up searching over every box before finding
the one with the smallest query.</p>
<p>Are we just talking about worst-case complexity for pathological arrangements
(e.g., a bunch of overlapping triangles piled at the origin)? No. Even on a
well-balanced, minimally overlapping AABB tree we could end up exploring most of
the leaves before finally finding the leaf containing the true closest point at
the very end.</p>
<p>This implies that we can’t just explore the left or right subtrees (or their
progeny) in arbitrary order. A quick fix is to peek at the closet distance to
the boxes containing the left and right trees respectively and prefer our depth
first search in the closest direction. This helps, but we still end up
<em>drilling</em> down to leaves when there are potentially entire large subtrees that
are closer. The problem is that depth first search is inherently
<a href="https://en.wikipedia.org/wiki/Stack_(abstract_data_type)">stack</a>-based and we
really want to use a <a href="https://en.wikipedia.org/wiki/Priority_queue">priority
queue</a> to explore the current best
looking path in our tree wherever it might be.</p>
<blockquote>
<p><strong>Question:</strong> Hey! Where’s the stack in depth first search? I implemented it
using recursion, there’s no <code>#include <stack></code> in my code!</p>
<p><strong><a href="https://en.wikipedia.org/wiki/Call_stack">Hint</a>:</strong> Where are the instructions and data of your program stored?</p>
</blockquote>
<p><a href="https://en.wikipedia.org/wiki/Breadth-first_search">Breadth-first search</a> is a
much better structure for distance queries on a spatial acceleration
data-structure. Pseudo-code for a closest distance algorithm might look like:</p>
<pre><code>// initialize a queue prioritized by minimum distance
d_r ← distance to root's box
Q.insert(d_r, root)
// initialize minimum distance seen so far
d ← ∞
while Q not empty
// d_s: distance from query to subtree's bounding box
(d_s, subtree) ← Q.pop
if d_s < d
if subtree is a leaf
d ← min[ d , distance from query to leaf object ]
else
d_l ← distance to left's box
Q.insert(d_l ,subtree.left)
d_r ← distance to right's box
Q.insert(d_r ,subtree.right)
</code></pre>
<blockquote>
<p><strong>Question:</strong> If I have just a single query to conduct on a set of <span class="math">\(n\)</span>
objects, is it worth it to use a BVH?</p>
<p><strong>Hint:</strong> What is the complexity of <em>building</em> a BVH? What is the complexity
of a single brute force query?</p>
</blockquote>
<h3 id="intersectionqueriesbetweentwotrees">Intersection queries between two trees</h3>
<p>Suppose we want to find <em>all pairs</em> of intersecting triangles between two
meshes. One approach would be to put one mesh’s triangles in an AABB tree, then
loop over the other mesh’s triangles using the tree to accelerate intersection
tests. This works well if the mesh in the tree has many more triangles than the
other mesh, but can we do better if both mesh have many triangles? How about
putting both meshes in a AABB trees. If the root bounding boxes don’t overlap we
find out <em>instantaneously</em> that there are no pairs of intersecting triangles. If
they do overlap, we check their childrens’ boxes against each other. Anytime two
boxes don’t overlap we save many expensive pairwise triangle checks. A rough
sketch of this algorithm using a simple (i.e., non prioritized) queue is like
this:</p>
<pre><code>// initialize list of candidate leaf pairs
leaf_pairs ← {}
if root_A.box intersects root_B.box
Q.insert( root_A, root_B )
while Q not empty
{nodeA,nodeB} ← Q.pop
if nodeA and nodeB are leaves
leaf_pairs.insert( node_A, node_B )
else if node_A is a leaf
if node_A.box intersects node_B.left.box
Q.insert( node_A, node_B.left )
if node_A.box intersects node_B.right.box
Q.insert( node_A, node_B.right )
else if node_B is a leaf
if node_A.left.box intersects node_B.box
Q.insert( node_A.left, node_B)
if node_A.right.box intersects node_B.box
Q.insert( node_A.right, node_B)
else
if node_A.left.box intersects node_B.left.box
Q.insert( node_A.left, node_B.left )
if node_A.left.box intersects node_B.right.box
Q.insert( node_A.left, node_B.right )
if node_A.right.box intersects node_B.right.box
Q.insert( node_A.right, node_B.right )
if node_A.right.box intersects node_B.left.box
Q.insert( node_A.right, node_B.left )
</code></pre>
<p>Careful, this sketch only considers a perfectly filled tree where nodes (and
their left/right children) are never null pointers. <a href="https://en.wiktionary.org/wiki/your_mileage_may_vary">Your trees may
vary</a>.</p>
<p>This <em><strong>broad phase</strong></em> identifies a set of overlapping bounding boxes containing
one triangle each. The broad phase is quick because it uses the bounding volume
hierarchy for acceleration and intersection between bounding boxes is a simple
and fast. The list of candidate pairs scales with the number of <em>actual
intersections</em> rather than the number of input triangles (as brute force
double-for loops does). This list can then be processed using the (expensive)
triangle-triangle intersection test in a <strong><em>narrow phase</em></strong>.</p>
<figure>
<img src="images/cheburashka-knight-intersections.gif" alt="Using an AABB Tree for each shape (light red and light blue triangle meshes),
we identify a set of candidate intersecting bounding boxes (red and blue)." />
<figcaption>Using an AABB Tree for each shape (light red and light blue triangle meshes),
we identify a set of candidate intersecting bounding boxes (red and blue).</figcaption>
</figure>
<blockquote>
<p><strong>Question:</strong> Suppose we want to detect intersections for a simulation of two
deforming meshes (e.g., elastic solids bumping into each other). Can we reuse
our AABB Tree even if the meshes are deforming? What if they’re just moving
rigidly (rotations and translations)?</p>
<p><strong>Hint:</strong> Is an axis-aligned box still axis-aligned if it’s rotated 45°?</p>
</blockquote>
<h3 id="timing">Timing</h3>
<p>Never conduct performance evaluations in debug mode. To set up a “release” mode
version of your project use:</p>
<pre><code>mkdir build_release
cd build_release
cmake -DCMAKE_BUILD_TYPE=Release ..
make
</code></pre>
<p>In this assignment, we’re aiming to improve the asymptotic complexity for the
<a href="https://en.wikipedia.org/wiki/Average-case_complexity">average case</a>. We will
not formalize the <a href="https://en.wikipedia.org/wiki/Probability_distribution">probability
distribution</a> of inputs,
but instead consider uniformly random <a href="https://en.wikipedia.org/wiki/Point_cloud">point
clouds</a> or real-world surface models.
The AABB Tree algorithms should behave like <span class="math">\(O(\log{n})\)</span> compared to brute
force <span class="math">\(O(n)\)</span> algorithms. For large inputs the difference should be striking.</p>
<h2 id="tasks">Tasks</h2>
<h3 id="whitelist">Whitelist</h3>
<p>This assignment uses <a href="https://en.wikipedia.org/wiki/Smart_pointer">smart
pointers</a>. In particular,
<a href="https://en.cppreference.com/w/cpp/memory/shared_ptr"><code>std::shared_ptr</code></a>. For
the most part you can use these like regular “raw”
<a href="https://en.wikipedia.org/wiki/Pointer_(computer_programming)">pointers</a>. But
for initialization use:</p>
<pre><code>// Instead of:
// MyClass * A = new MyClass();
// Use
std::shared_ptr<MyClass> A = std::make_shared<MyClass>();
</code></pre>
<p>And omit deletion lines:</p>
<pre><code>// No need for:
// delete A;
// Instead, it's destroyed when the last shared_ptr to A is destroyed
</code></pre>
<p>You’re encouraged to use the following</p>
<ul>
<li><code>std::numeric_limits<double>::infinity()</code> and
<code>-std::numeric_limits<double>::infinity()</code> in <code>#include <limits></code> are often
useful for initializing values before calculating a running minimum or
maximum respectively.</li>
<li><code>std::priority_queue</code></li>
<li><code>std::list</code> useful as a simple (non-priority) queue</li>
<li><code>std::pair</code> often useful to store key-value pairs (e.g., a priority and its
corresponding object)</li>
</ul>
<h3 id="blacklist">Blacklist</h3>
<p>Do not use or look at any of the following functions. Work out geometric
derivations by hand rather than googling for a solution. Always cite online
references as per academic honesty policies.</p>
<ul>
<li><code>Eigen::AlignedBox</code></li>
<li><code>igl::AABB</code></li>
<li><code>igl::ray_box_intersect</code></li>
<li><code>igl::ray_mesh_intersect</code></li>
<li><code>igl::ray_mesh_intersect</code></li>
<li><code>igl::point_simplex_squared_distance.cpp</code></li>
</ul>
<h3 id="srcray_intersect_triangle.cpp"><code>src/ray_intersect_triangle.cpp</code></h3>
<p>Intersect a ray with a triangle (feel free to
<a href="https://en.wiktionary.org/wiki/crib#Verb">crib</a> your solution from the <a href="https://github.com/alecjacobson/computer-graphics-ray-casting">ray
casting</a>).</p>
<h3 id="srcray_intersect_triangle_mesh_brute_force.cpp"><code>src/ray_intersect_triangle_mesh_brute_force.cpp</code></h3>
<p>Shoot a ray at a triangle mesh with <span class="math">\(n\)</span> faces and record the closest hit. Use
a brute force loop over all triangles, aim for <span class="math">\(O(n)\)</span> complexity but focus on
correctness. This will be your reference solution.</p>
<h3 id="srcray_intersect_box.cpp"><code>src/ray_intersect_box.cpp</code></h3>
<p>Intersect a ray with a <strong><em>solid</em></strong> box (careful: if the ray or <code>min_t</code> lands
<em>inside</em> the box this could still hit something stored inside the box, so this
counts as a hit).</p>
<h3 id="srcinsert_box_into_box.cpp"><code>src/insert_box_into_box.cpp</code></h3>
<p>Grow a box <code>B</code> by inserting a box <code>A</code>.</p>
<h3 id="srcinsert_triangle_into_box.cpp"><code>src/insert_triangle_into_box.cpp</code></h3>
<p>Grow a box <code>B</code> by inserting a triangle with corners <code>a</code>, <code>b</code>, and <code>c</code>.</p>
<h3 id="aabbtree::aabbtreeinsrcaabbtree.cpp"><code>AABBTree::AABBTree</code> in <code>src/AABBTree.cpp</code></h3>
<p>Construct an axis-aligned bounding box tree given a list of objects. Use the
midpoint along the longest axis of the box containing the given objects to
determine the left-right split.</p>
<h3 id="aabbtree::ray_intersectinsrcaabbtree.cpp"><code>AABBTree::ray_intersect</code> in <code>src/AABBTree.cpp</code></h3>
<p>Determine whether and how a ray intersects the contents of an AABB tree. The
method should perform in <span class="math">\(O(\log{n})\)</span> time for a tree containing <span class="math">\(n\)</span>
(reasonably distributed) objects.</p>
<p>If you run <code>./rays</code> you should see something like:</p>
<pre><code># Ray Triangle Mesh Intersection
|V| 334
|F| 668
Firing 100 rays...
| Method | Time in seconds |
|:------------|----------------:|
| brute force | 0.00158905983 |
| build tree | 0.00064301491 |
| use tree | 0.00004386902 |
</code></pre>
<p>If your method is incorrect, you will see some lines like this:</p>
<pre><code>...
Error: #bf_hit(38) (1) != #tree_hit(38) (0)
...
</code></pre>
<p>This example line means that your brute force algorithm thinks ray 38 hits your
object but your tree algorithm is not finding it.</p>
<h3 id="srcnearest_neighbor_brute_force.cpp"><code>src/nearest_neighbor_brute_force.cpp</code></h3>
<p>Compute the nearest neighbor for a query in the set of <span class="math">\(n\)</span> points (rows of
<code>points</code>). This should be a <strong><em>slow reference implementation</em></strong>. Aim for a
computational complexity of <span class="math">\(O(n)\)</span> but focus on correctness. </p>
<h3 id="srcpoint_box_squared_distance.cpp"><code>src/point_box_squared_distance.cpp</code></h3>
<p>Compute the squared distance between a query point and a box</p>
<h3 id="srcpoint_aabbtree_squared_distance.cpp"><code>src/point_AABBTree_squared_distance.cpp</code></h3>
<p>Compute the distrance from a query point to the objects stored in a AABBTree
using a priority queue. <em><strong>Note:</strong> this function is <strong>not</strong> meant to be called
recursively.</em></p>
<p>Running <code>./distances</code> you should also see something like this:</p>
<pre><code># Point Cloud Distance Queries
|points|: 100000
|querires|: 10000
| Method | Time in seconds |
|:------------|----------------:|
| brute force | 1.50723695755 |
| build tree | 0.14633584023 |
| use tree | 0.05846095085 |
</code></pre>
<h3 id="srcpoint_triangle_squared_distance.cpp"><code>src/point_triangle_squared_distance.cpp</code></h3>
<p>Compute the squared distance of a query point to a triangle, output the closest
point on the triangle in barycentric coordinates.</p>
<h3 id="srctriangle_triangle_intersection.cpp"><code>src/triangle_triangle_intersection.cpp</code></h3>
<p>Determine whether two triangles intersect.</p>
<h3 id="srcbox_box_intersect.cpp"><code>src/box_box_intersect.cpp</code></h3>
<p>Determine if two bounding boxes intersect</p>
<h3 id="srcfind_all_intersecting_pairs_using_aabbtrees.cpp"><code>src/find_all_intersecting_pairs_using_AABBTrees.cpp</code></h3>
<p>Find all intersecting pairs of <em>leaf boxes</em> between one AABB tree and another</p>
<p>Running <code>./intersections</code> will also produce something like this:</p>
<pre><code># Triangle Mesh Intersection Detection
|VA| 2002
|FA| 4000
|VB| 6669
|FB| 13334
| Method | Time in seconds |
|:------------|----------------:|
| brute force | 1.55577802658 |
| build trees | 0.01804995537 |
| use trees | 0.00816702843 |
</code></pre>
<p>If your method is incorrect, you will see some lines like this:</p>
<pre><code>...
Error: Intersecting pairs found using tree but not brute force:
7,722
...
</code></pre>
<p>This indicates that your tree is finding <em>more</em> intersecting triangles than your
brute force method. In particular, the tree thinks the <span class="math">\(7\)</span>-th triangle of mesh A
is intersecting the <span class="math">\(772\)</span>-th triangle of mesh B.</p>
</body>
</html>