opensurgsim
OsgRigidTransformConversions.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 
21 
22 #ifndef SURGSIM_GRAPHICS_OSGRIGIDTRANSFORMCONVERSIONS_H
23 #define SURGSIM_GRAPHICS_OSGRIGIDTRANSFORMCONVERSIONS_H
24 
29 #include "SurgSim/Math/Vector.h"
30 
31 #include <osg/Quat>
32 #include <osg/Vec2>
33 #include <osg/Vec3>
34 
35 namespace SurgSim
36 {
37 
38 namespace Graphics
39 {
40 
42 inline std::pair<osg::Quat, osg::Vec3f> toOsg(const SurgSim::Math::RigidTransform3f& transform)
43 {
44  SurgSim::Math::Quaternionf normalizedQuaternion = SurgSim::Math::Quaternionf(transform.linear()).normalized();
45  return std::make_pair(toOsg(normalizedQuaternion), toOsg(SurgSim::Math::Vector3f(transform.translation())));
46 }
48 inline std::pair<osg::Quat, osg::Vec3d> toOsg(const SurgSim::Math::RigidTransform3d& transform)
49 {
50  SurgSim::Math::Quaterniond normalizedQuaternion = SurgSim::Math::Quaterniond(transform.linear()).normalized();
51  return std::make_pair(toOsg(normalizedQuaternion), toOsg(SurgSim::Math::Vector3d(transform.translation())));
52 }
53 
55 inline SurgSim::Math::RigidTransform3f fromOsg(const osg::Quat& rotation, const osg::Vec3f& translation)
56 {
57  return SurgSim::Math::makeRigidTransform(fromOsg<float>(rotation), fromOsg(translation));
58 }
60 inline SurgSim::Math::RigidTransform3f fromOsg(const std::pair<osg::Quat, osg::Vec3f>& transform)
61 {
62  return fromOsg(transform.first, transform.second);
63 }
65 inline SurgSim::Math::RigidTransform3d fromOsg(const osg::Quat& rotation, const osg::Vec3d& translation)
66 {
67  return SurgSim::Math::makeRigidTransform(fromOsg<double>(rotation), fromOsg(translation));
68 }
70 inline SurgSim::Math::RigidTransform3d fromOsg(const std::pair<osg::Quat, osg::Vec3d>& transform)
71 {
72  return fromOsg(transform.first, transform.second);
73 }
74 
75 }; // namespace Graphics
76 
77 }; // namespace SurgSim
78 
79 #endif // SURGSIM_GRAPHICS_OSGRIGIDTRANSFORMCONVERSIONS_H
const Eigen::Matrix< float, 2, 2, Eigen::RowMajor > fromOsg(const osg::Matrix2 &matrix)
Convert from OSG to a 2x2 matrix of floats.
Definition: OsgMatrixConversions.h:73
Definitions of quaternion types.
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
Eigen::Matrix< float, 3, 1 > Vector3f
A 3D vector of floats.
Definition: Vector.h:41
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
Eigen::Quaternion< double > Quaterniond
A quaternion of doubles.
Definition: Quaternion.h:38
Eigen::Quaternion< float > Quaternionf
A quaternion of floats.
Definition: Quaternion.h:34
Eigen::Transform< float, 3, Eigen::Isometry > RigidTransform3f
A 3D rigid (isometric) transform, represented as floats.
Definition: RigidTransform.h:38
const osg::Matrix2 toOsg(const Eigen::Matrix< float, 2, 2, MOpt > &matrix)
Convert a fixed-size 2x2 matrix of floats to OSG.
Definition: OsgMatrixConversions.h:56
Conversions to and from OSG vector types.
Definitions of 2x2 and 3x3 rigid (isometric) transforms.
Conversions to and from OSG quaternion types.
Definitions of small fixed-size vector types.