本文整理汇总了C++中SpMat::coeffRef方法的典型用法代码示例。如果您正苦于以下问题:C++ SpMat::coeffRef方法的具体用法?C++ SpMat::coeffRef怎么用?C++ SpMat::coeffRef使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpMat
的用法示例。
在下文中一共展示了SpMat::coeffRef方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: applyFilter
//.........这里部分代码省略.........
for (std::map<size_t,CoeffScalar>::const_iterator it = sums.begin(); it != sums.end(); ++it)
{
coeffs.push_back(T(it->first, it->first, it->second));
}
laplaceMat.setFromTriplets(coeffs.begin(), coeffs.end());
// Get the two vertices with value set
VertexGrid vg;
vg.Set(m.vert.begin(), m.vert.end());
vcg::vertex::PointDistanceFunctor<ScalarType> pd;
vcg::tri::Tmark<CMeshO, VertexType> mv;
mv.SetMesh(&m);
mv.UnMarkAll();
CoordType closestP;
ScalarType minDist = 0;
VertexType * vp0 = vcg::GridClosest(vg, pd, mv, par.getPoint3f("point1"), m.bbox.Diag(), minDist, closestP);
VertexType * vp1 = vcg::GridClosest(vg, pd, mv, par.getPoint3f("point2"), m.bbox.Diag(), minDist, closestP);
if (vp0 == NULL || vp1 == NULL || vp0 == vp1)
{
this->errorMessage = "Error occurred for selected points.";
return false;
}
size_t v0_idx = vcg::tri::Index(m, vp0);
size_t v1_idx = vcg::tri::Index(m, vp1);
// Add penalty factor alpha
Log("Setting up the system matrix");
const CoeffScalar alpha = pow(10, 8);
Eigen::Matrix<CoeffScalar, Eigen::Dynamic, 1> b, x; // Unknown and known terms vectors
b.setZero(n);
b(v0_idx) = alpha * par.getFloat("value1");
b(v1_idx) = alpha * par.getFloat("value2");
laplaceMat.coeffRef(v0_idx, v0_idx) += alpha;
laplaceMat.coeffRef(v1_idx, v1_idx) += alpha;
// Solve system laplacianMat x = b
Log("System matrix decomposition...");
cb(20, "System matrix decomposition...");
Eigen::SimplicialLDLT<Eigen::SparseMatrix<CoeffScalar> > solver; // TODO eventually use another solver
solver.compute(laplaceMat);
if(solver.info() != Eigen::Success)
{
// decomposition failed
this->errorMessage = "System matrix decomposition failed: ";
if (solver.info() == Eigen::NumericalIssue)
this->errorMessage += "numerical issue.";
else if (solver.info() == Eigen::NoConvergence)
this->errorMessage += "no convergence.";
else if (solver.info() == Eigen::InvalidInput)
this->errorMessage += "invalid input.";
return false;
}
Log("Solving the system...");
cb(85, "Solving the system...");
x = solver.solve(b);
if(solver.info() != Eigen::Success)
{
// solving failed
this->errorMessage = "System solving failed.";
return false;
}
// Colorize bands for the 0-1 interval
if (par.getBool("colorize"))
{
float steps = 20.0f;
for (size_t i = 0; int(i) < n; ++i)
{
bool on = (int)(x[i]*steps)%2 == 1;
if (on)
{
m.vert[i].C() = vcg::Color4b::ColorRamp(0,2,x[i]);
}
else
{
m.vert[i].C() = vcg::Color4b::White;
}
}
}
// Set field value into vertex quality attribute
for (size_t i = 0; int(i) < n; ++i)
{
m.vert[i].Q() = x[i];
}
cb(100, "Done.");
return true;
}
default : assert(0);
}
return false;
}