Tulip  5.6.3
Large graphs analysis and drawing
tlp::BoundingBox Struct Reference

#include <BoundingBox.h>

Inherits Array< Vec3f, 2 >.

Public Member Functions

 BoundingBox ()
 
 BoundingBox (const tlp::Vec3f &min, const tlp::Vec3f &max, bool checkMinMax=false)
 
Vec3f center () const
 
void clear ()
 
bool contains (const tlp::BoundingBox &boundingBox) const
 
bool contains (const tlp::Vec3f &coord, bool noCheck=false) const
 
float depth () const
 
void expand (const std::vector< tlp::Vec3f > &coords)
 
void expand (const tlp::BoundingBox &bb, bool noCheck=false)
 
void expand (const tlp::Vec3f &coord, bool noCheck=false)
 
void getCompleteBB (Vec3f bb[8]) const
 
float height () const
 
void init (const tlp::Vec3f &coord)
 
bool intersect (const tlp::BoundingBox &boundingBox) const
 
bool intersect (const Vec3f &segStart, const Vec3f &segEnd) const
 
bool isValid () const
 
void scale (const tlp::Vec3f &factor)
 
void translate (const tlp::Vec3f &vec)
 
float width () const
 

Detailed Description

This class represents the 3D bounding box of an object. It is mostly used to determine whether or not two object are in a state of collision.

It is defined by two 3d points, the first one (A) being the lowest point, the second (B) being the highest. As a bounding box is a mathematical entity describing the lowest and highest points, whether these points are in the top-left corner or lower-right corner depends on the axes we use. Below is a crude ASCII-art description of the axes we use in our 3D world and the points where the min and max are thus positioned. Through the rest of this class's documentation, it will be assumed that this is the convention.

     y
    |
    |
    |_____ x
   /
  /
 z

    _________ B
   /        /|
  /        / |
 /________/  |
 |        |  |
 |        |  |
 |        | /
 |________|/
 A

Definition at line 67 of file BoundingBox.h.

Constructor & Destructor Documentation

◆ BoundingBox() [1/2]

tlp::BoundingBox::BoundingBox ( )

Creates an invalid boundig box. The minimum is (1, 1, 1) and the maximum is (-1, -1, -1).

◆ BoundingBox() [2/2]

tlp::BoundingBox::BoundingBox ( const tlp::Vec3f &  min,
const tlp::Vec3f &  max,
bool  checkMinMax = false 
)

Creates a bounding box that must be valid. Validity is checked in debug mode by an assert.

Parameters
minThe lower left closest point of the box.
maxThe higher right most farther point of the box.
computeindicates whether the bounding box has to be computed with the min/max args

Member Function Documentation

◆ center()

Vec3f tlp::BoundingBox::center ( ) const
inline

Returns the geometrical center of the bounding box. An assertion is raised in debug mode if the BoundingBox is not valid.

Returns
The center of the bounding box :Vec3f

Definition at line 106 of file BoundingBox.h.

◆ clear()

void tlp::BoundingBox::clear ( )

restore an invalid state.

◆ contains() [1/2]

bool tlp::BoundingBox::contains ( const tlp::BoundingBox boundingBox) const

Checks if the given bounding box is inside the current bounding box. If one of the bounding boxes is invalid the result is always false.

Parameters
boundingBoxThe bounding box to test inclusion
Returns
bool Whether boundingBox is in the bounding box.

◆ contains() [2/2]

bool tlp::BoundingBox::contains ( const tlp::Vec3f &  coord,
bool  noCheck = false 
) const

Checks if the given vector is inside the current bounding box. If the bounding box is invalid the result is always false.

Parameters
coordA point in the 3D space.
noCheckif true current bounding box validity is not checked
Returns
bool Whether coord is in the bounding box.

◆ depth()

float tlp::BoundingBox::depth ( ) const
inline

Returns the depth of the bounding box An assertion is raised in debug mode if the bounding box is not valid.

Definition at line 136 of file BoundingBox.h.

◆ expand() [1/3]

void tlp::BoundingBox::expand ( const std::vector< tlp::Vec3f > &  coords)
inline

Expands the bounding box to one containing all the point of the vector passed as parameter.

Parameters
coordsA vector of point in the 3D space we want the bounding box to encompass.
Returns
void

Definition at line 158 of file BoundingBox.h.

◆ expand() [2/3]

void tlp::BoundingBox::expand ( const tlp::BoundingBox bb,
bool  noCheck = false 
)

Expands the bounding box to one containing the bounding box passed as parameter. If the parameter is inside the bounding box, it remains unchanged.

Parameters
bbA bounding box.
noCheckif true current bounding box validity is not checked
Returns
void

◆ expand() [3/3]

void tlp::BoundingBox::expand ( const tlp::Vec3f &  coord,
bool  noCheck = false 
)

Expands the bounding box to one containing the point passed as parameter. If the parameter is inside the bounding box, it remains unchanged.

Parameters
coordA point in the 3D space we want the bounding box to encompass.
noCheckif true current bounding box validity is not checked
Returns
void

◆ getCompleteBB()

void tlp::BoundingBox::getCompleteBB ( Vec3f  bb[8]) const

The vector passed as parameter is modified to contain the 8 points of the bounding box. The points are, in order : 0: lower leftmost closest point (the bounding box's minimum) 1: lower rightmost closest point 2: highest rightmost closest point 3: highest leftmost closest point 4: lower rightmost farthest point 5: lower rightmost farthest point 6: highest rightmost farthest point 7: highest leftmost farthest point.

Crude ASCII art again, sorry for your eyes.

   6_________ 7
   /|       /|
  / |      / |
3/__|_____/2 |
 |  |_____|__|
 |  /4    |  /5
 | /      | /
 |/_______|/
 0        1
Parameters
bbA vector in which to put the points of the bounding box.
Returns
void

◆ height()

float tlp::BoundingBox::height ( ) const
inline

Returns the height of the bounding box An assertion is raised in debug mode if the bounding box is not valid.

Definition at line 126 of file BoundingBox.h.

◆ init()

void tlp::BoundingBox::init ( const tlp::Vec3f &  coord)
inline

init the bounding box with the point passed as parameter.

Parameters
coordA point in the 3D space

Definition at line 96 of file BoundingBox.h.

◆ intersect() [1/2]

bool tlp::BoundingBox::intersect ( const tlp::BoundingBox boundingBox) const

Checks if the given bounding box intersects the current one. If one of the bounding box is invalid return false.

Parameters
boundingBoxThe bounding box to compare with.
Returns
bool Whether the bounding boxes intersect.

◆ intersect() [2/2]

bool tlp::BoundingBox::intersect ( const Vec3f &  segStart,
const Vec3f &  segEnd 
) const

Checks if the bounding box intersects a given line segment. If the bounding box is invalid the result is always false.

Parameters
segStartthe start point of the line segment on which to check intersection
segEndthe end point of the line segment on which to check intersection
Returns
bool Whether the line segment intersects the bounding box

◆ isValid()

bool tlp::BoundingBox::isValid ( ) const

Checks whether the bounding box's lowest point is less than it's highest point. "Less Than" means axis-by-axis comparison, i.e. x1 < x2 && y1 < y2 && z1 < z2.

Returns
bool Whether this bounding box is valid.

◆ scale()

void tlp::BoundingBox::scale ( const tlp::Vec3f &  factor)

Scales the bounding box, i.e. multiplying its components by a vector passed as parameter.

Parameters
factorThe factor vector to scale this bounding box by.
Returns
void

◆ translate()

void tlp::BoundingBox::translate ( const tlp::Vec3f &  vec)

Translates the bounding box by the displacement given by the vector passed as parameter.

Parameters
vecThe displacement vector in 3D space to translate this bounding box by.
Returns
void

◆ width()

float tlp::BoundingBox::width ( ) const
inline

Returns the width of the bounding box An assertion is raised in debug mode if the BoundingBox is not valid.

Definition at line 116 of file BoundingBox.h.