opensurgsim
ConstraintImplementation.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_CONSTRAINTIMPLEMENTATION_H
17 #define SURGSIM_PHYSICS_CONSTRAINTIMPLEMENTATION_H
18 
19 #include <memory>
20 
21 #include <Eigen/Core>
22 
23 #include "SurgSim/Physics/Representation.h"
24 #include "SurgSim/Physics/ConstraintData.h"
25 #include "SurgSim/Physics/ConstraintImplementationFactory.h"
26 #include "SurgSim/Physics/ConstraintType.h"
27 #include "SurgSim/Physics/Localization.h"
28 #include "SurgSim/Physics/MlcpPhysicsProblem.h"
29 
30 namespace SurgSim
31 {
32 
33 namespace Physics
34 {
35 
39 enum ConstraintSideSign {CONSTRAINT_POSITIVE_SIDE, CONSTRAINT_NEGATIVE_SIDE};
40 
43 {
44 public:
47 
49  virtual ~ConstraintImplementation();
50 
53 
56  size_t getNumDof() const;
57 
60  virtual SurgSim::Physics::ConstraintType getConstraintType() const = 0;
61 
70  void build(double dt,
71  const ConstraintData& data,
72  const std::shared_ptr<Localization>& localization,
73  MlcpPhysicsProblem* mlcp,
74  size_t indexOfRepresentation,
75  size_t indexOfConstraint,
76  ConstraintSideSign sign);
77 
78 protected:
80  Eigen::SparseVector<double, Eigen::RowMajor, ptrdiff_t> m_newH;
81 
82 private:
83 
86  virtual size_t doGetNumDof() const = 0;
87 
96  virtual void doBuild(double dt,
97  const ConstraintData& data,
98  const std::shared_ptr<Localization>& localization,
99  MlcpPhysicsProblem* mlcp,
100  size_t indexOfRepresentation,
101  size_t indexOfConstraint,
102  ConstraintSideSign sign) = 0;
103 
104 };
105 
106 }; // namespace Physics
107 
108 }; // namespace SurgSim
109 
110 #endif // SURGSIM_PHYSICS_CONSTRAINTIMPLEMENTATION_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
A description of a physical mixed LCP system to be solved.
Definition: MlcpPhysicsProblem.h:43
static ConstraintImplementationFactory & getFactory()
Definition: ConstraintImplementation.cpp:34
ConstraintImplementation()
Constructor.
Definition: ConstraintImplementation.cpp:26
Base class for all CosntraintData Derived classes should be specific to a given constraint.
Definition: ConstraintData.h:27
void build(double dt, const ConstraintData &data, const std::shared_ptr< Localization > &localization, MlcpPhysicsProblem *mlcp, size_t indexOfRepresentation, size_t indexOfConstraint, ConstraintSideSign sign)
Builds the subset of an Mlcp physics problem associated to this implementation.
Definition: ConstraintImplementation.cpp:45
virtual SurgSim::Physics::ConstraintType getConstraintType() const =0
Gets the constraint type for this ConstraintImplementation.
Base class for all constraint implementations. A ConstraintImplementation defines 1 side of a constra...
Definition: ConstraintImplementation.h:42
Eigen::SparseVector< double, Eigen::RowMajor, ptrdiff_t > m_newH
Preallocated variable for derived implementations of doBuild.
Definition: ConstraintImplementation.h:80
size_t getNumDof() const
Gets the number of degree of freedom for this implementation.
Definition: ConstraintImplementation.cpp:40
This class manages ConstraintImplementations, and can be used to look up the correct implementation b...
Definition: ConstraintImplementationFactory.h:38
virtual ~ConstraintImplementation()
Destructor.
Definition: ConstraintImplementation.cpp:30