opensurgsim
OsgVectorConversions.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 
18 
19 #ifndef SURGSIM_GRAPHICS_OSGVECTORCONVERSIONS_H
20 #define SURGSIM_GRAPHICS_OSGVECTORCONVERSIONS_H
21 
22 #include "SurgSim/Math/Vector.h"
23 
24 #include <osg/Vec2f>
25 #include <osg/Vec2d>
26 #include <osg/Vec3f>
27 #include <osg/Vec3d>
28 #include <osg/Vec4f>
29 #include <osg/Vec4d>
30 
31 namespace SurgSim
32 {
33 
34 namespace Graphics
35 {
36 
38 inline osg::Vec2f toOsg(const SurgSim::Math::Vector2f& vector)
39 {
40  osg::Vec2f osgVector;
41  Eigen::Map<SurgSim::Math::Vector2f>(osgVector.ptr()) = vector;
42  return osgVector;
43 }
45 inline SurgSim::Math::Vector2f fromOsg(const osg::Vec2f& vector)
46 {
47  return SurgSim::Math::Vector2f(vector.ptr());
48 }
49 
51 inline osg::Vec2d toOsg(const SurgSim::Math::Vector2d& vector)
52 {
53  osg::Vec2d osgVector;
54  Eigen::Map<SurgSim::Math::Vector2d>(osgVector.ptr()) = vector;
55  return osgVector;
56 }
58 inline SurgSim::Math::Vector2d fromOsg(const osg::Vec2d& vector)
59 {
60  return SurgSim::Math::Vector2d(vector.ptr());
61 }
62 
64 inline osg::Vec3f toOsg(const SurgSim::Math::Vector3f& vector)
65 {
66  osg::Vec3f osgVector;
67  Eigen::Map<SurgSim::Math::Vector3f>(osgVector.ptr()) = vector;
68  return osgVector;
69 }
71 inline SurgSim::Math::Vector3f fromOsg(const osg::Vec3f& vector)
72 {
73  return SurgSim::Math::Vector3f(vector.ptr());
74 }
75 
77 inline osg::Vec3d toOsg(SurgSim::Math::Vector3d vector)
78 {
79  osg::Vec3d osgVector;
80  Eigen::Map<SurgSim::Math::Vector3d>(osgVector.ptr()) = vector;
81  return osgVector;
82 }
84 inline SurgSim::Math::Vector3d fromOsg(const osg::Vec3d& vector)
85 {
86  return SurgSim::Math::Vector3d(vector.ptr());
87 }
88 
89 
91 inline osg::Vec4f toOsg(const SurgSim::Math::Vector4f& vector)
92 {
93  osg::Vec4f osgVector;
94  Eigen::Map<SurgSim::Math::Vector4f>(osgVector.ptr()) = vector;
95  return osgVector;
96 }
98 inline SurgSim::Math::Vector4f fromOsg(const osg::Vec4f& vector)
99 {
100  return SurgSim::Math::Vector4f(vector.ptr());
101 }
102 
104 inline osg::Vec4d toOsg(const SurgSim::Math::Vector4d& vector)
105 {
106  osg::Vec4d osgVector;
107  Eigen::Map<SurgSim::Math::Vector4d>(osgVector.ptr()) = vector;
108  return osgVector;
109 }
111 inline SurgSim::Math::Vector4d fromOsg(const osg::Vec4d& vector)
112 {
113  return SurgSim::Math::Vector4d(vector.ptr());
114 }
115 
116 }; // namespace Graphics
117 
118 }; // namespace SurgSim
119 
120 #endif // SURGSIM_GRAPHICS_OSGVECTORCONVERSIONS_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
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
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::Matrix< float, 4, 1 > Vector4f
A 4D vector of floats.
Definition: Vector.h:45
Eigen::Matrix< double, 2, 1 > Vector2d
A 2D vector of doubles.
Definition: Vector.h:53
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
Eigen::Matrix< float, 2, 1 > Vector2f
A 2D vector of floats.
Definition: Vector.h:37
Definitions of small fixed-size vector types.