Radium Engine  1.5.20
Loading...
Searching...
No Matches
PoseOperation.cpp
1#include <Core/Animation/PoseOperation.hpp>
2#include <Core/Math/Interpolation.hpp>
3
4#include <Eigen/Geometry>
5
6namespace Ra {
7namespace Core {
8namespace Animation {
9
10bool compatible( const Pose& p0, const Pose& p1 ) {
11 return ( p0.size() == p1.size() );
12}
13
14Pose relativePose( const Pose& modelPose, const RestPose& restPose ) {
15 CORE_ASSERT( compatible( modelPose, restPose ), " Poses with different size " );
16 Pose T( restPose.size() );
17#pragma omp parallel for
18 for ( int i = 0; i < int( T.size() ); ++i ) {
19 T[i] = modelPose[i] * restPose[i].inverse( Eigen::Affine );
20 }
21 return T;
22}
23
24Pose applyTransformation( const Pose& pose, const AlignedStdVector<Transform>& transform ) {
25 Pose T( std::min( pose.size(), transform.size() ) );
26#pragma omp parallel for
27 for ( int i = 0; i < int( T.size() ); ++i ) {
28 T[i] = transform[i] * pose[i];
29 }
30 return T;
31}
32
33Pose applyTransformation( const Pose& pose, const Transform& transform ) {
34 Pose T( pose.size() );
35#pragma omp parallel for
36 for ( int i = 0; i < int( T.size() ); ++i ) {
37 T[i] = transform * pose[i];
38 }
39 return T;
40}
41
42bool areEqual( const Pose& p0, const Pose& p1 ) {
43 CORE_ASSERT( compatible( p0, p1 ), " Poses with different size " );
44 const uint n = p0.size();
45 for ( uint i = 0; i < n; ++i ) {
46 if ( !p0[i].isApprox( p1[i] ) ) { return false; }
47 }
48 return true;
49}
50
51Pose interpolatePoses( const Pose& a, const Pose& b, const Scalar t ) {
52 CORE_ASSERT( ( a.size() == b.size() ), "Poses are wrong" );
53 CORE_ASSERT( ( ( t >= Scalar( 0. ) ) && ( t <= Scalar( 1. ) ) ), "T is wrong" );
54
55 const uint size = a.size();
56 Pose interpolatedPose( size );
57
58#pragma omp parallel for
59 for ( int i = 0; i < int( size ); ++i ) {
60 interpolatedPose[i] = Math::linearInterpolate( a[i], b[i], t );
61 }
62
63 return interpolatedPose;
64}
65
66} // namespace Animation
67} // namespace Core
68} // namespace Ra
T min(T... args)
T linearInterpolate(const T &v0, const T &v1, const Scalar t)
std::vector< T, Eigen::aligned_allocator< T > > AlignedStdVector
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3
T transform(T... args)