OsgSkeletonRepresentation.h
Go to the documentation of this file.
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 
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 
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
Definition: CompoundShapeToGraphics.cpp:29
std::shared_ptr< std::map< std::string, BoneData > > m_bones
The named map of the bones in this skeleton.
Definition: OsgSkeletonRepresentation.h:100
std::shared_ptr< SurgSim::Framework::Logger > m_logger
The logger for this class.
Definition: OsgSkeletonRepresentation.h:94
osg::ref_ptr< osg::MatrixTransform > m_base
The first MatrixTransform node.
Definition: OsgSkeletonRepresentation.h:124
Skeleton representation is used to move a mesh based on the movements of pre-selected control points ...
Definition: OsgSkeletonRepresentation.h:50
osg::ref_ptr< osg::Shader > m_skinningShader
The hardware skinning shader.
Definition: OsgSkeletonRepresentation.h:112
Skeleton representation is used to move a mesh based on the movements of pre-selected control points ...
Definition: SkeletonRepresentation.h:36
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
osg::ref_ptr< osgUtil::UpdateVisitor > m_updateVisitor
Tree updater which updates the position of the bones.
Definition: OsgSkeletonRepresentation.h:115
std::shared_ptr< OsgModel > m_model
The model containing the bone and mesh information.
Definition: OsgSkeletonRepresentation.h:97
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
boost::shared_mutex m_mutex
Mutex to access m_bones safely.
Definition: OsgSkeletonRepresentation.h:103
size_t m_frameCount
Parameter to keep track of the skeleton&#39;s frame count. Set to the UpdateVisitor.
Definition: OsgSkeletonRepresentation.h:118
Definition: OculusView.h:25
std::string m_skinningShaderFileName
The file containing the skinning shader.
Definition: OsgSkeletonRepresentation.h:109
osg::ref_ptr< osg::Node > m_skeleton
The skeleton which is read from the mesh file.
Definition: OsgSkeletonRepresentation.h:106
osg::ref_ptr< osg::Node > m_root
The root node of the skeleton tree.
Definition: OsgSkeletonRepresentation.h:121
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55