geolib2
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Private Attributes | Friends | List of all members
geo::Shape Class Reference

A geometric description of a shape. More...

#include <Shape.h>

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

Public Member Functions

virtual Shapeclone () const
 
virtual bool contains (const Vector3 &p) const
 Determines whether a point p lies within the shape. More...
 
virtual bool empty () const
 empty Test whether the shape(mesh) is empty. More...
 
virtual Box getBoundingBox () const
 Returns the smallest box which includes all mesh points. Box is not rotated, but matches the axis of the Shape. More...
 
virtual double getMaxRadius () const
 Calculate the maximum distance from the origin of the shape to any point of the shape. More...
 
virtual const MeshgetMesh () const
 return the mesh defining the shape More...
 
virtual bool intersect (const Ray &r, float t0, float t1, double &distance) const
 intersect: currently always throws a logic error More...
 
virtual bool intersect (const Vector3 &p, const double radius) const
 Determines whether the shape intersects a sphere with center p. More...
 
virtual 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...
 
 Shape ()
 
virtual bool write (std::ostream &output) const
 write, serialise the shape More...
 
virtual ~Shape ()
 

Static Public Member Functions

static ShapePtr read (std::istream &input)
 read serialised data from an input stream and create a shape More...
 

Static Public Attributes

static const std::string TYPE = "mesh"
 

Protected Attributes

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...
 

Private Attributes

bool bounding_box_cache_valid_
 
Vector3 bounding_box_max_cache_
 
Vector3 bounding_box_min_cache_
 

Friends

class Importer
 

Detailed Description

A geometric description of a shape.

Defines a shape using a triangle mesh. The origin of the shape is not necesarily in the centre of the shape.

Definition at line 19 of file Shape.h.

Constructor & Destructor Documentation

◆ Shape()

geo::Shape::Shape ( )

Definition at line 139 of file Shape.cpp.

◆ ~Shape()

geo::Shape::~Shape ( )
virtual

Definition at line 142 of file Shape.cpp.

Member Function Documentation

◆ clone()

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

Reimplemented in geo::HeightMap, geo::CompositeShape, geo::Octree, and geo::Box.

Definition at line 145 of file Shape.cpp.

◆ contains()

bool geo::Shape::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 in geo::Octree, geo::Box, and geo::CompositeShape.

Definition at line 229 of file Shape.cpp.

◆ empty()

virtual bool geo::Shape::empty ( ) const
inlinevirtual

empty Test whether the shape(mesh) is empty.

Returns
True if the mesh is empty

Definition at line 104 of file Shape.h.

◆ getBoundingBox()

Box geo::Shape::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 in geo::Box, and geo::CompositeShape.

Definition at line 402 of file Shape.cpp.

◆ getMaxRadius()

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

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

Returns
Maximum radius found.

Reimplemented in geo::Box, geo::Octree, and geo::CompositeShape.

Definition at line 434 of file Shape.cpp.

◆ getMesh()

const Mesh & geo::Shape::getMesh ( ) const
virtual

return the mesh defining the shape

Returns
a constant reference to the mesh of the shape

Reimplemented in geo::Octree.

Definition at line 425 of file Shape.cpp.

◆ intersect() [1/2]

bool geo::Shape::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 in geo::Octree, geo::CompositeShape, geo::Box, and geo::HeightMap.

Definition at line 149 of file Shape.cpp.

◆ intersect() [2/2]

bool geo::Shape::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 in geo::Box, and geo::CompositeShape.

Definition at line 160 of file Shape.cpp.

◆ read()

ShapePtr geo::Shape::read ( std::istream input)
static

read serialised data from an input stream and create a shape

Parameters
inputinput stream, is expected to follow the format as generated by the 'write' method
Returns
shared pointer to the created shape

Definition at line 471 of file Shape.cpp.

◆ setMesh()

void geo::Shape::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 in geo::Box, and geo::CompositeShape.

Definition at line 429 of file Shape.cpp.

◆ write()

bool geo::Shape::write ( std::ostream output) const
virtual

write, serialise the shape

Serialisation must encode enough information to reconstruct a class object using the 'read' method

Parameters
outputoutput stream
Returns
always true

Definition at line 439 of file Shape.cpp.

Friends And Related Function Documentation

◆ Importer

friend class Importer
friend

Definition at line 21 of file Shape.h.

Member Data Documentation

◆ bounding_box_cache_valid_

bool geo::Shape::bounding_box_cache_valid_
mutableprivate

Definition at line 116 of file Shape.h.

◆ bounding_box_max_cache_

Vector3 geo::Shape::bounding_box_max_cache_
mutableprivate

Definition at line 118 of file Shape.h.

◆ bounding_box_min_cache_

Vector3 geo::Shape::bounding_box_min_cache_
mutableprivate

Definition at line 117 of file Shape.h.

◆ mesh_

Mesh geo::Shape::mesh_
protected

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.

Definition at line 112 of file Shape.h.

◆ TYPE

const std::string geo::Shape::TYPE = "mesh"
static

Definition at line 98 of file Shape.h.


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