OSVR-Core
MatrixEigenAssign.h
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 #ifndef INCLUDED_MatrixEigenAssign_h_GUID_23E844E3_DFBB_468C_1CD9_2BD88AA51871
26 #define INCLUDED_MatrixEigenAssign_h_GUID_23E844E3_DFBB_468C_1CD9_2BD88AA51871
27 
28 // Internal Includes
31 
32 // Library/third-party includes
33 // - none
34 
35 // Standard includes
36 // - none
37 
38 namespace osvr {
39 namespace util {
50  template <typename Scalar, typename T>
51  inline void matrixEigenAssign(T const &src, OSVR_MatrixConventions flags,
52  Scalar *dest) {
53  typedef Eigen::Matrix<Scalar, 4, 4> TargetType;
54  static_assert(!TargetType::IsRowMajor, "This and other code depends on "
55  "Eigen matrices being column "
56  "major by default");
57 
58  // These should all be fixed-size for speed, they're small.
59  EIGEN_STATIC_ASSERT_FIXED_SIZE(T);
60  // Make sure we have a 4x4 matrix
61  EIGEN_STATIC_ASSERT_MATRIX_SPECIFIC_SIZE(T, 4, 4);
62 
63  const bool needsTransposeFromColMaj =
64  detail::matrixNeedsTranspose(flags);
65  // If the source is a row-major matrix, then Eigen will automatically
66  // transpose to col-major (because that's what our "target type" is at
67  // compile time), so our transpose logic is flipped.
68  const bool needsTranspose = (T::IsRowMajor) ? !needsTransposeFromColMaj
69  : needsTransposeFromColMaj;
70  Eigen::Map<TargetType> destMat(dest);
71  if (needsTranspose) {
72  destMat = src.template cast<Scalar>().transpose();
73  } else {
74  destMat = src.template cast<Scalar>();
75  }
76  }
77 
78 } // namespace util
79 } // namespace osvr
80 
81 #endif // INCLUDED_MatrixEigenAssign_h_GUID_23E844E3_DFBB_468C_1CD9_2BD88AA51871
Definition: RunLoopManager.h:42
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:104
The main namespace for all C++ elements of the framework, internal and external.
Definition: namespace_osvr.dox:3
Header wrapping include of <Eigen/Core> and <Eigen/Geometry> for warning quieting.
uint16_t OSVR_MatrixConventions
Type for passing matrix convention flags.
Definition: MatrixConventionsC.h:54
A small structure to hold a non zero as a triplet (i,j,value).
Definition: SparseUtil.h:148
The matrix class, also used for vectors and row-vectors.
Definition: Matrix.h:127
void matrixEigenAssign(T const &src, OSVR_MatrixConventions flags, Scalar *dest)
Helper function template to assign/convert matrices as required.
Definition: MatrixEigenAssign.h:51