RigidRepresentationBase.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 
16 #ifndef SURGSIM_PHYSICS_RIGIDREPRESENTATIONBASE_H
17 #define SURGSIM_PHYSICS_RIGIDREPRESENTATIONBASE_H
18 
20 #include "SurgSim/Math/Shape.h"
24 
25 namespace SurgSim
26 {
27 
28 namespace Collision
29 {
30 class Representation;
31 }
32 
33 namespace Physics
34 {
35 
39 {
40 public:
43  explicit RigidRepresentationBase(const std::string& name);
44 
46  virtual ~RigidRepresentationBase();
47 
51  void setInitialState(const RigidState& state);
52 
53  void resetState() override;
54 
57  const RigidState& getInitialState() const;
60  const RigidState& getCurrentState() const;
63  const RigidState& getPreviousState() const;
64 
65  std::shared_ptr<Localization> createLocalization(const SurgSim::DataStructures::Location& location) override;
66 
69  void setDensity(double rho);
70 
73  double getDensity() const;
74 
77  double getMass() const;
78 
82 
86 
89  void setLinearDamping(double linearDamping);
90 
93  double getLinearDamping() const;
94 
97  void setAngularDamping(double angularDamping);
98 
101  double getAngularDamping() const;
102 
106  void setShape(const std::shared_ptr<SurgSim::Math::Shape> shape);
107 
110  const std::shared_ptr<SurgSim::Math::Shape> getShape() const;
111 
117  void setCollisionRepresentation(std::shared_ptr<SurgSim::Collision::Representation> representation) override;
118 
119  void beforeUpdate(double dt) override;
120  void afterUpdate(double dt) override;
121 
122 protected:
123  bool doInitialize() override;
124  bool doWakeUp() override;
125 
134 
137 
139  double m_rho;
140 
142  double m_mass;
143 
146 
149 
152 
155 
157  std::shared_ptr<SurgSim::Math::Shape> m_shape;
158 
163  template <class T>
164  std::shared_ptr<T> createTypedLocalization(const SurgSim::DataStructures::Location& location);
165 
166 private:
168  void updateProperties();
169 
170  virtual void updateGlobalInertiaMatrices(const RigidState& state) = 0;
171 };
172 
173 }; // Physics
174 }; // SurgSim
175 
177 
178 #endif // SURGSIM_PHYSICS_RIGIDREPRESENTATIONBASE_H
SurgSim::Physics::RigidRepresentationBase::RigidRepresentationBase
RigidRepresentationBase(const std::string &name)
Constructor.
Definition: RigidRepresentationBase.cpp:33
Shape.h
SurgSim::Physics::RigidState
The RigidState class describes a state (position and velocity information).
Definition: RigidState.h:31
SurgSim::Physics::RigidRepresentationBase::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: RigidRepresentationBase.cpp:215
SurgSim::Physics::RigidRepresentationBase::createTypedLocalization
std::shared_ptr< T > createTypedLocalization(const SurgSim::DataStructures::Location &location)
Creates typed localization.
Definition: RigidRepresentationBase-inl.h:26
SurgSim::Physics::RigidRepresentationBase::setLinearDamping
void setLinearDamping(double linearDamping)
Set the linear damping parameter.
Definition: RigidRepresentationBase.cpp:152
SurgSim::Physics::RigidRepresentationBase::setDensity
void setDensity(double rho)
Set the mass density of the rigid representation.
Definition: RigidRepresentationBase.cpp:126
SurgSim::Physics::RigidRepresentationBase::createLocalization
std::shared_ptr< Localization > createLocalization(const SurgSim::DataStructures::Location &location) override
Computes a localized coordinate w.r.t this representation, given a Location object.
Definition: RigidRepresentationBase.cpp:120
SurgSim::Physics::RigidRepresentationBase::getInitialState
const RigidState & getInitialState() const
Get the initial state of the rigid representation.
Definition: RigidRepresentationBase.cpp:105
SurgSim::Physics::RigidRepresentationBase::getLocalInertia
const SurgSim::Math::Matrix33d & getLocalInertia() const
Get the local inertia 3x3 matrix of the rigid body.
Definition: RigidRepresentationBase.cpp:147
SurgSim::Physics::RigidRepresentationBase::setShape
void setShape(const std::shared_ptr< SurgSim::Math::Shape > shape)
Set the shape to use internally for physical parameters computation.
Definition: RigidRepresentationBase.cpp:172
SurgSim::Physics::RigidRepresentationBase::m_initialState
RigidState m_initialState
Initial rigid representation state (useful for reset)
Definition: RigidRepresentationBase.h:127
SurgSim::Physics::RigidRepresentationBase::m_linearDamping
double m_linearDamping
Linear damping parameter (in N.s.m-1 or Kg.s-1)
Definition: RigidRepresentationBase.h:145
SurgSim::Physics::RigidRepresentationBase::getMass
double getMass() const
Get the mass of the rigid body.
Definition: RigidRepresentationBase.cpp:137
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Physics::RigidRepresentationBase::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: RigidRepresentationBase.cpp:74
SurgSim::Physics::Representation
The Representation class defines the base class for all physics objects.
Definition: Representation.h:53
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
RigidState.h
SurgSim::Physics::RigidRepresentationBase::setAngularDamping
void setAngularDamping(double angularDamping)
Set the angular damping parameter.
Definition: RigidRepresentationBase.cpp:162
SurgSim::Physics::RigidRepresentationBase::m_previousState
RigidState m_previousState
Previous rigid representation state.
Definition: RigidRepresentationBase.h:129
SurgSim::Physics::RigidRepresentationBase::getAngularDamping
double getAngularDamping() const
Get the angular damping parameter.
Definition: RigidRepresentationBase.cpp:167
RigidRepresentationBase-inl.h
SurgSim::Math::Matrix33d
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > Matrix33d
A 3x3 matrix of doubles.
Definition: Matrix.h:51
SurgSim::Physics::RigidRepresentationBase::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: RigidRepresentationBase.cpp:62
SurgSim::Physics::RigidRepresentationBase::updateGlobalInertiaMatrices
virtual void updateGlobalInertiaMatrices(const RigidState &state)=0
SurgSim::Physics::RigidRepresentationBase::getCurrentState
const RigidState & getCurrentState() const
Get the current state of the rigid representation.
Definition: RigidRepresentationBase.cpp:110
SurgSim::Physics::RigidRepresentationBase::m_localInertia
SurgSim::Math::Matrix33d m_localInertia
Inertia matrix in local coordinates.
Definition: RigidRepresentationBase.h:154
SurgSim::Physics::RigidRepresentationBase::m_mass
double m_mass
Total mass of the object (in Kg)
Definition: RigidRepresentationBase.h:142
SurgSim::Physics::RigidRepresentationBase::~RigidRepresentationBase
virtual ~RigidRepresentationBase()
Destructor.
Definition: RigidRepresentationBase.cpp:58
SurgSim::Physics::RigidRepresentationBase::resetState
void resetState() override
Reset the representation to its initial/default state.
Definition: RigidRepresentationBase.cpp:94
RigidLocalization.h
SurgSim::Physics::RigidRepresentationBase
The RigidRepresentationBase class defines the base class for all rigid motion based representations (...
Definition: RigidRepresentationBase.h:38
SurgSim::Physics::RigidRepresentationBase::m_parametersValid
bool m_parametersValid
Validity of the parameters.
Definition: RigidRepresentationBase.h:136
SurgSim::DataStructures::Location
A Location defines a local position w.r.t.
Definition: Location.h:39
Location.h
Representation.h
SurgSim::Physics::RigidRepresentationBase::m_currentState
RigidState m_currentState
Current rigid representation state.
Definition: RigidRepresentationBase.h:131
SurgSim::Physics::RigidRepresentationBase::getLinearDamping
double getLinearDamping() const
Get the linear damping parameter.
Definition: RigidRepresentationBase.cpp:157
SurgSim::Physics::RigidRepresentationBase::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: RigidRepresentationBase.cpp:209
SurgSim::Physics::RigidRepresentationBase::getPreviousState
const RigidState & getPreviousState() const
Get the previous state of the rigid representation.
Definition: RigidRepresentationBase.cpp:115
SurgSim::Physics::RigidRepresentationBase::m_finalState
RigidState m_finalState
Last valid/final rigid representation state.
Definition: RigidRepresentationBase.h:133
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Physics::RigidRepresentationBase::m_massCenter
SurgSim::Math::Vector3d m_massCenter
Mass-center of the object.
Definition: RigidRepresentationBase.h:151
SurgSim::Physics::RigidRepresentationBase::setInitialState
void setInitialState(const RigidState &state)
Set the initial state of the rigid representation.
Definition: RigidRepresentationBase.cpp:85
SurgSim::Physics::RigidRepresentationBase::m_shape
std::shared_ptr< SurgSim::Math::Shape > m_shape
Shape to be used for the mass/inertia calculation.
Definition: RigidRepresentationBase.h:157
SurgSim::Physics::RigidRepresentationBase::getMassCenter
const SurgSim::Math::Vector3d & getMassCenter() const
Get the mass center of the rigid body.
Definition: RigidRepresentationBase.cpp:142
SurgSim::Physics::RigidRepresentationBase::m_rho
double m_rho
Density of the object (in Kg.m-3)
Definition: RigidRepresentationBase.h:139
SurgSim::Physics::RigidRepresentationBase::getDensity
double getDensity() const
Get the mass density of the rigid representation.
Definition: RigidRepresentationBase.cpp:132
SurgSim::Physics::RigidRepresentationBase::updateProperties
void updateProperties()
Updates mass, mass center and inertia when density and/or shape used for mass inertia is updated.
Definition: RigidRepresentationBase.cpp:186
SurgSim::Physics::RigidRepresentationBase::m_angularDamping
double m_angularDamping
Angular damping parameter (in N.m.s.rad-1)
Definition: RigidRepresentationBase.h:148
SurgSim::Physics::RigidRepresentationBase::beforeUpdate
void beforeUpdate(double dt) override
Preprocessing done before the update call This needs to be called from the outside usually from a Com...
Definition: RigidRepresentationBase.cpp:204
SurgSim::Physics::RigidRepresentationBase::getShape
const std::shared_ptr< SurgSim::Math::Shape > getShape() const
Get the shape used internally for physical parameters computation.
Definition: RigidRepresentationBase.cpp:181