|
| Box () |
|
| Box (double xmin, double ymin, double zmin, double xmax, double ymax, double zmax) |
|
| Box (Vec rmin, Vec rmax) |
|
void | cellIndices (int &i, int &j, int &k, Vec r, int nx, int ny, int nz) const |
|
Vec | center () const |
|
bool | contains (const Box &box) const |
|
bool | contains (double x, double y, double z) const |
|
bool | contains (Vec r) const |
|
double | diagonal () const |
|
const Box & | extent () const |
|
void | extent (double &xmin, double &ymin, double &zmin, double &xmax, double &ymax, double &zmax) const |
|
Vec | fracPos (double xfrac, double yfrac, double zfrac) const |
|
Vec | fracPos (int xd, int yd, int zd, int xn, int yn, int zn) const |
|
bool | intersects (const Box &box) const |
|
bool | intersects (Vec r, const Vec k, double &smin, double &smax) const |
|
bool | intersects (Vec rc, double r) const |
|
Vec | rmax () const |
|
Vec | rmin () const |
|
double | volume () const |
|
Vec | widths () const |
|
double | xmax () const |
|
double | xmin () const |
|
double | xwidth () const |
|
double | ymax () const |
|
double | ymin () const |
|
double | ywidth () const |
|
double | zmax () const |
|
double | zmin () const |
|
double | zwidth () const |
|
Box is a low-level class for working with three-dimensional "boxes": each instance represents a cuboid that is lined up with the cartesian coordinate axes. A box is represented by means of its six cartesian coordinates \((x_\text{min},y_\text{min},z_\text{min},
\,x_\text{max},y_\text{max},z_\text{max})\) which are stored in data members with similar names. The class offers functions to retrieve various (mostly trivial) properties of the box, including its coordinates and widths in each direction and its volume. A Box instance is essentially immutable: once created it can no longer be changed. There is one exception to this rule: a derived class can replace the complete Box contents through the setExtent() function.
The Box class is largely implemented inline (in this header file). Most compilers optimize away all overhead so that using this class is just as efficient as directly writing the code in terms of the box components.
Vec Box::fracPos |
( |
double |
xfrac, |
|
|
double |
yfrac, |
|
|
double |
zfrac |
|
) |
| const |
|
inline |
This function returns a position in the box determined by a given fraction in each spatial direction
\[ x=x_\text{min}+x_\text{frac}\times(x_\text{max}-x_\text{min}) \]
\[ y=y_\text{min}+y_\text{frac}\times(y_\text{max}-y_\text{min}) \]
\[ z=z_\text{min}+z_\text{frac}\times(z_\text{max}-z_\text{min}) \]
The specified fractions must be between zero and one; this is not checked by the function.
Vec Box::fracPos |
( |
int |
xd, |
|
|
int |
yd, |
|
|
int |
zd, |
|
|
int |
xn, |
|
|
int |
yn, |
|
|
int |
zn |
|
) |
| const |
|
inline |
This function returns a position in the box determined by a given fraction in each spatial direction.
\[ x=x_\text{min}+\frac{x_\text{d}}{x_\text{n}}\times(x_\text{max}-x_\text{min}) \]
\[ y=y_\text{min}+\frac{y_\text{d}}{y_\text{n}}\times(y_\text{max}-y_\text{min}) \]
\[ z=z_\text{min}+\frac{z_\text{d}}{z_\text{n}}\times(z_\text{max}-z_\text{min}) \]
Each of the fractions is specified as the quotient of two integers; the integers are converted to floating point before the division is made. The quotients must be between zero and one; this is not checked by the function.
bool Box::intersects |
( |
Vec |
r, |
|
|
const Vec |
k, |
|
|
double & |
smin, |
|
|
double & |
smax |
|
) |
| const |
This function intersects the receiving axis-aligned bounding box with a ray (half-line) defined by the specified starting position \(\bf{r}\) and direction \(\bf{k}\). If the ray intersects the box, the function returns true after storing the near and far intersection distances relative to the starting position in \(s_\mathrm{min}\) and \(s_\mathrm{max}\), respectively. If the starting position is inside the box, the nearest intersection distance is set to zero. In other words, the following relation always holds: \(0\le s_\mathrm{min} < s_\mathrm{max}\).
If the ray does not intersect the box, the function returns false and the values of \(s_\mathrm{min}\) and \(s_\mathrm{max}\) are undefined. A ray that "touches" the box border in a single point is not considered to intersect the box. A ray along an edge or face on the lower side of the box is considered to intersect the box, while ray along an edge or face on the upper side of the box is considered not to intersect the box. This approach avoids duplicate intersection of adjacent boxes.
The function employs the slab method originated by Kay and Kajiya (1986) and adapted by Haines (1989) as described in "Geometric Tools for Computer Graphics" by Scheider and Eberly (2003, Elsevier).