DART 6.13.2
Loading...
Searching...
No Matches
Utils-impl.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, 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_DETAIL_UTILS_IMPL_HPP_
34#define DART_GUI_OSG_DETAIL_UTILS_IMPL_HPP_
35
37
38namespace dart::gui::osg {
39
40//==============================================================================
41template <typename T>
42constexpr T getAlphaThreshold()
43{
44 if constexpr (std::is_same_v<T, float>)
45 {
46 return 1e-6;
47 }
48 else if constexpr (std::is_same_v<T, double>)
49 {
50 return 1e-9;
51 }
52 else
53 {
54 return 1e-9;
55 }
56}
57
58//==============================================================================
59template <typename Scalar>
60::osg::Matrix eigToOsgMatrix(
61 const Eigen::Transform<Scalar, 3, Eigen::Isometry>& tf)
62{
63 return ::osg::Matrix(
64 tf(0, 0),
65 tf(1, 0),
66 tf(2, 0),
67 tf(3, 0),
68 tf(0, 1),
69 tf(1, 1),
70 tf(2, 1),
71 tf(3, 1),
72 tf(0, 2),
73 tf(1, 2),
74 tf(2, 2),
75 tf(3, 2),
76 tf(0, 3),
77 tf(1, 3),
78 tf(2, 3),
79 tf(3, 3));
80}
81
82//==============================================================================
83template <typename Derived>
84::osg::Matrix eigToOsgMatrix(const Eigen::DenseBase<Derived>& M)
85{
86 return ::osg::Matrix(
87 M(0, 0),
88 M(1, 0),
89 M(2, 0),
90 M(3, 0),
91 M(0, 1),
92 M(1, 1),
93 M(2, 1),
94 M(3, 1),
95 M(0, 2),
96 M(1, 2),
97 M(2, 2),
98 M(3, 2),
99 M(0, 3),
100 M(1, 3),
101 M(2, 3),
102 M(3, 3));
103}
104
105//==============================================================================
106template <typename Derived>
107::osg::Vec3f eigToOsgVec3f(const Eigen::MatrixBase<Derived>& vec)
108{
109 return ::osg::Vec3f(vec[0], vec[1], vec[2]);
110}
111
112//==============================================================================
113template <typename Derived>
114::osg::Vec3d eigToOsgVec3d(const Eigen::MatrixBase<Derived>& vec)
115{
116 return ::osg::Vec3d(vec[0], vec[1], vec[2]);
117}
118
119//==============================================================================
120template <typename Derived>
121typename std::conditional<
122 std::is_same<typename Derived::Scalar, float>::value,
123 ::osg::Vec3f,
124 ::osg::Vec3d>::type
125eigToOsgVec3(const Eigen::MatrixBase<Derived>& vec)
126{
127 using Vec3 = typename std::conditional<
128 std::is_same<typename Derived::Scalar, float>::value,
129 ::osg::Vec3f,
130 ::osg::Vec3d>::type;
131
132 return Vec3(vec[0], vec[1], vec[2]);
133}
134
135//==============================================================================
136template <typename Derived>
137::osg::Vec4f eigToOsgVec4f(const Eigen::MatrixBase<Derived>& vec)
138{
139 return ::osg::Vec4f(vec[0], vec[1], vec[2], vec[3]);
140}
141
142//==============================================================================
143template <typename Derived>
144::osg::Vec4d eigToOsgVec4d(const Eigen::MatrixBase<Derived>& vec)
145{
146 return ::osg::Vec4d(vec[0], vec[1], vec[2], vec[3]);
147}
148
149//==============================================================================
150template <typename Derived>
151std::conditional<
152 std::is_same<typename Derived::Scalar, float>::value,
153 ::osg::Vec4f,
154 ::osg::Vec4d>
155eigToOsgVec4(const Eigen::MatrixBase<Derived>& vec)
156{
157 return std::conditional<
158 std::is_same<typename Derived::Scalar, float>::value,
159 ::osg::Vec4f,
160 ::osg::Vec4d>(vec[0], vec[1], vec[2], vec[3]);
161}
162
163} // namespace dart::gui::osg
164
165#endif // DART_GUI_OSG_DETAIL_UTILS_IMPL_HPP_
std::string type
Definition SdfParser.cpp:82
Definition DefaultEventHandler.cpp:49
::osg::Vec3f eigToOsgVec3f(const Eigen::MatrixBase< Derived > &vec)
Converts Eigen::MatrixBase to osg::Vec3f.
Definition Utils-impl.hpp:107
::osg::Vec4f eigToOsgVec4f(const Eigen::MatrixBase< Derived > &vec)
Converts Eigen::MatrixBase to osg::Vec4f.
Definition Utils-impl.hpp:137
constexpr T getAlphaThreshold()
Returns the alpha threshold for demining if the object is a transparent object or not.
Definition Utils-impl.hpp:42
::osg::Matrix eigToOsgMatrix(const Eigen::Transform< Scalar, 3, Eigen::Isometry > &tf)
Converts Eigen::Isometry to osg::Matrix.
Definition Utils-impl.hpp:60
std::conditional< std::is_same< typename Derived::Scalar, float >::value, ::osg::Vec4f, ::osg::Vec4d > eigToOsgVec4(const Eigen::MatrixBase< Derived > &vec)
Converts Eigen::MatrixBase to osg::Vec4f or osg::Vec4d based on the scalar type.
Definition Utils-impl.hpp:155
::osg::Vec3d eigToOsgVec3d(const Eigen::MatrixBase< Derived > &vec)
Converts Eigen::MatrixBase to osg::Vec3d.
Definition Utils-impl.hpp:114
::osg::Vec4d eigToOsgVec4d(const Eigen::MatrixBase< Derived > &vec)
Converts Eigen::MatrixBase to osg::Vec4d.
Definition Utils-impl.hpp:144
std::conditional< std::is_same< typenameDerived::Scalar, float >::value,::osg::Vec3f,::osg::Vec3d >::type eigToOsgVec3(const Eigen::MatrixBase< Derived > &vec)
Converts Eigen::MatrixBase to osg::Vec3f or osg::Vec3d based on the scalar type.
Definition Utils-impl.hpp:125