opensurgsim
SkeletonRepresentation.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_SKELETONREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_SKELETONREPRESENTATION_H
18 
19 #include <string>
20 
21 #include "SurgSim/Framework/FrameworkConvert.h"
22 #include "SurgSim/Graphics/Model.h"
23 #include "SurgSim/Graphics/Representation.h"
26 
27 
28 namespace SurgSim
29 {
30 
31 namespace Graphics
32 {
33 
36 class SkeletonRepresentation : public virtual Representation
37 {
38 public:
39 
42  explicit SkeletonRepresentation(const std::string& name): Representation(name)
43  {
44  SURGSIM_ADD_SERIALIZABLE_PROPERTY(SkeletonRepresentation, std::shared_ptr<SurgSim::Framework::Asset>,
46 
47  // Enables the alternative use of the model file instead of the actual mesh object
48  DecoderType decoder = std::bind(&SkeletonRepresentation::loadModel,
49  this,
50  std::bind(&YAML::Node::as<std::string>, std::placeholders::_1));
51  setDecoder("ModelFileName", decoder);
52 
53  SetterType setter = std::bind(&SkeletonRepresentation::loadModel,
54  this,
55  std::bind(SurgSim::Framework::convert<std::string>, std::placeholders::_1));
56 
57  setSetter("ModelFileName", setter);
58 
59  typedef std::map<std::string, SurgSim::Math::RigidTransform3d> PoseMap;
60  SURGSIM_ADD_SERIALIZABLE_PROPERTY(SkeletonRepresentation, PoseMap,
62  }
63 
67  virtual void loadModel(const std::string& fileName) = 0;
68 
71  virtual void setModel(std::shared_ptr<SurgSim::Framework::Asset> model) = 0;
72 
74  virtual std::shared_ptr<Model> getModel() const = 0;
75 
79  virtual void setBonePose(const std::string& name, const SurgSim::Math::RigidTransform3d& pose) = 0;
80 
84  virtual SurgSim::Math::RigidTransform3d getBonePose(const std::string& name) const = 0;
85 
89  virtual void setNeutralBonePose(const std::string& name, const SurgSim::Math::RigidTransform3d& pose) = 0;
90 
94  virtual SurgSim::Math::RigidTransform3d getNeutralBonePose(const std::string& name) const = 0;
95 
96 protected:
99  virtual void setNeutralBonePoses(const std::map<std::string, SurgSim::Math::RigidTransform3d>& poses) = 0;
100 
103  virtual std::map<std::string, SurgSim::Math::RigidTransform3d> getNeutralBonePoses() const = 0;
104 };
105 
106 }; // namespace Graphics
107 }; // namespace SurgSim
108 
109 #endif // SURGSIM_GRAPHICS_SKELETONREPRESENTATION_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
virtual std::map< std::string, SurgSim::Math::RigidTransform3d > getNeutralBonePoses() const =0
Get all the neutral poses.
Eigen::Transform< double, 3, Eigen::Isometry > RigidTransform3d
A 3D rigid (isometric) transform, represented as doubles.
Definition: RigidTransform.h:46
virtual void setBonePose(const std::string &name, const SurgSim::Math::RigidTransform3d &pose)=0
Set the pose for a given bone.
SkeletonRepresentation(const std::string &name)
Constructor.
Definition: SkeletonRepresentation.h:42
This contains a series of functions to encode and decode Eigen data structures to and from YAML nodes...
Skeleton representation is used to move a mesh based on the movements of pre-selected control points ...
Definition: SkeletonRepresentation.h:36
virtual void setModel(std::shared_ptr< SurgSim::Framework::Asset > model)=0
Set the current model to the model passed.
virtual std::shared_ptr< Model > getModel() const =0
Definition: Model.h:27
void setSetter(const std::string &name, SetterType func)
Sets a setter for a given property.
Definition: Accessible.cpp:80
Base graphics representation class, which defines the interface that all graphics representations mus...
Definition: Representation.h:40
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
virtual void loadModel(const std::string &fileName)=0
Convenience function to trigger the load of the model with the given filename, if successful...
virtual SurgSim::Math::RigidTransform3d getBonePose(const std::string &name) const =0
Get the pose for a given bone.
void setDecoder(const std::string &name, DecoderType decoder)
Sets the functions used to convert data from a YAML::Node.
Definition: Accessible.cpp:125
virtual void setNeutralBonePoses(const std::map< std::string, SurgSim::Math::RigidTransform3d > &poses)=0
Set neutral poses for a set of bones.
virtual void setNeutralBonePose(const std::string &name, const SurgSim::Math::RigidTransform3d &pose)=0
Set the neutral pose for a given bone.
virtual SurgSim::Math::RigidTransform3d getNeutralBonePose(const std::string &name) const =0
Get the neutral pose for a given bone.