World Builder  1.1.0-pre
A geodynamic initial conditions generator
WorldBuilder::BoundingBox< spacedim > Class Template Reference

#include <bounding_box.h>

Public Member Functions

 BoundingBox ()
 
 BoundingBox (const std::pair< Point< spacedim >, Point< spacedim >> &boundary_points)
 
template<class Container >
 BoundingBox (const Container &points)
 
std::pair< Point< spacedim >, Point< spacedim > > & get_boundary_points ()
 
const std::pair< Point< spacedim >, Point< spacedim > > & get_boundary_points () const
 
bool operator== (const BoundingBox< spacedim > &box) const
 
bool operator!= (const BoundingBox< spacedim > &box) const
 
void merge_with (const BoundingBox< spacedim > &other_bbox)
 
bool point_inside (const Point< spacedim > &p, const double tolerance=std::numeric_limits< double >::epsilon()) const
 
void extend (const double amount)
 
double volume () const
 
Point< spacedim > center () const
 
double side_length (const unsigned int direction) const
 
double lower_bound (const unsigned int direction) const
 
double upper_bound (const unsigned int direction) const
 
template<>
 BoundingBox ()
 
template<>
 BoundingBox ()
 

Private Member Functions

bool point_inside_implementation (const Point< spacedim > &p, const double tolerance=std::numeric_limits< double >::epsilon()) const
 

Private Attributes

std::pair< Point< spacedim >, Point< spacedim > > boundary_points
 

Detailed Description

template<unsigned int spacedim>
class WorldBuilder::BoundingBox< spacedim >

A class that represents a box of arbitrary dimension spacedim and with sides parallel to the coordinate axes, that is, a region

\[ [x_0^L, x_0^U] \times ... \times [x_{spacedim-1}^L, x_{spacedim-1}^U], \]

where $(x_0^L , ..., x_{spacedim-1}^L)$ and $(x_0^U , ..., x_{spacedim-1}^U)$ denote the two vertices (bottom left and top right) which are used to represent the box. The quantities $x_k^L$ and $x_k^U$ denote the "lower" and "upper" bounds of values that are within the box for each coordinate direction $k$.

Geometrically, a bounding box is thus:

  • 1D: a segment (represented by its vertices in the proper order)
  • 2D: a rectangle (represented by the vertices V at bottom left, top right)
    .--------V
    | |
    V--------.
  • 3D: a cuboid (in which case the two vertices V follow the convention and are not owned by the same face)
    .------V
    / /|
    .------. |
    | | /
    | |/
    V------.

Bounding boxes are, for example, useful in parallel distributed meshes to give a general description of the owners of each portion of the mesh. More generally, bounding boxes are often used to roughly describe a region of space in which an object is contained; if a candidate point is not within the bounding box (a test that is cheap to execute), then it is not necessary to perform an expensive test whether the candidate point is in fact inside the object itself. Bounding boxes are therefore often used as a first, cheap rejection test before more detailed checks. As such, bounding boxes serve many of the same purposes as the convex hull, for which it is also relatively straightforward to compute whether a point is inside or outside, though not quite as cheap as for the bounding box.

Taking the cross section of a BoundingBox<spacedim> orthogonal to a given direction gives a box in one dimension lower: BoundingBox<spacedim - 1>. In 3D, the 2 coordinates of the cross section of BoundingBox<3> can be ordered in 2 different ways. That is, if we take the cross section orthogonal to the y direction we could either order a 3D-coordinate into a 2D-coordinate as $(x,z)$ or as $(z,x)$. This class uses the second convention, corresponding to the coordinates being ordered cyclicly $x y z x ... $ To be precise, if we take a cross section:

Orthogonal to Cross section coordinates ordered as
x (y, z)
y (z, x)
z (x, y)

This is according to the convention set by the function coordinate_to_one_dim_higher.

Note
The majority of this class is copied from the deal.II library.

Definition at line 97 of file bounding_box.h.

Constructor & Destructor Documentation

◆ BoundingBox() [1/5]

template<unsigned int spacedim>
WorldBuilder::BoundingBox< spacedim >::BoundingBox ( )

Standard constructor. Creates an object that corresponds to a box that corresponds to the entire space, i.e. a degenerate box with end points at minus and plus infinity.

◆ BoundingBox() [2/5]

template<unsigned int spacedim>
WorldBuilder::BoundingBox< spacedim >::BoundingBox ( const std::pair< Point< spacedim >, Point< spacedim >> &  boundary_points)
inline

Standard constructor for non-empty boxes: it uses a pair of points which describe the box: one for the bottom and one for the top corner.

Definition at line 274 of file bounding_box.h.

◆ BoundingBox() [3/5]

template<unsigned int spacedim>
template<class Container >
WorldBuilder::BoundingBox< spacedim >::BoundingBox ( const Container &  points)
inline

Construct the bounding box that encloses all the points in the given container.

The constructor supports any Container that provides begin() and end() iterators to Point<spacedim> elements.

Definition at line 291 of file bounding_box.h.

◆ BoundingBox() [4/5]

template<>
WorldBuilder::BoundingBox< 2 >::BoundingBox ( )
inline

Definition at line 238 of file bounding_box.h.

◆ BoundingBox() [5/5]

template<>
WorldBuilder::BoundingBox< 3 >::BoundingBox ( )
inline

Definition at line 254 of file bounding_box.h.

Member Function Documentation

◆ center()

template<unsigned int spacedim>
Point< spacedim > WorldBuilder::BoundingBox< spacedim >::center ( ) const

Returns the point in the center of the box.

Definition at line 486 of file bounding_box.h.

◆ extend()

template<unsigned int spacedim>
void WorldBuilder::BoundingBox< spacedim >::extend ( const double  amount)
inline

Increase (or decrease) the size of the bounding box by the given amount. After calling this method, the lower left corner of the bounding box will have each coordinate decreased by amount, and the upper right corner of the bounding box will have each coordinate increased by amount.

If you call this method with a negative number, and one of the axes of the original bounding box is smaller than amount/2, the method will trigger an assertion.

Definition at line 355 of file bounding_box.h.

Here is the caller graph for this function:

◆ get_boundary_points() [1/2]

template<unsigned int spacedim>
std::pair< Point< spacedim >, Point< spacedim > > & WorldBuilder::BoundingBox< spacedim >::get_boundary_points ( )
inline

Return a reference to the boundary_points

Definition at line 318 of file bounding_box.h.

Here is the caller graph for this function:

◆ get_boundary_points() [2/2]

template<unsigned int spacedim>
const std::pair< Point< spacedim >, Point< spacedim > > & WorldBuilder::BoundingBox< spacedim >::get_boundary_points ( ) const
inline

Return a const reference to the boundary_points

Definition at line 326 of file bounding_box.h.

◆ lower_bound()

template<unsigned int spacedim>
double WorldBuilder::BoundingBox< spacedim >::lower_bound ( const unsigned int  direction) const
inline

Return the lower bound of the box in direction.

Definition at line 463 of file bounding_box.h.

◆ merge_with()

template<unsigned int spacedim>
void WorldBuilder::BoundingBox< spacedim >::merge_with ( const BoundingBox< spacedim > &  other_bbox)
inline

Enlarge the current object so that it contains other_bbox . If the current object already contains other_bbox then it is not changed by this function.

Definition at line 432 of file bounding_box.h.

◆ operator!=()

template<unsigned int spacedim>
bool WorldBuilder::BoundingBox< spacedim >::operator!= ( const BoundingBox< spacedim > &  box) const
inline

Test for inequality.

Definition at line 346 of file bounding_box.h.

◆ operator==()

template<unsigned int spacedim>
bool WorldBuilder::BoundingBox< spacedim >::operator== ( const BoundingBox< spacedim > &  box) const
inline

Test for equality.

Definition at line 336 of file bounding_box.h.

◆ point_inside()

template<unsigned int spacedim>
bool WorldBuilder::BoundingBox< spacedim >::point_inside ( const Point< spacedim > &  p,
const double  tolerance = std::numeric_limits<double>::epsilon() 
) const
inline

Return true if the point is inside the Bounding Box, false otherwise. The parameter tolerance is a factor by which the bounding box is enlarged relative to the dimensions of the bounding box in order to determine in a numerically robust way whether the point is inside.

This function is a wrapper for the function point_inside_implementation to also test point+2pi is the longtiude is smaller then zero and point-2pi if the longitude is larger than zero.

Definition at line 371 of file bounding_box.h.

Here is the caller graph for this function:

◆ point_inside_implementation()

template<unsigned int spacedim>
bool WorldBuilder::BoundingBox< spacedim >::point_inside_implementation ( const Point< spacedim > &  p,
const double  tolerance = std::numeric_limits<double>::epsilon() 
) const
inlineprivate

Return true if the point is inside the Bounding Box, false otherwise. The parameter tolerance is a factor by which the bounding box is enlarged relative to the dimensions of the bounding box in order to determine in a numerically robust way whether the point is inside.

This function is supposed to be only used by the point_inside function.

Definition at line 403 of file bounding_box.h.

◆ side_length()

template<unsigned int spacedim>
double WorldBuilder::BoundingBox< spacedim >::side_length ( const unsigned int  direction) const
inline

Returns the side length of the box in direction.

Definition at line 500 of file bounding_box.h.

◆ upper_bound()

template<unsigned int spacedim>
double WorldBuilder::BoundingBox< spacedim >::upper_bound ( const unsigned int  direction) const
inline

Return the upper bound of the box in direction.

Definition at line 475 of file bounding_box.h.

◆ volume()

template<unsigned int spacedim>
double WorldBuilder::BoundingBox< spacedim >::volume ( ) const

Compute the volume (i.e. the dim-dimensional measure) of the BoundingBox.

Definition at line 450 of file bounding_box.h.

Member Data Documentation

◆ boundary_points

template<unsigned int spacedim>
std::pair<Point<spacedim>, Point<spacedim> > WorldBuilder::BoundingBox< spacedim >::boundary_points
private

Definition at line 227 of file bounding_box.h.


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