Browse Source

rm F, dense W

Alec Jacobson 5 years ago
parent
commit
1b53e54815

+ 10 - 11
include/igl/direct_delta_mush.cpp

@@ -10,12 +10,10 @@
 
 template <
   typename DerivedV,
-  typename DerivedF,
   typename DerivedOmega,
   typename DerivedU>
 IGL_INLINE void igl::direct_delta_mush(
   const Eigen::MatrixBase<DerivedV> & V,
-  const Eigen::MatrixBase<DerivedF> & F,
   const std::vector<Eigen::Affine3d, Eigen::aligned_allocator<Eigen::Affine3d> > & T,
   const Eigen::MatrixBase<DerivedOmega> & Omega,
   Eigen::PlainObjectBase<DerivedU> & U)
@@ -24,7 +22,6 @@ IGL_INLINE void igl::direct_delta_mush(
 
   // Shape checks
   assert(V.cols() == 3 && "V should contain 3D positions.");
-  assert(F.cols() == 3 && "F should contain triangles.");
   assert(Omega.rows() == V.rows() && "Omega contain the same number of rows as V.");
   assert(Omega.cols() == T.size() * 10 && "Omega should have #T*10 columns.");
 
@@ -91,7 +88,7 @@ template <
 IGL_INLINE void igl::direct_delta_mush_precomputation(
   const Eigen::MatrixBase<DerivedV> & V,
   const Eigen::MatrixBase<DerivedF> & F,
-  const Eigen::SparseMatrix<DerivedW> & W,
+  const Eigen::MatrixBase<DerivedW> & W,
   const int p,
   const typename DerivedV::Scalar lambda,
   const typename DerivedV::Scalar kappa,
@@ -174,7 +171,8 @@ IGL_INLINE void igl::direct_delta_mush_precomputation(
   // C positive semi-definite => ldlt solver
   SimplicialLDLT<SparseMatrix<DerivedW>> ldlt_W_prime;
   SparseMatrix<Scalar> c(I + kappa * L_bar);
-  Matrix<DerivedW, Dynamic, Dynamic> W_prime(W);
+  // working copy
+  DerivedW W_prime(W);
   ldlt_W_prime.compute(c.transpose());
   for (int iter = 0; iter < p; ++iter)
   {
@@ -257,7 +255,7 @@ IGL_INLINE void igl::direct_delta_mush_precomputation(
     {
       Matrix<Scalar, 10, 1> Omega_curr(10);
       Matrix<Scalar, 10, 1> Psi_curr = Psi.block(i, j * 10, 1, 10).transpose();
-      Omega_curr = (1. - alpha) * Psi_curr + alpha * W_prime.coeff(i, j) * p_vector;
+      Omega_curr = (1. - alpha) * Psi_curr + alpha * W_prime(i, j) * p_vector;
       Omega.block(i, j * 10, 1, 10) = Omega_curr.transpose();
     }
   }
@@ -267,21 +265,22 @@ IGL_INLINE void igl::direct_delta_mush_precomputation(
 
 // Explicit template instantiation
 template void
-igl::direct_delta_mush<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(
+igl::direct_delta_mush<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(
   Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const &,
-  Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const &,
   std::vector<Eigen::Transform<double, 3, 2, 0>, Eigen::aligned_allocator<Eigen::Transform<double, 3, 2, 0> > > const &,
   Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const &,
   Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > &);
 
 template void
-igl::direct_delta_mush_precomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, double, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(
+igl::direct_delta_mush_precomputation<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(
   Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const &,
   Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const &,
-  Eigen::SparseMatrix<double, 0, int> const &, int,
+  Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const &,
+  Eigen::SparseMatrix<double, 0, int> const &, 
+  int,
   Eigen::Matrix<double, -1, -1, 0, -1, -1>::Scalar,
   Eigen::Matrix<double, -1, -1, 0, -1, -1>::Scalar,
   Eigen::Matrix<double, -1, -1, 0, -1, -1>::Scalar,
   Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > &);
 
-#endif
+#endif

+ 1 - 4
include/igl/direct_delta_mush.h

@@ -21,19 +21,16 @@ namespace igl {
   //
   // Inputs:
   //   V  #V by 3 list of rest pose vertex positions
-  //   F  #F by 3 list of triangle indices into rows of V
   //   T  #T list of bone pose transformations
   //   Omega #V by #T*10 list of precomputated matrix values
   // Outputs:
   //   U  #V by 3 list of output vertex positions
   template <
     typename DerivedV,
-    typename DerivedF,
     typename DerivedOmega,
     typename DerivedU>
   IGL_INLINE void direct_delta_mush(
     const Eigen::MatrixBase<DerivedV> & V,
-    const Eigen::MatrixBase<DerivedF> & F,
     const std::vector<
       Eigen::Affine3d, Eigen::aligned_allocator<Eigen::Affine3d>
     > & T, /* should eventually be templated more generally than double */
@@ -60,7 +57,7 @@ namespace igl {
   IGL_INLINE void direct_delta_mush_precomputation(
     const Eigen::MatrixBase<DerivedV> & V,
     const Eigen::MatrixBase<DerivedF> & F,
-    const Eigen::SparseMatrix<DerivedW> & W,
+    const Eigen::MatrixBase<DerivedW> & W,
     const int p,
     const typename DerivedV::Scalar lambda,
     const typename DerivedV::Scalar kappa,

+ 3 - 4
tutorial/408_DirectDeltaMush/main.cpp

@@ -35,8 +35,7 @@ int main(int argc, char * argv[])
   float lambda = 3; // 0 < lambda
   float kappa = 1; // 0 < kappa < lambda
   float alpha = 0.8; // 0 <= alpha < 1
-  Eigen::SparseMatrix<double> Wsparse =  W.sparseView();
-  igl::direct_delta_mush_precomputation(V, F,Wsparse, p, lambda, kappa, alpha, Omega);
+  igl::direct_delta_mush_precomputation(V, F,W, p, lambda, kappa, alpha, Omega);
 
   igl::opengl::glfw::Viewer viewer;
   int frame = 0;
@@ -67,9 +66,9 @@ int main(int argc, char * argv[])
         for (int e = 0; e < BE.rows(); e++)
         {
           T_list[e] = Eigen::Affine3d::Identity();
-          T_list[e].matrix().block(0, 0, 3, 4) = Tf.block(e*4,0,4,3).transpose();
+          T_list[e].matrix().block(0,0,3,4) = Tf.block(e*4,0,4,3).transpose();
         }
-        igl::direct_delta_mush(V, F, T_list, Omega, U);
+        igl::direct_delta_mush(V, T_list, Omega, U);
       }
       U.rowwise() += offset;
       viewer.data(ddm_id).set_vertices(U);