本文整理汇总了C++中eigen::VectorXi::setZero方法的典型用法代码示例。如果您正苦于以下问题:C++ VectorXi::setZero方法的具体用法?C++ VectorXi::setZero怎么用?C++ VectorXi::setZero使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类eigen::VectorXi
的用法示例。
在下文中一共展示了VectorXi::setZero方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: u
IGL_INLINE void igl::PolyVectorFieldFinder<DerivedV, DerivedF>::setFieldFromGeneralCoefficients(const std::vector<Eigen::Matrix<std::complex<typename DerivedV::Scalar>, Eigen::Dynamic,1>> &coeffs,
std::vector<Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 2>> &pv)
{
pv.assign(n, Eigen::Matrix<typename DerivedV::Scalar, Eigen::Dynamic, 2>::Zero(numF, 2));
for (int i = 0; i <numF; ++i)
{
// poly coefficients: 1, 0, -Acoeff, 0, Bcoeff
// matlab code from roots (given there are no trailing zeros in the polynomial coefficients)
Eigen::Matrix<std::complex<typename DerivedV::Scalar>, Eigen::Dynamic,1> polyCoeff;
polyCoeff.setZero(2*n+1,1);
polyCoeff[0] = 1.;
int sign = 1;
for (int k =0; k<n; ++k)
{
sign = -sign;
int degree = 2*(k+1);
polyCoeff[degree] = (1.*sign)*coeffs[k](i);
}
Eigen::Matrix<std::complex<typename DerivedV::Scalar>, Eigen::Dynamic,1> roots;
igl::polyRoots<std::complex<typename DerivedV::Scalar>, typename DerivedV::Scalar >(polyCoeff,roots);
Eigen::VectorXi done; done.setZero(2*n,1);
Eigen::Matrix<std::complex<typename DerivedV::Scalar>, Eigen::Dynamic,1> u(n,1);
int ind =0;
for (int k=0; k<2*n; ++k)
{
if (done[k])
continue;
u[ind] = roots[k];
done[k] = 1;
int mini = -1;
double mind = 1e10;
for (int l =k+1; l<2*n; ++l)
{
double dist = abs(roots[l]+u[ind]);
if (dist<mind)
{
mind = dist;
mini = l;
}
}
done[mini] = 1;
ind ++;
}
for (int k=0; k<n; ++k)
{
pv[k](i,0) = real(u[k]);
pv[k](i,1) = imag(u[k]);
}
}
}
示例2: fu
IGL_INLINE void igl::PolyVectorFieldFinder<DerivedV, DerivedF>::
minQuadWithKnownMini(const Eigen::SparseMatrix<std::complex<typename DerivedV::Scalar> > &Q,
const Eigen::SparseMatrix<std::complex<typename DerivedV::Scalar> > &f,
const Eigen::VectorXi isConstrained,
const Eigen::Matrix<std::complex<typename DerivedV::Scalar>, Eigen::Dynamic, 1> &xknown,
Eigen::Matrix<std::complex<typename DerivedV::Scalar>, Eigen::Dynamic, 1> &x)
{
int N = Q.rows();
int nc = xknown.rows();
Eigen::VectorXi known; known.setZero(nc,1);
Eigen::VectorXi unknown; unknown.setZero(N-nc,1);
int indk = 0, indu = 0;
for (int i = 0; i<N; ++i)
if (isConstrained[i])
{
known[indk] = i;
indk++;
}
else
{
unknown[indu] = i;
indu++;
}
Eigen::SparseMatrix<std::complex<typename DerivedV::Scalar>> Quu, Quk;
igl::slice(Q,unknown, unknown, Quu);
igl::slice(Q,unknown, known, Quk);
std::vector<typename Eigen::Triplet<std::complex<typename DerivedV::Scalar> > > tripletList;
Eigen::SparseMatrix<std::complex<typename DerivedV::Scalar> > fu(N-nc,1);
igl::slice(f,unknown, Eigen::VectorXi::Zero(1,1), fu);
Eigen::SparseMatrix<std::complex<typename DerivedV::Scalar> > rhs = (Quk*xknown).sparseView()+.5*fu;
Eigen::SparseLU< Eigen::SparseMatrix<std::complex<typename DerivedV::Scalar>>> solver;
solver.compute(-Quu);
if(solver.info()!=Eigen::Success)
{
std::cerr<<"Decomposition failed!"<<std::endl;
return;
}
Eigen::SparseMatrix<std::complex<typename DerivedV::Scalar>> b = solver.solve(rhs);
if(solver.info()!=Eigen::Success)
{
std::cerr<<"Solving failed!"<<std::endl;
return;
}
indk = 0, indu = 0;
x.setZero(N,1);
for (int i = 0; i<N; ++i)
if (isConstrained[i])
x[i] = xknown[indk++];
else
x[i] = b.coeff(indu++,0);
}
示例3: if
void
pcl::Permutohedral::init (const std::vector<float> &feature, const int feature_dimension, const int N)
{
N_ = N;
d_ = feature_dimension;
// Create hash table
std::vector<std::vector<short> > keys;
keys.reserve ((d_+1) * N_);
std::multimap<size_t, int> hash_table;
// reserve class memory
if (offset_.size () > 0)
offset_.clear ();
offset_.resize ((d_ + 1) * N_);
if (barycentric_.size () > 0)
barycentric_.clear ();
barycentric_.resize ((d_ + 1) * N_);
// create vectors and matrices
Eigen::VectorXf scale_factor = Eigen::VectorXf::Zero (d_);
Eigen::VectorXf elevated = Eigen::VectorXf::Zero (d_ + 1);
Eigen::VectorXf rem0 = Eigen::VectorXf::Zero (d_+1);
Eigen::VectorXf barycentric = Eigen::VectorXf::Zero (d_+2);
Eigen::VectorXi rank = Eigen::VectorXi::Zero (d_+1);
Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic> canonical;
canonical = Eigen::Matrix<int, Eigen::Dynamic, Eigen::Dynamic>::Zero (d_+1, d_+1);
//short * key = new short[d_+1];
std::vector<short> key (d_+1);
// Compute the canonical simple
for (int i = 0; i <= d_; i++)
{
for (int j = 0; j <= (d_ - i); j++)
canonical (j, i) = i;
for (int j = (d_ - i + 1); j <= d_; j++)
canonical (j, i) = i - (d_ + 1);
}
// Expected standard deviation of our filter (p.6 in [Adams etal 2010])
float inv_std_dev = std::sqrt (2.0f / 3.0f) * static_cast<float> (d_ + 1);
// Compute the diagonal part of E (p.5 in [Adams etal 2010])
for (int i = 0; i < d_; i++)
scale_factor (i) = 1.0f / std::sqrt (static_cast<float> (i + 2) * static_cast<float> (i + 1)) * inv_std_dev;
// Compute the simplex each feature lies in
for (int k = 0; k < N_; k++)
//for (int k = 0; k < 5; k++)
{
// Elevate the feature (y = Ep, see p.5 in [Adams etal 2010])
int index = k * feature_dimension;
// sm contains the sum of 1..n of our faeture vector
float sm = 0;
for (int j = d_; j > 0; j--)
{
float cf = feature[index + j-1] * scale_factor (j-1);
elevated (j) = sm - static_cast<float> (j) * cf;
sm += cf;
}
elevated (0) = sm;
// Find the closest 0-colored simplex through rounding
float down_factor = 1.0f / static_cast<float>(d_+1);
float up_factor = static_cast<float>(d_+1);
int sum = 0;
for (int j = 0; j <= d_; j++){
float rd = floorf (0.5f + (down_factor * elevated (j))) ;
rem0 (j) = rd * up_factor;
sum += static_cast<int> (rd);
}
// rank differential to find the permutation between this simplex and the canonical one.
// (See pg. 3-4 in paper.)
rank.setZero ();
Eigen::VectorXf tmp = elevated - rem0;
for (int i = 0; i < d_; i++){
for (int j = i+1; j <= d_; j++)
if (tmp (i) < tmp (j))
rank (i)++;
else
rank (j)++;
}
// If the point doesn't lie on the plane (sum != 0) bring it back
for (int j = 0; j <= d_; j++){
rank (j) += sum;
if (rank (j) < 0){
rank (j) += d_+1;
rem0 (j) += static_cast<float> (d_ + 1);
}
else if (rank (j) > d_){
rank (j) -= d_+1;
rem0 (j) -= static_cast<float> (d_ + 1);
}
}
// Compute the barycentric coordinates (p.10 in [Adams etal 2010])
//.........这里部分代码省略.........
示例4: parallel_transport_angles
IGL_INLINE void igl::parallel_transport_angles(
const Eigen::PlainObjectBase<DerivedV>& V,
const Eigen::PlainObjectBase<DerivedF>& F,
const Eigen::PlainObjectBase<DerivedV>& FN,
const Eigen::MatrixXi &E2F,
const Eigen::MatrixXi &F2E,
Eigen::PlainObjectBase<DerivedK> &K)
{
int numE = E2F.rows();
Eigen::VectorXi isBorderEdge;
isBorderEdge.setZero(numE,1);
for(unsigned i=0; i<numE; ++i)
{
if ((E2F(i,0) == -1) || ((E2F(i,1) == -1)))
isBorderEdge[i] = 1;
}
K.setZero(numE);
// For every non-border edge
for (unsigned eid=0; eid<numE; ++eid)
{
if (!isBorderEdge[eid])
{
int fid0 = E2F(eid,0);
int fid1 = E2F(eid,1);
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> N0 = FN.row(fid0);
// Eigen::Matrix<typename DerivedV::Scalar, 1, 3> N1 = FN.row(fid1);
// find common edge on triangle 0 and 1
int fid0_vc = -1;
int fid1_vc = -1;
for (unsigned i=0;i<3;++i)
{
if (F2E(fid0,i) == eid)
fid0_vc = i;
if (F2E(fid1,i) == eid)
fid1_vc = i;
}
assert(fid0_vc != -1);
assert(fid1_vc != -1);
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> common_edge = V.row(F(fid0,(fid0_vc+1)%3)) - V.row(F(fid0,fid0_vc));
common_edge.normalize();
// Map the two triangles in a new space where the common edge is the x axis and the N0 the z axis
Eigen::Matrix<typename DerivedV::Scalar, 3, 3> P;
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> o = V.row(F(fid0,fid0_vc));
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> tmp = -N0.cross(common_edge);
P << common_edge, tmp, N0;
// P.transposeInPlace();
Eigen::Matrix<typename DerivedV::Scalar, 3, 3> V0;
V0.row(0) = V.row(F(fid0,0)) -o;
V0.row(1) = V.row(F(fid0,1)) -o;
V0.row(2) = V.row(F(fid0,2)) -o;
V0 = (P*V0.transpose()).transpose();
// assert(V0(0,2) < 1e-10);
// assert(V0(1,2) < 1e-10);
// assert(V0(2,2) < 1e-10);
Eigen::Matrix<typename DerivedV::Scalar, 3, 3> V1;
V1.row(0) = V.row(F(fid1,0)) -o;
V1.row(1) = V.row(F(fid1,1)) -o;
V1.row(2) = V.row(F(fid1,2)) -o;
V1 = (P*V1.transpose()).transpose();
// assert(V1(fid1_vc,2) < 10e-10);
// assert(V1((fid1_vc+1)%3,2) < 10e-10);
// compute rotation R such that R * N1 = N0
// i.e. map both triangles to the same plane
double alpha = -atan2(V1((fid1_vc+2)%3,2),V1((fid1_vc+2)%3,1));
Eigen::Matrix<typename DerivedV::Scalar, 3, 3> R;
R << 1, 0, 0,
0, cos(alpha), -sin(alpha) ,
0, sin(alpha), cos(alpha);
V1 = (R*V1.transpose()).transpose();
// assert(V1(0,2) < 1e-10);
// assert(V1(1,2) < 1e-10);
// assert(V1(2,2) < 1e-10);
// measure the angle between the reference frames
// k_ij is the angle between the triangle on the left and the one on the right
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> ref0 = V0.row(1) - V0.row(0);
Eigen::Matrix<typename DerivedV::Scalar, 1, 3> ref1 = V1.row(1) - V1.row(0);
ref0.normalize();
ref1.normalize();
double ktemp = atan2(ref1(1),ref1(0)) - atan2(ref0(1),ref0(0));
// just to be sure, rotate ref0 using angle ktemp...
Eigen::Matrix<typename DerivedV::Scalar,2,2> R2;
//.........这里部分代码省略.........
示例5: marching_tets
//.........这里部分代码省略.........
NV.row(i) = V.row(i);
}
for (int i = 0; i < new_verts.size(); ++i) {
NV.row(i + V.rows()) = new_verts[i];
}
// Set I
I.resize(NV.rows());
for (int i = 0; i < I.rows(); ++i) {
if (i < V.rows()) {
I(i) = i;
} else {
I(i) = -1;
}
}
Eigen::VectorXi facesMarkers;
facesMarkers.resize(faces.size());
// Copy faces
NF.resize(faces.size(), 3);
for (int i = 0; i < faces.size(); ++i) {
NF.row(i) = faces[i];
facesMarkers(i) = faces_markers[i];
}
Eigen::MatrixXd newV;
Eigen::MatrixXi newF;
Eigen::VectorXi SVJ, SVI, I2;
// Helpers::viewTriMesh(NV, NF, facesMarkers);
//igl::writeOFF("offset_mesh.off", NV, NF)
Helpers::writeMeshWithMarkers("offset_mesh", NV, NF, facesMarkers);
/*
igl::collapse_small_triangles(NV, NF, 1e-8, newF);
printf("Collapsed %d small triangles\n", NF.rows() - newF.rows());
NF = newF;
*/
///*
igl::remove_duplicate_vertices(NV, NF, 1e-20, newV, SVI, SVJ, newF);
I2.resize(newV.rows());
I2.setConstant(-1);
for (int i = 0; i < NV.rows(); ++i) {
if (I2(SVJ(i)) == -1) {
I2(SVJ(i)) = I(i);
} else {
I2(SVJ(i)) = std::min(I2(SVJ(i)), I(i));
}
}
NF = newF;
NV = newV;
I = I2;
// Now see if we have duplicated faces.
//igl::resolve_duplicated_faces(NF, newF, SVJ);
//NF = newF;
//*/
// Other option is to do these two:
// These are bad because sometimes the "small" triangles are not area zero,
// and doing the removeDuplicates will delete these triangles and make the
// mesh non-manifold. Better to wait for remeshing later.
//Helpers::removeDuplicates(NV, NF, I);
//Helpers::collapseSmallTriangles(NV, NF);
igl::remove_unreferenced(NV, NF, newV, newF, SVI, SVJ);
I2.resize(newV.rows());
I2.setConstant(-1);
for (int i = 0; i < I2.rows(); ++i) {
I2(i) = I(SVJ(i));
}
I = I2;
NV = newV;
NF = newF;
// orient everything correctly.
Eigen::VectorXi C;
igl::orientable_patches(NF, C);
igl::bfs_orient(NF, newF, C);
NF = newF;
igl::orient_outward(NV, NF, C, newF, SVJ);
NF = newF;
//igl::writeOFF("offset_mesh_normals.off", NV, NF);
#ifdef DEBUG_MESH
if (!Helpers::isMeshOkay(NV, NF)) {
printf("Error: Mesh is not okay at first...\n");
}
if (!Helpers::isManifold(NV, NF, I)) {
printf("Error: Mesh from marching tets not manifold!\n");
Eigen::VectorXi temp;
temp.resize(I.rows());
temp.setZero();
Helpers::isManifold(NV, NF, temp, true);
Helpers::viewTriMesh(NV, NF, temp);
Helpers::writeMeshWithMarkers("marching_tets_manifold", NV, NF, temp);
cout << "See marching_tets_manifold.off for problems.\n";
exit(1);
}
#endif
}