Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_colorprint_no_m600
This commit is contained in:
commit
b79457b723
3 changed files with 67 additions and 35 deletions
|
@ -148,8 +148,9 @@ protected:
|
|||
double m_norm; // A coefficient to scale distances
|
||||
MultiPolygon m_merged_pile; // The already merged pile (vector of items)
|
||||
Box m_pilebb; // The bounding box of the merged pile.
|
||||
ItemGroup m_remaining; // Remaining items (m_items at the beginning)
|
||||
ItemGroup m_items; // The items to be packed
|
||||
ItemGroup m_remaining; // Remaining items
|
||||
ItemGroup m_items; // allready packed items
|
||||
size_t m_item_count = 0; // Number of all items to be packed
|
||||
|
||||
template<class T> ArithmeticOnly<T, double> norm(T val)
|
||||
{
|
||||
|
@ -167,7 +168,6 @@ protected:
|
|||
const double bin_area = m_bin_area;
|
||||
const SpatIndex& spatindex = m_rtree;
|
||||
const SpatIndex& smalls_spatindex = m_smallsrtree;
|
||||
const ItemGroup& remaining = m_remaining;
|
||||
|
||||
// We will treat big items (compared to the print bed) differently
|
||||
auto isBig = [bin_area](double a) {
|
||||
|
@ -209,8 +209,8 @@ protected:
|
|||
} compute_case;
|
||||
|
||||
bool bigitems = isBig(item.area()) || spatindex.empty();
|
||||
if(bigitems && !remaining.empty()) compute_case = BIG_ITEM;
|
||||
else if (bigitems && remaining.empty()) compute_case = LAST_BIG_ITEM;
|
||||
if(bigitems && !m_remaining.empty()) compute_case = BIG_ITEM;
|
||||
else if (bigitems && m_remaining.empty()) compute_case = LAST_BIG_ITEM;
|
||||
else compute_case = SMALL_ITEM;
|
||||
|
||||
switch (compute_case) {
|
||||
|
@ -235,7 +235,7 @@ protected:
|
|||
// The smalles distance from the arranged pile center:
|
||||
double dist = norm(*(std::min_element(dists.begin(), dists.end())));
|
||||
double bindist = norm(pl::distance(ibb.center(), bincenter));
|
||||
dist = 0.8 * dist + 0.2*bindist;
|
||||
dist = 0.8 * dist + 0.2 * bindist;
|
||||
|
||||
// Prepare a variable for the alignment score.
|
||||
// This will indicate: how well is the candidate item
|
||||
|
@ -267,29 +267,24 @@ protected:
|
|||
if(ascore < alignment_score) alignment_score = ascore;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
density = std::sqrt(norm(fullbb.width()) * norm(fullbb.height()));
|
||||
|
||||
double R = double(m_remaining.size()) / m_item_count;
|
||||
|
||||
// The final mix of the score is the balance between the
|
||||
// distance from the full pile center, the pack density and
|
||||
// the alignment with the neighbors
|
||||
if (result.empty())
|
||||
score = 0.5 * dist + 0.5 * density;
|
||||
score = 0.50 * dist + 0.50 * density;
|
||||
else
|
||||
score = 0.40 * dist + 0.40 * density + 0.2 * alignment_score;
|
||||
score = R * 0.60 * dist +
|
||||
(1.0 - R) * 0.20 * density +
|
||||
0.20 * alignment_score;
|
||||
|
||||
break;
|
||||
}
|
||||
case LAST_BIG_ITEM: {
|
||||
auto mp = m_merged_pile;
|
||||
mp.emplace_back(item.transformedShape());
|
||||
auto chull = sl::convexHull(mp);
|
||||
|
||||
placers::EdgeCache<clppr::Polygon> ec(chull);
|
||||
|
||||
double circ = norm(ec.circumference());
|
||||
double bcirc = 2.0 * norm(fullbb.width() + fullbb.height());
|
||||
score = 0.5 * circ + 0.5 * bcirc;
|
||||
score = norm(pl::distance(ibb.center(), m_pilebb.center()));
|
||||
break;
|
||||
}
|
||||
case SMALL_ITEM: {
|
||||
|
@ -355,9 +350,11 @@ public:
|
|||
m_pck.configure(m_pconf);
|
||||
}
|
||||
|
||||
template<class...Args> inline void operator()(Args&&...args) {
|
||||
m_rtree.clear(); /*m_preload_idx.clear();*/
|
||||
m_pck.execute(std::forward<Args>(args)...);
|
||||
template<class It> inline void operator()(It from, It to) {
|
||||
m_rtree.clear();
|
||||
m_item_count += size_t(to - from);
|
||||
m_pck.execute(from, to);
|
||||
m_item_count = 0;
|
||||
}
|
||||
|
||||
inline void preload(std::vector<Item>& fixeditems) {
|
||||
|
@ -376,6 +373,7 @@ public:
|
|||
}
|
||||
|
||||
m_pck.configure(m_pconf);
|
||||
m_item_count += fixeditems.size();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -262,8 +262,14 @@ std::vector<unsigned int> Print::object_extruders() const
|
|||
{
|
||||
std::vector<unsigned int> extruders;
|
||||
extruders.reserve(m_regions.size() * 3);
|
||||
for (const PrintRegion *region : m_regions)
|
||||
region->collect_object_printing_extruders(extruders);
|
||||
std::vector<unsigned char> region_used(m_regions.size(), false);
|
||||
for (const PrintObject *object : m_objects)
|
||||
for (const std::vector<std::pair<t_layer_height_range, int>> &volumes_per_region : object->region_volumes)
|
||||
if (! volumes_per_region.empty())
|
||||
region_used[&volumes_per_region - &object->region_volumes.front()] = true;
|
||||
for (size_t idx_region = 0; idx_region < m_regions.size(); ++ idx_region)
|
||||
if (region_used[idx_region])
|
||||
m_regions[idx_region]->collect_object_printing_extruders(extruders);
|
||||
sort_remove_duplicates(extruders);
|
||||
return extruders;
|
||||
}
|
||||
|
@ -273,17 +279,24 @@ std::vector<unsigned int> Print::support_material_extruders() const
|
|||
{
|
||||
std::vector<unsigned int> extruders;
|
||||
bool support_uses_current_extruder = false;
|
||||
auto num_extruders = (unsigned int)m_config.nozzle_diameter.size();
|
||||
|
||||
for (PrintObject *object : m_objects) {
|
||||
if (object->has_support_material()) {
|
||||
assert(object->config().support_material_extruder >= 0);
|
||||
if (object->config().support_material_extruder == 0)
|
||||
support_uses_current_extruder = true;
|
||||
else
|
||||
extruders.push_back(object->config().support_material_extruder - 1);
|
||||
else {
|
||||
unsigned int i = (unsigned int)object->config().support_material_extruder - 1;
|
||||
extruders.emplace_back((i >= num_extruders) ? 0 : i);
|
||||
}
|
||||
assert(object->config().support_material_interface_extruder >= 0);
|
||||
if (object->config().support_material_interface_extruder == 0)
|
||||
support_uses_current_extruder = true;
|
||||
else
|
||||
extruders.push_back(object->config().support_material_interface_extruder - 1);
|
||||
else {
|
||||
unsigned int i = (unsigned int)object->config().support_material_interface_extruder - 1;
|
||||
extruders.emplace_back((i >= num_extruders) ? 0 : i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -577,6 +590,8 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
|
|||
|
||||
// Apply variables to placeholder parser. The placeholder parser is used by G-code export,
|
||||
// which should be stopped if print_diff is not empty.
|
||||
size_t num_extruders = m_config.nozzle_diameter.size();
|
||||
bool num_extruders_changed = false;
|
||||
if (! full_config_diff.empty() || ! placeholder_parser_overrides.empty()) {
|
||||
update_apply_status(this->invalidate_step(psGCodeExport));
|
||||
m_placeholder_parser.apply_config(std::move(placeholder_parser_overrides));
|
||||
|
@ -592,6 +607,10 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
|
|||
// Handle changes to regions config defaults
|
||||
m_default_region_config.apply_only(new_full_config, region_diff, true);
|
||||
m_full_print_config = std::move(new_full_config);
|
||||
if (num_extruders != m_config.nozzle_diameter.size()) {
|
||||
num_extruders = m_config.nozzle_diameter.size();
|
||||
num_extruders_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
class LayerRanges
|
||||
|
@ -768,7 +787,6 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
|
|||
print_object_status.emplace(PrintObjectStatus(print_object));
|
||||
|
||||
// 3) Synchronize ModelObjects & PrintObjects.
|
||||
size_t num_extruders = m_config.nozzle_diameter.size();
|
||||
for (size_t idx_model_object = 0; idx_model_object < model.objects.size(); ++ idx_model_object) {
|
||||
ModelObject &model_object = *m_model.objects[idx_model_object];
|
||||
auto it_status = model_object_status.find(ModelObjectStatus(model_object.id()));
|
||||
|
@ -815,7 +833,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_
|
|||
bool object_config_changed = model_object.config != model_object_new.config;
|
||||
if (object_config_changed)
|
||||
static_cast<DynamicPrintConfig&>(model_object.config) = static_cast<const DynamicPrintConfig&>(model_object_new.config);
|
||||
if (! object_diff.empty() || object_config_changed) {
|
||||
if (! object_diff.empty() || object_config_changed || num_extruders_changed) {
|
||||
PrintObjectConfig new_config = PrintObject::object_config_from_model_object(m_default_object_config, model_object, num_extruders);
|
||||
auto range = print_object_status.equal_range(PrintObjectStatus(model_object.id()));
|
||||
for (auto it = range.first; it != range.second; ++ it) {
|
||||
|
@ -1144,7 +1162,12 @@ std::string Print::validate() const
|
|||
// #4043
|
||||
if (total_copies_count > 1 && ! m_config.complete_objects.value)
|
||||
return L("The Spiral Vase option can only be used when printing a single object.");
|
||||
if (m_regions.size() > 1)
|
||||
assert(m_objects.size() == 1);
|
||||
size_t num_regions = 0;
|
||||
for (const std::vector<std::pair<t_layer_height_range, int>> &volumes_per_region : m_objects.front()->region_volumes)
|
||||
if (! volumes_per_region.empty())
|
||||
++ num_regions;
|
||||
if (num_regions > 1)
|
||||
return L("The Spiral Vase option can only be used when printing single material objects.");
|
||||
}
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ Flow PrintRegion::flow(FlowRole role, double layer_height, bool bridge, bool fir
|
|||
}
|
||||
double nozzle_diameter = m_print->config().nozzle_diameter.get_at(extruder-1);
|
||||
|
||||
return Flow::new_from_config_width(role, config_width, nozzle_diameter, layer_height, bridge ? (float)m_config.bridge_flow_ratio : 0.0);
|
||||
return Flow::new_from_config_width(role, config_width, (float)nozzle_diameter, (float)layer_height, bridge ? (float)m_config.bridge_flow_ratio : 0.0f);
|
||||
}
|
||||
|
||||
coordf_t PrintRegion::nozzle_dmr_avg(const PrintConfig &print_config) const
|
||||
|
@ -64,16 +64,27 @@ coordf_t PrintRegion::bridging_height_avg(const PrintConfig &print_config) const
|
|||
void PrintRegion::collect_object_printing_extruders(const PrintConfig &print_config, const PrintRegionConfig ®ion_config, std::vector<unsigned int> &object_extruders)
|
||||
{
|
||||
// These checks reflect the same logic used in the GUI for enabling/disabling extruder selection fields.
|
||||
auto num_extruders = (int)print_config.nozzle_diameter.size();
|
||||
auto emplace_extruder = [num_extruders, &object_extruders](int extruder_id) {
|
||||
int i = std::max(0, extruder_id - 1);
|
||||
object_extruders.emplace_back((i >= num_extruders) ? 0 : i);
|
||||
};
|
||||
if (region_config.perimeters.value > 0 || print_config.brim_width.value > 0)
|
||||
object_extruders.emplace_back(region_config.perimeter_extruder - 1);
|
||||
emplace_extruder(region_config.perimeter_extruder);
|
||||
if (region_config.fill_density.value > 0)
|
||||
object_extruders.emplace_back(region_config.infill_extruder - 1);
|
||||
emplace_extruder(region_config.infill_extruder);
|
||||
if (region_config.top_solid_layers.value > 0 || region_config.bottom_solid_layers.value > 0)
|
||||
object_extruders.emplace_back(region_config.solid_infill_extruder - 1);
|
||||
emplace_extruder(region_config.solid_infill_extruder);
|
||||
}
|
||||
|
||||
void PrintRegion::collect_object_printing_extruders(std::vector<unsigned int> &object_extruders) const
|
||||
{
|
||||
auto num_extruders = (int)print()->config().nozzle_diameter.size();
|
||||
// PrintRegion, if used by some PrintObject, shall have all the extruders set to an existing printer extruder.
|
||||
// If not, then there must be something wrong with the Print::apply() function.
|
||||
assert(this->config().perimeter_extruder <= num_extruders);
|
||||
assert(this->config().infill_extruder <= num_extruders);
|
||||
assert(this->config().solid_infill_extruder <= num_extruders);
|
||||
collect_object_printing_extruders(print()->config(), this->config(), object_extruders);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue