<p>You gave the formula as:</p>

<p>$$Cost(cell) = C_t + \frac{S_L}{S_{Cell}} \times N_L \times t_i + \frac{S_R}{S_{Cell}} \times N_R \times t_i$$</p>

<p>(You put $r_i$ at the right-hand end, but I assume that was a typo.) </p>

<p>There's a more general form of this formula</p>

<p>$$Cost(cell) = C_t + \sum_{k\ \in\ K} \frac{S_k}{S_{Cell}} \times N_k \times t_i$$</p>

<p>where $K$ is the set of all child nodes; that is, to get back to the two-children form you started with, $K = \{L, R\}$.</p>

<p>By generalising the formula like this, you can now calculate the cost for the first possibility the same way as the second two.</p>

<p>You're right that this is a slightly odd question. In practice, your traversal cost is going to be less for a binary tree than a $(&gt; 2)$-ary tree.</p>

<blockquote>
  <ul>
  <li>Does this ranking change if we change the spheres with a (scaled) tea-pot that still fits within the bounding volume?</li>
  </ul>
</blockquote>

<p>To answer this, you'll need to consider how this affects the surface area, and how this changes each score in turn.</p>

<blockquote>
  <ul>
  <li>Can this ranking depend on the position of the camera, when we only    consider visibility rays (so no shadow rays, for example)? You can assume you're working with an orthographic camera.</li>
  </ul>
</blockquote>

<p>There's two things to consider here.</p>

<p>1) Does any part of the heuristic depend on the position of the camera? Can moving the camera change any of the numbers that feed into the score?</p>

<p>2) Moving the camera can change how the boxes overlap. Remember that rays that pass through the box need to be tested against the box behind, so needless overlaps make the structure worse.</p>

<p>I think the point is that the heuristic is <em>only</em> a general rule. It's not hard to construct an example with two proposals <em>a</em> and <em>b</em>, where <em>a</em> scores much better but <em>b</em> is actually a better split for a particular camera, and this last part of the question is trying to get you to think about this.</p>

CC BY-SA 3.0
2018-01-29T12:22:44.820Z
Oh, you were probably typing out your answer when I replied above! Thank you very much for the detailed answer, Dan! Everything is much clearer now.
Robin Haveneers
CC BY-SA 3.0
2018-01-29T12:27:11.987Z
One question though, about the tea-pot. If the bounding box does not change, am I correct to assume that the enclosed object does not matter? The tea pot fits within the bounding box but the bounding box remains the same (cfr. the question), so it does not affect the surface area, which is still calculated using the 6 surfaces of the cubic bounding box.
Robin Haveneers
CC BY-SA 3.0
2018-01-29T13:07:05.770Z
Oh of course, this version of the SAH just uses the box volume. Ignore that bit then! I was thinking of a different version that actually uses the triangle areas in the leaf nodes. In that case, ask yourself the same question as for the last part: will changing the objects change any number in the heuristic? Will they change the actual hit-ratio of the box? What does this tell you about how the heuristic relates to the measured performance?
Dan Hulme
CC BY-SA 3.0
2018-01-29T14:25:22.897Z
I would say that changing the objects or the camera position doesn't change the heuristic, seen as though the surface area is based on Crofton's theorem (independent of the camera). So I'd assume that (in line with what you said) the position of the camera does not influence the score. But, it's only a heuristic so the position of the camera WILL influence the hit ratio. E.g: the 1st setup when we view a camera from above (y axis): if a ray hits the bounding box there, we have a much higher probability of actually hitting an object which is not the case if we have a camera along the z-axis.
Robin Haveneers
CC BY-SA 3.0
2018-01-29T11:45:02.767Z
2018-01-29T11:45:02.767Z
Dan Hulme
<p>My professor gave me the following example exam question:</p>

<blockquote>
  <p>Given 4 spheres with diameter = 1. Their centers are located on
  coordinates (2,4,0), (4,2,0), (4,6,0) and (6,4,0), as seen in the
  picture below. Three different hierarchies of tightest possible
  axis-aligned bounding volumes (AABB) are given:</p>
  
  <ul>
  <li>A single AABB around every sphere</li>
  <li>An AABB around the spheres with center (2,4,0) and (4,2,0) and    another around the spheres located at (4,6,0) and (6,4,0).</li>
  <li>An AABB around the spheres with center (2,4,0) and (6,4,0) and    another around the spheres located at (4,2,0) and (4,6,0).</li>
  </ul>
  
  <p>For every one of these the all-containing AABB is constructed.</p>
</blockquote>

<p><a href="https://i.sstatic.net/IEBNK.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/IEBNK.png" alt="Assignment"></a></p>

<p>The questions are:</p>

<blockquote>
  <ul>
  <li>Rank these 3 structures based on efficiency for intersecting a ray    with these spheres (best to worst)</li>
  <li>Does this ranking change if we change the spheres with a (scaled) tea-pot that still fits within the bounding volume?</li>
  <li>Can this ranking depend on the position of the camera, when we only    consider visibility rays (so no shadow rays, for example)? You can assume you're working with an orthographic camera.</li>
  </ul>
</blockquote>

<p>He insisted on not giving a 'philosophical' answer (like: 'this depends on ...') but rather actually calculating the cost using the surface are heuristic etc.</p>

<p>Only, I have no idea how to start. The cost function we have seen is defined as follows
$$Cost(cell) = C_t + \frac{S_L}{S_{Cell}} \times N_L \times t_i + \frac{S_R}{S_{Cell}} \times N_R \times t_i$$
With:</p>

<ul>
<li>$C_t$ the cost of traversal (which is an arbitrary constant, I think)</li>
<li>$S_L$/$S_R$ the surface area of the left/right child cell</li>
<li>$S_{cell}$ the surface area of the entire cell</li>
<li>$N_L$/$N_R$ the number of objects in the left/right child cell</li>
<li>$t_i$ the cost of object intersection (which is also an arbitrary
constant)</li>
</ul>

<p>However, the first hierarchy has 4 child cells, how would I calculate the cost here? Any tips on how to start this exercise would be very helpful.</p>

<p><strong>EDIT:</strong> Okay, so for the second and third setup, is it as simple as filling in the formula? For the second setup, this would lead to (assuming I made no numerical errors :) ):
$$\begin{align*}Cost(cell) &amp;= C_t + \frac{2*3^2 + 4*3*1}{2*5^2 + 4*5*1} * 2 * t_i + \frac{2*3^2 + 4*3*1}{2*5^2 + 4*5*1} * 2 * t_i \\ &amp;= C_t + \frac{120}{70} * t_i \end{align*}$$</p>

<p>For the third setup this would, analogously, lead to:
$$Cost(cell) = C_t + \frac{88}{70}*t_i$$.</p>

<p><strong>So now my question would boil down to: can I just do the same for the first setup, but instead evaluate 4 sub-cells? Also, am I correct in assuming $C_t$ and $t_i$ are fixed constants or do they depend on the setup?</strong></p>

CC BY-SA 3.0
2018-01-29T11:14:23.163Z
This is a great example of a homework question where you've "done your homework": you've shown how far you got and what you have, and where you're stuck. Good work!
Dan Hulme
CC BY-SA 3.0
2018-01-29T11:22:46.313Z
Thank you, now if only someone could help me figure it out,haha :D
Robin Haveneers
<raytracing><ray><bounding-volume-hierarchy>
Classify acceleration structure using surface area heuristic
Robin Haveneers
# Classify acceleration structure using surface area heuristic

(Asked by: username_0 on 2018-01-29)

My professor gave me the following example exam question:

> Given 4 spheres with diameter = 1. Their centers are located on
> coordinates (2,4,0), (4,2,0), (4,6,0) and (6,4,0), as seen in the
> picture below. Three different hierarchies of tightest possible
> axis-aligned bounding volumes (AABB) are given:
>
> * A single AABB around every sphere
> * An AABB around the spheres with center (2,4,0) and (4,2,0) and another around the spheres located at (4,6,0) and (6,4,0).
> * An AABB around the spheres with center (2,4,0) and (6,4,0) and another around the spheres located at (4,2,0) and (4,6,0).
>
> For every one of these the all-containing AABB is constructed.

[![Assignment](https://i.sstatic.net/IEBNK.png)](https://i.sstatic.net/IEBNK.png)

The questions are:

> * Rank these 3 structures based on efficiency for intersecting a ray with these spheres (best to worst)
> * Does this ranking change if we change the spheres with a (scaled) tea-pot that still fits within the bounding volume?
> * Can this ranking depend on the position of the camera, when we only consider visibility rays (so no shadow rays, for example)? You can assume you're working with an orthographic camera.

He insisted on not giving a 'philosophical' answer (like: 'this depends on ...') but rather actually calculating the cost using the surface are heuristic etc.

Only, I have no idea how to start. The cost function we have seen is defined as follows
$$Cost(cell) = C\_t + \frac{S\_L}{S\_{Cell}} \times N\_L \times t\_i + \frac{S\_R}{S\_{Cell}} \times N\_R \times t\_i$$
With:

* $C\_t$ the cost of traversal (which is an arbitrary constant, I think)
* $S\_L$/$S\_R$ the surface area of the left/right child cell
* $S\_{cell}$ the surface area of the entire cell
* $N\_L$/$N\_R$ the number of objects in the left/right child cell
* $t\_i$ the cost of object intersection (which is also an arbitrary
  constant)

However, the first hierarchy has 4 child cells, how would I calculate the cost here? Any tips on how to start this exercise would be very helpful.

**EDIT:** Okay, so for the second and third setup, is it as simple as filling in the formula? For the second setup, this would lead to (assuming I made no numerical errors :) ):
$$\begin{align\*}Cost(cell) &= C\_t + \frac{2\*3^2 + 4\*3\*1}{2\*5^2 + 4\*5\*1} \* 2 \* t\_i + \frac{2\*3^2 + 4\*3\*1}{2\*5^2 + 4\*5\*1} \* 2 \* t\_i \\ &= C\_t + \frac{120}{70} \* t\_i \end{align\*}$$

For the third setup this would, analogously, lead to:
$$Cost(cell) = C\_t + \frac{88}{70}\*t\_i$$.

**So now my question would boil down to: can I just do the same for the first setup, but instead evaluate 4 sub-cells? Also, am I correct in assuming $C\_t$ and $t\_i$ are fixed constants or do they depend on the setup?**

**Tags:** raytracing, ray, bounding-volume-hierarchy

> **Comments:**
> **username_1**: This is a great example of a homework question where you've "done your homework": you've shown how far you got and what you have, and where you're stuck. Good work!  
> **username_0**: Thank you, now if only someone could help me figure it out,haha :D  

---

## 1 answers

### Answer by username_1 on 2018-01-29. Score: 1 | Accepted answer

You gave the formula as:

$$Cost(cell) = C\_t + \frac{S\_L}{S\_{Cell}} \times N\_L \times t\_i + \frac{S\_R}{S\_{Cell}} \times N\_R \times t\_i$$

(You put $r\_i$ at the right-hand end, but I assume that was a typo.)

There's a more general form of this formula

$$Cost(cell) = C\_t + \sum\_{k\ \in\ K} \frac{S\_k}{S\_{Cell}} \times N\_k \times t\_i$$

where $K$ is the set of all child nodes; that is, to get back to the two-children form you started with, $K = \{L, R\}$.

By generalising the formula like this, you can now calculate the cost for the first possibility the same way as the second two.

You're right that this is a slightly odd question. In practice, your traversal cost is going to be less for a binary tree than a $(> 2)$-ary tree.

> * Does this ranking change if we change the spheres with a (scaled) tea-pot that still fits within the bounding volume?

To answer this, you'll need to consider how this affects the surface area, and how this changes each score in turn.

> * Can this ranking depend on the position of the camera, when we only consider visibility rays (so no shadow rays, for example)? You can assume you're working with an orthographic camera.

There's two things to consider here.

1) Does any part of the heuristic depend on the position of the camera? Can moving the camera change any of the numbers that feed into the score?

2) Moving the camera can change how the boxes overlap. Remember that rays that pass through the box need to be tested against the box behind, so needless overlaps make the structure worse.

I think the point is that the heuristic is *only* a general rule. It's not hard to construct an example with two proposals *a* and *b*, where *a* scores much better but *b* is actually a better split for a particular camera, and this last part of the question is trying to get you to think about this.

> **Comments:**
> **username_0**: Oh, you were probably typing out your answer when I replied above! Thank you very much for the detailed answer, Dan! Everything is much clearer now.  
> **username_0**: One question though, about the tea-pot. If the bounding box does not change, am I correct to assume that the enclosed object does not matter? The tea pot fits within the bounding box but the bounding box remains the same (cfr. the question), so it does not affect the surface area, which is still calculated using the 6 surfaces of the cubic bounding box.  
> **username_1**: Oh of course, this version of the SAH just uses the box volume. Ignore that bit then! I was thinking of a different version that actually uses the triangle areas in the leaf nodes. In that case, ask yourself the same question as for the last part: will changing the objects change any number in the heuristic? Will they change the actual hit-ratio of the box? What does this tell you about how the heuristic relates to the measured performance?  
> **username_0**: I would say that changing the objects or the camera position doesn't change the heuristic, seen as though the surface area is based on Crofton's theorem (independent of the camera). So I'd assume that (in line with what you said) the position of the camera does not influence the score. But, it's only a heuristic so the position of the camera WILL influence the hit ratio. E.g: the 1st setup when we view a camera from above (y axis): if a ray hits the bounding box there, we have a much higher probability of actually hitting an object which is not the case if we have a camera along the z-axis.  

---

