// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2017 Alec Jacobson and Oded Stein // // This Source Code Form is subject to the terms of the Mozilla Public License // 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/. #include "hessian_energy.h" #include #include #include #include #include #include template IGL_INLINE void igl::hessian_energy( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, Eigen::SparseMatrix& Q) { typedef typename DerivedV::Scalar denseScalar; typedef typename Eigen::Matrix VecXd; typedef typename Eigen::SparseMatrix SparseMat; typedef typename Eigen::DiagonalMatrix DiagMat; int dim = V.cols(); assert((dim==2 || dim==3) && "The dimension of the vertices should be 2 or 3"); SparseMat M; igl::massmatrix(V,F,igl::MASSMATRIX_TYPE_VORONOI,M); //Kill non-interior DOFs VecXd Mint = M.diagonal(); std::vector > bdryLoop; igl::boundary_loop(F,bdryLoop); for(const std::vector& loop : bdryLoop) for(const int& bdryVert : loop) Mint(bdryVert) = 0.; //Invert Mint for(int i=0; i 0) Mint(i) = 1./Mint(i); //Repeat Mint to form diaginal matrix DiagMat stackedMinv = Mint.replicate(dim*dim,1).asDiagonal(); //Compute squared Hessian SparseMat H; igl::fem_hessian(V,F,H); Q = H.transpose()*stackedMinv*H; } template IGL_INLINE void igl::fem_hessian( const Eigen::PlainObjectBase & V, const Eigen::PlainObjectBase & F, Eigen::SparseMatrix& H) { typedef typename DerivedV::Scalar denseScalar; typedef typename Eigen::Matrix VecXd; typedef typename Eigen::SparseMatrix SparseMat; typedef typename Eigen::DiagonalMatrix DiagMat; int dim = V.cols(); assert((dim==2 || dim==3) && "The dimension of the vertices should be 2 or 3"); //Construct the combined gradient matric SparseMat G; igl::grad(V, F, G, false); SparseMat GG(F.rows(), dim*V.rows()); GG.reserve(G.nonZeros()); for(int i=0; i, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); template void igl::fem_hessian, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, Eigen::SparseMatrix&); #endif