14#include <Eigen/Eigenvalues>
62 result.
translation = other.template topRightCorner<3, 1>();
66 const auto& scaledR = other.template topLeftCorner<3, 3>();
67 result.
scale = scaledR.col(0).norm();
99 const T invScale = T(1) /
scale;
107 assert(transforms.size() == weights.size());
108 if (transforms.empty()) {
121 const auto n = transforms.size();
122 for (
size_t i = 0; i < n; ++i) {
123 const auto& q = transforms[i].rotation;
124 QtQ += weights[i] * (q.coeffs() * q.coeffs().transpose());
127 const Eigen::SelfAdjointEigenSolver<Matrix4<T>> eigDecomp(QtQ);
129 eigDecomp.eigenvalues()[2] <=
130 eigDecomp.eigenvalues()[3]);
131 Vector4<T> avgcoeffs = eigDecomp.eigenvectors().col(3);
132 assert(std::abs(avgcoeffs.norm() - 1) < 1e-4);
138 for (
size_t i = 0; i < n; ++i) {
139 pos += weights[i] * transforms[i].translation;
140 scale += weights[i] * transforms[i].scale;
141 weightSum += weights[i];
147 if (weightSum != 0) {
#define MT_CHECK(condition,...)
Runtime check macros with two interchangeable backends:
constexpr T Eps(T FloatEps=T(1e-7), T DoubleEps=T(1e-16))
Returns a type-appropriate tolerance/epsilon value.
T uniform(const T &min, const T &max)
Convenience wrappers that forward to Random<>::GetSingleton().
TransformT< T > slerp(const TransformT< T > &t1, const TransformT< T > &t2, T weight)
Spherical linear interpolation between two transforms.
Eigen::Matrix< T, 4, 4 > Matrix4
Eigen::Quaternion< T > Quaternion
Unit quaternion representing a 3D rotation.
gsl::span< T > span
Span type alias using gsl::span (C++17 fallback).
TransformT< T > blendTransforms(momentum::span< const TransformT< T > > transforms, momentum::span< const T > weights)
Weighted blend of transforms: rotations are blended via averaged quaternions, translations and scales...
Eigen::Transform< T, 3, Eigen::Affine > Affine3
3D affine transform (linear part + translation).