DART 6.7.3
Loading...
Searching...
No Matches
Utils.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2019, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_GUI_OSG_UTILS_HPP_
34#define DART_GUI_OSG_UTILS_HPP_
35
36#include <Eigen/Geometry>
37
38#include <osg/Matrix>
39
40//==============================================================================
41template<typename Scalar>
42::osg::Matrix eigToOsgMatrix(const Eigen::Transform<Scalar,3,Eigen::Isometry>& tf)
43{
44 return ::osg::Matrix(
45 tf(0, 0), tf(1, 0), tf(2, 0), tf(3, 0),
46 tf(0, 1), tf(1, 1), tf(2, 1), tf(3, 1),
47 tf(0, 2), tf(1, 2), tf(2, 2), tf(3, 2),
48 tf(0, 3), tf(1, 3), tf(2, 3), tf(3, 3));
49}
50
51//==============================================================================
52template<typename Derived>
53::osg::Matrix eigToOsgMatrix(const Eigen::DenseBase<Derived>& M)
54{
55 return ::osg::Matrix(
56 M(0, 0), M(1, 0), M(2, 0), M(3, 0),
57 M(0, 1), M(1, 1), M(2, 1), M(3, 1),
58 M(0, 2), M(1, 2), M(2, 2), M(3, 2),
59 M(0, 3), M(1, 3), M(2, 3), M(3, 3));
60}
61
62//==============================================================================
63template<typename Derived>
64::osg::Vec3d eigToOsgVec3(const Eigen::MatrixBase<Derived>& vec)
65{
66 return ::osg::Vec3d(vec[0], vec[1], vec[2]);
67}
68
69//==============================================================================
70inline Eigen::Vector3d osgToEigVec3(const ::osg::Vec3d& vec)
71{
72 return Eigen::Vector3d(vec[0], vec[1], vec[2]);
73}
74
75//==============================================================================
76template<typename Derived>
77::osg::Vec4d eigToOsgVec4(const Eigen::MatrixBase<Derived>& vec)
78{
79 return ::osg::Vec4d(vec[0], vec[1], vec[2], vec[3]);
80}
81
82//==============================================================================
83inline Eigen::Vector4d osgToEigVec4(const ::osg::Vec4d& vec)
84{
85 return Eigen::Vector4d(vec[0], vec[1], vec[2], vec[3]);
86}
87
88#endif // DART_GUI_OSG_UTILS_HPP_
Eigen::Vector3d osgToEigVec3(const ::osg::Vec3d &vec)
Definition Utils.hpp:70
Eigen::Vector4d osgToEigVec4(const ::osg::Vec4d &vec)
Definition Utils.hpp:83
::osg::Vec4d eigToOsgVec4(const Eigen::MatrixBase< Derived > &vec)
Definition Utils.hpp:77
::osg::Vec3d eigToOsgVec3(const Eigen::MatrixBase< Derived > &vec)
Definition Utils.hpp:64
::osg::Matrix eigToOsgMatrix(const Eigen::Transform< Scalar, 3, Eigen::Isometry > &tf)
Definition Utils.hpp:42