|
@@ -6,10 +6,15 @@
|
|
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
// obtain one at http://mozilla.org/MPL/2.0/.
|
|
#include "harmonic.h"
|
|
#include "harmonic.h"
|
|
|
|
+#include "adjacency_matrix.h"
|
|
#include "cotmatrix.h"
|
|
#include "cotmatrix.h"
|
|
-#include "massmatrix.h"
|
|
|
|
|
|
+#include "diag.h"
|
|
#include "invert_diag.h"
|
|
#include "invert_diag.h"
|
|
|
|
+#include "isdiag.h"
|
|
|
|
+#include "massmatrix.h"
|
|
#include "min_quad_with_fixed.h"
|
|
#include "min_quad_with_fixed.h"
|
|
|
|
+#include "speye.h"
|
|
|
|
+#include "sum.h"
|
|
#include <Eigen/Sparse>
|
|
#include <Eigen/Sparse>
|
|
|
|
|
|
template <
|
|
template <
|
|
@@ -28,8 +33,7 @@ IGL_INLINE bool igl::harmonic(
|
|
{
|
|
{
|
|
using namespace Eigen;
|
|
using namespace Eigen;
|
|
typedef typename DerivedV::Scalar Scalar;
|
|
typedef typename DerivedV::Scalar Scalar;
|
|
- typedef Matrix<Scalar,Dynamic,1> VectorXS;
|
|
|
|
- SparseMatrix<Scalar> L,M,Mi;
|
|
|
|
|
|
+ SparseMatrix<Scalar> L,M;
|
|
cotmatrix(V,F,L);
|
|
cotmatrix(V,F,L);
|
|
switch(F.cols())
|
|
switch(F.cols())
|
|
{
|
|
{
|
|
@@ -39,18 +43,73 @@ IGL_INLINE bool igl::harmonic(
|
|
case 4:
|
|
case 4:
|
|
default:
|
|
default:
|
|
massmatrix(V,F,MASSMATRIX_TYPE_BARYCENTRIC,M);
|
|
massmatrix(V,F,MASSMATRIX_TYPE_BARYCENTRIC,M);
|
|
- break;
|
|
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
|
|
+ return harmonic(L,M,b,bc,k,W);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+template <
|
|
|
|
+ typename DerivedF,
|
|
|
|
+ typename Derivedb,
|
|
|
|
+ typename Derivedbc,
|
|
|
|
+ typename DerivedW>
|
|
|
|
+IGL_INLINE bool igl::harmonic(
|
|
|
|
+ const Eigen::PlainObjectBase<DerivedF> & F,
|
|
|
|
+ const Eigen::PlainObjectBase<Derivedb> & b,
|
|
|
|
+ const Eigen::PlainObjectBase<Derivedbc> & bc,
|
|
|
|
+ const int k,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedW> & W)
|
|
|
|
+{
|
|
|
|
+ using namespace Eigen;
|
|
|
|
+ typedef typename Derivedbc::Scalar Scalar;
|
|
|
|
+ SparseMatrix<Scalar> A;
|
|
|
|
+ adjacency_matrix(F,A);
|
|
|
|
+ // sum each row
|
|
|
|
+ SparseVector<Scalar> Asum;
|
|
|
|
+ sum(A,1,Asum);
|
|
|
|
+ // Convert row sums into diagonal of sparse matrix
|
|
|
|
+ SparseMatrix<Scalar> Adiag;
|
|
|
|
+ diag(Asum,Adiag);
|
|
|
|
+ SparseMatrix<Scalar> L = A-Adiag;
|
|
|
|
+ SparseMatrix<Scalar> M;
|
|
|
|
+ speye(L.rows(),M);
|
|
|
|
+ return harmonic(L,M,b,bc,k,W);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+template <
|
|
|
|
+ typename DerivedL,
|
|
|
|
+ typename DerivedM,
|
|
|
|
+ typename Derivedb,
|
|
|
|
+ typename Derivedbc,
|
|
|
|
+ typename DerivedW>
|
|
|
|
+IGL_INLINE bool igl::harmonic(
|
|
|
|
+ const Eigen::SparseMatrix<DerivedL> & L,
|
|
|
|
+ const Eigen::SparseMatrix<DerivedM> & M,
|
|
|
|
+ const Eigen::PlainObjectBase<Derivedb> & b,
|
|
|
|
+ const Eigen::PlainObjectBase<Derivedbc> & bc,
|
|
|
|
+ const int k,
|
|
|
|
+ Eigen::PlainObjectBase<DerivedW> & W)
|
|
|
|
+{
|
|
|
|
+ const int n = L.rows();
|
|
|
|
+ assert(n == L.cols() && "L must be square");
|
|
|
|
+ assert(n == M.cols() && "M must be same size as L");
|
|
|
|
+ assert(n == M.rows() && "M must be square");
|
|
|
|
+ assert(igl::isdiag(M) && "Mass matrix should be diagonal");
|
|
|
|
+
|
|
|
|
+ Eigen::SparseMatrix<DerivedM> Mi;
|
|
invert_diag(M,Mi);
|
|
invert_diag(M,Mi);
|
|
- SparseMatrix<Scalar> Q = -L;
|
|
|
|
|
|
+ Eigen::SparseMatrix<DerivedL> Q;
|
|
|
|
+ Q = -L;
|
|
for(int p = 1;p<k;p++)
|
|
for(int p = 1;p<k;p++)
|
|
{
|
|
{
|
|
Q = (Q*Mi*-L).eval();
|
|
Q = (Q*Mi*-L).eval();
|
|
}
|
|
}
|
|
- const VectorXS B = VectorXS::Zero(V.rows(),1);
|
|
|
|
|
|
+ typedef DerivedL Scalar;
|
|
min_quad_with_fixed_data<Scalar> data;
|
|
min_quad_with_fixed_data<Scalar> data;
|
|
- min_quad_with_fixed_precompute(Q,b,SparseMatrix<Scalar>(),true,data);
|
|
|
|
- W.resize(V.rows(),bc.cols());
|
|
|
|
|
|
+ min_quad_with_fixed_precompute(Q,b,Eigen::SparseMatrix<Scalar>(),true,data);
|
|
|
|
+ W.resize(n,bc.cols());
|
|
|
|
+ typedef Eigen::Matrix<Scalar,Eigen::Dynamic,1> VectorXS;
|
|
|
|
+ const VectorXS B = VectorXS::Zero(n,1);
|
|
for(int w = 0;w<bc.cols();w++)
|
|
for(int w = 0;w<bc.cols();w++)
|
|
{
|
|
{
|
|
const VectorXS bcw = bc.col(w);
|
|
const VectorXS bcw = bc.col(w);
|
|
@@ -64,9 +123,14 @@ IGL_INLINE bool igl::harmonic(
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
#ifdef IGL_STATIC_LIBRARY
|
|
// Explicit template specialization
|
|
// Explicit template specialization
|
|
template bool igl::harmonic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
|
|
template bool igl::harmonic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
|
|
template bool igl::harmonic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
template bool igl::harmonic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
template bool igl::harmonic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
template bool igl::harmonic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
|
|
+
|
|
|
|
+template bool igl::harmonic<Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
|
|
|
|
+template bool igl::harmonic<Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
|
|
+template bool igl::harmonic<Eigen::Matrix<int, -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::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
|
|
#endif
|
|
#endif
|