Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
eigen_adapters.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#pragma once
9
10#include <rerun.hpp>
11#include <Eigen/Core>
12
13#include <algorithm>
14#include <cstring>
15#include <vector>
16
17namespace rerun {
18
19// Rerun Adapter for Eigen::Vector3<T>
20template <typename TElement, typename T>
21struct CollectionAdapter<TElement, std::vector<Eigen::Vector3<T>>> {
23 Collection<TElement> operator()(const std::vector<Eigen::Vector3<T>>& container) {
24 return Collection<TElement>::borrow(container.data(), container.size());
25 }
26
27 // Do a full copy for temporaries (otherwise the data might be deleted when the temporary is
28 // destroyed).
29 Collection<TElement> operator()(std::vector<Eigen::Vector3<T>>&& container) {
30 std::vector<TElement> positions(container.size());
31 std::memcpy(positions.data(), container.data(), container.size() * sizeof(Eigen::Vector3<T>));
32 return Collection<TElement>::take_ownership(std::move(positions));
33 }
34};
35
36// Rerun Adapter for Eigen::Vector4<T>
37template <typename TElement, typename T>
38struct CollectionAdapter<TElement, std::vector<Eigen::Vector4<T>>> {
40 Collection<TElement> operator()(const std::vector<Eigen::Vector4<T>>& container) {
41 return Collection<TElement>::borrow(container.data(), container.size());
42 }
43
44 // Do a full copy for temporaries (otherwise the data might be deleted when the temporary is
45 // destroyed).
46 Collection<TElement> operator()(std::vector<Eigen::Vector4<T>>&& container) {
47 std::vector<TElement> positions(container.size());
48 std::memcpy(positions.data(), container.data(), container.size() * sizeof(Eigen::Vector4<T>));
49 return Collection<TElement>::take_ownership(std::move(positions));
50 }
51};
52
53// Adapter for converting a vector of Eigen::Vector3b to a vector of rerun::Color
54template <>
55struct CollectionAdapter<Color, std::vector<Eigen::Vector3<uint8_t>>> {
56 Collection<Color> operator()(const std::vector<Eigen::Vector3<uint8_t>>& container) {
57 std::vector<rerun::Color> colors;
58 colors.reserve(container.size());
59 std::transform(
60 container.cbegin(),
61 container.cend(),
62 std::back_inserter(colors),
63 [](const Eigen::Vector3<uint8_t>& vertexColor) {
64 return rerun::Color(vertexColor[0], vertexColor[1], vertexColor[2]);
65 });
66 return Collection<Color>::take_ownership(std::move(colors));
67 }
68};
69
70} // namespace rerun
Collection< Color > operator()(const std::vector< Eigen::Vector3< uint8_t > > &container)
Collection< TElement > operator()(std::vector< Eigen::Vector3< T > > &&container)
Collection< TElement > operator()(const std::vector< Eigen::Vector3< T > > &container)
Borrow for non-temporary.
Collection< TElement > operator()(const std::vector< Eigen::Vector4< T > > &container)
Borrow for non-temporary.
Collection< TElement > operator()(std::vector< Eigen::Vector4< T > > &&container)