// This file is part of libigl, a simple c++ geometry processing library. // // Copyright (C) 2013 Alec Jacobson // // 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 "massmatrix.h" #include "massmatrix_intrinsic.h" #include "edge_lengths.h" #include "normalize_row_sums.h" #include "sparse.h" #include "doublearea.h" #include "repmat.h" #include #include template IGL_INLINE void igl::massmatrix( const Eigen::MatrixBase & V, const Eigen::MatrixBase & F, const MassMatrixType type, Eigen::SparseMatrix& M) { using namespace Eigen; using namespace std; const int n = V.rows(); const int m = F.rows(); const int simplex_size = F.cols(); MassMatrixType eff_type = type; // Use voronoi of for triangles by default, otherwise barycentric if(type == MASSMATRIX_TYPE_DEFAULT) { eff_type = (simplex_size == 3?MASSMATRIX_TYPE_VORONOI:MASSMATRIX_TYPE_BARYCENTRIC); } // Not yet supported assert(type!=MASSMATRIX_TYPE_FULL); if(simplex_size == 3) { // Triangles // edge lengths numbered same as opposite vertices Matrix l; igl::edge_lengths(V,F,l); return massmatrix_intrinsic(l,F,type,M); }else if(simplex_size == 4) { Matrix MI; Matrix MJ; Matrix MV; assert(V.cols() == 3); assert(eff_type == MASSMATRIX_TYPE_BARYCENTRIC); MI.resize(m*4,1); MJ.resize(m*4,1); MV.resize(m*4,1); MI.block(0*m,0,m,1) = F.col(0); MI.block(1*m,0,m,1) = F.col(1); MI.block(2*m,0,m,1) = F.col(2); MI.block(3*m,0,m,1) = F.col(3); MJ = MI; // loop over tets for(int i = 0;i v0m3,v1m3,v2m3; v0m3.head(V.cols()) = V.row(F(i,0)) - V.row(F(i,3)); v1m3.head(V.cols()) = V.row(F(i,1)) - V.row(F(i,3)); v2m3.head(V.cols()) = V.row(F(i,2)) - V.row(F(i,3)); Scalar v = fabs(v0m3.dot(v1m3.cross(v2m3)))/6.0; MV(i+0*m) = v/4.0; MV(i+1*m) = v/4.0; MV(i+2*m) = v/4.0; MV(i+3*m) = v/4.0; } sparse(MI,MJ,MV,n,n,M); }else { // Unsupported simplex size assert(false && "Unsupported simplex size"); } } #ifdef IGL_STATIC_LIBRARY // Explicit template instantiation // generated by autoexplicit.sh template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); // generated by autoexplicit.sh template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); // generated by autoexplicit.sh template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); template void igl::massmatrix, Eigen::Matrix, double>(Eigen::MatrixBase > const&, Eigen::MatrixBase > const&, igl::MassMatrixType, Eigen::SparseMatrix&); #endif