// 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 "sparse.h" #include "doublearea.h" #include "volume.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); } 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) { // tetrahedra assert(V.cols() == 3 && "vertices must be defined in 3D for tetrahedra"); Matrix vol; volume(V,F,vol); vol = vol.array().abs(); Matrix MI; Matrix MJ; Matrix MV; switch (eff_type) { case 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; repmat(vol,4,1,MV); assert(MV.rows()==m*4&&MV.cols()==1); MV.array() /= 4.; break; case MASSMATRIX_TYPE_VORONOI: { assert(false && "Implementation incomplete"); break; } case MASSMATRIX_TYPE_FULL: MI.resize(m*16,1); MJ.resize(m*16,1); MV.resize(m*16,1); // indicies and values of the element mass matrix entries in the order // (1,0),(2,0),(3,0),(2,1),(3,1),(0,1),(3,2),(0,2),(1,2),(0,3),(1,3),(2,3),(0,0),(1,1),(2,2),(3,3); MI<, 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&); // 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