2016-12-08 18:02:16 +00:00
|
|
|
// Based on implementation by @platsch
|
|
|
|
|
|
|
|
#ifndef slic3r_Slicing_hpp_
|
|
|
|
#define slic3r_Slicing_hpp_
|
|
|
|
|
2019-01-21 16:51:37 +00:00
|
|
|
#include <cstring>
|
|
|
|
#include <map>
|
2016-12-12 16:53:38 +00:00
|
|
|
#include <set>
|
2019-01-21 16:51:37 +00:00
|
|
|
#include <type_traits>
|
2016-12-12 16:53:38 +00:00
|
|
|
#include <vector>
|
2016-12-08 18:02:16 +00:00
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
#include "libslic3r.h"
|
2019-01-22 10:12:50 +00:00
|
|
|
#include "Utils.hpp"
|
2019-06-03 13:35:21 +00:00
|
|
|
#include "PrintConfig.hpp"
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
namespace Slic3r
|
|
|
|
{
|
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
class PrintConfig;
|
|
|
|
class PrintObjectConfig;
|
2019-11-13 12:53:02 +00:00
|
|
|
class ModelObject;
|
2016-12-12 16:53:38 +00:00
|
|
|
|
|
|
|
// Parameters to guide object slicing and support generation.
|
|
|
|
// The slicing parameters account for a raft and whether the 1st object layer is printed with a normal or a bridging flow
|
|
|
|
// (using a normal flow over a soluble support, using a bridging flow over a non-soluble support).
|
2016-12-08 18:02:16 +00:00
|
|
|
struct SlicingParameters
|
|
|
|
{
|
|
|
|
SlicingParameters() { memset(this, 0, sizeof(SlicingParameters)); }
|
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
static SlicingParameters create_from_config(
|
|
|
|
const PrintConfig &print_config,
|
|
|
|
const PrintObjectConfig &object_config,
|
|
|
|
coordf_t object_height,
|
2017-05-03 16:28:22 +00:00
|
|
|
const std::vector<unsigned int> &object_extruders);
|
2016-12-12 16:53:38 +00:00
|
|
|
|
|
|
|
// Has any raft layers?
|
|
|
|
bool has_raft() const { return raft_layers() > 0; }
|
|
|
|
size_t raft_layers() const { return base_raft_layers + interface_raft_layers; }
|
|
|
|
|
|
|
|
// Is the 1st object layer height fixed, or could it be varied?
|
|
|
|
bool first_object_layer_height_fixed() const { return ! has_raft() || first_object_layer_bridging; }
|
|
|
|
|
|
|
|
// Height of the object to be printed. This value does not contain the raft height.
|
|
|
|
coordf_t object_print_z_height() const { return object_print_z_max - object_print_z_min; }
|
|
|
|
|
2019-03-05 13:05:58 +00:00
|
|
|
bool valid;
|
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
// Number of raft layers.
|
|
|
|
size_t base_raft_layers;
|
|
|
|
// Number of interface layers including the contact layer.
|
|
|
|
size_t interface_raft_layers;
|
|
|
|
|
|
|
|
// Layer heights of the raft (base, interface and a contact layer).
|
|
|
|
coordf_t base_raft_layer_height;
|
|
|
|
coordf_t interface_raft_layer_height;
|
|
|
|
coordf_t contact_raft_layer_height;
|
|
|
|
bool contact_raft_layer_height_bridging;
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
// The regular layer height, applied for all but the first layer, if not overridden by layer ranges
|
|
|
|
// or by the variable layer thickness table.
|
|
|
|
coordf_t layer_height;
|
2017-02-09 13:56:13 +00:00
|
|
|
// Minimum / maximum layer height, to be used for the automatic adaptive layer height algorithm,
|
|
|
|
// or by an interactive layer height editor.
|
|
|
|
coordf_t min_layer_height;
|
|
|
|
coordf_t max_layer_height;
|
|
|
|
coordf_t max_suport_layer_height;
|
2016-12-08 18:02:16 +00:00
|
|
|
|
2016-12-20 11:19:13 +00:00
|
|
|
// First layer height of the print, this may be used for the first layer of the raft
|
|
|
|
// or for the first layer of the print.
|
|
|
|
coordf_t first_print_layer_height;
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
// Thickness of the first layer. This is either the first print layer thickness if printed without a raft,
|
|
|
|
// or a bridging flow thickness if printed over a non-soluble raft,
|
|
|
|
// or a normal layer height if printed over a soluble raft.
|
2016-12-12 16:53:38 +00:00
|
|
|
coordf_t first_object_layer_height;
|
2016-12-08 18:02:16 +00:00
|
|
|
|
|
|
|
// If the object is printed over a non-soluble raft, the first layer may be printed with a briding flow.
|
2016-12-12 16:53:38 +00:00
|
|
|
bool first_object_layer_bridging;
|
2016-12-08 18:02:16 +00:00
|
|
|
|
2016-12-20 11:19:13 +00:00
|
|
|
// Soluble interface? (PLA soluble in water, HIPS soluble in lemonen)
|
|
|
|
// otherwise the interface must be broken off.
|
|
|
|
bool soluble_interface;
|
|
|
|
// Gap when placing object over raft.
|
|
|
|
coordf_t gap_raft_object;
|
|
|
|
// Gap when placing support over object.
|
|
|
|
coordf_t gap_object_support;
|
|
|
|
// Gap when placing object over support.
|
|
|
|
coordf_t gap_support_object;
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
// Bottom and top of the printed object.
|
|
|
|
// If printed without a raft, object_print_z_min = 0 and object_print_z_max = object height.
|
|
|
|
// Otherwise object_print_z_min is equal to the raft height.
|
2016-12-20 11:19:13 +00:00
|
|
|
coordf_t raft_base_top_z;
|
|
|
|
coordf_t raft_interface_top_z;
|
|
|
|
coordf_t raft_contact_top_z;
|
|
|
|
// In case of a soluble interface, object_print_z_min == raft_contact_top_z, otherwise there is a gap between the raft and the 1st object layer.
|
2016-12-08 18:02:16 +00:00
|
|
|
coordf_t object_print_z_min;
|
|
|
|
coordf_t object_print_z_max;
|
|
|
|
};
|
2019-01-22 10:12:50 +00:00
|
|
|
static_assert(IsTriviallyCopyable<SlicingParameters>::value, "SlicingParameters class is not POD (and it should be - see constructor).");
|
2019-01-21 14:03:20 +00:00
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
|
2017-06-08 14:58:29 +00:00
|
|
|
// The two slicing parameters lead to the same layering as long as the variable layer thickness is not in action.
|
|
|
|
inline bool equal_layering(const SlicingParameters &sp1, const SlicingParameters &sp2)
|
|
|
|
{
|
2019-03-05 13:05:58 +00:00
|
|
|
assert(sp1.valid);
|
|
|
|
assert(sp2.valid);
|
2017-06-08 14:58:29 +00:00
|
|
|
return sp1.base_raft_layers == sp2.base_raft_layers &&
|
|
|
|
sp1.interface_raft_layers == sp2.interface_raft_layers &&
|
|
|
|
sp1.base_raft_layer_height == sp2.base_raft_layer_height &&
|
|
|
|
sp1.interface_raft_layer_height == sp2.interface_raft_layer_height &&
|
|
|
|
sp1.contact_raft_layer_height == sp2.contact_raft_layer_height &&
|
|
|
|
sp1.contact_raft_layer_height_bridging == sp2.contact_raft_layer_height_bridging &&
|
|
|
|
sp1.layer_height == sp2.layer_height &&
|
|
|
|
sp1.min_layer_height == sp2.min_layer_height &&
|
|
|
|
sp1.max_layer_height == sp2.max_layer_height &&
|
2017-12-01 17:55:57 +00:00
|
|
|
// sp1.max_suport_layer_height == sp2.max_suport_layer_height &&
|
2017-06-08 14:58:29 +00:00
|
|
|
sp1.first_print_layer_height == sp2.first_print_layer_height &&
|
|
|
|
sp1.first_object_layer_height == sp2.first_object_layer_height &&
|
|
|
|
sp1.first_object_layer_bridging == sp2.first_object_layer_bridging &&
|
|
|
|
sp1.soluble_interface == sp2.soluble_interface &&
|
|
|
|
sp1.gap_raft_object == sp2.gap_raft_object &&
|
|
|
|
sp1.gap_object_support == sp2.gap_object_support &&
|
|
|
|
sp1.gap_support_object == sp2.gap_support_object &&
|
|
|
|
sp1.raft_base_top_z == sp2.raft_base_top_z &&
|
|
|
|
sp1.raft_interface_top_z == sp2.raft_interface_top_z &&
|
|
|
|
sp1.raft_contact_top_z == sp2.raft_contact_top_z &&
|
|
|
|
sp1.object_print_z_min == sp2.object_print_z_min;
|
|
|
|
}
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
typedef std::pair<coordf_t,coordf_t> t_layer_height_range;
|
2019-06-03 13:35:21 +00:00
|
|
|
typedef std::map<t_layer_height_range, DynamicPrintConfig> t_layer_config_ranges;
|
2016-12-08 18:02:16 +00:00
|
|
|
|
2019-06-20 14:15:09 +00:00
|
|
|
extern std::vector<std::pair<t_layer_height_range, coordf_t>> layer_height_ranges(const t_layer_config_ranges &config_ranges);
|
2016-12-08 18:02:16 +00:00
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
extern std::vector<coordf_t> layer_height_profile_from_ranges(
|
|
|
|
const SlicingParameters &slicing_params,
|
2019-06-05 09:50:59 +00:00
|
|
|
const t_layer_config_ranges &layer_config_ranges);
|
2016-12-12 16:53:38 +00:00
|
|
|
|
2019-11-14 09:22:48 +00:00
|
|
|
extern std::vector<double> layer_height_profile_adaptive(
|
2019-11-13 12:53:02 +00:00
|
|
|
const SlicingParameters& slicing_params,
|
2019-12-13 12:43:16 +00:00
|
|
|
const ModelObject& object, float quality_factor);
|
2019-11-15 14:49:07 +00:00
|
|
|
|
2019-11-20 13:06:30 +00:00
|
|
|
struct HeightProfileSmoothingParams
|
|
|
|
{
|
|
|
|
unsigned int radius;
|
|
|
|
bool keep_min;
|
|
|
|
|
|
|
|
HeightProfileSmoothingParams() : radius(5), keep_min(false) {}
|
|
|
|
HeightProfileSmoothingParams(unsigned int radius, bool keep_min) : radius(radius), keep_min(keep_min) {}
|
|
|
|
};
|
|
|
|
|
2019-11-18 09:25:23 +00:00
|
|
|
extern std::vector<double> smooth_height_profile(
|
2019-11-20 13:06:30 +00:00
|
|
|
const std::vector<double>& profile, const SlicingParameters& slicing_params,
|
|
|
|
const HeightProfileSmoothingParams& smoothing_params);
|
2016-12-21 15:00:41 +00:00
|
|
|
|
2019-01-21 09:06:51 +00:00
|
|
|
enum LayerHeightEditActionType : unsigned int {
|
2016-12-21 15:00:41 +00:00
|
|
|
LAYER_HEIGHT_EDIT_ACTION_INCREASE = 0,
|
|
|
|
LAYER_HEIGHT_EDIT_ACTION_DECREASE = 1,
|
|
|
|
LAYER_HEIGHT_EDIT_ACTION_REDUCE = 2,
|
|
|
|
LAYER_HEIGHT_EDIT_ACTION_SMOOTH = 3
|
|
|
|
};
|
|
|
|
|
2016-12-12 16:53:38 +00:00
|
|
|
extern void adjust_layer_height_profile(
|
|
|
|
const SlicingParameters &slicing_params,
|
|
|
|
std::vector<coordf_t> &layer_height_profile,
|
|
|
|
coordf_t z,
|
|
|
|
coordf_t layer_thickness_delta,
|
|
|
|
coordf_t band_width,
|
2016-12-21 15:00:41 +00:00
|
|
|
LayerHeightEditActionType action);
|
2016-12-12 16:53:38 +00:00
|
|
|
|
|
|
|
// Produce object layers as pairs of low / high layer boundaries, stored into a linear vector.
|
|
|
|
// The object layers are based at z=0, ignoring the raft layers.
|
|
|
|
extern std::vector<coordf_t> generate_object_layers(
|
|
|
|
const SlicingParameters &slicing_params,
|
|
|
|
const std::vector<coordf_t> &layer_height_profile);
|
|
|
|
|
|
|
|
// Produce a 1D texture packed into a 2D texture describing in the RGBA format
|
|
|
|
// the planned object layers.
|
|
|
|
// Returns number of cells used by the texture of the 0th LOD level.
|
|
|
|
extern int generate_layer_height_texture(
|
|
|
|
const SlicingParameters &slicing_params,
|
|
|
|
const std::vector<coordf_t> &layers,
|
|
|
|
void *data, int rows, int cols, bool level_of_detail_2nd_level);
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
}; // namespace Slic3r
|
|
|
|
|
2019-07-02 14:42:23 +00:00
|
|
|
namespace cereal
|
|
|
|
{
|
|
|
|
template<class Archive> void serialize(Archive& archive, Slic3r::t_layer_height_range &lhr) { archive(lhr.first, lhr.second); }
|
|
|
|
}
|
|
|
|
|
2016-12-08 18:02:16 +00:00
|
|
|
#endif /* slic3r_Slicing_hpp_ */
|