opensurgsim
OsgSkeletonRepresentation.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_GRAPHICS_OSGSKELETONREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGSKELETONREPRESENTATION_H
18 
19 #include <boost/thread.hpp>
20 #include <map>
21 #include <osg/MatrixTransform>
22 #include <osg/ref_ptr>
23 #include <osgUtil/UpdateVisitor>
24 #include <string>
25 
26 #include "SurgSim/Graphics/OsgRepresentation.h"
27 #include "SurgSim/Graphics/SkeletonRepresentation.h"
28 
29 #if defined(_MSC_VER)
30 #pragma warning(push)
31 #pragma warning(disable:4250)
32 #endif
33 
34 namespace osg
35 {
36 class Node;
37 class Shader;
38 };
39 
40 namespace SurgSim
41 {
42 namespace Graphics
43 {
44 
45 struct BoneData;
46 class OsgModel;
47 
51 {
52 public:
55  explicit OsgSkeletonRepresentation(const std::string& name);
56 
58 
59  void loadModel(const std::string& fileName) override;
60 
61  void setModel(std::shared_ptr<SurgSim::Framework::Asset> model) override;
62 
63  std::shared_ptr<Model> getModel() const override;
64 
67  void setSkinningShaderFileName(const std::string& fileName);
68 
70  std::string getSkinningShaderFileName() const;
71 
72  void setBonePose(const std::string& name, const SurgSim::Math::RigidTransform3d& pose) override;
73 
74  SurgSim::Math::RigidTransform3d getBonePose(const std::string& name) const override;
75 
76  void setNeutralBonePose(const std::string& name, const SurgSim::Math::RigidTransform3d& pose) override;
77 
78  SurgSim::Math::RigidTransform3d getNeutralBonePose(const std::string& name) const override;
79 
80 protected:
81  void setNeutralBonePoses(const std::map<std::string, SurgSim::Math::RigidTransform3d>& poses) override;
82 
83  std::map<std::string, SurgSim::Math::RigidTransform3d> getNeutralBonePoses() const override;
84 
85  void doUpdate(double dt) override;
86 
87  bool doInitialize() override;
88 
89 private:
91  bool setupBones();
92 
94  std::shared_ptr<SurgSim::Framework::Logger> m_logger;
95 
97  std::shared_ptr<OsgModel> m_model;
98 
100  std::shared_ptr<std::map<std::string, BoneData>> m_bones;
101 
103  mutable boost::shared_mutex m_mutex;
104 
106  osg::ref_ptr<osg::Node> m_skeleton;
107 
109  std::string m_skinningShaderFileName;
110 
112  osg::ref_ptr<osg::Shader> m_skinningShader;
113 
115  osg::ref_ptr<osgUtil::UpdateVisitor> m_updateVisitor;
116 
118  size_t m_frameCount;
119 
121  osg::ref_ptr<osg::Node> m_root;
122 
124  osg::ref_ptr<osg::MatrixTransform> m_base;
125 };
126 
127 }; // namespace Graphics
128 }; // namespace SurgSim
129 
130 #if defined(_MSC_VER)
131 #pragma warning(pop)
132 #endif
133 
134 #endif // SURGSIM_GRAPHICS_OSGSKELETONREPRESENTATION_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
Skeleton representation is used to move a mesh based on the movements of pre-selected control points ...
Definition: OsgSkeletonRepresentation.h:50
Skeleton representation is used to move a mesh based on the movements of pre-selected control points ...
Definition: SkeletonRepresentation.h:36
Definition: OsgImGuiHandler.h:8
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55