Fixing issues from code cleanup

This commit is contained in:
tamasmeszaros 2019-02-26 18:09:33 +01:00
parent 43f03b8032
commit 359de84a05
2 changed files with 25 additions and 39 deletions

View file

@ -1150,7 +1150,6 @@ bool SLASupportTree::generate(const std::vector<SupportPoint> &support_points,
using PtIndices = std::vector<unsigned>;
const size_t pcount = size_t(points.rows());
PtIndices filtered_indices; // all valid support points
PtIndices head_indices; // support points with pinhead
PtIndices headless_indices; // headless support points
PtIndices onmodel_head_indices; // supp. pts. connecting to model
@ -1201,7 +1200,6 @@ bool SLASupportTree::generate(const std::vector<SupportPoint> &support_points,
const PointSet& points,
const EigenMesh3D& mesh,
PointSet& support_normals,
PtIndices& filtered_indices,
PtIndices& head_indices,
PtIndices& headless_indices)
{
@ -1213,14 +1211,13 @@ bool SLASupportTree::generate(const std::vector<SupportPoint> &support_points,
thr(); return distance(p.first, se.first) < D_SP;
}, 2);
filtered_indices.resize(aliases.size());
PtIndices filtered_indices;
filtered_indices.reserve(aliases.size());
head_indices.reserve(aliases.size());
headless_indices.reserve(aliases.size());
unsigned count = 0;
for(auto& a : aliases) {
// Here we keep only the front point of the cluster.
filtered_indices[count++] = a.front();
filtered_indices.emplace_back(a.front());
}
// calculate the normals to the triangles for filtered points
@ -1238,7 +1235,9 @@ bool SLASupportTree::generate(const std::vector<SupportPoint> &support_points,
using libnest2d::opt::StopCriteria;
static const unsigned MAX_TRIES = 100;
for(unsigned i = 0; i < count; i++) {
for(unsigned i = 0, fidx = filtered_indices[0];
i < filtered_indices.size(); ++i, fidx = filtered_indices[i])
{
thr();
auto n = nmls.row(i);
@ -1261,7 +1260,7 @@ bool SLASupportTree::generate(const std::vector<SupportPoint> &support_points,
polar = std::max(polar, 3*PI / 4);
// save the head (pinpoint) position
Vec3d hp = points.row(filtered_indices[i]);
Vec3d hp = points.row(i);
double w = cfg.head_width_mm +
cfg.head_back_radius_mm +
@ -1322,15 +1321,15 @@ bool SLASupportTree::generate(const std::vector<SupportPoint> &support_points,
}
// save the verified and corrected normal
support_normals.row(filtered_indices[i]) = nn;
support_normals.row(fidx) = nn;
if(t > w) {
// mark the point for needing a head.
head_indices.emplace_back(filtered_indices[i]);
head_indices.emplace_back(fidx);
} else if( polar >= 3*PI/4 ) {
// Headless supports do not tilt like the headed ones so
// the normal should point almost to the ground.
headless_indices.emplace_back(filtered_indices[i]);
headless_indices.emplace_back(fidx);
}
}
}
@ -1937,8 +1936,7 @@ bool SLASupportTree::generate(const std::vector<SupportPoint> &support_points,
// inputs:
cref(cfg), cref(points), cref(mesh),
// outputs:
ref(support_normals), ref(filtered_indices), ref(head_indices),
ref(headless_indices)),
ref(support_normals), ref(head_indices), ref(headless_indices)),
bind(pinheads_fn,
// inputs:

View file

@ -219,7 +219,7 @@ template<class Vec> double distance(const Vec& pp1, const Vec& pp2) {
PointSet normals(const PointSet& points,
const EigenMesh3D& mesh,
double eps,
std::function<void()> throw_on_cancel,
std::function<void()> thr, // throw on cancel
const std::vector<unsigned>& pt_indices = {})
{
if(points.rows() == 0 || mesh.V().rows() == 0 || mesh.F().rows() == 0)
@ -231,29 +231,19 @@ PointSet normals(const PointSet& points,
std::iota(range.begin(), range.end(), 0);
}
std::vector<double> dists(range.size());
std::vector<int> I(range.size());
PointSet C(Eigen::Index(range.size()), 3);
PointSet ret(range.size(), 3);
tbb::parallel_for(size_t(0), range.size(),
[&range, &mesh, &points, &dists, &I, &C](size_t idx)
[&ret, &range, &mesh, &points, thr, eps](size_t ridx)
{
auto eidx = Eigen::Index(range[idx]);
int i = 0;
Vec3d c;
dists[idx] = mesh.squared_distance(points.row(eidx), i, c);
C.row(eidx) = c;
I[range[idx]] = i;
});
thr();
auto eidx = Eigen::Index(range[ridx]);
int faceid = 0;
Vec3d p;
// igl::point_mesh_squared_distance( points, mesh.V(), mesh.F(), dists, I, C);
mesh.squared_distance(points.row(eidx), faceid, p);
PointSet ret(I.size(), 3);
for(unsigned i = 0; i < I.size(); i++) {
throw_on_cancel();
auto idx = I[i];
auto trindex = mesh.F().row(idx);
auto trindex = mesh.F().row(faceid);
const Vec3d& p1 = mesh.V().row(trindex(0));
const Vec3d& p2 = mesh.V().row(trindex(1));
@ -267,8 +257,6 @@ PointSet normals(const PointSet& points,
// of its triangle. The procedure is the same, get the neighbor
// triangles and calculate an average normal.
const Vec3d& p = C.row(i);
// mark the vertex indices of the edge. ia and ib marks and edge ic
// will mark a single vertex.
int ia = -1, ib = -1, ic = -1;
@ -296,7 +284,7 @@ PointSet normals(const PointSet& points,
std::vector<Vec3i> neigh;
if(ic >= 0) { // The point is right on a vertex of the triangle
for(int n = 0; n < mesh.F().rows(); ++n) {
throw_on_cancel();
thr();
Vec3i ni = mesh.F().row(n);
if((ni(X) == ic || ni(Y) == ic || ni(Z) == ic))
neigh.emplace_back(ni);
@ -305,7 +293,7 @@ PointSet normals(const PointSet& points,
else if(ia >= 0 && ib >= 0) { // the point is on and edge
// now get all the neigboring triangles
for(int n = 0; n < mesh.F().rows(); ++n) {
throw_on_cancel();
thr();
Vec3i ni = mesh.F().row(n);
if((ni(X) == ia || ni(Y) == ia || ni(Z) == ia) &&
(ni(X) == ib || ni(Y) == ib || ni(Z) == ib))
@ -346,14 +334,14 @@ PointSet normals(const PointSet& points,
Vec3d sumnorm(0, 0, 0);
sumnorm = std::accumulate(neighnorms.begin(), lend, sumnorm);
sumnorm.normalize();
ret.row(i) = sumnorm;
ret.row(long(ridx)) = sumnorm;
}
else { // point lies safely within its triangle
Eigen::Vector3d U = p2 - p1;
Eigen::Vector3d V = p3 - p1;
ret.row(i) = U.cross(V).normalized();
ret.row(long(ridx)) = U.cross(V).normalized();
}
}
});
return ret;
}