STORM-IRIT / Radium-Engine

Research 3D Engine for rendering, animation and processing
https://storm-irit.github.io/Radium-Engine/
Apache License 2.0
100 stars 50 forks source link

Simple skinning #1021

Closed dlyr closed 1 year ago

dlyr commented 1 year ago

UPDATE the form below to describe your PR

codecov[bot] commented 1 year ago

Codecov Report

Merging #1021 (f44db6b) into release-candidate (f0cde85) will increase coverage by 0.06%. The diff coverage is 77.77%.

:exclamation: Current head f44db6b differs from pull request most recent head 857c8fc. Consider uploading reports for the commit 857c8fc to get more accurate results

@@                  Coverage Diff                  @@
##           release-candidate    #1021      +/-   ##
=====================================================
+ Coverage              45.59%   45.65%   +0.06%     
=====================================================
  Files                    341      342       +1     
  Lines                  22975    23014      +39     
=====================================================
+ Hits                   10475    10507      +32     
- Misses                 12500    12507       +7     
Impacted Files Coverage Δ
src/Engine/Scene/SkeletonComponent.cpp 0.00% <0.00%> (ø)
src/Engine/Scene/SkeletonComponent.hpp 0.00% <0.00%> (ø)
src/Engine/Scene/SkinningComponent.hpp 0.00% <0.00%> (ø)
src/Core/Geometry/MeshPrimitives.cpp 35.69% <100.00%> (+0.92%) :arrow_up:
src/Core/Math/LinearAlgebra.inl 90.74% <100.00%> (ø)
src/Core/Math/Math.hpp 100.00% <100.00%> (ø)
tests/unittest/Core/algebra.cpp 96.55% <100.00%> (+1.09%) :arrow_up:
src/Engine/Scene/GeometryComponent.inl 65.45% <0.00%> (-3.78%) :arrow_down:
src/Gui/Utils/KeyMappingManager.cpp 82.12% <0.00%> (+0.10%) :arrow_up:
src/Core/Geometry/TopologicalMesh.inl 89.27% <0.00%> (+1.87%) :arrow_up:

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

dlyr commented 1 year ago

I've tried to specialize template function for eigen matrix without success, for the record the pre non working implementation


/// Component-wise smoothstep() function on a floating-point vector.
/// \todo fix template resolution compared to scalar only version
/// https://www.fluentcpp.com/2017/08/11/how-to-do-partial-template-specialization-in-c/

template <typename DT, typename DU, typename DV>
inline typename DV::PlainMatrix
smoothstep<Eigen::MatrixBase<DT>, Eigen::MatrixBase<DU>, Eigen::MatrixBase<DV>>(
    const Eigen::MatrixBase<DT>& edge0,
    const Eigen::MatrixBase<DU>& edge1,
    const Eigen::MatrixBase<DV>& x ) {
    using std::clamp;
    typename DV::PlainMatrix t =
        clamp( ( x - edge0 ) / ( edge1 - edge0 ),
               DV::PlainMatrix::Constant( static_cast<typename DV::PlainMatrix::Scalar>( 0 ) ),
               DV::PlainMatrix::Constant( static_cast<typename DV::PlainMatrix::Scalar>( 1 ) ) );
    return t * t * ( 3.0 - 2.0 * t );
}

/// Component-wise smoothstep() function on a floating-point vector.
template <typename Derived>
inline typename Derived::PlainMatrix
smoothstep( const Scalar& edge0, const Scalar& edge1, const Eigen::MatrixBase<Derived>& v ) {
    return v.unaryExpr( [edge0, edge1]( Scalar x ) { return smoothstep( edge0, edge1, x ); } );
}
MathiasPaulin commented 1 year ago

I've tried to specialize template function for eigen matrix without success, for the record the pre non working implementation

Did you success ? I do not find the partial specialization for matrices in the PR. By specializing, do you mean specializing

template <typename T, typename V>
V smoothstep( T edge0, U edge1, V x )

(I do not understand why edge0 and edge1 should be different type) for the case V = Eigen::MatrixBase<W> for any W ?

did you try

template <typename T, template<typename W> typename V>
V<W> smoothstep( T edge0, U edge1, V<W> x ) { ... }

Perhaps I'm wrong but this is how I interpret the template template parameters https://en.cppreference.com/w/cpp/language/template_parameters#:~:text=since%20C%2B%2B20)-,Template,-template%20parameter

dlyr commented 1 year ago

It's not in the PR since I did not succeed. I've pasted my experiment here. right we can restrict to the same type for edge0 and edge1. The idea is to allow

smoothstep(scalar edge0, scalar edge1, scalar x);
smoothstep(scalar edge0, scalar edge1, vector x);
smoothstep(vector edge0, vector edge1, vector x);

as in glsl

I'll give a second try, but I think it's better to postpone to another pr.

dlyr commented 1 year ago

let's postpone. last try was

template <typename Derived>
inline typename Derived::PlainMatrix
smoothstep( const Scalar& edge0, const Scalar& edge1, const Eigen::MatrixBase<Derived>& v ) {
    return v.unaryExpr( [edge0, edge1]( Scalar x ) { return Ra::Core::Math::smoothstep( edge0, edge1, x ); } );
}

which gives

note: candidate template ignored: deduced conflicting types for parameter 'T' ('float' vs. 'Eigen::Matrix<float, 3, 1, 0, 3, 1>')
T smoothstep( T edge0, T edge1, T x ) {
  ^