All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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/OdeSolver.h"
27 
28 namespace SurgSim
29 {
30 
31 namespace Physics
32 {
33 
34 class Localization;
35 
47  public Representation,
49 {
50 public:
53  explicit DeformableRepresentation(const std::string& name);
54 
56  virtual ~DeformableRepresentation();
57 
58  virtual void resetState() override;
59 
60  virtual void setInitialState(std::shared_ptr<SurgSim::Math::OdeState> initialState);
61 
62  virtual const std::shared_ptr<SurgSim::Math::OdeState> getCurrentState() const;
63 
64  virtual const std::shared_ptr<SurgSim::Math::OdeState> getPreviousState() const;
65 
66  virtual const std::shared_ptr<SurgSim::Math::OdeState> getFinalState() const;
67 
70  size_t getNumDofPerNode() const;
71 
76 
80 
86  virtual void addExternalGeneralizedForce(std::shared_ptr<Localization> localization,
87  SurgSim::Math::Vector& generalizedForce,
90 
93 
96 
99 
105 
106  virtual void update(double dt) override;
107 
108  virtual void afterUpdate(double dt) override;
109 
110  virtual void applyCorrection(double dt, const Eigen::VectorBlock<SurgSim::Math::Vector>& deltaVelocity) override;
111 
113  void deactivateAndReset(void);
114 
119  virtual void setCollisionRepresentation(
120  std::shared_ptr<SurgSim::Collision::Representation> representation) override;
121 
122 protected:
123  virtual bool doWakeUp() override;
124 
128  virtual void transformState(std::shared_ptr<SurgSim::Math::OdeState> state,
129  const SurgSim::Math::RigidTransform3d& transform) = 0;
130 
132  std::shared_ptr<SurgSim::Math::OdeState> m_previousState;
133 
136  std::shared_ptr<SurgSim::Math::OdeState> m_currentState;
137 
139  std::shared_ptr<SurgSim::Math::OdeState> m_newState;
140 
143  std::shared_ptr<SurgSim::Math::OdeState> m_finalState;
144 
151 
154 
157 
160 
163 
167 
170 
173 
175  std::shared_ptr<SurgSim::Math::OdeSolver> m_odeSolver;
176 
177 private:
180 
183 };
184 
185 }; // namespace Physics
186 
187 }; // namespace SurgSim
188 
189 #endif // SURGSIM_PHYSICS_DEFORMABLEREPRESENTATION_H
190 
191 
192 
const SurgSim::Math::Matrix & getExternalGeneralizedDamping() const
Definition: DeformableRepresentation.cpp:130
virtual void transformState(std::shared_ptr< SurgSim::Math::OdeState > state, const SurgSim::Math::RigidTransform3d &transform)=0
Transform a state using a given transformation.
SurgSim::Math::Matrix m_externalGeneralizedDamping
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:149
const SurgSim::Math::Matrix & getComplianceMatrix() const
Gets the compliance matrix associated with motion.
Definition: DeformableRepresentation.cpp:135
The Representation class defines the base class for all physics objects.
Definition: Representation.h:56
virtual const std::shared_ptr< SurgSim::Math::OdeState > getPreviousState() const
Definition: DeformableRepresentation.cpp:94
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65
Base class for all deformable representations MassSprings, Finite Element Models,...
Definition: DeformableRepresentation.h:46
size_t getNumDofPerNode() const
Gets the number of degrees of freedom per node.
Definition: DeformableRepresentation.cpp:104
virtual bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: DeformableRepresentation.cpp:250
const SurgSim::Math::Vector & getExternalGeneralizedForce() const
Definition: DeformableRepresentation.cpp:120
std::shared_ptr< SurgSim::Math::OdeState > m_finalState
Last valid state (a.k.a final state)
Definition: DeformableRepresentation.h:143
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:136
Ode equation of 2nd order of the form M(x,v).a = F(x, v) with (x0, v0) for initial conditions and a s...
Definition: OdeEquation.h:40
SurgSim::Math::Matrix m_M
Mass matrix.
Definition: DeformableRepresentation.h:156
void setIntegrationScheme(SurgSim::Math::IntegrationScheme integrationScheme)
Sets the numerical integration scheme.
Definition: DeformableRepresentation.cpp:109
virtual 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, and change in velocity, deltaVelocity.
Definition: DeformableRepresentation.cpp:191
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:132
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:67
std::shared_ptr< SurgSim::Math::OdeSolver > m_odeSolver
Ode solver (its type depends on the numerical integration scheme)
Definition: DeformableRepresentation.h:175
virtual void update(double dt) override
Update the representation state to the current time step.
Definition: DeformableRepresentation.cpp:142
virtual ~DeformableRepresentation()
Destructor.
Definition: DeformableRepresentation.cpp:53
SurgSim::Math::IntegrationScheme getIntegrationScheme() const
Gets the numerical integration scheme.
Definition: DeformableRepresentation.cpp:115
DeformableRepresentation & operator=(const DeformableRepresentation &)
NO assignment operator.
IntegrationScheme
The diverse numerical integration scheme supported Each Ode Solver should have its own entry in this ...
Definition: OdeSolver.h:36
size_t m_numDofPerNode
Number of degrees of freedom per node (varies per deformable model)
Definition: DeformableRepresentation.h:166
DeformableRepresentation(const std::string &name)
Constructor.
Definition: DeformableRepresentation.cpp:41
SurgSim::Math::Matrix m_D
Damping matrix.
Definition: DeformableRepresentation.h:159
virtual void addExternalGeneralizedForce(std::shared_ptr< Localization > localization, 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.
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Math::Vector m_f
Force applied on the deformable representation.
Definition: DeformableRepresentation.h:153
void deactivateAndReset(void)
Deactivate and call resetState.
Definition: DeformableRepresentation.cpp:213
SurgSim::Math::IntegrationScheme m_integrationScheme
Numerical Integration scheme (dynamic explicit/implicit solver)
Definition: DeformableRepresentation.h:169
virtual const std::shared_ptr< SurgSim::Math::OdeState > getFinalState() const
Definition: DeformableRepresentation.cpp:99
SurgSim::Math::Matrix m_K
Stiffness matrix.
Definition: DeformableRepresentation.h:162
virtual void resetState() override
Reset the representation to its initial/default state.
Definition: DeformableRepresentation.cpp:56
SurgSim::Math::Matrix m_externalGeneralizedStiffness
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:148
virtual 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:173
SurgSim::Math::Vector m_externalGeneralizedForce
External generalized force, stiffness and damping applied on the deformable representation.
Definition: DeformableRepresentation.h:147
virtual const std::shared_ptr< SurgSim::Math::OdeState > getCurrentState() const
Definition: DeformableRepresentation.cpp:89
virtual 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:224
const SurgSim::Math::Matrix & getExternalGeneralizedStiffness() const
Definition: DeformableRepresentation.cpp:125
std::shared_ptr< SurgSim::Math::OdeState > m_newState
New state is a temporary variable to store the newly computed state.
Definition: DeformableRepresentation.h:139
virtual void setInitialState(std::shared_ptr< SurgSim::Math::OdeState > initialState)
Definition: DeformableRepresentation.cpp:67
bool m_needToReloadOdeSolver
Specify if the Ode Solver needs to be (re)loaded (do not exist yet, or integration scheme has changed...
Definition: DeformableRepresentation.h:172