Graphics Reference
In-Depth Information
For ray-triangle intersection, firstRayIntersection is often extended to
return the barycentric coordinates of the intersection location on the triangle hit.
As described in Section 9.2, these three weights are sufficient to reconstruct both
the location on the triangle where the ray first intersects it and any shading param-
eters interpolated from the vertices of the triangle. Returning the barycentric coor-
dinates is not necessary because, given the distance along the ray to the inter-
section, the caller could reconstruct them. However, they are naturally computed
during the intersection computation, so it is efficient and convenient to pass them
back to the caller rather than imposing the cost of recomputing them outside the
query operation.
Some data structures can resolve the query of whether any intersection exists
for r
< distance faster than they can find the closest one. This is useful for
shadow and ambient occlusion ray casting. In that case a method variant that takes
no value parameter and does not update distance is a useful extension.
37.2.2 Extracting Keys and Bounds
We want to be able to make data structures that can be instantiated for differ-
ent kinds of primitives. For example, a tree of triangles and a tree of boxes should
share an implementation. This notion of the tree template as separate from a spe-
cific type of tree is called polymorphism. It is something that you are probably
very familiar with from classic data structures. For example, std::vector<int>
and std::vector<std::string> share an implementation but are specialized for
different value types.
For spatial data structures, we therefore require some polymorphic interface
both for each data structure and for extracting a key from each Value . The choice
of interface depends on the implementation language and the needs of the sur-
rounding program.
37.2.2.1 Inheritance
In an object-oriented language such as Java, one typically uses inheritance to
extract keys, as shown in Listings 37.3 and 37.4 (the latter listing has the example).
Listing 37.3: A Java inheritance interface for expressing axis-aligned
bounding box, sphere, and point keys on a primitive and responding to
corresponding conservative intersection queries.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
public interface Primitive {
/ ** Returns a box that surrounds the primitive for use in
building spatial data structures. * /
public void getBoxBounds (AABox bounds);
public void getSphereBounds ( Sphere bounds);
public void getPosition ( Point3 pos);
/ ** Returns true if the primitive overlaps a box for use
in responding to spatial queries. * /
public bool intersectsBox (AABox box);
public bool intersectsBall ( Ball ball);
 
 
 
Search WWH ::




Custom Search