The SKIRT project
advanced radiative transfer for astrophysics
Box Class Reference

#include <Box.hpp>

Inheritance diagram for Box:

Public Member Functions

 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
void extend (const Box &box)
const Boxextent () 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

Protected Member Functions

void setExtent (const Box &extent)
void setExtent (double xmin, double ymin, double zmin, double xmax, double ymax, double zmax)

Private Attributes

double _xmax
double _xmin
double _ymax
double _ymin
double _zmax
double _zmin

Detailed Description

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.

Constructor & Destructor Documentation

◆ Box() [1/3]

Box::Box ( )
inline

The default constructor creates an empty box at the origin, i.e. it initializes all box coordinates to zero.

◆ Box() [2/3]

Box::Box ( double xmin,
double ymin,
double zmin,
double xmax,
double ymax,
double zmax )
inline

This constructor initializes the box coordinates to the values provided as arguments.

◆ Box() [3/3]

Box::Box ( Vec rmin,
Vec rmax )
inline

This constructor initializes the box coordinates to the components of the provided Vec objects, respectively specifying the minimum and maximum position.

Member Function Documentation

◆ cellIndices()

void Box::cellIndices ( int & i,
int & j,
int & k,
Vec r,
int nx,
int ny,
int nz ) const
inline

This function calculates the cell indices for a given position, assuming that the box would be partitioned in a given number of cells in each spatial direction.

◆ center()

Vec Box::center ( ) const
inline

This function returns the position corresponding to the center of the box

\[ x=\tfrac12 (x_\text{min}+x_\text{max}) \]

\[ y=\tfrac12 (y_\text{min}+y_\text{max}) \]

\[ z=\tfrac12 (x_\text{min}+z_\text{max}) \]

◆ contains() [1/3]

bool Box::contains ( const Box & box) const
inline

This function returns true if the given box is inside this box, false otherwise.

◆ contains() [2/3]

bool Box::contains ( double x,
double y,
double z ) const
inline

This function returns true if the position \((x,y,z)\) is inside the box, false otherwise.

◆ contains() [3/3]

bool Box::contains ( Vec r) const
inline

This function returns true if the position \({\bf{r}}\) is inside the box, false otherwise.

◆ diagonal()

double Box::diagonal ( ) const
inline

This function returns the length of the diagonal of the box, i.e. \(\sqrt{ (x_\text{max}-x_\text{min})^2 + (y_\text{max}-y_\text{min})^2 + (z_\text{max}-z_\text{min})^2 }\).

◆ extend()

void Box::extend ( const Box & box)
inline

This function extends the receiving box so that it contains both the specified and the original box.

◆ extent() [1/2]

const Box & Box::extent ( ) const
inline

This function returns a reference to the receiving box object. It is useful for explicitly retrieving the box object from instances of classes based on Box.

◆ extent() [2/2]

void Box::extent ( double & xmin,
double & ymin,
double & zmin,
double & xmax,
double & ymax,
double & zmax ) const
inline

This function stores the \((x_\text{min},y_\text{min},z_\text{min}, \,x_\text{max},y_\text{max},z_\text{max})\) coordinates of the box in the provided arguments.

◆ fracPos() [1/2]

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.

◆ fracPos() [2/2]

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.

◆ intersects() [1/3]

bool Box::intersects ( const Box & box) const
inline

This function returns true if the given box and this box have a non-zero intersection, false otherwise.

◆ intersects() [2/3]

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).

◆ intersects() [3/3]

bool Box::intersects ( Vec rc,
double r ) const

This function intersects the receiving axis-aligned bounding box with a sphere defined by the specified center position \({\bf{r}}_\mathrm{c}\) and radius \(r\). It returns true if the box and the sphere intersect, and false otherwise.

The function employs the algorithm due to Jim Arvo described in "Graphics Gems" (1990).

◆ rmax()

Vec Box::rmax ( ) const
inline

This function returns the maximum position \({\bf{r}}_\text{max}\) of the box.

◆ rmin()

Vec Box::rmin ( ) const
inline

This function returns the minimum position \({\bf{r}}_\text{min}\) of the box.

◆ setExtent() [1/2]

void Box::setExtent ( const Box & extent)
inlineprotected

This function replaces the extent of the box with the newly specified values. This function is intended for use in derived classes only.

◆ setExtent() [2/2]

void Box::setExtent ( double xmin,
double ymin,
double zmin,
double xmax,
double ymax,
double zmax )
inlineprotected

This function replaces the extent of the box with the newly specified values. This function is intended for use in derived classes only.

◆ volume()

double Box::volume ( ) const
inline

This function returns the volume \((x_\text{max}-x_\text{min}) \times (y_\text{max}-y_\text{min}) \times (z_\text{max}-z_\text{min})\) of the box.

◆ widths()

Vec Box::widths ( ) const
inline

This function returns the widths \((x_\text{max}-x_\text{min}, y_\text{max}-y_\text{min}, z_\text{max}-z_\text{min})\) of the box as a Vec object.

◆ xmax()

double Box::xmax ( ) const
inline

This function returns the \(x_\text{max}\) coordinate of the box.

◆ xmin()

double Box::xmin ( ) const
inline

This function returns the \(x_\text{min}\) coordinate of the box.

◆ xwidth()

double Box::xwidth ( ) const
inline

This function returns the width \(x_\text{max}-x_\text{min}\) of the box.

◆ ymax()

double Box::ymax ( ) const
inline

This function returns the \(y_\text{max}\) coordinate of the box.

◆ ymin()

double Box::ymin ( ) const
inline

This function returns the \(y_\text{min}\) coordinate of the box.

◆ ywidth()

double Box::ywidth ( ) const
inline

This function returns the width \(y_\text{max}-y_\text{min}\) of the box.

◆ zmax()

double Box::zmax ( ) const
inline

This function returns the \(z_\text{max}\) coordinate of the box.

◆ zmin()

double Box::zmin ( ) const
inline

This function returns the \(z_\text{min}\) coordinate of the box.

◆ zwidth()

double Box::zwidth ( ) const
inline

This function returns the width \(z_\text{max}-z_\text{min}\) of the box.

Member Data Documentation

◆ _xmin

double Box::_xmin
private

These data members represent the cartesian vector components


The documentation for this class was generated from the following file: