Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortamasmeszaros <meszaros.q@gmail.com>2019-06-18 18:10:13 +0300
committertamasmeszaros <meszaros.q@gmail.com>2019-06-18 18:42:10 +0300
commitb4ef812d32a2b35d8b23d9706ee3a76dc5a2229d (patch)
treeccec0831fc28294bad6ab662894c4d8fdf5f4db5 /src/libslic3r/SLA
parent12797f2aa8a3d663b2c07a98d2194603140daade (diff)
parent18bbf493c1eb6aee516a900e5e4366cb13e7a4a4 (diff)
Merge branch 'master' into tm_sla_printer_mirror
Diffstat (limited to 'src/libslic3r/SLA')
-rw-r--r--src/libslic3r/SLA/SLABasePool.cpp109
-rw-r--r--src/libslic3r/SLA/SLABoilerPlate.hpp9
-rw-r--r--src/libslic3r/SLA/SLARotfinder.cpp4
-rw-r--r--src/libslic3r/SLA/SLASupportTree.cpp4
-rw-r--r--src/libslic3r/SLA/SLASupportTreeIGL.cpp17
5 files changed, 43 insertions, 100 deletions
diff --git a/src/libslic3r/SLA/SLABasePool.cpp b/src/libslic3r/SLA/SLABasePool.cpp
index 171d2b8d0..3b199c4eb 100644
--- a/src/libslic3r/SLA/SLABasePool.cpp
+++ b/src/libslic3r/SLA/SLABasePool.cpp
@@ -53,7 +53,7 @@ Contour3D walls(const Polygon& lower, const Polygon& upper,
// Shorthand for the vertex arrays
auto& upoints = upper.points, &lpoints = lower.points;
- auto& rpts = ret.points; auto& rfaces = ret.indices;
+ auto& rpts = ret.points; auto& ind = ret.indices;
// If the Z levels are flipped, or the offset difference is negative, we
// will interpret that as the triangles normals should be inverted.
@@ -61,10 +61,11 @@ Contour3D walls(const Polygon& lower, const Polygon& upper,
// Copy the points into the mesh, convert them from 2D to 3D
rpts.reserve(upoints.size() + lpoints.size());
- rfaces.reserve(2*upoints.size() + 2*lpoints.size());
- const double sf = SCALING_FACTOR;
- for(auto& p : upoints) rpts.emplace_back(p.x()*sf, p.y()*sf, upper_z_mm);
- for(auto& p : lpoints) rpts.emplace_back(p.x()*sf, p.y()*sf, lower_z_mm);
+ ind.reserve(2 * upoints.size() + 2 * lpoints.size());
+ for (auto &p : upoints)
+ rpts.emplace_back(unscaled(p.x()), unscaled(p.y()), upper_z_mm);
+ for (auto &p : lpoints)
+ rpts.emplace_back(unscaled(p.x()), unscaled(p.y()), lower_z_mm);
// Create pointing indices into vertex arrays. u-upper, l-lower
size_t uidx = 0, lidx = offs, unextidx = 1, lnextidx = offs + 1;
@@ -121,9 +122,9 @@ Contour3D walls(const Polygon& lower, const Polygon& upper,
case Proceed::UPPER:
if(!ustarted || uidx != uendidx) { // there are vertices remaining
// Get the 3D vertices in order
- const Vec3d& p_up1 = rpts[size_t(uidx)];
- const Vec3d& p_low = rpts[size_t(lidx)];
- const Vec3d& p_up2 = rpts[size_t(unextidx)];
+ const Vec3d& p_up1 = rpts[uidx];
+ const Vec3d& p_low = rpts[lidx];
+ const Vec3d& p_up2 = rpts[unextidx];
// Calculate fitness: the average of the two connecting edges
double a = offsdiff2 - (distfn(p_up1, p_low) - zdiff2);
@@ -133,8 +134,9 @@ Contour3D walls(const Polygon& lower, const Polygon& upper,
if(current_fit > prev_fit) { // fit is worse than previously
proceed = Proceed::LOWER;
} else { // good to go, create the triangle
- inverted? rfaces.emplace_back(unextidx, lidx, uidx) :
- rfaces.emplace_back(uidx, lidx, unextidx) ;
+ inverted
+ ? ind.emplace_back(int(unextidx), int(lidx), int(uidx))
+ : ind.emplace_back(int(uidx), int(lidx), int(unextidx));
// Increment the iterators, rotate if necessary
++uidx; ++unextidx;
@@ -150,9 +152,9 @@ Contour3D walls(const Polygon& lower, const Polygon& upper,
case Proceed::LOWER:
// Mode with lower segment, upper vertex. Same structure:
if(!lstarted || lidx != lendidx) {
- const Vec3d& p_low1 = rpts[size_t(lidx)];
- const Vec3d& p_low2 = rpts[size_t(lnextidx)];
- const Vec3d& p_up = rpts[size_t(uidx)];
+ const Vec3d& p_low1 = rpts[lidx];
+ const Vec3d& p_low2 = rpts[lnextidx];
+ const Vec3d& p_up = rpts[uidx];
double a = offsdiff2 - (distfn(p_up, p_low1) - zdiff2);
double b = offsdiff2 - (distfn(p_up, p_low2) - zdiff2);
@@ -161,8 +163,9 @@ Contour3D walls(const Polygon& lower, const Polygon& upper,
if(current_fit > prev_fit) {
proceed = Proceed::UPPER;
} else {
- inverted? rfaces.emplace_back(uidx, lnextidx, lidx) :
- rfaces.emplace_back(lidx, lnextidx, uidx);
+ inverted
+ ? ind.emplace_back(int(uidx), int(lnextidx), int(lidx))
+ : ind.emplace_back(int(lidx), int(lnextidx), int(uidx));
++lidx; ++lnextidx;
if(lnextidx == rpts.size()) lnextidx = offs;
@@ -200,7 +203,7 @@ void offset(ExPolygon& sh, coord_t distance) {
}
ClipperOffset offs;
- offs.ArcTolerance = 0.01*mm(1);
+ offs.ArcTolerance = 0.01*scaled(1.0);
Paths result;
offs.AddPath(ctour, jtRound, etClosedPolygon);
offs.AddPaths(holes, jtRound, etClosedPolygon);
@@ -303,16 +306,6 @@ ExPolygons unify(const ExPolygons& shapes) {
return retv;
}
-/// Only a debug function to generate top and bottom plates from a 2D shape.
-/// It is not used in the algorithm directly.
-inline Contour3D roofs(const ExPolygon& poly, coord_t z_distance) {
- auto lower = triangulate_expolygon_3d(poly);
- auto upper = triangulate_expolygon_3d(poly, z_distance*SCALING_FACTOR, true);
- Contour3D ret;
- ret.merge(lower); ret.merge(upper);
- return ret;
-}
-
/// This method will create a rounded edge around a flat polygon in 3d space.
/// 'base_plate' parameter is the target plate.
/// 'radius' is the radius of the edges.
@@ -358,7 +351,7 @@ Contour3D round_edges(const ExPolygon& base_plate,
double x2 = xx*xx;
double stepy = std::sqrt(r2 - x2);
- offset(ob, s*mm(xx));
+ offset(ob, s*scaled(xx));
wh = ceilheight_mm - radius_mm + stepy;
Contour3D pwalls;
@@ -382,7 +375,7 @@ Contour3D round_edges(const ExPolygon& base_plate,
double xx = radius_mm - i*stepx;
double x2 = xx*xx;
double stepy = std::sqrt(r2 - x2);
- offset(ob, s*mm(xx));
+ offset(ob, s*scaled(xx));
wh = ceilheight_mm - radius_mm - stepy;
Contour3D pwalls;
@@ -402,41 +395,6 @@ Contour3D round_edges(const ExPolygon& base_plate,
return curvedwalls;
}
-/// Generating the concave part of the 3D pool with the bottom plate and the
-/// side walls.
-Contour3D inner_bed(const ExPolygon& poly,
- double depth_mm,
- double begin_h_mm = 0)
-{
- Contour3D bottom;
- Pointf3s triangles = triangulate_expolygon_3d(poly, -depth_mm + begin_h_mm);
- bottom.merge(triangles);
-
- coord_t depth = mm(depth_mm);
- coord_t begin_h = mm(begin_h_mm);
-
- auto lines = poly.lines();
-
- // Generate outer walls
- auto fp = [](const Point& p, Point::coord_type z) {
- return unscale(x(p), y(p), z);
- };
-
- for(auto& l : lines) {
- auto s = coord_t(bottom.points.size());
-
- bottom.points.emplace_back(fp(l.a, -depth + begin_h));
- bottom.points.emplace_back(fp(l.b, -depth + begin_h));
- bottom.points.emplace_back(fp(l.a, begin_h));
- bottom.points.emplace_back(fp(l.b, begin_h));
-
- bottom.indices.emplace_back(s + 3, s + 1, s);
- bottom.indices.emplace_back(s + 2, s + 3, s);
- }
-
- return bottom;
-}
-
inline Point centroid(Points& pp) {
Point c;
switch(pp.size()) {
@@ -518,7 +476,7 @@ ExPolygons concave_hull(const ExPolygons& polys, double max_dist_mm = 50,
double dx = x(c) - x(cc), dy = y(c) - y(cc);
double l = std::sqrt(dx * dx + dy * dy);
double nx = dx / l, ny = dy / l;
- double max_dist = mm(max_dist_mm);
+ double max_dist = scaled(max_dist_mm);
ExPolygon& expo = punion[idx++];
BoundingBox querybb(expo);
@@ -534,10 +492,10 @@ ExPolygons concave_hull(const ExPolygons& polys, double max_dist_mm = 50,
ctour.reserve(3);
ctour.emplace_back(cc);
- Point d(coord_t(mm(1)*nx), coord_t(mm(1)*ny));
+ Point d(coord_t(scaled(1.)*nx), coord_t(scaled(1.)*ny));
ctour.emplace_back(c + Point( -y(d), x(d) ));
ctour.emplace_back(c + Point( y(d), -x(d) ));
- offset(r, mm(1));
+ offset(r, scaled(1.));
return r;
});
@@ -569,15 +527,16 @@ void base_plate(const TriangleMesh &mesh, ExPolygons &output, float h,
// Now we have to unify all slice layers which can be an expensive operation
// so we will try to simplify the polygons
ExPolygons tmp; tmp.reserve(count);
- for(ExPolygons& o : out) for(ExPolygon& e : o) {
- auto&& exss = e.simplify(0.1/SCALING_FACTOR);
- for(ExPolygon& ep : exss) tmp.emplace_back(std::move(ep));
- }
+ for(ExPolygons& o : out)
+ for(ExPolygon& e : o) {
+ auto&& exss = e.simplify(scaled(0.1));
+ for(ExPolygon& ep : exss) tmp.emplace_back(std::move(ep));
+ }
ExPolygons utmp = unify(tmp);
for(auto& o : utmp) {
- auto&& smp = o.simplify(0.1/SCALING_FACTOR);
+ auto&& smp = o.simplify(scaled(0.1));
output.insert(output.end(), smp.begin(), smp.end());
}
}
@@ -607,11 +566,11 @@ Contour3D create_base_pool(const ExPolygons &ground_layer,
const double bottom_offs = (thickness + wingheight) / std::tan(slope);
// scaled values
- const coord_t s_thickness = mm(thickness);
- const coord_t s_eradius = mm(cfg.edge_radius_mm);
+ const coord_t s_thickness = scaled(thickness);
+ const coord_t s_eradius = scaled(cfg.edge_radius_mm);
const coord_t s_safety_dist = 2*s_eradius + coord_t(0.8*s_thickness);
- const coord_t s_wingdist = mm(wingdist);
- const coord_t s_bottom_offs = mm(bottom_offs);
+ const coord_t s_wingdist = scaled(wingdist);
+ const coord_t s_bottom_offs = scaled(bottom_offs);
auto& thrcl = cfg.throw_on_cancel;
diff --git a/src/libslic3r/SLA/SLABoilerPlate.hpp b/src/libslic3r/SLA/SLABoilerPlate.hpp
index 602121af9..86e90f3b7 100644
--- a/src/libslic3r/SLA/SLABoilerPlate.hpp
+++ b/src/libslic3r/SLA/SLABoilerPlate.hpp
@@ -11,11 +11,6 @@
namespace Slic3r {
namespace sla {
-using coord_t = Point::coord_type;
-
-/// get the scaled clipper units for a millimeter value
-inline coord_t mm(double v) { return coord_t(v/SCALING_FACTOR); }
-
/// Get x and y coordinates (because we are eigenizing...)
inline coord_t x(const Point& p) { return p(0); }
inline coord_t y(const Point& p) { return p(1); }
@@ -36,12 +31,10 @@ inline coord_t x(const Vec3crd& p) { return p(0); }
inline coord_t y(const Vec3crd& p) { return p(1); }
inline coord_t z(const Vec3crd& p) { return p(2); }
-using Indices = std::vector<Vec3crd>;
-
/// Intermediate struct for a 3D mesh
struct Contour3D {
Pointf3s points;
- Indices indices;
+ std::vector<Vec3i> indices;
void merge(const Contour3D& ctr) {
auto s3 = coord_t(points.size());
diff --git a/src/libslic3r/SLA/SLARotfinder.cpp b/src/libslic3r/SLA/SLARotfinder.cpp
index 1a91041b7..2e64059d6 100644
--- a/src/libslic3r/SLA/SLARotfinder.cpp
+++ b/src/libslic3r/SLA/SLARotfinder.cpp
@@ -44,7 +44,7 @@ std::array<double, 3> find_best_rotation(const ModelObject& modelobj,
// call the status callback in each iteration but the actual value may be
// the same for subsequent iterations (status goes from 0 to 100 but
// iterations can be many more)
- auto objfunc = [&emesh, &status, &statuscb, max_tries]
+ auto objfunc = [&emesh, &status, &statuscb, &stopcond, max_tries]
(double rx, double ry, double rz)
{
EigenMesh3D& m = emesh;
@@ -91,7 +91,7 @@ std::array<double, 3> find_best_rotation(const ModelObject& modelobj,
}
// report status
- statuscb( unsigned(++status * 100.0/max_tries) );
+ if(!stopcond()) statuscb( unsigned(++status * 100.0/max_tries) );
return score;
};
diff --git a/src/libslic3r/SLA/SLASupportTree.cpp b/src/libslic3r/SLA/SLASupportTree.cpp
index cb2001024..ae033c62f 100644
--- a/src/libslic3r/SLA/SLASupportTree.cpp
+++ b/src/libslic3r/SLA/SLASupportTree.cpp
@@ -236,13 +236,13 @@ Contour3D cylinder(double r, double h, size_t ssteps, const Vec3d sp = {0,0,0})
// According to the slicing algorithms, we need to aid them with generating
// a watertight body. So we create a triangle fan for the upper and lower
// ending of the cylinder to close the geometry.
- points.emplace_back(jp); size_t ci = points.size() - 1;
+ points.emplace_back(jp); int ci = int(points.size() - 1);
for(int i = 0; i < steps - 1; ++i)
indices.emplace_back(i + offs + 1, i + offs, ci);
indices.emplace_back(offs, steps + offs - 1, ci);
- points.emplace_back(endp); ci = points.size() - 1;
+ points.emplace_back(endp); ci = int(points.size() - 1);
for(int i = 0; i < steps - 1; ++i)
indices.emplace_back(ci, i, i + 1);
diff --git a/src/libslic3r/SLA/SLASupportTreeIGL.cpp b/src/libslic3r/SLA/SLASupportTreeIGL.cpp
index c368b8604..1609b9ac4 100644
--- a/src/libslic3r/SLA/SLASupportTreeIGL.cpp
+++ b/src/libslic3r/SLA/SLASupportTreeIGL.cpp
@@ -121,19 +121,10 @@ EigenMesh3D::EigenMesh3D(const TriangleMesh& tmesh): m_aabb(new AABBImpl()) {
V.resize(3*stl.stats.number_of_facets, 3);
F.resize(stl.stats.number_of_facets, 3);
for (unsigned int i = 0; i < stl.stats.number_of_facets; ++i) {
- const stl_facet* facet = stl.facet_start+i;
- V(3*i+0, 0) = double(facet->vertex[0](0));
- V(3*i+0, 1) = double(facet->vertex[0](1));
- V(3*i+0, 2) = double(facet->vertex[0](2));
-
- V(3*i+1, 0) = double(facet->vertex[1](0));
- V(3*i+1, 1) = double(facet->vertex[1](1));
- V(3*i+1, 2) = double(facet->vertex[1](2));
-
- V(3*i+2, 0) = double(facet->vertex[2](0));
- V(3*i+2, 1) = double(facet->vertex[2](1));
- V(3*i+2, 2) = double(facet->vertex[2](2));
-
+ const stl_facet &facet = stl.facet_start[i];
+ V.block<1, 3>(3 * i + 0, 0) = facet.vertex[0].cast<double>();
+ V.block<1, 3>(3 * i + 1, 0) = facet.vertex[1].cast<double>();
+ V.block<1, 3>(3 * i + 2, 0) = facet.vertex[2].cast<double>();
F(i, 0) = int(3*i+0);
F(i, 1) = int(3*i+1);
F(i, 2) = int(3*i+2);