opensurgsim
PhysicsManagerState.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2015, 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_PHYSICSMANAGERSTATE_H
17 #define SURGSIM_PHYSICS_PHYSICSMANAGERSTATE_H
18 
19 #include <memory>
20 #include <vector>
21 #include <unordered_map>
22 
23 #include "SurgSim/Collision/CollisionPair.h"
24 #include "SurgSim/Collision/ContactFilter.h"
25 #include "SurgSim/Collision/Representation.h"
26 #include "SurgSim/Particles/Representation.h"
27 #include "SurgSim/Physics/Constraint.h"
28 #include "SurgSim/Physics/MlcpMapping.h"
29 #include "SurgSim/Physics/MlcpPhysicsProblem.h"
30 #include "SurgSim/Physics/MlcpPhysicsSolution.h"
31 #include "SurgSim/Physics/Representation.h"
32 
33 
34 namespace SurgSim
35 {
36 namespace Physics
37 {
38 
39 class ConstraintComponent;
40 
41 enum ConstraintGroupType
42 {
43  CONSTRAINT_GROUP_TYPE_CONTACT = 0,
44  CONSTRAINT_GROUP_TYPE_SCENE,
45  CONSTRAINT_GROUP_TYPE_COUNT
46 };
47 
49 {
50 public:
53 
56 
59  void setRepresentations(const std::vector<std::shared_ptr<Representation>>& val);
60 
63  const std::vector<std::shared_ptr<Representation>>& getRepresentations();
64 
67  void setActiveRepresentations(const std::vector<std::shared_ptr<Representation>>& activeRepresentations);
68 
71  const std::vector<std::shared_ptr<Representation>>& getActiveRepresentations() const;
72 
75  void setCollisionRepresentations(const std::vector<std::shared_ptr<SurgSim::Collision::Representation>>& val);
76 
79  const std::vector<std::shared_ptr<SurgSim::Collision::Representation>>& getCollisionRepresentations();
80 
83  void setActiveCollisionRepresentations(const std::vector<std::shared_ptr<SurgSim::Collision::Representation>>& val);
84 
87  const std::vector<std::shared_ptr<SurgSim::Collision::Representation>>& getActiveCollisionRepresentations();
88 
91  void setParticleRepresentations(const std::vector<std::shared_ptr<SurgSim::Particles::Representation>>& val);
92 
95  const std::vector<std::shared_ptr<SurgSim::Particles::Representation>>& getParticleRepresentations();
96 
99  void setActiveParticleRepresentations(const std::vector<std::shared_ptr<SurgSim::Particles::Representation>>& val);
100 
103  const std::vector<std::shared_ptr<SurgSim::Particles::Representation>>& getActiveParticleRepresentations();
104 
107  void setConstraintComponents(const std::vector<std::shared_ptr<ConstraintComponent>>& val);
108 
111  const std::vector<std::shared_ptr<ConstraintComponent>>& getConstraintComponents();
112 
115  const std::unordered_map<std::shared_ptr<SurgSim::Collision::Representation>,
116  std::shared_ptr<SurgSim::Physics::Representation>>& getCollisionToPhysicsMap() const;
117 
121  void setCollisionPairs(const std::vector<std::shared_ptr<SurgSim::Collision::CollisionPair>>& val);
122 
125  const std::vector<std::shared_ptr<SurgSim::Collision::CollisionPair>>& getCollisionPairs();
126 
129  void setContactFilters(const std::vector<std::shared_ptr<SurgSim::Collision::ContactFilter>>& val);
130 
132  std::vector<std::shared_ptr<SurgSim::Collision::ContactFilter>> getContactFilters() const;
133 
134 
139  void setConstraintGroup(ConstraintGroupType type, const std::vector<std::shared_ptr<Constraint>>& constraints);
140 
144  const std::vector<std::shared_ptr<Constraint>>& getConstraintGroup(int type) const;
145 
148  void setActiveConstraints(const std::vector<std::shared_ptr<Constraint>>& activeConstraints);
149 
151  const std::vector<std::shared_ptr<Constraint>>& getActiveConstraints() const;
152 
156 
159  const MlcpPhysicsProblem& getMlcpProblem() const;
160 
164 
167  const MlcpPhysicsSolution& getMlcpSolution() const;
168 
173 
176  void setRepresentationsMapping(const MlcpMapping<Representation>& representationsMapping);
177 
182 
185  void setConstraintsMapping(const MlcpMapping<Constraint>& constraintsMapping);
186 
189  void setTimeOfImpact(double timeOfImpact);
190 
192  double getTimeOfImpact();
193 
195  bool shouldAbortGroup() const;
196 
199  void setAbortGroup(bool val);
200 
201 private:
202 
208  std::vector<std::shared_ptr<Representation>> m_representations;
209 
211  std::vector<std::shared_ptr<Representation>> m_activeRepresentations;
212 
214  std::vector<std::shared_ptr<SurgSim::Collision::Representation>> m_collisionRepresentations;
215 
217  std::vector<std::shared_ptr<SurgSim::Collision::Representation>> m_activeCollisionRepresentations;
218 
220  std::vector <std::shared_ptr<Collision::ContactFilter>> m_contactFilters;
221 
223  std::vector<std::shared_ptr<SurgSim::Particles::Representation>> m_particleRepresentations;
224 
226  std::vector<std::shared_ptr<SurgSim::Particles::Representation>> m_activeParticleRepresentations;
227 
229  std::vector<std::shared_ptr<ConstraintComponent>> m_constraintComponents;
230 
232  std::unordered_map<std::shared_ptr<SurgSim::Collision::Representation>,
233  std::shared_ptr<SurgSim::Physics::Representation>> m_collisionsToPhysicsMap;
234 
236  std::vector<std::shared_ptr<SurgSim::Collision::CollisionPair>> m_collisionPairs;
237 
239  std::unordered_map<int, std::vector<std::shared_ptr<Constraint>>> m_constraints;
240 
242  std::vector<std::shared_ptr<Constraint>> m_activeConstraints;
243 
245  MlcpMapping<Representation> m_representationsIndexMapping;
246 
248  MlcpMapping<Constraint> m_constraintsIndexMapping;
249 
252  MlcpPhysicsProblem m_mlcpPhysicsProblem;
253 
255  MlcpPhysicsSolution m_mlcpPhysicsSolution;
256 
258  bool m_abortGroup;
259 
261  double m_timeOfImpact;
262 };
263 
264 }; // Physics
265 }; // SurgSim
266 
267 #endif
const std::vector< std::shared_ptr< Representation > > & getRepresentations()
Gets the physics representations.
Definition: PhysicsManagerState.cpp:59
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
const MlcpMapping< Representation > & getRepresentationsMapping() const
Gets the representations mapping.
Definition: PhysicsManagerState.cpp:220
void setRepresentationsMapping(const MlcpMapping< Representation > &representationsMapping)
Set the representations mapping.
Definition: PhysicsManagerState.cpp:225
A description of a physical mixed LCP system to be solved.
Definition: MlcpPhysicsProblem.h:43
void setAbortGroup(bool val)
Set whether to abort the current grouped computation.
Definition: PhysicsManagerState.cpp:255
void setCollisionRepresentations(const std::vector< std::shared_ptr< SurgSim::Collision::Representation >> &val)
Sets the collision representations for the state.
Definition: PhysicsManagerState.cpp:83
const std::unordered_map< std::shared_ptr< SurgSim::Collision::Representation >, std::shared_ptr< SurgSim::Physics::Representation > > & getCollisionToPhysicsMap() const
Definition: PhysicsManagerState.cpp:78
const std::vector< std::shared_ptr< SurgSim::Particles::Representation > > & getParticleRepresentations()
Gets the particle representations.
Definition: PhysicsManagerState.cpp:112
const std::vector< std::shared_ptr< SurgSim::Collision::CollisionPair > > & getCollisionPairs()
Gets collision pairs.
Definition: PhysicsManagerState.cpp:157
void setActiveConstraints(const std::vector< std::shared_ptr< Constraint >> &activeConstraints)
Filter the map of constraints into the active constraints list.
Definition: PhysicsManagerState.cpp:189
void setActiveCollisionRepresentations(const std::vector< std::shared_ptr< SurgSim::Collision::Representation >> &val)
Sets the active collision representations for the state.
Definition: PhysicsManagerState.cpp:95
const std::vector< std::shared_ptr< Representation > > & getActiveRepresentations() const
Gets the active physics representations.
Definition: PhysicsManagerState.cpp:70
void setContactFilters(const std::vector< std::shared_ptr< SurgSim::Collision::ContactFilter >> &val)
Set the list of contact filters.
Definition: PhysicsManagerState.cpp:162
bool shouldAbortGroup() const
Definition: PhysicsManagerState.cpp:250
void setRepresentations(const std::vector< std::shared_ptr< Representation >> &val)
Sets the physics representations for the state, these are the basis for all the computations.
Definition: PhysicsManagerState.cpp:41
double getTimeOfImpact()
Definition: PhysicsManagerState.cpp:245
const std::vector< std::shared_ptr< SurgSim::Collision::Representation > > & getCollisionRepresentations()
Gets the collision representations.
Definition: PhysicsManagerState.cpp:90
PhysicsManagerState()
Constructor.
Definition: PhysicsManagerState.cpp:29
std::vector< std::shared_ptr< SurgSim::Collision::ContactFilter > > getContactFilters() const
Definition: PhysicsManagerState.cpp:167
void setConstraintGroup(ConstraintGroupType type, const std::vector< std::shared_ptr< Constraint >> &constraints)
Sets the group of constraints to a given value, the grouping indicates what type of constraint we are...
Definition: PhysicsManagerState.cpp:172
const std::vector< std::shared_ptr< ConstraintComponent > > & getConstraintComponents()
Gets the constraint components.
Definition: PhysicsManagerState.cpp:147
MlcpPhysicsSolution & getMlcpSolution()
Gets the Mlcp solution.
Definition: PhysicsManagerState.cpp:210
MlcpPhysicsProblem & getMlcpProblem()
Gets the Mlcp problem.
Definition: PhysicsManagerState.cpp:200
void setTimeOfImpact(double timeOfImpact)
Set the time of impact.
Definition: PhysicsManagerState.cpp:240
The description of a solution to a physical MLCP problem.
Definition: MlcpPhysicsSolution.h:34
void setCollisionPairs(const std::vector< std::shared_ptr< SurgSim::Collision::CollisionPair >> &val)
Sets collision pairs that should be considered, while this is not being verified the collision pairs ...
Definition: PhysicsManagerState.cpp:152
const std::vector< std::shared_ptr< Constraint > > & getActiveConstraints() const
Definition: PhysicsManagerState.cpp:195
const std::vector< std::shared_ptr< SurgSim::Collision::Representation > > & getActiveCollisionRepresentations()
Gets the list of active collision representations.
Definition: PhysicsManagerState.cpp:102
void setActiveRepresentations(const std::vector< std::shared_ptr< Representation >> &activeRepresentations)
Set the list of representations into the active representations list.
Definition: PhysicsManagerState.cpp:64
void setConstraintsMapping(const MlcpMapping< Constraint > &constraintsMapping)
Set the constraints mapping.
Definition: PhysicsManagerState.cpp:235
const std::vector< std::shared_ptr< Constraint > > & getConstraintGroup(int type) const
Gets constraint group.
Definition: PhysicsManagerState.cpp:179
void setActiveParticleRepresentations(const std::vector< std::shared_ptr< SurgSim::Particles::Representation >> &val)
Sets the active particle representations for the state.
Definition: PhysicsManagerState.cpp:117
Definition: PhysicsManagerState.h:48
void setParticleRepresentations(const std::vector< std::shared_ptr< SurgSim::Particles::Representation >> &val)
Sets the particle representations for the state.
Definition: PhysicsManagerState.cpp:107
Definition: MlcpMapping.h:27
void setConstraintComponents(const std::vector< std::shared_ptr< ConstraintComponent >> &val)
Sets the list of constraint components.
Definition: PhysicsManagerState.cpp:128
const MlcpMapping< Constraint > & getConstraintsMapping() const
Gets the constraints mapping.
Definition: PhysicsManagerState.cpp:230
const std::vector< std::shared_ptr< SurgSim::Particles::Representation > > & getActiveParticleRepresentations()
Gets the list of active particle representations.
Definition: PhysicsManagerState.cpp:123
~PhysicsManagerState()
Destructor.
Definition: PhysicsManagerState.cpp:36