opensurgsim
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
SurgSim::Physics::MassSpringModel Class Reference

Base class for a data structure for holding MassSpring mesh data. More...

#include <MassSpringModel.h>

Inheritance diagram for SurgSim::Physics::MassSpringModel:
SurgSim::DataStructures::Vertices< Mass > SurgSim::Framework::Asset SurgSim::Framework::Accessible SurgSim::Framework::FactoryBase< Asset >

Public Member Functions

 MassSpringModel ()
 Default constructor.
 
 SURGSIM_CLASSNAME (SurgSim::Physics::MassSpringModel)
 
void addMass (const std::shared_ptr< Mass > mass)
 Adds a mass. More...
 
void addSpring (const std::shared_ptr< Spring > spring)
 Adds a spring, and sets its rest length. More...
 
size_t getNumMasses () const
 Gets the number of masses. More...
 
size_t getNumSprings () const
 Gets the number of springs. More...
 
const std::vector< std::shared_ptr< Mass > > & getMasses () const
 Retrieves the masses.
 
const std::vector< std::shared_ptr< Spring > > & getSprings () const
 Retrieves a given spring from its id. More...
 
const std::shared_ptr< Mass > & getMass (size_t nodeId) const
 Retrieves the mass of a given node. More...
 
const std::shared_ptr< Spring > & getSpring (size_t springId) const
 Retrieves a given spring from its id. More...
 
size_t addBoundaryCondition (size_t boundaryCondition)
 Add boundary condition to mesh. More...
 
const std::vector< size_t > & getBoundaryConditions () const
 Gets entire vector of boundary conditions. More...
 
std::vector< size_t > & getBoundaryConditions ()
 Gets entire vector of boundary conditions (non-const) More...
 
size_t getBoundaryCondition (size_t id) const
 Retrieves a specific boundary condition. More...
 
size_t addElement (const std::vector< size_t > &nodeIds)
 Stores an element's node ids, e.g., for a 2d shape this may store triangle nodes. More...
 
const std::vector< size_t > & getNodeIds (size_t index) const
 Get an element's node ids. More...
 
size_t getNumElements () const
 
size_t getNumNodesPerElement () const
 
void setRadius (double radius)
 
const DataStructures::OptionalValue< double > & getRadius () const
 
void setThickness (double thickness)
 
const DataStructures::OptionalValue< double > & getThickness () const
 
bool save (const std::string &fileName, double physicsLength=0.0) const
 Save the current MassSpring mesh to a ply file. More...
 
- Public Member Functions inherited from SurgSim::DataStructures::Vertices< Mass >
 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< Mass > & 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...
 
virtual std::string getClassName () const =0
 Support serialization with a classname. More...
 
- 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
 

Protected Member Functions

bool doLoad (const std::string &filePath) override
 Derived classes will overwrite this method to do actual loading. More...
 
- Protected Member Functions inherited from SurgSim::DataStructures::Vertices< Mass >
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

std::vector< std::shared_ptr< Mass > > m_masses
 Masses.
 
std::vector< std::shared_ptr< Spring > > m_springs
 Springs.
 
std::vector< size_t > m_boundaryConditions
 Vector of vertex ids that have boundary conditions.
 
std::vector< std::vector< size_t > > m_nodeIds
 The node ids for each element, e.g., for triangles it contains the three node ids for each triangle.
 
DataStructures::OptionalValue< double > m_radius
 The radius, if any.
 
DataStructures::OptionalValue< double > m_thickness
 The thickness, if any.
 

Additional Inherited Members

- Public Types inherited from SurgSim::DataStructures::Vertices< Mass >
typedef Vertex< Mass > VertexType
 Vertex type for convenience.
 
- 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< Asset >
typedef ObjectFactory< AssetFactoryType
 
- Static Public Member Functions inherited from SurgSim::Framework::FactoryBase< Asset >
static FactoryTypegetFactory ()
 

Detailed Description

Base class for a data structure for holding MassSpring mesh data.

Member Function Documentation

§ addBoundaryCondition()

size_t SurgSim::Physics::MassSpringModel::addBoundaryCondition ( size_t  boundaryCondition)

Add boundary condition to mesh.

Parameters
boundaryConditionA vertex id that has a boundary condition
Returns
The new size of the vector of boundary conditions

§ addElement()

size_t SurgSim::Physics::MassSpringModel::addElement ( const std::vector< size_t > &  nodeIds)

Stores an element's node ids, e.g., for a 2d shape this may store triangle nodes.

Parameters
idsThe vector of node ids (i.e., mass ids) for the new element.
Returns
The new size of the vector of elements.

§ addMass()

void SurgSim::Physics::MassSpringModel::addMass ( const std::shared_ptr< Mass mass)

Adds a mass.

Parameters
massThe mass to add to the representation
Note
Masses are kept in an ordered list, giving them an index
This mass will be associated with the node of same index in any associated OdeState

§ addSpring()

void SurgSim::Physics::MassSpringModel::addSpring ( const std::shared_ptr< Spring spring)

Adds a spring, and sets its rest length.

Parameters
springThe spring to add to the representation

§ doLoad()

bool SurgSim::Physics::MassSpringModel::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.

§ getBoundaryCondition()

size_t SurgSim::Physics::MassSpringModel::getBoundaryCondition ( size_t  id) const

Retrieves a specific boundary condition.

Parameters
idThe id of the boundary condition in the vector
Returns
The vertex id which has a boundary condition

§ getBoundaryConditions() [1/2]

const std::vector< size_t > & SurgSim::Physics::MassSpringModel::getBoundaryConditions ( ) const

Gets entire vector of boundary conditions.

Returns
A vector of boundary conditions

§ getBoundaryConditions() [2/2]

std::vector< size_t > & SurgSim::Physics::MassSpringModel::getBoundaryConditions ( )

Gets entire vector of boundary conditions (non-const)

Returns
A vector of boundary conditions

§ getMass()

const std::shared_ptr< Mass > & SurgSim::Physics::MassSpringModel::getMass ( size_t  nodeId) const

Retrieves the mass of a given node.

Parameters
nodeIdThe node id for which the mass is requested
Returns
the mass attribute of a node
Note
Out of range nodeId will raise an exception

§ getNodeIds()

const std::vector< size_t > & SurgSim::Physics::MassSpringModel::getNodeIds ( size_t  index) const

Get an element's node ids.

Parameters
indexThe index of the element.
Returns
The vector of node ids.

§ getNumElements()

size_t SurgSim::Physics::MassSpringModel::getNumElements ( ) const
Returns
The number of elements.

§ getNumMasses()

size_t SurgSim::Physics::MassSpringModel::getNumMasses ( ) const

Gets the number of masses.

Returns
the number of masses

§ getNumNodesPerElement()

size_t SurgSim::Physics::MassSpringModel::getNumNodesPerElement ( ) const
Returns
The number of nodes per element.

§ getNumSprings()

size_t SurgSim::Physics::MassSpringModel::getNumSprings ( ) const

Gets the number of springs.

Returns
the number of springs

§ getRadius()

const DataStructures::OptionalValue< double > & SurgSim::Physics::MassSpringModel::getRadius ( ) const
Returns
The radius.

§ getSpring()

const std::shared_ptr< Spring > & SurgSim::Physics::MassSpringModel::getSpring ( size_t  springId) const

Retrieves a given spring from its id.

Parameters
springIdThe spring id for which the spring is requested
Returns
the spring for the given springId
Note
Out of range springId will raise an exception

§ getSprings()

const std::vector< std::shared_ptr< Spring > > & SurgSim::Physics::MassSpringModel::getSprings ( ) const

Retrieves a given spring from its id.

Parameters
springIdThe spring id for which the spring is requested
Returns
the spring for the given springId
Note
The spring is returned with read/write access
Out of range springId will raise an exception

§ getThickness()

const DataStructures::OptionalValue< double > & SurgSim::Physics::MassSpringModel::getThickness ( ) const
Returns
The thickness.

§ save()

bool SurgSim::Physics::MassSpringModel::save ( const std::string &  fileName,
double  physicsLength = 0.0 
) const

Save the current MassSpring mesh to a ply file.

See MassSpringPlyReaderDelegate for the file structure.

Parameters
fileNameName of the file for writing.
physicsLengthThe radius or thickness (for 2 or 3-node elements), if not already in the MassSpringModel.
Returns
true if the file was written successfully.

§ setRadius()

void SurgSim::Physics::MassSpringModel::setRadius ( double  radius)
Parameters
Theradius to set.

§ setThickness()

void SurgSim::Physics::MassSpringModel::setThickness ( double  thickness)
Parameters
Thethickness to set.

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