opensurgsim
Constraint.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_CONSTRAINT_H
17 #define SURGSIM_PHYSICS_CONSTRAINT_H
18 
19 #include "SurgSim/DataStructures/Location.h"
20 #include "SurgSim/Physics/ConstraintData.h"
21 #include "SurgSim/Physics/ConstraintImplementation.h"
22 #include "SurgSim/Physics/MlcpPhysicsProblem.h"
23 
24 #include <array>
25 #include <memory>
26 
27 namespace SurgSim
28 {
29 
30 namespace Physics
31 {
32 
35 {
36 public:
43  Constraint(
44  ConstraintType constraintType,
45  std::shared_ptr<ConstraintData> data,
46  std::shared_ptr<Representation> representation0,
47  const SurgSim::DataStructures::Location& location0,
48  std::shared_ptr<Representation> representation1,
49  const SurgSim::DataStructures::Location& location1);
50 
52  virtual ~Constraint();
53 
60  void setInformation(
61  ConstraintType constraintType,
62  std::shared_ptr<ConstraintData> data,
63  std::shared_ptr<Representation> representation0,
64  const SurgSim::DataStructures::Location& location0,
65  std::shared_ptr<Representation> representation1,
66  const SurgSim::DataStructures::Location& location1);
67 
70  const std::pair<std::shared_ptr<ConstraintImplementation>, std::shared_ptr<ConstraintImplementation>>&
71  getImplementations() const;
72 
75  const std::pair<std::shared_ptr<Localization>, std::shared_ptr<Localization>>&
76  getLocalizations() const;
77 
80  std::shared_ptr<ConstraintData> getData() const;
81 
84  size_t getNumDof() const;
85 
88  ConstraintType getType();
89 
96  void build(double dt,
97  MlcpPhysicsProblem* mlcpPhysicsProblem,
98  size_t indexOfRepresentation0,
99  size_t indexOfRepresentation1,
100  size_t indexOfConstraint);
101 
103  bool isActive();
104 
106  void setActive(bool flag);
107 
108 protected:
110  std::array<Math::MlcpConstraintType, NUM_CONSTRAINT_TYPES> m_mlcpMap;
111 
113  std::shared_ptr<ConstraintData> m_data;
114 
116  std::pair<std::shared_ptr<ConstraintImplementation>, std::shared_ptr<ConstraintImplementation>> m_implementations;
117  std::pair<std::shared_ptr<Localization>, std::shared_ptr<Localization>> m_localizations;
118 
120  size_t m_numDof;
121 
123  ConstraintType m_constraintType;
124 
132  virtual void doBuild(double dt,
133  const ConstraintData& data,
134  MlcpPhysicsProblem* mlcpPhysicsProblem,
135  size_t indexOfRepresentation0,
136  size_t indexOfRepresentation1,
137  size_t indexOfConstraint);
138 
140  bool m_active;
141 };
142 
143 }; // namespace Physics
144 
145 }; // namespace SurgSim
146 
147 #endif // SURGSIM_PHYSICS_CONSTRAINT_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
void setActive(bool flag)
Definition: Constraint.cpp:93
std::pair< std::shared_ptr< ConstraintImplementation >, std::shared_ptr< ConstraintImplementation > > m_implementations
Pair of implementations defining the 2 sides of the constraint.
Definition: Constraint.h:116
A description of a physical mixed LCP system to be solved.
Definition: MlcpPhysicsProblem.h:43
A Location defines a local position w.r.t.
Definition: Location.h:39
size_t m_numDof
The degrees of freedom that this constraint has.
Definition: Constraint.h:120
bool isActive()
Definition: Constraint.cpp:87
bool m_active
Flag to indicate whether this constraint is active or not.
Definition: Constraint.h:140
void build(double dt, MlcpPhysicsProblem *mlcpPhysicsProblem, size_t indexOfRepresentation0, size_t indexOfRepresentation1, size_t indexOfConstraint)
Builds subset of an Mlcp physics problem associated to this constraint.
Definition: Constraint.cpp:78
Base class for all CosntraintData Derived classes should be specific to a given constraint.
Definition: ConstraintData.h:27
ConstraintType getType()
Gets the ConstraintType.
Definition: Constraint.cpp:73
virtual ~Constraint()
Destructor.
Definition: Constraint.cpp:46
const std::pair< std::shared_ptr< Localization >, std::shared_ptr< Localization > > & getLocalizations() const
Gets both sides Localization as a pair.
Definition: Constraint.cpp:57
virtual void doBuild(double dt, const ConstraintData &data, MlcpPhysicsProblem *mlcpPhysicsProblem, size_t indexOfRepresentation0, size_t indexOfRepresentation1, size_t indexOfConstraint)
Builds subset of an Mlcp physics problem associated to this constraint user-defined call for extra tr...
Definition: Constraint.cpp:98
void setInformation(ConstraintType constraintType, std::shared_ptr< ConstraintData > data, std::shared_ptr< Representation > representation0, const SurgSim::DataStructures::Location &location0, std::shared_ptr< Representation > representation1, const SurgSim::DataStructures::Location &location1)
Sets all the values for this constraints, does validation on the parameters and will throw if somethi...
Definition: Constraint.cpp:127
Base class for all physics constraints. Contains data specific to the constraint and a pair of implem...
Definition: Constraint.h:34
const std::pair< std::shared_ptr< ConstraintImplementation >, std::shared_ptr< ConstraintImplementation > > & getImplementations() const
Gets both sides implementation as a pair.
Definition: Constraint.cpp:52
std::shared_ptr< ConstraintData > m_data
Specific data associated to this constraint.
Definition: Constraint.h:113
std::shared_ptr< ConstraintData > getData() const
Gets the data associated to this constraint.
Definition: Constraint.cpp:63
Constraint(ConstraintType constraintType, std::shared_ptr< ConstraintData > data, std::shared_ptr< Representation > representation0, const SurgSim::DataStructures::Location &location0, std::shared_ptr< Representation > representation1, const SurgSim::DataStructures::Location &location1)
Sets all the values for this constraints, does validation on the parameters and will throw if somethi...
Definition: Constraint.cpp:29
std::array< Math::MlcpConstraintType, NUM_CONSTRAINT_TYPES > m_mlcpMap
Constraint-MLCP mapping.
Definition: Constraint.h:110
size_t getNumDof() const
Gets the number of degree of freedom for this constraint.
Definition: Constraint.cpp:68
ConstraintType m_constraintType
The type of this constraint.
Definition: Constraint.h:123