Magnum::EigenIntegration namespace new in 2019.10

Integration with Eigen.

Conversion of math types from and to the Eigen library.

Usage

This library depends on the Eigen library and is built if MAGNUM_WITH_EIGEN is enabled when building Magnum Integration. To use this library with CMake, put FindMagnumIntegration.cmake into your modules/ directory, request the Eigen component of the MagnumIntegration package and link to the MagnumIntegration::Eigen target:

find_package(MagnumIntegration REQUIRED Eigen)

# ...
target_link_libraries(your-app PRIVATE MagnumIntegration::Eigen)

Additionally, if you're using Magnum as a CMake subproject, bundle the magnum-integration and eigen repositories and do the following before calling find_package(). If you want to use system-installed Eigen, omit the first part and point CMAKE_PREFIX_PATH to its installation dir if necessary.

set(EIGEN3_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/eigen)
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/eigen/cmake)

set(MAGNUM_WITH_EIGEN ON CACHE BOOL "" FORCE)
add_subdirectory(magnum-integration EXCLUDE_FROM_ALL)

See also Downloading and building integration libraries and Integration library usage with CMake for more information.

Type conversion

The library provides built-in conversion between Eigen's types and Magnum's own types. For example, an Eigen::Vector3f can be easily cast to Magnum's equivalent Vector3:

#include <Magnum/EigenIntegration/Integration.h>



Eigen::Vector3f a{1.0f, 2.0f, 3.0f};
Vector3 b(a);

auto c = Matrix4::rotation(35.0_degf, Vector3(a));

Or you can make a Containers::StridedArrayView2D onto a dynamically sized Eigen::MatrixXd and vice versa:

#include <Magnum/EigenIntegration/DynamicMatrixIntegration.h>



Eigen::MatrixXd data = ;
Containers::StridedArrayView2D<Double> view = EigenIntegration::arrayCast(data);

The integration routines are provided in the Magnum/EigenIntegration/Integration.h, Magnum/EigenIntegration/DynamicMatrixIntegration.h and Magnum/EigenIntegration/GeometryIntegration.h headers, see their documentation for more information.

Functions

template<class T>
auto arrayCast(const Containers::StridedArrayView2D<T>& from) -> Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>, Eigen::Unaligned, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>> new in Git master
Convert a Containers::StridedArrayView2D to Eigen's dynamic matrix type.
template<class T>
auto arrayCast(const Containers::StridedArrayView1D<T>& from) -> Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1>, Eigen::Unaligned, Eigen::InnerStride<>> new in Git master
Convert a Containers::StridedArrayView1D to Eigen's dynamic vector type.
template<class Derived>
auto arrayCast(const Eigen::DenseCoeffsBase<Derived, Eigen::DirectWriteAccessors>& from) -> std::enable_if<..., Containers::StridedArrayView1D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen expression to Containers::StridedArrayView1D.
template<class Derived>
auto arrayCast(const Eigen::DenseCoeffsBase<Derived, Eigen::DirectWriteAccessors>& from) -> std::enable_if<..., Containers::StridedArrayView2D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen expression to Containers::StridedArrayView2D.
template<class Derived, int Direction>
auto arrayCast(const Eigen::Reverse<Derived, Direction>& from) -> std::enable_if<..., Containers::StridedArrayView1D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen reverse expression to Containers::StridedArrayView1D.
template<class Derived, int Direction>
auto arrayCast(const Eigen::Reverse<Derived, Direction>& from) -> std::enable_if<..., Containers::StridedArrayView2D<typename Derived::Scalar>>::type new in Git master
Convert an Eigen reverse expression to Containers::StridedArrayView2D.
template<class To, class T>
auto cast(const Math::Quaternion<T>& from) -> To new in 2019.10
Convert a Magnum type to Eigen type.
template<class To, std::size_t cols, std::size_t rows, class T>
auto cast(const Math::RectangularMatrix<cols, rows, T>& from) -> To new in 2019.10
Convert a Magnum type to Eigen type.
template<class To, std::size_t size>
auto cast(const Math::BitVector<size>& from) -> To new in 2019.10
template<class To, std::size_t size, class T>
auto cast(const Math::Vector<size, T>& from) -> To new in 2019.10

Function documentation

template<class T>
Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic>, Eigen::Unaligned, Eigen::Stride<Eigen::Dynamic, Eigen::Dynamic>> Magnum::EigenIntegration::arrayCast(const Containers::StridedArrayView2D<T>& from) new in Git master

Convert a Containers::StridedArrayView2D to Eigen's dynamic matrix type.

template<class T>
Eigen::Map<Eigen::Matrix<T, Eigen::Dynamic, 1>, Eigen::Unaligned, Eigen::InnerStride<>> Magnum::EigenIntegration::arrayCast(const Containers::StridedArrayView1D<T>& from) new in Git master

Convert a Containers::StridedArrayView1D to Eigen's dynamic vector type.

Since for a one-dimensional Containers::StridedArrayView there is no column or row version, we always return an Eigen column vector.

template<class Derived>
std::enable_if<..., Containers::StridedArrayView1D<typename Derived::Scalar>>::type Magnum::EigenIntegration::arrayCast(const Eigen::DenseCoeffsBase<Derived, Eigen::DirectWriteAccessors>& from) new in Git master

Convert an Eigen expression to Containers::StridedArrayView1D.

If it is known at compile time that the Eigen expression has either one column or one row, then this function maps the Eigen expression to a Containers::StridedArrayView1D. Otherwise the overload below is picked, returning a Containers::StridedArrayView2D.

template<class Derived>
std::enable_if<..., Containers::StridedArrayView2D<typename Derived::Scalar>>::type Magnum::EigenIntegration::arrayCast(const Eigen::DenseCoeffsBase<Derived, Eigen::DirectWriteAccessors>& from) new in Git master

Convert an Eigen expression to Containers::StridedArrayView2D.

Takes care of any Eigen expression that was not handled by the one-dimensional overload above.

template<class Derived, int Direction>
std::enable_if<..., Containers::StridedArrayView1D<typename Derived::Scalar>>::type Magnum::EigenIntegration::arrayCast(const Eigen::Reverse<Derived, Direction>& from) new in Git master

Convert an Eigen reverse expression to Containers::StridedArrayView1D.

If it is known at compile time that the Eigen reverse expression has either one column or one row, then this function maps the Eigen reverse expression to a Containers::StridedArrayView1D. Otherwise the overload below is picked, returning a Containers::StridedArrayView2D.

template<class Derived, int Direction>
std::enable_if<..., Containers::StridedArrayView2D<typename Derived::Scalar>>::type Magnum::EigenIntegration::arrayCast(const Eigen::Reverse<Derived, Direction>& from) new in Git master

Convert an Eigen reverse expression to Containers::StridedArrayView2D.

Takes care of any Eigen expression that was not handled by the one-dimensional overload above.

template<class To, class T>
To Magnum::EigenIntegration::cast(const Math::Quaternion<T>& from) new in 2019.10

Convert a Magnum type to Eigen type.

Provided only for consistency with cast(const Math::RectangularMatrix<cols, rows, T>&), cast(const Math::BitVector<size>&) and cast(const Math::Vector<size, T>&) — conversion from Math::Quaternion to Eigen::Quaternion<T> can be done directly via an explicit conversion, unlike with matrices and vectors there's no need for a helper function.

template<class To, std::size_t cols, std::size_t rows, class T>
To Magnum::EigenIntegration::cast(const Math::RectangularMatrix<cols, rows, T>& from) new in 2019.10

Convert a Magnum type to Eigen type.

Due to the design of Eigen::Array and Eigen::Matrix classes, it's not possible to use the usual explicit conversion approach. See Magnum/EigenIntegration/Integration.h for more information.

template<class To, std::size_t size>
To Magnum::EigenIntegration::cast(const Math::BitVector<size>& from) new in 2019.10

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

template<class To, std::size_t size, class T>
To Magnum::EigenIntegration::cast(const Math::Vector<size, T>& from) new in 2019.10

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.