Core 1.0
|
An axis aligned box. More...
#include <box.h>
Public Member Functions | |
Box () | |
Empty. | |
Box (const double &) | |
Create a cube centered at the origin and of given half side length. More... | |
Box (const Vector &) | |
Create an empty box given one vertex. More... | |
Box (const Vector &, const Vector &) | |
Create a box given two opposite corners. More... | |
Box (const Vector &, const double &) | |
Create a box given a center point and the half side length. More... | |
Box (const Vector &, const double &, const double &, const double &) | |
Create a box given a center point and its width, length, and height. More... | |
Box (const double &, const double &, const double &) | |
Create a box given its sizes. More... | |
Box (const Vector *, int) | |
Creates the bounding box of a set of points. More... | |
Box (const QVector< Vector > &) | |
Creates the bounding box of a set of points. More... | |
Box (const Box &, const Box &) | |
Create a box embedding two boxes. More... | |
Box (const Box &, const Frame &) | |
Creates an axis aligned bounding box from a box and a frame. More... | |
Box (const Box &, const FrameScaled &) | |
Creates an axis aligned bounding box from a box and a frame. More... | |
Box (const Box &, const Matrix &) | |
Creates an axis aligned bounding box from a box and a transformation matrix. More... | |
~Box () | |
Empty. | |
Vector & | operator[] (int) |
Returns either end vertex of the box. | |
Vector | operator[] (int) const |
Overloaded. | |
Vector | Center () const |
Returns the center of the box. | |
Vector | Vertex (int) const |
Returns the k-th vertex of the box. More... | |
Vector | Vertex (int, int, int, int, int, int) const |
Compute the coordinates of a grid aligned point. More... | |
Segment | Edge (int) const |
Compute the k-th edge segment of the box. More... | |
Plane | Face (int) const |
Compute the k-th plane of the box. More... | |
Vector | Size () const |
Compute the size (width, length and height) of a box. More... | |
Vector | Diagonal () const |
Returns the diagonal of the box. | |
double | Radius () const |
Returns the radius of the box, i.e. the length of the half diagonal of the box. | |
double | R (const Vector &) const |
Computes the squared Euclidean distance between the box and a point. More... | |
double | Signed (const Vector &) const |
Computes the signed distance between the box and a point. More... | |
Vector | Normal (const Vector &) const |
Computes the normal vector between a point and a box. More... | |
double | R (const Box &) const |
Compute the squared Euclidean distance between two boxes. More... | |
double | RInfinity (const Box &) const |
Compute the maximum distance between two boxes. More... | |
int | Intersect (const Ray &) const |
Check the intersection between a box and a ray. More... | |
int | Intersect (const Ray &, double &, double &) const |
Computes the intersection between a box and a ray. More... | |
int | Intersect (const Ray &, double &) const |
Compute the first positive intersection between the box and a ray. More... | |
int | Intersect (const Ray &, double &, double &, Vector &, Vector &) const |
Compute the intersection between an axis aligned box and a ray. More... | |
int | Intersect (const Ray &, double &, Vector &) const |
Compute the first positive intersection between the box and a ray. More... | |
int | Intersect (const Vector &, const Vector &) const |
Check if a segment intersects an axis aligned box. More... | |
bool | Intersect (const Box &) const |
Check if the box intersects another box. More... | |
bool | Inside (const Box &) const |
Check if an argument box is inside the box. More... | |
bool | Inside (const Vector &) const |
Check if a point is inside the box. More... | |
Box | Intersection (const Box &) const |
Computes the intersection between two boxes. More... | |
int | Difference (const Box &, Box *) const |
Computes the difference between two boxes. More... | |
bool | Empty () const |
Check if a box is empty. More... | |
double | Volume () const |
Compute the volume of a box. | |
double | Area () const |
Compute the surface area of a box. | |
void | SetCubic () |
Creates the tightest embedding cube from an arbitrarilly shaped box. More... | |
void | SetInscribedCubic () |
Creates the biggest cube iscribed in the box. More... | |
Box | Cube () const |
Return the tightest embedding cube from an arbitrarilly shaped box. More... | |
void | Extend (const double &) |
Extend the limits of the box by a given distance. More... | |
Box | Extended (const double &) const |
Extend the limits of the box by a given distance. More... | |
void | Extend (const Vector &) |
Extend the limits of the box given a point. More... | |
void | SetParallelepipedic (const double &, int &, int &, int &) |
Creates a parallelepipedic box whose dimensions are integer multiples of a given input reference size. More... | |
void | SetParallelepipedic (int, int &, int &, int &) |
Inflates a box so that its dimensions should be a fraction of its maximum side length. More... | |
Box | Sub (int) const |
Computes the sub-box in the n-th octant. More... | |
int | Octant (const Vector &) const |
Compute the octant index of a vertex with respect to the box center. More... | |
void | Translate (const Vector &) |
Translates a box. More... | |
Box | Translated (const Vector &) const |
Translated box. More... | |
void | Scale (const double &) |
Scales a box. More... | |
void | Scale (const Vector &) |
Scales a box. More... | |
Box | Scaled (const Vector &) const |
Scales a box and return the scaled box. More... | |
Box | Offsetted (const Vector &) const |
Offets a box. More... | |
Box | Centered () const |
Compute the box translated to origin. More... | |
Box | Cut (const Vector &, const Vector &) const |
Compute the minimal box embedding the box cut by half space. More... | |
int | IntegerAxis () const |
Compute the axis which has the greater length. | |
Vector | RandomInside (Random &=Random::R239) const |
Generate a random vector inside the box. More... | |
Vector | RandomSurface (Random &=Random::R239) const |
Generate a random vector on the surface of the box. More... | |
QVector< Vector > | Poisson (const double &, int, Random &=Random::R239) const |
Compute a Poisson sphere distribution inside a box. More... | |
Static Public Attributes | |
static constexpr const double | epsilon = 1.0e-5 |
Epsilon value used to check intersections and some round off errors and for ray intersection tests. | |
static const Box | Infinity |
Largest box. More... | |
static const Box | Null |
Null box, equivalent to: More... | |
static const Box | Unit |
Unit box. | |
static const int | edge [24] |
Edge vertex indexes. | |
static const Vector | normal [6] |
Face normals. | |
Protected Attributes | |
Vector | a |
Lower vertex. | |
Vector | b |
Upper vertex. | |
Friends | |
bool | operator== (const Box &, const Box &) |
Check if two boxes are (strictly) equal. More... | |
bool | operator!= (const Box &, const Box &) |
Check if two boxes are (strictly) different. More... | |
Box | operator+ (const Box &, const Box &) |
Computes the Minkowski sum of two boxes. More... | |
Box | operator* (const double &, const Box &) |
Scales a box by a scalar factor. | |
Box | operator* (const Box &, const double &) |
Overloaded. | |
std::ostream & | operator<< (std::ostream &, const Box &) |
Overloaded. More... | |
An axis aligned box.
The class stores the opposite two corners as vectors. The center and the radius (diagonal vector) are computed on the fly by inline functions.
The vertices of a box can be obtained by the Box::Vertex() member function which returns one of the eight vertices of the box. The two opposite corners can be obtained faster as follows:
This class provides a set of useful functions, such as the intersection between a box and a ray. This class also implements the Minkowski sum of boxes by overloading some operators.
Note that some intersection methods involving boxes may be implemented in other classes, for instance Segment::Intersect(const Box&) const.
|
explicit |
|
explicit |
Create an empty box given one vertex.
a | Vertex. |
Create a box given two opposite corners.
Note that this constructor does not check the coordinates of the two vectors. Therefore, the coordinates of a should be lower than those of b.
To create the axis aligned bounding box of two vectors a and b in the general case, one should use:
a,b | End vertices. |
|
explicit |
Create a box given a center point and the half side length.
c | Center. |
r | Half side length. |
|
explicit |
Create a box given a center point and its width, length, and height.
c | center. |
x,y,z | Width,length, and height. |
|
explicit |
Create a box given its sizes.
x,y,z | Width,length, and height. |
|
explicit |
Creates the bounding box of a set of points.
v | Array of vertices. |
n | Number of vertices. |
|
explicit |
Creates the bounding box of a set of points.
v | Array of vertices. |
Create a box embedding two boxes.
x,y | Argument boxes. |
Creates an axis aligned bounding box from a box and a frame.
box | The box. |
frame | Transformation. |
|
explicit |
Creates an axis aligned bounding box from a box and a frame.
box | The box. |
frame | Transformation. |
Creates an axis aligned bounding box from a box and a transformation matrix.
box | The box. |
t | Transformation matrix. |
Box Box::Centered | ( | ) | const |
Box Box::Cube | ( | ) | const |
Return the tightest embedding cube from an arbitrarilly shaped box.
Compute the minimal box embedding the box cut by half space.
The part of the box that will be removed lies in the positive side of the half space.
p | Plane point. |
n | Plane normal. |
Computes the difference between two boxes.
y | Argument box. |
boxes | An array of up to 8 boxes. |
Segment Box::Edge | ( | int | k | ) | const |
|
inline |
Check if a box is empty.
The box is empty if one of the coordinates of its lower point is greater than the coordinates of the opposite point.
void Box::Extend | ( | const double & | r | ) |
Extend the limits of the box by a given distance.
Note that this is the same as performing the Minkowski sum with a cubic box of size r.
r | Range. |
void Box::Extend | ( | const Vector & | p | ) |
Extend the limits of the box given a point.
If the point lies inside the box, the vertices of the box are unchanged.
p | Point. |
Box Box::Extended | ( | const double & | r | ) | const |
Extend the limits of the box by a given distance.
Note that this is the same as performing the Minkowski sum with a cubic box of size r.
r | Range. |
Plane Box::Face | ( | int | k | ) | const |
Compute the k-th plane of the box.
k | Integer. |
|
inline |
Check if an argument box is inside the box.
box | The box. |
|
inline |
Check if a point is inside the box.
p | Point. |
|
inline |
Check if the box intersects another box.
box | Argument box. |
int Box::Intersect | ( | const Ray & | ray | ) | const |
Check the intersection between a box and a ray.
Although intersection depths are computed internally, none are returned. This function calls the intersection function and hides arguments in local variables.
ray | The ray. |
int Box::Intersect | ( | const Ray & | ray, |
double & | t | ||
) | const |
Compute the first positive intersection between the box and a ray.
ray | The ray. |
t | Intersection depth. |
int Box::Intersect | ( | const Ray & | ray, |
double & | tmin, | ||
double & | tmax | ||
) | const |
Computes the intersection between a box and a ray.
Sorted intersection depths are returned if intersection occurs.
ray | The ray |
tmin,tmax | Intersection depths |
int Box::Intersect | ( | const Ray & | ray, |
double & | tmin, | ||
double & | tmax, | ||
Vector & | an, | ||
Vector & | bn | ||
) | const |
Compute the intersection between an axis aligned box and a ray.
Parameters return the sorted intersection depths and the corresponding normal vectors.
ray | The ray. |
tmin,tmax | Minimum and maximum intersection depths. |
an,bn | Normals at intersection points. |
Compute the first positive intersection between the box and a ray.
ray | The ray. |
t | Intersection depth. |
n | Normal at intersection point. |
Check if a segment intersects an axis aligned box.
Testing a box and a segment for intersection requires checking only six separating axes: the box's three principal axes, and the vector cross products of these axes with the line direction. Again, the vectors used for these tests do not have to be normalized, and these tests can be simplified by transforming the line segment into the box's coordinate frame.
a,b | Line segment. |
Computes the intersection between two boxes.
Note that if the intersection is empty, the resulting box is invalid.
x | Argument box. |
Computes the normal vector between a point and a box.
Let q the projection of p onto the box, the normal vector is defined as n=p-q.
p | Point. |
int Box::Octant | ( | const Vector & | p | ) | const |
Compute the octant index of a vertex with respect to the box center.
p | Point. |
QVector< Vector > Box::Poisson | ( | const double & | r, |
int | n, | ||
Random & | random = Random::R239 |
||
) | const |
Compute a Poisson sphere distribution inside a box.
This function uses a simple O(n3) dart throwing algorithm.
r | Radius of the sphere. |
n | Number of candidate points. |
random | Random number generator. |
double Box::R | ( | const Box & | y | ) | const |
Compute the squared Euclidean distance between two boxes.
This function computes the squared distance to avoid the computation of a square root.
y | The box. |
|
inline |
Computes the squared Euclidean distance between the box and a point.
p | Point. |
Vector Box::RandomInside | ( | Random & | random = Random::R239 | ) | const |
Generate a random vector inside the box.
random | Random number generator. |
Vector Box::RandomSurface | ( | Random & | random = Random::R239 | ) | const |
Generate a random vector on the surface of the box.
random | Random number generator. |
double Box::RInfinity | ( | const Box & | y | ) | const |
Compute the maximum distance between two boxes.
y | The box. |
void Box::Scale | ( | const double & | s | ) |
Scales a box.
Note that this function handles negative coefficients in the scaling vector (by swapping coordinates if need be).
s | Scaling. |
void Box::Scale | ( | const Vector & | s | ) |
Scales a box.
Note that this function handles negative coefficients in the scaling vector (by swapping coordinates if need be).
s | Scaling vector. |
void Box::SetCubic | ( | ) |
Creates the tightest embedding cube from an arbitrarilly shaped box.
This function creates a cube located at the same center point, and its side length equal to the maximum side of the argument box.
void Box::SetInscribedCubic | ( | ) |
Creates the biggest cube iscribed in the box.
This function creates a cube located at the same center point, and its side length equal to the minimum side of the argument box.
void Box::SetParallelepipedic | ( | const double & | size, |
int & | x, | ||
int & | y, | ||
int & | z | ||
) |
Creates a parallelepipedic box whose dimensions are integer multiples of a given input reference size.
size | Reference size, the dimension of the box will be a multiple of this size. |
x,y,z | Three integers. |
void Box::SetParallelepipedic | ( | int | n, |
int & | x, | ||
int & | y, | ||
int & | z | ||
) |
Inflates a box so that its dimensions should be a fraction of its maximum side length.
n | Fraction. |
x,y,z | Three integers. |
double Box::Signed | ( | const Vector & | p | ) | const |
Computes the signed distance between the box and a point.
p | Point. |
|
inline |
Compute the size (width, length and height) of a box.
Box Box::Sub | ( | int | n | ) | const |
Computes the sub-box in the n-th octant.
n | Octant index. |
void Box::Translate | ( | const Vector & | t | ) |
Translates a box.
t | Translation vector. |
|
inline |
Vector Box::Vertex | ( | int | i, |
int | j, | ||
int | k, | ||
int | x, | ||
int | y, | ||
int | z | ||
) | const |
Compute the coordinates of a grid aligned point.
This function computes the coordinates of a point inside the box as if the box was decomposed into a regular grid.
i,j,k | Integer coordinates. |
x,y,z | Virtual grid size. |
Check if two boxes are (strictly) different.
a,b | Boxes. |
Computes the Minkowski sum of two boxes.
a,b | Argument boxes. |
|
friend |
Overloaded.
s | Stream. |
box | The box. |
Check if two boxes are (strictly) equal.
a,b | Boxes. |
|
static |
Largest box.
Huge bounding box, which should enclose any other.