Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/libslic3r/SLAPrintSteps.cpp')
-rw-r--r--src/libslic3r/SLAPrintSteps.cpp126
1 files changed, 50 insertions, 76 deletions
diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp
index 01220a633..d8bea62ae 100644
--- a/src/libslic3r/SLAPrintSteps.cpp
+++ b/src/libslic3r/SLAPrintSteps.cpp
@@ -1,3 +1,4 @@
+#include <libslic3r/Exception.hpp>
#include <libslic3r/SLAPrintSteps.hpp>
#include <libslic3r/MeshBoolean.hpp>
@@ -92,9 +93,10 @@ void SLAPrint::Steps::apply_printer_corrections(SLAPrintObject &po, SliceOrigin
coord_t clpr_offs = scaled(doffs);
faded_lyrs = std::min(po.m_slice_index.size(), faded_lyrs);
+ size_t faded_lyrs_efc = std::max(size_t(1), faded_lyrs - 1);
- auto efc = [start_efc, faded_lyrs](size_t pos) {
- return (faded_lyrs - 1 - pos) * start_efc / (faded_lyrs - 1);
+ auto efc = [start_efc, faded_lyrs_efc](size_t pos) {
+ return (faded_lyrs_efc - pos) * start_efc / faded_lyrs_efc;
};
std::vector<ExPolygons> &slices = o == soModel ?
@@ -187,7 +189,7 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po)
}
if (MeshBoolean::cgal::does_self_intersect(*holes_mesh_cgal))
- throw std::runtime_error(L("Too much overlapping holes."));
+ throw Slic3r::SlicingError(L("Too many overlapping holes."));
auto hollowed_mesh_cgal = MeshBoolean::cgal::triangle_mesh_to_cgal(hollowed_mesh);
@@ -195,7 +197,7 @@ void SLAPrint::Steps::drill_holes(SLAPrintObject &po)
MeshBoolean::cgal::minus(*hollowed_mesh_cgal, *holes_mesh_cgal);
hollowed_mesh = MeshBoolean::cgal::cgal_to_triangle_mesh(*hollowed_mesh_cgal);
} catch (const std::runtime_error &) {
- throw std::runtime_error(L(
+ throw Slic3r::SlicingError(L(
"Drilling holes into the mesh failed. "
"This is usually caused by broken model. Try to fix it first."));
}
@@ -241,7 +243,7 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
if(slindex_it == po.m_slice_index.end())
//TRN To be shown at the status bar on SLA slicing error.
- throw std::runtime_error(
+ throw Slic3r::RuntimeError(
L("Slicing had to be stopped due to an internal error: "
"Inconsistent slice index."));
@@ -264,11 +266,12 @@ void SLAPrint::Steps::slice_model(SLAPrintObject &po)
std::vector<ExPolygons> interior_slices;
interior_slicer.slice(slice_grid, SlicingMode::Regular, closing_r, &interior_slices, thr);
- sla::ccr::enumerate(interior_slices.begin(), interior_slices.end(),
- [&po](const ExPolygons &slice, size_t i) {
- po.m_model_slices[i] =
- diff_ex(po.m_model_slices[i], slice);
- });
+ sla::ccr::for_each(size_t(0), interior_slices.size(),
+ [&po, &interior_slices] (size_t i) {
+ const ExPolygons &slice = interior_slices[i];
+ po.m_model_slices[i] =
+ diff_ex(po.m_model_slices[i], slice);
+ });
}
auto mit = slindex_it;
@@ -360,18 +363,6 @@ void SLAPrint::Steps::support_points(SLAPrintObject &po)
// removed them on purpose. No calculation will be done.
po.m_supportdata->pts = po.transformed_support_points();
}
-
- // If the zero elevation mode is engaged, we have to filter out all the
- // points that are on the bottom of the object
- if (is_zero_elevation(po.config())) {
- double tolerance = po.config().pad_enable.getBool() ?
- po.m_config.pad_wall_thickness.getFloat() :
- po.m_config.support_base_height.getFloat();
-
- remove_bottom_points(po.m_supportdata->pts,
- po.m_supportdata->emesh.ground_level(),
- tolerance);
- }
}
void SLAPrint::Steps::support_tree(SLAPrintObject &po)
@@ -382,6 +373,13 @@ void SLAPrint::Steps::support_tree(SLAPrintObject &po)
if (pcfg.embed_object)
po.m_supportdata->emesh.ground_level_offset(pcfg.wall_thickness_mm);
+
+ // If the zero elevation mode is engaged, we have to filter out all the
+ // points that are on the bottom of the object
+ if (is_zero_elevation(po.config())) {
+ remove_bottom_points(po.m_supportdata->pts,
+ float(po.m_supportdata->emesh.ground_level() + EPSILON));
+ }
po.m_supportdata->cfg = make_support_cfg(po.m_config);
// po.m_supportdata->emesh.load_holes(po.transformed_drainhole_points());
@@ -449,7 +447,7 @@ void SLAPrint::Steps::generate_pad(SLAPrintObject &po) {
auto &pad_mesh = po.m_supportdata->support_tree_ptr->retrieve_mesh(sla::MeshType::Pad);
if (!validate_pad(pad_mesh, pcfg))
- throw std::runtime_error(
+ throw Slic3r::SlicingError(
L("No pad can be generated for this model with the "
"current configuration"));
@@ -617,7 +615,7 @@ void SLAPrint::Steps::initialize_printer_input()
for(const SliceRecord& slicerecord : o->get_slice_index()) {
if (!slicerecord.is_valid())
- throw std::runtime_error(
+ throw Slic3r::SlicingError(
L("There are unprintable objects. Try to "
"adjust support settings to make the "
"objects printable."));
@@ -673,6 +671,8 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() {
double models_volume(0.0);
double estim_time(0.0);
+ std::vector<double> layers_times;
+ layers_times.reserve(printer_input.size());
size_t slow_layers = 0;
size_t fast_layers = 0;
@@ -684,14 +684,16 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() {
using Lock = std::lock_guard<sla::ccr::SpinningMutex>;
// Going to parallel:
- auto printlayerfn = [
+ auto printlayerfn = [this,
// functions and read only vars
areafn, area_fill, display_area, exp_time, init_exp_time, fast_tilt, slow_tilt, delta_fade_time,
// write vars
&mutex, &models_volume, &supports_volume, &estim_time, &slow_layers,
- &fast_layers, &fade_layer_time](PrintLayer& layer, size_t sliced_layer_cnt)
+ &fast_layers, &fade_layer_time, &layers_times](size_t sliced_layer_cnt)
{
+ PrintLayer &layer = m_print->m_printer_input[sliced_layer_cnt];
+
// vector of slice record references
auto& slicerecord_references = layer.slices();
@@ -775,26 +777,27 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() {
else
slow_layers++;
-
// Calculation of the printing time
-
+
+ double layer_times = 0.0;
if (sliced_layer_cnt < 3)
- estim_time += init_exp_time;
- else if (fade_layer_time > exp_time)
- {
+ layer_times += init_exp_time;
+ else if (fade_layer_time > exp_time) {
fade_layer_time -= delta_fade_time;
- estim_time += fade_layer_time;
+ layer_times += fade_layer_time;
}
else
- estim_time += exp_time;
-
- estim_time += tilt_time;
+ layer_times += exp_time;
+ layer_times += tilt_time;
+
+ layers_times.push_back(layer_times);
+ estim_time += layer_times;
}
};
// sequential version for debugging:
// for(size_t i = 0; i < m_printer_input.size(); ++i) printlayerfn(i);
- sla::ccr::enumerate(printer_input.begin(), printer_input.end(), printlayerfn);
+ sla::ccr::for_each(size_t(0), printer_input.size(), printlayerfn);
auto SCALING2 = SCALING_FACTOR * SCALING_FACTOR;
print_statistics.support_used_material = supports_volume * SCALING2;
@@ -804,8 +807,10 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() {
// A layers count o the highest object
if (printer_input.size() == 0)
print_statistics.estimated_print_time = std::nan("");
- else
+ else {
print_statistics.estimated_print_time = estim_time;
+ print_statistics.layers_times = layers_times;
+ }
print_statistics.fast_layers_count = fast_layers;
print_statistics.slow_layers_count = slow_layers;
@@ -816,16 +821,7 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() {
// Rasterizing the model objects, and their supports
void SLAPrint::Steps::rasterize()
{
- if(canceled()) return;
-
- auto &print_statistics = m_print->m_print_statistics;
- auto &printer_input = m_print->m_printer_input;
-
- // Set up the printer, allocate space for all the layers
- sla::RasterWriter &printer = m_print->init_printer();
-
- auto lvlcnt = unsigned(printer_input.size());
- printer.layers(lvlcnt);
+ if(canceled() || !m_print->m_printer) return;
// coefficient to map the rasterization state (0-99) to the allocated
// portion (slot) of the process state
@@ -837,7 +833,7 @@ void SLAPrint::Steps::rasterize()
// pst: previous state
double pst = current_status();
- double increment = (slot * sd) / printer_input.size();
+ double increment = (slot * sd) / m_print->m_printer_input.size();
double dstatus = current_status();
sla::ccr::SpinningMutex slck;
@@ -845,20 +841,14 @@ void SLAPrint::Steps::rasterize()
// procedure to process one height level. This will run in parallel
auto lvlfn =
- [this, &slck, &printer, increment, &dstatus, &pst]
- (PrintLayer& printlayer, size_t idx)
+ [this, &slck, increment, &dstatus, &pst]
+ (sla::RasterBase& raster, size_t idx)
{
+ PrintLayer& printlayer = m_print->m_printer_input[idx];
if(canceled()) return;
- auto level_id = unsigned(idx);
-
- // Switch to the appropriate layer in the printer
- printer.begin_layer(level_id);
-
- for(const ClipperLib::Polygon& poly : printlayer.transformed_slices())
- printer.draw_polygon(poly, level_id);
- // Finish the layer for later saving it.
- printer.finish_layer(level_id);
+ for (const ClipperLib::Polygon& poly : printlayer.transformed_slices())
+ raster.draw(poly);
// Status indication guarded with the spinlock
{
@@ -875,24 +865,8 @@ void SLAPrint::Steps::rasterize()
// last minute escape
if(canceled()) return;
- // Sequential version (for testing)
- // for(unsigned l = 0; l < lvlcnt; ++l) lvlfn(l);
-
// Print all the layers in parallel
- sla::ccr::enumerate(printer_input.begin(), printer_input.end(), lvlfn);
-
- // Set statistics values to the printer
- sla::RasterWriter::PrintStatistics stats;
- stats.used_material = (print_statistics.objects_used_material +
- print_statistics.support_used_material) / 1000;
-
- int num_fade = m_print->m_default_object_config.faded_layers.getInt();
- stats.num_fade = num_fade >= 0 ? size_t(num_fade) : size_t(0);
- stats.num_fast = print_statistics.fast_layers_count;
- stats.num_slow = print_statistics.slow_layers_count;
- stats.estimated_print_time_s = print_statistics.estimated_print_time;
-
- printer.set_statistics(stats);
+ m_print->m_printer->draw_layers(m_print->m_printer_input.size(), lvlfn);
}
std::string SLAPrint::Steps::label(SLAPrintObjectStep step)