PhysicsManager.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_PHYSICSMANAGER_H
17 #define SURGSIM_PHYSICS_PHYSICSMANAGER_H
18 
19 #include <boost/thread/mutex.hpp>
20 #include <memory>
21 #include <vector>
22 
26 
27 
28 namespace SurgSim
29 {
30 namespace Framework
31 {
32 class Component;
33 }
34 
35 namespace Collision
36 {
37 class CollisionPair;
38 class Representation;
39 }
40 namespace Physics
41 {
42 
43 class BuildMlcp;
44 class ConstraintComponent;
45 class ContactConstraintGeneration;
46 class DcdCollision;
47 class FreeMotion;
48 class PostUpdate;
49 class PreUpdate;
50 class PushResults;
51 class Representation;
52 class SolveMlcp;
53 class UpdateCollisionRepresentations;
54 
58 {
59 public:
60 
63  virtual ~PhysicsManager();
64 
66  virtual int getType() const override;
67 
68  friend class PhysicsManagerTest;
69 
73  void getFinalState(SurgSim::Physics::PhysicsManagerState* s) const;
74 
78  void addExcludedCollisionPair(std::shared_ptr<SurgSim::Collision::Representation> representation1,
79  std::shared_ptr<SurgSim::Collision::Representation> representation2);
80 
84  void removeExcludedCollisionPair(std::shared_ptr<SurgSim::Collision::Representation> representation1,
85  std::shared_ptr<SurgSim::Collision::Representation> representation2);
86 
87 protected:
90  bool executeAdditions(const std::shared_ptr<SurgSim::Framework::Component>& component) override;
91  bool executeRemovals(const std::shared_ptr<SurgSim::Framework::Component>& component) override;
93 
96  virtual bool doInitialize() override;
97  virtual bool doStartUp() override;
98  virtual bool doUpdate(double dt) override;
100 
101  void initializeComputations(bool copyState);
102 private:
109  std::vector<std::shared_ptr<SurgSim::Collision::CollisionPair>>::iterator findExcludedCollisionPair(
110  std::shared_ptr<SurgSim::Collision::Representation> representation1,
111  std::shared_ptr<SurgSim::Collision::Representation> representation2);
112 
113  std::vector<std::shared_ptr<Representation>> m_representations;
114 
115  std::vector<std::shared_ptr<SurgSim::Collision::Representation>> m_collisionRepresentations;
116 
117  std::vector<std::shared_ptr<ConstraintComponent>> m_constraintComponents;
118 
120  std::vector<std::shared_ptr<SurgSim::Collision::CollisionPair>> m_excludedCollisionPairs;
121 
124 
127  std::unique_ptr<PreUpdate> m_preUpdateStep;
128  std::unique_ptr<FreeMotion> m_freeMotionStep;
129  std::unique_ptr<DcdCollision> m_dcdCollisionStep;
130  std::unique_ptr<ContactConstraintGeneration> m_constraintGenerationStep;
131  std::unique_ptr<BuildMlcp> m_buildMlcpStep;
132  std::unique_ptr<SolveMlcp> m_solveMlcpStep;
133  std::unique_ptr<PushResults> m_pushResultsStep;
134  std::unique_ptr<PostUpdate> m_postUpdateStep;
135  std::unique_ptr<UpdateCollisionRepresentations> m_updateCollisionRepresentationsStep;
137 
140 };
141 
142 }; // namespace Physics
143 }; // namespace SurgSim
144 
145 
146 
147 #endif
Definition: DriveElementFromInputBehavior.cpp:27
PhyicsManager handles the physics and motion calculation, it uses Computations to separate the algori...
Definition: PhysicsManager.h:57
std::unique_ptr< PreUpdate > m_preUpdateStep
Definition: PhysicsManager.h:127
std::unique_ptr< DcdCollision > m_dcdCollisionStep
Definition: PhysicsManager.h:129
std::vector< std::shared_ptr< SurgSim::Collision::Representation > > m_collisionRepresentations
Definition: PhysicsManager.h:115
Base Component Manager class.
Definition: ComponentManager.h:49
std::unique_ptr< SolveMlcp > m_solveMlcpStep
Definition: PhysicsManager.h:132
std::unique_ptr< BuildMlcp > m_buildMlcpStep
Definition: PhysicsManager.h:131
std::unique_ptr< PushResults > m_pushResultsStep
Definition: PhysicsManager.h:133
std::unique_ptr< FreeMotion > m_freeMotionStep
Definition: PhysicsManager.h:128
std::vector< std::shared_ptr< Representation > > m_representations
Definition: PhysicsManager.h:113
std::unique_ptr< PostUpdate > m_postUpdateStep
Definition: PhysicsManager.h:134
A simple thread-safe data container that can support multiple writers and readers.
Definition: LockedContainer.h:54
Definition: PhysicsManagerState.h:46
boost::mutex m_excludedCollisionPairMutex
Mutex to protect m_excludedCollisionPairs from being read/written simultaneously. ...
Definition: PhysicsManager.h:123
std::unique_ptr< ContactConstraintGeneration > m_constraintGenerationStep
Definition: PhysicsManager.h:130
std::vector< std::shared_ptr< SurgSim::Collision::CollisionPair > > m_excludedCollisionPairs
List of Collision::Representation pairs to be excluded from contact generation.
Definition: PhysicsManager.h:120
SurgSim::Framework::LockedContainer< SurgSim::Physics::PhysicsManagerState > m_finalState
A thread-safe copy of the last PhysicsManagerState in the previous update.
Definition: PhysicsManager.h:139
std::unique_ptr< UpdateCollisionRepresentations > m_updateCollisionRepresentationsStep
Definition: PhysicsManager.h:135
std::vector< std::shared_ptr< ConstraintComponent > > m_constraintComponents
Definition: PhysicsManager.h:117