Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_sinking_objects_collision

This commit is contained in:
enricoturri1966 2021-10-05 09:51:04 +02:00
commit ddcbbee3b0
11 changed files with 68 additions and 61 deletions

View file

@ -65,7 +65,7 @@ void CSGDisplay::render_scene()
glFlush(); glFlush();
} }
void Scene::set_print(uqptr<SLAPrint> &&print) void Scene::set_print(std::unique_ptr<SLAPrint> &&print)
{ {
m_print = std::move(print); m_print = std::move(print);
@ -85,7 +85,7 @@ void CSGDisplay::SceneCache::clear()
primitives.clear(); primitives.clear();
} }
shptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh) std::shared_ptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh)
{ {
auto p = std::make_shared<Primitive>(); auto p = std::make_shared<Primitive>();
p->load_mesh(mesh); p->load_mesh(mesh);
@ -94,7 +94,7 @@ shptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh)
return p; return p;
} }
shptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh, std::shared_ptr<Primitive> CSGDisplay::SceneCache::add_mesh(const TriangleMesh &mesh,
OpenCSG::Operation o, OpenCSG::Operation o,
unsigned c) unsigned c)
{ {

View file

@ -17,11 +17,6 @@ class SLAPrint;
namespace GL { namespace GL {
// Simple shorthands for smart pointers
template<class T> using shptr = std::shared_ptr<T>;
template<class T> using uqptr = std::unique_ptr<T>;
template<class T> using wkptr = std::weak_ptr<T>;
template<class T, class A = std::allocator<T>> using vector = std::vector<T, A>; template<class T, class A = std::allocator<T>> using vector = std::vector<T, A>;
// remove empty weak pointers from a vector // remove empty weak pointers from a vector
@ -61,7 +56,7 @@ public:
}; };
private: private:
vector<wkptr<Listener>> m_listeners; vector<std::weak_ptr<Listener>> m_listeners;
public: public:
virtual ~MouseInput() = default; virtual ~MouseInput() = default;
@ -95,7 +90,7 @@ public:
call(&Listener::on_moved_to, m_listeners, x, y); call(&Listener::on_moved_to, m_listeners, x, y);
} }
void add_listener(shptr<Listener> listener) void add_listener(std::shared_ptr<Listener> listener)
{ {
m_listeners.emplace_back(listener); m_listeners.emplace_back(listener);
cleanup(m_listeners); cleanup(m_listeners);
@ -322,7 +317,7 @@ public:
// The scene is a wrapper around SLAPrint which holds the data to be visualized. // The scene is a wrapper around SLAPrint which holds the data to be visualized.
class Scene class Scene
{ {
uqptr<SLAPrint> m_print; std::unique_ptr<SLAPrint> m_print;
public: public:
// Subscribers will be notified if the model is changed. This might be a // Subscribers will be notified if the model is changed. This might be a
@ -340,19 +335,19 @@ public:
Scene(); Scene();
~Scene(); ~Scene();
void set_print(uqptr<SLAPrint> &&print); void set_print(std::unique_ptr<SLAPrint> &&print);
const SLAPrint * get_print() const { return m_print.get(); } const SLAPrint * get_print() const { return m_print.get(); }
BoundingBoxf3 get_bounding_box() const; BoundingBoxf3 get_bounding_box() const;
void add_listener(shptr<Listener> listener) void add_listener(std::shared_ptr<Listener> listener)
{ {
m_listeners.emplace_back(listener); m_listeners.emplace_back(listener);
cleanup(m_listeners); cleanup(m_listeners);
} }
private: private:
vector<wkptr<Listener>> m_listeners; vector<std::weak_ptr<Listener>> m_listeners;
}; };
// The basic Display. This is almost just an interface but will do all the // The basic Display. This is almost just an interface but will do all the
@ -366,20 +361,20 @@ protected:
Vec2i m_size; Vec2i m_size;
bool m_initialized = false; bool m_initialized = false;
shptr<Camera> m_camera; std::shared_ptr<Camera> m_camera;
FpsCounter m_fps_counter; FpsCounter m_fps_counter;
public: public:
explicit Display(shptr<Camera> camera = nullptr) explicit Display(std::shared_ptr<Camera> camera = nullptr)
: m_camera(camera ? camera : std::make_shared<PerspectiveCamera>()) : m_camera(camera ? camera : std::make_shared<PerspectiveCamera>())
{} {}
~Display() override; ~Display() override;
shptr<const Camera> get_camera() const { return m_camera; } std::shared_ptr<const Camera> get_camera() const { return m_camera; }
shptr<Camera> get_camera() { return m_camera; } std::shared_ptr<Camera> get_camera() { return m_camera; }
void set_camera(shptr<Camera> cam) { m_camera = cam; } void set_camera(std::shared_ptr<Camera> cam) { m_camera = cam; }
virtual void swap_buffers() = 0; virtual void swap_buffers() = 0;
virtual void set_active(long width, long height); virtual void set_active(long width, long height);
@ -410,14 +405,14 @@ protected:
// Cache the renderable primitives. These will be fetched when the scene // Cache the renderable primitives. These will be fetched when the scene
// is modified. // is modified.
struct SceneCache { struct SceneCache {
vector<shptr<Primitive>> primitives; vector<std::shared_ptr<Primitive>> primitives;
vector<Primitive *> primitives_free; vector<Primitive *> primitives_free;
vector<OpenCSG::Primitive *> primitives_csg; vector<OpenCSG::Primitive *> primitives_csg;
void clear(); void clear();
shptr<Primitive> add_mesh(const TriangleMesh &mesh); std::shared_ptr<Primitive> add_mesh(const TriangleMesh &mesh);
shptr<Primitive> add_mesh(const TriangleMesh &mesh, std::shared_ptr<Primitive> add_mesh(const TriangleMesh &mesh,
OpenCSG::Operation op, OpenCSG::Operation op,
unsigned covexity); unsigned covexity);
} m_scene_cache; } m_scene_cache;
@ -446,13 +441,13 @@ class Controller : public std::enable_shared_from_this<Controller>,
Vec2i m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev; Vec2i m_mouse_pos, m_mouse_pos_rprev, m_mouse_pos_lprev;
bool m_left_btn = false, m_right_btn = false; bool m_left_btn = false, m_right_btn = false;
shptr<Scene> m_scene; std::shared_ptr<Scene> m_scene;
vector<wkptr<Display>> m_displays; vector<std::weak_ptr<Display>> m_displays;
// Call a method of Camera on all the cameras of the attached displays // Call a method of Camera on all the cameras of the attached displays
template<class F, class...Args> template<class F, class...Args>
void call_cameras(F &&f, Args&&... args) { void call_cameras(F &&f, Args&&... args) {
for (wkptr<Display> &l : m_displays) for (std::weak_ptr<Display> &l : m_displays)
if (auto disp = l.lock()) if (auto cam = disp->get_camera()) if (auto disp = l.lock()) if (auto cam = disp->get_camera())
(cam.get()->*f)(std::forward<Args>(args)...); (cam.get()->*f)(std::forward<Args>(args)...);
} }
@ -460,7 +455,7 @@ class Controller : public std::enable_shared_from_this<Controller>,
public: public:
// Set the scene that will be controlled. // Set the scene that will be controlled.
void set_scene(shptr<Scene> scene) void set_scene(std::shared_ptr<Scene> scene)
{ {
m_scene = scene; m_scene = scene;
m_scene->add_listener(shared_from_this()); m_scene->add_listener(shared_from_this());
@ -468,7 +463,7 @@ public:
const Scene * get_scene() const { return m_scene.get(); } const Scene * get_scene() const { return m_scene.get(); }
void add_display(shptr<Display> disp) void add_display(std::shared_ptr<Display> disp)
{ {
m_displays.emplace_back(disp); m_displays.emplace_back(disp);
cleanup(m_displays); cleanup(m_displays);

View file

@ -12,7 +12,7 @@ class CSGVolume: public Volume
class ShaderCSGDisplay: public Display { class ShaderCSGDisplay: public Display {
protected: protected:
vector<shptr<CSGVolume>> m_volumes; vector<std::shared_ptr<CSGVolume>> m_volumes;
void add_mesh(const TriangleMesh &mesh); void add_mesh(const TriangleMesh &mesh);
public: public:

View file

@ -34,7 +34,7 @@ using namespace Slic3r::GL;
class Renderer { class Renderer {
protected: protected:
wxGLCanvas *m_canvas; wxGLCanvas *m_canvas;
shptr<wxGLContext> m_context; std::shared_ptr<wxGLContext> m_context;
public: public:
Renderer(wxGLCanvas *c): m_canvas{c} { Renderer(wxGLCanvas *c): m_canvas{c} {
@ -86,16 +86,16 @@ public:
class Canvas: public wxGLCanvas class Canvas: public wxGLCanvas
{ {
// One display is active at a time, the OCSGRenderer by default. // One display is active at a time, the OCSGRenderer by default.
shptr<Slic3r::GL::Display> m_display; std::shared_ptr<Slic3r::GL::Display> m_display;
public: public:
template<class...Args> template<class...Args>
Canvas(Args &&...args): wxGLCanvas(std::forward<Args>(args)...) {} Canvas(Args &&...args): wxGLCanvas(std::forward<Args>(args)...) {}
shptr<Slic3r::GL::Display> get_display() const { return m_display; } std::shared_ptr<Slic3r::GL::Display> get_display() const { return m_display; }
void set_display(shptr<Slic3r::GL::Display> d) { m_display = d; } void set_display(std::shared_ptr<Slic3r::GL::Display> d) { m_display = d; }
}; };
// Enumerate possible mouse events, we will record them. // Enumerate possible mouse events, we will record them.
@ -197,14 +197,14 @@ public:
class MyFrame: public wxFrame class MyFrame: public wxFrame
{ {
// Instantiate the 3D engine. // Instantiate the 3D engine.
shptr<Scene> m_scene; // Model std::shared_ptr<Scene> m_scene; // Model
shptr<Canvas> m_canvas; // Views store std::shared_ptr<Canvas> m_canvas; // Views store
shptr<OCSGRenderer> m_ocsgdisplay; // View std::shared_ptr<OCSGRenderer> m_ocsgdisplay; // View
shptr<ShaderCSGRenderer> m_shadercsg_display; // Another view std::shared_ptr<ShaderCSGRenderer> m_shadercsg_display; // Another view
shptr<Controller> m_ctl; // Controller std::shared_ptr<Controller> m_ctl; // Controller
// Add a status bar with progress indication. // Add a status bar with progress indication.
shptr<Slic3r::GUI::ProgressStatusBar> m_stbar; std::shared_ptr<Slic3r::GUI::ProgressStatusBar> m_stbar;
RecorderMouseInput m_mouse; RecorderMouseInput m_mouse;
@ -237,7 +237,7 @@ class MyFrame: public wxFrame
} }
}; };
uqptr<SLAJob> m_ui_job; std::unique_ptr<SLAJob> m_ui_job;
// To keep track of the running average of measured fps values. // To keep track of the running average of measured fps values.
double m_fps_avg = 0.; double m_fps_avg = 0.;

View file

@ -423,7 +423,7 @@ void fill_slicerconf(ConfMap &m, const SLAPrint &print)
} // namespace } // namespace
uqptr<sla::RasterBase> SL1Archive::create_raster() const std::unique_ptr<sla::RasterBase> SL1Archive::create_raster() const
{ {
sla::RasterBase::Resolution res; sla::RasterBase::Resolution res;
sla::RasterBase::PixelDim pxdim; sla::RasterBase::PixelDim pxdim;

View file

@ -12,7 +12,7 @@ class SL1Archive: public SLAArchive {
SLAPrinterConfig m_cfg; SLAPrinterConfig m_cfg;
protected: protected:
uqptr<sla::RasterBase> create_raster() const override; std::unique_ptr<sla::RasterBase> create_raster() const override;
sla::RasterEncoder get_encoder() const override; sla::RasterEncoder get_encoder() const override;
public: public:

View file

@ -13,10 +13,6 @@
namespace Slic3r { namespace Slic3r {
template<class T> using uqptr = std::unique_ptr<T>;
template<class T> using shptr = std::shared_ptr<T>;
template<class T> using wkptr = std::weak_ptr<T>;
namespace sla { namespace sla {
// Raw byte buffer paired with its size. Suitable for compressed image data. // Raw byte buffer paired with its size. Suitable for compressed image data.
@ -112,7 +108,7 @@ struct PPMRasterEncoder {
std::ostream& operator<<(std::ostream &stream, const EncodedRaster &bytes); std::ostream& operator<<(std::ostream &stream, const EncodedRaster &bytes);
// If gamma is zero, thresholding will be performed which disables AA. // If gamma is zero, thresholding will be performed which disables AA.
uqptr<RasterBase> create_raster_grayscale_aa( std::unique_ptr<RasterBase> create_raster_grayscale_aa(
const RasterBase::Resolution &res, const RasterBase::Resolution &res,
const RasterBase::PixelDim & pxdim, const RasterBase::PixelDim & pxdim,
double gamma = 1.0, double gamma = 1.0,

View file

@ -391,7 +391,7 @@ class SLAArchive {
protected: protected:
std::vector<sla::EncodedRaster> m_layers; std::vector<sla::EncodedRaster> m_layers;
virtual uqptr<sla::RasterBase> create_raster() const = 0; virtual std::unique_ptr<sla::RasterBase> create_raster() const = 0;
virtual sla::RasterEncoder get_encoder() const = 0; virtual sla::RasterEncoder get_encoder() const = 0;
public: public:

View file

@ -2055,21 +2055,21 @@ static inline PrintObjectSupportMaterial::MyLayer* detect_bottom_contacts(
// Trim the already created base layers above the current layer intersecting with the new bottom contacts layer. // Trim the already created base layers above the current layer intersecting with the new bottom contacts layer.
//FIXME Maybe this is no more needed, as the overlapping base layers are trimmed by the bottom layers at the final stage? //FIXME Maybe this is no more needed, as the overlapping base layers are trimmed by the bottom layers at the final stage?
touching = offset(touching, float(SCALED_EPSILON)); touching = offset(touching, float(SCALED_EPSILON));
for (int layer_id_above = layer_id + 1; layer_id_above < int(object.total_layer_count()); ++layer_id_above) { for (int layer_id_above = layer_id + 1; layer_id_above < int(object.total_layer_count()); ++ layer_id_above) {
const Layer &layer_above = *object.layers()[layer_id_above]; const Layer &layer_above = *object.layers()[layer_id_above];
if (layer_above.print_z > layer_new.print_z - EPSILON) if (layer_above.print_z > layer_new.print_z - EPSILON)
break; break;
if (! layer_support_areas[layer_id_above].empty()) { if (Polygons &above = layer_support_areas[layer_id_above]; ! above.empty()) {
#ifdef SLIC3R_DEBUG #ifdef SLIC3R_DEBUG
SVG::export_expolygons(debug_out_path("support-support-areas-raw-before-trimming-%d-with-%f-%lf.svg", iRun, layer.print_z, layer_above.print_z), SVG::export_expolygons(debug_out_path("support-support-areas-raw-before-trimming-%d-with-%f-%lf.svg", iRun, layer.print_z, layer_above.print_z),
{ { { union_ex(touching) }, { "touching", "blue", 0.5f } }, { { { union_ex(touching) }, { "touching", "blue", 0.5f } },
{ { union_safety_offset_ex(layer_support_areas[layer_id_above]) }, { "above", "red", "black", "", scaled<coord_t>(0.1f), 0.5f } } }); { { union_safety_offset_ex(above) }, { "above", "red", "black", "", scaled<coord_t>(0.1f), 0.5f } } });
#endif /* SLIC3R_DEBUG */ #endif /* SLIC3R_DEBUG */
layer_support_areas[layer_id_above] = diff(layer_support_areas[layer_id_above], touching); above = diff(above, touching);
#ifdef SLIC3R_DEBUG #ifdef SLIC3R_DEBUG
Slic3r::SVG::export_expolygons( Slic3r::SVG::export_expolygons(
debug_out_path("support-support-areas-raw-after-trimming-%d-with-%f-%lf.svg", iRun, layer.print_z, layer_above.print_z), debug_out_path("support-support-areas-raw-after-trimming-%d-with-%f-%lf.svg", iRun, layer.print_z, layer_above.print_z),
union_ex(layer_support_areas[layer_id_above])); union_ex(above));
#endif /* SLIC3R_DEBUG */ #endif /* SLIC3R_DEBUG */
} }
} }
@ -2622,10 +2622,9 @@ void PrintObjectSupportMaterial::generate_base_layers(
// New polygons for layer_intermediate. // New polygons for layer_intermediate.
Polygons polygons_new; Polygons polygons_new;
// Use the precomputed layer_support_areas. // Use the precomputed layer_support_areas. "idx_object_layer_above": above means above since the last iteration, not above after this call.
idx_object_layer_above = std::max(0, idx_lower_or_equal(object.layers().begin(), object.layers().end(), idx_object_layer_above, idx_object_layer_above = idx_lower_or_equal(object.layers().begin(), object.layers().end(), idx_object_layer_above,
[&layer_intermediate](const Layer *layer){ return layer->print_z <= layer_intermediate.print_z + EPSILON; })); [&layer_intermediate](const Layer* layer) { return layer->print_z <= layer_intermediate.print_z + EPSILON; });
polygons_new = layer_support_areas[idx_object_layer_above];
// Polygons to trim polygons_new. // Polygons to trim polygons_new.
Polygons polygons_trimming; Polygons polygons_trimming;
@ -2640,7 +2639,7 @@ void PrintObjectSupportMaterial::generate_base_layers(
idx_top_contact_above = idx_lower_or_equal(top_contacts, idx_top_contact_above, idx_top_contact_above = idx_lower_or_equal(top_contacts, idx_top_contact_above,
[&layer_intermediate](const MyLayer *layer){ return layer->bottom_z <= layer_intermediate.print_z - EPSILON; }); [&layer_intermediate](const MyLayer *layer){ return layer->bottom_z <= layer_intermediate.print_z - EPSILON; });
// Collect all the top_contact layer intersecting with this layer. // Collect all the top_contact layer intersecting with this layer.
for ( int idx_top_contact_overlapping = idx_top_contact_above; idx_top_contact_overlapping >= 0; -- idx_top_contact_overlapping) { for (int idx_top_contact_overlapping = idx_top_contact_above; idx_top_contact_overlapping >= 0; -- idx_top_contact_overlapping) {
MyLayer &layer_top_overlapping = *top_contacts[idx_top_contact_overlapping]; MyLayer &layer_top_overlapping = *top_contacts[idx_top_contact_overlapping];
if (layer_top_overlapping.print_z < layer_intermediate.bottom_z + EPSILON) if (layer_top_overlapping.print_z < layer_intermediate.bottom_z + EPSILON)
break; break;
@ -2651,6 +2650,22 @@ void PrintObjectSupportMaterial::generate_base_layers(
polygons_append(polygons_trimming, layer_top_overlapping.polygons); polygons_append(polygons_trimming, layer_top_overlapping.polygons);
} }
if (idx_object_layer_above < 0) {
// layer_support_areas are synchronized with object layers and they contain projections of the contact layers above them.
// This intermediate layer is not above any object layer, thus there is no information in layer_support_areas about
// towers supporting contact layers intersecting the first object layer. Project these contact layers now.
polygons_new = layer_support_areas.front();
double first_layer_z = object.layers().front()->print_z;
for (int i = idx_top_contact_above + 1; i < int(top_contacts.size()); ++ i) {
MyLayer &contacts = *top_contacts[i];
if (contacts.print_z > first_layer_z + EPSILON)
break;
assert(contacts.bottom_z > layer_intermediate.print_z - EPSILON);
polygons_append(polygons_new, contacts.polygons);
}
} else
polygons_new = layer_support_areas[idx_object_layer_above];
// Trimming the base layer with any overlapping bottom layer. // Trimming the base layer with any overlapping bottom layer.
// Following cases are recognized: // Following cases are recognized:
// 1) bottom.bottom_z >= base.top_z -> No overlap, no trimming needed. // 1) bottom.bottom_z >= base.top_z -> No overlap, no trimming needed.

View file

@ -228,7 +228,7 @@ DPIFrame(NULL, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_S
return; return;
} }
// check unsaved changes only if project wasn't saved // check unsaved changes only if project wasn't saved
else if (saved_project == wxID_NO && event.CanVeto() && else if (plater()->is_project_dirty() && saved_project == wxID_NO && event.CanVeto() &&
!wxGetApp().check_and_save_current_preset_changes(_L("PrusaSlicer is closing"), _L("Closing PrusaSlicer while some presets are modified."))) { !wxGetApp().check_and_save_current_preset_changes(_L("PrusaSlicer is closing"), _L("Closing PrusaSlicer while some presets are modified."))) {
event.Veto(); event.Veto();
return; return;

View file

@ -2109,13 +2109,14 @@ void Plater::priv::update(unsigned int flags)
} }
unsigned int update_status = 0; unsigned int update_status = 0;
if (this->printer_technology == ptSLA || (flags & (unsigned int)UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE)) const bool force_background_processing_restart = this->printer_technology == ptSLA || (flags & (unsigned int)UpdateParams::FORCE_BACKGROUND_PROCESSING_UPDATE);
if (force_background_processing_restart)
// Update the SLAPrint from the current Model, so that the reload_scene() // Update the SLAPrint from the current Model, so that the reload_scene()
// pulls the correct data. // pulls the correct data.
update_status = this->update_background_process(false, flags & (unsigned int)UpdateParams::POSTPONE_VALIDATION_ERROR_MESSAGE); update_status = this->update_background_process(false, flags & (unsigned int)UpdateParams::POSTPONE_VALIDATION_ERROR_MESSAGE);
this->view3D->reload_scene(false, flags & (unsigned int)UpdateParams::FORCE_FULL_SCREEN_REFRESH); this->view3D->reload_scene(false, flags & (unsigned int)UpdateParams::FORCE_FULL_SCREEN_REFRESH);
this->preview->reload_print(); this->preview->reload_print();
if (this->printer_technology == ptSLA) if (force_background_processing_restart)
this->restart_background_process(update_status); this->restart_background_process(update_status);
else else
this->schedule_background_process(); this->schedule_background_process();