add throw if canceled calls into support spot generating algorithm

This commit is contained in:
PavelMikus 2023-01-10 16:12:32 +01:00 committed by Pavel Mikuš
parent a57680ea67
commit 727e7cc4f1
5 changed files with 18 additions and 12 deletions

View File

@ -13,7 +13,7 @@
namespace Slic3r
{
void PrintTryCancel::operator()()
void PrintTryCancel::operator()() const
{
m_print->throw_if_canceled();
}

View File

@ -340,7 +340,7 @@ class PrintTryCancel
{
public:
// calls print.throw_if_canceled().
void operator()();
void operator()() const;
private:
friend PrintBase;
PrintTryCancel() = delete;

View File

@ -7,6 +7,7 @@
#include "I18N.hpp"
#include "Layer.hpp"
#include "MutablePolygon.hpp"
#include "PrintBase.hpp"
#include "SupportMaterial.hpp"
#include "TreeSupport.hpp"
#include "Surface.hpp"
@ -420,8 +421,9 @@ void PrintObject::generate_support_spots()
BOOST_LOG_TRIVIAL(debug) << "Searching support spots - start";
m_print->set_status(75, L("Searching support spots"));
if (!this->shared_regions()->generated_support_points.has_value()) {
PrintTryCancel cancel_func = m_print->make_try_cancel();
SupportSpotsGenerator::Params params{this->print()->m_config.filament_type.values};
SupportSpotsGenerator::SupportPoints supp_points = SupportSpotsGenerator::full_search(this, params);
SupportSpotsGenerator::SupportPoints supp_points = SupportSpotsGenerator::full_search(this, cancel_func, params);
this->m_shared_regions->generated_support_points = {this->trafo_centered(), supp_points};
m_print->throw_if_canceled();
}
@ -463,7 +465,6 @@ void PrintObject::estimate_curled_extrusions()
SupportSpotsGenerator::Params params{this->print()->m_config.filament_type.values};
SupportSpotsGenerator::estimate_supports_malformations(this->support_layers(), support_flow_width, params);
SupportSpotsGenerator::estimate_malformations(this->layers(), params);
m_print->throw_if_canceled();
BOOST_LOG_TRIVIAL(debug) << "Estimating areas with curled extrusions - end";
}
@ -787,10 +788,10 @@ bool PrintObject::invalidate_step(PrintObjectStep step)
} else if (step == posPrepareInfill) {
invalidated |= this->invalidate_steps({ posInfill, posIroning });
} else if (step == posInfill) {
invalidated |= this->invalidate_steps({ posIroning });
invalidated |= this->invalidate_steps({ posIroning, posSupportSpotsSearch });
invalidated |= m_print->invalidate_steps({ psSkirtBrim });
} else if (step == posSlice) {
invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posSupportMaterial, posEstimateCurledExtrusions });
invalidated |= this->invalidate_steps({ posPerimeters, posPrepareInfill, posInfill, posIroning, posSupportSpotsSearch, posSupportMaterial, posEstimateCurledExtrusions });
invalidated |= m_print->invalidate_steps({ psSkirtBrim });
m_slicing_params.valid = false;
} else if (step == posSupportMaterial) {

View File

@ -8,6 +8,7 @@
#include "Point.hpp"
#include "Polygon.hpp"
#include "Print.hpp"
#include "PrintBase.hpp"
#include "Tesselate.hpp"
#include "libslic3r.h"
#include "tbb/parallel_for.h"
@ -32,8 +33,8 @@
#include "libslic3r/ClipperUtils.hpp"
#include "Geometry/ConvexHull.hpp"
// #define DETAILED_DEBUG_LOGS
// #define DEBUG_FILES
#define DETAILED_DEBUG_LOGS
#define DEBUG_FILES
#ifdef DEBUG_FILES
#include <boost/nowide/cstdio.hpp>
@ -661,7 +662,7 @@ public:
}
};
SupportPoints check_stability(const PrintObject *po, const Params &params)
SupportPoints check_stability(const PrintObject *po, const PrintTryCancel& cancel_func, const Params &params)
{
SupportPoints supp_points{};
SupportGridFilter supports_presence_grid(po, params.min_distance_between_support_points);
@ -674,6 +675,7 @@ SupportPoints check_stability(const PrintObject *po, const Params &params)
std::unordered_map<size_t, SliceConnection> next_slice_idx_to_weakest_connection;
for (size_t layer_idx = 0; layer_idx < po->layer_count(); ++layer_idx) {
cancel_func();
const Layer *layer = po->get_layer(layer_idx);
float bottom_z = layer->bottom_z();
auto create_support_point_position = [bottom_z](const Vec2f &layer_pos) { return Vec3f{layer_pos.x(), layer_pos.y(), bottom_z}; };
@ -873,9 +875,9 @@ void debug_export(SupportPoints support_points, std::string file_name)
// std::vector<size_t> quick_search(const PrintObject *po, const Params &params) {
// return {};
// }
SupportPoints full_search(const PrintObject *po, const Params &params)
SupportPoints full_search(const PrintObject *po, const PrintTryCancel& cancel_func, const Params &params)
{
SupportPoints supp_points = check_stability(po, params);
SupportPoints supp_points = check_stability(po, cancel_func, params);
#ifdef DEBUG_FILES
debug_export(supp_points, "issues");
#endif

View File

@ -3,6 +3,7 @@
#include "Layer.hpp"
#include "Line.hpp"
#include "PrintBase.hpp"
#include <boost/log/trivial.hpp>
#include <vector>
@ -22,6 +23,8 @@ struct Params {
filament_type = std::string("PLA");
} else {
filament_type = filament_types[0];
BOOST_LOG_TRIVIAL(debug)
<< "SupportSpotsGenerator: applying filament type: " << filament_type;
}
}
@ -76,7 +79,7 @@ struct Malformations {
};
// std::vector<size_t> quick_search(const PrintObject *po, const Params &params);
SupportPoints full_search(const PrintObject *po, const Params &params);
SupportPoints full_search(const PrintObject *po, const PrintTryCancel& cancel_func, const Params &params);
void estimate_supports_malformations(std::vector<SupportLayer*> &layers, float supports_flow_width, const Params &params);
void estimate_malformations(std::vector<Layer*> &layers, const Params &params);