Browse Source

fixed arap

Teseo Schneider 6 years ago
parent
commit
1bea273f3c

+ 15 - 9
include/igl/arap_linear_block.cpp

@@ -10,13 +10,13 @@
 #include "cotmatrix_entries.h"
 #include <Eigen/Dense>
 
-template <typename MatV, typename MatF, typename Scalar>
+template <typename MatV, typename MatF, typename MatK>
 IGL_INLINE void igl::arap_linear_block(
   const MatV & V,
   const MatF & F,
   const int d,
   const igl::ARAPEnergyType energy,
-  Eigen::SparseMatrix<Scalar> & Kd)
+  MatK & Kd)
 {
   switch(energy)
   {
@@ -36,13 +36,15 @@ IGL_INLINE void igl::arap_linear_block(
 }
 
 
-template <typename MatV, typename MatF, typename Scalar>
+template <typename MatV, typename MatF, typename MatK>
 IGL_INLINE void igl::arap_linear_block_spokes(
   const MatV & V,
   const MatF & F,
   const int d,
-  Eigen::SparseMatrix<Scalar> & Kd)
+  MatK & Kd)
 {
+  typedef typename MatK::Scalar Scalar;
+
   using namespace std;
   using namespace Eigen;
   // simplex size (3: triangles, 4: tetrahedra)
@@ -101,13 +103,15 @@ IGL_INLINE void igl::arap_linear_block_spokes(
   Kd.makeCompressed();
 }
 
-template <typename MatV, typename MatF, typename Scalar>
+template <typename MatV, typename MatF, typename MatK>
 IGL_INLINE void igl::arap_linear_block_spokes_and_rims(
   const MatV & V,
   const MatF & F,
   const int d,
-  Eigen::SparseMatrix<Scalar> & Kd)
+  MatK & Kd)
 {
+  typedef typename MatK::Scalar Scalar;
+
   using namespace std;
   using namespace Eigen;
   // simplex size (3: triangles, 4: tetrahedra)
@@ -183,13 +187,14 @@ IGL_INLINE void igl::arap_linear_block_spokes_and_rims(
   Kd.makeCompressed();
 }
 
-template <typename MatV, typename MatF, typename Scalar>
+template <typename MatV, typename MatF, typename MatK>
 IGL_INLINE void igl::arap_linear_block_elements(
   const MatV & V,
   const MatF & F,
   const int d,
-  Eigen::SparseMatrix<Scalar> & Kd)
+  MatK & Kd)
 {
+  typedef typename MatK::Scalar Scalar;
   using namespace std;
   using namespace Eigen;
   // simplex size (3: triangles, 4: tetrahedra)
@@ -249,5 +254,6 @@ IGL_INLINE void igl::arap_linear_block_elements(
 
 #ifdef IGL_STATIC_LIBRARY
 // Explicit template instantiation
-template IGL_INLINE void igl::arap_linear_block<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> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, int, igl::ARAPEnergyType, Eigen::SparseMatrix<double, 0, int>&);
+template void igl::arap_linear_block<Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >, Eigen::SparseMatrix<double, 0, int> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, int, igl::ARAPEnergyType, Eigen::SparseMatrix<double, 0, int>&);
+template void igl::arap_linear_block<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::SparseMatrix<double, 0, int> >(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, int, igl::ARAPEnergyType, Eigen::SparseMatrix<double, 0, int>&);
 #endif

+ 8 - 8
include/igl/arap_linear_block.h

@@ -43,32 +43,32 @@ namespace igl
   //   Kd  #V by #V/#F block of the linear constructor matrix corresponding to
   //     coordinate d
   //
-  template <typename MatV, typename MatF, typename Scalar>
+  template <typename MatV, typename MatF, typename MatK>
   IGL_INLINE void arap_linear_block(
     const MatV & V,
     const MatF & F,
     const int d,
     const igl::ARAPEnergyType energy,
-    Eigen::SparseMatrix<Scalar> & Kd);
+    MatK & Kd);
   // Helper functions for each energy type
-  template <typename MatV, typename MatF, typename Scalar>
+  template <typename MatV, typename MatF, typename MatK>
   IGL_INLINE void arap_linear_block_spokes(
     const MatV & V,
     const MatF & F,
     const int d,
-    Eigen::SparseMatrix<Scalar> & Kd);
-  template <typename MatV, typename MatF, typename Scalar>
+    MatK & Kd);
+  template <typename MatV, typename MatF, typename MatK>
   IGL_INLINE void arap_linear_block_spokes_and_rims(
     const MatV & V,
     const MatF & F,
     const int d,
-    Eigen::SparseMatrix<Scalar> & Kd);
-  template <typename MatV, typename MatF, typename Scalar>
+    MatK & Kd);
+  template <typename MatV, typename MatF, typename MatK>
   IGL_INLINE void arap_linear_block_elements(
     const MatV & V,
     const MatF & F,
     const int d,
-    Eigen::SparseMatrix<Scalar> & Kd);
+    MatK & Kd);
 }
 
 #ifndef IGL_STATIC_LIBRARY

+ 13 - 7
include/igl/arap_rhs.cpp

@@ -12,12 +12,13 @@
 #include "cat.h"
 #include <iostream>
 
+template<typename DerivedV, typename DerivedF, typename DerivedK>
 IGL_INLINE void igl::arap_rhs(
-  const Eigen::MatrixXd & V, 
-  const Eigen::MatrixXi & F,
-  const int dim,
-  const igl::ARAPEnergyType energy,
-  Eigen::SparseMatrix<double>& K)
+    const Eigen::MatrixBase<DerivedV> & V, 
+    const Eigen::MatrixBase<DerivedF> & F,
+    const int dim,
+    const igl::ARAPEnergyType energy,
+    Eigen::SparseMatrixBase<DerivedK>& K)
 {
   using namespace std;
   using namespace Eigen;
@@ -48,7 +49,7 @@ IGL_INLINE void igl::arap_rhs(
       return;
   }
 
-  SparseMatrix<double> KX,KY,KZ;
+  DerivedK KX,KY,KZ;
   arap_linear_block(V,F,0,energy,KX);
   arap_linear_block(V,F,1,energy,KY);
   if(Vdim == 2)
@@ -62,7 +63,7 @@ IGL_INLINE void igl::arap_rhs(
       K = cat(2,cat(2,repdiag(KX,dim),repdiag(KY,dim)),repdiag(KZ,dim));
     }else if(dim ==2)
     {
-      SparseMatrix<double> ZZ(KX.rows()*2,KX.cols());
+      DerivedK ZZ(KX.rows()*2,KX.cols());
       K = cat(2,cat(2,
             cat(2,repdiag(KX,dim),ZZ),
             cat(2,repdiag(KY,dim),ZZ)),
@@ -87,3 +88,8 @@ IGL_INLINE void igl::arap_rhs(
   
 }
 
+
+
+#ifdef IGL_STATIC_LIBRARY
+template void igl::arap_rhs(const Eigen::MatrixBase<Eigen::MatrixXd> & V, const Eigen::MatrixBase<Eigen::MatrixXi> & F,const int dim, const igl::ARAPEnergyType energy,Eigen::SparseMatrixBase<Eigen::SparseMatrix<double>>& K);
+#endif

+ 4 - 3
include/igl/arap_rhs.h

@@ -29,12 +29,13 @@ namespace igl
   //     b = K * reshape(permute(R,[3 1 2]),size(V|F,1)*size(V,2)*size(V,2),1);
   //   
   // See also: arap_linear_block
+  template<typename DerivedV, typename DerivedF, typename DerivedK>
   IGL_INLINE void arap_rhs(
-    const Eigen::MatrixXd & V, 
-    const Eigen::MatrixXi & F,
+    const Eigen::MatrixBase<DerivedV> & V, 
+    const Eigen::MatrixBase<DerivedF> & F,
     const int dim,
     const igl::ARAPEnergyType energy,
-    Eigen::SparseMatrix<double>& K);
+    Eigen::SparseMatrixBase<DerivedK>& K);
 }
 #ifndef IGL_STATIC_LIBRARY
 #include "arap_rhs.cpp"