opensurgsim
Fem3DRepresentation.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013-2016, 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_FEM3DREPRESENTATION_H
17 #define SURGSIM_PHYSICS_FEM3DREPRESENTATION_H
18 
19 #include <memory>
20 #include <string>
21 #include <unordered_map>
22 
23 #include "SurgSim/Framework/FrameworkConvert.h"
24 #include "SurgSim/Math/Matrix.h"
26 #include "SurgSim/Math/Vector.h"
27 #include "SurgSim/Physics/Fem3D.h"
28 #include "SurgSim/Physics/FemRepresentation.h"
29 
30 namespace SurgSim
31 {
32 namespace DataStructures
33 {
34 struct IndexedLocalCoordinate;
35 struct Location;
36 }
37 namespace Framework
38 {
39 class Asset;
40 }
41 namespace Math
42 {
43 class MeshShape;
44 class OdeState;
45 }
46 
47 namespace Physics
48 {
49 class Localization;
50 
51 SURGSIM_STATIC_REGISTRATION(Fem3DRepresentation);
52 
55 {
56 public:
59  explicit Fem3DRepresentation(const std::string& name);
60 
62  virtual ~Fem3DRepresentation();
63 
64  SURGSIM_CLASSNAME(SurgSim::Physics::Fem3DRepresentation);
65 
66  void loadFem(const std::string& fileName) override;
67 
71  void setFem(std::shared_ptr<SurgSim::Framework::Asset> mesh);
72 
74  std::shared_ptr<Fem3D> getFem() const;
75 
76  void addExternalGeneralizedForce(std::shared_ptr<Localization> localization,
77  const SurgSim::Math::Vector& generalizedForce,
79  const SurgSim::Math::Matrix& D = SurgSim::Math::Matrix()) override;
80 
81  std::shared_ptr<Localization> createLocalization(const SurgSim::DataStructures::Location& location) override;
82 
83 protected:
84  bool doWakeUp() override;
85 
86  void transformState(std::shared_ptr<SurgSim::Math::OdeState> state,
87  const SurgSim::Math::RigidTransform3d& transform) override;
88 
89  bool doInitialize() override;
90 
91 private:
96  std::unordered_map<size_t, size_t> createTriangleIdToElementIdMap(
97  std::shared_ptr<const SurgSim::Math::MeshShape> mesh);
98 
102  std::shared_ptr<Localization> createNodeLocalization(size_t nodeId);
103 
107  std::shared_ptr<Localization> createTriangleLocalization(
109 
113  std::shared_ptr<Localization> createElementLocalization(
115 
117  std::unordered_map<size_t, size_t> m_triangleIdToElementIdMap;
118 
120  std::shared_ptr<Fem3D> m_fem;
121 };
122 
123 } // namespace Physics
124 } // namespace SurgSim
125 
126 #endif // SURGSIM_PHYSICS_FEM3DREPRESENTATION_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Finite Element Model 3D is a fem built with 3D FemElement.
Definition: Fem3DRepresentation.h:54
A generic (size_t index, Vector coordinate) pair.
Definition: IndexedLocalCoordinate.h:29
Finite Element Model (a.k.a FEM) is a deformable model (a set of nodes connected by FemElement)...
Definition: FemRepresentation.h:46
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
A Location defines a local position w.r.t.
Definition: Location.h:39
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
A dynamic size column vector.
Definition: Vector.h:68
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Definitions of small fixed-size square matrix types.
Definitions of small fixed-size vector types.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > Matrix
A dynamic size matrix.
Definition: Matrix.h:65