use center of enforcer only with spAligned

This commit is contained in:
Lukas Matena 2020-09-11 16:27:06 +02:00
parent fffb79a085
commit 8dd345ed4c
2 changed files with 22 additions and 10 deletions

View File

@ -9,6 +9,18 @@
namespace Slic3r { namespace Slic3r {
// This penalty is added to all points inside custom blockers (subtracted from pts inside enforcers).
static constexpr float ENFORCER_BLOCKER_PENALTY = 1e6;
// In case there are custom enforcers/blockers, the loop polygon shall always have
// sides smaller than this (so it isn't limited to original resolution).
static constexpr float MINIMAL_POLYGON_SIDE = scale_(0.2f);
// When spAligned is active and there is a support enforcer,
// add this penalty to its center.
static constexpr float ENFORCER_CENTER_PENALTY = -1e3;
static float extrudate_overlap_penalty(float nozzle_r, float weight_zero, float overlap_distance) static float extrudate_overlap_penalty(float nozzle_r, float weight_zero, float overlap_distance)
@ -205,7 +217,7 @@ Point SeamPlacer::get_seam(const size_t layer_idx, const SeamPosition seam_posit
if (this->is_custom_seam_on_layer(layer_idx)) { if (this->is_custom_seam_on_layer(layer_idx)) {
// Seam enf/blockers can begin and end in between the original vertices. // Seam enf/blockers can begin and end in between the original vertices.
// Let add extra points in between and update the leghths. // Let add extra points in between and update the leghths.
polygon.densify(scale_(0.2f)); polygon.densify(MINIMAL_POLYGON_SIDE);
} }
if (seam_position != spRandom) { if (seam_position != spRandom) {
@ -295,7 +307,7 @@ Point SeamPlacer::get_seam(const size_t layer_idx, const SeamPosition seam_posit
// Custom seam. Huge (negative) constant penalty is applied inside // Custom seam. Huge (negative) constant penalty is applied inside
// blockers (enforcers) to rule out points that should not win. // blockers (enforcers) to rule out points that should not win.
this->apply_custom_seam(polygon, penalties, lengths, layer_idx); this->apply_custom_seam(polygon, penalties, lengths, layer_idx, seam_position);
// Find a point with a minimum penalty. // Find a point with a minimum penalty.
size_t idx_min = std::min_element(penalties.begin(), penalties.end()) - penalties.begin(); size_t idx_min = std::min_element(penalties.begin(), penalties.end()) - penalties.begin();
@ -529,13 +541,11 @@ static std::vector<size_t> find_enforcer_centers(const Polygon& polygon,
void SeamPlacer::apply_custom_seam(const Polygon& polygon, void SeamPlacer::apply_custom_seam(const Polygon& polygon,
std::vector<float>& penalties, std::vector<float>& penalties,
const std::vector<float>& lengths, const std::vector<float>& lengths,
int layer_id) const int layer_id, SeamPosition seam_position) const
{ {
if (! is_custom_seam_on_layer(layer_id)) if (! is_custom_seam_on_layer(layer_id))
return; return;
static constexpr float ENFORCER_BLOCKER_PENALTY = 1e6;
std::vector<size_t> enforcers_idxs; std::vector<size_t> enforcers_idxs;
std::vector<size_t> blockers_idxs; std::vector<size_t> blockers_idxs;
this->get_enforcers_and_blockers(layer_id, polygon, enforcers_idxs, blockers_idxs); this->get_enforcers_and_blockers(layer_id, polygon, enforcers_idxs, blockers_idxs);
@ -548,10 +558,12 @@ void SeamPlacer::apply_custom_seam(const Polygon& polygon,
assert(i < penalties.size()); assert(i < penalties.size());
penalties[i] += float(ENFORCER_BLOCKER_PENALTY); penalties[i] += float(ENFORCER_BLOCKER_PENALTY);
} }
std::vector<size_t> enf_centers = find_enforcer_centers(polygon, lengths, enforcers_idxs); if (seam_position == spAligned) {
for (size_t idx : enf_centers) { std::vector<size_t> enf_centers = find_enforcer_centers(polygon, lengths, enforcers_idxs);
assert(idx < penalties.size()); for (size_t idx : enf_centers) {
penalties[idx] -= 1000.f; assert(idx < penalties.size());
penalties[idx] += ENFORCER_CENTER_PENALTY;
}
} }
//////////////////////// ////////////////////////

View File

@ -36,7 +36,7 @@ private:
void apply_custom_seam(const Polygon& polygon, void apply_custom_seam(const Polygon& polygon,
std::vector<float>& penalties, std::vector<float>& penalties,
const std::vector<float>& lengths, const std::vector<float>& lengths,
int layer_id) const; int layer_id, SeamPosition seam_position) const;
// Return random point of a polygon. The distribution will be uniform // Return random point of a polygon. The distribution will be uniform
// along the contour and account for enforcers and blockers. // along the contour and account for enforcers and blockers.