OsgSkeletonRepresentation.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_GRAPHICS_OSGSKELETONREPRESENTATION_H
#define SURGSIM_GRAPHICS_OSGSKELETONREPRESENTATION_H
#include <boost/thread.hpp>
#include <map>
#include <osg/MatrixTransform>
#include <osg/ref_ptr>
#include <osgUtil/UpdateVisitor>
#include <string>
#include "SurgSim/Graphics/OsgRepresentation.h"
#include "SurgSim/Graphics/SkeletonRepresentation.h"
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4250)
#endif
namespace osg
{
class Node;
class Shader;
};
namespace SurgSim
{
namespace Graphics
{
struct BoneData;
class OsgModel;
class OsgSkeletonRepresentation : public OsgRepresentation, public SkeletonRepresentation
{
public:
explicit OsgSkeletonRepresentation(const std::string& name);
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgSkeletonRepresentation);
void loadModel(const std::string& fileName) override;
void setModel(std::shared_ptr<SurgSim::Framework::Asset> model) override;
std::shared_ptr<Model> getModel() const override;
void setSkinningShaderFileName(const std::string& fileName);
std::string getSkinningShaderFileName() const;
void setBonePose(const std::string& name, const SurgSim::Math::RigidTransform3d& pose) override;
SurgSim::Math::RigidTransform3d getBonePose(const std::string& name) const override;
void setNeutralBonePose(const std::string& name, const SurgSim::Math::RigidTransform3d& pose) override;
SurgSim::Math::RigidTransform3d getNeutralBonePose(const std::string& name) const override;
protected:
void setNeutralBonePoses(const std::map<std::string, SurgSim::Math::RigidTransform3d>& poses) override;
std::map<std::string, SurgSim::Math::RigidTransform3d> getNeutralBonePoses() const override;
void doUpdate(double dt) override;
bool doInitialize() override;
private:
bool setupBones();
std::shared_ptr<SurgSim::Framework::Logger> m_logger;
std::shared_ptr<OsgModel> m_model;
std::shared_ptr<std::map<std::string, BoneData>> m_bones;
mutable boost::shared_mutex m_mutex;
osg::ref_ptr<osg::Node> m_skeleton;
std::string m_skinningShaderFileName;
osg::ref_ptr<osg::Shader> m_skinningShader;
osg::ref_ptr<osgUtil::UpdateVisitor> m_updateVisitor;
size_t m_frameCount;
osg::ref_ptr<osg::Node> m_root;
osg::ref_ptr<osg::MatrixTransform> m_base;
};
}; // namespace Graphics
}; // namespace SurgSim
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif // SURGSIM_GRAPHICS_OSGSKELETONREPRESENTATION_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
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::m_logger
std::shared_ptr< SurgSim::Framework::Logger > m_logger
The logger for this class.
Definition: OsgSkeletonRepresentation.h:94
SurgSim::Graphics::OsgSkeletonRepresentation::m_base
osg::ref_ptr< osg::MatrixTransform > m_base
The first MatrixTransform node.
Definition: OsgSkeletonRepresentation.h:124
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_skinningShader
osg::ref_ptr< osg::Shader > m_skinningShader
The hardware skinning shader.
Definition: OsgSkeletonRepresentation.h:112
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_CLASSNAME
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
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
SurgSim::Graphics::OsgSkeletonRepresentation::m_model
std::shared_ptr< OsgModel > m_model
The model containing the bone and mesh information.
Definition: OsgSkeletonRepresentation.h:97
SurgSim::Math::RigidTransform3d
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
SurgSim::Graphics::OsgSkeletonRepresentation::m_mutex
boost::shared_mutex m_mutex
Mutex to access m_bones safely.
Definition: OsgSkeletonRepresentation.h:103
SurgSim::Graphics::OsgSkeletonRepresentation::m_frameCount
size_t m_frameCount
Parameter to keep track of the skeleton&#39;s frame count. Set to the UpdateVisitor.
Definition: OsgSkeletonRepresentation.h:118
osg
Definition: OculusView.h:25
OsgRepresentation.h
SurgSim::Graphics::OsgSkeletonRepresentation::m_skinningShaderFileName
std::string m_skinningShaderFileName
The file containing the skinning shader.
Definition: OsgSkeletonRepresentation.h:109
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::m_root
osg::ref_ptr< osg::Node > m_root
The root node of the skeleton tree.
Definition: OsgSkeletonRepresentation.h:121
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
SkeletonRepresentation.h