Skip to content

Commit

Permalink
Merge branch 'master_slic3rPE_PR'
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Oct 16, 2018
2 parents a20f93e + d7056e5 commit 280bb5d
Show file tree
Hide file tree
Showing 17 changed files with 697 additions and 26 deletions.
5 changes: 3 additions & 2 deletions xs/src/libslic3r/ExtrusionEntity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,10 @@ class ExtrusionMultiPath : public ExtrusionEntity
// Minimum volumetric velocity of this extrusion entity. Used by the constant nozzle pressure algorithm.
double min_mm3_per_mm() const;
Polyline as_polyline() const;
virtual double total_volume() const { double volume =0.; for (const auto& path : paths) volume += path.total_volume(); return volume; }
virtual double total_volume() const { double volume = 0.; for (const auto& path : paths) volume += path.total_volume(); return volume; }
};


// Single continuous extrusion loop, possibly with varying extrusion thickness, extrusion height or bridging / non bridging.
class ExtrusionLoop : public ExtrusionEntity
{
Expand Down Expand Up @@ -244,7 +245,7 @@ class ExtrusionLoop : public ExtrusionEntity
// Minimum volumetric velocity of this extrusion entity. Used by the constant nozzle pressure algorithm.
double min_mm3_per_mm() const;
Polyline as_polyline() const { return this->polygon().split_at_first_point(); }
virtual double total_volume() const { double volume =0.; for (const auto& path : paths) volume += path.total_volume(); return volume; }
virtual double total_volume() const { double volume = 0.; for (const auto& path : paths) volume += path.total_volume(); return volume; }

private:
ExtrusionLoopRole m_loop_role;
Expand Down
2 changes: 2 additions & 0 deletions xs/src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2367,6 +2367,8 @@ std::string GCode::_extrude(const ExtrusionPath &path, std::string description,
speed = m_config.get_abs_value("top_solid_infill_speed");
} else if (path.role() == erGapFill) {
speed = m_config.get_abs_value("gap_fill_speed");
} else if (path.role() == erNone) {
speed = m_config.get_abs_value("travel_speed");
} else {
CONFESS("Invalid speed");
}
Expand Down
5 changes: 3 additions & 2 deletions xs/src/libslic3r/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ void Layer::make_perimeters()
&& config.gap_fill_speed == other_config.gap_fill_speed
&& config.overhangs == other_config.overhangs
&& config.serialize("perimeter_extrusion_width").compare(other_config.serialize("perimeter_extrusion_width")) == 0
&& config.thin_walls == other_config.thin_walls
&& config.external_perimeters_first == other_config.external_perimeters_first) {
&& config.thin_walls == other_config.thin_walls
&& config.external_perimeters_first == other_config.external_perimeters_first
&& config.perimeter_loop == other_config.perimeter_loop) {
layerms.push_back(other_layerm);
done.insert(it - this->regions.begin());
}
Expand Down
8 changes: 8 additions & 0 deletions xs/src/libslic3r/Line.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@ Line::ccw(const Point& point) const
return point.ccw(*this);
}

coord_t
Line::dot(Line &l2) const
{
Vector v_1 = vector();
Vector v_2 = l2.vector();
return v_1.x*v_2.x + v_1.y*v_2.y;
}

double Line3::length() const
{
return a.distance_to(b);
Expand Down
1 change: 1 addition & 0 deletions xs/src/libslic3r/Line.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class Line
void extend_start(double distance);
bool intersection(const Line& line, Point* intersection) const;
double ccw(const Point& point) const;
coord_t dot(Line &l2) const;
};

class ThickLine : public Line
Expand Down
4 changes: 4 additions & 0 deletions xs/src/libslic3r/MedialAxis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,15 @@ MedialAxis::extends_line(ThickPolyline& polyline, const ExPolygons& anchors, con
new_back = polyline.points.back();
} else {
(void)this->expolygon.contour.first_intersection(line, &new_back);
// safety check if no intersection
if (new_back.x == 0 && new_back.y == 0) return;
polyline.points.push_back(new_back);
polyline.width.push_back(polyline.width.back());
}
Point new_bound;
(void)bounds.contour.first_intersection(line, &new_bound);
// safety check if no intersection
if (new_bound.x == 0 && new_bound.y == 0) return;
/* if (new_bound.coincides_with_epsilon(new_back)) {
return;
}*/
Expand Down
37 changes: 37 additions & 0 deletions xs/src/libslic3r/MultiPoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,43 @@ MultiPoint::dump_perl() const
return ret.str();
}

// Projection of a point onto the polygon.
Point MultiPoint::point_projection(const Point &point) const {
Point proj = point;
double dmin = std::numeric_limits<double>::max();
if (!this->points.empty()) {
for (size_t i = 0; i < this->points.size()-1; ++i) {
const Point &pt0 = this->points[i];
const Point &pt1 = this->points[i + 1];
double d = pt0.distance_to(point);
if (d < dmin) {
dmin = d;
proj = pt0;
}
d = pt1.distance_to(point);
if (d < dmin) {
dmin = d;
proj = pt1;
}
Pointf v1(coordf_t(pt1.x - pt0.x), coordf_t(pt1.y - pt0.y));
coordf_t div = dot(v1);
if (div > 0.) {
Pointf v2(coordf_t(point.x - pt0.x), coordf_t(point.y - pt0.y));
coordf_t t = dot(v1, v2) / div;
if (t > 0. && t < 1.) {
Point foot(coord_t(floor(coordf_t(pt0.x) + t * v1.x + 0.5)), coord_t(floor(coordf_t(pt0.y) + t * v1.y + 0.5)));
d = foot.distance_to(point);
if (d < dmin) {
dmin = d;
proj = foot;
}
}
}
}
}
return proj;
}

//FIXME This is very inefficient in term of memory use.
// The recursive algorithm shall run in place, not allocating temporary data in each recursion.
Points
Expand Down
2 changes: 2 additions & 0 deletions xs/src/libslic3r/MultiPoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ class MultiPoint
bool intersection(const Line& line, Point* intersection) const;
bool first_intersection(const Line& line, Point* intersection) const;
std::string dump_perl() const;
// Projection of a point onto the lines defined by the points.
virtual Point point_projection(const Point &point) const;

static Points _douglas_peucker(const Points &points, const double tolerance);
};
Expand Down
Loading

0 comments on commit 280bb5d

Please sign in to comment.