Wipe tower: changed the way how initial wipe tower preview depth is calculated

This commit is contained in:
Lukas Matena 2023-03-17 13:49:35 +01:00
parent 0cedbe91ca
commit 9775bf213d
4 changed files with 41 additions and 13 deletions

View File

@ -1346,6 +1346,31 @@ std::pair<double, double> WipeTower::get_wipe_tower_cone_base(double width, doub
return std::make_pair(R, support_scale); return std::make_pair(R, support_scale);
} }
// Static method to extract wipe_volumes[from][to] from the configuration.
std::vector<std::vector<float>> WipeTower::extract_wipe_volumes(const PrintConfig& config)
{
// Get wiping matrix to get number of extruders and convert vector<double> to vector<float>:
std::vector<float> wiping_matrix(cast<float>(config.wiping_volumes_matrix.values));
// Extract purging volumes for each extruder pair:
std::vector<std::vector<float>> wipe_volumes;
const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON);
for (unsigned int i = 0; i<number_of_extruders; ++i)
wipe_volumes.push_back(std::vector<float>(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders));
// Also include filament_minimal_purge_on_wipe_tower. This is needed for the preview.
for (unsigned int i = 0; i<number_of_extruders; ++i) {
for (unsigned int j = 0; j<number_of_extruders; ++j) {
float w = wipe_volumes[i][j];
if (wipe_volumes[i][j] < config.filament_minimal_purge_on_wipe_tower.get_at(j))
wipe_volumes[i][j] = config.filament_minimal_purge_on_wipe_tower.get_at(j);
}
}
return wipe_volumes;
}
// Appends a toolchange into m_plan and calculates neccessary depth of the corresponding box // Appends a toolchange into m_plan and calculates neccessary depth of the corresponding box
void WipeTower::plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool, void WipeTower::plan_toolchange(float z_par, float layer_height_par, unsigned int old_tool,
unsigned int new_tool, float wipe_volume) unsigned int new_tool, float wipe_volume)

View File

@ -22,8 +22,8 @@ class WipeTower
{ {
public: public:
static const std::string never_skip_tag() { return "_GCODE_WIPE_TOWER_NEVER_SKIP_TAG"; } static const std::string never_skip_tag() { return "_GCODE_WIPE_TOWER_NEVER_SKIP_TAG"; }
static std::pair<double, double> get_wipe_tower_cone_base(double width, double height, double depth, double angle_deg); static std::pair<double, double> get_wipe_tower_cone_base(double width, double height, double depth, double angle_deg);
static std::vector<std::vector<float>> extract_wipe_volumes(const PrintConfig& config);
struct Extrusion struct Extrusion
{ {

View File

@ -1337,11 +1337,22 @@ const WipeTowerData& Print::wipe_tower_data(size_t extruders_cnt) const
{ {
// If the wipe tower wasn't created yet, make sure the depth and brim_width members are set to default. // If the wipe tower wasn't created yet, make sure the depth and brim_width members are set to default.
if (! is_step_done(psWipeTower) && extruders_cnt !=0) { if (! is_step_done(psWipeTower) && extruders_cnt !=0) {
const_cast<Print*>(this)->m_wipe_tower_data.brim_width = m_config.wipe_tower_brim_width;
// Calculating depth should take into account currently set wiping volumes.
// For a long time, the initial preview would just use 900/width per toolchange (15mm on a 60mm wide tower)
// and it worked well enough. Let's try to do slightly better by accounting for the purging volumes.
std::vector<std::vector<float>> wipe_volumes = WipeTower::extract_wipe_volumes(m_config);
std::vector<float> max_wipe_volumes;
for (const std::vector<float>& v : wipe_volumes)
max_wipe_volumes.emplace_back(*std::max_element(v.begin(), v.end()));
float maximum = std::accumulate(max_wipe_volumes.begin(), max_wipe_volumes.end(), 0.f);
maximum = maximum * extruders_cnt / max_wipe_volumes.size();
float width = float(m_config.wipe_tower_width); float width = float(m_config.wipe_tower_width);
float layer_height = 0.2f; // just assume fixed value, it will still be better than before.
const_cast<Print*>(this)->m_wipe_tower_data.depth = (900.f/width) * float(extruders_cnt - 1); const_cast<Print*>(this)->m_wipe_tower_data.depth = (maximum/layer_height)/width;
const_cast<Print*>(this)->m_wipe_tower_data.brim_width = m_config.wipe_tower_brim_width;
} }
return m_wipe_tower_data; return m_wipe_tower_data;
@ -1353,13 +1364,7 @@ void Print::_make_wipe_tower()
if (! this->has_wipe_tower()) if (! this->has_wipe_tower())
return; return;
// Get wiping matrix to get number of extruders and convert vector<double> to vector<float>: std::vector<std::vector<float>> wipe_volumes = WipeTower::extract_wipe_volumes(m_config);
std::vector<float> wiping_matrix(cast<float>(m_config.wiping_volumes_matrix.values));
// Extract purging volumes for each extruder pair:
std::vector<std::vector<float>> wipe_volumes;
const unsigned int number_of_extruders = (unsigned int)(sqrt(wiping_matrix.size())+EPSILON);
for (unsigned int i = 0; i<number_of_extruders; ++i)
wipe_volumes.push_back(std::vector<float>(wiping_matrix.begin()+i*number_of_extruders, wiping_matrix.begin()+(i+1)*number_of_extruders));
// Let the ToolOrdering class know there will be initial priming extrusions at the start of the print. // Let the ToolOrdering class know there will be initial priming extrusions at the start of the print.
m_wipe_tower_data.tool_ordering = ToolOrdering(*this, (unsigned int)-1, true); m_wipe_tower_data.tool_ordering = ToolOrdering(*this, (unsigned int)-1, true);
@ -1412,7 +1417,7 @@ void Print::_make_wipe_tower()
//wipe_tower.set_zhop(); //wipe_tower.set_zhop();
// Set the extruder & material properties at the wipe tower object. // Set the extruder & material properties at the wipe tower object.
for (size_t i = 0; i < number_of_extruders; ++ i) for (size_t i = 0; i < m_config.nozzle_diameter.size(); ++ i)
wipe_tower.set_extruder(i, m_config); wipe_tower.set_extruder(i, m_config);
m_wipe_tower_data.priming = Slic3r::make_unique<std::vector<WipeTower::ToolChangeResult>>( m_wipe_tower_data.priming = Slic3r::make_unique<std::vector<WipeTower::ToolChangeResult>>(

View File

@ -488,8 +488,6 @@ int GLVolumeCollection::load_wipe_tower_preview(
float rotation_angle, bool size_unknown, float brim_width) float rotation_angle, bool size_unknown, float brim_width)
#endif // ENABLE_OPENGL_ES #endif // ENABLE_OPENGL_ES
{ {
if (depth < 0.01f)
return int(this->volumes.size() - 1);
if (height == 0.0f) if (height == 0.0f)
height = 0.1f; height = 0.1f;