opensurgsim
LinearSpring.h
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 
16 #ifndef SURGSIM_PHYSICS_LINEARSPRING_H
17 #define SURGSIM_PHYSICS_LINEARSPRING_H
18 
19 #include "SurgSim/Physics/Spring.h"
20 
21 namespace SurgSim
22 {
23 namespace Math
24 {
25 class OdeState;
26 }
27 namespace Physics
28 {
29 class MassSpringModel;
30 
32 class LinearSpring : public Spring
33 {
34 public:
37  LinearSpring(size_t nodeId0, size_t nodeId1);
38 
43  explicit LinearSpring(const std::shared_ptr<Math::OdeState> state, size_t nodeId0, size_t nodeId1, double stiffness,
44  double damping);
45 
50  explicit LinearSpring(const std::shared_ptr<MassSpringModel> massSpring, size_t nodeId0, size_t nodeId1,
51  double stiffness, double damping);
52 
53  void initialize(const SurgSim::Math::OdeState& state) override;
54 
58  void setStiffness(double stiffness);
59 
62  double getStiffness() const;
63 
67  void setDamping(double damping);
68 
71  double getDamping() const;
72 
76  void setRestLength(double restLength);
77 
80  double getRestLength() const;
81 
86  void addForce(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F, double scale = 1.0) override;
87 
93  void addDamping(const SurgSim::Math::OdeState& state, SurgSim::Math::SparseMatrix* D, double scale = 1.0) override;
94 
100  void addStiffness(const SurgSim::Math::OdeState& state, SurgSim::Math::SparseMatrix* K,
101  double scale = 1.0) override;
102 
109  void addFDK(const SurgSim::Math::OdeState& state, SurgSim::Math::Vector* F,
111 
119  void addMatVec(const SurgSim::Math::OdeState& state, double alphaD, double alphaK,
120  const SurgSim::Math::Vector& vector, SurgSim::Math::Vector* F) override;
121 
126  bool operator ==(const Spring& spring) const;
127 
132  bool operator !=(const Spring& spring) const;
133 
134 protected:
142  bool computeDampingAndStiffness(const SurgSim::Math::OdeState& state,
145 
146 private:
148  double m_restLength;
149 
151  double m_stiffness;
152 
154  double m_damping;
155 };
156 
157 }; // namespace Physics
158 
159 }; // namespace SurgSim
160 
161 #endif // SURGSIM_PHYSICS_LINEARSPRING_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::SparseMatrix< double > SparseMatrix
A sparse matrix.
Definition: SparseMatrix.h:32
The state of an ode of 2nd order of the form with boundary conditions.
Definition: OdeState.h:38
Base class for all springs It handles the node ids to which it is connected and requires all derived ...
Definition: Spring.h:42
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
Linear spring connecting 2 nodes with a viscous term.
Definition: LinearSpring.h:32
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51