Representation.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_REPRESENTATION_H
17 #define SURGSIM_PHYSICS_REPRESENTATION_H
18 
19 #include <string>
20 #include <typeindex>
21 
23 #include "SurgSim/Math/Vector.h"
25 
26 namespace SurgSim
27 {
28 
29 namespace DataStructures
30 {
31 struct Location;
32 }
33 
34 namespace Framework
35 {
36 class Logger;
37 }
38 
39 namespace Collision
40 {
41 class Representation;
42 }
43 
44 namespace Physics
45 {
46 
47 class Constraint;
48 class ConstraintData;
49 class ConstraintImplementation;
50 class Localization;
51 
54 {
55 public:
58  explicit Representation(const std::string& name);
59 
61  virtual ~Representation();
62 
64  virtual void resetState();
65 
68  size_t getNumDof() const;
69 
73 
76  bool isGravityEnabled() const;
77 
82 
87 
91  virtual void beforeUpdate(double dt);
92 
95  virtual void update(double dt);
96 
100  virtual void afterUpdate(double dt);
101 
105  virtual std::shared_ptr<Localization> createLocalization(const SurgSim::DataStructures::Location& location);
106 
114  virtual void applyCorrection(double dt, const Eigen::VectorBlock<SurgSim::Math::Vector>& deltaVelocity);
115 
117  std::shared_ptr<SurgSim::Collision::Representation> getCollisionRepresentation() const;
118 
122  virtual void setCollisionRepresentation(std::shared_ptr<SurgSim::Collision::Representation> representation);
123 
127  std::shared_ptr<ConstraintImplementation> getConstraintImplementation(SurgSim::Physics::ConstraintType type);
128 
129 protected:
134  void setNumDof(size_t numDof);
135 
138  const SurgSim::Math::Vector3d& getGravity() const;
139 
141  std::shared_ptr<SurgSim::Collision::Representation> m_collisionRepresentation;
142 
147 
148 private:
151 
154 
157 
159  size_t m_numDof;
160 
163 
166 
168  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
169 };
170 
171 }; // namespace Physics
172 
173 }; // namespace SurgSim
174 
175 #endif // SURGSIM_PHYSICS_REPRESENTATION_H
SurgSim::Physics::Representation::~Representation
virtual ~Representation()
Destructor.
Definition: Representation.cpp:47
SurgSim::Physics::Representation::m_gravity
const SurgSim::Math::Vector3d m_gravity
Gravity vector.
Definition: Representation.h:156
ConstraintType.h
Vector.h
SurgSim::Physics::Representation::createLocalization
virtual std::shared_ptr< Localization > createLocalization(const SurgSim::DataStructures::Location &location)
Computes a localized coordinate w.r.t this representation, given a Location object.
Definition: Representation.cpp:92
SurgSim::Physics::Representation::setNumDof
void setNumDof(size_t numDof)
Set the number of degrees of freedom.
Definition: Representation.cpp:101
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Physics::Representation::setIsDrivingSceneElementPose
void setIsDrivingSceneElementPose(bool isDrivingSceneElementPose)
Set whether this Representation is controlling the pose of the SceneElement that it is part of.
Definition: Representation.cpp:70
SurgSim::Physics::Representation::isDrivingSceneElementPose
bool isDrivingSceneElementPose()
Query if this Representation is controlling the pose of the SceneElement that it is part of.
Definition: Representation.cpp:75
SurgSim::Physics::Representation::setIsGravityEnabled
void setIsGravityEnabled(bool isGravityEnabled)
Set the gravity enable flag.
Definition: Representation.cpp:60
SurgSim::Physics::Representation::getCollisionRepresentation
std::shared_ptr< SurgSim::Collision::Representation > getCollisionRepresentation() const
Definition: Representation.cpp:111
SurgSim::Physics::Representation::getGravity
const SurgSim::Math::Vector3d & getGravity() const
Get the gravity used by this Representation.
Definition: Representation.cpp:106
SurgSim::Physics::Representation::resetState
virtual void resetState()
Reset the representation to its initial/default state.
Definition: Representation.cpp:51
SurgSim::Physics::Representation::isGravityEnabled
bool isGravityEnabled() const
Get the gravity enable flag.
Definition: Representation.cpp:65
SurgSim::Math::Vector3d
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
SurgSim::Physics::Representation
The Representation class defines the base class for all physics objects.
Definition: Representation.h:53
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Physics::Representation::getConstraintImplementation
std::shared_ptr< ConstraintImplementation > getConstraintImplementation(SurgSim::Physics::ConstraintType type)
Get a constraint implementation of the given type for this representation.
Definition: Representation.cpp:121
SurgSim::Physics::Representation::beforeUpdate
virtual void beforeUpdate(double dt)
Preprocessing done before the update call This needs to be called from the outside usually from a Com...
Definition: Representation.cpp:80
SurgSim::Physics::ConstraintType
ConstraintType
Definition: ConstraintType.h:24
SurgSim::Physics::Representation::operator=
Representation & operator=(const Representation &)
NO assignment operator.
SurgSim::Framework::Representation
Representations are manifestations of a SceneElement.
Definition: Representation.h:33
SurgSim::Physics::Representation::getNumDof
size_t getNumDof() const
Query the object number of degrees of freedom.
Definition: Representation.cpp:55
SurgSim::Physics::Representation::update
virtual void update(double dt)
Update the representation state to the current time step.
Definition: Representation.cpp:84
Representation.h
SurgSim::DataStructures::Location
A Location defines a local position w.r.t.
Definition: Location.h:39
SurgSim::Physics::Representation::applyCorrection
virtual void applyCorrection(double dt, const Eigen::VectorBlock< SurgSim::Math::Vector > &deltaVelocity)
Update the Representation's current position and velocity using a time interval, dt,...
Definition: Representation.cpp:97
SurgSim::Physics::Representation::Representation
Representation(const std::string &name)
Constructor.
Definition: Representation.cpp:32
SurgSim::Physics::Representation::afterUpdate
virtual void afterUpdate(double dt)
Postprocessing done after the update call This needs to be called from the outside usually from a Com...
Definition: Representation.cpp:88
SurgSim::Physics::Representation::m_isDrivingSceneElementPose
bool m_isDrivingSceneElementPose
Is this representation driving the sceneElement pose.
Definition: Representation.h:165
SurgSim::Physics::Representation::m_collisionRepresentation
std::shared_ptr< SurgSim::Collision::Representation > m_collisionRepresentation
This entity's collision representation, these are usually very specific to the physics representation...
Definition: Representation.h:141
SurgSim::Physics::Representation::m_isGravityEnabled
bool m_isGravityEnabled
Gravity enabled flag.
Definition: Representation.h:162
SurgSim::Physics::Representation::setCollisionRepresentation
virtual void setCollisionRepresentation(std::shared_ptr< SurgSim::Collision::Representation > representation)
Set the collision representation for this physics representation, when the collision object is involv...
Definition: Representation.cpp:116
SurgSim::Physics::Representation::m_numDof
size_t m_numDof
Number of degrees of freedom for this representation.
Definition: Representation.h:159
SurgSim::Physics::Representation::m_logger
std::shared_ptr< SurgSim::Framework::Logger > m_logger
Logger for this class.
Definition: Representation.h:168
SurgSim::Physics::Representation::driveSceneElementPose
void driveSceneElementPose(const SurgSim::Math::RigidTransform3d &pose)
This conditionally updates that pose for the scenelement to the given pose The update gets exectuded ...
Definition: Representation.cpp:132