Momentum
A library for solving nonlinear optimization problems related to human body kinematics
Loading...
Searching...
No Matches
types.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 <bitset>
11#include <cstdint>
12#include <iterator>
13
14#ifdef _MSC_VER
15#pragma warning(push)
16#pragma warning(disable : 4456) // hidden local declaration
17#pragma warning(disable : 4702) // unreachable code
18#endif
19#include <Eigen/Core>
20#include <Eigen/Geometry>
21#include <Eigen/Sparse>
22#ifdef _MSC_VER
23#pragma warning(pop)
24#endif
25
27
28namespace Eigen {
30using Vector3b = Vector3<uint8_t>;
31} // namespace Eigen
32
33namespace momentum {
34
37inline constexpr int Dynamic = Eigen::Dynamic;
38
39template <class T>
40using Map = Eigen::Map<T>;
41
42template <class T>
43using Ref = Eigen::Ref<T>;
44
45template <typename Scalar, int Dim>
46using Line = Eigen::ParametrizedLine<Scalar, Dim>;
47
48template <typename Scalar, int Dim>
49using Plane = Eigen::Hyperplane<Scalar, Dim>;
50
51template <typename Scalar, int Dim>
52using Box = Eigen::AlignedBox<Scalar, Dim>;
53
54template <int Dim>
55using Boxf = Eigen::AlignedBox<float, Dim>;
56
57template <int Dim>
58using Boxd = Eigen::AlignedBox<double, Dim>;
59
60template <int Dim>
61using Boxi = Eigen::AlignedBox<std::int32_t, Dim>;
62
63template <typename T>
64using Box2 = Eigen::AlignedBox<T, 2>;
65template <typename T>
66using Box3 = Eigen::AlignedBox<T, 3>;
67
70
73
76
79template <typename T>
80using MatrixX = Eigen::Matrix<T, Dynamic, Dynamic>;
81
88
89template <typename T>
90using Matrix0 = Eigen::Matrix<T, 0, 0>;
91template <typename T>
92using Matrix1 = Eigen::Matrix<T, 1, 1>;
93template <typename T>
94using Matrix2 = Eigen::Matrix<T, 2, 2>;
95template <typename T>
96using Matrix3 = Eigen::Matrix<T, 3, 3>;
97template <typename T>
98using Matrix4 = Eigen::Matrix<T, 4, 4>;
99template <typename T>
100using Matrix5 = Eigen::Matrix<T, 5, 5>;
101template <typename T>
102using Matrix6 = Eigen::Matrix<T, 6, 6>;
103
111
119
127
135
143
151
155template <typename T>
156using Matrix3X = Eigen::Matrix<T, 3, Dynamic>;
163
164template <typename T>
165using MatrixX3 = Eigen::Matrix<T, Dynamic, 3>;
172
175template <typename T, int N, int M = N>
176using RowMatrix = Eigen::Matrix<T, N, M, Eigen::RowMajor>;
177template <typename T>
179
182template <typename T>
183using SparseMatrix = Eigen::SparseMatrix<T>;
190
191template <typename T>
192using SparseRowMatrix = Eigen::SparseMatrix<T, Eigen::RowMajor>;
199
202template <typename T, int Dim, int Options = 0>
203using Vector = Eigen::Matrix<T, Dim, 1, Options>;
204
206template <typename T>
208
215
216template <int Dim>
218template <int Dim>
220template <int Dim>
222template <int Dim>
224template <int Dim>
226template <int Dim>
228
229template <typename T>
231template <typename T>
233template <typename T>
235template <typename T>
237template <typename T>
239template <typename T>
241template <typename T>
243template <typename T>
245template <typename T>
247
257
265
273
281
289
297
298template <typename T, int Dim>
299using RowVector = Eigen::Matrix<T, 1, Dim>;
300template <typename T>
302
309
310template <typename T>
312template <typename T>
314template <typename T>
316template <typename T>
318template <typename T>
320template <typename T>
322template <typename T>
324
332
340
348
356
364
372
373template <typename T>
374using AngleAxis = Eigen::AngleAxis<T>;
377
384template <typename T>
385using Quaternion = Eigen::Quaternion<T>;
388
389template <typename T>
390using Translation3 = Eigen::Translation<T, 3>;
393
396template <typename T>
397using Isometry3 = Eigen::Transform<T, 3, Eigen::Isometry>;
400
403template <typename T>
404using Affine3 = Eigen::Transform<T, 3, Eigen::Affine>;
407
410using TransformationList = std::vector<Affine3f>;
412template <typename T>
413using TransformationListT = std::vector<Affine3<T>>;
414
424
427constexpr size_t kMaxModelParams = 2048;
430using ParameterSet = std::bitset<kMaxModelParams>;
431
452template <typename T>
456
465template <typename OtherScalar, template <typename...> class ContainerType, typename ObjectType>
466[[nodiscard]] decltype(auto) cast(const ContainerType<ObjectType>& originalContainer) {
467 using Scalar = typename ObjectType::Scalar;
468
469 if constexpr (std::is_same_v<OtherScalar, Scalar>) {
470 return originalContainer;
471 } else {
472 using CastedType = std::remove_const_t<
473 std::remove_reference_t<decltype(std::declval<ObjectType>().template cast<OtherScalar>())>>;
474
475 ContainerType<CastedType> castedContainer;
476 castedContainer.reserve(originalContainer.size());
477
478 std::transform(
479 originalContainer.begin(),
480 originalContainer.end(),
481 std::back_inserter(castedContainer),
482 [](const ObjectType& item) { return item.template cast<OtherScalar>(); });
483
484 return castedContainer;
485 }
486}
487
488} // namespace momentum
Definition types.h:28
Vector3< uint8_t > Vector3b
3D vector of unsigned bytes; commonly used for RGB color storage in momentum (see ColorArray).
Definition types.h:30
Vector2< float > Vector2f
Definition types.h:250
Vector< T, 4 > Vector4
Definition types.h:238
Vector1< std::int32_t > Vector1i
Definition types.h:291
Vector6< std::uint8_t > Vector6b
Definition types.h:272
Vector6< std::uint32_t > Vector6u
Definition types.h:288
Matrix6< double > Matrix6d
Definition types.h:118
Eigen::AlignedBox< T, 3 > Box3
Definition types.h:66
RowVector5< std::uint8_t > RowVector5b
Definition types.h:346
Eigen::AlignedBox< std::int32_t, Dim > Boxi
Definition types.h:61
Matrix3X< std::uint8_t > Matrix3Xb
Definition types.h:159
Vector3< double > Vector3d
Definition types.h:261
Matrix3< float > Matrix3f
Definition types.h:107
Matrix6< std::uint16_t > Matrix6s
Definition types.h:134
Quaternion< double > Quaterniond
Definition types.h:387
Vector2< std::uint16_t > Vector2s
Definition types.h:276
Matrix6< std::uint8_t > Matrix6b
Definition types.h:126
VectorX< std::uint32_t > VectorXu
Definition types.h:213
Affine3< float > Affine3f
Definition types.h:405
Vector4< std::uint8_t > Vector4b
Definition types.h:270
RowVector1< double > RowVector1d
Definition types.h:334
RowVector4< std::uint32_t > RowVector4u
Definition types.h:361
RowVector4< float > RowVector4f
Definition types.h:329
Quaternion< float > Quaternionf
Definition types.h:386
Vector2< std::uint8_t > Vector2b
Definition types.h:268
Matrix2< float > Matrix2f
Definition types.h:106
Vector8< float > Vector8f
Definition types.h:256
Matrix0< float > Matrix0f
Definition types.h:104
SparseRowMatrix< std::uint32_t > SparseRowMatrixu
Definition types.h:197
Vector4< double > Vector4d
Definition types.h:262
MatrixX< std::uint16_t > MatrixXs
Definition types.h:85
RowVector6< std::uint16_t > RowVector6s
Definition types.h:355
SparseMatrix< std::int32_t > SparseMatrixi
Definition types.h:189
Vector6< std::int32_t > Vector6i
Definition types.h:296
SparseRowMatrix< std::uint16_t > SparseRowMatrixs
Definition types.h:196
Translation3< float > Translation3f
Definition types.h:391
RowVector6< float > RowVector6f
Definition types.h:331
RowVector6< std::uint32_t > RowVector6u
Definition types.h:363
Vector< T, 7 > Vector7
Definition types.h:244
RowVector2< double > RowVector2d
Definition types.h:335
RowVector3< std::uint8_t > RowVector3b
Definition types.h:344
Matrix3X< std::int32_t > Matrix3Xi
Definition types.h:162
Eigen::AlignedBox< T, 2 > Box2
Definition types.h:64
SparseRowMatrix< double > SparseRowMatrixd
Definition types.h:194
constexpr size_t kMaxModelParams
Maximum number of model parameters supported per frame across any character.
Definition types.h:427
Vector0< float > Vector0f
Definition types.h:248
SparseMatrix< std::uint8_t > SparseMatrixb
Definition types.h:186
Matrix0< std::uint8_t > Matrix0b
Definition types.h:120
RowVectorX< std::int32_t > RowVectorXi
Definition types.h:308
RowVector3< double > RowVector3d
Definition types.h:336
RowVector2< std::uint32_t > RowVector2u
Definition types.h:359
Vector< float, Dim > Vectorf
Definition types.h:217
Vector1< std::uint8_t > Vector1b
Definition types.h:267
RowVector2< std::int32_t > RowVector2i
Definition types.h:367
Matrix6< std::int32_t > Matrix6i
Definition types.h:150
Vector5< float > Vector5f
Definition types.h:253
Vector2< std::uint32_t > Vector2u
Definition types.h:284
RowVector0< std::uint32_t > RowVector0u
Definition types.h:357
Eigen::Matrix< T, 3, Dynamic > Matrix3X
3-row, dynamic-column matrix.
Definition types.h:156
Eigen::Matrix< T, 3, 3 > Matrix3
Definition types.h:96
Vector< T, 5 > Vector5
Definition types.h:240
Matrix4< double > Matrix4d
Definition types.h:116
Vector6< double > Vector6d
Definition types.h:264
Vector4< std::uint16_t > Vector4s
Definition types.h:278
Vector< T, 1 > Vector1
Definition types.h:232
RowVector1< std::int32_t > RowVector1i
Definition types.h:366
Vector2< double > Vector2d
Definition types.h:260
Vector0< std::uint16_t > Vector0s
Definition types.h:274
RowVector1< float > RowVector1f
Definition types.h:326
RowVector3< std::uint32_t > RowVector3u
Definition types.h:360
Eigen::Matrix< T, 1, Dim > RowVector
Definition types.h:299
Box3< float > Box3f
Definition types.h:69
Matrix6< std::uint32_t > Matrix6u
Definition types.h:142
Eigen::Ref< T > Ref
Definition types.h:43
Matrix1< std::uint8_t > Matrix1b
Definition types.h:121
std::vector< Affine3f > TransformationList
One affine transform per joint, indexed by joint id.
Definition types.h:410
Eigen::Matrix< T, 0, 0 > Matrix0
Definition types.h:90
Eigen::ParametrizedLine< Scalar, Dim > Line
Definition types.h:46
Eigen::SparseMatrix< T, Eigen::RowMajor > SparseRowMatrix
Definition types.h:192
Vector3< std::uint8_t > Vector3b
Definition types.h:269
Eigen::AngleAxis< T > AngleAxis
Definition types.h:374
RowVector< T, 6 > RowVector6
Definition types.h:323
Vector< T, 0 > Vector0
Definition types.h:230
VectorX< std::int32_t > VectorXi
Definition types.h:214
Eigen::Matrix< T, 4, 4 > Matrix4
Definition types.h:98
Matrix2< double > Matrix2d
Definition types.h:114
Vector3< std::uint32_t > Vector3u
Definition types.h:285
Matrix3Xb ColorArray
Per-vertex RGB color in [0, 255] bytes (size: 3 x numVertices).
Definition types.h:423
MatrixX3< std::uint8_t > MatrixX3b
Definition types.h:168
Vector0< double > Vector0d
Definition types.h:258
RowVectorX< std::uint8_t > RowVectorXb
Definition types.h:305
RowVectorX< float > RowVectorXf
Definition types.h:303
Vector2< std::int32_t > Vector2i
Definition types.h:292
Box3< std::int32_t > Box3i
Definition types.h:75
Vector4< std::int32_t > Vector4i
Definition types.h:294
Matrix3Xi TriangleArray
Triangle index buffer; column i holds the three vertex indices of triangle i (size: 3 x numTriangles)...
Definition types.h:421
AngleAxis< double > AngleAxisd
Definition types.h:376
Matrix0< std::int32_t > Matrix0i
Definition types.h:144
Eigen::Matrix< T, Dynamic, 3 > MatrixX3
Definition types.h:165
Matrix2< std::uint8_t > Matrix2b
Definition types.h:122
MatrixX3< double > MatrixX3d
Definition types.h:167
Vector5< double > Vector5d
Definition types.h:263
Matrix3X< float > Matrix3Xf
Definition types.h:157
Vector< double, Dim > Vectord
Definition types.h:219
Box2< double > Box2d
Definition types.h:71
MatrixX< double > MatrixXd
Definition types.h:83
Matrix4< std::int32_t > Matrix4i
Definition types.h:148
RowVector4< std::uint8_t > RowVector4b
Definition types.h:345
MatrixX< std::uint8_t > MatrixXb
Definition types.h:84
Eigen::AlignedBox< Scalar, Dim > Box
Definition types.h:52
Eigen::Hyperplane< Scalar, Dim > Plane
Definition types.h:49
RowVector5< std::uint16_t > RowVector5s
Definition types.h:354
RowVector0< std::uint16_t > RowVector0s
Definition types.h:349
RowVector< T, Dynamic > RowVectorX
Definition types.h:301
Vector< std::uint16_t, Dim > Vectors
Definition types.h:223
RowVector< T, 1 > RowVector1
Definition types.h:313
VectorX< std::uint16_t > VectorXs
Definition types.h:212
Vector< std::int32_t, Dim > Vectori
Definition types.h:227
Eigen::AlignedBox< float, Dim > Boxf
Definition types.h:55
Vector7< float > Vector7f
Definition types.h:255
constexpr int Dynamic
Re-export of Eigen::Dynamic for use as a compile-time dimension token in momentum's type aliases (e....
Definition types.h:37
Vector< T, 2 > Vector2
Definition types.h:234
RowVector5< std::uint32_t > RowVector5u
Definition types.h:362
RowVectorX< double > RowVectorXd
Definition types.h:304
Matrix0< std::uint16_t > Matrix0s
Definition types.h:128
Vector< T, 6 > Vector6
Definition types.h:242
Vector5< std::uint32_t > Vector5u
Definition types.h:287
Eigen::Quaternion< T > Quaternion
Unit quaternion representing a 3D rotation.
Definition types.h:385
Matrix3Xf NormalArray
Per-vertex normals matching the layout of VertexArray (size: 3 x numVertices).
Definition types.h:418
Matrix3< std::uint32_t > Matrix3u
Definition types.h:139
SparseRowMatrix< std::int32_t > SparseRowMatrixi
Definition types.h:198
RowVector4< double > RowVector4d
Definition types.h:337
Vector4< std::uint32_t > Vector4u
Definition types.h:286
Vector4< float > Vector4f
Definition types.h:252
Matrix3< std::int32_t > Matrix3i
Definition types.h:147
Eigen::Matrix< T, 6, 6 > Matrix6
Definition types.h:102
Eigen::Matrix< T, Dynamic, Dynamic > MatrixX
Dynamic-size, column-major dense matrix.
Definition types.h:80
RowVector< T, 3 > RowVector3
Definition types.h:317
RowVector< T, 0 > RowVector0
Definition types.h:311
MatrixX3< std::uint16_t > MatrixX3s
Definition types.h:169
Vector1< std::uint16_t > Vector1s
Definition types.h:275
Vector< T, Dynamic > VectorX
Dynamic-size column vector. Common return type for solver residuals and parameter vectors.
Definition types.h:207
RowVector5< double > RowVector5d
Definition types.h:338
Matrix5< std::uint32_t > Matrix5u
Definition types.h:141
Eigen::SparseMatrix< T > SparseMatrix
Column-major sparse matrix.
Definition types.h:183
RowVector5< float > RowVector5f
Definition types.h:330
RowVector2< std::uint8_t > RowVector2b
Definition types.h:343
Matrix4< float > Matrix4f
Definition types.h:108
Eigen::Transform< T, 3, Eigen::Isometry > Isometry3
3D rigid transform (rotation + translation, no scale or shear).
Definition types.h:397
RowVector0< std::uint8_t > RowVector0b
Definition types.h:341
Isometry3< float > Isometry3f
Definition types.h:398
Matrix6< float > Matrix6f
Definition types.h:110
Vector0< std::uint8_t > Vector0b
Definition types.h:266
Eigen::Matrix< T, 1, 1 > Matrix1
Definition types.h:92
Vector6< float > Vector6f
Definition types.h:254
Eigen::Matrix< T, Dim, 1, Options > Vector
Column vector alias (an Nx1 Eigen matrix).
Definition types.h:203
Matrix5< std::uint8_t > Matrix5b
Definition types.h:125
Matrix5< std::uint16_t > Matrix5s
Definition types.h:133
RowVector1< std::uint32_t > RowVector1u
Definition types.h:358
Vector3< std::uint16_t > Vector3s
Definition types.h:277
Matrix1< std::uint32_t > Matrix1u
Definition types.h:137
Matrix0< double > Matrix0d
Definition types.h:112
Box2< float > Box2f
Definition types.h:68
Matrix1< double > Matrix1d
Definition types.h:113
RowVector1< std::uint8_t > RowVector1b
Definition types.h:342
RowVector0< std::int32_t > RowVector0i
Definition types.h:365
Matrix3< double > Matrix3d
Definition types.h:115
Matrix2< std::int32_t > Matrix2i
Definition types.h:146
Matrix1< std::uint16_t > Matrix1s
Definition types.h:129
RowVector0< double > RowVector0d
Definition types.h:333
RowVectorX< std::uint32_t > RowVectorXu
Definition types.h:307
MatrixX< std::int32_t > MatrixXi
Definition types.h:87
RowVector1< std::uint16_t > RowVector1s
Definition types.h:350
Vector1< std::uint32_t > Vector1u
Definition types.h:283
MatrixX3< std::uint32_t > MatrixX3u
Definition types.h:170
Box2< std::int32_t > Box2i
Definition types.h:74
Vector< T, 8 > Vector8
Definition types.h:246
Matrix1< float > Matrix1f
Definition types.h:105
RowVector2< std::uint16_t > RowVector2s
Definition types.h:351
SparseMatrix< std::uint32_t > SparseMatrixu
Definition types.h:188
Matrix3X< std::uint32_t > Matrix3Xu
Definition types.h:161
Isometry3< double > Isometry3d
Definition types.h:399
Eigen::Matrix< T, 5, 5 > Matrix5
Definition types.h:100
SparseMatrix< double > SparseMatrixd
Definition types.h:185
Affine3< double > Affine3d
Definition types.h:406
RowMatrix< T, Dynamic > RowMatrixX
Definition types.h:178
Matrix1< std::int32_t > Matrix1i
Definition types.h:145
RowVector3< float > RowVector3f
Definition types.h:328
RowVector3< std::uint16_t > RowVector3s
Definition types.h:352
Matrix5< double > Matrix5d
Definition types.h:117
gsl::span< T > span
Span type alias using gsl::span (C++17 fallback).
Definition span_compat.h:54
Eigen::Translation< T, 3 > Translation3
Definition types.h:390
Vector< std::uint32_t, Dim > Vectoru
Definition types.h:225
Matrix5< float > Matrix5f
Definition types.h:109
RowVector< T, 2 > RowVector2
Definition types.h:315
Vector3< std::int32_t > Vector3i
Definition types.h:293
Vector1< float > Vector1f
Definition types.h:249
Vector5< std::int32_t > Vector5i
Definition types.h:295
Matrix3X< std::uint16_t > Matrix3Xs
Definition types.h:160
SparseMatrix< std::uint16_t > SparseMatrixs
Definition types.h:187
RowVector0< float > RowVector0f
Definition types.h:325
Matrix3< std::uint8_t > Matrix3b
Definition types.h:123
RowVector6< std::int32_t > RowVector6i
Definition types.h:371
MatrixX3< float > MatrixX3f
Definition types.h:166
Vector< T, 3 > Vector3
Definition types.h:236
Vector3< float > Vector3f
Definition types.h:251
Matrix4< std::uint32_t > Matrix4u
Definition types.h:140
Matrix3< std::uint16_t > Matrix3s
Definition types.h:131
VectorX< double > VectorXd
Definition types.h:210
Matrix3Xf VertexArray
Mesh vertex positions; column i is the position of vertex i (size: 3 x numVertices).
Definition types.h:416
VectorX< float > VectorXf
Definition types.h:209
RowVector6< double > RowVector6d
Definition types.h:339
Matrix5< std::int32_t > Matrix5i
Definition types.h:149
VectorX< std::uint8_t > VectorXb
Definition types.h:211
Matrix0< std::uint32_t > Matrix0u
Definition types.h:136
Vector1< double > Vector1d
Definition types.h:259
std::vector< Affine3< T > > TransformationListT
Scalar-templated counterpart of TransformationList.
Definition types.h:413
Matrix4< std::uint16_t > Matrix4s
Definition types.h:132
Vector6< std::uint16_t > Vector6s
Definition types.h:280
Eigen::Matrix< T, N, M, Eigen::RowMajor > RowMatrix
Row-major dense matrix alias.
Definition types.h:176
SparseRowMatrix< std::uint8_t > SparseRowMatrixb
Definition types.h:195
RowVector2< float > RowVector2f
Definition types.h:327
Eigen::AlignedBox< double, Dim > Boxd
Definition types.h:58
RowVectorX< std::uint16_t > RowVectorXs
Definition types.h:306
std::bitset< kMaxModelParams > ParameterSet
Bitset for model parameter enablement.
Definition types.h:430
Matrix2< std::uint16_t > Matrix2s
Definition types.h:130
Vector5< std::uint16_t > Vector5s
Definition types.h:279
SparseMatrix< float > SparseMatrixf
Definition types.h:184
Vector0< std::uint32_t > Vector0u
Definition types.h:282
RowVector< T, 5 > RowVector5
Definition types.h:321
Eigen::Map< T > Map
Definition types.h:40
SparseRowMatrix< float > SparseRowMatrixf
Definition types.h:193
MatrixX< float > MatrixXf
Definition types.h:82
Matrix2< std::uint32_t > Matrix2u
Definition types.h:138
RowVector4< std::uint16_t > RowVector4s
Definition types.h:353
decltype(auto) cast(const ContainerType< ObjectType > &originalContainer)
Casts the scalar type of objects in a container that support the cast<>() method.
Definition types.h:466
Eigen::Transform< T, 3, Eigen::Affine > Affine3
3D affine transform (linear part + translation).
Definition types.h:404
Vector< std::uint8_t, Dim > Vectorb
Definition types.h:221
Matrix3X< double > Matrix3Xd
Definition types.h:158
Vector0< std::int32_t > Vector0i
Definition types.h:290
RowVector3< std::int32_t > RowVector3i
Definition types.h:368
Vector5< std::uint8_t > Vector5b
Definition types.h:271
Translation3< double > Translation3d
Definition types.h:392
MatrixX3< std::int32_t > MatrixX3i
Definition types.h:171
AngleAxis< float > AngleAxisf
Definition types.h:375
Eigen::Matrix< T, 2, 2 > Matrix2
Definition types.h:94
MatrixX< std::uint32_t > MatrixXu
Definition types.h:86
Box3< double > Box3d
Definition types.h:72
RowVector4< std::int32_t > RowVector4i
Definition types.h:369
RowVector< T, 4 > RowVector4
Definition types.h:319
RowVector5< std::int32_t > RowVector5i
Definition types.h:370
RowVector6< std::uint8_t > RowVector6b
Definition types.h:347
Matrix4< std::uint8_t > Matrix4b
Definition types.h:124
Provides a C++17-compatible span type alias.
A utility struct that facilitates the deduction of a momentum::span type from a given type.
Definition types.h:453
momentum::span< T > type
Definition types.h:454