本文整理汇总了C++中eigen::SparseMatrix::setZero方法的典型用法代码示例。如果您正苦于以下问题:C++ SparseMatrix::setZero方法的具体用法?C++ SparseMatrix::setZero怎么用?C++ SparseMatrix::setZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::SparseMatrix
的用法示例。
在下文中一共展示了SparseMatrix::setZero方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: vertices
void Poisson_LIMSolver2D::prepareProblemData(std::vector<int>& hessRowIdx, std::vector<int>& hessColIdx)
{
const int numNodes = mesh->InitalVertices->rows();
// create sparse gradient operator matrix
Eigen::SparseMatrix<double> tempG;
Eigen::VectorXd dAreas,dAreasTemp;
Eigen::Matrix<double,Eigen::Dynamic,Eigen::Dynamic> vertices(*mesh->DeformedVertices);
Eigen::Matrix<int,Eigen::Dynamic,Eigen::Dynamic> faces(*mesh->Triangles);
igl::grad(vertices,faces,tempG);
// Only get x and y derivatives of elements as z is zero
int newRowSize = 2.0/3.0*tempG.rows();
std::vector<Eigen::Triplet<double> > triplets;
for (int k=0;k<tempG.outerSize();++k)
{
for (Eigen::SparseMatrix<double>::InnerIterator it(tempG,k);it;++it)
{
int row = it.row();
int col = it.col();
if(row < newRowSize)
{
triplets.push_back(Eigen::Triplet<double>(row,col,it.value()));
}
}
}
tempG.setZero();
tempG.resize(newRowSize,tempG.cols());
tempG.setFromTriplets(triplets.begin(), triplets.end());
// Extend gradient operator matrix for x and y scalar function
triplets.clear();
G.resize(newRowSize*2,tempG.cols()*2);
for (int k=0;k<tempG.outerSize();++k)
{
for (Eigen::SparseMatrix<double>::InnerIterator it(tempG,k);it;++it)
{
int row = it.row()*2;
int col = it.col()*2;
triplets.push_back(Eigen::Triplet<double>(row,col,it.value()));
triplets.push_back(Eigen::Triplet<double>(row+1,col+1,it.value()));
}
}
G.setFromTriplets(triplets.begin(), triplets.end());
// Compute area weights
Eigen::SparseMatrix<double> M;
igl::doublearea(vertices,faces,dAreas);
triplets.clear();
M.resize(dAreas.rows()*4,dAreas.rows()*4);
for(int r=0;r<dAreas.rows();r++)
{
int id = 4*r;
triplets.push_back(Eigen::Triplet<double>(id,id,dAreas(r)));
triplets.push_back(Eigen::Triplet<double>(id+1,id+1,dAreas(r)));
triplets.push_back(Eigen::Triplet<double>(id+2,id+2,dAreas(r)));
triplets.push_back(Eigen::Triplet<double>(id+3,id+3,dAreas(r)));
}
M.setFromTriplets(triplets.begin(),triplets.end());
// Compute laplacian
L = 0.5*G.transpose()*M*G;
for (int k=0;k<L.outerSize();++k)
{
for (Eigen::SparseMatrix<double>::InnerIterator it(L,k);it;++it)
{
int row = it.row();
int col = it.col();
// std::sort for upper triangule matrix
if(row <= col)
{
hessRowIdx.push_back(row);
hessColIdx.push_back(col);
}
}
}
GTb = 0.5*G.transpose()*M*b;
constantEnergyPart = b.transpose()*b;
}