Dem Bones  1.2.0
Skinning Decomposition Library
Dem::DemBonesExt< _Scalar, _AniMeshScalar > Class Template Reference

Extended class to handle hierarchical skeleton with local rotations/translations and bind matrices. More...

#include "DemBones/DemBonesExt.h"

Inheritance diagram for Dem::DemBonesExt< _Scalar, _AniMeshScalar >:
Dem::DemBones< _Scalar, _AniMeshScalar >

Public Types

using MatrixX = Eigen::Matrix< _Scalar, Eigen::Dynamic, Eigen::Dynamic >
 
using Matrix4 = Eigen::Matrix< _Scalar, 4, 4 >
 
using Matrix3 = Eigen::Matrix< _Scalar, 3, 3 >
 
using VectorX = Eigen::Matrix< _Scalar, Eigen::Dynamic, 1 >
 
using Vector4 = Eigen::Matrix< _Scalar, 4, 1 >
 
using Vector3 = Eigen::Matrix< _Scalar, 3, 1 >
 
using SparseMatrix = Eigen::SparseMatrix< _Scalar >
 
using Triplet = Eigen::Triplet< _Scalar >
 
- Public Types inherited from Dem::DemBones< _Scalar, _AniMeshScalar >
using MatrixX = Eigen::Matrix< _Scalar, Eigen::Dynamic, Eigen::Dynamic >
 
using Matrix4 = Eigen::Matrix< _Scalar, 4, 4 >
 
using Matrix3 = Eigen::Matrix< _Scalar, 3, 3 >
 
using VectorX = Eigen::Matrix< _Scalar, Eigen::Dynamic, 1 >
 
using Vector4 = Eigen::Matrix< _Scalar, 4, 1 >
 
using Vector3 = Eigen::Matrix< _Scalar, 3, 1 >
 
using SparseMatrix = Eigen::SparseMatrix< _Scalar >
 
using Triplet = Eigen::Triplet< _Scalar >
 

Public Member Functions

 DemBonesExt ()
 Constructor and setting default parameters. More...
 
void clear ()
 Clear all data. More...
 
void computeRTB (int s, MatrixX &lr, MatrixX &lt, MatrixX &gb, MatrixX &lbr, MatrixX &lbt, bool degreeRot=true)
 Local rotations, translations and global bind matrices of a subject. More...
 
- Public Member Functions inherited from Dem::DemBones< _Scalar, _AniMeshScalar >
 DemBones ()
 Constructor and setting default parameters. More...
 
void clear ()
 Clear all data. More...
 
void init ()
 Initialize missing skinning weights and/or bone transformations. More...
 
void computeTranformations ()
 Update bone transformations by running nTransIters iterations with transAffine and transAffineNorm regularizers. More...
 
void computeWeights ()
 Update skinning weights by running nWeightsIters iterations with weightsSmooth and weightsSmoothStep regularizers. More...
 
void compute ()
 Skinning decomposition by nIters iterations of alternative updating weights and bone transformations. More...
 
_Scalar rmse ()
 
virtual void cbInitSplitBegin ()
 Callback function invoked before each spliting of bone clusters in initialization. More...
 
virtual void cbInitSplitEnd ()
 Callback function invoked after each spliting of bone clusters in initialization. More...
 
virtual void cbIterBegin ()
 Callback function invoked before each global iteration update. More...
 
virtual bool cbIterEnd ()
 Callback function invoked after each global iteration update, stop iteration if return true. More...
 
virtual void cbWeightsBegin ()
 Callback function invoked before each skinning weights update. More...
 
virtual void cbWeightsEnd ()
 Callback function invoked after each skinning weights update. More...
 
virtual void cbTranformationsBegin ()
 Callback function invoked before each bone transformations update. More...
 
virtual void cbTransformationsEnd ()
 Callback function invoked after each bone transformations update. More...
 
virtual void cbTransformationsIterBegin ()
 Callback function invoked before each local bone transformations update iteration. More...
 
virtual bool cbTransformationsIterEnd ()
 Callback function invoked after each local bone transformations update iteration, stop iteration if return true. More...
 
virtual void cbWeightsIterBegin ()
 Callback function invoked before each local weights update iteration. More...
 
virtual bool cbWeightsIterEnd ()
 Callback function invoked after each local weights update iteration, stop iteration if return true. More...
 

Public Attributes

Eigen::VectorXd fTime
 Timestamps for bone transformations m, [size] = nS, fTime(k) is the timestamp of frame k. More...
 
std::vector< std::string > boneName
 Name of bones, [size] = nB, boneName(j) is the name bone of j. More...
 
Eigen::VectorXi parent
 Parent bone index, [size] = nB, parent(j) is the index of parent bone of j, parent(j) = -1 if j has no parent. More...
 
MatrixX bind
 Original bind pre-matrix, [size] = [4*nS, 4*nB], bind.block(4*s, 4*j, 4, 4) is the global bind matrix of bone j on subject s at the rest pose. More...
 
MatrixX preMulInv
 Inverse pre-multiplication matrices, [size] = [4*nS, 4*nB], preMulInv.block(4*s, 4*j, 4, 4) is the inverse of pre-local transformation of bone j on subject s. More...
 
Eigen::MatrixXi rotOrder
 Rotation order, [size] = [3*nS, nB], rotOrder.col(j).segment<3>(3*s) is the rotation order of bone j on subject s, 0=X, 1=Y, 2=Z, e.g. {0, 1, 2} is XYZ order
More...
 
MatrixX orient
 Orientations of bones, [size] = [3*nS, nB], orient.col(j).segment<3>(3*s) is the(rx, ry, rz) orientation of bone j in degree. More...
 
int bindUpdate
 Bind transformation update, 0=keep original, 1=set translations to p-norm centroids (using transAffineNorm) and rotations to identity, 2=do 1 and group joints. More...
 
- Public Attributes inherited from Dem::DemBones< _Scalar, _AniMeshScalar >
int nIters
 [parameter] Number of global iterations, default = 30 More...
 
int nInitIters
 [parameter] Number of clustering update iterations in the initalization, default = 10 More...
 
int nTransIters
 [parameter] Number of bone transformations update iterations per global iteration, default = 5 More...
 
_Scalar transAffine
 [parameter] Translations affinity soft constraint, default = 10.0 More...
 
_Scalar transAffineNorm
 [parameter] p-norm for bone translations affinity soft constraint, default = 4.0 More...
 
int nWeightsIters
 [parameter] Number of weights update iterations per global iteration, default = 3 More...
 
int nnz
 [parameter] Number of non-zero weights per vertex, default = 8 More...
 
_Scalar weightsSmooth
 [parameter] Weights smoothness soft constraint, default = 1e-4 More...
 
_Scalar weightsSmoothStep
 [parameter] Step size for the weights smoothness soft constraint, default = 1.0 More...
 
_Scalar weightEps
 [parameter] Epsilon for weights solver, default = 1e-15 More...
 
int nV
 Number of vertices, typically indexed by i. More...
 
int nB
 Number of bones, typically indexed by j. More...
 
int nS
 Number of subjects, typically indexed by s. More...
 
int nF
 Number of total frames, typically indexed by k, nF = fStart(nS) More...
 
Eigen::VectorXi fStart
 Start frame indices, size = nS+1, fStart(s), fStart(s+1) are data frames for subject s. More...
 
Eigen::VectorXi subjectID
 Subject index of the frame, size = nF, subjectID(k)=s, where fStart(s) <= k < fStart(s+1) More...
 
MatrixX u
 Geometry at the rest poses, size = [3*nS, nV], u.col(i).segment(3*s, 3) is the rest pose of vertex i of subject s. More...
 
SparseMatrix w
 Skinning weights, size = [nB, nV], w.col(i) are the skinning weights of vertex i, w(j, i) is the influence of bone j to vertex i. More...
 
VectorX lockW
 Skinning weights lock control, size = nV, lockW(i) is the amount of input skinning weights will be kept for vertex i, where 0 (no lock) <= lockW(i) <= 1 (full lock) More...
 
MatrixX m
 Bone transformations, size = [4*nF*4, 4*nB], m.blk4(k, j) is the 4*4 relative transformation matrix of bone j at frame k. More...
 
Eigen::VectorXi lockM
 Bone transformation lock control, size = nB, lockM(j) is the amount of input transformations will be kept for bone j, where lockM(j) = 0 (no lock) or 1 (lock) More...
 
Eigen::Matrix< _AniMeshScalar, Eigen::Dynamic, Eigen::Dynamic > v
 Animated mesh sequence, size = [3*nF, nV], v.col(i).segment(3*k, 3) is the position of vertex i at frame k. More...
 
std::vector< std::vector< int > > fv
 Mesh topology, size=[number of polygons], fv[p] is the vector of vertex indices of polygon p. More...
 
const int & iter
 [zero indexed, read only] Current global iteration number that can be used for callback functions More...
 
const int & iterTransformations
 [zero indexed, read only] Current bone transformations update iteration number that can be used for callback functions More...
 
const int & iterWeights
 [zero indexed, read only] Current weights update iteration number that can be used for callback functions More...
 

Detailed Description

template<class _Scalar, class _AniMeshScalar>
class Dem::DemBonesExt< _Scalar, _AniMeshScalar >

Extended class to handle hierarchical skeleton with local rotations/translations and bind matrices.

Call computeRTB() to get local rotations/translations and bind matrices after skinning decomposition is done and other data is set.

_Scalar is the floating-point data type. _AniMeshScalar is the floating-point data type of mesh sequence v.

Definition at line 31 of file DemBonesExt.h.

Member Typedef Documentation

◆ Matrix3

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::Matrix3 = Eigen::Matrix<_Scalar, 3, 3>

Definition at line 37 of file DemBonesExt.h.

◆ Matrix4

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::Matrix4 = Eigen::Matrix<_Scalar, 4, 4>

Definition at line 36 of file DemBonesExt.h.

◆ MatrixX

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::MatrixX = Eigen::Matrix<_Scalar, Eigen::Dynamic, Eigen::Dynamic>

Definition at line 35 of file DemBonesExt.h.

◆ SparseMatrix

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::SparseMatrix = Eigen::SparseMatrix<_Scalar>

Definition at line 41 of file DemBonesExt.h.

◆ Triplet

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::Triplet = Eigen::Triplet<_Scalar>

Definition at line 42 of file DemBonesExt.h.

◆ Vector3

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::Vector3 = Eigen::Matrix<_Scalar, 3, 1>

Definition at line 40 of file DemBonesExt.h.

◆ Vector4

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::Vector4 = Eigen::Matrix<_Scalar, 4, 1>

Definition at line 39 of file DemBonesExt.h.

◆ VectorX

template<class _Scalar , class _AniMeshScalar >
using Dem::DemBonesExt< _Scalar, _AniMeshScalar >::VectorX = Eigen::Matrix<_Scalar, Eigen::Dynamic, 1>

Definition at line 38 of file DemBonesExt.h.

Constructor & Destructor Documentation

◆ DemBonesExt()

template<class _Scalar , class _AniMeshScalar >
Dem::DemBonesExt< _Scalar, _AniMeshScalar >::DemBonesExt ( )
inline

Constructor and setting default parameters.

Definition at line 99 of file DemBonesExt.h.

99  : bindUpdate(0) {
100  clear();
101  }

Member Function Documentation

◆ clear()

template<class _Scalar , class _AniMeshScalar >
void Dem::DemBonesExt< _Scalar, _AniMeshScalar >::clear ( )
inline

Clear all data.

Definition at line 105 of file DemBonesExt.h.

105  {
106  fTime.resize(0);
107  boneName.resize(0);
108  parent.resize(0);
109  bind.resize(0, 0);
110  preMulInv.resize(0, 0);
111  rotOrder.resize(0, 0);
112  orient.resize(0, 0);
114  }

◆ computeRTB()

template<class _Scalar , class _AniMeshScalar >
void Dem::DemBonesExt< _Scalar, _AniMeshScalar >::computeRTB ( int  s,
MatrixX lr,
MatrixX lt,
MatrixX gb,
MatrixX lbr,
MatrixX lbt,
bool  degreeRot = true 
)
inline

Local rotations, translations and global bind matrices of a subject.

Required all data in the base class: u, fv, nV, v, nF, fStart, subjectID, nS, m, w, nB

This function will initialize missing attributes:

  • parent: -1 vector (if no joint grouping) or parent to a root, [size] = nB
  • preMulInv: 4*4 identity matrix blocks, [size] = [4*nS, 4*nB]
  • rotOrder: {0, 1, 2} vector blocks, [size] = [3*nS, nB]
  • orient: 0 matrix, [size] = [3*nS, nB]
Parameters
[in]sis the subject index
[out]lris the [3*nFr, nB] by-reference output local rotations, lr.col(j).segment<3>(3*k) is the (rx, ry, rz) of bone j at frame k
[out]ltis the [3*nFr, nB] by-reference output local translations, lt.col(j).segment<3>(3*k) is the (tx, ty, tz) of bone j at frame k
[out]gbis the [4, 4*nB] by-reference output global bind matrices, gb.block(0, 4*j, 4, 4) is the bind matrix of bone j
[out]lbris the [3, nB] by-reference output local rotations at bind pose lbr.col(j).segment<3>(3*k) is the (rx, ry, rz) of bone j
[out]lbtis the [3, nB] by-reference output local translations at bind pose, lbt.col(j).segment<3>(3*k) is the (tx, ty, tz) of bone j
[in]degreeRot=truewill output rotations in degree, otherwise output in radian

Definition at line 133 of file DemBonesExt.h.

133  {
134  computeBind(s, gb);
135 
136  if (parent.size()==0) {
137  if (bindUpdate==2) {
138  int root=computeRoot();
139  parent=Eigen::VectorXi::Constant(nB, root);
140  parent(root)=-1;
141  } else parent=Eigen::VectorXi::Constant(nB, -1);
142  }
143  if (preMulInv.size()==0) preMulInv=MatrixX::Identity(4, 4).replicate(nS, nB);
144  if (rotOrder.size()==0) rotOrder=Eigen::Vector3i(0, 1, 2).replicate(nS, nB);
145  if (orient.size()==0) orient=MatrixX::Zero(3*nS, nB);
146 
147  int nFs=fStart(s+1)-fStart(s);
148  lr.resize(nFs*3, nB);
149  lt.resize(nFs*3, nB);
150  lbr.resize(3, nB);
151  lbt.resize(3, nB);
152 
153  MatrixX lm(4*nFs, 4*nB);
154  #pragma omp parallel for
155  for (int j=0; j<nB; j++) {
156  Eigen::Vector3i ro=rotOrder.col(j).template segment<3>(s*3);
157 
158  Vector3 ov=orient.vec3(s, j)*EIGEN_PI/180;
159  Matrix3 invOM=Matrix3(Eigen::AngleAxis<_Scalar>(ov(ro(2)), Vector3::Unit(ro(2))))*
160  Eigen::AngleAxis<_Scalar>(ov(ro(1)), Vector3::Unit(ro(1)))*
161  Eigen::AngleAxis<_Scalar>(ov(ro(0)), Vector3::Unit(ro(0)));
162  invOM.transposeInPlace();
163 
164  Matrix4 lb;
165  if (parent(j)==-1) lb=preMulInv.blk4(s, j)*gb.blk4(0, j);
166  else lb=preMulInv.blk4(s, j)*gb.blk4(0, parent(j)).inverse()*gb.blk4(0, j);
167 
168  Vector3 curRot=Vector3::Zero();
169  toRot(invOM*lb.template topLeftCorner<3, 3>(), curRot, ro);
170  lbr.col(j)=curRot;
171  lbt.col(j)=lb.template topRightCorner<3, 1>();
172 
173  Matrix4 lm;
174  for (int k=0; k<nFs; k++) {
175  if (parent(j)==-1) lm=preMulInv.blk4(s, j)*m.blk4(k+fStart(s), j)*gb.blk4(0, j);
176  else lm=preMulInv.blk4(s, j)*(m.blk4(k+fStart(s), parent(j))*gb.blk4(0, parent(j))).inverse()*m.blk4(k+fStart(s), j)*gb.blk4(0, j);
177  toRot(invOM*lm.template topLeftCorner<3, 3>(), curRot, ro);
178  lr.vec3(k, j)=curRot;
179  lt.vec3(k, j)=lm.template topRightCorner<3, 1>();
180  }
181  }
182 
183  if (degreeRot) {
184  lr*=180/EIGEN_PI;
185  lbr*=180/EIGEN_PI;
186  }
187  }

Member Data Documentation

◆ bind

template<class _Scalar , class _AniMeshScalar >
MatrixX Dem::DemBonesExt< _Scalar, _AniMeshScalar >::bind

Original bind pre-matrix, [size] = [4*nS, 4*nB], bind.block(4*s, 4*j, 4, 4) is the global bind matrix of bone j on subject s at the rest pose.

Definition at line 83 of file DemBonesExt.h.

◆ bindUpdate

template<class _Scalar , class _AniMeshScalar >
int Dem::DemBonesExt< _Scalar, _AniMeshScalar >::bindUpdate

Bind transformation update, 0=keep original, 1=set translations to p-norm centroids (using transAffineNorm) and rotations to identity, 2=do 1 and group joints.

Definition at line 95 of file DemBonesExt.h.

◆ boneName

template<class _Scalar , class _AniMeshScalar >
std::vector<std::string> Dem::DemBonesExt< _Scalar, _AniMeshScalar >::boneName

Name of bones, [size] = nB, boneName(j) is the name bone of j.

Definition at line 77 of file DemBonesExt.h.

◆ fTime

template<class _Scalar , class _AniMeshScalar >
Eigen::VectorXd Dem::DemBonesExt< _Scalar, _AniMeshScalar >::fTime

Timestamps for bone transformations m, [size] = nS, fTime(k) is the timestamp of frame k.

Definition at line 74 of file DemBonesExt.h.

◆ orient

template<class _Scalar , class _AniMeshScalar >
MatrixX Dem::DemBonesExt< _Scalar, _AniMeshScalar >::orient

Orientations of bones, [size] = [3*nS, nB], orient.col(j).segment<3>(3*s) is the(rx, ry, rz) orientation of bone j in degree.

Definition at line 92 of file DemBonesExt.h.

◆ parent

template<class _Scalar , class _AniMeshScalar >
Eigen::VectorXi Dem::DemBonesExt< _Scalar, _AniMeshScalar >::parent

Parent bone index, [size] = nB, parent(j) is the index of parent bone of j, parent(j) = -1 if j has no parent.

Definition at line 80 of file DemBonesExt.h.

◆ preMulInv

template<class _Scalar , class _AniMeshScalar >
MatrixX Dem::DemBonesExt< _Scalar, _AniMeshScalar >::preMulInv

Inverse pre-multiplication matrices, [size] = [4*nS, 4*nB], preMulInv.block(4*s, 4*j, 4, 4) is the inverse of pre-local transformation of bone j on subject s.

Definition at line 86 of file DemBonesExt.h.

◆ rotOrder

template<class _Scalar , class _AniMeshScalar >
Eigen::MatrixXi Dem::DemBonesExt< _Scalar, _AniMeshScalar >::rotOrder

Rotation order, [size] = [3*nS, nB], rotOrder.col(j).segment<3>(3*s) is the rotation order of bone j on subject s, 0=X, 1=Y, 2=Z, e.g. {0, 1, 2} is XYZ order

Definition at line 89 of file DemBonesExt.h.


The documentation for this class was generated from the following file:
Dem::DemBones::m
MatrixX m
Bone transformations, size = [4*nF*4, 4*nB], m.blk4(k, j) is the 4*4 relative transformation matrix o...
Definition: DemBones.h:139
Dem::DemBonesExt::MatrixX
Eigen::Matrix< _Scalar, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Definition: DemBonesExt.h:35
Dem::DemBones::fStart
Eigen::VectorXi fStart
Start frame indices, size = nS+1, fStart(s), fStart(s+1) are data frames for subject s.
Definition: DemBones.h:123
Dem::DemBonesExt::preMulInv
MatrixX preMulInv
Inverse pre-multiplication matrices, [size] = [4*nS, 4*nB], preMulInv.block(4*s, 4*j,...
Definition: DemBonesExt.h:86
Dem::DemBonesExt::orient
MatrixX orient
Orientations of bones, [size] = [3*nS, nB], orient.col(j).segment<3>(3*s) is the(rx,...
Definition: DemBonesExt.h:92
Dem::DemBonesExt::clear
void clear()
Clear all data.
Definition: DemBonesExt.h:105
Dem::DemBonesExt::Matrix3
Eigen::Matrix< _Scalar, 3, 3 > Matrix3
Definition: DemBonesExt.h:37
Dem::DemBonesExt::fTime
Eigen::VectorXd fTime
Timestamps for bone transformations m, [size] = nS, fTime(k) is the timestamp of frame k.
Definition: DemBonesExt.h:74
Dem::DemBones::nS
int nS
Number of subjects, typically indexed by s.
Definition: DemBones.h:118
Dem::DemBonesExt::Vector3
Eigen::Matrix< _Scalar, 3, 1 > Vector3
Definition: DemBonesExt.h:40
Dem::DemBonesExt::bind
MatrixX bind
Original bind pre-matrix, [size] = [4*nS, 4*nB], bind.block(4*s, 4*j, 4, 4) is the global bind matrix...
Definition: DemBonesExt.h:83
Dem::DemBonesExt::parent
Eigen::VectorXi parent
Parent bone index, [size] = nB, parent(j) is the index of parent bone of j, parent(j) = -1 if j has n...
Definition: DemBonesExt.h:80
Dem::DemBonesExt::bindUpdate
int bindUpdate
Bind transformation update, 0=keep original, 1=set translations to p-norm centroids (using transAffin...
Definition: DemBonesExt.h:95
Dem::DemBones::nB
int nB
Number of bones, typically indexed by j.
Definition: DemBones.h:116
Dem::DemBonesExt::boneName
std::vector< std::string > boneName
Name of bones, [size] = nB, boneName(j) is the name bone of j.
Definition: DemBonesExt.h:77
Dem::DemBonesExt::rotOrder
Eigen::MatrixXi rotOrder
Rotation order, [size] = [3*nS, nB], rotOrder.col(j).segment<3>(3*s) is the rotation order of bone j ...
Definition: DemBonesExt.h:89
Dem::DemBones::clear
void clear()
Clear all data.
Definition: DemBones.h:161
Dem::DemBonesExt::Matrix4
Eigen::Matrix< _Scalar, 4, 4 > Matrix4
Definition: DemBonesExt.h:36