Example #1
0
void Mesh::buildAreaMatrix(Eigen::SparseMatrix<double>& A) const
{
    std::vector<Eigen::Triplet<double>> ATriplet;
    
    for (VertexCIter v = vertices.begin(); v != vertices.end(); v++) {
        ATriplet.push_back(Eigen::Triplet<double>(v->index, v->index, v->dualArea()));
    }
    
    A.setFromTriplets(ATriplet.begin(), ATriplet.end());
}
Example #2
0
void Mesh::buildLaplacian(Eigen::SparseMatrix<double>& L) const
{
    std::vector<Eigen::Triplet<double>> LTriplet;
    
    for (VertexCIter v = vertices.begin(); v != vertices.end(); v++) {
        
        HalfEdgeCIter he = v->he;
        double dualArea = v->dualArea();
        double sumCoefficients = 0.0;
        do {
            // (cotA + cotB) / 2A
            double coefficient = 0.5 * (he->cotan() + he->flip->cotan()) / dualArea;
            sumCoefficients += coefficient;
            
            LTriplet.push_back(Eigen::Triplet<double>(v->index, he->flip->vertex->index, -coefficient));
            
            he = he->flip->next;
        } while (he != v->he);

        LTriplet.push_back(Eigen::Triplet<double>(v->index, v->index, sumCoefficients));
    }
    
    L.setFromTriplets(LTriplet.begin(), LTriplet.end());
}