[][src]Module pbrt::core::geometry

Almost all nontrivial graphics programs are built on a foundation of geometric classes. These classes represent mathematical constructs like points, vectors, and rays.

Points

A point is a zero-dimensional location in 2D or 3D space. The Point2 and Point3 classes in pbrt represent points in the obvious way: using x, y, z (in 3D) coordinates with respect to a coordinate system. Although the same representation is used for vectors, the fact that a point represents a position whereas a vector represents a direction leads to a number of important differences in how they are treated.

use pbrt::core::geometry::{Point3i, Point3f};

fn main() {
    let int_origin = Point3i { x: 0, y: 0, z: 0 };
    let float_origin = Point3f {
        x: 0.0,
        y: 0.0,
        z: 0.0,
    };

    println!("int   {:?}", int_origin);
    println!("float {:?}", float_origin);
}

Vectors

pbrt provides both 2D and 3D vector classes. Both are parameterized by the type of the underlying vector element, thus making it easy to instantiate vectors of both integer and floating-point types.

use pbrt::core::geometry::{Vector3i, Vector3f};

fn main() {
    let int_null = Vector3i { x: 0, y: 0, z: 0 };
    let float_null = Vector3f {
        x: 0.0,
        y: 0.0,
        z: 0.0,
    };

    println!("int   {:?}", int_null);
    println!("float {:?}", float_null);
}

Normals

A surface normal (or just normal) is a vector that is perpendicular to a surface at a particular position. It can be defined as the cross product of any two nonparallel vectors that are tangent to the surface at a point. Although normals are superficially similar to vectors, it is important to distinguish between the two of them: because normals are defined in terms of their relationship to a particular surface, they behave differently than vectors in some situations, particularly when applying transformations.

use pbrt::core::geometry::Normal3f;

fn main() {
    let float_null = Normal3f {
        x: 0.0,
        y: 0.0,
        z: 0.0,
    };

    println!("float {:?}", float_null);
}

Rays

A ray is a semi-infinite line specified by its origin and direction. pbrt represents a Ray with a Point3f for the origin and a Vector3f for the direction. We only need rays with floating-point origins and directions, so Ray isn't a template class parameterized by an arbitrary type, as points, vectors, and normals were.

use pbrt::core::geometry::{Ray, Point3f, Vector3f};
use std::cell::Cell;

fn main() {
    let origin = Point3f {
        x: -5.5,
        y: 2.75,
        z: 0.0,
    };
    let direction = Vector3f {
        x: 1.0,
        y: -8.75,
        z: 2.25,
    };
    let ray = Ray {
        o: origin,
        d: direction,
        t_max: Cell::new(std::f32::INFINITY),
        time: 0.0,
        medium: None,
        differential: None,
    };
}

RayDifferentials

RayDifferential is a subclass of Ray that contains additional information about two auxiliary rays. These extra rays represent camera rays offset by one sample in the x and y direction from the main ray on the film plane. By determining the area that these three rays project on an object being shaded, the Texture can estimate an area to average over for proper antialiasing.

In Rust we don't have inheritance, therefore we use an Option in the Ray struct, which means the additional information can be present (or not).

Bounding Boxes

Many parts of the system operate on axis-aligned regions of space. For example, multi-threading in pbrt is implemented by subdividing the image into rectangular tiles that can be processed independently, and the bounding volume hierarchy uses 3D boxes to bound geometric primitives in the scene. The Bounds2 and Bounds3 template classes are used to represent the extent of these sort of regions. Both are parameterized by a type T that is used to represent the coordinates of its extents.

use pbrt::core::geometry::{Bounds3i, Bounds3f, Point3i, Point3f};

fn main() {
    let int_origin = Point3i { x: 0, y: 0, z: 0 };
    let int_xyz111 = Point3i { x: 1, y: 1, z: 1 };
    let float_origin = Point3f {
        x: 0.0,
        y: 0.0,
        z: 0.0,
    };
    let float_xyz111 = Point3f {
        x: 1.0,
        y: 1.0,
        z: 1.0,
    };
    let int_unit_cube = Bounds3i {
        p_min: int_origin,
        p_max: int_xyz111,
    };
    let float_unit_cube = Bounds3f {
        p_min: float_origin,
        p_max: float_xyz111,
    };

    println!("int   {:?}", int_unit_cube);
    println!("float {:?}", float_unit_cube);
}

Structs

Bounds2Iterator
Bounds2f
Bounds2i
Bounds3f
Bounds3i
MinMaxEnumIter
Normal3f
Normal3i
Point2f
Point2i
Point3f
Point3i
Ray
RayDifferential
Vector2f
Vector2i
Vector3f
Vector3i
XYEnumIter
XYZEnumIter

Enums

MinMaxEnum
XYEnum
XYZEnum

Functions

bnd2_expand

Pads the bounding box by a constant factor in both dimensions.

bnd2_intersect_bnd2i

The intersection of two bounding boxes can be found by computing the maximum of their two respective minimum coordinates and the minimum of their maximum coordinates.

bnd2_union_pnt2

Given a bounding box and a point, the bnd2_union_pnt2() function returns a new bounding box that encompasses that point as well as the original box.

bnd3_expand

Pads the bounding box by a constant factor in all dimensions.

bnd3_union_bnd3f

Construct a new box that bounds the space encompassed by two other bounding boxes.

bnd3_union_pnt3f

Given a bounding box and a point, the bnd3_union_pnt3() function returns a new bounding box that encompasses that point as well as the original box.

nrm_abs_dot_vec3f

Computes the absolute value of the dot product.

nrm_abs_dot_vec3i

Computes the absolute value of the dot product.

nrm_absf

Return normal with the absolute value of each coordinate.

nrm_absi

Return normal with the absolute value of each coordinate.

nrm_cross_vec3

Given a normal and a vector in 3D, the cross product is a vector that is perpendicular to both of them.

nrm_dot_nrmf

Product of the Euclidean magnitudes of a normal (and another normal) and the cosine of the angle between them. A return value of zero means both are orthogonal, a value if one means they are codirectional.

nrm_dot_nrmi

Product of the Euclidean magnitudes of a normal (and another normal) and the cosine of the angle between them. A return value of zero means both are orthogonal, a value if one means they are codirectional.

nrm_dot_vec3f

Product of the Euclidean magnitudes of a normal (and a vector) and the cosine of the angle between them. A return value of zero means both are orthogonal, a value if one means they are codirectional.

nrm_dot_vec3i

Product of the Euclidean magnitudes of a normal (and a vector) and the cosine of the angle between them. A return value of zero means both are orthogonal, a value if one means they are codirectional.

nrm_faceforward_nrm

Flip a surface normal so that it lies in the same hemisphere as a given normal.

nrm_faceforward_vec3

Flip a surface normal so that it lies in the same hemisphere as a given vector.

pnt2_ceil

Apply ceil operation component-wise.

pnt2_floor

Apply floor operation component-wise.

pnt2_inside_bnd2f

Determine if a given point is inside the bounding box.

pnt2_inside_bnd2i

Determine if a given point is inside the bounding box.

pnt2_inside_exclusivef

Is a 2D point inside a 2D bound?

pnt2_inside_exclusivei

Is a 2D point inside a 2D bound?

pnt2_max_pnt2i

Apply std::cmp::max operation component-wise.

pnt2_min_pnt2i

Apply std::cmp::min operation component-wise.

pnt3_abs

Apply abs operation component-wise.

pnt3_ceil

Apply ceil operation component-wise.

pnt3_distance_squaredf

The distance squared between two points is the length of the vector between them squared.

pnt3_distancef

The distance between two points is the length of the vector between them.

pnt3_floor

Apply floor operation component-wise.

pnt3_inside_bnd3

Determine if a given point is inside the bounding box.

pnt3_lerp

Interpolate linearly between two provided points.

pnt3_offset_ray_origin

When tracing spawned rays leaving the intersection point p, we offset their origins enough to ensure that they are past the boundary of the error box and thus won't incorrectly re-intersect the surface.

pnt3_permutef

Permute the coordinate values according to the povided permutation.

pnt3_permutei

Permute the coordinate values according to the povided permutation.

pnt3f_inside_exclusive

Is a 3D point inside a 3D bound?

pnt3i_inside_exclusive

Is a 3D point inside a 3D bound?

spherical_direction

Calculate appropriate direction vector from two angles.

spherical_direction_vec3

Take three basis vectors representing the x, y, and z axes and return the appropriate direction vector with respect to the coordinate frame defined by them.

spherical_phi

Conversion of a direction to spherical angles.

spherical_theta

Conversion of a direction to spherical angles. Note that spherical_theta() assumes that the vector v has been normalized before being passed in.

vec2_dotf

Product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. A return value of zero means both vectors are orthogonal, a value if one means they are codirectional.

vec2_doti

Product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. A return value of zero means both vectors are orthogonal, a value if one means they are codirectional.

vec3_abs_dot_nrmf

Computes the absolute value of the dot product.

vec3_abs_dot_nrmi

Computes the absolute value of the dot product.

vec3_abs_dot_vec3f

Computes the absolute value of the dot product.

vec3_abs_dot_vec3i

Computes the absolute value of the dot product.

vec3_coordinate_system

Construct a local coordinate system given only a single 3D vector.

vec3_cross_nrm

Given a vectors and a normal in 3D, the cross product is a vector that is perpendicular to both of them.

vec3_cross_vec3

Given two vectors in 3D, the cross product is a vector that is perpendicular to both of them.

vec3_dot_nrmf

Product of the Euclidean magnitudes of a vector (and a normal) and the cosine of the angle between them. A return value of zero means both are orthogonal, a value if one means they are codirectional.

vec3_dot_nrmi

Product of the Euclidean magnitudes of a vector (and a normal) and the cosine of the angle between them. A return value of zero means both are orthogonal, a value if one means they are codirectional.

vec3_dot_vec3f

Product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. A return value of zero means both vectors are orthogonal, a value if one means they are codirectional.

vec3_dot_vec3i

Product of the Euclidean magnitudes of the two vectors and the cosine of the angle between them. A return value of zero means both vectors are orthogonal, a value if one means they are codirectional.

vec3_max_componentf

Return the largest coordinate value.

vec3_max_componenti

Return the largest coordinate value.

vec3_max_dimensionf

Return the index of the component with the largest value.

vec3_max_dimensioni

Return the index of the component with the largest value.

vec3_permutef

Permute the coordinate values according to the povided permutation.

vec3_permutei

Permute the coordinate values according to the povided permutation.