Implemented caching of SlicingParameters by PrintObject

This commit is contained in:
bubnikv 2019-03-04 15:28:04 +01:00
parent 2fe542e0fc
commit cc79b1553d
2 changed files with 15 additions and 9 deletions

View File

@ -93,7 +93,7 @@ public:
const LayerPtrs& layers() const { return m_layers; } const LayerPtrs& layers() const { return m_layers; }
const SupportLayerPtrs& support_layers() const { return m_support_layers; } const SupportLayerPtrs& support_layers() const { return m_support_layers; }
const Transform3d& trafo() const { return m_trafo; } const Transform3d& trafo() const { return m_trafo; }
const Points& copies() const { return m_copies; } const Points& copies() const { return m_copies; }
// since the object is aligned to origin, bounding box coincides with size // since the object is aligned to origin, bounding box coincides with size
BoundingBox bounding_box() const { return BoundingBox(Point(0,0), to_2d(this->size)); } BoundingBox bounding_box() const { return BoundingBox(Point(0,0), to_2d(this->size)); }
@ -161,6 +161,7 @@ protected:
bool invalidate_all_steps(); bool invalidate_all_steps();
// Invalidate steps based on a set of parameters changed. // Invalidate steps based on a set of parameters changed.
bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys); bool invalidate_state_by_config_options(const std::vector<t_config_option_key> &opt_keys);
SlicingParameters slicing_parameters_internal() const;
static PrintObjectConfig object_config_from_model_object(const PrintObjectConfig &default_object_config, const ModelObject &object, size_t num_extruders); static PrintObjectConfig object_config_from_model_object(const PrintObjectConfig &default_object_config, const ModelObject &object, size_t num_extruders);
static PrintRegionConfig region_config_from_model_volume(const PrintRegionConfig &default_region_config, const ModelVolume &volume, size_t num_extruders); static PrintRegionConfig region_config_from_model_volume(const PrintRegionConfig &default_region_config, const ModelVolume &volume, size_t num_extruders);
@ -195,6 +196,7 @@ private:
// for external callers) // for external callers)
Point m_copies_shift; Point m_copies_shift;
SlicingParameters m_slicing_params;
LayerPtrs m_layers; LayerPtrs m_layers;
SupportLayerPtrs m_support_layers; SupportLayerPtrs m_support_layers;

View File

@ -104,7 +104,8 @@ void PrintObject::slice()
return; return;
m_print->set_status(10, "Processing triangulated mesh"); m_print->set_status(10, "Processing triangulated mesh");
std::vector<coordf_t> layer_height_profile; std::vector<coordf_t> layer_height_profile;
this->update_layer_height_profile(*this->model_object(), this->slicing_parameters(), layer_height_profile); m_slicing_params = this->slicing_parameters_internal();
this->update_layer_height_profile(*this->model_object(), m_slicing_params, layer_height_profile);
m_print->throw_if_canceled(); m_print->throw_if_canceled();
this->_slice(layer_height_profile); this->_slice(layer_height_profile);
m_print->throw_if_canceled(); m_print->throw_if_canceled();
@ -1360,13 +1361,18 @@ PrintRegionConfig PrintObject::region_config_from_model_volume(const PrintRegion
return config; return config;
} }
SlicingParameters PrintObject::slicing_parameters() const SlicingParameters PrintObject::slicing_parameters_internal() const
{ {
return SlicingParameters::create_from_config( return SlicingParameters::create_from_config(
this->print()->config(), m_config, this->print()->config(), m_config,
unscale<double>(this->size(2)), this->object_extruders()); unscale<double>(this->size(2)), this->object_extruders());
} }
SlicingParameters PrintObject::slicing_parameters() const
{
return this->is_step_done(posSlice) ? m_slicing_params : this->slicing_parameters_internal();
}
SlicingParameters PrintObject::slicing_parameters(const DynamicPrintConfig &full_config, const ModelObject &model_object) SlicingParameters PrintObject::slicing_parameters(const DynamicPrintConfig &full_config, const ModelObject &model_object)
{ {
PrintConfig print_config; PrintConfig print_config;
@ -1451,23 +1457,21 @@ void PrintObject::_slice(const std::vector<coordf_t> &layer_height_profile)
tbb_init = new tbb::task_scheduler_init(1); tbb_init = new tbb::task_scheduler_init(1);
#endif #endif
SlicingParameters slicing_params = this->slicing_parameters();
// 1) Initialize layers and their slice heights. // 1) Initialize layers and their slice heights.
std::vector<float> slice_zs; std::vector<float> slice_zs;
{ {
this->clear_layers(); this->clear_layers();
// Object layers (pairs of bottom/top Z coordinate), without the raft. // Object layers (pairs of bottom/top Z coordinate), without the raft.
std::vector<coordf_t> object_layers = generate_object_layers(slicing_params, layer_height_profile); std::vector<coordf_t> object_layers = generate_object_layers(m_slicing_params, layer_height_profile);
// Reserve object layers for the raft. Last layer of the raft is the contact layer. // Reserve object layers for the raft. Last layer of the raft is the contact layer.
int id = int(slicing_params.raft_layers()); int id = int(m_slicing_params.raft_layers());
slice_zs.reserve(object_layers.size()); slice_zs.reserve(object_layers.size());
Layer *prev = nullptr; Layer *prev = nullptr;
for (size_t i_layer = 0; i_layer < object_layers.size(); i_layer += 2) { for (size_t i_layer = 0; i_layer < object_layers.size(); i_layer += 2) {
coordf_t lo = object_layers[i_layer]; coordf_t lo = object_layers[i_layer];
coordf_t hi = object_layers[i_layer + 1]; coordf_t hi = object_layers[i_layer + 1];
coordf_t slice_z = 0.5 * (lo + hi); coordf_t slice_z = 0.5 * (lo + hi);
Layer *layer = this->add_layer(id ++, hi - lo, hi + slicing_params.object_print_z_min, slice_z); Layer *layer = this->add_layer(id ++, hi - lo, hi + m_slicing_params.object_print_z_min, slice_z);
slice_zs.push_back(float(slice_z)); slice_zs.push_back(float(slice_z));
if (prev != nullptr) { if (prev != nullptr) {
prev->upper_layer = layer; prev->upper_layer = layer;
@ -2246,7 +2250,7 @@ void PrintObject::combine_infill()
void PrintObject::_generate_support_material() void PrintObject::_generate_support_material()
{ {
PrintObjectSupportMaterial support_material(this, PrintObject::slicing_parameters()); PrintObjectSupportMaterial support_material(this, m_slicing_params);
support_material.generate(*this); support_material.generate(*this);
} }