From 5997f2759cfb1d041c47ee4e03d6cc7c03a02ac7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Hejl?= <hejl.lukas@gmail.com> Date: Wed, 2 Sep 2020 22:53:10 +0200 Subject: [PATCH] Change in passing octree struct --- src/libslic3r/Fill/Fill.cpp | 4 ++-- src/libslic3r/Layer.hpp | 6 +++++- src/libslic3r/Print.hpp | 9 ++++----- src/libslic3r/PrintObject.cpp | 20 ++++++++++---------- 4 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/libslic3r/Fill/Fill.cpp b/src/libslic3r/Fill/Fill.cpp index c948df400..9d468a6aa 100644 --- a/src/libslic3r/Fill/Fill.cpp +++ b/src/libslic3r/Fill/Fill.cpp @@ -318,7 +318,7 @@ void export_group_fills_to_svg(const char *path, const std::vector<SurfaceFill> #endif // friend to Layer -void Layer::make_fills() +void Layer::make_fills(FillAdaptive_Internal::Octree* adaptive_fill_octree) { for (LayerRegion *layerm : m_regions) layerm->fills.clear(); @@ -345,7 +345,7 @@ void Layer::make_fills() f->layer_id = this->id(); f->z = this->print_z; f->angle = surface_fill.params.angle; - f->adapt_fill_octree = this->object()->adaptiveInfillOctree(); + f->adapt_fill_octree = adaptive_fill_octree; // calculate flow spacing for infill pattern generation bool using_internal_flow = ! surface_fill.surface.is_solid() && ! surface_fill.params.flow.bridge; diff --git a/src/libslic3r/Layer.hpp b/src/libslic3r/Layer.hpp index c104d46da..4c824a109 100644 --- a/src/libslic3r/Layer.hpp +++ b/src/libslic3r/Layer.hpp @@ -13,6 +13,10 @@ class Layer; class PrintRegion; class PrintObject; +namespace FillAdaptive_Internal { + struct Octree; +}; + class LayerRegion { public: @@ -134,7 +138,7 @@ public: return false; } void make_perimeters(); - void make_fills(); + void make_fills(FillAdaptive_Internal::Octree* adaptive_fill_octree); void make_ironing(); void export_region_slices_to_svg(const char *path) const; diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 2e2746a34..9b5d9d4c1 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -11,7 +11,6 @@ #include "GCode/ToolOrdering.hpp" #include "GCode/WipeTower.hpp" #include "GCode/ThumbnailData.hpp" -#include "Fill/FillAdaptive.hpp" #include "libslic3r.h" @@ -26,6 +25,9 @@ enum class SlicingMode : uint32_t; class Layer; class SupportLayer; +namespace FillAdaptive_Internal { + struct Octree; +}; // Print step IDs for keeping track of the print state. enum PrintStep { @@ -193,7 +195,6 @@ public: void project_and_append_custom_enforcers(std::vector<ExPolygons>& enforcers) const { project_and_append_custom_supports(FacetSupportType::ENFORCER, enforcers); } void project_and_append_custom_blockers(std::vector<ExPolygons>& blockers) const { project_and_append_custom_supports(FacetSupportType::BLOCKER, blockers); } - FillAdaptive_Internal::Octree* adaptiveInfillOctree() { return m_adapt_fill_octree.get(); } private: // to be called from Print only. friend class Print; @@ -235,7 +236,7 @@ private: void discover_horizontal_shells(); void combine_infill(); void _generate_support_material(); - void prepare_adaptive_infill_data(); + std::unique_ptr<FillAdaptive_Internal::Octree> prepare_adaptive_infill_data(); // XYZ in scaled coordinates Vec3crd m_size; @@ -256,8 +257,6 @@ private: // so that next call to make_perimeters() performs a union() before computing loops bool m_typed_slices = false; - std::unique_ptr<FillAdaptive_Internal::Octree> m_adapt_fill_octree = nullptr; - std::vector<ExPolygons> slice_region(size_t region_id, const std::vector<float> &z, SlicingMode mode) const; std::vector<ExPolygons> slice_modifiers(size_t region_id, const std::vector<float> &z) const; std::vector<ExPolygons> slice_volumes(const std::vector<float> &z, SlicingMode mode, const std::vector<const ModelVolume*> &volumes) const; diff --git a/src/libslic3r/PrintObject.cpp b/src/libslic3r/PrintObject.cpp index 1ab5664a0..25b20ea9a 100644 --- a/src/libslic3r/PrintObject.cpp +++ b/src/libslic3r/PrintObject.cpp @@ -362,8 +362,6 @@ void PrintObject::prepare_infill() } // for each layer #endif /* SLIC3R_DEBUG_SLICE_PROCESSING */ - this->prepare_adaptive_infill_data(); - this->set_done(posPrepareInfill); } @@ -373,13 +371,15 @@ void PrintObject::infill() this->prepare_infill(); if (this->set_started(posInfill)) { + std::unique_ptr<FillAdaptive_Internal::Octree> octree = this->prepare_adaptive_infill_data(); + BOOST_LOG_TRIVIAL(debug) << "Filling layers in parallel - start"; tbb::parallel_for( tbb::blocked_range<size_t>(0, m_layers.size()), - [this](const tbb::blocked_range<size_t>& range) { + [this, &octree](const tbb::blocked_range<size_t>& range) { for (size_t layer_idx = range.begin(); layer_idx < range.end(); ++ layer_idx) { m_print->throw_if_canceled(); - m_layers[layer_idx]->make_fills(); + m_layers[layer_idx]->make_fills(octree.get()); } } ); @@ -432,14 +432,14 @@ void PrintObject::generate_support_material() } } -void PrintObject::prepare_adaptive_infill_data() +std::unique_ptr<FillAdaptive_Internal::Octree> PrintObject::prepare_adaptive_infill_data() { const ConfigOptionPercent* opt_fill_density = this->print()->full_print_config().option<ConfigOptionPercent>("fill_density"); const ConfigOptionFloatOrPercent* opt_infill_extrusion_width = this->print()->full_print_config().option<ConfigOptionFloatOrPercent>("infill_extrusion_width"); if(opt_fill_density == nullptr || opt_infill_extrusion_width == nullptr || opt_fill_density->value <= 0 || opt_infill_extrusion_width->value <= 0) { - return; + return std::unique_ptr<FillAdaptive_Internal::Octree>{}; } float fill_density = opt_fill_density->value; @@ -448,15 +448,15 @@ void PrintObject::prepare_adaptive_infill_data() coordf_t line_spacing = infill_extrusion_width / ((fill_density / 100.0f) * 0.333333333f); BoundingBoxf bed_shape(this->print()->config().bed_shape.values); - BoundingBoxf3 printer_volume(Vec3d(bed_shape.min(0), bed_shape.min(1), 0), - Vec3d(bed_shape.max(0), bed_shape.max(1), this->print()->config().max_print_height)); + BoundingBoxf3 printer_volume(Vec3d(bed_shape.min.x(), bed_shape.min.y(), 0), + Vec3d(bed_shape.max.x(), bed_shape.max.y(), this->print()->config().max_print_height)); Vec3d model_center = this->model_object()->bounding_box().center(); - model_center(2) = 0.0f; // Set position in Z axis to 0 + model_center.z() = 0.0f; // Set position in Z axis to 0 // Center of the first cube in octree TriangleMesh mesh = this->model_object()->mesh(); - this->m_adapt_fill_octree = FillAdaptive::build_octree(mesh, line_spacing, printer_volume, model_center); + return FillAdaptive::build_octree(mesh, line_spacing, printer_volume, model_center); } void PrintObject::clear_layers()