OSVR Framework (Internal Development Docs)  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
MatrixConventionsC.cpp
Go to the documentation of this file.
1 
11 // Copyright 2015 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
29 #include <osvr/Util/EigenInterop.h>
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 // - none
37 
39 template <typename Scalar>
40 static inline OSVR_ReturnCode pose3toMatrix(OSVR_Pose3 const *pose,
42  Scalar *mat) {
43  if (!mat || !pose) {
44  return OSVR_RETURN_FAILURE;
45  }
46  auto xform = osvr::util::fromPose(*pose);
47  osvr::util::matrixEigenAssign(xform.matrix(), flags, mat);
48  return OSVR_RETURN_SUCCESS;
49 }
50 
51 OSVR_ReturnCode osvrPose3ToMatrixd(OSVR_Pose3 const *pose,
52  OSVR_MatrixConventions flags, double *mat) {
53  return pose3toMatrix(pose, flags, mat);
54 }
55 
56 OSVR_ReturnCode osvrPose3ToMatrixf(OSVR_Pose3 const *pose,
57  OSVR_MatrixConventions flags, float *mat) {
58  return pose3toMatrix(pose, flags, mat);
59 }
60 
61 namespace {
62 static_assert(!static_cast<bool>(Eigen::Matrix4d::IsRowMajor),
63  "This and related code in MatrixConventions assume Eigen is "
64  "still column-major by default.");
65 
66 static_assert((OSVR_MATRIX_MASK_ROWMAJOR | OSVR_MATRIX_MASK_ROWVECTORS |
67  OSVR_MATRIX_MASK_LHINPUT | OSVR_MATRIX_MASK_UNSIGNEDZ) ==
68  (OSVR_MATRIX_MASK_ROWMAJOR ^ OSVR_MATRIX_MASK_ROWVECTORS ^
69  OSVR_MATRIX_MASK_LHINPUT ^ OSVR_MATRIX_MASK_UNSIGNEDZ),
70  "Matrix convention masks must be independent!");
71 
72 using namespace osvr::util::detail;
73 static_assert(CompactMatrixConventions::ComputeBits<
74  CompactMatrixFlags::NeedsTranspose>::value == (0x1 << 0),
75  "Metafunction test");
76 static_assert(CompactMatrixConventions::ComputeBits<
77  CompactMatrixFlags::LeftHandInput>::value == (0x1 << 1),
78  "Metafunction test");
79 static_assert(CompactMatrixConventions::ComputeBits<
80  CompactMatrixFlags::UnsignedZ>::value == (0x1 << 2),
81  "Metafunction test");
82 static_assert(
83  CompactMatrixConventions::ComputeBits<
84  CompactMatrixFlags::NeedsTranspose, CompactMatrixFlags::LeftHandInput,
85  CompactMatrixFlags::UnsignedZ>::value == (1 + 2 + 4),
86  "Metafunction test");
87 } // namespace
OSVR_ReturnCode osvrPose3ToMatrixd(OSVR_Pose3 const *pose, OSVR_MatrixConventions flags, double *mat)
Set a matrix of doubles based on a Pose3.
Header wrapping include of and for warning quieting.
Eigen::Isometry3d fromPose(OSVR_Pose3 const &pose)
Turn an OSVR_Pose3 into an Eigen::Transform.
Definition: EigenInterop.h:81
uint16_t OSVR_MatrixConventions
Type for passing matrix convention flags.
#define OSVR_RETURN_FAILURE
The "failure" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:47
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
OSVR_ReturnCode osvrPose3ToMatrixf(OSVR_Pose3 const *pose, OSVR_MatrixConventions flags, float *mat)
Set a matrix of floats based on a Pose3.
A structure defining a 3D (6DOF) rigid body pose: translation and rotation.
Definition: Pose3C.h:54
Header for interoperation between the Eigen math library, the internal mini math library, and VRPN's quatlib.
void matrixEigenAssign(T const &src, OSVR_MatrixConventions flags, Scalar *dest)
Helper function template to assign/convert matrices as required.
double Scalar
Common scalar type.