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 
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 
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
SurgSim::Graphics::OsgSkeletonRepresentation::m_frameCount
size_t m_frameCount
Parameter to keep track of the skeleton's frame count. Set to the UpdateVisitor.
Definition: OsgSkeletonRepresentation.h:118
SurgSim::Graphics::OsgSkeletonRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgSkeletonRepresentation.cpp:343
SurgSim::Graphics::OsgSkeletonRepresentation::setupBones
bool setupBones()
Setup the bones with the model and skinning shader.
Definition: OsgSkeletonRepresentation.cpp:398
SurgSim::Graphics::OsgSkeletonRepresentation::getBonePose
SurgSim::Math::RigidTransform3d getBonePose(const std::string &name) const override
Get the pose for a given bone.
Definition: OsgSkeletonRepresentation.cpp:248
SurgSim::Graphics::OsgSkeletonRepresentation::setSkinningShaderFileName
void setSkinningShaderFileName(const std::string &fileName)
Set the file containing the skinning shader.
Definition: OsgSkeletonRepresentation.cpp:218
SurgSim::Graphics::OsgSkeletonRepresentation::m_skinningShader
osg::ref_ptr< osg::Shader > m_skinningShader
The hardware skinning shader.
Definition: OsgSkeletonRepresentation.h:112
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
osg
Definition: OculusView.h:25
SurgSim::Graphics::OsgSkeletonRepresentation::m_skinningShaderFileName
std::string m_skinningShaderFileName
The file containing the skinning shader.
Definition: OsgSkeletonRepresentation.h:109
SurgSim::Graphics::SkeletonRepresentation
Skeleton representation is used to move a mesh based on the movements of pre-selected control points ...
Definition: SkeletonRepresentation.h:36
SurgSim::Graphics::OsgSkeletonRepresentation::getSkinningShaderFileName
std::string getSkinningShaderFileName() const
Definition: OsgSkeletonRepresentation.cpp:223
SurgSim::Graphics::OsgSkeletonRepresentation::m_root
osg::ref_ptr< osg::Node > m_root
The root node of the skeleton tree.
Definition: OsgSkeletonRepresentation.h:121
SurgSim::Graphics::OsgSkeletonRepresentation::doUpdate
void doUpdate(double dt) override
Definition: OsgSkeletonRepresentation.cpp:325
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgSkeletonRepresentation::m_skeleton
osg::ref_ptr< osg::Node > m_skeleton
The skeleton which is read from the mesh file.
Definition: OsgSkeletonRepresentation.h:106
SurgSim::Graphics::OsgSkeletonRepresentation::setBonePose
void setBonePose(const std::string &name, const SurgSim::Math::RigidTransform3d &pose) override
Set the pose for a given bone.
Definition: OsgSkeletonRepresentation.cpp:228
SurgSim::Graphics::OsgSkeletonRepresentation::m_logger
std::shared_ptr< SurgSim::Framework::Logger > m_logger
The logger for this class.
Definition: OsgSkeletonRepresentation.h:94
SurgSim::Graphics::OsgSkeletonRepresentation::getNeutralBonePoses
std::map< std::string, SurgSim::Math::RigidTransform3d > getNeutralBonePoses() const override
Get all the neutral poses.
Definition: OsgSkeletonRepresentation.cpp:313
SurgSim::Graphics::OsgSkeletonRepresentation::m_model
std::shared_ptr< OsgModel > m_model
The model containing the bone and mesh information.
Definition: OsgSkeletonRepresentation.h:97
SurgSim::Graphics::OsgSkeletonRepresentation::m_base
osg::ref_ptr< osg::MatrixTransform > m_base
The first MatrixTransform node.
Definition: OsgSkeletonRepresentation.h:124
SurgSim::Graphics::OsgSkeletonRepresentation::setNeutralBonePose
void setNeutralBonePose(const std::string &name, const SurgSim::Math::RigidTransform3d &pose) override
Set the neutral pose for a given bone.
Definition: OsgSkeletonRepresentation.cpp:266
SurgSim::Graphics::OsgSkeletonRepresentation::getModel
std::shared_ptr< Model > getModel() const override
Definition: OsgSkeletonRepresentation.cpp:213
SurgSim::Graphics::OsgSkeletonRepresentation::OsgSkeletonRepresentation
OsgSkeletonRepresentation(const std::string &name)
Constructor.
Definition: OsgSkeletonRepresentation.cpp:184
SurgSim::Graphics::OsgSkeletonRepresentation
Skeleton representation is used to move a mesh based on the movements of pre-selected control points ...
Definition: OsgSkeletonRepresentation.h:50
SurgSim::Graphics::OsgSkeletonRepresentation::m_updateVisitor
osg::ref_ptr< osgUtil::UpdateVisitor > m_updateVisitor
Tree updater which updates the position of the bones.
Definition: OsgSkeletonRepresentation.h:115
SkeletonRepresentation.h
SurgSim::Graphics::OsgSkeletonRepresentation::setModel
void setModel(std::shared_ptr< SurgSim::Framework::Asset > model) override
Set the current model to the model passed.
Definition: OsgSkeletonRepresentation.cpp:204
SurgSim::Graphics::OsgSkeletonRepresentation::m_bones
std::shared_ptr< std::map< std::string, BoneData > > m_bones
The named map of the bones in this skeleton.
Definition: OsgSkeletonRepresentation.h:100
SurgSim::Graphics::OsgSkeletonRepresentation::setNeutralBonePoses
void setNeutralBonePoses(const std::map< std::string, SurgSim::Math::RigidTransform3d > &poses) override
Set neutral poses for a set of bones.
Definition: OsgSkeletonRepresentation.cpp:305
SurgSim::Graphics::OsgSkeletonRepresentation::loadModel
void loadModel(const std::string &fileName) override
Convenience function to trigger the load of the model with the given filename, if successful,...
Definition: OsgSkeletonRepresentation.cpp:195
SurgSim::Graphics::OsgSkeletonRepresentation::m_mutex
boost::shared_mutex m_mutex
Mutex to access m_bones safely.
Definition: OsgSkeletonRepresentation.h:103
SurgSim::Graphics::OsgSkeletonRepresentation::getNeutralBonePose
SurgSim::Math::RigidTransform3d getNeutralBonePose(const std::string &name) const override
Get the neutral pose for a given bone.
Definition: OsgSkeletonRepresentation.cpp:287
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::OsgSkeletonRepresentation::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgSkeletonRepresentation)
OsgRepresentation.h
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55