DeformableRepresentation.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
18 
19 #ifndef SURGSIM_PHYSICS_DEFORMABLEREPRESENTATION_H
20 #define SURGSIM_PHYSICS_DEFORMABLEREPRESENTATION_H
21 
22 #include <memory>
23 
25 #include "SurgSim/Math/Matrix.h"
27 #include "SurgSim/Math/OdeSolver.h"
28 #include "SurgSim/Math/OdeState.h"
29 #include "SurgSim/Math/Vector.h"
31 
32 namespace SurgSim
33 {
34 
35 namespace Physics
36 {
37 
38 class Localization;
39 
51  public Representation,
53 {
54 public:
57  explicit DeformableRepresentation(const std::string& name);
58 
60  virtual ~DeformableRepresentation();
61 
62  void resetState() override;
63 
66  virtual void setInitialState(std::shared_ptr<SurgSim::Math::OdeState> initialState);
67 
70  virtual const std::shared_ptr<SurgSim::Math::OdeState> getCurrentState() const;
71 
74  virtual const std::shared_ptr<SurgSim::Math::OdeState> getPreviousState() const;
75 
78  virtual const std::shared_ptr<SurgSim::Math::OdeState> getFinalState() const;
79 
83  virtual void interpolatePreviousState(double t);
84 
87  size_t getNumDofPerNode() const;
88 
93 
98 
101  std::shared_ptr<SurgSim::Math::OdeSolver> getOdeSolver() const;
102 
106  void setLinearSolver(SurgSim::Math::LinearSolver linearSolver);
107 
112 
118  virtual void addExternalGeneralizedForce(std::shared_ptr<Localization> localization,
119  const SurgSim::Math::Vector& generalizedForce,
122 
125 
128 
131 
132  Math::Matrix applyCompliance(const Math::OdeState& state, const Math::Matrix& b) override;
133 
135  virtual const SurgSim::Math::Matrix& getComplianceMatrix() const;
136 
137  void update(double dt) override;
138 
139  void afterUpdate(double dt) override;
140 
141  void applyCorrection(double dt, const Eigen::VectorBlock<SurgSim::Math::Vector>& deltaVelocity) override;
142 
144  void deactivateAndReset();
145 
150  void setCollisionRepresentation(std::shared_ptr<SurgSim::Collision::Representation> representation) override;
151 
152  void setLocalPose(const SurgSim::Math::RigidTransform3d& pose) override;
153 
154 
155 
156 protected:
157  bool doInitialize() override;
158  bool doWakeUp() override;
159 
163  virtual void transformState(std::shared_ptr<SurgSim::Math::OdeState> state,
164  const SurgSim::Math::RigidTransform3d& transform) = 0;
165 
167  std::shared_ptr<SurgSim::Math::OdeState> m_previousState;
168 
171  std::shared_ptr<SurgSim::Math::OdeState> m_currentState;
172 
174  std::shared_ptr<SurgSim::Math::OdeState> m_newState;
175 
178  std::shared_ptr<SurgSim::Math::OdeState> m_finalState;
179 
190 
194 
197 
200 
202  std::shared_ptr<SurgSim::Math::OdeSolver> m_odeSolver;
203 
204 private:
207 
210 };
211 
212 }; // namespace Physics
213 
214 }; // namespace SurgSim
215 
216 #endif // SURGSIM_PHYSICS_DEFORMABLEREPRESENTATION_H
217 
218 
219 
LinearSparseSolveAndInverse.h
SurgSim::Physics::DeformableRepresentation
Base class for all deformable representations MassSprings, Finite Element Models,....
Definition: DeformableRepresentation.h:50
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::DeformableRepresentation::getExternalGeneralizedForce
const SurgSim::Math::Vector & getExternalGeneralizedForce() const
Definition: DeformableRepresentation.cpp:159
SurgSim::Physics::DeformableRepresentation::m_previousHasExternalGeneralizedForce
bool m_previousHasExternalGeneralizedForce
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:186
SurgSim::Physics::DeformableRepresentation::m_integrationScheme
SurgSim::Math::IntegrationScheme m_integrationScheme
Numerical Integration scheme (dynamic explicit/implicit solver)
Definition: DeformableRepresentation.h:196
Vector.h
SurgSim::Math::OdeState
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
OdeState.h
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_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::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_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::getComplianceMatrix
virtual const SurgSim::Math::Matrix & getComplianceMatrix() const
Gets the compliance matrix associated with motion.
Definition: DeformableRepresentation.cpp:191
SurgSim::Physics::DeformableRepresentation::getIntegrationScheme
SurgSim::Math::IntegrationScheme getIntegrationScheme() const
Gets the numerical integration scheme.
Definition: DeformableRepresentation.cpp:137
SurgSim::Physics::DeformableRepresentation::getLinearSolver
SurgSim::Math::LinearSolver getLinearSolver() const
Gets the linear algebraic solver.
Definition: DeformableRepresentation.cpp:154
SurgSim::Physics::DeformableRepresentation::update
void update(double dt) override
Update the representation state to the current time step.
Definition: DeformableRepresentation.cpp:197
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::setIntegrationScheme
void setIntegrationScheme(SurgSim::Math::IntegrationScheme integrationScheme)
Sets the numerical integration scheme.
Definition: DeformableRepresentation.cpp:130
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
Matrix.h
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::Representation
The Representation class defines the base class for all physics objects.
Definition: Representation.h:53
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
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::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::getOdeSolver
std::shared_ptr< SurgSim::Math::OdeSolver > getOdeSolver() const
Definition: DeformableRepresentation.cpp:142
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_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::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::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::Physics::DeformableRepresentation::DeformableRepresentation
DeformableRepresentation(const std::string &name)
Constructor.
Definition: DeformableRepresentation.cpp:47
SurgSim::Math::SparseMatrix
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
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::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::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::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::applyCorrection
void applyCorrection(double dt, const Eigen::VectorBlock< SurgSim::Math::Vector > &deltaVelocity) override
Update the Representation's current position and velocity using a time interval, dt,...
Definition: DeformableRepresentation.cpp:254
SurgSim::Physics::DeformableRepresentation::getExternalGeneralizedStiffness
const SurgSim::Math::SparseMatrix & getExternalGeneralizedStiffness() const
Definition: DeformableRepresentation.cpp:164
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::Physics::DeformableRepresentation::resetState
void resetState() override
Reset the representation to its initial/default state.
Definition: DeformableRepresentation.cpp:66
SurgSim::Physics::DeformableRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: DeformableRepresentation.cpp:313
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::setLinearSolver
void setLinearSolver(SurgSim::Math::LinearSolver linearSolver)
Sets the linear algebraic solver.
Definition: DeformableRepresentation.cpp:147
SurgSim::Physics::DeformableRepresentation::~DeformableRepresentation
virtual ~DeformableRepresentation()
Destructor.
Definition: DeformableRepresentation.cpp:62
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::Physics::DeformableRepresentation::m_externalGeneralizedForce
SurgSim::Math::Vector m_externalGeneralizedForce
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:183
Representation.h
SurgSim::Math::Vector
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
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
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
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::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::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: DeformableRepresentation.cpp:389
SurgSim::Physics::DeformableRepresentation::getNumDofPerNode
size_t getNumDofPerNode() const
Gets the number of degrees of freedom per node.
Definition: DeformableRepresentation.cpp:125
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
SurgSim::Physics::DeformableRepresentation::getExternalGeneralizedDamping
const SurgSim::Math::SparseMatrix & getExternalGeneralizedDamping() const
Definition: DeformableRepresentation.cpp:169
SurgSim::Math::Matrix
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
OdeSolver.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