geolib2
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
geo::Box Class Reference

#include <Box.h>

Inheritance diagram for geo::Box:
Inheritance graph
[legend]

Public Member Functions

 Box (const Vector3 &min, const Vector3 &max)
 
Boxclone () const
 
bool contains (const Vector3 &p) const
 Determines whether a point p lies within the shape. More...
 
void enclose (const Box &box, const Pose3D &pose)
 
Box getBoundingBox () const
 Returns the smallest box which includes all mesh points. Box is not rotated, but matches the axis of the Shape. More...
 
Vector3 getCenter () const
 Determine the center of the box with respect to the origin of the box. More...
 
const Vector3getMax () const
 get vertex of the box with maximum coordinates More...
 
double getMaxRadius () const
 Calculate the maximum distance from the origin of the shape to any point of the shape. More...
 
const Vector3getMin () const
 get vertex of the box with minimum coordinates More...
 
Vector3 getSize () const
 get the size of the box along all axes More...
 
bool intersect (const Box &other) const
 Determines whether this Box intersects with another box. More...
 
bool intersect (const Ray &r, float t0, float t1, double &distance) const
 intersect: currently always throws a logic error More...
 
bool intersect (const Vector3 &p, const double radius) const
 Determines whether the shape intersects a sphere with center p. More...
 
void setMesh (const Mesh &mesh)
 set the Mesh Any child classes should throw a std::logic_error in case the mesh should not be changed via setMesh. More...
 
- Public Member Functions inherited from geo::Shape
virtual bool empty () const
 empty Test whether the shape(mesh) is empty. More...
 
virtual const MeshgetMesh () const
 return the mesh defining the shape More...
 
 Shape ()
 
virtual bool write (std::ostream &output) const
 write, serialise the shape More...
 
virtual ~Shape ()
 

Protected Member Functions

void generate_mesh_ ()
 Should be called any time bounds is changed. More...
 

Protected Attributes

Vector3 bounds [2]
 
double max_radius_
 
- Protected Attributes inherited from geo::Shape
Mesh mesh_
 Should not be read or written to directly in general. Use setMesh and getMesh to write respectively read the mesh. In a few exceptions, the mesh can be written direcly. Make sure that mesh keeps consistent with other member variables. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from geo::Shape
static ShapePtr read (std::istream &input)
 read serialised data from an input stream and create a shape More...
 
- Static Public Attributes inherited from geo::Shape
static const std::string TYPE = "mesh"
 

Detailed Description

A class describing a box geometry

The box is defined by two vectors. Its origin is therefore not in the center of the box

Definition at line 15 of file Box.h.

Constructor & Destructor Documentation

◆ Box()

geo::Box::Box ( const Vector3 min,
const Vector3 max 
)

Definition at line 11 of file Box.cpp.

Member Function Documentation

◆ clone()

Box * geo::Box::clone ( ) const
virtual

Reimplemented from geo::Shape.

Definition at line 17 of file Box.cpp.

◆ contains()

bool geo::Box::contains ( const Vector3 p) const
virtual

Determines whether a point p lies within the shape.

Parameters
ppoint to test
Returns
True means point p lies inside the shape

Let the line segment P connect points p and an arbitrary point p_out outside of the shape We count the number of intersections between P and the shape. A positive number means point p is inside the shape. We use plucker coordinates to determine whether or not a triangle intersects line segment P. more details https://members.loria.fr/SLazard/ARC-Visi3D/Pant-project/files/Line_Segment_Triangle.html

Reimplemented from geo::Shape.

Definition at line 86 of file Box.cpp.

◆ enclose()

void geo::Box::enclose ( const Box box,
const Pose3D pose 
)

Definition at line 96 of file Box.cpp.

◆ generate_mesh_()

void geo::Box::generate_mesh_ ( )
protected

Should be called any time bounds is changed.

Definition at line 133 of file Box.cpp.

◆ getBoundingBox()

Box geo::Box::getBoundingBox ( ) const
virtual

Returns the smallest box which includes all mesh points. Box is not rotated, but matches the axis of the Shape.

Return a bounding box, which is the same as the object itself.

Returns
itself

Reimplemented from geo::Shape.

Definition at line 92 of file Box.cpp.

◆ getCenter()

Vector3 geo::Box::getCenter ( ) const

Determine the center of the box with respect to the origin of the box.

Returns

Definition at line 115 of file Box.cpp.

◆ getMax()

const Vector3 & geo::Box::getMax ( ) const

get vertex of the box with maximum coordinates

Returns
vector

Definition at line 123 of file Box.cpp.

◆ getMaxRadius()

double geo::Box::getMaxRadius ( ) const
virtual

Calculate the maximum distance from the origin of the shape to any point of the shape.

Returns
Maximum radius found.

Reimplemented from geo::Shape.

Definition at line 51 of file Box.cpp.

◆ getMin()

const Vector3 & geo::Box::getMin ( ) const

get vertex of the box with minimum coordinates

Returns
vector

Definition at line 119 of file Box.cpp.

◆ getSize()

Vector3 geo::Box::getSize ( ) const

get the size of the box along all axes

Returns
vector with the sizes of the box along the corresponding axes

Definition at line 111 of file Box.cpp.

◆ intersect() [1/3]

bool geo::Box::intersect ( const Box other) const

Determines whether this Box intersects with another box.

The two boxes are not rotated, they are assumed to be axis aligned.

Parameters
othersecond box
Returns
True means this box intersects with the other box

Definition at line 55 of file Box.cpp.

◆ intersect() [2/3]

bool geo::Box::intersect ( const Ray r,
float  t0,
float  t1,
double &  distance 
) const
virtual

intersect: currently always throws a logic error

Parameters
r
t0
t1
distance
Returns
true when the ray intersects the shape

Reimplemented from geo::Shape.

Definition at line 21 of file Box.cpp.

◆ intersect() [3/3]

bool geo::Box::intersect ( const Vector3 p,
const double  radius 
) const
virtual

Determines whether the shape intersects a sphere with center p.

Parameters
pcenter of the sphere
radiusradius of the sphere
Returns
True means the sphere intersects the shape

Main logic: http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.49.9172&rep=rep1&type=pdf Projection in triangle logic: https://www.baeldung.com/cs/check-if-point-is-in-2d-triangle#1-mathematical-idea-2

Reimplemented from geo::Shape.

Definition at line 69 of file Box.cpp.

◆ setMesh()

void geo::Box::setMesh ( const Mesh mesh)
virtual

set the Mesh Any child classes should throw a std::logic_error in case the mesh should not be changed via setMesh.

Parameters
meshmesh to set

Reimplemented from geo::Shape.

Definition at line 127 of file Box.cpp.

Member Data Documentation

◆ bounds

Vector3 geo::Box::bounds[2]
protected

Definition at line 77 of file Box.h.

◆ max_radius_

double geo::Box::max_radius_
protected

Definition at line 79 of file Box.h.


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