59template <
typename T,
class Data,
size_t FuncDim = 3>
82 const T& lossC = T(1));
97 for (
const auto& c : constraints) {
137 Eigen::Ref<Eigen::VectorX<T>> gradient)
override;
144 Eigen::Ref<Eigen::MatrixX<T>> jacobian,
145 Eigen::Ref<Eigen::VectorX<T>> residual,
146 int& usedRows)
override;
163 std::span<
const Eigen::Vector3<T>> worldVecs,
165 std::span<DfdvType> dfdv)
const = 0;
Implementation of "A General and Adaptive Robust Loss Function" (https://arxiv.org/abs/1701....
static constexpr T kL2
Special-case alpha values that are either at a singularity in the general formula or simplify to a cl...
SkeletonErrorFunctionT(const Skeleton &skel, const ParameterTransform &pt)
size_t getJacobianSize() const final
Returns the Jacobian size.
bool needsMesh() const final
double getError(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState) override
Computes the error.
virtual void evalFunction(size_t constrIndex, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, std::span< const Eigen::Vector3< T > > worldVecs, FuncType &f, std::span< DfdvType > dfdv) const =0
Computes the residual and derivatives.
void addConstraints(std::span< const VertexNormalDataT< T > > constraints)
VertexErrorFunctionT(const Character &character, const ParameterTransform ¶meterTransform, const T &lossAlpha=GeneralizedLossT< T >::kL2, const T &lossC=T(1))
Constructor.
void setMaxThreads(size_t maxThreads)
Sets the maximum number of threads for parallel execution.
GeneralizedLossT< T > loss_
size_t getNumConstraints() const
Returns the number of constraints.
const std::vector< Data > & getConstraints() const
Returns the current constraints.
std::vector< VertexNormalDataT< T > > constraints_
Eigen::Matrix< T, FuncDim, 1 > FuncType
double getGradient(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::VectorX< T > > gradient) override
Computes the gradient.
void setConstraints(std::span< const Data > constraints)
Sets all constraints, replacing existing ones.
Eigen::Matrix< T, FuncDim, 3 > DfdvType
void addConstraint(const VertexNormalDataT< T > &constraint)
const Character & character_
void clearConstraints()
Clears all constraints.
static constexpr size_t kFuncDim
static constexpr T kLegacyWeight
const Character * getCharacter() const final
Returns the character (needed for mesh-based computations).
double getJacobian(const ModelParametersT< T > ¶ms, const SkeletonStateT< T > &state, const MeshStateT< T > &meshState, Eigen::Ref< Eigen::MatrixX< T > > jacobian, Eigen::Ref< Eigen::VectorX< T > > residual, int &usedRows) override
Computes the Jacobian.
~VertexErrorFunctionT() override=default
Shared types used across error function hierarchies.
ParameterTransformT< float > ParameterTransform
gsl::span< T > span
Span type alias using gsl::span (C++17 fallback).
constexpr size_t kInvalidIndex
Sentinel value indicating an invalid or unset size_t index.
A character model with skeletal structure, mesh, and optional components.
Represents the complete state of a model's mesh.
A vector of size numModelParams holding the values of all model parameters for a character.
Represents the complete state of a skeleton.
VertexConstraintData(size_t vIndex, float w, const std::string &n="")
std::string name
Name of the constraint (for debugging).
VertexConstraintData()=default
float weight
Weight of the constraint.
size_t vertexIndex
Vertex index in the mesh.