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

A geometric description of a shape as a union of other shapes. More...

#include <CompositeShape.h>

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

Public Member Functions

void addShape (const Shape &shape, const Pose3D &pose)
 add a shape to the composite More...
 
CompositeShapeclone () const
 
 CompositeShape ()
 
bool contains (const Vector3 &p) const
 Determines whether a point p lies within the shape. More...
 
Box getBoundingBox () const
 Returns the smallest box which includes all mesh points. Box is not rotated, but matches the axis of the Shape. More...
 
double getMaxRadius () const
 Calculate the maximum distance from the origin of the shape to any point of the shape. More...
 
const std::vector< std::pair< ShapePtr, Transform > > & getShapes () const
 Get all the child shapes and their inverse pose relative to the "origin" of the CompositeShape. 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...
 
virtual ~CompositeShape ()
 
- 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 Attributes

Box bb_
 
Vector3 max_
 
double max_radius_
 
Vector3 min_
 
std::vector< std::pair< ShapePtr, Transform > > shapes_
 
- 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 geometric description of a shape as a union of other shapes.

Definition at line 16 of file CompositeShape.h.

Constructor & Destructor Documentation

◆ CompositeShape()

geo::CompositeShape::CompositeShape ( )

Definition at line 9 of file CompositeShape.cpp.

◆ ~CompositeShape()

geo::CompositeShape::~CompositeShape ( )
virtual

Definition at line 12 of file CompositeShape.cpp.

Member Function Documentation

◆ addShape()

void geo::CompositeShape::addShape ( const Shape shape,
const Pose3D pose 
)

add a shape to the composite

Parameters
shapechild shape to be added
posepose of the origin of the child shape relative to the origin of the composite shape

Definition at line 86 of file CompositeShape.cpp.

◆ clone()

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

Reimplemented from geo::Shape.

Definition at line 15 of file CompositeShape.cpp.

◆ contains()

bool geo::CompositeShape::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 64 of file CompositeShape.cpp.

◆ getBoundingBox()

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

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

Returns
geo::Box of the bounding box.

Reimplemented from geo::Shape.

Definition at line 115 of file CompositeShape.cpp.

◆ getMaxRadius()

double geo::CompositeShape::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 82 of file CompositeShape.cpp.

◆ getShapes()

const std::vector< std::pair< ShapePtr, Transform > > & geo::CompositeShape::getShapes ( ) const

Get all the child shapes and their inverse pose relative to the "origin" of the CompositeShape.

Returns
reference to the vector of all ShapePtr and Transform

Definition at line 119 of file CompositeShape.cpp.

◆ intersect() [1/2]

bool geo::CompositeShape::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 19 of file CompositeShape.cpp.

◆ intersect() [2/2]

bool geo::CompositeShape::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 50 of file CompositeShape.cpp.

◆ setMesh()

void geo::CompositeShape::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 123 of file CompositeShape.cpp.

Member Data Documentation

◆ bb_

Box geo::CompositeShape::bb_
protected

Definition at line 65 of file CompositeShape.h.

◆ max_

Vector3 geo::CompositeShape::max_
protected

Definition at line 63 of file CompositeShape.h.

◆ max_radius_

double geo::CompositeShape::max_radius_
protected

Definition at line 59 of file CompositeShape.h.

◆ min_

Vector3 geo::CompositeShape::min_
protected

Definition at line 61 of file CompositeShape.h.

◆ shapes_

std::vector<std::pair<ShapePtr, Transform> > geo::CompositeShape::shapes_
protected

Pairs of child shapes and the transform from the origin of the child shape to the origin of the composite shape

Definition at line 57 of file CompositeShape.h.


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