20template <
typename Scalar,
size_t N,
typename Derived>
22 const std::vector<std::array<Scalar, N>> &from,
23 Eigen::PlainObjectBase<Derived> &to)
25 if (from.size() == 0) {
29 to.resize(from.size(), N);
30 for (
size_t i = 0; i < from.size(); ++i) {
31 for (
size_t j = 0; j < N; ++j) {
32 to(i, j) = from[i][j];
37template <
typename Scalar,
typename Derived>
39 const std::vector<std::pair<Scalar, Scalar>> &from,
40 Eigen::PlainObjectBase<Derived> &to)
42 if (from.size() == 0) {
46 to.resize(from.size(), 2);
47 for (
size_t i = 0; i < from.size(); ++i) {
48 to.row(i) << from[i].first, from[i].second;
52template <
typename Scalar,
int N,
typename Derived>
54 const std::vector<Eigen::Matrix<Scalar, N, 1>> &from,
55 Eigen::PlainObjectBase<Derived> &to)
57 if (from.size() == 0) {
61 to.resize(from.size(), N);
62 for (
size_t i = 0; i < from.size(); ++i) {
63 for (
size_t j = 0; j < N; ++j) {
64 to(i, j) = from[i][j];
69template <
typename Scalar,
int N,
typename Derived>
71 const std::vector<Eigen::Matrix<Scalar, 1, N>> &from,
72 Eigen::PlainObjectBase<Derived> &to)
74 if (from.size() == 0) {
78 to.resize(from.size(), N);
79 for (
size_t i = 0; i < from.size(); ++i) {
80 for (
size_t j = 0; j < N; ++j) {
81 to(i, j) = from[i][j];
86template <
typename Scalar>
87void vector_to_eigen(
const std::vector<Scalar> &from, Eigen::Matrix<Scalar, Eigen::Dynamic, 1> &to)
89 if (from.size() == 0) {
93 to.resize(from.size(), 1);
94 for (
size_t i = 0; i < from.size(); ++i) {
99template <
typename Scalar,
typename Derived>
100void flat_vector_to_eigen(
101 const std::vector<Scalar> &from,
102 Eigen::PlainObjectBase<Derived> &to,
105 int row_major_flag = Eigen::RowMajor)
108 to.resize(rows, cols);
109 const bool is_row_major = (row_major_flag & Eigen::RowMajor);
110 for (Eigen::Index i = 0; i < to.size(); ++i) {
111 size_t r = (is_row_major ? i / cols : i % rows);
112 size_t c = (is_row_major ? i % cols : i / rows);
117template <
typename Derived,
typename Scalar,
size_t N>
118void eigen_to_vector(
const Eigen::MatrixBase<Derived> &from, std::vector<std::array<Scalar, N>> &to)
120 if (from.cols() != N) {
121 throw std::invalid_argument(
"Wrong number of columns");
123 to.resize(from.rows());
124 for (
size_t i = 0; i < to.size(); ++i) {
125 for (
size_t j = 0; j < N; ++j) {
126 to[i][j] = from(i, j);
131template <
typename Derived,
typename Scalar>
133 const Eigen::MatrixBase<Derived> &from,
134 std::vector<std::pair<Scalar, Scalar>> &to)
136 if (from.cols() != 2) {
137 throw std::invalid_argument(
"Wrong number of columns");
139 to.resize(from.rows());
140 for (
size_t i = 0; i < to.size(); ++i) {
141 to[i] = std::make_pair(from[i][0], from[i][1]);
145template <
typename Derived,
typename Scalar>
146void eigen_to_flat_vector(
147 const Eigen::MatrixBase<Derived> &from,
148 std::vector<Scalar> &to,
149 int row_major_flag = Eigen::RowMajor)
151 to.resize(from.size());
152 const bool is_row_major = (row_major_flag & Eigen::RowMajor);
153 for (Eigen::Index i = 0; i < static_cast<Eigen::Index>(to.size()); ++i) {
154 Eigen::Index r = (is_row_major ? i / from.cols() : i % from.rows());
155 Eigen::Index c = (is_row_major ? i % from.cols() : i / from.rows());
#define la_runtime_assert(...)
Runtime assertion check.
Definition: assert.h:169
Main namespace for Lagrange.
Definition: AABBIGL.h:30