DeformableRepresentation.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_PHYSICS_DEFORMABLEREPRESENTATION_H
#define SURGSIM_PHYSICS_DEFORMABLEREPRESENTATION_H
#include <memory>
#include "SurgSim/Math/LinearSparseSolveAndInverse.h"
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/OdeEquation.h"
#include "SurgSim/Math/OdeSolver.h"
#include "SurgSim/Math/OdeState.h"
#include "SurgSim/Math/Vector.h"
#include "SurgSim/Physics/Representation.h"
namespace SurgSim
{
namespace Physics
{
class Localization;
class DeformableRepresentation :
public Representation,
public SurgSim::Math::OdeEquation
{
public:
explicit DeformableRepresentation(const std::string& name);
virtual ~DeformableRepresentation();
void resetState() override;
virtual void setInitialState(std::shared_ptr<SurgSim::Math::OdeState> initialState);
virtual const std::shared_ptr<SurgSim::Math::OdeState> getCurrentState() const;
virtual const std::shared_ptr<SurgSim::Math::OdeState> getPreviousState() const;
virtual const std::shared_ptr<SurgSim::Math::OdeState> getFinalState() const;
virtual void interpolatePreviousState(double t);
size_t getNumDofPerNode() const;
void setIntegrationScheme(SurgSim::Math::IntegrationScheme integrationScheme);
SurgSim::Math::IntegrationScheme getIntegrationScheme() const;
std::shared_ptr<SurgSim::Math::OdeSolver> getOdeSolver() const;
void setLinearSolver(SurgSim::Math::LinearSolver linearSolver);
SurgSim::Math::LinearSolver getLinearSolver() const;
virtual void addExternalGeneralizedForce(std::shared_ptr<Localization> localization,
const SurgSim::Math::Vector& generalizedForce,
const SurgSim::Math::Matrix& K = SurgSim::Math::Matrix(),
const SurgSim::Math::Matrix& D = SurgSim::Math::Matrix()) = 0;
const SurgSim::Math::Vector& getExternalGeneralizedForce() const;
const SurgSim::Math::SparseMatrix& getExternalGeneralizedStiffness() const;
const SurgSim::Math::SparseMatrix& getExternalGeneralizedDamping() const;
Math::Matrix applyCompliance(const Math::OdeState& state, const Math::Matrix& b) override;
virtual const SurgSim::Math::Matrix& getComplianceMatrix() const;
void update(double dt) override;
void afterUpdate(double dt) override;
void applyCorrection(double dt, const Eigen::VectorBlock<SurgSim::Math::Vector>& deltaVelocity) override;
void deactivateAndReset();
void setCollisionRepresentation(std::shared_ptr<SurgSim::Collision::Representation> representation) override;
void setLocalPose(const SurgSim::Math::RigidTransform3d& pose) override;
protected:
bool doInitialize() override;
bool doWakeUp() override;
virtual void transformState(std::shared_ptr<SurgSim::Math::OdeState> state,
const SurgSim::Math::RigidTransform3d& transform) = 0;
std::shared_ptr<SurgSim::Math::OdeState> m_previousState;
std::shared_ptr<SurgSim::Math::OdeState> m_currentState;
std::shared_ptr<SurgSim::Math::OdeState> m_newState;
std::shared_ptr<SurgSim::Math::OdeState> m_finalState;
bool m_hasExternalGeneralizedForce;
SurgSim::Math::Vector m_externalGeneralizedForce;
SurgSim::Math::SparseMatrix m_externalGeneralizedStiffness;
SurgSim::Math::SparseMatrix m_externalGeneralizedDamping;
bool m_previousHasExternalGeneralizedForce;
SurgSim::Math::SparseMatrix m_previousExternalGeneralizedStiffness;
SurgSim::Math::SparseMatrix m_previousExternalGeneralizedDamping;
size_t m_numDofPerNode;
SurgSim::Math::IntegrationScheme m_integrationScheme;
SurgSim::Math::LinearSolver m_linearSolver;
std::shared_ptr<SurgSim::Math::OdeSolver> m_odeSolver;
private:
DeformableRepresentation(const DeformableRepresentation&);
DeformableRepresentation& operator =(const DeformableRepresentation&);
};
}; // namespace Physics
}; // namespace SurgSim
#endif // SURGSIM_PHYSICS_DEFORMABLEREPRESENTATION_H
Representation.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Physics::DeformableRepresentation::m_previousExternalGeneralizedDamping
SurgSim::Math::SparseMatrix m_previousExternalGeneralizedDamping
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:188
SurgSim::Physics::DeformableRepresentation::transformState
virtual void transformState(std::shared_ptr< SurgSim::Math::OdeState > state, const SurgSim::Math::RigidTransform3d &transform)=0
Transform a state using a given transformation.
SurgSim::Physics::Representation
The Representation class defines the base class for all physics objects.
Definition: Representation.h:53
OdeState.h
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
SurgSim::Physics::DeformableRepresentation::getIntegrationScheme
SurgSim::Math::IntegrationScheme getIntegrationScheme() const
Gets the numerical integration scheme.
Definition: DeformableRepresentation.cpp:137
SurgSim::Physics::DeformableRepresentation
Base class for all deformable representations MassSprings, Finite Element Models,...
Definition: DeformableRepresentation.h:50
OdeSolver.h
SurgSim::Physics::DeformableRepresentation::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: DeformableRepresentation.cpp:389
SurgSim::Physics::DeformableRepresentation::m_finalState
std::shared_ptr< SurgSim::Math::OdeState > m_finalState
Last valid state (a.k.a final state)
Definition: DeformableRepresentation.h:178
SurgSim::Physics::DeformableRepresentation::m_previousExternalGeneralizedStiffness
SurgSim::Math::SparseMatrix m_previousExternalGeneralizedStiffness
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:187
SurgSim::Physics::DeformableRepresentation::m_currentState
std::shared_ptr< SurgSim::Math::OdeState > m_currentState
The currently calculated state inside the physics loop, after the whole calculation is done this will...
Definition: DeformableRepresentation.h:171
SurgSim::Math::OdeEquation
Ode equation of 2nd order of the form with for initial conditions and a set of boundary conditions...
Definition: OdeEquation.h:54
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
SurgSim::Physics::DeformableRepresentation::getExternalGeneralizedStiffness
const SurgSim::Math::SparseMatrix & getExternalGeneralizedStiffness() const
Definition: DeformableRepresentation.cpp:164
SurgSim::Physics::DeformableRepresentation::getComplianceMatrix
virtual const SurgSim::Math::Matrix & getComplianceMatrix() const
Gets the compliance matrix associated with motion.
Definition: DeformableRepresentation.cpp:191
SurgSim::Physics::DeformableRepresentation::getExternalGeneralizedForce
const SurgSim::Math::Vector & getExternalGeneralizedForce() const
Definition: DeformableRepresentation.cpp:159
SurgSim::Physics::DeformableRepresentation::setIntegrationScheme
void setIntegrationScheme(SurgSim::Math::IntegrationScheme integrationScheme)
Sets the numerical integration scheme.
Definition: DeformableRepresentation.cpp:130
SurgSim::Physics::DeformableRepresentation::applyCorrection
void applyCorrection(double dt, const Eigen::VectorBlock< SurgSim::Math::Vector > &deltaVelocity) override
Update the Representation&#39;s current position and velocity using a time interval, dt, and change in velocity, deltaVelocity.
Definition: DeformableRepresentation.cpp:254
SurgSim::Math::LinearSolver
LinearSolver
The linear numerical integration scheme supported Each Linear Solver should have its own entry in thi...
Definition: LinearSparseSolveAndInverse.h:41
SurgSim::Physics::DeformableRepresentation::m_previousState
std::shared_ptr< SurgSim::Math::OdeState > m_previousState
The previous state inside the calculation loop, this has no meaning outside of the loop...
Definition: DeformableRepresentation.h:167
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
SurgSim::Physics::DeformableRepresentation::m_previousHasExternalGeneralizedForce
bool m_previousHasExternalGeneralizedForce
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:186
SurgSim::Math::SparseMatrix
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
SurgSim::Physics::DeformableRepresentation::m_odeSolver
std::shared_ptr< SurgSim::Math::OdeSolver > m_odeSolver
Ode solver (its type depends on the numerical integration scheme)
Definition: DeformableRepresentation.h:202
SurgSim::Physics::DeformableRepresentation::addExternalGeneralizedForce
virtual void addExternalGeneralizedForce(std::shared_ptr< Localization > localization, const SurgSim::Math::Vector &generalizedForce, const SurgSim::Math::Matrix &K=SurgSim::Math::Matrix(), const SurgSim::Math::Matrix &D=SurgSim::Math::Matrix())=0
Add an external generalized force applied on a specific localization.
SurgSim::Physics::DeformableRepresentation::update
void update(double dt) override
Update the representation state to the current time step.
Definition: DeformableRepresentation.cpp:197
SurgSim::Physics::DeformableRepresentation::~DeformableRepresentation
virtual ~DeformableRepresentation()
Destructor.
Definition: DeformableRepresentation.cpp:62
SurgSim::Physics::DeformableRepresentation::interpolatePreviousState
virtual void interpolatePreviousState(double t)
Declare a new previous state by interpolating between the old previous state and the current state us...
Definition: DeformableRepresentation.cpp:405
SurgSim::Physics::DeformableRepresentation::operator=
DeformableRepresentation & operator=(const DeformableRepresentation &)
NO assignment operator.
SurgSim::Physics::DeformableRepresentation::deactivateAndReset
void deactivateAndReset()
Deactivate and call resetState.
Definition: DeformableRepresentation.cpp:276
SurgSim::Math::IntegrationScheme
IntegrationScheme
The diverse numerical integration scheme supported Each Ode Solver should have its own entry in this ...
Definition: OdeSolver.h:36
SurgSim::Physics::DeformableRepresentation::m_numDofPerNode
size_t m_numDofPerNode
Number of degrees of freedom per node (varies per deformable model)
Definition: DeformableRepresentation.h:193
SurgSim::Physics::DeformableRepresentation::DeformableRepresentation
DeformableRepresentation(const std::string &name)
Constructor.
Definition: DeformableRepresentation.cpp:47
SurgSim::Physics::DeformableRepresentation::m_externalGeneralizedDamping
SurgSim::Math::SparseMatrix m_externalGeneralizedDamping
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:185
SurgSim::Physics::DeformableRepresentation::m_externalGeneralizedStiffness
SurgSim::Math::SparseMatrix m_externalGeneralizedStiffness
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:184
SurgSim::Physics::DeformableRepresentation::getOdeSolver
std::shared_ptr< SurgSim::Math::OdeSolver > getOdeSolver() const
Definition: DeformableRepresentation.cpp:142
SurgSim::Physics::DeformableRepresentation::getNumDofPerNode
size_t getNumDofPerNode() const
Gets the number of degrees of freedom per node.
Definition: DeformableRepresentation.cpp:125
SurgSim::Physics::DeformableRepresentation::applyCompliance
Math::Matrix applyCompliance(const Math::OdeState &state, const Math::Matrix &b) override
Calculate the product C.b where C is the compliance matrix with boundary conditions applied...
Definition: DeformableRepresentation.cpp:174
Matrix.h
Definitions of small fixed-size square matrix types.
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Physics::DeformableRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: DeformableRepresentation.cpp:313
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Physics::DeformableRepresentation::setLocalPose
void setLocalPose(const SurgSim::Math::RigidTransform3d &pose) override
Set the pose of the representation with respect to the Scene Element.
Definition: DeformableRepresentation.cpp:77
SurgSim::Physics::DeformableRepresentation::getPreviousState
virtual const std::shared_ptr< SurgSim::Math::OdeState > getPreviousState() const
Return the previous state of the deformable representation.
Definition: DeformableRepresentation.cpp:115
SurgSim::Physics::DeformableRepresentation::m_integrationScheme
SurgSim::Math::IntegrationScheme m_integrationScheme
Numerical Integration scheme (dynamic explicit/implicit solver)
Definition: DeformableRepresentation.h:196
SurgSim::Physics::DeformableRepresentation::setLinearSolver
void setLinearSolver(SurgSim::Math::LinearSolver linearSolver)
Sets the linear algebraic solver.
Definition: DeformableRepresentation.cpp:147
SurgSim::Physics::DeformableRepresentation::getCurrentState
virtual const std::shared_ptr< SurgSim::Math::OdeState > getCurrentState() const
Return the current state of the deformable representation.
Definition: DeformableRepresentation.cpp:110
SurgSim::Physics::DeformableRepresentation::resetState
void resetState() override
Reset the representation to its initial/default state.
Definition: DeformableRepresentation.cpp:66
SurgSim::Physics::DeformableRepresentation::getExternalGeneralizedDamping
const SurgSim::Math::SparseMatrix & getExternalGeneralizedDamping() const
Definition: DeformableRepresentation.cpp:169
SurgSim::Physics::DeformableRepresentation::m_hasExternalGeneralizedForce
bool m_hasExternalGeneralizedForce
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:182
SurgSim::Physics::DeformableRepresentation::getLinearSolver
SurgSim::Math::LinearSolver getLinearSolver() const
Gets the linear algebraic solver.
Definition: DeformableRepresentation.cpp:154
LinearSparseSolveAndInverse.h
SurgSim::Physics::DeformableRepresentation::getFinalState
virtual const std::shared_ptr< SurgSim::Math::OdeState > getFinalState() const
Return the final state of the deformable representation.
Definition: DeformableRepresentation.cpp:120
SurgSim::Physics::DeformableRepresentation::afterUpdate
void afterUpdate(double dt) override
Postprocessing done after the update call This needs to be called from the outside usually from a Com...
Definition: DeformableRepresentation.cpp:228
SurgSim::Physics::DeformableRepresentation::m_externalGeneralizedForce
SurgSim::Math::Vector m_externalGeneralizedForce
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:183
SurgSim::Physics::DeformableRepresentation::setCollisionRepresentation
void setCollisionRepresentation(std::shared_ptr< SurgSim::Collision::Representation > representation) override
Set the collision representation for this physics representation, when the collision object is involv...
Definition: DeformableRepresentation.cpp:287
SurgSim::Physics::DeformableRepresentation::m_linearSolver
SurgSim::Math::LinearSolver m_linearSolver
Linear algebraic solver used.
Definition: DeformableRepresentation.h:199
SurgSim::Physics::DeformableRepresentation::m_newState
std::shared_ptr< SurgSim::Math::OdeState > m_newState
New state is a temporary variable to store the newly computed state.
Definition: DeformableRepresentation.h:174
SurgSim::Physics::DeformableRepresentation::setInitialState
virtual void setInitialState(std::shared_ptr< SurgSim::Math::OdeState > initialState)
Initialize the state variables to initialState.
Definition: DeformableRepresentation.cpp:85
OdeEquation.h