opensurgsim
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SurgSim::Math::MeshShape Class Reference

Mesh shape: shape made of a triangle mesh The triangle mesh needs to be watertight to produce valid volume, center and second moment of volume. More...

#include <MeshShape.h>

Inheritance diagram for SurgSim::Math::MeshShape:
SurgSim::Math::VerticesShape SurgSim::DataStructures::TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData > SurgSim::Math::Shape SurgSim::DataStructures::Vertices< SurgSim::DataStructures::EmptyData > SurgSim::Framework::Asset SurgSim::Framework::Accessible SurgSim::Framework::FactoryBase< Shape > SurgSim::Framework::Accessible SurgSim::Framework::FactoryBase< Asset > SurgSim::Math::SurfaceMeshShape

Public Member Functions

 MeshShape ()
 Constructor.
 
 MeshShape (const MeshShape &other)
 Copy constructor. More...
 
template<class V , class E , class T >
 MeshShape (const SurgSim::DataStructures::TriangleMesh< V, E, T > &other)
 Copy constructor when the template data is a different type. More...
 
 SURGSIM_CLASSNAME (SurgSim::Math::MeshShape)
 
int getType () const override
 
const SurgSim::Math::Vector3dgetNormal (size_t triangleId) const
 Get normal for triangle. More...
 
double getVolume () const override
 Get the volume of the shape. More...
 
Vector3d getCenter () const override
 Get the volumetric center of the shape. More...
 
Matrix33d getSecondMomentOfVolume () const override
 Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix. More...
 
std::shared_ptr< ShapegetTransformed (const RigidTransform3d &pose) const override
 Get a copy of this shape with an applied rigid transform. More...
 
const std::shared_ptr< const SurgSim::DataStructures::AabbTreegetAabbTree () const
 Get the AabbTree. More...
 
bool isValid () const override
 Check if the shape is valid. More...
 
void setPose (const RigidTransform3d &pose) override
 Set the pose on a transformable shape. More...
 
void buildAabbTree ()
 Build the AabbTree, which is an axis-aligned bounding box r-tree used to accelerate spatial searches.
 
void updateAabbTree ()
 Update the AabbTree, this will only update the bounding boxes for the triangles, without rebalancing the tree do this for smaller changes as it is much faster than building the tree.
 
bool calculateNormals ()
 Calculate normals for all triangles. More...
 
void updateShape () override
 Update the internals of a transformable shape.
 
void updateShapePartial () override
 Update some of the internals of a transformable shape. More...
 
- Public Member Functions inherited from SurgSim::Math::VerticesShape
bool isTransformable () const override
 
void setInitialVertices (const DataStructures::Vertices< DataStructures::EmptyData > &vertices)
 Set the initial Vertices. More...
 
void setInitialVertices (DataStructures::Vertices< DataStructures::EmptyData > &&vertices)
 Set the initial Vertices via r-value. More...
 
const DataStructures::Vertices< DataStructures::EmptyData > & getInitialVertices () const
 Get the initial Vertices. More...
 
- Public Member Functions inherited from SurgSim::Math::Shape
 Shape ()
 Constructor.
 
virtual ~Shape ()
 Destructor.
 
virtual std::string getClassName () const
 Get class name.
 
virtual const Math::Aabbd & getBoundingBox () const
 
- Public Member Functions inherited from SurgSim::Framework::Accessible
 Accessible ()
 Default Constructor.
 
 ~Accessible ()
 Destructor.
 
template<class T >
getValue (const std::string &name) const
 Retrieves the value with the name by executing the getter if it is found and tries to convert it to the given type. More...
 
boost::any getValue (const std::string &name) const
 Retrieves the value with the name by executing the getter if it is found. More...
 
template<class T >
bool getValue (const std::string &name, T *value) const
 Retrieves the value with the name by executing the getter if it is found, and converts it to the type of the output parameter. More...
 
void setValue (const std::string &name, const boost::any &value)
 Sets a value of a property that has setter. More...
 
bool isReadable (const std::string &name) const
 Check whether a property is readable. More...
 
bool isWriteable (const std::string &name) const
 Check whether a property is writable. More...
 
void setGetter (const std::string &name, GetterType func)
 Sets a getter for a given property. More...
 
void setSetter (const std::string &name, SetterType func)
 Sets a setter for a given property. More...
 
void setAccessors (const std::string &name, GetterType getter, SetterType setter)
 Sets the accessors getter and setter in one function. More...
 
void removeAccessors (const std::string &name)
 Removes all the accessors (getter and setter) for a given property. More...
 
void forwardProperty (const std::string &name, const Accessible &target, const std::string &targetProperty)
 Adds a property with the given name that uses the targets accessors, in effect forwarding the value to the target. More...
 
void setSerializable (const std::string &name, EncoderType encoder, DecoderType decoder)
 Sets the functions used to convert data from and to a YAML::Node. More...
 
void setDecoder (const std::string &name, DecoderType decoder)
 Sets the functions used to convert data from a YAML::Node. More...
 
YAML::Node encode () const
 Encode this Accessible to a YAML::Node. More...
 
void decode (const YAML::Node &node, const std::vector< std::string > &ignoredProperties=std::vector< std::string >())
 Decode this Accessible from a YAML::Node, will throw an exception if the data type cannot be converted. More...
 
std::vector< std::string > getProperties ()
 
template<>
boost::any getValue (const std::string &name) const
 
- Public Member Functions inherited from SurgSim::DataStructures::TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData >
 TriangleMesh ()
 Constructor. The mesh is initially empty (no vertices, no edges, no triangles).
 
 TriangleMesh (const TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData > &other)
 Copy constructor when the template data is the same type. More...
 
 TriangleMesh (const TriangleMesh< V, E, T > &other)
 Copy constructor when the template data is a different type. More...
 
 TriangleMesh (TriangleMesh &&other)
 Move Constructor. More...
 
virtual ~TriangleMesh ()
 Destructor.
 
TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData > & operator= (const TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData > &other)
 Copy Assignment. More...
 
TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData > & operator= (TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData > &&other)
 Move Assignment. More...
 
std::string getClassName () const override
 Support serialization with a classname. More...
 
size_t addEdge (const EdgeType &edge)
 Adds an edge to the mesh. More...
 
size_t addTriangle (const TriangleType &triangle)
 Adds a triangle to the mesh. More...
 
size_t getNumEdges () const
 Get the number of edges. More...
 
size_t getNumTriangles () const
 Get the number of triangles. More...
 
const std::vector< EdgeType > & getEdges () const
 Retrieve all edges. More...
 
std::vector< EdgeType > & getEdges ()
 Retrieve all edges (non const version) More...
 
const std::vector< TriangleType > & getTriangles () const
 Retrieve all triangles. More...
 
std::vector< TriangleType > & getTriangles ()
 Retrieve all triangles (non const version) More...
 
const EdgeTypegetEdge (size_t id) const
 Retrieve a specific edge. More...
 
EdgeTypegetEdge (size_t id)
 Retrieve a specific edge (non const version) More...
 
std::array< SurgSim::Math::Vector3d, 2 > getEdgePositions (size_t id) const
 Returns an array of the edge's vertices' positions. More...
 
const TriangleTypegetTriangle (size_t id) const
 Retrieve a specific triangle. More...
 
TriangleTypegetTriangle (size_t id)
 Retrieve a specific triangle (non const version) More...
 
void removeTriangle (size_t id)
 Marks a triangle as invalid, the triangle cannot be accessed via getTriangle anymore. More...
 
std::array< SurgSim::Math::Vector3d, 3 > getTrianglePositions (size_t id) const
 Returns an array of the triangle's vertices' positions. More...
 
bool isValid () const
 Test if the TriangleMesh is valid (valid vertex Ids used in all MeshElements) More...
 
void save (const std::string &fileName)
 Save the triangle mesh in the ply format. More...
 
- Public Member Functions inherited from SurgSim::DataStructures::Vertices< SurgSim::DataStructures::EmptyData >
 Vertices ()
 Constructor.
 
 Vertices (const Vertices< V > &other)
 Copy constructor when the template data is a different type In this case, no data will be copied. More...
 
Vertices< SurgSim::DataStructures::EmptyData > & operator= (const Vertices< V > &other)
 Assignment when the template data is a different type In this case, no data will be copied. More...
 
virtual ~Vertices ()
 Destructor.
 
void clear ()
 Clear mesh to return to an empty state (no vertices).
 
bool update ()
 Performs any updates that are required when the vertices are modified. More...
 
size_t addVertex (const VertexType &vertex)
 Adds a vertex to the mesh. More...
 
size_t getNumVertices () const
 Returns the number of vertices in this mesh.
 
const VertexTypegetVertex (size_t id) const
 Returns the specified vertex.
 
VertexTypegetVertex (size_t id)
 Returns the specified vertex (non const version).
 
const std::vector< VertexType > & getVertices () const
 Returns a vector containing the position of each vertex.
 
std::vector< VertexType > & getVertices ()
 Returns a vector containing the position of each vertex (non const version).
 
void setVertexPosition (size_t id, const SurgSim::Math::Vector3d &position)
 Sets the position of a vertex. More...
 
const SurgSim::Math::Vector3dgetVertexPosition (size_t id) const
 Returns the position of a vertex. More...
 
void setVertexPositions (const std::vector< SurgSim::Math::Vector3d > &positions, bool doUpdate=true)
 Sets the position of each vertex. More...
 
void transform (const Math::RigidTransform3d &pose)
 Apply a rigid transform to each vertex. More...
 
bool operator== (const Vertices &mesh) const
 Compares the mesh with another one (equality) More...
 
bool operator!= (const Vertices &mesh) const
 Compares the mesh with another one (inequality) More...
 
- Public Member Functions inherited from SurgSim::Framework::Asset
 Asset ()
 Constructor.
 
 Asset (const Asset &rhs)
 Copy Constructor.
 
virtual ~Asset ()
 Destructor.
 
void load (const std::string &fileName, const SurgSim::Framework::ApplicationData &data)
 Load a file with given name using 'data' as look up path(s). More...
 
void load (const std::string &fileName)
 Overloaded function using SurgSim::Framework::Runtime::getApplicationData() as look up path(s). More...
 
std::string getFileName () const
 Return the name of file loaded by this class. More...
 

Protected Member Functions

bool doUpdate () override
 Performs any updates that are required when the vertices are modified. More...
 
bool doLoad (const std::string &fileName) override
 Derived classes will overwrite this method to do actual loading. More...
 
virtual void computeVolumeIntegrals ()
 Compute useful volume integrals based on the triangle mesh, which are used to get the volume , center and second moment of volume. More...
 
- Protected Member Functions inherited from SurgSim::DataStructures::TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData >
std::string m_className
 
std::string m_className
 
std::string m_className
 
virtual void doClearEdges ()
 Remove all edges from the mesh.
 
virtual void doClearTriangles ()
 Remove all triangles from the mesh.
 
virtual bool isEqual (const Vertices< SurgSim::DataStructures::EmptyData > &mesh) const
 Internal comparison of meshes of the same type: returns true if equal, false if not equal. More...
 
bool doLoad (const std::string &fileName) override
 Derived classes will overwrite this method to do actual loading. More...
 
- Protected Member Functions inherited from SurgSim::DataStructures::Vertices< SurgSim::DataStructures::EmptyData >
virtual void doClearVertices ()
 Remove all vertices from the mesh.
 
virtual bool isEqual (const Vertices &mesh) const
 Internal comparison of meshes of the same type: returns true if equal, false if not equal. More...
 

Protected Attributes

SurgSim::Math::Vector3d m_center
 Center (considering a uniform distribution in the mesh volume)
 
double m_volume
 Volume (in m^-3)
 
SurgSim::Math::Matrix33d m_secondMomentOfVolume
 Second moment of volume.
 
- Protected Attributes inherited from SurgSim::Math::VerticesShape
DataStructures::Vertices< DataStructures::EmptyDatam_initialVertices
 The initial vertex positions.
 
- Protected Attributes inherited from SurgSim::Math::Shape
Math::Aabbd m_aabb
 

Additional Inherited Members

- Public Types inherited from SurgSim::Math::Shape
typedef ::SurgSim::Math::Vector3d Vector3d
 
typedef ::SurgSim::Math::Matrix33d Matrix33d
 
- Public Types inherited from SurgSim::Framework::Accessible
typedef std::function< boost::any(void)> GetterType
 
typedef std::function< void(boost::any)> SetterType
 
typedef std::function< YAML::Node(void)> EncoderType
 
typedef std::function< void(const YAML::Node *)> DecoderType
 
- Public Types inherited from SurgSim::Framework::FactoryBase< Shape >
typedef ObjectFactory< Shape > FactoryType
 
- Public Types inherited from SurgSim::DataStructures::TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData >
typedef MeshElement< 2, SurgSim::DataStructures::EmptyDataEdgeType
 Edge type for convenience (Ids of the 2 vertices)
 
typedef MeshElement< 3, SurgSim::DataStructures::NormalDataTriangleType
 Triangle type for convenience (Ids of the 3 vertices)
 
- Public Types inherited from SurgSim::DataStructures::Vertices< SurgSim::DataStructures::EmptyData >
typedef Vertex< SurgSim::DataStructures::EmptyDataVertexType
 Vertex type for convenience.
 
- Public Types inherited from SurgSim::Framework::FactoryBase< Asset >
typedef ObjectFactory< AssetFactoryType
 
- Static Public Member Functions inherited from SurgSim::Framework::FactoryBase< Shape >
static FactoryTypegetFactory ()
 
- Static Public Member Functions inherited from SurgSim::Framework::FactoryBase< Asset >
static FactoryTypegetFactory ()
 
- Static Protected Attributes inherited from SurgSim::DataStructures::TriangleMesh< SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::EmptyData, SurgSim::DataStructures::NormalData >
static std::string m_className
 

Detailed Description

Mesh shape: shape made of a triangle mesh The triangle mesh needs to be watertight to produce valid volume, center and second moment of volume.

If it is not the case and you need valid geometric properties, use SurfaceMeshShape instead. Various geometrical properties (volume based) are computed from the triangle mesh using David Eberly's work (http://www.geometrictools.com/Documentation/PolyhedralMassProperties.pdf) which is improving Brian Mirtich previous work (http://www.cs.berkeley.edu/~jfc/mirtich/massProps.html) by making the assumption that the polyhedral mesh is composed of triangles.

Note
The internal mesh should not be modified, otherwise the geometric properties will be invalid.
Practical use cases:
* Fixed/Rigid object, the mesh will not change anyway.
* Deformable object, the mesh will be updated, but the geometric properties will not be used.
See also
SurfaceMeshShape

Constructor & Destructor Documentation

§ MeshShape() [1/2]

SurgSim::Math::MeshShape::MeshShape ( const MeshShape other)
explicit

Copy constructor.

Parameters
otherThe MeshShape to be copied from

§ MeshShape() [2/2]

template<class V , class E , class T >
SurgSim::Math::MeshShape::MeshShape ( const SurgSim::DataStructures::TriangleMesh< V, E, T > &  other)
explicit

Copy constructor when the template data is a different type.

Template Parameters
VertexDataType of extra data stored in each vertex
EdgeDataType of extra data stored in each edge
TriangleDataType of extra data stored in each triangle
Parameters
otherThe mesh to be copied from. Vertex, edge and triangle data will not be copied

Member Function Documentation

§ calculateNormals()

bool SurgSim::Math::MeshShape::calculateNormals ( )

Calculate normals for all triangles.

Note
Normals will be normalized.
Returns
true on success, or false if any triangle has an indeterminate normal.

§ computeVolumeIntegrals()

void SurgSim::Math::MeshShape::computeVolumeIntegrals ( )
protectedvirtual

Compute useful volume integrals based on the triangle mesh, which are used to get the volume , center and second moment of volume.

Reimplemented in SurgSim::Math::SurfaceMeshShape.

§ doLoad()

bool SurgSim::Math::MeshShape::doLoad ( const std::string &  filePath)
overrideprotectedvirtual

Derived classes will overwrite this method to do actual loading.

Note
This method is not required to do any check on the validity or the existence of the file.
Parameters
filePathAbsolute path to the file.
Returns
True if loading is successful; Otherwise, false.

Implements SurgSim::Framework::Asset.

§ doUpdate()

bool SurgSim::Math::MeshShape::doUpdate ( )
overrideprotectedvirtual

Performs any updates that are required when the vertices are modified.

Override this method to implement update functionality. For example, this could be overridden to calculate normals for each Vertex.

Returns
true on success.

Reimplemented from SurgSim::DataStructures::Vertices< SurgSim::DataStructures::EmptyData >.

§ getAabbTree()

const std::shared_ptr< const SurgSim::DataStructures::AabbTree > SurgSim::Math::MeshShape::getAabbTree ( ) const

Get the AabbTree.

Returns
The object's associated AabbTree

§ getCenter()

SurgSim::Math::Vector3d SurgSim::Math::MeshShape::getCenter ( ) const
overridevirtual

Get the volumetric center of the shape.

Returns
The center of the shape

Implements SurgSim::Math::Shape.

§ getNormal()

const SurgSim::Math::Vector3d & SurgSim::Math::MeshShape::getNormal ( size_t  triangleId) const

Get normal for triangle.

Parameters
triangleIdThe triangle to get normal.
Returns
The normal for the triangle with given ID.

§ getSecondMomentOfVolume()

SurgSim::Math::Matrix33d SurgSim::Math::MeshShape::getSecondMomentOfVolume ( ) const
overridevirtual

Get the second central moment of the volume, commonly used to calculate the moment of inertia matrix.

Returns
The 3x3 symmetric second moment matrix

Implements SurgSim::Math::Shape.

§ getTransformed()

std::shared_ptr< Shape > SurgSim::Math::MeshShape::getTransformed ( const RigidTransform3d pose) const
overridevirtual

Get a copy of this shape with an applied rigid transform.

Parameters
poseThe pose to transform the shape by
Returns
the posed shape

Reimplemented from SurgSim::Math::Shape.

§ getType()

int SurgSim::Math::MeshShape::getType ( ) const
overridevirtual
Returns
the type of shape

Implements SurgSim::Math::Shape.

Reimplemented in SurgSim::Math::SurfaceMeshShape.

§ getVolume()

double SurgSim::Math::MeshShape::getVolume ( ) const
overridevirtual

Get the volume of the shape.

Returns
The volume of the shape (in m-3)

Implements SurgSim::Math::Shape.

§ isValid()

bool SurgSim::Math::MeshShape::isValid ( ) const
overridevirtual

Check if the shape is valid.

Returns
True if shape is valid; Otherwise, false.

Implements SurgSim::Math::Shape.

Reimplemented in SurgSim::Math::SurfaceMeshShape.

§ setPose()

void SurgSim::Math::MeshShape::setPose ( const RigidTransform3d pose)
overridevirtual

Set the pose on a transformable shape.

Parameters
poseThe pose to transform the shape by.

Reimplemented from SurgSim::Math::Shape.

§ updateShapePartial()

void SurgSim::Math::MeshShape::updateShapePartial ( )
overridevirtual

Update some of the internals of a transformable shape.

Only called if the AABB has not changed much.

Reimplemented from SurgSim::Math::Shape.


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