[−][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.
extern crate pbrt; use pbrt::core::geometry::Point3; fn main() { let int_origin = Point3 { x: 0, y: 0, z: 0 }; let float_origin = Point3 { 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.
extern crate pbrt; use pbrt::core::geometry::Vector3; fn main() { let int_null = Vector3 { x: 0, y: 0, z: 0 }; let float_null = Vector3 { 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.
extern crate pbrt; use pbrt::core::geometry::Normal3; fn main() { let int_null = Normal3 { x: 0, y: 0, z: 0 }; let float_null = Normal3 { x: 0.0, y: 0.0, z: 0.0, }; println!("int {:?}", int_null); 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.
extern crate pbrt; use pbrt::core::geometry::{Ray, Point3f, Vector3f}; 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: 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
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.
extern crate pbrt; use pbrt::core::geometry::{Bounds3, Point3}; fn main() { let int_origin = Point3 { x: 0, y: 0, z: 0 }; let int_xyz111 = Point3 { x: 1, y: 1, z: 1 }; let float_origin = Point3 { x: 0.0, y: 0.0, z: 0.0, }; let float_xyz111 = Point3 { x: 1.0, y: 1.0, z: 1.0, }; let int_unit_cube = Bounds3 { p_min: int_origin, p_max: int_xyz111, }; let float_unit_cube = Bounds3 { p_min: float_origin, p_max: float_xyz111, }; println!("int {:?}", int_unit_cube); println!("float {:?}", float_unit_cube); }
Structs
Bounds2 | |
Bounds2Iterator | |
Bounds3 | |
Normal3 | |
Point2 | |
Point3 | |
Ray | |
RayDifferential | |
Vector2 | |
Vector3 |
Functions
bnd2_expand |
Pads the bounding box by a constant factor in both dimensions. |
bnd3_expand |
Pads the bounding box by a constant factor in all dimensions. |
bnd2_intersect_bnd2 |
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_union_bnd3 |
Construct a new box that bounds the space encompassed by two other bounding boxes. |
bnd3_union_pnt3 |
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 |
Return normal with the absolute value of each coordinate. |
nrm_abs_dot_vec3 |
Computes the absolute value of the dot product. |
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_nrm |
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_vec3 |
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_floor |
Apply floor operation component-wise. |
pnt2_ceil |
Apply ceil operation component-wise. |
pnt2_inside_exclusive |
Is a 2D point inside a 2D bound? |
pnt3_permute |
Permute the coordinate values according to the povided permutation. |
pnt3_lerp |
Interpolate linearly between two provided points. |
pnt3_floor |
Apply floor operation component-wise. |
pnt3_ceil |
Apply ceil operation component-wise. |
pnt3_abs |
Apply abs operation component-wise. |
pnt3_distance |
The distance between two points is the length of the vector between them. |
pnt3_distance_squared |
The distance squared between two points is the length of the vector between them squared. |
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_inside_exclusive |
Is a 3D point inside a 3D bound? |
pnt2_inside_bnd2 |
Determine if a given point is inside the bounding box. |
pnt2_max_pnt2 |
Apply std::cmp::max operation component-wise. |
pnt2_min_pnt2 |
Apply std::cmp::min operation component-wise. |
pnt3_inside_bnd3 |
Determine if a given point is inside the bounding box. |
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_dot |
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_nrm |
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_abs_dot_nrm |
Computes the absolute value of the dot product. |
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_max_component |
Return the largest coordinate value. |
vec3_max_dimension |
Return the index of the component with the largest value. |
vec3_permute |
Permute the coordinate values according to the povided permutation. |
vec3_coordinate_system |
Construct a local coordinate system given only a single 3D vector. |
vec3_abs_dot_vec3 |
Computes the absolute value of the dot product. |
vec3_cross_vec3 |
Given two vectors in 3D, the cross product is a vector that is perpendicular to both of them. |
vec3_dot_vec3 |
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. |
Type Definitions
Bounds2f | |
Bounds2i | |
Bounds3f | |
Bounds3i | |
Normal3f | |
Point2f | |
Point2i | |
Point3f | |
Point3i | |
Vector2f | |
Vector2i | |
Vector3f | |
Vector3i |